import{r as m,j as e,Q as v,a as l,t as i}from"./app-BBZbvTSO.js";import{A as S}from"./app-layout-DgXit_SB.js";import U from"./layout-CRccZ4Da.js";import{H as A}from"./heading-small-CjA8Z0WM.js";import{B as j}from"./button-CZmOQP7j.js";import{S as C}from"./Select-BSWSW26d.js";/* empty css            */import"./utils-YhN_nlHn.js";import"./index-C0VDnRYN.js";import"./index-CbDI-tXU.js";import"./Combination-9YgcTppv.js";import"./index-13DH8-b5.js";import"./index-C1VwruLz.js";import"./tooltip-CRkL5R4V.js";import"./index-hDbW6ayQ.js";import"./floating-ui.dom-DtF1XweH.js";import"./index-AiAmtg3H.js";import"./dropdown-menu-DkvU_mzU.js";import"./index-IvSACaye.js";import"./index-BosTFUDi.js";import"./index-Dbn6AP0q.js";import"./settings-1sj5BLwD.js";import"./app-logo-icon-BZsH9yGo.js";import"./index-BnKWxTXF.js";import"./image-BEhzBCM8.js";import"./globe-DRyUQWUz.js";import"./users-DU0sA3Q7.js";import"./layout-grid-CF44vN4j.js";import"./chevron-right-fDICdnKB.js";import"./heading-D7WRqD78.js";import"./separator-BzKY_P4f.js";function oe({project:u}){var x;const[t,p]=m.useState(u),[o,n]=m.useState(null),[f,d]=m.useState([]),b=[{title:t.name,href:route("projects.show",t.id)},{title:"Settings",href:route("projects.settings.project",t.id)},{title:"User Access",href:route("projects.settings.user-access",t.id)}],g=s=>s?(l.get("/user-management/api/users",{params:{search:s,per_page:10}}).then(r=>{var h;const c=((h=t.members)==null?void 0:h.map(a=>a.id))||[],w=r.data.data.filter(a=>!c.includes(a.id)).map(a=>({value:a.id,label:`${a.name} <${a.email}>`}));d(w)}),s):(d([]),s),N=async()=>{if(o)try{const s=await l.post(route("projects.settings.members.add",t.id),{user_id:o.value});p(s.data),n(null),i.success("Member added")}catch{i.error("Failed to add member")}},y=async s=>{try{const r=await l.delete(route("projects.settings.members.remove",[t.id,s]));p(r.data),i.success("Member removed")}catch{i.error("Failed to remove member")}};return e.jsxs(S,{breadcrumbs:b,children:[e.jsx(v,{title:"User Access"}),e.jsx(U,{project:t,children:e.jsxs("div",{className:"space-y-8 max-w-2xl",children:[e.jsx(A,{title:"User Access",description:"Grant or revoke access to this project"}),e.jsx("div",{className:"border rounded-md overflow-x-auto",children:e.jsxs("table",{className:"min-w-full text-sm",children:[e.jsx("thead",{className:"bg-muted/50",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-3 py-2 text-left",children:"Name"}),e.jsx("th",{className:"px-3 py-2 text-left",children:"Email"}),e.jsx("th",{className:"px-3 py-2",children:"Roles"}),e.jsx("th",{className:"px-3 py-2"})]})}),e.jsxs("tbody",{children:[(x=t.members)==null?void 0:x.map(s=>{var r;return e.jsxs("tr",{className:"border-t",children:[e.jsx("td",{className:"px-3 py-2 whitespace-nowrap",children:s.name}),e.jsx("td",{className:"px-3 py-2 whitespace-nowrap",children:s.email}),e.jsx("td",{className:"px-3 py-2 whitespace-nowrap",children:(r=s.roles)==null?void 0:r.map(c=>c.name).join(", ")}),e.jsx("td",{className:"px-3 py-2 text-center whitespace-nowrap",children:e.jsx(j,{size:"icon",variant:"ghost",className:"text-red-600",onClick:()=>y(s.id),children:"✕"})})]},s.id)}),(!t.members||t.members.length===0)&&e.jsx("tr",{children:e.jsx("td",{className:"px-3 py-2 text-muted-foreground",colSpan:4,children:"No members yet."})})]})]})}),e.jsxs("div",{className:"flex gap-2 items-center mt-4 w-full",children:[e.jsx(C,{value:o,onChange:n,onInputChange:g,options:f,placeholder:"Search users...",isClearable:!0,className:"w-full"}),e.jsx(j,{disabled:!o,onClick:N,children:"Add"})]})]})})]})}export{oe as default};
