import { callAction } from "@agent-native/core/client/hooks"; import { useT } from "@agent-native/core/client/i18n"; import { useSetHeaderActions, useSetPageTitle, } from "@agent-native/toolkit/app-shell"; import { IconAlertTriangle, IconPalette, IconPlus, IconRefresh, } from "@tabler/icons-react"; import { useMemo, useState } from "react"; import { DesignSystemCard } from "@/components/design-system/DesignSystemCard"; import { DesignSystemSetup } from "@/components/design-system/DesignSystemSetup"; import { Button } from "@/components/ui/button"; import { useDesignSystems } from "@/hooks/use-design-systems"; import type { DesignSystemData } from "../../shared/api"; import { missingDesignSystemDataFields } from "../../shared/design-system-validation"; export default function DesignSystems() { const t = useT(); const { designSystems, isLoading, error, refetch } = useDesignSystems(); const [showSetup, setShowSetup] = useState(false); const [editingId, setEditingId] = useState(null); const handleCardClick = (id: string) => { setEditingId(id); setShowSetup(true); }; const handleSetDefault = async (id: string) => { try { await callAction("set-default-design-system", { id }); refetch(); } catch (err) { console.error("Failed to set default design system:", err); } }; const handleComplete = () => { setShowSetup(false); setEditingId(null); refetch(); }; const handleClose = () => { setShowSetup(false); setEditingId(null); }; const parseDesignData = (dataStr: string): DesignSystemData | null => { try { const parsed = JSON.parse(dataStr) as DesignSystemData; // DesignSystemCard reads colors.* / typography.* unconditionally, down // to nested fields like typography.headingFont. Rows written before // create/update validation existed can have `colors: {}` and still // pass a truthy check, so reuse the same nested-field validator the // actions use rather than only checking the top-level objects exist. if (missingDesignSystemDataFields(parsed).length > 0) return null; return parsed; } catch { return null; } }; useSetPageTitle(t("header.designSystems")); useSetHeaderActions( useMemo( () => ( ), [], ), ); return (
{isLoading ? ( <>
{Array.from({ length: 4 }).map((_, i) => (
))}
) : error ? (

{t("home.loadFailed")}

{t("home.loadFailedDescription")}

) : designSystems.length === 0 ? ( { setEditingId(null); setShowSetup(true); }} /> ) : ( <>
{/* New design system card */} {/* Design system cards */} {designSystems.map((ds) => { const parsed = parseDesignData(ds.data); if (!parsed) return null; return ( handleCardClick(ds.id)} onSetDefault={() => handleSetDefault(ds.id)} /> ); })}
)}
{/* Setup/Edit Dialog */}
); } function EmptyState({ onCreateNew }: { onCreateNew: () => void }) { const t = useT(); return (

{t("designSystems.emptyTitle")}

{t("designSystems.emptyDescription")}

); }