import { LlmModelType } from '@/constants/knowledge';
import { useComposeLlmOptionsByModelTypes } from '@/hooks/use-llm-request';
import { useTranslation } from 'react-i18next';
import { SelectWithSearch } from '../originui/select-with-search';
import { RAGFlowFormItem } from '../ragflow-form';

export type LLMFormFieldProps = {
  options?: any[];
  name?: string;
  testId?: string;
  optionTestIdPrefix?: string;
};

export const useModelOptions = () => {
  const modelOptions = useComposeLlmOptionsByModelTypes([
    LlmModelType.Chat,
    LlmModelType.Image2text,
  ]);
  return {
    modelOptions,
  };
};

export function LLMFormField({
  options,
  name,
  testId,
  optionTestIdPrefix,
}: LLMFormFieldProps) {
  const { t } = useTranslation();
  const { modelOptions } = useModelOptions();

  return (
    <RAGFlowFormItem name={name || 'llm_id'} label={t('chat.model')}>
      <SelectWithSearch
        options={options || modelOptions}
        testId={testId}
        optionTestIdPrefix={optionTestIdPrefix}
      ></SelectWithSearch>
    </RAGFlowFormItem>
  );
}
