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,CAAC,QAAQ,EAAE,QAAQ,CAAC,EAAE,KAAe,CAAC;IAC9D,CAAC;CAEJ","sourcesContent":["/* eslint-disable @typescript-eslint/no-unsafe-declaration-merging */\nimport { APIMessage, APIModalSubmitInteraction, ComponentType, InteractionType, LocaleString, ModalSubmitActionRowComponent, ModalSubmitComponent } from \"discord-api-types/v10\";\nimport BaseInteraction from \"./BaseInteraction.mjs\";\nimport { InteractionResponseMixin, applyInteractionResponseMixins, createInteractionMixinList } from \"./Response.mjs\";\n\n\nexport default class ModalSubmitInteraction extends BaseInteraction {\n    declare type: InteractionType.ModalSubmit;\n\n    /** The custom id for the modal */\n    customId: string;\n    /** The fields that the invoking user has provided for the modal */\n    fields: ModalSubmitFields;\n    /** The selected language of the invoking user */\n    locale: LocaleString;\n    /** For components, the message they were attached to */\n    message?: APIMessage;\n\n    constructor(interaction: APIModalSubmitInteraction) {\n        super(interaction);\n\n        this.customId = interaction.data.custom_id;\n        this.fields = new ModalSubmitFields(interaction.data.components ?? []);\n        this.locale = interaction.locale;\n        this.message = interaction.message;\n    }\n\n    /** Whether this is from a message component. */\n    isFromMessage(): this is ModalMessageModalSubmitInteraction {\n        return Boolean(this.message);\n    }\n\n}\n\nconst allowedResponses = createInteractionMixinList([\n    \"reply\",\n    \"editReply\",\n    \"deleteReply\",\n    \"deferReply\",\n    \"fetchReply\",\n    \"followUp\"\n]);\n\napplyInteractionResponseMixins(ModalSubmitInteraction, [...allowedResponses, \"update\", \"deferUpdate\"]);\n\nexport default interface ModalSubmitInteraction extends InteractionResponseMixin<typeof allowedResponses> { }\n\nexport interface ModalMessageModalSubmitInteraction extends ModalSubmitInteraction { message: APIMessage }\nexport interface ModalMessageModalSubmitInteraction extends InteractionResponseMixin<[\"update\", \"deferUpdate\"]> { }\n\n\nexport type fields = TextInputOption;\n\n\nexport class BaseField {\n    type: ComponentType;\n    customId: string;\n    value: string | number | boolean;\n\n    constructor(type: ComponentType, customId: string, value: string | number | boolean) {\n        this.type = type;\n        this.customId = customId;\n        this.value = value;\n    }\n}\nexport class TextInputOption extends BaseField {\n    declare type: ComponentType.TextInput;\n    declare value: string;\n\n    constructor(customId: string, value: string) {\n        super(ComponentType.TextInput, customId, value);\n    }\n}\n\nfunction formatField(component: ModalSubmitComponent): fields {\n    switch (component.type) {\n        case ComponentType.TextInput:\n            return new TextInputOption(component.custom_id, component.value);\n        default:\n            throw new Error(`Unknown component type: ${component.type}`);\n    }\n}\n\nexport class ModalSubmitFields {\n    values: Record<string, fields> = {};\n\n    constructor(components: ModalSubmitActionRowComponent[]) {\n        // this.components = components;\n\n        for (const row of components) {\n            for (const component of row.components) {\n                this.values[component.custom_id] = formatField(component);\n            }\n        }\n    }\n\n    getField(customId: string, required: true): fields;\n    getField(customId: string, required?: boolean): fields | undefined;\n    getField(customId: string, required?: boolean): fields | undefined {\n        const field = this.values[customId];\n        if (!field && required) {\n            throw new Error(`Field ${customId} is required`);\n        }\n        return field;\n    }\n\n    getTextInputValue(customId: string, required: true): string;\n    getTextInputValue(customId: string, required?: boolean): string | undefined;\n    getTextInputValue(customId: string, required?: boolean): string | undefined {\n        return this.getField(customId, required)?.value as string;\n    }\n\n}\n"]}