import{r as e}from"./rolldown-runtime-hePW80VL.js";import{n as t,t as n}from"./jsx-runtime-DE3RlOCf.js";import{s as r}from"./index-BY2WY3ZC.js";var i=e(t(),1),a=e(n(),1);function o(){let[e,t]=(0,i.useState)(``),[n,o]=(0,i.useState)([]),[s,c]=(0,i.useState)(!1),[l,u]=(0,i.useState)(null),[d,f]=(0,i.useState)(!1),p=(0,i.useCallback)(async()=>{if(e.trim()){c(!0),u(null),f(!0);try{let t=await r.getTransactionDetail({voucher_number:e.trim()});o(Array.isArray(t)?t:t.results??[])}catch(e){u(e instanceof Error?e.message:`Failed to load`)}finally{c(!1)}}},[e]);return(0,a.jsxs)(`div`,{className:`flex flex-col h-full p-4 gap-4`,children:[(0,a.jsxs)(`div`,{className:`flex items-center gap-1 text-sm border-b pb-2`,children:[(0,a.jsx)(`span`,{className:`text-muted-foreground`,children:`Audit`}),(0,a.jsx)(`span`,{className:`text-muted-foreground mx-1`,children:`/`}),(0,a.jsx)(`span`,{className:`font-semibold`,children:`Transaction Audit Detail`})]}),(0,a.jsxs)(`div`,{className:`flex gap-3 items-end p-4 bg-card border rounded-lg`,children:[(0,a.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,a.jsx)(`label`,{className:`text-xs font-medium text-muted-foreground`,children:`Voucher No. or Object Name`}),(0,a.jsx)(`input`,{type:`text`,className:`h-8 rounded border border-input bg-background px-2 text-sm w-64`,placeholder:`e.g. SI-2024-001 or ATEST1`,value:e,onChange:e=>t(e.target.value),onKeyDown:e=>e.key===`Enter`&&p()})]}),(0,a.jsx)(`button`,{className:`h-8 px-4 rounded bg-primary text-primary-foreground text-sm font-medium disabled:opacity-50`,onClick:p,disabled:s||!e.trim(),children:s?`Searching…`:`Search`})]}),l&&(0,a.jsx)(`div`,{className:`text-sm text-destructive bg-destructive/10 rounded p-3`,children:l}),d&&!s&&(0,a.jsx)(`div`,{className:`flex-1 overflow-auto`,children:(0,a.jsxs)(`table`,{className:`w-full text-xs border-collapse`,children:[(0,a.jsx)(`thead`,{className:`sticky top-0 z-10 bg-slate-700 text-white`,children:(0,a.jsx)(`tr`,{children:[`#`,`Timestamp`,`Username`,`Action`,`Voucher`,`Object`,`Field`,`Old Value`,`New Value`].map(e=>(0,a.jsx)(`th`,{className:`px-3 py-2 text-left border border-slate-600 whitespace-nowrap font-medium`,children:e},e))})}),(0,a.jsxs)(`tbody`,{children:[n.length===0&&(0,a.jsx)(`tr`,{children:(0,a.jsx)(`td`,{colSpan:9,className:`text-center py-8 text-muted-foreground`,children:`No field changes found for this voucher`})}),n.map((e,t)=>(0,a.jsxs)(`tr`,{className:t%2==0?`bg-white hover:bg-slate-50`:`bg-slate-50 hover:bg-slate-100`,children:[(0,a.jsx)(`td`,{className:`px-3 py-1.5 border border-slate-200 text-center text-muted-foreground`,children:e.sr_no}),(0,a.jsx)(`td`,{className:`px-3 py-1.5 border border-slate-200 whitespace-nowrap text-muted-foreground`,children:e.timestamp?.slice(0,19).replace(`T`,` `)}),(0,a.jsx)(`td`,{className:`px-3 py-1.5 border border-slate-200 font-medium`,children:e.username}),(0,a.jsx)(`td`,{className:`px-3 py-1.5 border border-slate-200`,children:(0,a.jsx)(`span`,{className:`px-1.5 py-0.5 rounded text-[10px] font-semibold ${e.action===`CREATE`?`bg-emerald-100 text-emerald-700`:e.action===`DELETE`?`bg-rose-100 text-rose-700`:e.action===`UPDATE`?`bg-amber-100 text-amber-700`:`bg-slate-100 text-slate-600`}`,children:e.action})}),(0,a.jsx)(`td`,{className:`px-3 py-1.5 border border-slate-200 font-mono`,children:e.voucher_number||`—`}),(0,a.jsx)(`td`,{className:`px-3 py-1.5 border border-slate-200 max-w-[150px] truncate`,children:e.object_repr}),(0,a.jsx)(`td`,{className:`px-3 py-1.5 border border-slate-200 font-medium`,children:e.field_name}),(0,a.jsx)(`td`,{className:`px-3 py-1.5 border border-slate-200 max-w-[150px] truncate`,children:(0,a.jsx)(`span`,{className:`line-through text-rose-600`,children:e.old_value||`—`})}),(0,a.jsx)(`td`,{className:`px-3 py-1.5 border border-slate-200 max-w-[150px] truncate`,children:(0,a.jsx)(`span`,{className:`text-emerald-700 font-medium`,children:e.new_value||`—`})})]},e.id))]})]})})]})}export{o as default};