/* =========================================================== Forja 3D — Calculadora de Precificação =========================================================== */ function Calculator({ go }) { const s = useStore(); const st = s.settings; const fils = s.filaments; const [name, setName] = useState(''); const [filId, setFilId] = useState(fils[0]?.id || 'custom'); const [customKg, setCustomKg] = useState(100); const [grams, setGrams] = useState(80); const [hours, setHours] = useState(4); const [mins, setMins] = useState(0); const [packaging, setPackaging] = useState(st.defaultPackaging); const [extra, setExtra] = useState(0); const [fail, setFail] = useState(st.failRate); const [margin, setMargin] = useState(st.defaultMargin); const [fee, setFee] = useState(st.marketplaceFee); const [saved, setSaved] = useState(false); const fil = fils.find((f) => f.id === filId); const costPerKg = filId === 'custom' ? customKg : (fil?.costPerKg || 0); const printTimeMin = (Number(hours) || 0) * 60 + (Number(mins) || 0); const c = computeCost({ grams: Number(grams) || 0, costPerKg, printTimeMin, packaging: Number(packaging) || 0, margin: Number(margin) || 0, failRate: Number(fail) || 0, marketplaceFee: Number(fee) || 0, extraCost: Number(extra) || 0 }, st); const parts = [ { k: 'Filamento', v: c.filament, color: 'var(--orange)' }, { k: 'Energia', v: c.energy, color: '#e0a73b' }, { k: 'Mão de obra', v: c.labor, color: '#5aa9e0' }, { k: 'Depreciação', v: c.depreciation, color: '#9b7ce0' }, { k: 'Embalagem', v: c.packaging, color: '#3ec06b' }, ...(c.extraCost > 0 ? [{ k: 'Custo extra', v: c.extraCost, color: '#8a827a' }] : []), ]; const feeChannels = [ { label: 'Shopee', v: 14 }, { label: 'Mercado Livre', v: 16 }, { label: 'Elo7', v: 12 }, { label: 'Venda direta', v: 0 }, ]; function saveToCatalog() { store.addProduct({ name: name || 'Item sem nome', filamentId: filId === 'custom' ? null : filId, weightG: Number(grams) || 0, printTimeMin, price: Math.round(c.finalPrice * 100) / 100, color: fil?.color || 'var(--orange)' }); setSaved(true); setTimeout(() => setSaved(false), 2200); } return (