import { useEffect, useRef, useState } from "react"; import { Download, Loader2 } from "lucide-react"; import { useTranslation } from "react-i18next"; import type { ChannelFeatureAction } from "@/channel-plugins/types"; import { ToggleButton } from "@/components/ui/toggle-button"; import { ChannelLogo, ChannelStatusBadge, channelStatusLabel, channelToggleChecked, localizedChannelDisplayName, } from "@/components/settings/channels/ChannelIdentity"; import { Button } from "@/components/ui/button"; import type { NanobotFeatureInfo } from "@/lib/types"; import { cn } from "@/lib/utils"; export function ChannelCatalogRow({ feature, showBrandLogos, onSelect, actionKey, actionsDisabled = false, onAction, }: { feature: NanobotFeatureInfo; showBrandLogos: boolean; onSelect: (connect?: boolean) => void; actionKey: string | null; actionsDisabled?: boolean; onAction: ChannelFeatureAction; }) { const { t } = useTranslation(); const tx = (key: string, fallback: string) => t(key, { defaultValue: fallback }); const displayName = localizedChannelDisplayName(feature, t); const alwaysEnabled = feature.capabilities?.includes("always_enabled") ?? false; const pendingChecked = actionKey === `enable:${feature.name}` ? true : actionKey === `disable:${feature.name}` ? false : null; const ownActionBusy = pendingChecked !== null || actionKey === `install:${feature.name}`; const checked = alwaysEnabled || (pendingChecked ?? channelToggleChecked(feature)); const anyActionBusy = Boolean(actionKey); const installButtonRef = useRef(null); const [installHint, setInstallHint] = useState(false); useEffect(() => { if (!installHint) return; const timeout = window.setTimeout(() => setInstallHint(false), 1400); return () => window.clearTimeout(timeout); }, [installHint]); const pointToInstall = () => { setInstallHint(true); installButtonRef.current?.focus(); }; const channelIdentity = ( <>

{displayName}

); return (
{alwaysEnabled ? (
{channelIdentity}
) : ( )} {feature.runtime_status === "failed" ? (
{channelStatusLabel(feature, tx)}
) : null}
{!feature.installed ? ( ) : ( { if (enabled && feature.configured === false) onSelect(true); else onAction(enabled ? "enable" : "disable", feature.name); }} /> )}
); }