import { useState } from "react"; import { GripVertical, Plus, Trash2 } from "lucide-react"; import { Button } from "./button"; import { Input } from "./input"; import { Switch } from "./switch"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "./select"; import { cn } from "../../lib/utils"; /** Predefined document category options advisors can pick from. */ const DOCUMENT_TYPES = [ "Income Verification", "Bank Statements", "Rental Income", "Property Evidence", "Liabilities", "Identity", "Employment Contract", "Notice of Assessment", "Contract of Sale", "Savings History", ]; export interface ChecklistCategory { id: string; name: string; /** Required for the main applicant. */ requiredMain: boolean; /** Required for the co-applicant. */ requiredCo: boolean; /** true when the advisor typed a custom name not in the predefined list. */ custom?: boolean; } export interface DocumentChecklistTemplateProps { /** Initial list of checklist categories. */ categories?: ChecklistCategory[]; /** Called on every edit (add / change / delete). */ onChange?: (categories: ChecklistCategory[]) => void; /** Called when the advisor clicks Save. */ onSave?: (categories: ChecklistCategory[]) => void; /** Called when the advisor clicks Cancel. */ onCancel?: () => void; className?: string; } /** * DocumentChecklistTemplate — organism * * Editable list of document categories. Each category has separate Required * toggles for Main and Co applicants. Name is chosen from a predefined * dropdown or typed as a custom value. */ export function DocumentChecklistTemplate({ categories: initial = [], onChange, onSave, onCancel, className, }: DocumentChecklistTemplateProps) { const [categories, setCategories] = useState(() => initial.map((c) => ({ ...c, custom: c.custom ?? !DOCUMENT_TYPES.includes(c.name), })), ); const [isDirty, setIsDirty] = useState(false); function update(next: ChecklistCategory[]) { setCategories(next); setIsDirty(true); onChange?.(next); } function handleSelectType(id: string, value: string) { if (value === "__custom__") { update( categories.map((c) => c.id === id ? { ...c, name: "", custom: true } : c, ), ); } else { update( categories.map((c) => c.id === id ? { ...c, name: value, custom: false } : c, ), ); } } function handleCustomName(id: string, name: string) { update(categories.map((c) => (c.id === id ? { ...c, name } : c))); } function handleToggle(id: string, field: "requiredMain" | "requiredCo") { update( categories.map((c) => (c.id === id ? { ...c, [field]: !c[field] } : c)), ); } function handleDelete(id: string) { update(categories.filter((c) => c.id !== id)); } function handleAdd() { update([ ...categories, { id: `cat-${Date.now()}`, name: "", requiredMain: true, requiredCo: false, custom: false, }, ]); } const COLS = "grid-cols-[20px_1fr_64px_64px_32px]"; return (
{/* ── Header — title only ── */}
Document Checklist Template
{/* ── Description ── */}

Define the document categories required for loan applications. Set required status separately for Main and Co-applicants.

{/* ── Body ── */}
{/* Column headers */} {categories.length > 0 && (
Category Name Main Co
)} {/* Rows */} {categories.length === 0 ? (
No categories yet. Add one below.
) : (
{categories.map((cat) => (
{/* Name: Select (predefined) or Input (custom) */} {cat.custom ? ( handleCustomName(cat.id, e.target.value)} placeholder="Type category name…" className="h-8 text-sm" autoFocus /> ) : ( )}
handleToggle(cat.id, "requiredMain")} size="sm" />
handleToggle(cat.id, "requiredCo")} size="sm" />
))}
)} {/* Add Category */}
{/* ── Footer ── */}
{onCancel && ( )}
); }