export type SlashCommandResult = { handled: true; feedback: string } | { handled: false };

type UseSlashCommandsParams = {
  sessionId: string | null;
};

export function useSlashCommands({ sessionId }: UseSlashCommandsParams) {
  const execute = async (input: string): Promise<SlashCommandResult> => {
    const trimmed = input.trim();
    if (!trimmed.startsWith('/')) return { handled: false };
    if (!sessionId) return { handled: false };

    const spaceIndex = trimmed.indexOf(' ');
    const commandName = spaceIndex === -1 ? trimmed.slice(1) : trimmed.slice(1, spaceIndex);

    switch (commandName) {
      case 'help': {
        const helpText = ['Available commands:', '  /help - Show this help message'].join('\n');
        return { handled: true, feedback: helpText };
      }

      default:
        return { handled: false };
    }
  };

  return { execute };
}
