/* Componentes compartilhados — Login, Sidebar, Topbar, widgets */
const { useState:uS, useEffect:uE, useRef:uR } = React;
/* ---------------- LOGIN ---------------- */
function Login({onLogin}){
const [perfil,setPerfil]=uS('ceo');
const [show,setShow]=uS(false);
const [remember,setRemember]=uS(true);
const [email,setEmail]=uS('jean.barbosa@maximiano.adv.br');
const [pwd,setPwd]=uS('••••••••••');
const [loading,setLoading]=uS(false);
const sel=MX.perfis.find(p=>p.id===perfil);
uE(()=>{
const map={ceo:'jean.barbosa',gestor:'joao.mendes',adv:'jackeline.batista',admin:'rodrigo'};
setEmail(map[perfil]+'@maximiano.adv.br');
},[perfil]);
const submit=(e)=>{ e.preventDefault(); setLoading(true); setTimeout(()=>onLogin(perfil),650); };
return (
>
);
}
/* ---------------- TOPBAR ---------------- */
function Topbar({title,crumb,profile,onSwitch,right,onMenuOpen}){
const [menu,setMenu]=uS(null); // 'profile' | 'notif' | null
const ref=uR(null);
uE(()=>{
const h=e=>{ if(ref.current && !ref.current.contains(e.target)) setMenu(null); };
document.addEventListener('mousedown',h); return ()=>document.removeEventListener('mousedown',h);
},[]);
const [notifs,setNotifs]=uS(MX.notifications);
const unread=notifs.filter(n=>n.unread).length;
const notifColors={gold:['#f5edde','#9a743b'],green:['#e7f0ea','#3f7a57'],red:['#f3e6e3','#a8554a'],navy:['#eef0f4','#3a4159']};
return (
{right}
{menu==='notif' && (
Notificações
{notifs.map(n=>{
const[bg,fg]=notifColors[n.cor];
return (
setNotifs(notifs.map(x=>x.id===n.id?{...x,unread:false}:x))}>
{n.titulo}
{n.msg}
{n.tempo}
{n.unread &&
}
);
})}
)}
{menu==='profile' && (
Trocar de perfil (demo)
{MX.perfis.map(p=>(
))}
)}
);
}
/* ---------------- WIDGETS ---------------- */
function KPI({label,icon,value,delta,deltaLabel,spark,sparkColor}){
return (
{label}
{value}
{delta!=null && =0?'up':'down')}>
=0?'arrowUp':'arrowDown'} size={12} stroke={2.5}/>{Math.abs(delta).toLocaleString('pt-BR',{minimumFractionDigits:1,maximumFractionDigits:1})}%
}
{deltaLabel}
{spark &&
}
);
}
function Modal({title,onClose,children,foot}){
return (
{if(e.target===e.currentTarget)onClose();}}>
{title}
{children}
{foot &&
{foot}
}
);
}
Object.assign(window,{ Login, Sidebar, Topbar, KPI, Modal });