// Preview SVG del pastel — pisos apilables con colores dinámicos const { useMemo } = React; function CakePreview({ tiers }) { // tiers: array de { flavorColor, color (hex), tierType } // Piso 1 = base (más grande), piso N = arriba (más chico) const data = useMemo(() => { const n = tiers.length; if (n === 0) return []; // Width scaling: base piso width depends on n; smaller cakes are narrower const baseMax = 280; const maxW = n === 1 ? 180 : Math.min(baseMax, 140 + n * 24); const minW = Math.max(70, maxW - 50 - (n - 1) * 14); const widthStep = n === 1 ? 0 : (maxW - minW) / (n - 1); const baseH = 70; const heightStep = 5; return tiers.map((t, i) => { const w = maxW - i * widthStep; let h = baseH - i * heightStep; if (t.tierType === "doble") h = h * 1.55; if (t.tierType === "extendido") h = h * 1.25; const fillRaw = t.color || "#F8EFD9"; // Si el color es muy claro (cerca de blanco), usar contorno fuerte return { w, h, flavorColor: t.flavorColor || "#F4E4BC", color: fillRaw, }; }); }, [tiers]); const totalH = data.reduce((s, d) => s + d.h + 4, 0) + 40; const cx = 175; let yCursor = totalH - 24; const vbH = Math.max(totalH + 20, 280); return ( {/* sombra suelo */} {/* plato */} {/* pisos: stack desde abajo */} {data.map((d, i) => { const y = yCursor - d.h - 4; yCursor = y; const x = cx - d.w / 2; const ry = 4; return ( {/* sombra lateral */} {/* highlight superior */} {/* sombra interior (banda de relleno = sabor del pan) */} {/* gotitas decorativas en la base del piso */} {(() => { const count = Math.max(4, Math.floor(d.w / 26)); return Array.from({ length: count }).map((_, k) => { const px = x + (k + 0.5) * (d.w / count); return ( ); }); })()} {/* etiqueta del piso */} {data.length - i} ); })} {/* coronita estilo logo en el último piso (arriba) */} {data.length > 0 && (() => { const topW = data[data.length - 1].w; const cy = yCursor - 10; const scale = topW < 110 ? 0.7 : 1; return ( ); })()} ); } window.CakePreview = CakePreview;