import { useState, Suspense } from 'react'; import { DiffEditor } from '@/lib/monacoLoader'; import { AlertTriangle, Loader2 } from 'lucide-react'; import { Modal, ModalHeader, ModalFooter, ConfirmModal } from '@/components/ui/modal'; import { Tabs, TabsList, TabsTrigger, TabsHighlight, TabsHighlightItem } from '@/components/ui/tabs'; import { Button } from '@/components/ui/button'; import { Checkbox } from '@/components/ui/checkbox'; import { Label } from '@/components/ui/label'; import { springs } from '@/lib/motion'; export interface PullResult { commitSha: string; incomingCompose: string; incomingEnv: string | null; currentCompose: string; currentEnv: string | null; validation: { ok: boolean; error?: string }; hasLocalChanges: boolean; } interface GitSourceDiffDialogProps { open: boolean; onOpenChange: (open: boolean) => void; stackName: string; pull: PullResult | null; syncEnv: boolean; autoDeployDefault: boolean; isDarkMode: boolean; applying: boolean; onApply: (commitSha: string, deploy: boolean) => Promise; onDismiss: () => Promise; } export function GitSourceDiffDialog({ open, onOpenChange, stackName, pull, syncEnv, autoDeployDefault, isDarkMode, applying, onApply, onDismiss, }: GitSourceDiffDialogProps) { const [diffTab, setDiffTab] = useState<'compose' | 'env'>('compose'); const [deployAfter, setDeployAfter] = useState(autoDeployDefault); const [confirmOpen, setConfirmOpen] = useState(false); const envAvailable = syncEnv && pull?.incomingEnv !== null; const effectiveTab = envAvailable ? diffTab : 'compose'; if (!pull) return null; const shortSha = pull.commitSha.slice(0, 7); const apply = async () => { await onApply(pull.commitSha, deployAfter); }; const handleApplyClick = () => { if (pull.hasLocalChanges) { setConfirmOpen(true); return; } apply(); }; const currentValue = effectiveTab === 'compose' ? pull.currentCompose : (pull.currentEnv ?? ''); const incomingValue = effectiveTab === 'compose' ? pull.incomingCompose : (pull.incomingEnv ?? ''); return ( <>
{!pull.validation.ok && (

Incoming compose failed validation

{pull.validation.error}
)} {pull.hasLocalChanges && (

Local edits detected on disk

Applying will overwrite changes that differ from the last applied commit.

)} {envAvailable && ( setDiffTab(v as 'compose' | 'env')}> Compose .env )}
}>
setDeployAfter(checked === true)} disabled={applying || !pull.validation.ok} /> } secondary={ } primary={ } />
{ setConfirmOpen(false); await apply(); }} /> ); }