"use client"; /** * FooterAggregateModal — 테이블 푸터 집계 설정 모달 * * design-system.md Shell 패턴 적용. * 특정 열을 클릭하면 열리며, 해당 열의 집계 유형(합계/평균/개수/수식)을 설정. */ import React, { useState, useEffect, useCallback, useRef } from "react"; import { Dialog, DialogContent, DialogTitle, DialogDescription } from "@/components/ui/dialog"; import { Button } from "@/components/ui/button"; import { useUnsavedChangesGuard, UnsavedChangesDialog } from "@/components/common/UnsavedChangesGuard"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"; import { Calculator, X } from "lucide-react"; import type { ComponentConfig } from "@/types/report"; type TableColumn = NonNullable[number]; interface FooterAggregateModalProps { open: boolean; onOpenChange: (open: boolean) => void; column: TableColumn | null; columnIndex: number; onSave: (idx: number, updates: Partial) => void; } export function FooterAggregateModal({ open, onOpenChange, column, columnIndex, onSave }: FooterAggregateModalProps) { const [summaryType, setSummaryType] = useState<"SUM" | "AVG" | "COUNT" | "NONE">("NONE"); const [formula, setFormula] = useState(""); const initialSnapshotRef = useRef(""); const hasChanges = useCallback(() => { const current = JSON.stringify({ summaryType, formula }); return current !== initialSnapshotRef.current; }, [summaryType, formula]); const guard = useUnsavedChangesGuard({ hasChanges, onClose: () => onOpenChange(false), }); useEffect(() => { if (column) { const initType = column.summaryType || "NONE"; const initFormula = column.formula || ""; setSummaryType(initType); setFormula(initFormula); initialSnapshotRef.current = JSON.stringify({ summaryType: initType, formula: initFormula }); } }, [column]); const handleSave = () => { onSave(columnIndex, { summaryType, formula: summaryType === "NONE" ? undefined : formula || undefined, }); onOpenChange(false); }; if (!column) return null; return ( <> 계산 방식 설정 {column.field || column.header} 열의 계산 방식을 설정합니다 {/* Header */}

계산 방식 설정

{/* Content */}

{column.field || column.header} 열의 계산 방식을 설정합니다.

{summaryType !== "NONE" && (
setFormula(e.target.value)} placeholder="예: {price} * {qty}" className="h-9 font-mono text-sm" />

비워두면 기본 계산이 적용됩니다.

)}
{/* Footer */}
); }