/* global React */ /* Header PARTAGÉ du portail revendeur French Kits (barre pro + marque + nav + compte/panier + burger mobile). Self-contained : lit window.NAV_TABS / window.CLIENT / window.EXTRANET_CONFIG / window.PORTAIL_CONFIG / window.EcUI. Props: orderUnits (badge panier). Définit un EcHeader global réutilisable. */ function EcHeader({ orderUnits }) { const cfg = window.EXTRANET_CONFIG || {}; const pc = window.PORTAIL_CONFIG || {}; const base = cfg.base_url || ''; const client = window.CLIENT; const isLogged = !!(client && client.nom); const navTabs = window.NAV_TABS || []; // Badge panier : compteur serveur, resynchronisé sur l'événement 'ec-cart-changed' (cohérent sur toutes les pages) const [units, setUnits] = React.useState(orderUnits || 0); React.useEffect(() => { if (!isLogged) { setUnits(0); return; } const load = () => fetch(base + '/panier', { credentials: 'same-origin' }).then(r => r.json()).then(d => setUnits(parseInt(d.nb_articles, 10) || 0)).catch(() => {}); load(); window.addEventListener('ec-cart-changed', load); return () => window.removeEventListener('ec-cart-changed', load); }, [isLogged, base]); const T = (window.EcUI && window.EcUI.T) || {}; const INK = T.ink || 'oklch(0.255 0.016 48)'; const PRIMARY = T.primary || 'oklch(0.62 0.14 40)'; const PROBAR = T.probar || 'oklch(0.5 0.12 38)'; const CORAL = T.coral || 'oklch(0.575 0.125 42)'; const CREAM = T.cream || 'oklch(0.945 0.016 82)'; const GREY = T.mute || 'oklch(0.55 0.012 65)'; const ONBAR = T.onbar || 'oklch(0.95 0.03 65)'; const SERIF = T.serif || "'Playfair Display',serif"; const marque = pc.marque || 'French Kits'; const accent = pc.marque_accent || 'Kits'; const marquePrefix = accent && marque.indexOf(accent) === 0 ? '' : (marque.split(accent)[0] || ''); const societe = pc.societe || 'Émotions Créatives'; const badge = pc.badge || 'PORTAIL REVENDEUR'; const logo = pc.logo || ''; const baseline = pc.header_baseline || ('par ' + societe); const barreLabel = pc.barre_label || 'ESPACE REVENDEUR PROFESSIONNEL'; const reassurances = (pc.reassurances && pc.reassurances.length) ? pc.reassurances : ['Tarifs HT réservés aux professionnels', 'Fabriqué en France 🇫🇷']; const [open, setOpen] = React.useState(false); // menu compte const [menu, setMenu] = React.useState(false); // menu burger mobile const [cartOpen, setCartOpen] = React.useState(false); // cart drawer React.useEffect(() => { if (!open) return; const h = (e) => { if (!e.target.closest('.ec-chip-wrap')) setOpen(false); }; document.addEventListener('click', h); return () => document.removeEventListener('click', h); }, [open]); return ( {/* ===== Barre utilitaire pro (terracotta) ===== */}
{barreLabel} {reassurances.map((r, i) => ( {i > 0 && ·} {r} ))}
{/* ===== Header sticky ===== */}
{/* Marque : logo image (ou lockup texte si pas de logo) + baseline société */} {logo ? {marque} : {marquePrefix}{accent}®} {baseline} {/* Nav (slide-in en mobile) */} {/* Zone droite */}
{isLogged ? (
{open && (
{[['Mon profil', base + '/mon-profil'], ['Mes adresses', base + '/mes-adresses'], ['Mes commandes', cfg.mes_commandes_url || (base + '/mes-commandes')]].map(([lbl, href], i) => ( {lbl} ))}
Se déconnecter
)}
) : ( Se connecter )}
{/* Backdrop menu mobile — DANS le header (même contexte d'empilement que le panneau de nav) */}
setMenu(false)}>
{/* Barre de chips raccourcis (sous le header) : New Printemps · New Été · Commander (sans Accueil) */}
{[{ slug: 'nouveautes-printemps', label: 'Printemps', neu: true }, { slug: 'nouveautes-ete', label: 'Été', neu: true }, { slug: 'commander', label: 'Commander', neu: false }].map((c) => { const t = navTabs.find(x => x.slug === c.slug); if (!t) return null; return ( {c.neu && New} {c.label} ); })}
{/* Cart drawer partagé */} {typeof EcCartDrawer !== 'undefined' && setCartOpen(false)} />}
); }