'use client' import type { FC } from 'react' import React, { useState } from 'react' import { useTranslation } from 'react-i18next' import { PortalToFollowElem, PortalToFollowElemContent, PortalToFollowElemTrigger, } from '@/app/components/base/portal-to-follow-elem' import AppTrigger from '@/app/components/plugins/plugin-detail-panel/app-selector/app-trigger' import AppPicker from '@/app/components/plugins/plugin-detail-panel/app-selector/app-picker' // import Button from '@/app/components/base/button' import { useAppDetail } from '@/service/use-apps' import type { App } from '@/types/app' import type { OffsetOptions, Placement, } from '@floating-ui/react' type Props = { value?: { app_id: string inputs: Record files?: any[] } disabled?: boolean placement?: Placement offset?: OffsetOptions onSelect: (app: { app_id: string inputs: Record files?: any[] }) => void supportAddCustomTool?: boolean } const AppSelector: FC = ({ value, disabled, placement = 'bottom', offset = 4, onSelect, }) => { const { t } = useTranslation() const [isShow, onShowChange] = useState(false) const handleTriggerClick = () => { if (disabled) return onShowChange(true) } const { data: currentApp } = useAppDetail(value?.app_id || 'empty') const [isShowChooseApp, setIsShowChooseApp] = useState(false) const handleSelectApp = (app: App) => { const appValue = { app_id: app.id, inputs: value?.inputs || {}, files: value?.files || [], } onSelect(appValue) setIsShowChooseApp(false) } return ( <>
{t('tools.toolSelector.label')}
} isShow={isShowChooseApp} onShowChange={setIsShowChooseApp} disabled={false} onSelect={handleSelectApp} />
{/* app inputs config panel */}
) } export default React.memo(AppSelector)