import type { Message , MessageSelectOptionData } from "discord.js" ; import { randomUUID } from "node:crypto" ; import type { InteractionContext } from "../interaction-context" ; /**
 * Options passed to  selectMenuComponent export type SelectMenuComponentOptions = { /**
     * The array of options that can be selected.
     * Same structure as [MessageSelectOptionData from DJS](https://discord.js.org/#/docs/main/stable/typedef/MessageSelectOptionData)
     */ options : MessageSelectOptionData [ ] ; see selectMenuComponent selected ? : Iterable < string > | string | undefined ; /** The placeholder text to display when no options are selected */ placeholder ? : string | undefined ; /**
     * Called when one or more options are selected.
     * Use this callback to update your current selected state.
     *
     * **Note:** For multi-select ( SelectMenuComponentOptions . maxValues ), this doesn't get called immediately.
     * It only gets called after clicking away from the select dropdown.
      onSelect : ( context : SelectMenuInteractionContext ) => unknown ; /**
     * The minimum number of options that can be selected.
     * Passing this option will enable multi-select,
     * and can't be 0.
     */ minValues ? : number | undefined ; /**
     * The maximum number of options that can be selected.
     * Passing this option will enable multi-select,
     * and can't be greater than the number of options.
     */ maxValues ? : number | undefined ; } ; /**
 * Returned from  selectMenuComponent export type SelectMenuComponent = Omit < SelectMenuComponentOptions , "selected" > & { type : "selectMenu" ; customId : string ; } ; /**
 * Context object passed to  SelectMenuComponentOptions . onSelect export type SelectMenuInteractionContext = InteractionContext & { /** The message that the component is on */ readonly message : Message ; /** The values the user selected */ readonly values : string [ ] ; } ; /**
 * Represents a Discord [select menu](https://discord.com/developers/docs/interactions/message-components#select-menus) component.
 *
 * ```js
 * let selected
 *
 * context.reply(() =>
 *   selectMenuComponent({
 *     options: [
 *       { label: "option 1", value: "option 1" },
 *       { label: "option 2", value: "option 2" },
 *     ],
 *     placeholder: "select one",
 *     selected,
 *     onChange: (values) => {
 *       selected = values[0]
 *     },
 *   }),
 * )
 * ```
 */ export function selectMenuComponent ( { options , selected , ... args } ) { const selectedOptions = typeof selected === "string" ? new Set ( [ selected ] ) : selected != null ? new Set ( selected ) : new Set ( ) ; return { ... args , type : "selectMenu" , customId : randomUUID ( ) , options : options . map ( ( option ) => ( { ... option , default : option . default ?? selectedOptions . has ( option . value ) , } ) ) , } ; }