/** * ListingTemplateCard Component * * Summary card component for displaying a single listing template. * Shows template overview with listing type, slot count, structure info, and item actions. * * Features: * - Listing type display with formatted label * - Item selector (primary) with code styling * - Structure metadata (layout, itemsPerRow) * - Slot badges (max 5 visible with overflow indicator) * - Action badges for item actions * - Clickable card with hover effect * * @layer Presentation */ import * as React from 'react'; import { ListingTemplate } from '@archer/domain'; import { Badge } from '@/components/ui/badge'; import { cn } from '@/lib/utils'; import { formatListingType, formatDataRole, formatActionType } from '@/lib/pattern-format-utils'; export interface ListingTemplateCardProps { template: ListingTemplate; onClick?: () => void; className?: string; } export const ListingTemplateCard = React.forwardRef( ({ template, onClick, className }, ref) => { // Convert slots Record to array for rendering const slotsArray = Object.entries(template.slots).map(([key, slot]) => ({ key, ...slot, })); const slotCount = slotsArray.length; const visibleSlots = slotsArray.slice(0, 5); const remainingSlots = slotCount - 5; return (
{ if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); onClick?.(); } }} aria-label={`View details for ${formatListingType(template.listingType)} template`} > {/* Header: Listing Type + Slot Count */}

{formatListingType(template.listingType)}

{slotCount} slot{slotCount !== 1 ? 's' : ''}
{/* Metadata: Item Selector + Structure */}
Item Selector: {template.itemSelector.primary}
{template.structure && (
Layout: {template.structure.layout} {template.structure.itemsPerRow && ( ({template.structure.itemsPerRow} per row) )}
)}
{/* Slots: Show first 5 with overflow indicator */}
{visibleSlots.map((slot) => ( {formatDataRole(slot.role)} ))} {remainingSlots > 0 && ( +{remainingSlots} more )}
{/* Actions: Show all item actions */} {template.itemActions && template.itemActions.length > 0 && (
Actions:
{template.itemActions.map((action, idx) => ( {formatActionType(action.actionType)} ))}
)}
); } ); ListingTemplateCard.displayName = 'ListingTemplateCard';