import { type ReactElement } from "react"; import { Layers } from "lucide-react"; import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { Card, CardContent, CardDescription, CardFooter, CardTitle, } from "@/components/ui/card"; import { Separator } from "@/components/ui/separator"; import { cn } from "@/lib/utils"; import { formatDateShort } from "@/lib/format-date"; // --------------------------------------------------------------------------- // Types // --------------------------------------------------------------------------- /** Visibility group a template belongs to. */ export type TemplateScope = "private" | "company" | "wealthx"; export interface TemplateCardProps { name: string; description?: string; /** Column blueprint — only the names are needed for the preview strip. */ columns: { name: string }[]; scope: TemplateScope; /** Admin-pinned official template — shows a star marker. */ isOfficial?: boolean; creator: { name: string; avatarUrl?: string }; /** How many boards were created from this template. */ usageCount: number; /** ISO date of the last edit. */ updatedAt: string; /** Highlights the card (e.g. picked in the create-from-template gallery). */ selected?: boolean; /** Click the card body — open detail or pick in a gallery. */ onSelect?: () => void; /** Primary CTA — create a board from this template. Hidden when omitted. */ onUse?: () => void; className?: string; } // --------------------------------------------------------------------------- // Helpers // --------------------------------------------------------------------------- const getInitials = (name: string): string => name .split(" ") .map((part) => part[0]) .filter(Boolean) .slice(0, 2) .join("") .toUpperCase(); // --------------------------------------------------------------------------- // Component // --------------------------------------------------------------------------- /** * A single Kanban template tile. Used in the Create-from-Template gallery and * the Template Library page. Shows the column structure preview, creator and * usage so an advisor can pick the right starting point. */ export function TemplateCard({ name, description, columns, isOfficial = false, creator, usageCount, updatedAt, selected = false, onSelect, onUse, className, }: TemplateCardProps): ReactElement { const isInteractive = Boolean(onSelect); return ( { if (e.key === "Enter" || e.key === " ") { e.preventDefault(); onSelect?.(); } } : undefined } > {/* Title + badges */}
{name}
{isOfficial && Official} {columns.length} columns
{description && ( {description} )} {/* Column structure preview */}
{columns.map((col, i) => ( {col.name} ))}
{/* Footer: creator + usage + optional CTA */}
{creator.avatarUrl && ( )} {getInitials(creator.name)}
{creator.name} {usageCount.toLocaleString()} uses · {formatDateShort(updatedAt)}
{onUse && ( )}
); }