'use client' import type { FC } from 'react' import React from 'react' import cn from '@/utils/classnames' import { RiArrowDownSLine, RiArrowRightSLine } from '@remixicon/react' import { useGetLanguage } from '@/context/i18n' import { CollectionType } from '../../../tools/types' import type { ToolWithProvider } from '../../types' import { BlockEnum } from '../../types' import type { ToolDefaultValue } from '../types' import { ViewType } from '../view-type-select' import ActonItem from './action-item' import BlockIcon from '../../block-icon' import { useBoolean } from 'ahooks' type Props = { className?: string payload: ToolWithProvider viewType: ViewType isShowLetterIndex: boolean onSelect: (type: BlockEnum, tool?: ToolDefaultValue) => void } const Tool: FC = ({ className, payload, viewType, isShowLetterIndex, onSelect, }) => { const language = useGetLanguage() const isTreeView = viewType === ViewType.tree const actions = payload.tools const hasAction = payload.type === CollectionType.builtIn const [isFold, { toggle: toggleFold, }] = useBoolean(false) const FoldIcon = isFold ? RiArrowDownSLine : RiArrowRightSLine return (
{ if (hasAction) { toggleFold() return } onSelect(BlockEnum.Tool, { provider_id: payload.id, provider_type: payload.type, provider_name: payload.name, tool_name: payload.name, tool_label: payload.label[language], title: payload.label[language], }) }} >
{payload.label[language]}
{hasAction && ( )}
{hasAction && isFold && ( actions.map(action => ( )) )}
) } export default React.memo(Tool)