'use client'; import React, { useState } from 'react'; import { CalculationInput, CalculationResult, PaperType } from '@/types'; import { Copy, Printer, Save, Check, Layers, Sparkles, Scissors, TrendingUp, } from 'lucide-react'; interface CostBreakdownCardProps { input: CalculationInput; result: CalculationResult; paperType: PaperType; onOpenPrintModal: () => void; onSaveOrder: () => void; isSavingOrder?: boolean; } export const CostBreakdownCard: React.FC = ({ input, result, paperType, onOpenPrintModal, onSaveOrder, isSavingOrder = false, }) => { const [copied, setCopied] = useState(false); const { costs, quantities, chosenTech, imposition } = result; const handleCopyZalo = () => { const text = `📢 BÁO GIÁ IN ẤN - ${input.jobName} • Kích thước: ${input.widthMm} x ${input.heightMm} mm • Số lượng: ${input.quantity.toLocaleString('vi-VN')} chiếc • Chất liệu: ${paperType.name} • Công nghệ: ${chosenTech === 'offset' ? 'In Offset' : 'In Nhanh KTS'} (${input.printSides === '2_side' ? '2 mặt' : '1 mặt'}) ${costs.finishingDetails.length > 0 ? `• Gia công: ${costs.finishingDetails.map((f) => f.name).join(', ')}\n` : ''}👉 TỔNG TIỀN: ${costs.finalPrice.toLocaleString('vi-VN')} VNĐ (${costs.unitPrice.toLocaleString('vi-VN')}đ/c)`; navigator.clipboard.writeText(text); setCopied(true); setTimeout(() => setCopied(false), 2000); }; // Tính tỷ lệ % thành phần chi phí để vẽ thanh tiến trình const totalBase = Math.max(1, costs.totalBaseCost); const paperPct = Math.round((costs.paperCost / totalBase) * 100); const printPct = Math.round((costs.totalPrintCost / totalBase) * 100); const finishPct = Math.max(0, 100 - paperPct - printPct); return (
{/* Hero Header */}
Tổng Báo Giá {chosenTech === 'offset' ? 'Máy In Offset' : 'In Nhanh KTS'}
{costs.finalPrice.toLocaleString('vi-VN')} VNĐ
Đơn giá: {costs.unitPrice.toLocaleString('vi-VN')}đ / chiếc SL: {quantities.productQty.toLocaleString('vi-VN')}
{/* Thanh cơ cấu chi phí (Breakdown progress bar) */}
Cơ cấu chi phí sản xuất: {costs.totalBaseCost.toLocaleString('vi-VN')}đ
Giấy ({paperPct}%) In ấn ({printPct}%) Gia công ({finishPct}%)
{/* Danh sách chi tiết vắn tắt */}
{chosenTech === 'digital' && costs.digitalDetails?.mode === 'with_paper' ? `Phôi giấy INTC (${quantities.totalPrintSheets} tờ):` : `Tiền giấy (${quantities.parentSheetsNeeded} tờ mẹ):`} {costs.paperCost === 0 && costs.digitalDetails?.mode === 'with_paper' ? ( Đã gồm trong giá in ) : costs.paperCost === 0 && input.customerSuppliedPaper ? ( Khách tự cấp giấy ) : ( `${costs.paperCost.toLocaleString('vi-VN')}đ` )}
{chosenTech === 'offset' ? `Tiền in ${costs.plateCost === 0 ? '(Gói trọn gồm kẽm)' : `(${costs.platesCount} kẽm + công)`}:` : `Tiền in (${quantities.totalPrintSheets} tờ, Không bù hao):`} {costs.totalPrintCost.toLocaleString('vi-VN')}đ
{chosenTech === 'digital' && costs.digitalDetails && (
{costs.digitalDetails.mode === 'with_paper' ? '📦 In kèm giấy (INTC 14.03)' : '⚙️ In gia công (Konica C12000)'} Khổ: {costs.digitalDetails.sheetSizeName || imposition.printSheet.name}
Đơn giá: {costs.digitalDetails.ratePerSheet.toLocaleString('vi-VN')}đ / tờ in ({quantities.totalPrintSheets} tờ) {costs.shortRunFee && costs.shortRunFee > 0 ? ( Phụ phí SL ít: +{costs.shortRunFee.toLocaleString('vi-VN')}đ ) : ( Miễn phụ phí )}
✓ In đúng {quantities.totalPrintSheets} tờ thực tế (Không bù hao)
)}
Gia công ({costs.finishingDetails.length} khâu): {costs.finishingCost.toLocaleString('vi-VN')}đ
Lợi nhuận gộp ({input.profitMarginPercent}%): +{costs.profitAmount.toLocaleString('vi-VN')}đ
{costs.vatAmount > 0 && (
Thuế VAT ({input.vatPercent}%): +{costs.vatAmount.toLocaleString('vi-VN')}đ
)}
{/* Hành động */}
); };