"use client"; import { Link } from "@tanstack/react-router"; import { Lock, AlertCircle, CheckCircle2, Plug } from "lucide-react"; import { Button } from "@/components/ui/button"; import { Badge } from "@/components/ui/badge"; import type { IntegrationCardState } from "@/hooks/use-integrations"; import { toast } from "sonner"; import { useState } from "react"; import { invokeFunction } from "@/lib/invoke-function"; interface Props { state: IntegrationCardState; agentReady: boolean; } export function IntegrationCard({ state, agentReady }: Props) { const { mcp } = state; const [connecting, setConnecting] = useState(false); async function handleConnect() { if (!agentReady) { toast.error("Seu agente ainda está sendo provisionado."); return; } setConnecting(true); const { data, error } = await invokeFunction<{ authorize_url: string }>( "oauth-start", { mcp_slug: mcp.slug }, ); setConnecting(false); if (error || !data?.authorize_url) { toast.error(error?.message ?? "Não foi possível iniciar a conexão."); return; } window.location.href = data.authorize_url; } return (

{mcp.name}

{state.kind === "connected" && ( Conectado )} {state.kind === "error" && ( {state.integration.status === "expired" ? "Expirado" : state.integration.status === "revoked" ? "Revogado" : "Erro"} )} {state.kind === "locked" && ( Bloqueado )}

{mcp.description}

{state.kind === "connected" && state.integration.connected_account_email && (

Conta: {state.integration.connected_account_email}

)} {state.kind === "error" && state.integration.error_message && (

{state.integration.error_message}

)} {state.kind === "locked" && (

Disponível nos planos: {state.mcp.available_in_plans.join(", ") || "—"}

)}
{state.kind === "available" && ( )} {state.kind === "locked" && ( )} {(state.kind === "connected" || state.kind === "error") && ( )}
); }