import{r as i,j as e,H as b,L as o,a as d}from"./app-BQEFzdw6.js";import{A as f}from"./AppLayout-kozc03ce.js";import{P as w}from"./PageHeader-Bj1OQnqr.js";import{B as _}from"./Badge-CiLdjUlo.js";import{C as S}from"./ConfirmDialog-DkDf4ypa.js";import{F as C}from"./PlusIcon-ElxOOThC.js";import{F as L}from"./PencilIcon-BWjiauNE.js";import"./useThemeColor-qPCpc713.js";import"./Modal-CYT-I8ae.js";import"./with-selector-kbxKzNSf.js";function A({title:s,titleId:r,...n},c){return i.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",strokeWidth:1.5,stroke:"currentColor","aria-hidden":"true","data-slot":"icon",ref:c,"aria-labelledby":r},n),s?i.createElement("title",{id:r},s):null,i.createElement("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M5.636 5.636a9 9 0 1 0 12.728 0M12 3v9"}))}const k=i.forwardRef(A);function I({users:s,filters:r}){var p,g,h,u,y;const[n,c]=i.useState((r==null?void 0:r.search)??""),[a,x]=i.useState(null);function j(t){t.preventDefault(),d.get(route("settings.users.index"),{search:n},{preserveState:!0,replace:!0})}function N(t){d.patch(route("settings.users.activate",t.id))}const m=s.data??s;return e.jsxs(f,{children:[e.jsx(b,{title:"Users"}),e.jsx(w,{title:"User Management",subtitle:"Manage system users and their roles",children:e.jsxs(o,{href:route("settings.users.create"),className:"btn btn-primary flex items-center gap-2",children:[e.jsx(C,{className:"w-4 h-4"})," New User"]})}),e.jsxs("div",{className:"p-4 sm:p-6",children:[e.jsxs("form",{onSubmit:j,className:"mb-4 flex gap-3",children:[e.jsx("input",{className:"form-input w-64",placeholder:"Search name or email…",value:n,onChange:t=>c(t.target.value)}),e.jsx("button",{type:"submit",className:"btn btn-secondary",children:"Search"}),n&&e.jsx("button",{type:"button",className:"btn",onClick:()=>{c(""),d.get(route("settings.users.index"))},children:"Clear"})]}),e.jsx("div",{className:"card overflow-hidden",children:e.jsxs("table",{className:"min-w-full divide-y divide-gray-200",children:[e.jsx("thead",{className:"bg-gray-50",children:e.jsx("tr",{children:["Name","Email","Phone","Roles","Last Login","Status","Actions"].map(t=>e.jsx("th",{className:"px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider",children:t},t))})}),e.jsxs("tbody",{className:"divide-y divide-gray-100 bg-white",children:[m.map(t=>e.jsxs("tr",{className:"hover:bg-gray-50",children:[e.jsx("td",{className:"px-4 py-3 text-sm font-medium text-gray-900",children:t.name}),e.jsx("td",{className:"px-4 py-3 text-sm text-gray-600",children:t.email}),e.jsx("td",{className:"px-4 py-3 text-sm text-gray-600",children:t.phone??"—"}),e.jsx("td",{className:"px-4 py-3",children:e.jsxs("div",{className:"flex flex-wrap gap-1",children:[(t.roles??[]).map(l=>{var v;return e.jsx("span",{className:"inline-flex items-center px-2 py-0.5 rounded text-xs bg-indigo-100 text-indigo-700 font-medium",children:(v=l.name)==null?void 0:v.replace(/_/g," ")},l.id??l.name)}),(t.roles??[]).length===0&&e.jsx("span",{className:"text-gray-400 text-xs",children:"No roles"})]})}),e.jsx("td",{className:"px-4 py-3 text-sm text-gray-500",children:t.last_login_at?new Date(t.last_login_at).toLocaleDateString("en-GB",{day:"2-digit",month:"short",year:"numeric"}):"Never"}),e.jsx("td",{className:"px-4 py-3",children:e.jsx(_,{status:t.is_active?"active":"cancelled",label:t.is_active?"Active":"Inactive"})}),e.jsx("td",{className:"px-4 py-3",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(o,{href:route("settings.users.edit",t.id),title:"Edit",className:"text-gray-400 hover:text-yellow-600",children:e.jsx(L,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>x({type:"toggle",user:t}),title:t.is_active?"Deactivate":"Activate",className:`${t.is_active?"text-gray-400 hover:text-red-600":"text-gray-400 hover:text-green-600"}`,children:e.jsx(k,{className:"w-4 h-4"})})]})})]},t.id)),m.length===0&&e.jsx("tr",{children:e.jsx("td",{colSpan:7,className:"px-4 py-8 text-center text-gray-400",children:"No users found."})})]})]})}),s.links&&e.jsx("div",{className:"mt-4 flex gap-1",children:s.links.map((t,l)=>e.jsx(o,{href:t.url??"#",className:`px-3 py-1.5 text-sm rounded border ${t.active?"bg-primary-600 text-white border-primary-600":"bg-white text-gray-600 border-gray-300 hover:bg-gray-50"} ${t.url?"":"opacity-40 pointer-events-none"}`,dangerouslySetInnerHTML:{__html:t.label}},l))})]}),e.jsx(S,{open:(a==null?void 0:a.type)==="toggle",onClose:()=>x(null),onConfirm:()=>N(a.user),title:(p=a==null?void 0:a.user)!=null&&p.is_active?"Deactivate User":"Activate User",message:`Are you sure you want to ${(g=a==null?void 0:a.user)!=null&&g.is_active?"deactivate":"activate"} ${(h=a==null?void 0:a.user)==null?void 0:h.name}?`,confirmLabel:(u=a==null?void 0:a.user)!=null&&u.is_active?"Deactivate":"Activate",variant:(y=a==null?void 0:a.user)!=null&&y.is_active?"danger":"warning"})]})}export{I as default};
