import { motion } from 'motion/react'; import { useParams, useNavigate } from 'react-router'; import { TrendingUp, ArrowUpRight, Download, Loader2, FileText, FileSpreadsheet, ChevronDown } from 'lucide-react'; import { SectionWrapper } from './ui/SectionWrapper'; import { DropdownMenu, DropdownMenuTrigger, DropdownMenuContent, DropdownMenuItem, } from '@/shared/ui/dropdown-menu'; import { useExportPDF } from '@/features/report/hooks/useExportPDF'; import { useExportCSV } from '@/features/report/hooks/useExportCSV'; import type { KPIMetric, MarketingReport } from '@/features/report/types/report'; interface KPIDashboardProps { metrics: KPIMetric[]; clinicName?: string; /** 전체 리포트 — CSV 내보내기에 사용 */ report?: MarketingReport; } function isNegativeValue(value: string | number): boolean { const lower = String(value).toLowerCase(); return lower === '0' || lower.includes('없음') || lower.includes('불가') || lower === 'n/a' || lower === '-' || lower.includes('측정 불가'); } /** 가독성을 위해 큰 숫자 포맷팅: 150000 → 150K, 1500000 → 1.5M */ function formatKpiValue(value: string | number): string { const str = String(value ?? ''); // 이미 포맷된 경우(K, M, %, ~, 월, 건 등 포함) 그대로 반환 if (/[KkMm%~월건회개명/]/.test(str)) return str; // 순수 숫자로 파싱 시도 const num = parseInt(str.replace(/,/g, ''), 10); if (isNaN(num)) return str; if (num >= 1_000_000) return `${(num / 1_000_000).toFixed(1)}M`; if (num >= 10_000) return `${Math.round(num / 1_000)}K`; if (num >= 1_000) return `${(num / 1_000).toFixed(1)}K`; return str; } export default function KPIDashboard({ metrics, clinicName, report }: KPIDashboardProps) { const { id } = useParams<{ id: string }>(); const navigate = useNavigate(); const { exportPDF, isExporting } = useExportPDF(); const { exportReportCSV } = useExportCSV(); const baseFilename = `INFINITH_Marketing_Report_${clinicName || 'Report'}`; return ( {/* KPI Table */} {/* Header */}
Metric
Current
3-Month Target
12-Month Target
{/* Data rows */} {metrics.map((metric, i) => (
{metric.metric}
{formatKpiValue(metric.current)}
{formatKpiValue(metric.target3Month)}
{formatKpiValue(metric.target12Month)}
))}
{/* CTA Card */}

Start Your Transformation

INFINITH와 함께 데이터 기반 마케팅 전환을 시작하세요. 90일 안에 측정 가능한 성과를 만들어 드립니다.

exportPDF(baseFilename)}> PDF로 저장 report && exportReportCSV(baseFilename, report)} > CSV로 저장
); }