'use client' import type { FC } from 'react' import React from 'react' import cn from 'classnames' import { useBoolean, useClickAway } from 'ahooks' import { ChevronDownIcon } from '@heroicons/react/24/outline' import { useTranslation } from 'react-i18next' import ModelIcon from '@/app/components/app/configuration/config-model/model-icon' import { UNIVERSAL_CHAT_MODEL_LIST as MODEL_LIST } from '@/config' import { Checked as CheckedIcon } from '@/app/components/base/icons/src/public/model' export type IModelConfigProps = { modelId: string onChange?: (model: string) => void readonly?: boolean } const ModelConfig: FC = ({ modelId, onChange, readonly, }) => { const { t } = useTranslation() const currModel = MODEL_LIST.find(item => item.id === modelId) const [isShowOption, { setFalse: hideOption, toggle: toogleOption }] = useBoolean(false) const triggerRef = React.useRef(null) useClickAway(() => { hideOption() }, triggerRef) return (
{t('explore.universalChat.model')}
!readonly && toogleOption()} className={cn( readonly ? 'cursor-not-allowed' : 'cursor-pointer', 'flex items-center h-9 px-3 space-x-2 rounded-lg', isShowOption && 'bg-gray-100', )}>
{currModel?.name}
{!readonly && }
{isShowOption && (
{MODEL_LIST.map(item => (
onChange?.(item.id)} className="w-[232px] flex items-center h-9 px-4 rounded-lg cursor-pointer hover:bg-gray-100">
{item.name}
{(item.id === currModel?.id) && }
))}
)}
) } export default React.memo(ModelConfig)