/* Chandrahasa — live catalogue card renderer. Values are escaped before insertion. */ 'use strict'; CH.escapeHTML = CH.escapeHTML || function escapeHTML(value) { return String(value ?? '').replace(/[&<>"']/g, ch => ({'&':'&','<':'<','>':'>','"':'"',"'":'''}[ch])); }; CH.productCardHTML = function productCardHTML(p) { const esc = CH.escapeHTML; const img = p.images && p.images[0] ? p.images[0] : ''; const image = img ? `${esc(p.name)}` : ``; const discount = p.compare_price && p.compare_price > p.price ? Math.round((1 - p.price / p.compare_price) * 100) : 0; const badge = p.badge ? `${esc(p.badge)}` : ''; const compare = discount ? `${CH.money(p.compare_price)}${discount}% off` : ''; const hasReviews = Number(p.review_count) > 0 && Number.isFinite(Number(p.rating)); const rating = hasReviews ? `
${'★'.repeat(Math.max(0,Math.min(5,Math.round(Number(p.rating)))))}${Number(p.rating).toFixed(1)} · ${Number(p.review_count).toLocaleString('en-IN')} reviews
` : ''; const maker = p.artisan ? `${esc(p.artisan)}` : ''; const huid = p.huid ? `
HUID ${esc(p.huid)}
` : ''; return `
${image}${badge}
${maker}

${esc(p.name)}

${rating}
${CH.money(p.price)}${compare}
${huid}
`; }; CH.renderProductGrid = function renderProductGrid(selector, items) { const grid = CH.$(selector); if (!grid) return; if (!items || !items.length) { grid.innerHTML = '
No products are available in this collection right now.
'; return; } grid.innerHTML = items.map(CH.productCardHTML).join(''); }; CH.skeletonGrid = function skeletonGrid(selector, n = 4) { const grid = CH.$(selector); if (!grid) return; grid.innerHTML = Array.from({length:n},()=>'').join(''); };