import{o as e}from"./rolldown-runtime-BM3Ffeng.js";import{$f as t,$l as n,Fg as r,Gy as i,Hy as a,Mg as o,Ms as s,X as c,Y as l,Zv as u,ap as d,dg as f,dv as p,eg as m,kp as h,lh as g,m_ as _,mv as v,ph as y,pv as b,q as x,sg as S,tp as C,ty as w}from"./index-DDwwBb9e.js";import{n as T,t as E}from"./WithPermissionGuard-wX0IC3VF.js";import{t as D}from"./SettingsLayout-DkhRoxt1.js";var O=e(i()),k=a();function A(e){return typeof e==`object`&&!!e&&`id`in e&&`name`in e&&typeof e.id==`string`&&typeof e.name==`string`}function j(e){return Array.isArray(e)&&e.every(e=>typeof e==`string`)}function M(e,t){return e&&A(e)?{label:e.name,value:`custom:${e.id}`,description:e.description??(j(e.permissions)?`${e.permissions.length} permissions`:`Custom role`),isCustom:!0,customRoleId:e.id}:l[t]}function N(e){return{userId:{label:`${e.user.name} (${e.user.email})`,value:e.user.id},role:M(e.assignedRole,e.role),saved:!0}}function P(){let e=h().query.team,{organization:t}=d(),n=g.team.getTeamWithMembers.useQuery({slug:e,organizationId:t?.id??``},{enabled:typeof e==`string`&&!!t?.id});if(n.error){let e=n.error;if(e instanceof S&&e.data?.code===`UNAUTHORIZED`)return(0,k.jsx)(D,{children:(0,k.jsx)(f,{paddingX:4,paddingY:6,gap:4,align:`start`,children:(0,k.jsx)(T,{permission:`team:view`,message:`You don't have permission to view this team. Please contact your team administrator for access.`})})})}return n.isLoading||!n.data?(0,k.jsx)(D,{children:(0,k.jsxs)(f,{paddingX:4,paddingY:6,gap:6,width:`full`,maxWidth:`920px`,align:`start`,children:[(0,k.jsxs)(_,{gap:`8px`,children:[(0,k.jsx)(o,{height:`20px`,width:`60px`}),(0,k.jsx)(o,{height:`20px`,width:`12px`}),(0,k.jsx)(o,{height:`20px`,width:`120px`})]}),(0,k.jsx)(o,{height:`32px`,width:`200px`}),(0,k.jsx)(b,{width:`full`,children:(0,k.jsx)(p,{paddingY:4,children:(0,k.jsxs)(f,{gap:4,align:`start`,children:[(0,k.jsxs)(f,{gap:2,align:`start`,width:`full`,children:[(0,k.jsx)(o,{height:`16px`,width:`80px`}),(0,k.jsx)(o,{height:`40px`,width:`full`})]}),(0,k.jsxs)(f,{gap:2,align:`start`,width:`full`,children:[(0,k.jsx)(o,{height:`16px`,width:`100px`}),(0,k.jsx)(o,{height:`40px`,width:`full`})]})]})})})]})}):(0,k.jsx)(F,{team:n.data})}function F({team:e}){let i=(0,O.useCallback)(e=>({name:e.name,members:e.members.map(N)}),[]),[a,o]=(0,O.useState)(i(e)),l=t({defaultValues:a});(0,O.useEffect)(()=>{let t=i(e);o(t),l.reset(t)},[e,i,l]);let{handleSubmit:d,control:T}=l,E=C({control:T}),A=g.team.update.useMutation(),j=g.team.archiveById.useMutation(),M=g.useContext(),P=h(),F=n(t=>{s(t,a)||(o(t),A.mutate({teamId:e.id,name:t.name,members:t.members.map(e=>({userId:e.userId?.value??``,role:e.role.value,customRoleId:e.role.customRoleId}))},{onSuccess:()=>{y.create({title:`Team updated successfully`,type:`success`,duration:2e3,meta:{closable:!0}}),M.organization.getAll.refetch()},onError:e=>{m(e)||e instanceof S&&e.data?.code===`UNAUTHORIZED`&&y.create({title:`You need to be an administrator of the organization to update this team`,type:`error`,duration:5e3,meta:{closable:!0}})}}))},250);(0,O.useEffect)(()=>{d(F)()},[E,d,F]);let[I,L]=(0,O.useState)(!1);return(0,k.jsxs)(D,{children:[(0,k.jsxs)(f,{gap:8,align:`start`,width:`full`,children:[(0,k.jsx)(x,{organizationId:e.organizationId,team:e,form:l,onSubmit:F,isLoading:A.isLoading}),(0,k.jsx)(r,{}),(0,k.jsxs)(f,{align:`start`,gap:3,width:`full`,children:[(0,k.jsx)(w,{size:`sm`,color:`red.500`,children:`Danger Zone`}),(0,k.jsx)(b,{width:`full`,borderColor:`red.200`,children:(0,k.jsx)(p,{children:(0,k.jsxs)(_,{justify:`space-between`,children:[(0,k.jsxs)(f,{align:`start`,gap:0,children:[(0,k.jsx)(u,{fontWeight:`medium`,children:`Archive this team`}),(0,k.jsx)(u,{fontSize:`sm`,color:`fg.muted`,children:`Hides the team and all its projects. Contact LangWatch support to restore it.`})]}),(0,k.jsx)(v,{colorPalette:`red`,variant:`outline`,size:`sm`,onClick:()=>L(!0),disabled:j.isLoading,children:`Archive team`})]})})})]})]}),(0,k.jsx)(c,{open:I,onOpenChange:e=>{e||L(!1)},title:`Archive Team`,message:`Are you sure you want to archive "${e.name}"? This will hide the team and all its projects. Contact LangWatch support to restore it.`,confirmLabel:`Archive`,tone:`danger`,loading:j.isLoading,onConfirm:()=>{j.mutate({teamId:e.id},{onSuccess:()=>{L(!1),P.push(`/settings/teams`)},onError:()=>{y.create({title:`Failed to archive team`,type:`error`,duration:5e3,meta:{closable:!0}})}})}})]})}var I=E(`team:view`,{layoutComponent:D})(P);export{I as default};
//# sourceMappingURL=_team_-BjmURExK.js.map