import React from "react"; import { AlertCircle, Check, CheckCircle2, Clock, Loader2, Mail, Shield, User, } from "lucide-react"; import { Button } from "@/components/ui/button"; import { Card, CardContent } from "@/components/ui/card"; import { Checkbox } from "@/components/ui/checkbox"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from "@/components/ui/dialog"; import { Switch } from "@/components/ui/switch"; import type { AiBuilderServiceData } from "./types"; // --------------------------------------------------------------------------- // ServiceConfigurationModal // --------------------------------------------------------------------------- export type ServiceCredentialField = { id: string; label: string; value: string; onChange: (value: string) => void; placeholder?: string; /** Input type, e.g. "password" for secrets. Defaults to "text". */ type?: string; }; export type ServiceConfigurationModalProps = { open: boolean; onOpenChange: (open: boolean) => void; serviceTitle: string; isConnected: boolean; serviceData?: AiBuilderServiceData; /** Brand icon node shown in the not-connected centered layout */ iconNode?: React.ReactNode; /** Permissions shown in the not-connected state */ connectPermissions?: string[]; /** Subtitle shown below the service name in the not-connected state */ connectDescription?: string; /** Connection detail inputs shown in the not-connected state (e.g. API * keys) — the service connects with these instead of an OAuth flow. */ credentialFields?: ServiceCredentialField[]; /** Status line shown in the connected state's success banner. */ connectedStatusLabel?: string; /** Label for the connect button in the not-connected state. */ connectLabel?: string; /** Connection-test progress shown above the footer in the not-connected * state — drives a spinner (testing), green tick (success) or red error * line. The caller owns the test itself. */ connectStatus?: "idle" | "testing" | "success" | "error"; connectStatusMessage?: string; onConnect: () => void; onDisconnect: () => void; onReconnect: () => void; }; export function ServiceConfigurationModal({ open, onOpenChange, serviceTitle, isConnected, serviceData, iconNode, connectPermissions, connectDescription = "Link your account to enable automated workflows with WealthX.", credentialFields, connectedStatusLabel = "Active — integration is running", connectLabel = "Connect", connectStatus = "idle", connectStatusMessage, onConnect, onDisconnect, onReconnect, }: ServiceConfigurationModalProps) { return ( {isConnected ? ( <> {serviceTitle} Manage your integration settings.
{connectedStatusLabel}
{serviceData && ( <>

Account Information

{serviceData.accountIdentifierLabel}: {serviceData.accountIdentifier}
Connected on: {serviceData.connectedOn}
Last synced: {serviceData.lastSynced}

Granted Permissions

{serviceData.permissions.map((permission) => (
{permission}
))}

Sync Settings

{serviceData.syncLabel}

{serviceData.syncDescription}

{serviceData.emailCategories && (

Email Filters

Choose which inbox categories to sync into WealthX.

{serviceData.emailCategories.available.map( (category) => { const checked = serviceData.emailCategories!.selected.includes( category ); return (
{ const next = v ? [ ...serviceData.emailCategories! .selected, category, ] : serviceData.emailCategories!.selected.filter( (c) => c !== category ); serviceData.emailCategories!.onChange( next ); }} />
); } )}
)} )}
) : ( <>
{iconNode ?? ( )}

Connect {serviceTitle}

{connectDescription}

{credentialFields && credentialFields.length > 0 && (

Connection Details

{credentialFields.map((field) => (
field.onChange(e.target.value)} />
))}
)} {connectPermissions && connectPermissions.length > 0 && (

Permissions requested

{connectPermissions.map((perm) => (
{perm}
))}
)}
{connectStatus !== "idle" && (
{connectStatus === "testing" && ( )} {connectStatus === "success" && ( )} {connectStatus === "error" && ( )} {connectStatusMessage ?? (connectStatus === "testing" ? "Testing connection..." : connectStatus === "success" ? "Connection valid and live" : "Could not connect. Check your details and try again.")}
)} )}
); }