"use client"; import * as React from "react"; import { AnimatePresence, motion } from "framer-motion"; import { IconCheck, IconPlugConnected } from "@tabler/icons-react"; import { cn } from "../lib/utils"; import { transitions } from "../lib/motion"; import { useConnection } from "../hooks/use-connection"; import { Button } from "./button"; import { Spinner } from "./spinner"; /** * A button that asks once more before a destructive action, in place: * the first press arms it ("Delete?"), the second confirms. It disarms * after a few seconds or on blur. */ export function ConfirmButton({ children, confirmLabel, onConfirm, variant = "destructive", size = "default", disarmAfterMs = 4000, className, }: { children: React.ReactNode; confirmLabel?: React.ReactNode; onConfirm: () => Promise | unknown; variant?: "destructive" | "default" | "outline"; size?: "default" | "sm"; disarmAfterMs?: number; className?: string; }) { const [armed, setArmed] = React.useState(false); const [pending, setPending] = React.useState(false); React.useEffect(() => { if (!armed) return; const timer = setTimeout(() => setArmed(false), disarmAfterMs); return () => clearTimeout(timer); }, [armed, disarmAfterMs]); return ( ); } /** Connect (or show) an account on another service, by connection key. */ export function ConnectButton({ connectionKey, label, className, }: { connectionKey: string; /** Defaults to "Connect ". */ label?: string; className?: string; }) { const connection = useConnection(connectionKey); const name = connection.status?.name ?? connectionKey; if (connection.isLoading) { return ( ); } if (connection.status?.connected) { return ( {connection.status.account?.label ? `Connected as ${connection.status.account.label}` : `${name} connected`} ); } return ( ); }