import {
DownloadIcon,
RefreshCwIcon,
Trash2Icon,
} from "lucide-react"
import { useTranslation } from "react-i18next"
import { Badge } from "@/components/ui/badge"
import { TooltipIconButton } from "@/components/common/tooltip-icon-button"
import { pluginStoreActions, usePluginStore } from "@/store"
import { Switch } from "@/components/ui/switch"
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip"
import { openURL } from "@/utils/dataSender"
import {
pluginDeprecationStatus,
type PluginDetailSelectedItem,
type PluginInstalledItem,
} from "./types"
import {
buildPluginDeprecationKey,
normalizePluginDisplayName,
pluginDefaultLogoUrl,
resolvePluginHomepageUrl,
} from "./utils"
interface PluginDetailHeaderProps {
selectedItem: PluginDetailSelectedItem | null
plugin: PluginInstalledItem | null
isMutating: boolean
}
export function PluginDetailHeader({
selectedItem,
plugin,
isMutating,
}: PluginDetailHeaderProps) {
const { t } = useTranslation()
const deprecationByPlugin = usePluginStore.use.deprecationByPlugin()
if (!selectedItem) {
return (
)
}
const pluginDisplayName = normalizePluginDisplayName(selectedItem.fullName)
const pluginAuthor = selectedItem.author.trim() || "Unknown"
const pluginDescription = selectedItem.description.trim()
const pluginLogo = selectedItem.logo.trim() || pluginDefaultLogoUrl
const pluginHomepageUrl = resolvePluginHomepageUrl(selectedItem.fullName, [
plugin?.homepage,
selectedItem.homepage,
])
const deprecationState = deprecationByPlugin[
buildPluginDeprecationKey(selectedItem.fullName, selectedItem.version)
]
const isDeprecated = Boolean(
deprecationState?.status === pluginDeprecationStatus.Ready &&
deprecationState.isDeprecated
)
const handleOpenPluginHomepage = async () => {
openURL(pluginHomepageUrl)
}
const handleSetPluginEnabled = async (enabled: boolean) => {
if (!plugin) {
return
}
await pluginStoreActions.setPluginEnabled(plugin.fullName, enabled)
}
const handleUpdatePlugin = async () => {
if (!plugin) {
return
}
await pluginStoreActions.updatePlugin(plugin.fullName)
}
const handleUninstallPlugin = async () => {
if (!plugin) {
return
}
await pluginStoreActions.uninstallPlugin(plugin.fullName)
}
const handleInstallPlugin = async () => {
await pluginStoreActions.installPlugin(selectedItem.fullName)
}
return (

{
event.currentTarget.onerror = null
event.currentTarget.src = pluginDefaultLogoUrl
}}
/>
{selectedItem.hasInstall ? (
{t("PLUGIN_INSTALLED")}
) : null}
{isDeprecated ? (
{t("PLUGIN_DEPRECATED_BADGE")}
) : null}
{pluginDescription ? (
{pluginDescription}
) : null}
v{selectedItem.version}
ยท
{pluginAuthor}
{plugin ? (
}
size="icon-sm"
disabled={isMutating}
onClick={async () => {
await handleUninstallPlugin()
}}
/>
}
size="icon-sm"
isLoading={isMutating}
onClick={async () => {
await handleUpdatePlugin()
}}
/>
{plugin.enabled ? t("ENABLE") : t("DISABLE")}
{
await handleSetPluginEnabled(checked)
}}
/>
{plugin.enabled ? t("DISABLE_PLUGIN") : t("ENABLE_PLUGIN")}
) : selectedItem.hasInstall ? null : (
}
size="icon-sm"
isLoading={isMutating}
onClick={async () => {
await handleInstallPlugin()
}}
/>
)}
)
}