import{a as e,n as t,t as n}from"./jsx-runtime-B-hcVAMW.js";import{t as r}from"./Badge-BGqYAYKM.js";import{t as i}from"./EmptyState-BCP63FMk.js";var a=e(t(),1),o={profile:`neutral`,status:`info`,assignment:`info`,document:`info`,payment:`success`,invoice:`success`,commission:`success`,processing:`info`,task:`neutral`,communication:`neutral`,note:`neutral`,accounting:`success`,payroll:`success`,recruitment:`info`,security:`danger`,system:`neutral`};function s(e){let t=new Date().toDateString(),n=new Date(Date.now()-864e5).toDateString(),r=new Map;for(let i of e){let e=i.created_at?new Date(i.created_at):null,a=e?e.toDateString()===t?`Today`:e.toDateString()===n?`Yesterday`:e.toLocaleDateString(void 0,{day:`numeric`,month:`long`,year:`numeric`}):`Unknown date`;r.set(a,[...r.get(a)??[],i])}return[...r.entries()].map(([e,t])=>({label:e,entries:t}))}var c=n();function l({activities:e}){return e.length===0?(0,c.jsx)(i,{title:`Nothing has happened yet`,description:`Actions on this record will appear here as they happen.`}):(0,c.jsx)(`div`,{className:`space-y-8`,children:s(e).map(e=>(0,c.jsxs)(`section`,{children:[(0,c.jsx)(`h3`,{className:`text-xs font-semibold uppercase tracking-wide text-slate-500`,children:e.label}),(0,c.jsx)(`ol`,{className:`mt-3 space-y-3`,children:e.entries.map(e=>(0,c.jsx)(u,{activity:e},e.id))})]},e.label))})}function u({activity:e}){let[t,n]=(0,a.useState)(!1),i=(e.changes?.length??0)>0,s=e.metadata?.reason,l=e.created_at?new Date(e.created_at).toLocaleTimeString(void 0,{hour:`numeric`,minute:`2-digit`}):`—`;return(0,c.jsxs)(`li`,{className:`rounded-xl border border-slate-200 bg-white p-4`,children:[(0,c.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[(0,c.jsxs)(`div`,{className:`min-w-0`,children:[(0,c.jsx)(`p`,{className:`text-sm font-medium text-slate-900`,children:e.title}),e.description&&(0,c.jsx)(`p`,{className:`mt-0.5 text-sm text-slate-600`,children:e.description}),(0,c.jsxs)(`p`,{className:`mt-1 text-xs text-slate-500`,children:[l,` · `,e.actor,e.actor_role?` (${e.actor_role.replace(/-/g,` `)})`:``]})]}),(0,c.jsx)(r,{tone:o[e.category],children:e.category_label})]}),s&&(0,c.jsxs)(`p`,{className:`mt-2 rounded-lg bg-slate-50 p-2 text-xs text-slate-700`,children:[(0,c.jsx)(`span`,{className:`font-medium`,children:`Reason:`}),` `,s]}),!!e.metadata?.overridden&&(0,c.jsx)(`p`,{className:`mt-2 rounded-lg bg-amber-50 p-2 text-xs text-amber-900`,children:`Requirements were overridden for this change.`}),i&&(0,c.jsxs)(`div`,{className:`mt-3`,children:[(0,c.jsx)(`button`,{type:`button`,onClick:()=>n(e=>!e),"aria-expanded":t,className:`text-xs font-medium text-brand-700 underline underline-offset-4`,children:t?`Hide detail`:`Show what changed`}),t&&(0,c.jsxs)(`dl`,{className:`mt-2 space-y-1.5 rounded-lg bg-slate-50 p-3`,children:[e.changes.map(e=>(0,c.jsxs)(`div`,{className:`text-xs`,children:[(0,c.jsx)(`dt`,{className:`font-medium text-slate-700`,children:e.label}),(0,c.jsxs)(`dd`,{className:`text-slate-600`,children:[(0,c.jsx)(`span`,{className:`text-slate-500`,children:`Before:`}),` `,d(e.before),(0,c.jsx)(`br`,{}),(0,c.jsx)(`span`,{className:`text-slate-500`,children:`After:`}),` `,d(e.after)]})]},e.field)),e.ip_address&&(0,c.jsxs)(`p`,{className:`pt-1 font-mono text-[11px] text-slate-400`,children:[e.ip_address,e.request_id?` · ${e.request_id.slice(0,8)}`:``]})]})]})]})}function d(e){return e==null||e===``?`empty`:typeof e==`boolean`?e?`yes`:`no`:typeof e==`object`?`updated`:String(e)}export{l as t};