"use client"; import { useState, useEffect } from "react"; import type { FormEvent, MouseEvent } from "react"; import { BlueprintTarget } from "@capakraken/shared"; import type { BlueprintFieldDefinition } from "@capakraken/shared"; import { trpc } from "~/lib/trpc/client.js"; import { BlueprintFieldCatalog } from "./BlueprintFieldCatalog.js"; import { useSelection } from "~/hooks/useSelection.js"; import { BatchActionBar } from "~/components/ui/BatchActionBar.js"; import { ConfirmDialog } from "~/components/ui/ConfirmDialog.js"; import { FilterBar } from "~/components/ui/FilterBar.js"; import { SortableColumnHeader } from "~/components/ui/SortableColumnHeader.js"; import { useTableSort } from "~/hooks/useTableSort.js"; import { useViewPrefs } from "~/hooks/useViewPrefs.js"; const INPUT_CLS = "px-3 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-brand-500 text-sm"; const BTN_PRIMARY = "px-4 py-2 bg-brand-600 text-white rounded-lg hover:bg-brand-700 text-sm font-medium disabled:opacity-50"; const BTN_SECONDARY = "px-4 py-2 border border-gray-300 text-gray-700 rounded-lg hover:bg-gray-50 text-sm font-medium"; interface NewBlueprintModalProps { onClose: () => void; onCreated: () => void; } type BlueprintTargetValue = "RESOURCE" | "PROJECT"; type BlueprintSortField = "name" | "target" | "fieldCount" | "presetCount" | "global"; function NewBlueprintModal({ onClose, onCreated }: NewBlueprintModalProps) { const utils = trpc.useUtils(); const [name, setName] = useState(""); const [description, setDescription] = useState(""); const [target, setTarget] = useState("RESOURCE"); const [error, setError] = useState(null); const createMutation = trpc.blueprint.create.useMutation(); async function handleSubmit(e: FormEvent) { e.preventDefault(); setError(null); if (!name.trim()) { setError("Name is required."); return; } try { await createMutation.mutateAsync({ name: name.trim(), description: description.trim() || undefined, target: target as BlueprintTarget, fieldDefs: [], defaults: {}, validationRules: [], }); await utils.blueprint.list.invalidate(); onCreated(); onClose(); } catch (err) { setError(err instanceof Error ? err.message : "Failed to create blueprint."); } } function handleBackdropClick(e: MouseEvent) { if (e.target === e.currentTarget) onClose(); } return (

New Blueprint

setName(e.target.value)} placeholder="e.g. Resource Extended Fields" className={INPUT_CLS} autoFocus />