import type { Component } from 'solid-js'; import { For, createMemo, Show, createSignal } from 'solid-js'; import { Trash2, ChevronDown, Copy, ListTree } from 'lucide-solid'; import type { EstimateItem, SubScope, Scope } from '../types'; import ItemRow from './ItemRow'; import LazyItem from './LazyItem'; interface SubScopeCardProps { subScope: SubScope; items: EstimateItem[]; onUpdateSubScope: (id: string, updates: Partial) => void; onUpdateItem: (id: string, updates: Partial) => void; onDeleteItem: (id: string) => void; onDeleteSubScope: (id: string) => void; onDragStart: (e: DragEvent, id: string) => void; onDrop: (e: DragEvent, scopeId: string, subScopeId: string) => void; onDuplicateItem: (id: string) => void; allScopes: Scope[]; allSubScopes: SubScope[]; onCopySubScopeItems: (sourceSubScopeId: string, targetSubScopeId: string) => void; isSidebarCollapsed: () => boolean; selectedIds: string[]; onToggleSelection: (id: string, isMulti: boolean, isShift: boolean) => void; onClearSelection: () => void; hideColumns?: boolean; } const SubScopeCard: Component = (props) => { const [isCollapsed, setIsCollapsed] = createSignal(false); const [isOver, setIsOver] = createSignal(false); const [showCopyMenu, setShowCopyMenu] = createSignal(false); const totals = createMemo(() => { return props.items.reduce((acc, item) => { const base = item.quantity * item.unitPrice; const markup = item.markupType === 'percent' ? base * (item.markup / 100) : item.markup; const contingency = item.contingencyType === 'percent' ? base * (item.contingency / 100) : item.contingency; return { amount: acc.amount + base + markup + contingency, quantity: acc.quantity + item.quantity }; }, { amount: 0, quantity: 0 }); }); const formatNumber = (num: number) => { return num.toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 2 }); }; const formatQuantity = (num: number) => { return num.toLocaleString(undefined, { minimumFractionDigits: 0, maximumFractionDigits: 2 }); }; const handleDragOver = (e: DragEvent) => { e.preventDefault(); e.stopPropagation(); setIsOver(true); }; const handleDragLeave = () => { setIsOver(false); }; const handleDrop = (e: DragEvent) => { e.preventDefault(); e.stopPropagation(); setIsOver(false); props.onDrop(e, props.subScope.scopeId, props.subScope.id); }; return (
props.onUpdateSubScope(props.subScope.id, { name: e.currentTarget.value })} class="bg-transparent border-none outline-none font-black text-foreground text-sm focus:ring-0 w-48" />
{props.items.length} Items {formatQuantity(totals().quantity)} Qty ${formatNumber(totals().amount)}
Select Target Sub-scope
{(scope) => (
{scope.name}
ss.scopeId === scope.id && ss.id !== props.subScope.id)}> {(targetSS) => ( )}
)}
{ if (e.target === e.currentTarget) props.onClearSelection(); }} class="p-2 space-y-1.5" > {(item) => ( 0} onToggleSelection={props.onToggleSelection} hideColumns={props.hideColumns} /> )}
Empty Sub-scope
); }; export default SubScopeCard;