'use client' import type { PluginDetail } from '@/app/components/plugins/types' import { Button } from '@langgenius/dify-ui/button' import { Tooltip, TooltipContent, TooltipTrigger } from '@langgenius/dify-ui/tooltip' import { memo, useId } from 'react' import { useTranslation } from 'react-i18next' import Badge from '@/app/components/base/badge' import { HeaderModals } from '@/app/components/plugins/plugin-detail-panel/detail-header/components' import { useDetailHeaderState, usePluginOperations } from '@/app/components/plugins/plugin-detail-panel/detail-header/hooks' import OperationDropdown from '@/app/components/plugins/plugin-detail-panel/operation-dropdown' import { useReadmePanelStore } from '@/app/components/plugins/readme-panel/store' import { PluginSource } from '@/app/components/plugins/types' import PluginVersionPicker from '@/app/components/plugins/update-plugin/plugin-version-picker' import { useLocale } from '@/context/i18n' import useTheme from '@/hooks/use-theme' import { getMarketplaceUrl } from '@/utils/var' type Props = { detail: PluginDetail onUpdate?: (isDelete?: boolean) => void } const usePluginDetailHeader = useDetailHeaderState const getDetailUrl = ( detail: PluginDetail, locale: string, theme: string, ) => { const { source, meta } = detail const { author, name } = detail.declaration || detail if (source === PluginSource.github) return meta?.repo ? `https://github.com/${meta.repo}` : '' if (source === PluginSource.marketplace) return getMarketplaceUrl(`/plugins/${author}/${name}`, { language: locale, theme }) return '' } const DataSourcePluginActions = ({ detail, onUpdate, }: Props) => { const { t } = useTranslation() const { theme } = useTheme() const locale = useLocale() const readmeTriggerId = useId() const openReadmePanel = useReadmePanelStore(s => s.openReadmePanel) const detailHeaderState = usePluginDetailHeader(detail) const { modalStates, versionPicker, hasNewVersion, isAutoUpgradeEnabled, isFromGitHub, isFromMarketplace, } = detailHeaderState const { handleUpdate, handleUpdatedFromMarketplace, handleDelete, } = usePluginOperations({ detail, modalStates, versionPicker, isFromMarketplace, onUpdate, }) const displayVersion = isFromGitHub ? (detail.meta?.version ?? detail.version) : detail.version const handleVersionSelect = (state: { version: string, unique_identifier: string, isDowngrade?: boolean }) => { versionPicker.setTargetVersion(state) handleUpdate(state.isDowngrade) } const handleTriggerLatestUpdate = () => { if (isFromMarketplace) { versionPicker.setTargetVersion({ version: detail.latest_version, unique_identifier: detail.latest_unique_identifier, }) } handleUpdate() } const handleViewReadme = () => { openReadmePanel({ detail, triggerId: readmeTriggerId, }) } return (