| 1 | import { AutoCompleteOption } from '../autocomplete/AutoCompleteOption.js'; |
| 2 | import { SlashCommand } from './SlashCommand.js'; |
| 3 | import { SlashCommandEnumValue } from './SlashCommandEnumValue.js'; |
| 4 | |
| 5 | export class SlashCommandEnumAutoCompleteOption extends AutoCompleteOption { |
| 6 | /** |
| 7 | * @param {SlashCommand} cmd |
| 8 | * @param {SlashCommandEnumValue} enumValue |
| 9 | * @returns {SlashCommandEnumAutoCompleteOption} |
| 10 | */ |
| 11 | static from(cmd, enumValue) { |
| 12 | const mapped = this.valueToOptionMap.find(it => enumValue instanceof it.value)?.option ?? this; |
| 13 | return new mapped(cmd, enumValue); |
| 14 | } |
| 15 | /**@type {{value:(typeof SlashCommandEnumValue), option:(typeof SlashCommandEnumAutoCompleteOption)}[]} */ |
| 16 | static valueToOptionMap = []; |
| 17 | /**@type {SlashCommand}*/ cmd; |
| 18 | /**@type {SlashCommandEnumValue}*/ enumValue; |
| 19 | |
| 20 | |
| 21 | /** |
| 22 | * @param {SlashCommand} cmd |
| 23 | * @param {SlashCommandEnumValue} enumValue |
| 24 | */ |
| 25 | constructor(cmd, enumValue) { |
| 26 | super(enumValue.value, enumValue.typeIcon, enumValue.type, enumValue.matchProvider, enumValue.valueProvider, enumValue.makeSelectable); |
| 27 | this.cmd = cmd; |
| 28 | this.enumValue = enumValue; |
| 29 | } |
| 30 | |
| 31 | |
| 32 | renderItem() { |
| 33 | let li; |
| 34 | li = this.makeItem(this.name, this.typeIcon, true, [], [], null, this.enumValue.description); |
| 35 | li.setAttribute('data-name', this.name); |
| 36 | li.setAttribute('data-option-type', this.type); |
| 37 | return li; |
| 38 | } |
| 39 | |
| 40 | |
| 41 | renderDetails() { |
| 42 | return this.cmd.renderHelpDetails(); |
| 43 | } |
| 44 | } |