'use client'; import React from 'react'; import { Filament } from '@/src/types/filament'; interface FilamentRowProps { filament: Filament; } export function FilamentRow({ filament }: FilamentRowProps) { const hasRefill = filament.refill > 0; const hasSpool = filament.spulna > 0; // Parse prices from the cena field (format: "3499" or "3499/3999") let refillPrice = 3499; let spoolPrice = 3999; if (filament.cena) { const prices = filament.cena.split('/'); if (prices.length === 1) { refillPrice = parseInt(prices[0]) || 3499; spoolPrice = parseInt(prices[0]) || 3999; } else if (prices.length === 2) { refillPrice = parseInt(prices[0]) || 3499; spoolPrice = parseInt(prices[1]) || 3999; } } const saleActive = filament.sale_active && filament.sale_percentage; const saleRefillPrice = saleActive ? Math.round(refillPrice * (1 - filament.sale_percentage! / 100)) : refillPrice; const saleSpoolPrice = saleActive ? Math.round(spoolPrice * (1 - filament.sale_percentage! / 100)) : spoolPrice; return ( {filament.tip} {filament.finish}
{filament.boja_hex && (
)} {filament.boja}
{hasRefill ? ( {filament.refill} ) : ( 0 )} {hasSpool ? ( {filament.spulna} ) : ( 0 )} {filament.kolicina} {!hasRefill && !hasSpool ? ( '-' ) : ( <> {hasRefill && ( {refillPrice.toLocaleString('sr-RS')} )} {hasRefill && saleActive && ( {saleRefillPrice.toLocaleString('sr-RS')} )} {hasRefill && hasSpool && /} {hasSpool && ( {spoolPrice.toLocaleString('sr-RS')} )} {hasSpool && saleActive && ( {saleSpoolPrice.toLocaleString('sr-RS')} )} RSD {saleActive && ( -{filament.sale_percentage}% )} )} ); }