import type { SlashCommandEntry } from '../../../../../plugins';

/** Plugin id tag for built-in commands in the slash command menu. */
export const BUILT_IN_SLASH_COMMAND_SOURCE = 'built-in';

/** i18n key for the built-in command source badge. */
export const BUILT_IN_SLASH_COMMAND_SOURCE_KEY = 'chat.slashCommand.builtInSource';

/** A first-party slash command that inserts fixed text into the chat as a message. */
export interface BuiltInSlashCommand {
  descriptionKey: string;
  icon?: string;
  name: string;
  text: string;
}

/**
 * Default commands available everywhere (chat servers and direct messages),
 * without requiring any plugin to be installed.
 */
export const BUILT_IN_SLASH_COMMANDS: readonly BuiltInSlashCommand[] = [
  {
    name: 'lenny',
    descriptionKey: 'chat.slashCommand.lennyDescription',
    text: '( ͡° ͜ʖ ͡°)'
  }
];

/**
 * Adapts the built-in command definitions to the `SlashCommandEntry` shape used
 * by the composer menu. Each entry's `run` sends the command's text through the
 * provided callback so it posts as a normal chat message.
 */
export function buildBuiltInSlashCommandEntries(
  sendText: (text: string) => void,
  instant: (key: string) => string = (key) => key
): SlashCommandEntry[] {
  return BUILT_IN_SLASH_COMMANDS.map((command) => ({
    contribution: {
      description: instant(command.descriptionKey),
      icon: command.icon,
      name: command.name,
      run: () => sendText(command.text),
      scope: 'global'
    },
    id: `${BUILT_IN_SLASH_COMMAND_SOURCE}:${command.name}`,
    pluginId: instant(BUILT_IN_SLASH_COMMAND_SOURCE_KEY)
  }));
}
