"use client"; import { useState, useCallback } from "react"; import { IconTerminal2, IconCopy, IconCheck } from "@tabler/icons-react"; import { Button } from "@kandev/ui/button"; import { Tooltip, TooltipContent, TooltipTrigger } from "@kandev/ui/tooltip"; import type { RecoveryAuthMethod } from "@/components/task/chat/types"; import { copyToClipboard } from "@/lib/utils/copy-to-clipboard"; import { useTranslation } from "react-i18next"; function buildFullCommand(termAuth: RecoveryAuthMethod["terminal_auth"]): string | null { if (!termAuth) return null; if (termAuth.args && termAuth.args.length > 0) { return `${termAuth.command} ${termAuth.args.join(" ")}`; } return termAuth.command; } export function AuthMethodsPanel({ methods, onOpenTerminal, }: { methods: RecoveryAuthMethod[]; onOpenTerminal: (command: string) => void; }) { const { t } = useTranslation(); return (
{t("task:authenticationRequiredLogInBeforeResuming")}
{methods.map((method) => ( ))}
); } export function GenericAuthPanel({ onOpenTerminal }: { onOpenTerminal: () => void }) { const { t } = useTranslation(); return (
{t("task:authenticationRequiredPleaseLogInVia")}
); } function AuthMethodRow({ method, onOpenTerminal, }: { method: RecoveryAuthMethod; onOpenTerminal: (command: string) => void; }) { const { t } = useTranslation(); const [copied, setCopied] = useState(false); const termAuth = method.terminal_auth; const fullCommand = buildFullCommand(termAuth); const handleCopy = useCallback(async () => { if (!fullCommand) return; if (await copyToClipboard(fullCommand)) { setCopied(true); setTimeout(() => setCopied(false), 2000); } }, [fullCommand]); return (
{method.name}
{termAuth && fullCommand ? (
{fullCommand}
{t("task:copyCommand")} {t("task:openTheBottomTerminalAndPaste")}
) : (
{method.description || t("task:loginRequired")}
)}
); }