1import{r as n,j as e}from"./vendor-DTJgL5bq.js";import{C as he,b as pe,c as xe,d as je,e as ge,L as T,I as F,B as C,h as R,g as fe}from"./index-hFQE3-fy.js";/* empty css */import"./flatpickr-C_UUl-Yg.js";import"./router-BvlDjZPB.js";const te="/api/dzo/admin/audit-logs/",Ne=t=>!!t&&typeof t=="object"&&Array.isArray(t.results)&&typeof t.count=="number",ve="Europe/Zagreb",ye=t=>{if(!t)return"-";const r=new Date(t);if(Number.isNaN(r.getTime()))return"-";const o=new Intl.DateTimeFormat("hr-HR",{timeZone:ve,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",hour12:!1}).formatToParts(r),c=D=>{var m;return((m=o.find(I=>I.type===D))==null?void 0:m.value)||""},a=c("day"),l=c("month"),v=c("year"),g=c("hour"),y=c("minute");return!a||!l||!v||!g||!y?"-":`${a}.${l}.${v} ${g}:${y}`},se=t=>{if(!t)return"";const r=new Date(t);return Number.isNaN(r.getTime())?"":r.toISOString()},be=t=>String(t||"").trim().toLowerCase(),re=t=>{if(t==null)return"-";if(typeof t=="string")return t;try{return JSON.stringify(t)}catch{return String(t)}},we=t=>{if(!t||typeof t!="object")return[];const r=t.changed_fields||t.changed||t.fields_changed,o=t.old_values||t.previous_values||{},c=t.new_values||t.values||{};return Array.isArray(r)&&r.length>0?r.filter(a=>typeof a=="string"&&a).map(a=>({field:a,oldValue:o[a],newValue:c[a]})):t.changes&&typeof t.changes=="object"?Object.entries(t.changes).map(([a,l])=>l&&typeof l=="object"?{field:a,oldValue:l.old,newValue:l.new}:{field:a,oldValue:void 0,newValue:l}):[]},ae=t=>{if(t===void 0)return"â";if(t===null)return"null";if(typeof t=="boolean")return t?"Da":"Ne";if(typeof t=="string"&&t.trim()==="")return"â";if(typeof t=="object")try{return JSON.stringify(t)}catch{return String(t)}return String(t)},Se=(t,r)=>{if(!r)return!0;const o=be(r);return[t.action,t.object_type,t.object_id,t.user_username||"",String(t.user??""),re(t.details)].join(" ").toLowerCase().includes(o)},ne=[25,50,100,250,500];function Ae(){const[t,r]=n.useState([]),[o,c]=n.useState(0),[a,l]=n.useState(!1),[v,g]=n.useState(null),[y,D]=n.useState(null),[m,I]=n.useState(""),[b,M]=n.useState(""),[w,H]=n.useState(""),[f,N]=n.useState(1),[h,U]=n.useState(50),[S,G]=n.useState("-created_at"),[J,A]=n.useState(!1),[ie,V]=n.useState(!1),[ce,q]=n.useState(new Set),k=n.useRef(null),P=async(s,u,i,x,z,$)=>{l(!0),g(null),D(null);try{const d={page:s,page_size:i,ordering:x},p=u.trim();p&&(d.search=p);const E=se(z),L=se($);E&&(d.created_from=E),L&&(d.created_to=L);const j=await fe(te,d);if(Ne(j)){r(j.results||[]),c(Number(j.count||0)),A(!!j.previous),V(!!j.next);return}if(Array.isArray(j)){const ue=j||[],K=E?new Date(E).getTime():null,Q=L?new Date(L).getTime():null,B=[...ue.filter(O=>{if(!Se(O,p))return!1;const _=new Date(O.created_at).getTime();return!(Number.isNaN(_)||K!=null&&_<K||Q!=null&&_>Q)})].sort((O,_)=>{const W=new Date(O.created_at).getTime(),X=new Date(_.created_at).getTime(),Y=Number.isNaN(W)?0:W,ee=Number.isNaN(X)?0:X;return x==="-created_at"?ee-Y:Y-ee}),Z=(s-1)*i,me=B.slice(Z,Z+i);r(me),c(B.length),A(s>1),V(Z+i<B.length),D("Backend vraca nepaginiran odgovor; prikaz je lokalno paginiran. Preporuka: deploy backend patch za pagination.");return}r([]),c(0),A(!1),V(!1),g("NeoÄekivan API odgovor za audit log.")}catch(d){r([]),c(0),A(!1),V(!1),g((d==null?void 0:d.message)||"GreÅ¡ka pri dohvatu audit logova.")}finally{l(!1)}};n.useEffect(()=>{P(f,m,h,S,b,w)},[f,h,S]),n.useEffect(()=>(k.current&&window.clearTimeout(k.current),k.current=window.setTimeout(()=>{N(1),P(1,m,h,S,b,w)},300),()=>{k.current&&window.clearTimeout(k.current)}),[m,b,w]);const le=()=>{I(""),M(""),H(""),G("-created_at"),U(50),N(1),q(new Set),P(1,"",50,"-created_at","","")},oe=s=>{q(u=>{const i=new Set(u);return i.has(s)?i.delete(s):i.add(s),i})},de=n.useMemo(()=>!o||!h?1:Math.max(1,Math.ceil(o/h)),[o,h]);return e.jsx("div",{className:"page-shell page-stack",children:e.jsxs(he,{children:[e.jsxs(pe,{children:[e.jsx(xe,{children:"DZO - Audit log"}),e.jsxs(je,{children:["Pregled zapisa iz ",e.jsx("span",{className:"font-mono",children:te})," uz server-side paginaciju."]})]}),e.jsxs(ge,{className:"space-y-3",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-7 gap-3",children:[e.jsxs("div",{className:"md:col-span-2 space-y-1",children:[e.jsx(T,{children:"Pretraga"}),e.jsx(F,{value:m,onChange:s=>I(String(s.target.value||"")),placeholder:"action, object_type, object_id, korisnik, details..."})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(T,{children:"Vrijeme od"}),e.jsx(F,{type:"datetime-local",value:b,onChange:s=>M(String(s.target.value||""))})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(T,{children:"Vrijeme do"}),e.jsx(F,{type:"datetime-local",value:w,onChange:s=>H(String(s.target.value||""))})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(T,{children:"Sort"}),e.jsxs("select",{className:"w-full border rounded-md px-3 py-2 bg-white dark:bg-gray-900",value:S,onChange:s=>G(s.target.value),children:[e.jsx("option",{value:"-created_at",children:"Najnovije prvo"}),e.jsx("option",{value:"created_at",children:"Najstarije prvo"})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(T,{children:"Po stranici"}),e.jsx("select",{className:"w-full border rounded-md px-3 py-2 bg-white dark:bg-gray-900",value:String(h),onChange:s=>{const u=Number(s.target.value||50),i=ne.includes(u)?u:50;U(i),N(1)},children:ne.map(s=>e.jsx("option",{value:String(s),children:s},s))})]}),e.jsx("div",{className:"space-y-1 flex flex-col justify-end gap-2",children:e.jsxs("div",{className:"flex gap-2",children:[e.jsx(C,{variant:"outline",onClick:()=>void P(f,m,h,S,b,w),disabled:a,children:"Osvježi"}),e.jsx(C,{variant:"outline",onClick:le,disabled:a,children:"Reset"})]})})]}),v?e.jsx("div",{className:"text-sm text-red-700",children:v}):null,y?e.jsx("div",{className:"text-sm text-amber-700",children:y}):null,e.jsxs("div",{className:"flex flex-wrap gap-2 items-center text-sm",children:[e.jsxs(R,{variant:"outline",children:["Ukupno: ",o]}),e.jsxs(R,{variant:"outline",children:["Stranica: ",f,"/",de]}),e.jsxs(R,{variant:"outline",children:["Vidljivo: ",t.length]}),a?e.jsx(R,{variant:"outline",children:"UÄitavanje..."}):null]}),e.jsx("div",{className:"overflow-x-auto border rounded-lg",children:e.jsxs("table",{className:"min-w-[1250px] w-full text-sm",children:[e.jsx("thead",{className:"bg-muted/40",children:e.jsxs("tr",{className:"text-left",children:[e.jsx("th",{className:"p-2",children:"Vrijeme"}),e.jsx("th",{className:"p-2",children:"Akcija"}),e.jsx("th",{className:"p-2",children:"Objekt"}),e.jsx("th",{className:"p-2",children:"Object ID"}),e.jsx("th",{className:"p-2",children:"Korisnik"}),e.jsx("th",{className:"p-2",children:"Detalji"})]})}),e.jsxs("tbody",{children:[t.map(s=>{const u=ce.has(s.id),i=re(s.details),x=we(s.details),z=i.length>180,$=z?`${i.slice(0,180)}...`:i,d=s.user_username||(s.user!=null?`user#${s.user}`:"-");return e.jsxs("tr",{className:"border-t",children:[e.jsx("td",{className:"p-2 whitespace-nowrap",children:ye(s.created_at)}),e.jsx("td",{className:"p-2 whitespace-nowrap",children:s.action||"-"}),e.jsx("td",{className:"p-2 whitespace-nowrap",children:s.object_type||"-"}),e.jsx("td",{className:"p-2 whitespace-nowrap font-mono",children:s.object_id||"-"}),e.jsx("td",{className:"p-2 whitespace-nowrap",children:d}),e.jsxs("td",{className:"p-2",children:[x.length>0?e.jsxs("div",{className:"mb-2 text-xs",children:[x.slice(0,8).map(p=>e.jsxs("div",{className:"text-slate-700 dark:text-slate-200",children:[e.jsx("span",{className:"font-medium",children:p.field}),": ",ae(p.oldValue)," â ",ae(p.newValue)]},`${s.id}-${p.field}`)),x.length>8?e.jsxs("div",{className:"text-xs text-slate-500",children:["⦠joÅ¡ ",x.length-8," promjena"]}
1):null]}):null,e.jsx("div",{className:"text-xs text-muted-foreground break-all",children:u?i:$}),z?e.jsx("button",{className:"mt-1 text-xs text-sky-700 hover:underline",onClick:()=>oe(s.id),type:"button",children:u?"Sakrij detalje":"Prikazi detalje"}):null]})]},s.id)}),t.length?null:e.jsx("tr",{children:e.jsx("td",{className:"p-4 text-center text-muted-foreground",colSpan:6,children:a?"UÄitavanje...":"Nema zapisa za odabrane kriterije."})})]})]})}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(C,{variant:"outline",disabled:a||!J||f<=1,onClick:()=>N(1),children:"Prva"}),e.jsx(C,{variant:"outline",disabled:a||!J||f<=1,onClick:()=>N(s=>Math.max(1,s-1)),children:"Prethodna"}),e.jsx(C,{variant:"outline",disabled:a||!ie,onClick:()=>N(s=>s+1),children:"Sljedeca"})]})]})]})})}export{Ae as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.