// Shared UI primitives for Regula // ───────────────────────────── Icons (minimal, 1.5px) const Icon = ({ name, size = 14 }) => { const paths = { home: <>, building: <>, chat: <>, book: <>, search: <>, settings: <>, plus: <>, arrow: <>, up: <>, down: <>, clock: <>, file: <>, upload: <>, send: <>, sparkle: <>, download: <>, filter: <>, more: <>, close: <>, bell: <>, check: <>, edit: <>, expand: <>, drag: <> }; return ( {paths[name]} ); }; // ───────────────────────────── Sparkline const Sparkline = ({ data, w = 84, h = 28, color = 'var(--ink)', fill = false }) => { const min = Math.min(...data), max = Math.max(...data); const range = max - min || 1; const step = w / (data.length - 1); const pts = data.map((v, i) => [i * step, h - ((v - min) / range) * (h - 4) - 2]); const d = pts.map((p, i) => (i === 0 ? 'M' : 'L') + p[0].toFixed(1) + ',' + p[1].toFixed(1)).join(' '); const areaD = d + ` L${w},${h} L0,${h} Z`; return ( {fill && } ); }; // ───────────────────────────── Delta const Delta = ({ value, abs, invert = false }) => { const positive = invert ? value < 0 : value > 0; const negative = invert ? value > 0 : value < 0; const cls = positive ? 'up' : negative ? 'down' : 'flat'; const arrow = positive ? '↑' : negative ? '↓' : '·'; return ( {arrow} {value > 0 ? '+' : ''}{value.toFixed(1)}% {abs && {abs}} ); }; // ───────────────────────────── Sidebar const Sidebar = ({ page, setPage, activeCompanyId, setActiveCompanyId }) => { const { companies } = window.REGULA_DATA; const sections = [ { id: 'dashboard', label: 'Cockpit', icon: 'home' }, { id: 'detail', label: 'Società', icon: 'building', count: companies.length }, { id: 'tesoreria', label: 'Tesoreria', icon: 'clock' }, { id: 'forecasting', label: 'Forecasting', icon: 'up' }, { id: 'investimenti', label: 'Investimenti', icon: 'book' }, { id: 'allocazione', label: 'Allocazione Capitali', icon: 'arrow' }, { id: 'assistant', label: 'AI Assistant', icon: 'sparkle' }, { id: 'kb', label: 'Knowledge Base', icon: 'file', count: 124 } ]; return ( ); }; // ───────────────────────────── Horizon switch (global) const HorizonSwitch = ({ horizon, setHorizon }) => { const opts = [ { id: 'operativo', label: 'Operativo', sub: 'settimana · mese' }, { id: 'tattico', label: 'Tattico', sub: 'trimestre · anno' }, { id: 'strategico', label: 'Strategico', sub: '3–5 anni' } ]; return (
{opts.map(o => ( ))}
); }; // ───────────────────────────── Topbar const Topbar = ({ crumbs, meta, horizon, setHorizon }) => (
{crumbs.map((c, i) => ( {i > 0 && /} {c} ))}
{horizon !== undefined && } {meta}
Cerca ⌘K
); // ───────────────────────────── Integrations footer const IntegrationsBar = () => { const items = window.REGULA_EXT?.integrations || []; return (
Integrazioni {items.map((it, i) => (
{it.mark}
{it.name} {it.lastSync}
))}
); }; Object.assign(window, { Icon, Sparkline, Delta, Sidebar, Topbar, HorizonSwitch, IntegrationsBar });