1import{r as c,j as e,u as S,b as U}from"./app-BeGqF6ux.js";import{M as z,B as d,b as p}from"./Tooltip-DYcxt1UG.js";import{I as v}from"./Input-CzZXrXpb.js";import{S as k}from"./SearchInput-BpopGZxf.js";import{S as b}from"./Select-BUAvowba.js";import"./index-Dkf2GVy1.js";import"./dayjs-BlgjZc9C.js";import{C as f}from"./ClipLoader-Cb4IakqU.js";import"./button.styles-7lPNyjJO.js";import"./iconBase-CN8tsjra.js";import"./useTranslation-kJHeU9i8.js";import"./helpers-CgA5RTdO.js";import"./extends-DDykod_l.js";import"./index-CuywqdpV.js";import"./animation-DR5N1PjO.js";const A=t=>{const[l,a]=c.useState(""),[s,o]=c.useState(!1),[i,n]=c.useState(null);return{searchTerm:l,setSearchTerm:a,loading:s,users:i,searchUsers:async x=>{x.preventDefault(),o(!0);try{const m=await U.get(route("admin.organization.users.search",{organization:t.id,term:l}));n(m.data)}catch(m){console.error("Error fetching users:",m)}finally{o(!1)}},resetSearch:()=>{a(""),o(!1),n(null)}}},D=({users:t,onAddUser:l})=>t?e.jsx("div",{className:"mt-2 flex max-h-48 flex-col gap-sm overflow-auto",children:t.length>0?t.map(a=>e.jsxs("div",{className:"flex justify-between rounded-lg p-2 hover:border",children:[e.jsxs("div",{children:[e.jsxs("p",{className:"text-paragraph-1-bold font-semibold",children:["Email: ",a.email]}),e.jsxs("p",{className:"text-paragraph-1-light text-gray-700",children:["Name: ",a.name]})]}),e.jsxs(d,{variant:"ghost",onClick:()=>l(a),children:[e.jsx(p,{name:"HiPlus",size:"xs"}),e.jsx("p",{children:"Add to organization"})]})]},`user-${a.id}`)):e.jsx("p",{className:"mt-2 flex justify-center text-heading-4",children:"No users found"})}):null,E=({organization:t,handleBack:l,handleClose:a})=>{const s=S({email:"",name:"",role:"user"}),o=["user","admin"],i=r=>{r.preventDefault(),s.post(route("admin.organizations.users.store",{organization:t}),{onStart:()=>s.clearErrors(),onSuccess:a,preserveState:"errors"})},n=r=>{r.preventDefault(),s.reset(),l()};return e.jsxs("div",{children:[e.jsx("div",{className:"flex justify-end",children:e.jsxs(d,{variant:"ghost",onClick:n,children:[e.jsx(p,{name:"HiArrowLeft",size:"xs"}),e.jsx("p",{children:"Back"})]})}),e.jsxs("form",{className:"flex w-full flex-col gap-md",onSubmit:i,children:[e.jsx("div",{className:"flex flex-col gap-sm",children:e.jsx(v,{type:"email",label:"Email",placeholder:"[email protected]",autoComplete:"off",required:!0,value:s.data.email,onChange:r=>s.setData("email",`${r}`),invalid:s.errors.email})}),e.jsx("div",{className:"flex flex-col gap-sm",children:e.jsx(v,{type:"text",label:"Name (optional)",placeholder:"John Wick",autoComplete:"off",value:s.data.name,onChange:r=>s.setData("name",`${r}`),invalid:s.errors.name})}),e.jsx("div",{className:"flex flex-col gap-sm",children:e.jsx(b,{placeholder:"Select a role",label:"Role",value:s.data.role,onChange:r=>s.setData("role",`${r}`),invalid:s.errors.role,options:o.map(r=>({label:r,value:r}))})}),s.processing?e.jsxs("div",{className:"mt-2 flex items-center gap-sm",children:[e.jsx(f,{color:"#3b82f6",size:15,speedMultiplier:.6}),e.jsx("p",{className:"text-blue-500",children:"Creating user"})]}):e.jsx(d,{type:"submit",children:"Create user"})]})]})},B=({organization:t,handleClose:l,user:a})=>{const s=S({role:"user"}),o=["user","admin"],i=r=>{r.preventDefault(),s.post(route("admin.organization.users.add-to-organization",{organization:t.id,user:a.id}),{onStart:()=>s.clearErrors(),onSuccess:l,preserveState:"errors"})},n=r=>{r.preventDefault(),s.reset(),l()};return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("p",{className:"text-heading-6",children:["Are you sure you want to add the user ",e.jsx("strong",{children:a.email})," to the organization",e.jsxs("strong",{children:[" ",t.name]}),"?"]}),e.jsxs(d,{variant:"ghost",onClick:n,children:[e.jsx(p,{name:"HiArrowLeft",size:"xs"}),e.jsx("p",{children:"Back"})]})]}),e.jsxs("form",{className:"mt-6 flex w-full flex-col gap-md",onSubmit:i,children:[e.jsx("div",{className:"flex flex-col gap-sm",children:e.jsx(b,{label:"Please select a role for this user...",placeholder:"Select a role",value:s.data.role,onChange:r=>s.setData("role",`${r}`),options:o.map(r=>({label:r,value:r})),invalid:s.errors.role})}),s.processing?e.jsxs("div",{className:"mt-2 flex items-center gap-sm",children:[e.jsx(f,{color:"#3b82f6",size:15,speedMultiplier:.6}),e.jsx("p",{className:"text-blue-500",children:"Creating user"})]}):e.jsx(d,{className:"w-fit",type:"submit",children:"Attach user"})]})]})};function Q({show:t,onClose:l,organization:a}){const[s,o]=c.useState(!1),[i,n]=c.useState(!1),[r,u]=c.useState(null),{searchTerm:x,setSearchTerm:m,loading:C,users:N,searchUsers:y,resetSearch:j}
1=A(a);c.useEffect(()=>{j()},[s]);const w=h=>{u(h),n(!0)},g=()=>{o(!1),n(!1),u(null),j(),l()};return e.jsx(e.Fragment,{children:e.jsx(z,{open:t,onClose:g,header:{title:s?"Create user":"Add User"},footer:!s&&!i?{primaryAction:{onClick:()=>o(!0),label:"Create new user",variant:"secondary"}}:void 0,children:s?e.jsx(E,{organization:a,handleBack:()=>o(!1),handleClose:g}):e.jsxs(e.Fragment,{children:[r&&e.jsx(B,{organization:a,handleClose:()=>{n(!1),u(null)},user:r}),!i&&!s&&e.jsxs(e.Fragment,{children:[e.jsxs("form",{className:"w-full max-w-2xl",onSubmit:y,children:[e.jsx(k,{hideLabel:!0,placeholder:"Search for users",value:x,onChange:h=>m(h),caption:'Press "Enter" to search'}),e.jsx("button",{className:"sr-only",type:"submit",children:"Submit"})]}),C&&e.jsxs("div",{className:"mt-2 flex items-center justify-center gap-sm",children:[e.jsx(f,{color:"blue",size:20,speedMultiplier:.6}),e.jsx("p",{className:"animate-pulse text-xl font-bold",children:"Searching"})]}),e.jsx(D,{users:N,onAddUser:w})]})]})})})}export{Q 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.