@wacht/jsx 1.0.0-beta.50 → 1.0.0-beta.51

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs.js CHANGED
@@ -105,7 +105,7 @@ See https://styled-components.com/docs/faqs#why-am-i-getting-a-warning-about-sev
105
105
  10.0.0.0/24`,className:"w-input--area w-input--mono"})]})]})]}),((P=i==null?void 0:i.b2b_settings)==null?void 0:P.allow_org_deletion)&&t.jsxs("div",{className:"w-flex-col w-gap-3",children:[t.jsx($i,{children:"Danger zone"}),t.jsxs("div",{className:"w-danger w-flex-col w-items-start w-gap-3",children:[t.jsxs("div",{className:"w-flex w-items-center w-justify-between w-gap-2 w-full",children:[t.jsxs("div",{className:"w-grow w-flex-col w-gap-1",children:[t.jsx("div",{className:"w-sec",children:"Delete organization"}),t.jsx("div",{className:"w-secsub",children:"Once you delete this organization, there is no going back."})]}),t.jsx(se,{$size:"sm",$outline:!0,$destructive:!0,onClick:()=>{j(!N),_("")},children:N?"Cancel":"Delete organization"})]}),N&&t.jsxs("div",{className:"w-flex-col w-gap-3 w-full",children:[t.jsxs(We,{children:[t.jsxs(Ve,{htmlFor:"confirm_org_name",children:["Type"," ",t.jsx("strong",{children:e.name})," ","to confirm"]}),t.jsx(xe,{id:"confirm_org_name",type:"text",value:b,onChange:$=>_($.target.value),placeholder:e.name})]}),t.jsx(se,{$size:"sm",$destructive:!0,onClick:F,disabled:b!==e.name||v,children:v?t.jsx(ye,{size:12}):"Delete forever"})]})]})]})]}):t.jsx(ye,{})},Ar=(e,a)=>a?`${e} ${a}`:e,$t=o.forwardRef(({className:e,...a},s)=>t.jsx("table",{ref:s,className:Ar("w-table",e),...a}));$t.displayName="Table";const Ot=o.forwardRef((e,a)=>t.jsx("thead",{ref:a,...e}));Ot.displayName="TableHead";const Zt=o.forwardRef((e,a)=>t.jsx("tbody",{ref:a,...e}));Zt.displayName="TableBody";const it=o.forwardRef((e,a)=>t.jsx("tr",{ref:a,...e}));it.displayName="TableRow";const $e=o.forwardRef((e,a)=>t.jsx("th",{ref:a,...e}));$e.displayName="TableHeader";const Ke=o.forwardRef(({className:e,...a},s)=>t.jsx("td",{ref:s,className:e,...a}));Ke.displayName="TableCell";const Qm=o.forwardRef(({className:e,...a},s)=>t.jsx("td",{ref:s,className:Ar("w-td--flex",e),...a}));Qm.displayName="TableCellFlex";const Ht=o.forwardRef(({className:e,...a},s)=>t.jsx("td",{ref:s,className:Ar("w-td--actions",e),...a}));Ht.displayName="ActionsCell";const Ct=({title:e,description:a,icon:s,action:n})=>t.jsxs("div",{className:"w-empty",children:[t.jsx("div",{className:"w-empty-ic",children:s??t.jsx(Ou,{size:20})}),t.jsxs("div",{className:"w-empty-text",children:[t.jsx("h4",{children:e}),t.jsx("p",{children:a})]}),n&&t.jsx("div",{className:"w-empty-action",children:n})]}),xt=({triggerRef:e,isOpen:a,minWidth:s=300,defaultMaxHeight:n=400,offset:i=8,contentRef:l})=>{const[m,c]=o.useState();return o.useEffect(()=>{if(!a||!e.current){c(void 0);return}const d=()=>{var N;if(!e.current)return;const u=e.current.getBoundingClientRect(),h=window.innerWidth,f=window.innerHeight,g=((N=l==null?void 0:l.current)==null?void 0:N.offsetWidth)||s,x=f-u.bottom,w=u.top,b={};x>=w?(b.top=u.bottom+i,b.maxHeight=Math.min(n,x-i*2)):(b.bottom=f-u.top+i,b.maxHeight=Math.min(n,w-i*2));const _=h-u.left,v=u.right,k=_>=v?u.left:u.right-g;b.left=Math.max(i,Math.min(h-g-i,k)),c(b)},p=requestAnimationFrame(d);return window.addEventListener("resize",d),window.addEventListener("scroll",d,!0),()=>{cancelAnimationFrame(p),window.removeEventListener("resize",d),window.removeEventListener("scroll",d,!0)}},[a,s,n,i,l]),m},Oi=({onClose:e,domain:a,triggerRef:s})=>{const n=o.useRef(null),[i,l]=o.useState(),[m,c]=o.useState(""),[d,p]=o.useState(!1),[u,h]=o.useState(!1),{addDomain:f,verifyDomain:g}=ha(),{toast:x}=_t(),w=xt({contentRef:n,triggerRef:s??{current:null},isOpen:u,minWidth:360,defaultMaxHeight:420}),b=j=>/^[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(\.[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*\.[a-zA-Z]{2,}$/.test(j),_=j=>j.trim().toLowerCase().replace(/^https?:\/\//,""),v=async()=>{const j=_(m);if(!j){x("Please enter a domain name","error");return}if(!b(j)){x("Please enter a valid domain (e.g., example.com)","error");return}if(j.length>253){x("Domain name is too long","error");return}p(!0);try{const C=await f({fqdn:j});x("Domain added","info"),l(C.data)}catch(C){x(C.message||"Failed to add domain. Please try again.","error")}finally{p(!1)}},k=async()=>{if(!(!i||d)){p(!0);try{await g(i),e==null||e(),x("Domain verified","info")}catch(j){x(j.message||"Failed to verify domain. Check DNS records and try again.","error")}finally{p(!1)}}};if(o.useEffect(()=>{h(!0);const j=y=>{n.current&&!n.current.contains(y.target)&&(e==null||e())},C=y=>{y.key==="Escape"&&(e==null||e())};return document.addEventListener("mousedown",j),document.addEventListener("keydown",C),()=>{document.removeEventListener("mousedown",j),document.removeEventListener("keydown",C)}},[e]),o.useEffect(()=>{a&&l(a)},[a]),!u)return null;const N={position:"fixed",zIndex:1001,top:(w==null?void 0:w.top)!==void 0?`${w.top}px`:void 0,bottom:(w==null?void 0:w.bottom)!==void 0?`${w.bottom}px`:void 0,left:(w==null?void 0:w.left)!==void 0?`${w.left}px`:void 0,right:(w==null?void 0:w.right)!==void 0?`${w.right}px`:void 0,visibility:w?"visible":"hidden"};return i?t.jsxs("div",{ref:n,className:"w-pop w-pop--wide",style:N,onClick:j=>j.stopPropagation(),role:"dialog","aria-labelledby":"verify-domain-title","aria-modal":"true",children:[t.jsxs("div",{className:"w-pop-body",children:[t.jsx("div",{className:"w-pop-title",id:"verify-domain-title",children:"Verify domain"}),t.jsx("p",{className:"w-pop-sub",children:"Add this DNS record, then verify."}),t.jsxs("label",{className:"w-field",children:[t.jsx("span",{className:"w-label",children:"Type"}),t.jsx(xe,{value:i==null?void 0:i.verification_dns_record_type,disabled:!0})]}),t.jsxs("label",{className:"w-field",children:[t.jsx("span",{className:"w-label",children:"Name"}),t.jsx(xe,{value:i==null?void 0:i.verification_dns_record_name,disabled:!0})]}),t.jsxs("label",{className:"w-field",children:[t.jsx("span",{className:"w-label",children:"Value"}),t.jsx(xe,{value:i==null?void 0:i.verification_dns_record_data,disabled:!0})]})]}),t.jsxs("div",{className:"w-pop-foot",children:[t.jsx("button",{type:"button",className:"w-btn w-btn--ghost w-btn--sm",onClick:e,children:"Cancel"}),t.jsx("button",{type:"button",className:"w-btn w-btn--primary w-btn--sm",onClick:k,disabled:d,children:d?t.jsx(ye,{size:12}):"Verify"})]})]}):t.jsxs("div",{ref:n,className:"w-pop w-pop--wide",style:N,onClick:j=>j.stopPropagation(),role:"dialog","aria-labelledby":"add-domain-title","aria-modal":"true",children:[t.jsxs("div",{className:"w-pop-body",children:[t.jsx("div",{className:"w-pop-title",id:"add-domain-title",children:"Add domain"}),t.jsx("p",{className:"w-pop-sub",children:"Verified members auto-join this org."}),t.jsxs("label",{className:"w-field",children:[t.jsx("span",{className:"w-label",children:"Domain"}),t.jsx(xe,{type:"text",placeholder:"example.com",value:m,onChange:j=>c(j.target.value),onKeyDown:j=>{j.key==="Enter"&&m&&v()},autoFocus:!0,"aria-label":"Domain name"})]})]}),t.jsxs("div",{className:"w-pop-foot",children:[t.jsx("button",{type:"button",className:"w-btn w-btn--ghost w-btn--sm",onClick:e,children:"Cancel"}),t.jsx("button",{type:"button",className:"w-btn w-btn--primary w-btn--sm",onClick:v,disabled:!m||d,children:d?t.jsx(ye,{size:12}):"Continue"})]})]})},Jm=({organization:e})=>{const{getOrganizationDomains:a,removeOrganizationDomain:s}=Vt(),[n,i]=o.useState(null),[l,m]=o.useState(!1),[c,d]=o.useState(null),[p,u]=o.useState(new Set),h=o.useRef(null),f=o.useRef({}),{data:g=[],isLoading:x,mutate:w}=ke(e!=null&&e.id?`wacht-org-domains:${e.id}`:null,async()=>(await(a==null?void 0:a(e))||[]).map(k=>({...k,verified:k.verified!==void 0?k.verified:!1}))),b=(v,k)=>{u(N=>{const j=new Set(N);return k?j.add(v):j.delete(v),j})},_=async v=>{b(v.id,!0);try{await s(e,v),w()}finally{b(v.id,!1),i(null)}};return x?t.jsx(ye,{}):t.jsxs(t.Fragment,{children:[t.jsxs(Er,{children:[t.jsxs("div",{className:"w-grow w-flex-col w-gap-1",children:[t.jsx("div",{className:"w-sec",children:"Domains"}),t.jsx("div",{className:"w-secsub",children:"Users with verified domain emails auto-join this organization."})]}),t.jsx(se,{ref:h,onClick:()=>m(!0),$size:"sm",children:"Add domain"}),l&&t.jsx(Oi,{onClose:()=>{m(!1),w()},triggerRef:h})]}),g!=null&&g.length?t.jsx(mn,{children:t.jsxs($t,{children:[t.jsx(Ot,{children:t.jsxs(it,{children:[t.jsx($e,{children:"Domain"}),t.jsx($e,{children:"Status"}),t.jsx($e,{children:"Added"}),t.jsx($e,{})]})}),t.jsx(Zt,{children:g.map(v=>{const k=p.has(v.id);return t.jsxs(it,{children:[t.jsx(Ke,{children:v.fqdn}),t.jsx(Ke,{children:v.verified?t.jsx(ma,{$variant:"success",children:"Verified"}):t.jsx(ma,{$variant:"warning",children:"Pending"})}),t.jsx(Ke,{children:new Date(v.created_at).toLocaleDateString()}),t.jsx(Ht,{children:t.jsxs("div",{className:"w-actions",children:[t.jsx(se,{ref:N=>{N&&(f.current[v.id]=N)},$size:"sm",$outline:!0,disabled:k,onClick:()=>d(v.id),children:v.verified?"View DNS":"Verify"}),t.jsx(se,{$size:"sm",$outline:!0,$destructive:!0,disabled:k,onClick:()=>i(v.id),children:k?t.jsx(ye,{size:12}):"Remove"})]})})]},v.id)})})]})}):t.jsx(Ct,{title:"No domains added",description:"Users with verified domain emails automatically join this organization."}),n&&t.jsx(Ya,{title:"Remove domain?",description:"Active users aren't affected, but new users with this domain won't auto-join.",onConfirm:()=>{const v=g.find(k=>k.id===n);v&&_(v)},onCancel:()=>i(null)}),c&&t.jsx(Oi,{domain:g.find(v=>v.id===c),onClose:()=>d(null),triggerRef:{current:f.current[c]}})]})},Bc=({onClose:e,onSuccess:a,roles:s,triggerRef:n})=>{const i=o.useRef(null),[l,m]=o.useState(""),[c,d]=o.useState(null),[p,u]=o.useState(!1),[h,f]=o.useState(!1),{inviteMember:g}=ha(),{toast:x}=_t(),w=xt({contentRef:i,triggerRef:n??{current:null},isOpen:h,minWidth:360,defaultMaxHeight:360}),b=s.map(k=>({value:k.id,label:k.name})),_=k=>/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(k),v=async()=>{const k=l.trim().toLowerCase();if(!(!k||!c)){if(!_(k)){x("Please enter a valid email address","error");return}if(k.length>320){x("Email address is too long","error");return}u(!0);try{await g({email:k,organizationRole:c}),a==null||a()}catch(N){x(N.message||"Failed to send invitation. Please try again.","error")}finally{u(!1)}}};return o.useEffect(()=>{f(!0);const k=j=>{i.current&&!i.current.contains(j.target)&&(e==null||e())},N=j=>{j.key==="Escape"&&(e==null||e())};return document.addEventListener("mousedown",k),document.addEventListener("keydown",N),()=>{document.removeEventListener("mousedown",k),document.removeEventListener("keydown",N)}},[e]),h?t.jsxs("div",{ref:i,className:"w-pop w-pop--wide",style:{position:"fixed",zIndex:1001,top:(w==null?void 0:w.top)!==void 0?`${w.top}px`:void 0,bottom:(w==null?void 0:w.bottom)!==void 0?`${w.bottom}px`:void 0,left:(w==null?void 0:w.left)!==void 0?`${w.left}px`:void 0,right:(w==null?void 0:w.right)!==void 0?`${w.right}px`:void 0,visibility:w?"visible":"hidden"},onClick:k=>k.stopPropagation(),role:"dialog","aria-labelledby":"invite-member-title","aria-modal":"true",children:[t.jsxs("div",{className:"w-pop-body",children:[t.jsx("div",{className:"w-pop-title",id:"invite-member-title",children:"Invite member"}),t.jsxs("label",{className:"w-field",children:[t.jsx("span",{className:"w-label",children:"Email"}),t.jsx(xe,{type:"email",placeholder:"colleague@company.com",value:l,onChange:k=>m(k.target.value),onKeyDown:k=>{k.key==="Enter"&&l&&c&&v()},autoFocus:!0,"aria-label":"Email address for invitation"})]}),t.jsxs("label",{className:"w-field",children:[t.jsx("span",{className:"w-label",children:"Role"}),t.jsx(dn,{options:b,value:c==null?void 0:c.id,onChange:k=>d(s.find(N=>N.id===k)),placeholder:"Select a role","aria-label":"Select role for invited member"})]})]}),t.jsxs("div",{className:"w-pop-foot",children:[t.jsx("button",{type:"button",className:"w-btn w-btn--ghost w-btn--sm",onClick:e,children:"Cancel"}),t.jsx("button",{type:"button",className:"w-btn w-btn--primary w-btn--sm",onClick:v,disabled:!l||!c||p,children:p?t.jsx(ye,{size:12}):"Send invite"})]})]}):null},Xm=({organization:e})=>{const{getOrganizationMembers:a,getOrganizationRoles:s,addRoleToOrganizationMember:n,removeRoleFromOrganizationMember:i,removeOrganizationMember:l}=Vt(),{session:m}=ot(),{toast:c}=_t(),[d,p]=o.useState(""),[u,h]=o.useState(1),[f]=o.useState(10),[g,x]=o.useState(!1),[w,b]=o.useState(new Set),_=o.useRef(null),[v,k]=o.useState(d);o.useEffect(()=>{const S=setTimeout(()=>{k(d),h(1)},500);return()=>clearTimeout(S)},[d]);const{data:N,mutate:j}=ke(e?`wacht-api-organizations:${e.id}:members:${u}:${f}:${v}`:null,()=>a==null?void 0:a(e,{page:u,limit:f,search:v}),{keepPreviousData:!0}),C=(N==null?void 0:N.data)||[],y=(N==null?void 0:N.meta)||{total:0,limit:10},E=Math.ceil(y.total/(y.limit||10)),{data:R=[]}=ke(e?`wacht-api-organizations:${e.id}:roles`:null,()=>(s==null?void 0:s(e))||[]),F=R,A=(S,O)=>{b(P=>{const $=new Set(P);return O?$.add(S):$.delete(S),$})},I=async(S,O,P)=>{A(S.id,!0);try{P?(await i(e,S,O),c("Role removed","info")):(await n(e,S,O),c("Role added","info")),j()}catch($){c($.message||"Failed to update role","error")}finally{A(S.id,!1)}},L=async S=>{A(S.id,!0);try{await l(e,S),j(),c("Member removed","info")}catch(O){c(O.message||"Failed to remove member","error")}finally{A(S.id,!1)}};return N?t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"w-toolbar",children:[t.jsx(Ic,{value:d,onChange:p,placeholder:"Search members..."}),t.jsxs("div",{className:"w-flex w-items-center w-gap-3",children:[y.total>0&&t.jsxs("div",{className:"w-secsub",children:[y.total," member",y.total!==1?"s":""]}),t.jsx(se,{ref:_,onClick:()=>x(!0),$size:"sm",children:"Invite"})]})]}),g&&t.jsx(Bc,{onClose:()=>x(!1),onSuccess:()=>{j(),x(!1)},roles:F,triggerRef:_}),C.length===0?t.jsx(Ct,{title:d?"No members match":"No members yet",description:"Invite someone or connect a corporate domain to auto-join."}):t.jsx(mn,{children:t.jsxs($t,{children:[t.jsx(Ot,{children:t.jsxs(it,{children:[t.jsx($e,{children:"Member"}),t.jsx($e,{children:"Joined"}),t.jsx($e,{children:"Roles"}),t.jsx($e,{})]})}),t.jsx(Zt,{children:C.map(S=>{var $,Z;const O=(($=S.user)==null?void 0:$.id)===((Z=m==null?void 0:m.active_signin)==null?void 0:Z.user_id),P=w.has(S.id);return t.jsxs(it,{children:[t.jsx(Ke,{children:t.jsx(e4,{member:S,isCurrentUser:O})}),t.jsx(Ke,{children:new Date(S.created_at).toLocaleDateString()}),t.jsx(Ke,{children:t.jsx(t4,{member:S,roles:F,onToggle:I,disabled:P})}),t.jsx(Ht,{children:t.jsx("div",{className:"w-actions",children:t.jsx(se,{$size:"sm",$outline:!0,$destructive:!0,disabled:P||O,onClick:()=>L(S),title:O?"You cannot remove yourself":"Remove member",children:P?t.jsx(ye,{size:12}):"Remove"})})})]},S.id)})})]})}),E>1&&t.jsxs("div",{className:"w-flex w-items-center w-justify-center w-gap-4 w-mt-6",children:[t.jsx(se,{onClick:()=>h(S=>Math.max(1,S-1)),disabled:u===1,$size:"sm",$outline:!0,children:"Previous"}),t.jsxs("span",{className:"w-secsub",children:[u," / ",E]}),t.jsx(se,{onClick:()=>h(S=>Math.min(E,S+1)),disabled:u===E,$size:"sm",$outline:!0,children:"Next"})]})]}):t.jsx(ye,{})},e4=({member:e,isCurrentUser:a})=>{var l,m;const s=e.user,n=(c="",d="")=>`${c[0]||""}${d[0]||""}`.toUpperCase()||"?",i=s?`${s.first_name||""} ${s.last_name||""}`.trim()||((l=s.primary_email_address)==null?void 0:l.email):"Unknown";return t.jsxs("div",{className:"w-flex w-items-center w-gap-3 w-grow",children:[t.jsx("div",{className:"w-avatar w-avatar--md",children:s!=null&&s.profile_picture_url?t.jsx("img",{src:s.profile_picture_url,alt:i}):n(s==null?void 0:s.first_name,s==null?void 0:s.last_name)}),t.jsxs("div",{className:"w-grow w-flex-col w-gap-1",children:[t.jsxs("div",{className:"w-flex w-items-center w-gap-2",children:[t.jsx("span",{className:"w-sec",children:i}),a&&t.jsx(ma,{$variant:"neutral",children:"You"})]}),t.jsx("span",{className:"w-secsub",children:(m=s==null?void 0:s.primary_email_address)==null?void 0:m.email})]})]})},t4=({member:e,roles:a,onToggle:s,disabled:n})=>{var c;const i=e.roles||[],l=d=>i.some(p=>p.id===d),m=i.length===0?"No role":i.length===1?(c=i[0])==null?void 0:c.name:`${i.length} roles`;return t.jsxs(js,{children:[t.jsx(ks,{children:t.jsxs(se,{$size:"sm",$outline:!0,disabled:n,className:"w-justify-between w-rolepick-btn",children:[m,t.jsx(Dt,{size:12})]})}),t.jsx(_s,{children:a.length===0?t.jsx("div",{className:"w-secsub w-menu-head",children:"No roles configured"}):a.map(d=>{const p=l(d.id);return t.jsx(ea,{onClick:()=>s(e,d,p),children:t.jsxs("div",{className:"w-flex w-items-center w-justify-between w-gap-3 w-full",children:[t.jsx("span",{children:d.name}),p&&t.jsx(Ge,{size:13,className:"w-text-primary"})]})},d.id)})})]})},a4=e=>{const a=e.expires_at;return a?new Date(a).getTime()<Date.now():!1},s4=({organization:e})=>{const{getOrganizationInvitations:a,getOrganizationRoles:s,discardOrganizationInvitation:n,resendOrganizationInvitation:i}=Vt(),{toast:l}=_t(),[m,c]=o.useState(!1),[d,p]=o.useState(new Set),u=o.useRef(null),{data:h=[],isLoading:f,mutate:g}=ke(e?`wacht-api-organizations:${e.id}:invitations`:null,()=>(a==null?void 0:a(e))||[]),{data:x=[],isLoading:w}=ke(e?`wacht-api-organizations:${e.id}:roles`:null,()=>(s==null?void 0:s(e))||[]),b=x,_=(N,j)=>{p(C=>{const y=new Set(C);return j?y.add(N):y.delete(N),y})},v=async N=>{_(N.id,!0);try{await n(e,N),g(),l("Invitation cancelled","info")}catch(j){l(j.message||"Failed to cancel invitation","error")}finally{_(N.id,!1)}},k=async N=>{_(N.id,!0);try{await i(e,N),l("Invitation resent","info")}catch(j){l(j.message||"Failed to resend invitation","error")}finally{_(N.id,!1)}};return f||w?t.jsx(ye,{}):t.jsxs(t.Fragment,{children:[t.jsxs(Er,{children:[t.jsxs("div",{className:"w-grow w-flex-col w-gap-1",children:[t.jsx("div",{className:"w-sec",children:"Invitations"}),t.jsx("div",{className:"w-secsub",children:"Pending invites to join this organization."})]}),t.jsx(se,{ref:u,onClick:()=>c(!0),$size:"sm",children:"Invite"})]}),m&&t.jsx(Bc,{onClose:()=>c(!1),onSuccess:()=>{g(),c(!1)},roles:b,triggerRef:u}),h.length===0?t.jsx(Ct,{title:"No pending invitations",description:"Invite members to collaborate."}):t.jsx(mn,{children:t.jsxs($t,{children:[t.jsx(Ot,{children:t.jsxs(it,{children:[t.jsx($e,{children:"Email"}),t.jsx($e,{children:"Role"}),t.jsx($e,{children:"Status"}),t.jsx($e,{children:"Invited"}),t.jsx($e,{})]})}),t.jsx(Zt,{children:h.map(N=>{var y;const j=a4(N),C=d.has(N.id);return t.jsxs(it,{children:[t.jsx(Ke,{children:N.email}),t.jsx(Ke,{children:((y=N.initial_organization_role)==null?void 0:y.name)||"No role"}),t.jsx(Ke,{children:j?t.jsx(ma,{$variant:"danger",children:"Expired"}):t.jsx(ma,{$variant:"warning",children:"Pending"})}),t.jsx(Ke,{children:new Date(N.created_at).toLocaleDateString()}),t.jsx(Ht,{children:t.jsxs("div",{className:"w-actions",children:[t.jsx(se,{$size:"sm",$outline:!0,disabled:C,onClick:()=>k(N),children:"Resend"}),t.jsx(se,{$size:"sm",$outline:!0,$destructive:!0,disabled:C,onClick:()=>v(N),children:C?t.jsx(ye,{size:12}):"Cancel"})]})})]},N.id)})})]})})]})},Zi=({onClose:e,onSuccess:a,role:s,triggerRef:n})=>{var j;const i=o.useRef(null),[l,m]=o.useState((s==null?void 0:s.name)||""),[c,d]=o.useState((s==null?void 0:s.permissions)||[]),[p,u]=o.useState(!1),[h,f]=o.useState(!1),{deployment:g}=_e(),{toast:x}=_t(),w=xt({contentRef:i,triggerRef:n??{current:null},isOpen:h,minWidth:400,defaultMaxHeight:500}),b=!!s,_=Array.isArray((j=g==null?void 0:g.b2b_settings)==null?void 0:j.organization_permissions)?g.b2b_settings.organization_permissions.map(C=>({value:C,label:C})):[];o.useEffect(()=>{f(!0);const C=R=>{i.current&&!i.current.contains(R.target)&&(e==null||e())},y=R=>{R.key==="Escape"&&(e==null||e())},E=setTimeout(()=>{document.addEventListener("mousedown",C),document.addEventListener("keydown",y)},100);return()=>{clearTimeout(E),document.removeEventListener("mousedown",C),document.removeEventListener("keydown",y)}},[e]);const v=C=>C.trim().replace(/[<>"'&]/g,""),k=C=>C.length>=2&&C.length<=50&&/^[a-zA-Z0-9\s_-]+$/.test(C),N=async()=>{const C=v(l);if(!C){x("Please enter a role name","error");return}if(!k(C)){x("Role name must be 2–50 characters, letters/numbers/spaces only.","error");return}if(c.length===0){x("Please select at least one permission","error");return}u(!0);try{const y={id:s==null?void 0:s.id,name:C,permissions:c};a==null||a(y)}catch(y){x(y.message||`Failed to ${b?"update":"create"} role. Please try again.`,"error")}finally{u(!1)}};return h?t.jsxs("div",{ref:i,className:"w-pop w-pop--wide",style:{position:"fixed",zIndex:1001,top:(w==null?void 0:w.top)!==void 0?`${w.top}px`:void 0,bottom:(w==null?void 0:w.bottom)!==void 0?`${w.bottom}px`:void 0,left:(w==null?void 0:w.left)!==void 0?`${w.left}px`:void 0,right:(w==null?void 0:w.right)!==void 0?`${w.right}px`:void 0,visibility:w?"visible":"hidden"},onClick:C=>C.stopPropagation(),role:"dialog","aria-labelledby":"role-dialog-title","aria-modal":"true",children:[t.jsxs("div",{className:"w-pop-body",children:[t.jsx("div",{className:"w-pop-title",id:"role-dialog-title",children:b?"Edit role":"New role"}),t.jsxs("label",{className:"w-field",children:[t.jsx("span",{className:"w-label",children:"Name"}),t.jsx(xe,{type:"text",placeholder:"e.g. Admin, Editor, Viewer",value:l,onChange:C=>m(C.target.value),autoFocus:!0,"aria-label":"Role name"})]}),t.jsxs("label",{className:"w-field",children:[t.jsx("span",{className:"w-label",children:"Permissions"}),t.jsx(Dc,{options:_,value:c,onChange:d,placeholder:"Select permissions","aria-label":"Select permissions for role"})]})]}),t.jsxs("div",{className:"w-pop-foot",children:[t.jsx("button",{type:"button",className:"w-btn w-btn--ghost w-btn--sm",onClick:e,children:"Cancel"}),t.jsx("button",{type:"button",className:"w-btn w-btn--primary w-btn--sm",onClick:N,disabled:!l||p,children:p?t.jsx(ye,{size:12}):b?"Update":"Create"})]})]}):null};function Mr(e){return typeof e=="object"&&e!==null}function Gc(e,a){const s=e[a];return typeof s=="string"?s.length>0&&s!=="0":typeof s=="number"?Number.isFinite(s)&&s>0:!1}function n4(e,a){const s=e[a];return typeof s=="boolean"?s:null}function qc(e){if(!Mr(e))return!1;const a=n4(e,"is_deployment_level");return a!==null?a:!1}function r4(e){return!Mr(e)||qc(e)?!1:Gc(e,"organization_id")}function dr(e){return!Mr(e)||qc(e)?!1:Gc(e,"workspace_id")}const i4=({organization:e})=>{var j;const{getOrganizationRoles:a,removeOrganizationRoles:s}=Vt(),{deployment:n}=_e(),[i,l]=o.useState({isOpen:!1}),[m,c]=o.useState(null),[d,p]=o.useState(null),[u,h]=o.useState(new Set),f=o.useRef(null),g=o.useRef(new Map),{data:x=[],isLoading:w,mutate:b}=ke(e?`wacht-api-organizations:${e.id}:roles`:null,()=>(a==null?void 0:a(e))||[]),_=(C,y)=>{h(E=>{const R=new Set(E);return y?R.add(C):R.delete(C),R})},v=async C=>{try{await new Promise(y=>setTimeout(y,500)),c({text:`Role ${C.id?"updated":"created"} successfully`,type:"success"}),l({isOpen:!1}),b()}catch(y){const E=y instanceof Error?y.message:"Failed to save role";c({text:E,type:"error"})}finally{setTimeout(()=>c(null),3e3)}},k=async C=>{_(C.id,!0);try{await s(e,C),b()}finally{_(C.id,!1),p(null)}};if(w&&x.length===0)return t.jsx(ye,{});const N=C=>{const y=r4(C),E=u.has(C.id),R=C.permissions.length;return t.jsxs(it,{children:[t.jsx(Ke,{children:t.jsxs("span",{className:"w-inline w-gap-2 w-sec",children:[C.name,!y&&t.jsx(ma,{$variant:"neutral",children:"Default"})]})}),t.jsx(Ke,{children:R===0?t.jsx(ma,{$variant:"neutral",children:"No permissions"}):t.jsxs("div",{className:"w-inline w-items-center w-gap-2",children:[t.jsxs(ma,{$variant:"primary",children:[R," ",R===1?"permission":"permissions"]}),t.jsx("span",{className:"w-truncate w-text-secondary w-maxw-sm",children:C.permissions.join(", ")})]})}),t.jsx(Ht,{children:y?t.jsxs("div",{className:"w-actions",children:[t.jsx(se,{ref:F=>{F&&g.current.set(C.id,F)},$size:"sm",$outline:!0,disabled:E,onClick:()=>l({isOpen:!0,role:C,triggerElement:g.current.get(C.id)??null}),children:"Edit"}),t.jsx(se,{$size:"sm",$outline:!0,$destructive:!0,disabled:E,onClick:()=>p(C.id),children:E?t.jsx(ye,{size:12}):"Delete"})]}):t.jsx("span",{className:"w-secsub",children:"Read-only"})})]},C.id)};return t.jsxs(t.Fragment,{children:[m&&t.jsxs("div",{className:`w-banner ${m.type==="success"?"w-banner--success":"w-banner--error"} w-mb-4`,children:[m.type==="success"?t.jsx(Ge,{size:16}):t.jsx(Ha,{size:16}),t.jsx("span",{className:"w-banner-txt",children:m.text})]}),t.jsxs(Er,{children:[t.jsxs("div",{className:"w-grow w-flex-col w-gap-1",children:[t.jsx("div",{className:"w-sec",children:"Roles"}),t.jsx("div",{className:"w-secsub",children:"Define granular permissions for members."})]}),((j=n==null?void 0:n.b2b_settings)==null?void 0:j.custom_org_role_enabled)&&t.jsx(se,{ref:f,onClick:()=>l({isOpen:!0,triggerElement:f.current}),$size:"sm",children:"Add role"})]}),i.isOpen&&!i.role&&t.jsx(Zi,{onClose:()=>l({isOpen:!1}),onSuccess:v,triggerRef:{current:i.triggerElement||f.current}}),x.length===0?t.jsx(Ct,{title:"No roles yet",description:"Define custom roles to manage granular permissions."}):t.jsx(t.Fragment,{children:t.jsx(mn,{children:t.jsxs($t,{children:[t.jsx(Ot,{children:t.jsxs(it,{children:[t.jsx($e,{children:"Role"}),t.jsx($e,{children:"Permissions"}),t.jsx($e,{})]})}),t.jsx(Zt,{children:x.map(N)})]})})}),d&&t.jsx(Ya,{title:"Delete role?",description:"This action cannot be undone. Users with this role might lose access to certain features.",onConfirm:()=>{const C=x.find(y=>y.id===d);C&&k(C)},onCancel:()=>p(null)}),i.isOpen&&i.role&&t.jsx(Zi,{role:i.role,onClose:()=>l({isOpen:!1}),onSuccess:v,triggerRef:{current:i.triggerElement||null}})]})},o4=()=>{const{activeOrganization:e,loading:a}=ha(),[s,n]=o.useState(null);return o.useEffect(()=>{e?n(e):!a&&!e&&s&&n(null)},[e,a,s]),{activeOrganization:s||e,loading:a}},Kc=()=>{var w,b,_;const{loading:e,activeOrganization:a}=o4(),{updateOrganization:s}=ha(),{deployment:n}=_e(),[i,l]=o.useState("general"),[m,c]=o.useState(null),[d,p]=o.useState("info"),[u,h]=o.useState(!1),f=o.useRef(null),g=o.useCallback((v,k="info")=>{c(v),p(k),setTimeout(()=>c(null),3e3)},[]),x=async v=>{var N;const k=(N=v.target.files)==null?void 0:N[0];if(k){if(k.size>2*1024*1024){g("File size cannot exceed 2MB","error");return}if(!k.type.startsWith("image/")){g("Please select a valid image file","error");return}try{h(!0),await s({image:k}),g("Logo updated","info")}catch(j){g((j==null?void 0:j.message)||"Failed to update logo","error")}finally{h(!1),f.current&&(f.current.value="")}}};return e&&!a?t.jsx(Me,{children:t.jsx(On,{className:"w-items-center w-justify-center",children:t.jsx(ye,{})})}):a?t.jsx(Me,{children:t.jsx(Mi,{children:t.jsx(Sr.Provider,{value:{screen:null,setScreen:()=>{},toast:g},children:t.jsxs(On,{className:"w-relative",children:[t.jsxs(Wm,{children:[t.jsxs("button",{type:"button",className:"w-avatar w-avatar--lg w-avatar-edit","data-busy":u?"":void 0,onClick:()=>{var v;return(v=f.current)==null?void 0:v.click()},disabled:u,title:"Change logo","aria-label":"Change organization logo",children:[a.image_url?t.jsx("img",{src:a.image_url,alt:a.name}):((w=a.name)==null?void 0:w.slice(0,2).toUpperCase())||"O",t.jsx("span",{className:"w-avatar-veil",children:u?t.jsx(ye,{size:14}):t.jsx(an,{size:16})})]}),t.jsx("input",{ref:f,type:"file",accept:"image/*",style:{display:"none"},onChange:x}),t.jsxs(Bm,{children:[t.jsx(Gm,{children:a.name}),t.jsx(qm,{children:a.member_count!=null?`${a.member_count} members`:"Organization settings"})]})]}),t.jsx(zm,{children:t.jsxs(Dm,{children:[t.jsx(Va,{$isActive:i==="general",onClick:()=>l("general"),children:t.jsxs(za,{children:[t.jsx(Sa,{size:16})," General"]})}),t.jsx(Va,{$isActive:i==="domains",onClick:()=>l("domains"),children:t.jsxs(za,{children:[t.jsx(Su,{size:16})," Domains"]})}),t.jsx(Va,{$isActive:i==="members",onClick:()=>l("members"),children:t.jsxs(za,{children:[t.jsx(ls,{size:16})," Members"]})}),t.jsx(Va,{$isActive:i==="invitations",onClick:()=>l("invitations"),children:t.jsxs(za,{children:[t.jsx(cl,{size:16})," Invitations"]})}),((b=n==null?void 0:n.b2b_settings)==null?void 0:b.custom_org_role_enabled)&&t.jsx(Va,{$isActive:i==="roles",onClick:()=>l("roles"),children:t.jsxs(za,{children:[t.jsx(Xt,{size:16})," Roles"]})}),((_=n==null?void 0:n.b2b_settings)==null?void 0:_.enterprise_sso_enabled)&&t.jsx(Va,{$isActive:i==="sso",onClick:()=>l("sso"),children:t.jsxs(za,{children:[t.jsx(Xt,{size:16})," SSO"]})})]})}),t.jsxs(Um,{children:[i==="general"&&t.jsx(Ym,{organization:a}),i==="domains"&&t.jsx(Jm,{organization:a}),i==="members"&&t.jsx(Xm,{organization:a}),i==="invitations"&&t.jsx(s4,{organization:a}),i==="roles"&&t.jsx(i4,{organization:a}),i==="sso"&&t.jsx(Tm,{organization:a})]}),m&&t.jsxs("div",{className:`w-toast w-toast--contained ${d==="error"?"w-toast--error":"w-toast--success"}`,children:[t.jsx("span",{className:"w-toast-ic",children:d==="error"?t.jsx(Ha,{size:12}):t.jsx(Ge,{size:12})}),t.jsx("span",{className:"w-toast-msg",children:m})]})]})})})}):t.jsx(Me,{children:t.jsx(Mi,{children:t.jsx(On,{className:"w-items-center w-justify-center",children:t.jsxs("div",{className:"w-empty",children:[t.jsx("span",{className:"w-empty-ic",children:t.jsx(ms,{size:20})}),t.jsx("h4",{children:"No Organization Selected"}),t.jsx(s0,{})]})})})})},Yc=({isOpen:e,onClose:a,title:s,showHeader:n,headerContent:i,footerContent:l,customContent:m,children:c,showCloseButton:d})=>t.jsx(ze,{isOpen:e,onClose:a,children:t.jsx(ze.Overlay,{children:t.jsxs(ze.Content,{className:"w-dialog--panel",children:[n&&t.jsx(ze.Header,{showCloseButton:d,children:i||s}),m||c||t.jsx(Kc,{}),l&&t.jsx(ze.Footer,{children:l})]})})}),Rr=({organizationId:e,onSuccess:a,onCancel:s,onCreateOrganization:n})=>t.jsx(Me,{children:t.jsx("div",{className:"w-flex w-justify-center w-full",children:t.jsx(Uc,{mode:"ws",organizationId:e,onSuccess:a,onCancel:s,onCreateOrganization:n})})}),Lr=({isOpen:e,onClose:a,onCreated:s,organizationId:n})=>{const[i,l]=o.useState(!1),[m,c]=o.useState(n),d=()=>{s==null||s(),a==null||a()},p=()=>{l(!0)},u=h=>{var g,x,w;const f=((x=(g=h==null?void 0:h.data)==null?void 0:g.organization)==null?void 0:x.id)??((w=h==null?void 0:h.organization)==null?void 0:w.id)??(h==null?void 0:h.id);f&&c(f),l(!1)};return t.jsx(Me,{children:t.jsx(ze,{isOpen:e,onClose:a,children:t.jsx(ze.Overlay,{children:t.jsx(ze.Content,{className:"w-dialog--create",children:i?t.jsx(un,{onSuccess:u,onCancel:()=>l(!1)}):t.jsx(Rr,{organizationId:m||n,onSuccess:d,onCancel:a,onCreateOrganization:p})})})})})},ht=(...e)=>e.filter(Boolean).join(" "),l4=({className:e,...a})=>t.jsx("div",{className:ht("w-contents",e),...a}),Hi=({className:e,...a})=>t.jsx("div",{className:ht("w-card","w-flex-col","w-full","w-minh-full",e),...a}),c4=({className:e,...a})=>t.jsx("div",{className:ht("w-tabsbar",e),...a}),d4=({className:e,...a})=>t.jsx("div",{className:ht("w-flex","w-items-center","w-gap-1","w-tabs",e),...a}),Os=({$isActive:e,className:a,...s})=>t.jsx("button",{className:ht("w-tab",e&&"w-tab--active",a),...s}),Zs=({className:e,...a})=>t.jsx("span",{className:ht("w-inline","w-gap-2",e),...a}),u4=({className:e,children:a,...s})=>t.jsx("div",{className:ht("w-tabbody",e),...s,children:t.jsx("div",{className:"w-tabpane",children:a})}),Qs=o.forwardRef(({className:e,...a},s)=>t.jsx("button",{ref:s,className:ht("w-kebab",e),...a}));Qs.displayName="IconButton";const Qc=({className:e,...a})=>t.jsx("div",{className:ht("w-sechead",e),...a}),Fi=({className:e,...a})=>t.jsx("div",{className:ht("w-flex","w-items-center","w-justify-between","w-gap-4",e),...a}),Ti=({className:e,...a})=>t.jsx("div",{className:ht("w-grow",e),...a}),Ii=({className:e,...a})=>t.jsx("div",{className:ht("w-flex","w-items-center","w-gap-3","w-none",e),...a}),Pr=({className:e,...a})=>t.jsx("div",{className:ht("w-full",e),...a}),m4=({className:e,...a})=>t.jsx("div",{className:ht("w-page-head",e),...a}),p4=({className:e,...a})=>t.jsx("div",{className:ht("w-grow","w-flex-col","w-gap-1",e),...a}),h4=({className:e,...a})=>t.jsx("div",{className:ht("w-sec","w-truncate",e),...a}),f4=({className:e,...a})=>t.jsx("div",{className:ht("w-secsub","w-truncate",e),...a}),Vi=({$first:e,className:a,...s})=>t.jsx("div",{className:ht("w-sec",a),...s}),w4=()=>{var E,R;const{activeWorkspace:e,loading:a,updateWorkspace:s}=zt(),{deleteWorkspace:n}=wa(),{deployment:i}=_e(),{toast:l}=_t(),[m,c]=o.useState((e==null?void 0:e.name)||""),[d,p]=o.useState((e==null?void 0:e.description)||""),[u,h]=o.useState({mfa_required:!1,ip_restrictions:!1,allowed_ips:""}),[f,g]=o.useState(!1),[x,w]=o.useState(""),[b,_]=o.useState(!1),[v,k]=o.useState(!1);o.useEffect(()=>{var F;e&&(c(e.name||""),p(e.description||""),h({mfa_required:e.enforce_2fa||!1,ip_restrictions:e.enable_ip_restriction||!1,allowed_ips:((F=e.whitelisted_ips)==null?void 0:F.join(`
106
106
  `))||""}))},[e]);const N=async()=>{if(!(!e||f))try{g(!0),await s({name:m,description:d,enforce_2fa:u.mfa_required,enable_ip_restriction:u.ip_restrictions,whitelisted_ips:u.allowed_ips.split(`
107
107
  `).filter(F=>F.trim())}),l("Changes saved","info")}catch(F){l(F.message||"Failed to save changes","error")}finally{g(!1)}},j=async()=>{if(!(!e||x!==e.name))try{_(!0),await n(e),l("Workspace deleted","info")}catch{l("Failed to delete workspace","error")}finally{_(!1),w("")}};if(a&&!e)return t.jsx(ye,{});if(!e)return null;const C=(E=i==null?void 0:i.b2b_settings)==null?void 0:E.enforce_mfa_per_workspace_enabled,y=(R=i==null?void 0:i.b2b_settings)==null?void 0:R.ip_allowlist_per_workspace_enabled;return t.jsxs("div",{className:"w-flex-col w-gap-4",children:[t.jsxs("div",{className:"w-flex-col w-gap-3",children:[t.jsxs(We,{children:[t.jsx(Ve,{htmlFor:"name",children:"Workspace name"}),t.jsx(xe,{id:"name",value:m,onChange:F=>c(F.target.value),onBlur:N,placeholder:"Workspace name",required:!0})]}),t.jsxs(We,{children:[t.jsx(Ve,{htmlFor:"description",children:"Description"}),t.jsx(xe,{id:"description",as:"textarea",value:d,onChange:F=>p(F.target.value),onBlur:N,placeholder:"Optional description",className:"w-input--area"})]})]}),(C||y)&&t.jsxs("div",{className:"w-flex-col w-gap-3",children:[t.jsx(Vi,{children:"Security"}),C&&t.jsxs(Fi,{children:[t.jsxs(Ti,{children:[t.jsx("div",{className:"w-sec",children:"Multi-factor authentication"}),t.jsx("p",{className:"w-secsub",children:"Require all workspace members to set up MFA."})]}),t.jsx(Ii,{children:t.jsx(Oa,{checked:u.mfa_required,onChange:()=>{h(F=>({...F,mfa_required:!F.mfa_required})),setTimeout(N,0)}})})]}),y&&t.jsxs(t.Fragment,{children:[t.jsxs(Fi,{children:[t.jsxs(Ti,{children:[t.jsx("div",{className:"w-sec",children:"IP restrictions"}),t.jsx("p",{className:"w-secsub",children:"Only allow access from specific IP addresses."})]}),t.jsx(Ii,{children:t.jsx(Oa,{checked:u.ip_restrictions,onChange:()=>{h(F=>({...F,ip_restrictions:!F.ip_restrictions})),setTimeout(N,0)}})})]}),u.ip_restrictions&&t.jsxs(We,{children:[t.jsx(Ve,{htmlFor:"allowed_ips",children:"Allowed IP addresses"}),t.jsx(xe,{id:"allowed_ips",as:"textarea",value:u.allowed_ips,onChange:F=>h(A=>({...A,allowed_ips:F.target.value})),onBlur:N,placeholder:`192.168.1.1
108
- 10.0.0.0/24`,className:"w-input--area w-mono-sm"})]})]})]}),t.jsxs("div",{className:"w-flex-col w-gap-3",children:[t.jsx(Vi,{children:"Danger zone"}),t.jsxs("div",{className:"w-danger",children:[t.jsxs("div",{className:"w-grow",children:[t.jsx("div",{className:"w-sec",children:"Delete workspace"}),t.jsx("div",{className:"w-secsub",children:"Once you delete this workspace, there is no going back."})]}),t.jsx(se,{$size:"sm",$outline:!0,$destructive:!0,onClick:()=>{k(!v),w("")},children:v?"Cancel":"Delete workspace"})]}),v&&t.jsxs("div",{className:"w-flex-col w-gap-3",children:[t.jsxs(We,{children:[t.jsxs(Ve,{htmlFor:"confirm_workspace_name",children:["Type ",t.jsx("strong",{children:e.name})," to confirm"]}),t.jsx(xe,{id:"confirm_workspace_name",type:"text",value:x,onChange:F=>w(F.target.value),placeholder:e.name})]}),t.jsx(se,{$size:"sm",$destructive:!0,onClick:j,disabled:x!==e.name||b,children:b?t.jsx(ye,{size:12}):"Delete forever"})]})]})]})},g4=({onClose:e,onSuccess:a,roles:s,triggerRef:n})=>{const i=o.useRef(null),[l,m]=o.useState(""),[c,d]=o.useState(null),[p,u]=o.useState(!1),[h,f]=o.useState(!1),{toast:g}=_t(),{inviteMember:x}=zt(),w=xt({contentRef:i,triggerRef:n??{current:null},isOpen:h,minWidth:360,defaultMaxHeight:320}),b=s.map(k=>({value:k.id,label:k.name}));o.useEffect(()=>{f(!0);const k=C=>{i.current&&!i.current.contains(C.target)&&(e==null||e())},N=C=>{C.key==="Escape"&&(e==null||e())},j=setTimeout(()=>{document.addEventListener("mousedown",k),document.addEventListener("keydown",N)},100);return()=>{clearTimeout(j),document.removeEventListener("mousedown",k),document.removeEventListener("keydown",N)}},[e]);const _=k=>/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(k),v=async()=>{const k=l.trim().toLowerCase();if(!(!k||!c)){if(!_(k)){g("Please enter a valid email address","error");return}if(k.length>320){g("Email address is too long","error");return}u(!0);try{await x({email:k,workspaceRoleId:c.id}),a==null||a()}catch(N){const j=N.message||"Failed to send invitation. Please try again.";g(j,"error")}finally{u(!1)}}};return h?t.jsxs("div",{ref:i,className:"w-pop w-pop--wide",style:{position:"fixed",zIndex:1001,top:(w==null?void 0:w.top)!==void 0?`${w.top}px`:void 0,bottom:(w==null?void 0:w.bottom)!==void 0?`${w.bottom}px`:void 0,left:(w==null?void 0:w.left)!==void 0?`${w.left}px`:void 0,right:(w==null?void 0:w.right)!==void 0?`${w.right}px`:void 0,maxHeight:w!=null&&w.maxHeight?`${w.maxHeight}px`:void 0,visibility:w?"visible":"hidden"},onClick:k=>k.stopPropagation(),role:"dialog","aria-labelledby":"invite-workspace-member-title","aria-modal":"true",children:[t.jsxs("div",{className:"w-pop-body",children:[t.jsx("div",{className:"w-pop-title",id:"invite-workspace-member-title",children:"Invite member"}),t.jsxs(We,{children:[t.jsx(Ve,{children:"Email Address"}),t.jsx(xe,{type:"email",placeholder:"colleague@company.com",value:l,onChange:k=>m(k.target.value),autoFocus:!0,"aria-label":"Email address for workspace invitation","aria-describedby":"workspace-email-help"})]}),t.jsxs(We,{children:[t.jsx(Ve,{children:"Role"}),t.jsx(dn,{options:b,value:c==null?void 0:c.id,onChange:k=>d(s.find(N=>N.id===k)),placeholder:"Select a role","aria-label":"Select role for invited workspace member"})]})]}),t.jsxs("div",{className:"w-pop-foot",children:[t.jsx("button",{type:"button",className:"w-btn w-btn--ghost w-btn--sm",onClick:e,children:"Cancel"}),t.jsx("button",{type:"button",className:"w-btn w-btn--primary w-btn--sm",onClick:v,disabled:!l||!c||p,children:p?t.jsx(ye,{size:14}):"Send invite"})]})]}):null},x4=()=>{const{activeWorkspace:e,getMembers:a,getRoles:s,removeMember:n,addMemberRole:i,removeMemberRole:l}=zt(),{session:m}=ot(),{toast:c}=_t(),[d,p]=o.useState(""),[u,h]=o.useState(1),[f]=o.useState(10),[g,x]=o.useState(""),[w,b]=o.useState(!1),_=o.useRef(null);o.useEffect(()=>{const A=setTimeout(()=>{x(d),h(1)},500);return()=>clearTimeout(A)},[d]);const{data:v,mutate:k}=ke(e?`wacht-api-workspaces:${e.id}:members:${u}:${f}:${g}`:null,()=>a==null?void 0:a({page:u,limit:f,search:g}),{keepPreviousData:!0}),N=(v==null?void 0:v.data)||[],j=(v==null?void 0:v.meta)||{total:0,limit:10},C=Math.ceil(j.total/(j.limit||10)),{data:y=[]}=ke(e?`wacht-api-workspaces:${e.id}:roles`:null,()=>s()||[]),E=y,R=async(A,I,L)=>{try{L?(await l(A,I),c("Role removed","info")):(await i(A,I),c("Role added","info")),k()}catch{c("Failed to update role","error")}},F=async A=>{try{await n(A),c("Member removed","info"),k()}catch{c("Failed to remove member","error")}};return v?t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"w-toolbar",children:[t.jsx(Ic,{value:d,onChange:p,placeholder:"Search members..."}),t.jsxs("div",{className:"w-flex w-items-center w-gap-3",children:[j.total>0&&t.jsxs("div",{className:"w-text-muted w-secsub",children:[j.total," member",j.total!==1?"s":""]}),t.jsx(se,{ref:_,onClick:()=>b(!0),$size:"sm",children:"Invite"})]})]}),w&&t.jsx(g4,{onClose:()=>b(!1),onSuccess:()=>{k(),b(!1)},roles:E,triggerRef:_}),N.length===0?t.jsx(Ct,{title:d?"No members match":"No members yet",description:"Members added to the organization can be invited here."}):t.jsx(t.Fragment,{children:t.jsx(Pr,{children:t.jsxs($t,{children:[t.jsx(Ot,{children:t.jsxs(it,{children:[t.jsx($e,{children:"Member"}),t.jsx($e,{children:"Joined"}),t.jsx($e,{children:"Role"})]})}),t.jsx(Zt,{children:N.map(A=>t.jsxs(it,{children:[t.jsx(Ke,{children:t.jsx(v4,{member:A,session:m})}),t.jsx(Ke,{children:new Date(A.created_at).toLocaleDateString()}),t.jsx(Ht,{children:t.jsx(b4,{member:A,roles:E,onToggle:(I,L)=>R(A.id,I,L),onRemove:()=>F(A.id)})})]},A.id))})]})})}),C>1&&t.jsxs("div",{className:"w-flex w-items-center w-justify-center w-gap-4",children:[t.jsx(se,{onClick:()=>h(A=>Math.max(1,A-1)),disabled:u===1,$size:"sm",children:"Previous"}),t.jsxs("span",{className:"w-secsub",children:[u," / ",C]}),t.jsx(se,{onClick:()=>h(A=>Math.min(C,A+1)),disabled:u===C,$size:"sm",children:"Next"})]})]}):t.jsx(ye,{})},v4=({member:e,session:a,subtitle:s})=>{var m,c,d;const n=e.public_user_data||e.user,i=(n==null?void 0:n.id)===((m=a==null?void 0:a.active_signin)==null?void 0:m.user_id),l=(p="",u="")=>`${p[0]||""}${u[0]||""} `.toUpperCase();return t.jsxs("div",{className:"w-flex w-items-center w-gap-3",children:[t.jsx("div",{className:"w-avatar",children:n!=null&&n.profile_picture_url?t.jsx("img",{src:n.profile_picture_url,alt:"Avatar"}):l(n==null?void 0:n.first_name,n==null?void 0:n.last_name)||"?"}),t.jsxs("div",{children:[t.jsxs("div",{className:"w-flex w-items-center w-gap-2",children:[t.jsx("span",{className:"w-sec",children:n?`${n.first_name||""} ${n.last_name||""} `.trim()||((c=n.primary_email_address)==null?void 0:c.email):"Unknown"}),i&&t.jsx("span",{className:"w-pill",children:"You"})]}),t.jsxs("div",{className:"w-flex w-wrap w-gap-2 w-secsub",children:[t.jsx("span",{children:(d=n==null?void 0:n.primary_email_address)==null?void 0:d.email}),s&&t.jsxs("span",{className:"w-text-muted",children:["• ",s]})]})]})]})},b4=({member:e,roles:a,onToggle:s,onRemove:n})=>{var m;const i=e.roles||[],l=c=>i.some(d=>d.id===c);return t.jsxs(js,{children:[t.jsx(ks,{children:t.jsxs(se,{$outline:!0,$size:"sm",className:"w-justify-between w-rolepick-btn",children:[i.length>0?(m=i==null?void 0:i[0])==null?void 0:m.name:"No role"," ",t.jsx(Dt,{size:14})]})}),t.jsxs(_s,{children:[a.map(c=>{const d=l(c.id);return t.jsx(ea,{onClick:()=>s(c.id,d),children:t.jsxs("div",{className:"w-flex w-justify-between w-full w-gap-3",children:[t.jsx("span",{children:c.name}),d&&t.jsx(Ge,{size:14,className:"w-text-success"})]})},c.id)}),t.jsx(Fc,{}),t.jsx(ea,{$destructive:!0,onClick:n,children:t.jsxs("div",{className:"w-flex w-items-center w-gap-2",children:[t.jsx(gr,{size:14})," Remove Member"]})})]})]})},y4=({onClose:e,onSuccess:a,roles:s,createInvitation:n,triggerRef:i})=>{const l=o.useRef(null),[m,c]=o.useState(""),[d,p]=o.useState(s[0]||null),[u,h]=o.useState(!1),[f,g]=o.useState(!1),{toast:x}=_t(),w=xt({contentRef:l,triggerRef:i,isOpen:f,minWidth:360,defaultMaxHeight:320}),b=s.map(k=>({value:k.id,label:k.name})),_=k=>/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(k),v=async()=>{const k=m.trim().toLowerCase();if(!(!k||!d)){if(!_(k)){x("Please enter a valid email address","error");return}if(k.length>320){x("Email address is too long","error");return}h(!0);try{await n({email:k,role_id:d.id}),a()}catch(N){x(N.message||"Failed to send invitation. Please try again.","error")}finally{h(!1)}}};return o.useEffect(()=>{g(!0);const k=j=>{l.current&&!l.current.contains(j.target)&&(e==null||e())},N=j=>{j.key==="Escape"&&(e==null||e())};return document.addEventListener("mousedown",k),document.addEventListener("keydown",N),()=>{document.removeEventListener("mousedown",k),document.removeEventListener("keydown",N)}},[e]),f?t.jsxs("div",{ref:l,className:"w-pop w-pop--wide w-pop-body",style:{position:"fixed",zIndex:1001,top:(w==null?void 0:w.top)!==void 0?`${w.top}px`:void 0,bottom:(w==null?void 0:w.bottom)!==void 0?`${w.bottom}px`:void 0,left:(w==null?void 0:w.left)!==void 0?`${w.left}px`:void 0,right:(w==null?void 0:w.right)!==void 0?`${w.right}px`:void 0,visibility:w?"visible":"hidden"},onClick:k=>k.stopPropagation(),role:"dialog","aria-labelledby":"invite-member-title","aria-modal":"true",children:[t.jsx("div",{className:"w-pop-title",id:"invite-member-title",children:"Invite member"}),t.jsxs("div",{className:"w-field",children:[t.jsx("label",{className:"w-label",children:"Email"}),t.jsx(xe,{type:"email",placeholder:"colleague@company.com",value:m,onChange:k=>c(k.target.value),onKeyDown:k=>{k.key==="Enter"&&m&&d&&v()},autoFocus:!0,"aria-label":"Email address for invitation"})]}),t.jsxs("div",{className:"w-field",children:[t.jsx("label",{className:"w-label",children:"Role"}),t.jsx(dn,{options:b,value:d==null?void 0:d.id,onChange:k=>p(s.find(N=>N.id===k)),placeholder:"Select a role","aria-label":"Select role for invited member"})]}),t.jsxs("div",{className:"w-flex w-gap-2",children:[t.jsx(se,{$size:"sm",$outline:!0,$fullWidth:!0,onClick:e,children:"Cancel"}),t.jsx(se,{$size:"sm",$fullWidth:!0,onClick:v,disabled:!m||!d||u,children:u?t.jsx(ye,{size:12}):"Send invite"})]})]}):null},j4=()=>{const{activeWorkspace:e,loading:a,getRoles:s,getInvitations:n,inviteMember:i,discardInvitation:l,resendInvitation:m}=zt(),{toast:c}=_t(),[d,p]=o.useState(!0),[u,h]=o.useState(!0),[f,g]=o.useState([]),[x,w]=o.useState([]),[b,_]=o.useState(!1),v=o.useRef(null),k=async()=>{if(e){p(!0),h(!0);try{const[C,y]=await Promise.all([s(),n()]);w(C),g(y)}catch{}finally{p(!1),h(!1)}}};o.useEffect(()=>{k()},[e==null?void 0:e.id]);const N=async C=>{try{await l(C),k(),c("Invitation cancelled","info")}catch{c("Failed to cancel invitation","error")}},j=async C=>{try{await m(C),k(),c("Invitation resent","info")}catch{c("Failed to resend invitation","error")}};return a||d||u?t.jsx(ye,{}):t.jsxs(t.Fragment,{children:[t.jsxs(Qc,{children:[t.jsxs("div",{className:"w-grow",children:[t.jsx("div",{className:"w-sec",children:"Invitations"}),t.jsx("div",{className:"w-secsub",children:"Pending invites to join this workspace."})]}),t.jsx(se,{ref:v,onClick:()=>_(!0),$size:"sm",children:"Invite"})]}),b&&t.jsx(y4,{onClose:()=>_(!1),onSuccess:()=>{k(),_(!1),c("Invitation sent","info")},roles:x,createInvitation:C=>i({email:C.email,workspaceRoleId:C.role_id}),triggerRef:v}),f.length===0?t.jsx(Ct,{title:"No pending invitations",description:"Invite members to your workspace."}):t.jsx(t.Fragment,{children:t.jsx(Pr,{children:t.jsxs($t,{children:[t.jsx(Ot,{children:t.jsxs(it,{children:[t.jsx($e,{children:"Email"}),t.jsx($e,{children:"Role"}),t.jsx($e,{children:"Invited"}),t.jsx($e,{})]})}),t.jsx(Zt,{children:f.map(C=>{var y,E;return t.jsxs(it,{children:[t.jsx(Ke,{children:C.email}),t.jsx(Ke,{children:((y=C.initial_workspace_role)==null?void 0:y.name)||((E=C.initial_organization_role)==null?void 0:E.name)||"No role"}),t.jsx(Ke,{children:new Date(C.created_at).toLocaleDateString()}),t.jsx(Ht,{children:t.jsx(_4,{onResend:()=>j(C.id),onCancel:()=>N(C.id)})})]},C.id)})})]})})})]})},_4=({onResend:e,onCancel:a})=>t.jsxs(js,{children:[t.jsx(ks,{children:t.jsx(Qs,{children:"•••"})}),t.jsxs(_s,{children:[t.jsxs(ea,{onClick:e,children:[t.jsx(Nl,{size:16})," Resend"]}),t.jsxs(ea,{$destructive:!0,onClick:a,children:[t.jsx(gr,{size:16})," Cancel"]})]})]}),zi=({onClose:e,onSuccess:a,role:s,triggerRef:n})=>{var C,y;const i=o.useRef(null),[l,m]=o.useState((s==null?void 0:s.name)||""),[c,d]=o.useState((s==null?void 0:s.permissions)||[]),[p,u]=o.useState(!1),[h,f]=o.useState(!1),{deployment:g}=_e(),{toast:x}=_t(),w=xt({contentRef:i,triggerRef:n??{current:null},isOpen:h,minWidth:400,defaultMaxHeight:500}),b=!!s,_=((C=g==null?void 0:g.b2b_settings)==null?void 0:C.workspace_permissions)||((y=g==null?void 0:g.b2b_settings)==null?void 0:y.organization_permissions)||[],v=Array.isArray(_)?_.map(E=>({value:E,label:E})):[];o.useEffect(()=>{f(!0);const E=A=>{i.current&&!i.current.contains(A.target)&&(e==null||e())},R=A=>{A.key==="Escape"&&(e==null||e())},F=setTimeout(()=>{document.addEventListener("mousedown",E),document.addEventListener("keydown",R)},100);return()=>{clearTimeout(F),document.removeEventListener("mousedown",E),document.removeEventListener("keydown",R)}},[e]);const k=E=>E.trim().replace(/[<>"'&]/g,""),N=E=>E.length>=2&&E.length<=50&&/^[a-zA-Z0-9\s_-]+$/.test(E),j=async()=>{const E=k(l);if(!E){x("Please enter a role name","error");return}if(!N(E)){x("Role name must be 2–50 characters, letters/numbers/spaces only.","error");return}if(c.length===0){x("Please select at least one permission","error");return}u(!0);try{const R={id:s==null?void 0:s.id,name:E,permissions:c};a==null||a(R)}catch(R){x(R.message||`Failed to ${b?"update":"create"} role. Please try again.`,"error")}finally{u(!1)}};return h?t.jsxs("div",{ref:i,className:"w-pop w-pop--wide",style:{position:"fixed",zIndex:1001,top:(w==null?void 0:w.top)!==void 0?`${w.top}px`:void 0,bottom:(w==null?void 0:w.bottom)!==void 0?`${w.bottom}px`:void 0,left:(w==null?void 0:w.left)!==void 0?`${w.left}px`:void 0,right:(w==null?void 0:w.right)!==void 0?`${w.right}px`:void 0,visibility:w?"visible":"hidden"},onClick:E=>E.stopPropagation(),role:"dialog","aria-labelledby":"role-dialog-title","aria-modal":"true",children:[t.jsxs("div",{className:"w-pop-body",children:[t.jsx("div",{className:"w-pop-title",id:"role-dialog-title",children:b?"Edit role":"New role"}),t.jsxs("label",{className:"w-field",children:[t.jsx("span",{className:"w-label",children:"Name"}),t.jsx(xe,{type:"text",placeholder:"e.g. Admin, Editor, Viewer",value:l,onChange:E=>m(E.target.value),autoFocus:!0,"aria-label":"Role name"})]}),t.jsxs("label",{className:"w-field",children:[t.jsx("span",{className:"w-label",children:"Permissions"}),t.jsx(Dc,{options:v,value:c,onChange:d,placeholder:"Select permissions","aria-label":"Select permissions for role"})]})]}),t.jsxs("div",{className:"w-pop-foot",children:[t.jsx("button",{type:"button",className:"w-btn w-btn--ghost w-btn--sm",onClick:e,children:"Cancel"}),t.jsx("button",{type:"button",className:"w-btn w-btn--primary w-btn--sm",onClick:j,disabled:!l||p,children:p?t.jsx(ye,{size:12}):b?"Update":"Create"})]})]}):null},k4=()=>{var N;const{activeWorkspace:e,loading:a,getRoles:s,createRole:n,deleteRole:i}=zt(),{deployment:l}=_e(),{toast:m}=_t(),[c,d]=o.useState({isOpen:!1}),[p,u]=o.useState(null),[h,f]=o.useState(null),g=o.useRef(null),x=o.useRef(new Map),{data:w=[],isLoading:b,mutate:_}=ke(e?`wacht-api-workspaces:${e.id}:roles`:null,()=>s()||[]),v=async j=>{try{await n(j.name,j.permissions||[]),m("Role saved successfully","info"),d({isOpen:!1}),_()}catch{m("Failed to save role","error")}},k=async j=>{try{await i(j),m("Role deleted","info"),u(null),_()}catch{m("Failed to delete role","error")}};return a||b?t.jsx(ye,{}):t.jsxs(t.Fragment,{children:[t.jsxs(Qc,{children:[t.jsxs("div",{className:"w-grow",children:[t.jsx("div",{className:"w-sec",children:"Roles"}),t.jsx("div",{className:"w-secsub",children:"Define granular permissions for this workspace."})]}),((N=l==null?void 0:l.b2b_settings)==null?void 0:N.custom_workspace_role_enabled)&&t.jsx(se,{ref:g,onClick:()=>d({isOpen:!0,triggerElement:g.current}),$size:"sm",children:"Add role"})]}),c.isOpen&&!c.role&&t.jsx(zi,{triggerRef:{current:c.triggerElement||null},onClose:()=>d({isOpen:!1}),onSuccess:v}),w.length===0?t.jsx(Ct,{title:"No roles yet",description:"Create workspace-specific roles to manage access."}):t.jsx(t.Fragment,{children:t.jsx(Pr,{children:t.jsxs($t,{children:[t.jsx(Ot,{children:t.jsxs(it,{children:[t.jsx($e,{children:"Role"}),t.jsx($e,{children:"Permissions"}),t.jsx($e,{})]})}),t.jsx(Zt,{children:w.map(j=>{var C;return t.jsxs(it,{children:[t.jsx(Ke,{children:t.jsxs("div",{className:"w-flex w-items-center w-gap-2 w-wrap",children:[t.jsx("span",{className:"w-sec",children:j.name}),!dr(j)&&t.jsx("span",{className:"w-pill",children:"Default"})]})}),t.jsx(Ke,{children:t.jsxs("span",{className:"w-text-secondary",children:[(C=j.permissions)==null?void 0:C.join(", "),!dr(j)&&" • Cannot be edited or deleted"]})}),t.jsx(Ht,{children:t.jsx(C4,{role:j,onEdit:y=>d({isOpen:!0,role:j,triggerElement:y}),onDelete:()=>u(j.id),open:h===j.id,onOpenChange:y=>f(y?j.id:null),dropdownButtonRefs:x})})]},j.id)})})]})})}),p&&t.jsx(Ya,{title:"Delete role?",description:"Are you sure? This will remove the role from all workspace members.",onConfirm:()=>{const j=w.find(C=>C.id===p);j&&k(j)},onCancel:()=>u(null)}),c.isOpen&&c.role&&t.jsx(zi,{role:c.role,triggerRef:{current:c.triggerElement||null},onClose:()=>d({isOpen:!1}),onSuccess:v})]})},C4=({role:e,onEdit:a,onDelete:s,open:n,onOpenChange:i,dropdownButtonRefs:l})=>dr(e)?t.jsxs(js,{open:n,openChange:i,children:[t.jsx(ks,{children:t.jsx(Qs,{ref:c=>{c&&l.current.set(e.id,c)},children:"•••"})}),t.jsxs(_s,{children:[t.jsx(ea,{onClick:()=>a(l.current.get(e.id)??null),children:"Edit Role"}),t.jsxs(ea,{$destructive:!0,onClick:s,children:[t.jsx(gr,{size:16})," Remove Role"]})]})]}):t.jsx(Qs,{disabled:!0,title:"Deployment roles cannot be edited","aria-label":"Deployment roles cannot be edited",children:"•••"}),N4=e=>(e||"").slice(0,2).toUpperCase()||"W",Jc=()=>{var b,_;const{activeWorkspace:e,loading:a,updateWorkspace:s}=zt(),{deployment:n}=_e(),[i,l]=o.useState("general"),[m,c]=o.useState(null),[d,p]=o.useState("info"),[u,h]=o.useState(!1),f=o.useRef(null),g=o.useCallback((v,k="info")=>{c(v),p(k),setTimeout(()=>c(null),3e3)},[]),x=async v=>{var N;const k=(N=v.target.files)==null?void 0:N[0];if(k){if(k.size>2*1024*1024){g("File size cannot exceed 2MB","error");return}if(!k.type.startsWith("image/")){g("Please select a valid image file","error");return}try{h(!0),await s({image:k}),g("Logo updated","info")}catch(j){g((j==null?void 0:j.message)||"Failed to update logo","error")}finally{h(!1),f.current&&(f.current.value="")}}};if(a&&!e)return t.jsx(Me,{children:t.jsx(Hi,{className:"w-items-center w-justify-center",children:t.jsx(ye,{})})});if(!e)return null;const w=(b=e.organization)==null?void 0:b.name;return t.jsx(Me,{children:t.jsx(l4,{children:t.jsx(Sr.Provider,{value:{screen:null,setScreen:()=>{},toast:g},children:t.jsxs(Hi,{className:"w-relative",children:[t.jsxs(m4,{children:[t.jsxs("button",{type:"button",className:"w-avatar w-avatar--lg w-avatar-edit",onClick:()=>{var v;return(v=f.current)==null?void 0:v.click()},disabled:u,"data-busy":u?"":void 0,title:"Change logo","aria-label":"Change workspace logo",children:[e.image_url?t.jsx("img",{src:e.image_url,alt:e.name}):N4(e.name),t.jsx("span",{className:"w-avatar-veil",children:u?t.jsx(ye,{size:14}):t.jsx(an,{size:16})})]}),t.jsx("input",{ref:f,type:"file",accept:"image/*",className:"w-none",hidden:!0,onChange:x}),t.jsxs(p4,{children:[t.jsx(h4,{children:e.name}),t.jsx(f4,{children:w?`${w} · Workspace settings`:"Workspace settings"})]})]}),t.jsx(c4,{children:t.jsxs(d4,{children:[t.jsx(Os,{$isActive:i==="general",onClick:()=>l("general"),children:t.jsxs(Zs,{children:[t.jsx(Sa,{size:14})," General"]})}),t.jsx(Os,{$isActive:i==="members",onClick:()=>l("members"),children:t.jsxs(Zs,{children:[t.jsx(ls,{size:14})," Members"]})}),t.jsx(Os,{$isActive:i==="invitations",onClick:()=>l("invitations"),children:t.jsxs(Zs,{children:[t.jsx(Nl,{size:14})," Invitations"]})}),((_=n==null?void 0:n.b2b_settings)==null?void 0:_.custom_workspace_role_enabled)&&t.jsx(Os,{$isActive:i==="roles",onClick:()=>l("roles"),children:t.jsxs(Zs,{children:[t.jsx(Xt,{size:14})," Roles"]})})]})}),t.jsxs(u4,{children:[i==="general"&&t.jsx(w4,{}),i==="members"&&t.jsx(x4,{}),i==="invitations"&&t.jsx(j4,{}),i==="roles"&&t.jsx(k4,{})]}),m&&t.jsxs("div",{className:`w-toast w-toast--contained ${d==="error"?"w-toast--error":"w-toast--success"}`,children:[t.jsx("span",{className:"w-toast-ic",children:d==="error"?t.jsx(Ha,{size:14}):t.jsx(Ge,{size:14})}),t.jsx("span",{className:"w-toast-msg",children:m})]})]})})})})},$r=({isOpen:e,onClose:a,title:s,showHeader:n,headerContent:i,footerContent:l,customContent:m,children:c,showCloseButton:d})=>t.jsx(ze,{isOpen:e,onClose:a,children:t.jsx(ze.Overlay,{children:t.jsxs(ze.Content,{className:"w-dialog--panel",children:[n&&t.jsx(ze.Header,{showCloseButton:d,children:i||s}),m||c||t.jsx(Jc,{}),l&&t.jsx(ze.Footer,{children:l})]})})}),Xc=["organization:admin"],e0=["organization:admin","organization:manage"],t0=["workspace:admin"],a0=["workspace:admin","workspace:manage"];function Or(e,a){return e!=null&&e.roles?e.roles.some(s=>{var n;return(n=s.permissions)==null?void 0:n.some(i=>a.includes(i))}):!1}function Zr(e){return Or(e,e0)}function S4(e){return Or(e,Xc)}function Hr(e,a){return e!=null&&e.roles?e.roles.some(s=>{var n;return(n=s.permissions)==null?void 0:n.some(i=>a.includes(i))}):!1}function Fr(e){return Hr(e,a0)}function E4(e){return Hr(e,t0)}const s0=({showPersonal:e=!0})=>{var Se,qe,le;const[a,s]=o.useState(!1),[n,i]=o.useState(!1),[l,m]=o.useState(new Set),c=o.useRef(null),d=o.useRef(null),p=xt({triggerRef:c,isOpen:a,minWidth:300}),u=Kt(!1),h=Kt(!1),f=Kt(!1),g=Kt(!1),[x,w]=o.useState(null),[b,_]=o.useState(null),{organizationMemberships:v,loading:k,refetch:N}=fa(),{activeOrganization:j,activeMembership:C,leave:y}=ha(),{activeWorkspace:E,activeMembership:R,leave:F}=zt(),{workspaces:A,loading:I}=wa(),{session:L,switchOrganization:S,switchWorkspace:O}=ot(),{deployment:P}=_e(),$=P==null?void 0:P.b2b_settings.organizations_enabled,Z=$&&(P==null?void 0:P.b2b_settings.workspaces_enabled),H=P==null?void 0:P.b2b_settings.allow_users_to_create_orgs,M=!C,B=o.useMemo(()=>{var Y,q;return M?{name:"Personal account",image_url:(q=(Y=L==null?void 0:L.active_signin)==null?void 0:Y.user)==null?void 0:q.profile_picture_url,isPersonal:!0}:{name:Z&&E?`${j==null?void 0:j.name} / ${E.name}`:(j==null?void 0:j.name)||"",image_url:j==null?void 0:j.image_url,isPersonal:!1}},[M,j,E,L,Z]);if(o.useEffect(()=>{j&&Z&&m(V=>{if(V.has(j.id))return V;const Y=new Set(V);return Y.add(j.id),Y})},[j,Z]),o.useEffect(()=>{if(!a)return;let V=null;const Y=setTimeout(()=>{const q=G=>{var z,me;const de=G.target;(z=c.current)!=null&&z.contains(de)||(me=d.current)!=null&&me.contains(de)||(s(!1),_(null))};document.addEventListener("mousedown",q),V=()=>document.removeEventListener("mousedown",q)},50);return()=>{clearTimeout(Y),V==null||V()}},[a]),o.useEffect(()=>{if(!b)return;const V=setTimeout(()=>_(null),5e3);return()=>clearTimeout(V)},[b]),!$)return null;const D=V=>V.split(" ").map(Y=>Y[0]).join("").toUpperCase().slice(0,2),W=V=>{i(!0),S(V).finally(()=>i(!1))},K=V=>{i(!0),O(V).finally(()=>i(!1))},ee=V=>{m(Y=>{const q=new Set(Y);return q.has(V)?q.delete(V):q.add(V),q})},ce=()=>{h.open(),s(!1)},be=()=>{g.open(),s(!1)},Q=async()=>{if(y){_(null);try{await y(),await N(),s(!1)}catch(V){_(V instanceof Error?V.message:"Failed to leave organization")}}},ie=async()=>{if(F){_(null);try{await F(),s(!1)}catch(V){_(V instanceof Error?V.message:"Failed to leave workspace")}}},ne=!!((Se=C==null?void 0:C.eligibility_restriction)!=null&&Se.type)&&C.eligibility_restriction.type!=="none",U=!!j&&!ne&&Zr(C),Qe=!!Z&&!!E&&!ne&&Fr(R);return!!!L||k||Z&&I?t.jsx(Me,{children:t.jsx("div",{className:"w-full w-relative",children:t.jsxs("div",{className:"w-combo",children:[t.jsx("span",{className:"w-skel",style:{width:20,height:20}}),t.jsx("span",{className:"w-skel w-grow",style:{height:12}})]})})}):t.jsx(Me,{children:t.jsxs("div",{className:"w-full w-relative",children:[t.jsxs("button",{ref:c,className:"w-orgtrigger","data-open":a?"":void 0,onClick:()=>{s(!a),a||_(null)},disabled:n,children:[t.jsx("span",{className:`w-avatar w-avatar--sm${B.isPersonal,""}`,children:B.image_url?t.jsx("img",{src:B.image_url,alt:B.name}):B.isPersonal?t.jsx(ps,{size:11}):D(B.name)}),t.jsx("span",{className:"w-grow w-truncate",children:B.name}),t.jsx(yu,{size:13})]}),typeof window<"u"&&Xs.createPortal(t.jsxs("div",{ref:d,className:"wacht-root w-menu w-flex-col",style:{position:"fixed",width:300,maxWidth:"calc(100vw - 16px)",maxHeight:p!=null&&p.maxHeight?`${p.maxHeight}px`:420,padding:0,zIndex:99999,top:(p==null?void 0:p.top)!==void 0?`${p.top}px`:void 0,bottom:(p==null?void 0:p.bottom)!==void 0?`${p.bottom}px`:void 0,left:(p==null?void 0:p.left)!==void 0?`${p.left}px`:void 0,right:(p==null?void 0:p.right)!==void 0?`${p.right}px`:void 0,visibility:p&&a?"visible":"hidden",opacity:a&&p?1:0,transform:a?"translateY(0)":"translateY(-4px)",pointerEvents:a?"auto":"none",transition:`opacity 0.15s ease, transform 0.15s ease, visibility 0s linear ${a?"0s":"0.15s"}`},children:[b&&t.jsxs("div",{className:"w-banner w-banner--error w-switch-banner",children:[t.jsx(Aa,{size:13}),t.jsx("span",{className:"w-banner-txt w-text-error",children:b})]}),t.jsx("div",{className:"w-grow w-switch-body",children:k||I?t.jsx(t.Fragment,{children:[1,2,3].map(V=>t.jsxs("div",{className:"w-flex w-items-center w-gap-3",style:{padding:"0 8px",height:34},children:[t.jsx("span",{className:"w-skel",style:{width:22,height:22}}),t.jsx("span",{className:"w-skel",style:{width:V===2?"60%":"80%",height:11}})]},V))}):t.jsxs(t.Fragment,{children:[e&&t.jsxs("button",{className:"w-menu-item",onClick:()=>{M||W()},disabled:n||M,children:[t.jsx("span",{className:"w-avatar w-avatar--sm",children:(le=(qe=L==null?void 0:L.active_signin)==null?void 0:qe.user)!=null&&le.profile_picture_url?t.jsx("img",{src:L.active_signin.user.profile_picture_url,alt:"Personal"}):t.jsx(ps,{size:12})}),t.jsx("span",{className:"w-grow w-truncate",children:"Personal account"}),M&&t.jsx(Ge,{size:13,className:"w-text-primary w-none"})]}),t.jsx("hr",{className:"w-hr"}),t.jsx("div",{className:"w-menu-label",children:"Organizations"}),v==null?void 0:v.map(V=>{var me,st;const Y=V.organization,q=Y.id===(j==null?void 0:j.id),G=l.has(Y.id),de=Z?(A==null?void 0:A.filter(Oe=>Oe.organization.id===Y.id))||[]:[],z=!!((me=V.eligibility_restriction)!=null&&me.type)&&V.eligibility_restriction.type!=="none";return t.jsxs(o.Fragment,{children:[t.jsxs("button",{className:"w-menu-item",onClick:()=>{z||(Z?ee(Y.id):q||W(Y.id))},disabled:n,style:z?{opacity:.55,cursor:"not-allowed"}:void 0,title:(st=V.eligibility_restriction)==null?void 0:st.message,children:[t.jsx("span",{className:"w-avatar w-avatar--sm",children:Y.image_url?t.jsx("img",{src:Y.image_url,alt:Y.name}):D(Y.name)}),t.jsx("span",{className:"w-grow w-truncate",children:Y.name}),t.jsxs("span",{className:"w-inline w-gap-1 w-none",children:[z&&t.jsx(Aa,{size:12,className:"w-text-error"}),q&&U&&t.jsx("span",{className:"w-rowact",role:"button",title:"Organization settings","aria-label":"Organization settings",onClick:Oe=>{Oe.stopPropagation(),ce()},children:t.jsx(Sa,{size:13})}),q&&!z&&t.jsx("span",{className:"w-rowact",role:"button",title:"Leave organization","aria-label":"Leave organization",onClick:Oe=>{Oe.stopPropagation(),Q()},children:t.jsx(Ea,{size:13})}),q&&!Z&&t.jsx(Ge,{size:13,className:"w-text-primary"}),Z&&t.jsx(Dt,{size:11,className:"w-text-muted",style:{transition:"transform 0.2s ease",transform:G?"rotate(0deg)":"rotate(-90deg)"}})]})]}),Z&&G&&!z&&t.jsxs("div",{className:"w-switch-nest",children:[de.map(Oe=>{var J,re;const Ze=q&&(E==null?void 0:E.id)===Oe.id,mt=((J=Oe.eligibility_restriction)==null?void 0:J.type)&&Oe.eligibility_restriction.type!=="none";return t.jsxs("button",{className:"w-menu-item",onClick:()=>{!Ze&&!mt&&K(Oe.id)},disabled:n,style:mt?{opacity:.55,cursor:"not-allowed"}:void 0,title:(re=Oe.eligibility_restriction)==null?void 0:re.message,children:[t.jsx("span",{className:"w-avatar w-avatar--sm",children:Oe.image_url?t.jsx("img",{src:Oe.image_url,alt:Oe.name}):D(Oe.name).charAt(0)}),t.jsx("span",{className:"w-grow w-truncate",children:Oe.name}),t.jsxs("span",{className:"w-inline w-gap-1 w-none",children:[mt&&t.jsx(Aa,{size:12,className:"w-text-error"}),Ze&&Qe&&t.jsx("span",{className:"w-rowact",role:"button",title:"Workspace settings","aria-label":"Workspace settings",onClick:ue=>{ue.stopPropagation(),be()},children:t.jsx(Sa,{size:13})}),Ze&&t.jsx("span",{className:"w-rowact",role:"button",title:"Leave workspace","aria-label":"Leave workspace",onClick:ue=>{ue.stopPropagation(),ie()},children:t.jsx(Ea,{size:13})}),Ze&&t.jsx(Ge,{size:12,className:"w-text-primary"})]})]},Oe.id)}),t.jsxs("button",{className:"w-menu-item w-menu-item--muted",onClick:()=>{w(Y.id),f.open()},disabled:n,children:[t.jsx(Nt,{size:13}),t.jsx("span",{className:"w-grow w-truncate",children:"New workspace"})]})]})]},Y.id)}),H&&t.jsxs(t.Fragment,{children:[t.jsx("hr",{className:"w-hr"}),t.jsxs("button",{className:"w-menu-item w-menu-item--muted",onClick:()=>u.open(),disabled:n,children:[t.jsx(Nt,{size:13}),t.jsx("span",{className:"w-grow w-truncate",children:"New organization"})]})]})]})})]}),document.body),$&&H&&t.jsx(Wc,{isOpen:u.isOpen,onClose:u.close,onCreated:N}),t.jsx(Yc,{isOpen:h.isOpen,onClose:h.close}),Z&&t.jsxs(t.Fragment,{children:[t.jsx($r,{isOpen:g.isOpen,onClose:g.close}),t.jsx(Lr,{isOpen:f.isOpen,onClose:()=>{f.close(),w(null)},organizationId:x||void 0})]})]})})},n0=o.createContext(void 0),ta=()=>{const e=o.useContext(n0);if(!e)throw new Error("useScreenContext must be used within a ScreenProvider");return e},he=(...e)=>e.filter(Boolean).join(" "),r0=o.forwardRef(({className:e,...a},s)=>t.jsx("div",{ref:s,className:he("w-contents",e),...a}));r0.displayName="TypographyProvider";const ur=o.forwardRef(({className:e,...a},s)=>t.jsx("div",{ref:s,className:he("w-card","w-flex-col","w-full","w-minh-full",e),...a}));ur.displayName="Container";const i0=o.forwardRef(({className:e,...a},s)=>t.jsx("div",{ref:s,className:he("w-tabsbar",e),...a}));i0.displayName="TabsContainer";const o0=o.forwardRef(({className:e,...a},s)=>t.jsx("div",{ref:s,className:he("w-flex","w-items-center","w-gap-1","w-tabs",e),...a}));o0.displayName="TabsList";const _a=o.forwardRef(({$isActive:e,className:a,...s},n)=>t.jsx("button",{ref:n,className:he("w-tab",e&&"w-tab--active",a),...s}));_a.displayName="Tab";const ka=o.forwardRef(({className:e,...a},s)=>t.jsx("span",{ref:s,className:he("w-inline","w-gap-1",e),...a}));ka.displayName="TabIcon";const l0=o.forwardRef(({className:e,children:a,...s},n)=>t.jsx("div",{ref:n,className:he("w-tabbody",e),...s,children:t.jsx("div",{className:"w-tabpane",children:a})}));l0.displayName="TabContent";const A4=o.forwardRef(({className:e,...a},s)=>t.jsx("button",{ref:s,className:he("w-btn","w-btn--icon",e),...a}));A4.displayName="IconButton";const c0=o.forwardRef(({className:e,...a},s)=>t.jsx("div",{ref:s,className:he("w-flex","w-items-center","w-justify-between","w-wrap","w-gap-3",e),...a}));c0.displayName="HeaderCTAContainer";const M4=o.forwardRef(({className:e,...a},s)=>t.jsx("div",{ref:s,className:he("w-flex","w-items-start","w-gap-6",e),...a}));M4.displayName="ProfileSectionLayout";const R4=o.forwardRef(({className:e,...a},s)=>t.jsx("div",{ref:s,className:he("w-none",e),...a}));R4.displayName="ProfileImageContainer";const d0=o.forwardRef(({className:e,...a},s)=>t.jsx("div",{ref:s,className:he("w-vrow",e),...a}));d0.displayName="SecurityItemRow";const u0=o.forwardRef(({className:e,...a},s)=>t.jsx("div",{ref:s,className:he("w-grow",e),...a}));u0.displayName="SecurityItemContent";const m0=o.forwardRef(({className:e,...a},s)=>t.jsx("div",{ref:s,className:he("w-flex","w-items-center","w-gap-2","w-none",e),...a}));m0.displayName="SecurityItemActions";const Tr=o.forwardRef(({className:e,...a},s)=>t.jsx("div",{ref:s,className:he("w-sechead",e),...a}));Tr.displayName="ResponsiveHeaderContainer";const pn=o.forwardRef(({className:e,...a},s)=>t.jsx("div",{ref:s,className:he("w-full",e),...a}));pn.displayName="DesktopTableContainer";const p0=o.forwardRef(({className:e,...a},s)=>t.jsx("div",{ref:s,className:he("w-flex","w-gap-3",e),...a}));p0.displayName="FormRow";const L4=o.forwardRef(({className:e,...a},s)=>t.jsx("div",{ref:s,className:he("w-vrow",e),...a}));L4.displayName="ConnectionItemRow";const P4=o.forwardRef(({className:e,...a},s)=>t.jsx("div",{ref:s,className:he("w-flex","w-items-center","w-gap-2","w-grow",e),...a}));P4.displayName="ConnectionLeft";const $4=o.forwardRef(({className:e,...a},s)=>t.jsx("div",{ref:s,className:he("w-flex","w-items-center","w-justify-end","w-gap-1","w-none",e),...a}));$4.displayName="ConnectionRight";const Ir=o.forwardRef(({className:e,...a},s)=>t.jsx("div",{ref:s,className:he("w-iconbox",e),...a}));Ir.displayName="IconWrapper";const O4=o.forwardRef(({className:e,...a},s)=>t.jsx("div",{ref:s,className:he("w-flex","w-wrap","w-gap-2",e),...a}));O4.displayName="ButtonActions";const h0=o.forwardRef(({className:e,...a},s)=>t.jsx("div",{ref:s,className:he("w-page-head",e),...a}));h0.displayName="PageHeader";const Z4=o.forwardRef(({className:e,...a},s)=>t.jsx("div",{ref:s,className:he("w-avatar",e),...a}));Z4.displayName="PageHeaderAvatar";const f0=o.forwardRef(({className:e,...a},s)=>t.jsx("div",{ref:s,className:he("w-flex-col","w-gap-1","w-grow",e),...a}));f0.displayName="PageHeaderInfo";const w0=o.forwardRef(({className:e,...a},s)=>t.jsx("div",{ref:s,className:he("w-sec","w-truncate",e),...a}));w0.displayName="PageHeaderName";const g0=o.forwardRef(({className:e,...a},s)=>t.jsx("div",{ref:s,className:he("w-secsub","w-truncate",e),...a}));g0.displayName="PageHeaderSub";const H4=o.forwardRef(({className:e,...a},s)=>t.jsx("div",{ref:s,className:he("w-flex","w-items-center","w-gap-1","w-none",e),...a}));H4.displayName="PageHeaderActions";const F4=o.forwardRef(({className:e,...a},s)=>t.jsx("div",{ref:s,className:he("w-flex-col","w-gap-4",e),...a}));F4.displayName="PageContent";const T4=o.forwardRef(({className:e,...a},s)=>t.jsx("section",{ref:s,className:he("w-card",e),...a}));T4.displayName="Card";const I4=o.forwardRef(({className:e,...a},s)=>t.jsx("section",{ref:s,className:he("w-card","w-danger",e),...a}));I4.displayName="DangerCard";const V4=o.forwardRef(({className:e,...a},s)=>t.jsx("div",{ref:s,className:he("w-card-head",e),...a}));V4.displayName="CardHeader";const z4=o.forwardRef(({className:e,...a},s)=>t.jsx("div",{ref:s,className:he("w-flex-col","w-gap-1","w-grow",e),...a}));z4.displayName="CardTitleBlock";const D4=o.forwardRef(({className:e,...a},s)=>t.jsx("h3",{ref:s,className:he("w-sec",e),...a}));D4.displayName="CardTitle";const U4=o.forwardRef(({className:e,...a},s)=>t.jsx("p",{ref:s,className:he("w-secsub",e),...a}));U4.displayName="CardSubtitle";const W4=o.forwardRef(({className:e,...a},s)=>t.jsx("div",{ref:s,className:he("w-flex","w-items-center","w-wrap","w-gap-2","w-none",e),...a}));W4.displayName="CardActions";const B4=o.forwardRef(({className:e,...a},s)=>t.jsx("div",{ref:s,className:he("w-hr",e),...a}));B4.displayName="CardDivider";const G4=o.forwardRef(({className:e,...a},s)=>t.jsx("div",{ref:s,className:he("w-card-body",e),...a}));G4.displayName="CardBody";const q4=o.forwardRef(({className:e,...a},s)=>t.jsx("div",{ref:s,className:he("w-card-foot",e),...a}));q4.displayName="CardFooter";const K4=o.forwardRef(({className:e,...a},s)=>t.jsx("div",{ref:s,className:he("w-list",e),...a}));K4.displayName="RowList";const Y4=o.forwardRef(({className:e,...a},s)=>t.jsx("div",{ref:s,className:he("w-rowitem",e),...a}));Y4.displayName="RowItem";const Q4=o.forwardRef(({className:e,...a},s)=>t.jsx("div",{ref:s,className:he("w-flex-col","w-gap-1","w-grow",e),...a}));Q4.displayName="RowInfo";const J4=o.forwardRef(({className:e,...a},s)=>t.jsx("div",{ref:s,className:he("w-sec",e),...a}));J4.displayName="RowTitle";const X4=o.forwardRef(({className:e,...a},s)=>t.jsx("div",{ref:s,className:he("w-secsub",e),...a}));X4.displayName="RowSub";const e6=o.forwardRef(({className:e,...a},s)=>t.jsx("div",{ref:s,className:he("w-flex","w-items-center","w-wrap","w-gap-2","w-none",e),...a}));e6.displayName="RowActions";const t6={primary:"w-pill--current",success:"w-pill--success",warning:"w-pill--pending",danger:"w-pill--error",neutral:""},Ga=({$variant:e="neutral",className:a,children:s,...n})=>t.jsxs("span",{className:he("w-pill",t6[e],a),...n,children:[t.jsx("span",{className:"w-dot"}),s]}),a6=o.forwardRef(({className:e,...a},s)=>t.jsx("div",{ref:s,className:he("w-list",e),...a}));a6.displayName="Table";const s6=o.forwardRef(({$cols:e,className:a,style:s,...n},i)=>t.jsx("div",{ref:i,className:he("w-listhead","w-gap-4",a),style:{gridTemplateColumns:e||"1fr 1fr auto",...s},...n}));s6.displayName="TableHead";const n6=o.forwardRef(({className:e,...a},s)=>t.jsx("div",{ref:s,className:e,...a}));n6.displayName="Th";const r6=o.forwardRef(({$cols:e,className:a,style:s,...n},i)=>t.jsx("div",{ref:i,className:he("w-row","w-gap-4",a),style:{gridTemplateColumns:e||"1fr 1fr auto",...s},...n}));r6.displayName="Tr";const i6=o.forwardRef(({className:e,...a},s)=>t.jsx("div",{ref:s,className:he("w-truncate","w-text-secondary",e),...a}));i6.displayName="Td";const o6=o.forwardRef(({className:e,...a},s)=>t.jsx("div",{ref:s,className:he("w-grid-2",e),...a}));o6.displayName="FieldGrid";const l6=o.forwardRef(({className:e,...a},s)=>t.jsx("div",{ref:s,className:he("w-field",e),...a}));l6.displayName="Field";const c6=o.forwardRef(({className:e,...a},s)=>t.jsx("label",{ref:s,className:he("w-label",e),...a}));c6.displayName="FieldLabel";const d6=()=>{var I,L;const{deployment:e}=_e(),{refetch:a}=ot(),{user:s,updateProfile:n,deleteAccount:i}=ga(),{toast:l}=ta(),[m,c]=o.useState(""),[d,p]=o.useState(""),[u,h]=o.useState(""),[f,g]=o.useState(!1),[x,w]=o.useState(!1),[b,_]=o.useState(!1),[v,k]=o.useState("");o.useEffect(()=>{s&&!f&&(c(s.first_name||""),p(s.last_name||""),h(s.username||""),g(!0))},[s,f]);const N=o.useCallback(async()=>{if(s)try{const S={};m!==s.first_name&&(S.first_name=m),d!==s.last_name&&(S.last_name=d),u!==s.username&&(S.username=u),Object.keys(S).length>0&&await n(S)}catch(S){l(S.message||"Failed to save profile changes","error")}},[s,n,m,d,u,l]),j=S=>{c(S.target.value)},C=S=>{p(S.target.value)},y=S=>{h(S.target.value)},E=()=>{N()},R=()=>{N()},F=()=>{N()};if(!s)return t.jsx("div",{className:"w-loading",children:t.jsx(ye,{})});const A=async()=>{if(!(!s||v!=="delete this account")){_(!0);try{await i(""),l("Account deleted successfully","info"),await a()}catch(S){l(S.message||"Failed to delete account","error")}finally{_(!1),k(""),w(!1)}}};return t.jsxs("div",{className:"w-flex-col w-gap-6",children:[t.jsxs("div",{className:"w-flex-col w-gap-4",children:[t.jsx("p",{className:"w-secsub",children:"Basic information about your profile"}),t.jsxs("div",{className:"w-flex-col w-gap-4",children:[t.jsxs(p0,{children:[t.jsxs(We,{className:"w-grow",children:[t.jsx(Ve,{htmlFor:"firstName",children:"First Name"}),t.jsx(xe,{id:"firstName",type:"text",value:m,onChange:j,onBlur:E,placeholder:"Enter your first name",required:!0})]}),t.jsxs(We,{className:"w-grow",children:[t.jsx(Ve,{htmlFor:"lastName",children:"Last Name"}),t.jsx(xe,{id:"lastName",type:"text",value:d,onChange:C,onBlur:R,placeholder:"Enter your last name",required:!0})]})]}),((L=(I=e==null?void 0:e.auth_settings)==null?void 0:I.username)==null?void 0:L.enabled)&&t.jsxs(We,{children:[t.jsx(Ve,{htmlFor:"username",children:"Username"}),t.jsx(xe,{id:"username",type:"text",value:u,onChange:y,onBlur:F,placeholder:"Enter your username",required:!0})]})]})]}),t.jsx("div",{className:"w-hr"}),t.jsxs("div",{className:"w-flex-col w-gap-4",children:[t.jsxs("div",{className:"w-flex-col w-gap-1",children:[t.jsx("h3",{className:"w-sec",children:"Danger Zone"}),t.jsx("p",{className:"w-secsub",children:"Irreversible and destructive actions"})]}),t.jsxs("div",{className:"w-danger w-flex-col w-items-start",children:[t.jsxs("div",{className:"w-flex w-items-center w-justify-between w-gap-4 w-full",children:[t.jsxs("div",{className:"w-flex-col w-gap-1",children:[t.jsx("div",{className:"w-sec",children:"Delete Account"}),t.jsx("div",{className:"w-secsub",children:"Once you delete your account, there is no going back. Please be certain."})]}),t.jsx(se,{$destructive:!0,$size:"sm",onClick:()=>{x?(w(!1),k("")):w(!0)},children:x?"Cancel":"Delete"})]}),x&&t.jsxs("div",{className:"w-full w-flex-col w-gap-3",children:[t.jsxs(We,{children:[t.jsx(Ve,{htmlFor:"confirm_username",children:'Type "delete this account" to confirm'}),t.jsx(xe,{id:"confirm_username",type:"text",value:v,onChange:S=>k(S.target.value),placeholder:"delete this account"})]}),t.jsx(se,{$destructive:!0,$fullWidth:!0,onClick:A,disabled:v!=="delete this account"||b,children:b?t.jsx(ye,{size:12}):"Delete Forever"})]})]})]})]})},Di=({onClose:e,onAddEmail:a,onAttemptVerification:s,onPrepareVerification:n,existingEmail:i,triggerRef:l})=>{const m=o.useRef(null),[c,d]=o.useState(!1),{toast:p}=ta(),u=xt({contentRef:m,triggerRef:l??{current:null},isOpen:c,minWidth:340,defaultMaxHeight:360});o.useEffect(()=>{d(!0);const j=y=>{m.current&&!m.current.contains(y.target)&&e()},C=y=>{y.key==="Escape"&&e()};return document.addEventListener("mousedown",j),document.addEventListener("keydown",C),()=>{document.removeEventListener("mousedown",j),document.removeEventListener("keydown",C)}},[e]);const[h,f]=o.useState(i?"otp":"email"),[g,x]=o.useState(i||""),[w,b]=o.useState(""),[_,v]=o.useState(!1),k=async()=>{if(!(!g||_)){v(!0);try{await a(g),f("otp")}catch(j){p(j.message||"Failed to add email. Please try again.","error")}finally{v(!1)}}},N=async()=>{v(!0);try{await s(w),e()}catch(j){p(j.message||"Failed to verify email. Check the code and try again.","error")}finally{v(!1)}};return c?t.jsx("div",{ref:m,className:"w-pop",style:{position:"fixed",zIndex:1001,maxWidth:"calc(100vw - 24px)",top:(u==null?void 0:u.top)!==void 0?`${u.top}px`:void 0,bottom:(u==null?void 0:u.bottom)!==void 0?`${u.bottom}px`:void 0,left:(u==null?void 0:u.left)!==void 0?`${u.left}px`:void 0,right:(u==null?void 0:u.right)!==void 0?`${u.right}px`:void 0,visibility:u?"visible":"hidden"},onClick:j=>j.stopPropagation(),children:h==="email"?t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"w-pop-body",children:[t.jsx("div",{className:"w-pop-title",children:"Add email address"}),t.jsxs("label",{className:"w-field",children:[t.jsx("span",{className:"w-label",children:"Email address"}),t.jsx(xe,{id:"email-input",type:"email",placeholder:"you@company.com",value:g,onChange:j=>x(j.target.value),onKeyDown:j=>{j.key==="Enter"&&k()},autoFocus:!0})]})]}),t.jsxs("div",{className:"w-pop-foot",children:[t.jsx("button",{type:"button",className:"w-btn w-btn--ghost w-btn--sm",onClick:e,children:"Cancel"}),t.jsx("button",{type:"button",className:"w-btn w-btn--primary w-btn--sm",onClick:k,disabled:!g||_,children:_?"Sending…":"Send code"})]})]}):t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"w-pop-body",children:[!i&&t.jsxs("button",{type:"button",className:"w-link w-link--muted w-inline w-gap-1",style:{alignSelf:"flex-start",background:"none",border:0,cursor:"pointer"},onClick:()=>f("email"),children:[t.jsx(sn,{size:11})," Back"]}),t.jsxs("div",{className:"w-flex-col w-gap-1",children:[t.jsx("div",{className:"w-pop-title",children:"Verify your email"}),t.jsxs("p",{className:"w-pop-sub",children:["Enter the 6-digit code sent to ",t.jsx("strong",{children:g})]})]}),t.jsx(xa,{onComplete:async j=>b(j),onResend:n,isSubmitting:_})]}),t.jsxs("div",{className:"w-pop-foot",children:[t.jsx("button",{type:"button",className:"w-btn w-btn--ghost w-btn--sm",onClick:e,children:"Cancel"}),t.jsx("button",{type:"button",className:"w-btn w-btn--primary w-btn--sm",onClick:N,disabled:w.length<6||_,children:_?"Verifying…":"Verify"})]})]})}):null},u6=()=>{var R,F,A,I;const{deployment:e}=_e(),{toast:a}=ta(),[s,n]=o.useState(""),[i,l]=o.useState(!1),[m,c]=o.useState(null),[d,p]=o.useState(new Set),u=o.useRef(null),h=o.useRef({}),{user:f,createEmailAddress:g,deleteEmailAddress:x,prepareEmailVerification:w,attemptEmailVerification:b,makeEmailPrimary:_}=ga();if(!((F=(R=e==null?void 0:e.auth_settings)==null?void 0:R.email_address)!=null&&F.enabled))return null;const v=(L,S)=>{p(O=>{const P=new Set(O);return S?P.add(L):P.delete(L),P})},k=async L=>{v(L,!0);try{await _(L),await f.refetch(),a("Primary email updated","info")}catch(S){a(S.message||"Failed to update primary email","error")}finally{v(L,!1)}},N=async L=>{if(L===(f==null?void 0:f.primary_email_address_id)){a("Cannot delete primary email. Set another email as primary first.","error");return}v(L,!0);try{await x(L),await f.refetch(),a("Email removed","info")}catch(S){a(S.message||"Failed to delete email address. Please try again.","error")}finally{v(L,!1)}},j=async L=>{v(L,!0);try{await w(L),await f.refetch(),c(L)}catch(S){a(S.message||"Failed to send verification","error")}finally{v(L,!1)}},C=(f==null?void 0:f.user_email_addresses)||[],y=L=>L.id===(f==null?void 0:f.primary_email_address_id)?t.jsx(Ga,{$variant:"success",children:"Primary"}):L.verified?t.jsx(Ga,{$variant:"neutral",children:"Backup"}):t.jsx(Ga,{$variant:"warning",children:"Pending verification"}),E=L=>{const S=L.id===(f==null?void 0:f.primary_email_address_id),O=d.has(L.id);return S?t.jsx("span",{className:"w-secsub",children:"Cannot remove"}):t.jsxs("div",{className:"w-actions",children:[L.verified&&t.jsx(se,{$size:"sm",$outline:!0,disabled:O,onClick:()=>k(L.id),children:"Make primary"}),!L.verified&&t.jsx(se,{ref:P=>{P&&(h.current[L.id]=P)},$size:"sm",$outline:!0,disabled:O,onClick:()=>j(L.id),children:"Resend"}),t.jsx(se,{$size:"sm",$destructive:!0,disabled:O,onClick:()=>N(L.id),children:O?t.jsx(ye,{size:12}):"Remove"})]})};return t.jsxs(t.Fragment,{children:[t.jsxs(Tr,{children:[t.jsxs("div",{className:"w-grow w-flex-col w-gap-1",children:[t.jsx("div",{className:"w-sec",children:"Email addresses"}),t.jsx("div",{className:"w-secsub",children:"Sign in and receive notifications at these addresses."})]}),t.jsxs("div",{className:"w-none w-relative",children:[t.jsx(se,{ref:u,$size:"sm",onClick:()=>l(!0),children:"Add email"}),i&&t.jsx(Di,{triggerRef:u,onClose:()=>l(!1),onAddEmail:async L=>{const S=await g(L);n(S.data.id),await w(S.data.id),f.refetch()},onPrepareVerification:async()=>{await w(s),f.refetch()},onAttemptVerification:async L=>{await b(s,L),f.refetch(),l(!1),n(""),a("Email added and verified","info")}})]})]}),C.length?t.jsx(t.Fragment,{children:t.jsx(pn,{children:t.jsxs($t,{children:[t.jsx(Ot,{children:t.jsxs(it,{children:[t.jsx($e,{children:"Email address"}),t.jsx($e,{children:"Status"}),t.jsx($e,{})]})}),t.jsx(Zt,{children:C.map(L=>t.jsxs(it,{children:[t.jsx(Ke,{children:L.email}),t.jsx(Ke,{children:y(L)}),t.jsx(Ht,{children:E(L)})]},L.id))})]})})}):t.jsx(Ct,{title:"No email addresses",description:"Add an email address to get started."}),m&&t.jsx(Di,{existingEmail:(I=(A=f==null?void 0:f.user_email_addresses)==null?void 0:A.find(L=>L.id===m))==null?void 0:I.email,triggerRef:{current:h.current[m]},onClose:()=>c(null),onAddEmail:async()=>{},onPrepareVerification:async()=>{await w(m),f.refetch()},onAttemptVerification:async L=>{await b(m,L),f.refetch(),c(null),a("Email verified","info")}})]})},Ui=({onClose:e,onAddPhone:a,onAttemptVerification:s,existingPhone:n,onPrepareVerification:i,triggerRef:l})=>{var y;const m=o.useRef(null),[c,d]=o.useState(!1),{toast:p}=ta(),u=xt({contentRef:m,triggerRef:l??{current:null},isOpen:c,minWidth:340,defaultMaxHeight:360});o.useEffect(()=>{d(!0);const E=F=>{m.current&&!m.current.contains(F.target)&&e()},R=F=>{F.key==="Escape"&&e()};return document.addEventListener("mousedown",E),document.addEventListener("keydown",R),()=>{document.removeEventListener("mousedown",E),document.removeEventListener("keydown",R)}},[e]);const[h,f]=o.useState(n?"otp":"phone"),[g,x]=o.useState((n==null?void 0:n.replace(/^\+\d+/,""))||""),[w,b]=o.useState((y=Intl.DateTimeFormat().resolvedOptions().locale.split("-"))==null?void 0:y.pop()),[_,v]=o.useState(""),[k,N]=o.useState(!1),j=async()=>{if(!(!g||k)){N(!0);try{await a(g,w||""),f("otp")}catch(E){p(E.message||"Failed to add phone number. Please try again.","error")}finally{N(!1)}}},C=async()=>{N(!0);try{await s(_),e()}catch(E){p(E.message||"Failed to verify phone. Check the code and try again.","error")}finally{N(!1)}};return c?t.jsx("div",{ref:m,className:"w-pop",style:{position:"fixed",zIndex:1001,maxWidth:"calc(100vw - 24px)",top:(u==null?void 0:u.top)!==void 0?`${u.top}px`:void 0,bottom:(u==null?void 0:u.bottom)!==void 0?`${u.bottom}px`:void 0,left:(u==null?void 0:u.left)!==void 0?`${u.left}px`:void 0,right:(u==null?void 0:u.right)!==void 0?`${u.right}px`:void 0,visibility:u?"visible":"hidden"},onClick:E=>E.stopPropagation(),children:h==="phone"?t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"w-pop-body",children:[t.jsx("div",{className:"w-pop-title",children:"Add phone number"}),t.jsxs("label",{className:"w-field",children:[t.jsx("span",{className:"w-label",children:"Phone number"}),t.jsx(bs,{value:g,onChange:E=>x(E.target.value),error:"",countryCode:w,setCountryCode:b})]})]}),t.jsxs("div",{className:"w-pop-foot",children:[t.jsx("button",{type:"button",className:"w-btn w-btn--ghost w-btn--sm",onClick:e,children:"Cancel"}),t.jsx("button",{type:"button",className:"w-btn w-btn--primary w-btn--sm",onClick:j,disabled:!g||k,children:k?"Sending…":"Send code"})]})]}):t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"w-pop-body",children:[!n&&t.jsxs("button",{type:"button",className:"w-link w-link--muted w-inline w-gap-1",style:{alignSelf:"flex-start",background:"none",border:0,cursor:"pointer"},onClick:()=>f("phone"),children:[t.jsx(sn,{size:11})," Back"]}),t.jsxs("div",{className:"w-flex-col w-gap-1",children:[t.jsx("div",{className:"w-pop-title",children:"Verify phone number"}),t.jsxs("p",{className:"w-pop-sub",children:["Enter the 6-digit code sent to ",t.jsx("strong",{children:n||g})]})]}),t.jsx(xa,{onComplete:E=>v(E),onResend:async()=>i(),isSubmitting:k})]}),t.jsxs("div",{className:"w-pop-foot",children:[t.jsx("button",{type:"button",className:"w-btn w-btn--ghost w-btn--sm",onClick:e,children:"Cancel"}),t.jsx("button",{type:"button",className:"w-btn w-btn--primary w-btn--sm",onClick:C,disabled:_.length!==6||k,children:k?"Verifying…":"Verify"})]})]})}):null},m6=()=>{var F,A,I,L;const{deployment:e}=_e(),{toast:a}=ta(),[s,n]=o.useState(""),[i,l]=o.useState(!1),[m,c]=o.useState(null),[d,p]=o.useState(new Set),u=o.useRef(null),h=o.useRef({}),{user:f,createPhoneNumber:g,deletePhoneNumber:x,preparePhoneVerification:w,attemptPhoneVerification:b,makePhonePrimary:_}=ga();if(!((A=(F=e==null?void 0:e.auth_settings)==null?void 0:F.phone_number)!=null&&A.enabled))return null;const v=(S,O)=>{p(P=>{const $=new Set(P);return O?$.add(S):$.delete(S),$})},k=S=>{const O=Bs.find(P=>P.dialCode===S);return(O==null?void 0:O.flag)||"🌍"},N=async S=>{v(S,!0);try{await _(S),await f.refetch(),a("Primary phone updated","info")}catch(O){a(O.message||"Failed to update primary phone","error")}finally{v(S,!1)}},j=async S=>{if(S===(f==null?void 0:f.primary_phone_number_id)){a("Cannot delete primary phone. Set another phone as primary first.","error");return}v(S,!0);try{await x(S),await f.refetch(),a("Phone removed","info")}catch(O){a(O.message||"Failed to delete phone. Please try again.","error")}finally{v(S,!1)}},C=async S=>{v(S,!0);try{await w(S),await f.refetch(),c(S)}catch(O){a(O.message||"Failed to send verification","error")}finally{v(S,!1)}},y=(f==null?void 0:f.user_phone_numbers)||[],E=S=>S.id===(f==null?void 0:f.primary_phone_number_id)?t.jsx(Ga,{$variant:"success",children:"Primary"}):S.verified?t.jsx(Ga,{$variant:"neutral",children:"Backup"}):t.jsx(Ga,{$variant:"warning",children:"Pending verification"}),R=S=>{const O=S.id===(f==null?void 0:f.primary_phone_number_id),P=d.has(S.id);return O?t.jsx("span",{className:"w-secsub",children:"Cannot remove"}):t.jsxs("div",{className:"w-actions",children:[S.verified&&t.jsx(se,{$size:"sm",$outline:!0,disabled:P,onClick:()=>N(S.id),children:"Make primary"}),!S.verified&&t.jsx(se,{ref:$=>{$&&(h.current[S.id]=$)},$size:"sm",$outline:!0,disabled:P,onClick:()=>C(S.id),children:"Resend"}),t.jsx(se,{$size:"sm",$destructive:!0,disabled:P,onClick:()=>j(S.id),children:P?t.jsx(ye,{size:12}):"Remove"})]})};return t.jsxs(t.Fragment,{children:[t.jsxs(Tr,{children:[t.jsxs("div",{className:"w-grow w-flex-col w-gap-1",children:[t.jsx("div",{className:"w-sec",children:"Phone numbers"}),t.jsx("div",{className:"w-secsub",children:"Used for sign-in and two-factor authentication."})]}),t.jsxs("div",{className:"w-none w-relative",children:[t.jsx(se,{ref:u,$size:"sm",onClick:()=>l(!0),children:"Add phone"}),i&&t.jsx(Ui,{triggerRef:u,onClose:()=>l(!1),onAddPhone:async(S,O)=>{const P=await g(S,O);n(P.data.id),await w(P.data.id)},onPrepareVerification:async()=>{await w(s),f.refetch()},onAttemptVerification:async S=>{await b(s,S),f.refetch(),l(!1),n(""),a("Phone added and verified","info")}}),m&&t.jsx(Ui,{existingPhone:(L=(I=f==null?void 0:f.user_phone_numbers)==null?void 0:I.find(S=>S.id===m))==null?void 0:L.phone_number,triggerRef:{current:h.current[m]},onClose:()=>c(null),onAddPhone:async()=>{},onPrepareVerification:async()=>{await w(m),f.refetch()},onAttemptVerification:async S=>{await b(m,S),f.refetch(),c(null),a("Phone verified","info")}})]})]}),y.length?t.jsx(t.Fragment,{children:t.jsx(pn,{children:t.jsxs($t,{children:[t.jsx(Ot,{children:t.jsxs(it,{children:[t.jsx($e,{children:"Phone number"}),t.jsx($e,{children:"Status"}),t.jsx($e,{})]})}),t.jsx(Zt,{children:y.map(S=>t.jsxs(it,{children:[t.jsx(Ke,{children:t.jsxs("span",{className:"w-inline w-gap-2",children:[t.jsx("span",{children:k(S.country_code)}),t.jsx("span",{className:"w-text-secondary",children:S.country_code}),t.jsx("span",{children:S.phone_number})]})}),t.jsx(Ke,{children:E(S)}),t.jsx(Ht,{children:R(S)})]},S.id))})]})})}):t.jsx(Ct,{title:"No phone numbers",description:"Add a phone number to get started."})]})},p6=e=>t.jsxs("svg",{width:"800px",height:"800px",viewBox:"0 0 16 16",xmlns:"http://www.w3.org/2000/svg",fill:"none",...e,children:[t.jsx("path",{fill:"#F35325",d:"M1 1h6.5v6.5H1V1z"}),t.jsx("path",{fill:"#81BC06",d:"M8.5 1H15v6.5H8.5V1z"}),t.jsx("path",{fill:"#05A6F0",d:"M1 8.5h6.5V15H1V8.5z"}),t.jsx("path",{fill:"#FFBA08",d:"M8.5 8.5H15V15H8.5V8.5z"})]}),h6={google_oauth:{icon:t.jsx(bc,{}),label:"Google"},microsoft_oauth:{icon:t.jsx(p6,{}),label:"Microsoft"},github_oauth:{icon:t.jsx(vc,{}),label:"GitHub"},gitlab_oauth:{icon:t.jsx(_c,{}),label:"GitLab"},linkedin_oauth:{icon:t.jsx(jc,{}),label:"LinkedIn"},discord_oauth:{icon:t.jsx(kc,{}),label:"Discord"},x_oauth:{icon:t.jsx(yc,{}),label:"X"}},f6=()=>{const{user:e,disconnectSocialConnection:a,connectSocialAccount:s}=ga(),{deployment:n}=_e(),i=(n==null?void 0:n.social_connections.filter(c=>c.enabled))||[],l=c=>{s({provider:c,redirectUri:window.location.href})},m=async c=>{await a(c.toString()),e.refetch()};return i.length===0?t.jsx(Ct,{title:"No providers available",description:"Social sign-in providers have not been configured for this app."}):t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"w-flex w-items-center w-gap-3",children:t.jsxs("div",{className:"w-grow w-flex-col w-gap-1",children:[t.jsx("div",{className:"w-sec",children:"Connected accounts"}),t.jsx("div",{className:"w-secsub",children:"Sign in faster by linking third-party accounts."})]})}),t.jsx("div",{className:"w-list",children:i.map(c=>{var h;const d=h6[c.provider];if(!d)return null;const p=((h=e==null?void 0:e.social_connections)==null?void 0:h.filter(f=>f.provider===c.provider))||[],u=p.length>0;return t.jsxs("div",{className:"w-vrow",children:[t.jsxs("div",{className:"w-flex w-items-center w-gap-3 w-grow",children:[t.jsx(Ir,{children:d.icon}),t.jsxs("div",{className:"w-flex-col w-gap-1 w-grow",children:[t.jsx("div",{className:"w-sec",children:d.label}),u?t.jsx("div",{className:"w-flex w-wrap w-gap-1",children:p.map(f=>t.jsxs("span",{className:"w-chip",children:[t.jsx("span",{className:"w-truncate",children:f.email_address}),t.jsx("span",{className:"w-chip-x",role:"button",onClick:()=>m(f.id),title:"Remove connection","aria-label":"Remove connection",children:t.jsx(Ra,{size:10,weight:"bold"})})]},f.id))}):t.jsx("span",{className:"w-secsub",children:"Not linked"})]})]}),t.jsx("div",{className:`w-flex w-justify-end w-none${u?" w-row-act-top":""}`,children:t.jsx(se,{$size:"sm",$outline:!0,onClick:()=>l(c.provider),children:u?"Link another":"Link"})})]},c.provider)})})]})};var w6=Object.defineProperty,Js=Object.getOwnPropertySymbols,x0=Object.prototype.hasOwnProperty,v0=Object.prototype.propertyIsEnumerable,Wi=(e,a,s)=>a in e?w6(e,a,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[a]=s,mr=(e,a)=>{for(var s in a||(a={}))x0.call(a,s)&&Wi(e,s,a[s]);if(Js)for(var s of Js(a))v0.call(a,s)&&Wi(e,s,a[s]);return e},pr=(e,a)=>{var s={};for(var n in e)x0.call(e,n)&&a.indexOf(n)<0&&(s[n]=e[n]);if(e!=null&&Js)for(var n of Js(e))a.indexOf(n)<0&&v0.call(e,n)&&(s[n]=e[n]);return s};/**
108
+ 10.0.0.0/24`,className:"w-input--area w-mono-sm"})]})]})]}),t.jsxs("div",{className:"w-flex-col w-gap-3",children:[t.jsx(Vi,{children:"Danger zone"}),t.jsxs("div",{className:"w-danger",children:[t.jsxs("div",{className:"w-grow",children:[t.jsx("div",{className:"w-sec",children:"Delete workspace"}),t.jsx("div",{className:"w-secsub",children:"Once you delete this workspace, there is no going back."})]}),t.jsx(se,{$size:"sm",$outline:!0,$destructive:!0,onClick:()=>{k(!v),w("")},children:v?"Cancel":"Delete workspace"})]}),v&&t.jsxs("div",{className:"w-flex-col w-gap-3",children:[t.jsxs(We,{children:[t.jsxs(Ve,{htmlFor:"confirm_workspace_name",children:["Type ",t.jsx("strong",{children:e.name})," to confirm"]}),t.jsx(xe,{id:"confirm_workspace_name",type:"text",value:x,onChange:F=>w(F.target.value),placeholder:e.name})]}),t.jsx(se,{$size:"sm",$destructive:!0,onClick:j,disabled:x!==e.name||b,children:b?t.jsx(ye,{size:12}):"Delete forever"})]})]})]})},g4=({onClose:e,onSuccess:a,roles:s,triggerRef:n})=>{const i=o.useRef(null),[l,m]=o.useState(""),[c,d]=o.useState(null),[p,u]=o.useState(!1),[h,f]=o.useState(!1),{toast:g}=_t(),{inviteMember:x}=zt(),w=xt({contentRef:i,triggerRef:n??{current:null},isOpen:h,minWidth:360,defaultMaxHeight:320}),b=s.map(k=>({value:k.id,label:k.name}));o.useEffect(()=>{f(!0);const k=C=>{i.current&&!i.current.contains(C.target)&&(e==null||e())},N=C=>{C.key==="Escape"&&(e==null||e())},j=setTimeout(()=>{document.addEventListener("mousedown",k),document.addEventListener("keydown",N)},100);return()=>{clearTimeout(j),document.removeEventListener("mousedown",k),document.removeEventListener("keydown",N)}},[e]);const _=k=>/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(k),v=async()=>{const k=l.trim().toLowerCase();if(!(!k||!c)){if(!_(k)){g("Please enter a valid email address","error");return}if(k.length>320){g("Email address is too long","error");return}u(!0);try{await x({email:k,workspaceRoleId:c.id}),a==null||a()}catch(N){const j=N.message||"Failed to send invitation. Please try again.";g(j,"error")}finally{u(!1)}}};return h?t.jsxs("div",{ref:i,className:"w-pop w-pop--wide",style:{position:"fixed",zIndex:1001,top:(w==null?void 0:w.top)!==void 0?`${w.top}px`:void 0,bottom:(w==null?void 0:w.bottom)!==void 0?`${w.bottom}px`:void 0,left:(w==null?void 0:w.left)!==void 0?`${w.left}px`:void 0,right:(w==null?void 0:w.right)!==void 0?`${w.right}px`:void 0,maxHeight:w!=null&&w.maxHeight?`${w.maxHeight}px`:void 0,visibility:w?"visible":"hidden"},onClick:k=>k.stopPropagation(),role:"dialog","aria-labelledby":"invite-workspace-member-title","aria-modal":"true",children:[t.jsxs("div",{className:"w-pop-body",children:[t.jsx("div",{className:"w-pop-title",id:"invite-workspace-member-title",children:"Invite member"}),t.jsxs(We,{children:[t.jsx(Ve,{children:"Email Address"}),t.jsx(xe,{type:"email",placeholder:"colleague@company.com",value:l,onChange:k=>m(k.target.value),autoFocus:!0,"aria-label":"Email address for workspace invitation","aria-describedby":"workspace-email-help"})]}),t.jsxs(We,{children:[t.jsx(Ve,{children:"Role"}),t.jsx(dn,{options:b,value:c==null?void 0:c.id,onChange:k=>d(s.find(N=>N.id===k)),placeholder:"Select a role","aria-label":"Select role for invited workspace member"})]})]}),t.jsxs("div",{className:"w-pop-foot",children:[t.jsx("button",{type:"button",className:"w-btn w-btn--ghost w-btn--sm",onClick:e,children:"Cancel"}),t.jsx("button",{type:"button",className:"w-btn w-btn--primary w-btn--sm",onClick:v,disabled:!l||!c||p,children:p?t.jsx(ye,{size:14}):"Send invite"})]})]}):null},x4=()=>{const{activeWorkspace:e,getMembers:a,getRoles:s,removeMember:n,addMemberRole:i,removeMemberRole:l}=zt(),{session:m}=ot(),{toast:c}=_t(),[d,p]=o.useState(""),[u,h]=o.useState(1),[f]=o.useState(10),[g,x]=o.useState(""),[w,b]=o.useState(!1),_=o.useRef(null);o.useEffect(()=>{const A=setTimeout(()=>{x(d),h(1)},500);return()=>clearTimeout(A)},[d]);const{data:v,mutate:k}=ke(e?`wacht-api-workspaces:${e.id}:members:${u}:${f}:${g}`:null,()=>a==null?void 0:a({page:u,limit:f,search:g}),{keepPreviousData:!0}),N=(v==null?void 0:v.data)||[],j=(v==null?void 0:v.meta)||{total:0,limit:10},C=Math.ceil(j.total/(j.limit||10)),{data:y=[]}=ke(e?`wacht-api-workspaces:${e.id}:roles`:null,()=>s()||[]),E=y,R=async(A,I,L)=>{try{L?(await l(A,I),c("Role removed","info")):(await i(A,I),c("Role added","info")),k()}catch{c("Failed to update role","error")}},F=async A=>{try{await n(A),c("Member removed","info"),k()}catch{c("Failed to remove member","error")}};return v?t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"w-toolbar",children:[t.jsx(Ic,{value:d,onChange:p,placeholder:"Search members..."}),t.jsxs("div",{className:"w-flex w-items-center w-gap-3",children:[j.total>0&&t.jsxs("div",{className:"w-text-muted w-secsub",children:[j.total," member",j.total!==1?"s":""]}),t.jsx(se,{ref:_,onClick:()=>b(!0),$size:"sm",children:"Invite"})]})]}),w&&t.jsx(g4,{onClose:()=>b(!1),onSuccess:()=>{k(),b(!1)},roles:E,triggerRef:_}),N.length===0?t.jsx(Ct,{title:d?"No members match":"No members yet",description:"Members added to the organization can be invited here."}):t.jsx(t.Fragment,{children:t.jsx(Pr,{children:t.jsxs($t,{children:[t.jsx(Ot,{children:t.jsxs(it,{children:[t.jsx($e,{children:"Member"}),t.jsx($e,{children:"Joined"}),t.jsx($e,{children:"Role"})]})}),t.jsx(Zt,{children:N.map(A=>t.jsxs(it,{children:[t.jsx(Ke,{children:t.jsx(v4,{member:A,session:m})}),t.jsx(Ke,{children:new Date(A.created_at).toLocaleDateString()}),t.jsx(Ht,{children:t.jsx(b4,{member:A,roles:E,onToggle:(I,L)=>R(A.id,I,L),onRemove:()=>F(A.id)})})]},A.id))})]})})}),C>1&&t.jsxs("div",{className:"w-flex w-items-center w-justify-center w-gap-4",children:[t.jsx(se,{onClick:()=>h(A=>Math.max(1,A-1)),disabled:u===1,$size:"sm",children:"Previous"}),t.jsxs("span",{className:"w-secsub",children:[u," / ",C]}),t.jsx(se,{onClick:()=>h(A=>Math.min(C,A+1)),disabled:u===C,$size:"sm",children:"Next"})]})]}):t.jsx(ye,{})},v4=({member:e,session:a,subtitle:s})=>{var m,c,d;const n=e.public_user_data||e.user,i=(n==null?void 0:n.id)===((m=a==null?void 0:a.active_signin)==null?void 0:m.user_id),l=(p="",u="")=>`${p[0]||""}${u[0]||""} `.toUpperCase();return t.jsxs("div",{className:"w-flex w-items-center w-gap-3",children:[t.jsx("div",{className:"w-avatar",children:n!=null&&n.profile_picture_url?t.jsx("img",{src:n.profile_picture_url,alt:"Avatar"}):l(n==null?void 0:n.first_name,n==null?void 0:n.last_name)||"?"}),t.jsxs("div",{children:[t.jsxs("div",{className:"w-flex w-items-center w-gap-2",children:[t.jsx("span",{className:"w-sec",children:n?`${n.first_name||""} ${n.last_name||""} `.trim()||((c=n.primary_email_address)==null?void 0:c.email):"Unknown"}),i&&t.jsx("span",{className:"w-pill",children:"You"})]}),t.jsxs("div",{className:"w-flex w-wrap w-gap-2 w-secsub",children:[t.jsx("span",{children:(d=n==null?void 0:n.primary_email_address)==null?void 0:d.email}),s&&t.jsxs("span",{className:"w-text-muted",children:["• ",s]})]})]})]})},b4=({member:e,roles:a,onToggle:s,onRemove:n})=>{var m;const i=e.roles||[],l=c=>i.some(d=>d.id===c);return t.jsxs(js,{children:[t.jsx(ks,{children:t.jsxs(se,{$outline:!0,$size:"sm",className:"w-justify-between w-rolepick-btn",children:[i.length>0?(m=i==null?void 0:i[0])==null?void 0:m.name:"No role"," ",t.jsx(Dt,{size:14})]})}),t.jsxs(_s,{children:[a.map(c=>{const d=l(c.id);return t.jsx(ea,{onClick:()=>s(c.id,d),children:t.jsxs("div",{className:"w-flex w-justify-between w-full w-gap-3",children:[t.jsx("span",{children:c.name}),d&&t.jsx(Ge,{size:14,className:"w-text-success"})]})},c.id)}),t.jsx(Fc,{}),t.jsx(ea,{$destructive:!0,onClick:n,children:t.jsxs("div",{className:"w-flex w-items-center w-gap-2",children:[t.jsx(gr,{size:14})," Remove Member"]})})]})]})},y4=({onClose:e,onSuccess:a,roles:s,createInvitation:n,triggerRef:i})=>{const l=o.useRef(null),[m,c]=o.useState(""),[d,p]=o.useState(s[0]||null),[u,h]=o.useState(!1),[f,g]=o.useState(!1),{toast:x}=_t(),w=xt({contentRef:l,triggerRef:i,isOpen:f,minWidth:360,defaultMaxHeight:320}),b=s.map(k=>({value:k.id,label:k.name})),_=k=>/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(k),v=async()=>{const k=m.trim().toLowerCase();if(!(!k||!d)){if(!_(k)){x("Please enter a valid email address","error");return}if(k.length>320){x("Email address is too long","error");return}h(!0);try{await n({email:k,role_id:d.id}),a()}catch(N){x(N.message||"Failed to send invitation. Please try again.","error")}finally{h(!1)}}};return o.useEffect(()=>{g(!0);const k=j=>{l.current&&!l.current.contains(j.target)&&(e==null||e())},N=j=>{j.key==="Escape"&&(e==null||e())};return document.addEventListener("mousedown",k),document.addEventListener("keydown",N),()=>{document.removeEventListener("mousedown",k),document.removeEventListener("keydown",N)}},[e]),f?t.jsxs("div",{ref:l,className:"w-pop w-pop--wide w-pop-body",style:{position:"fixed",zIndex:1001,top:(w==null?void 0:w.top)!==void 0?`${w.top}px`:void 0,bottom:(w==null?void 0:w.bottom)!==void 0?`${w.bottom}px`:void 0,left:(w==null?void 0:w.left)!==void 0?`${w.left}px`:void 0,right:(w==null?void 0:w.right)!==void 0?`${w.right}px`:void 0,visibility:w?"visible":"hidden"},onClick:k=>k.stopPropagation(),role:"dialog","aria-labelledby":"invite-member-title","aria-modal":"true",children:[t.jsx("div",{className:"w-pop-title",id:"invite-member-title",children:"Invite member"}),t.jsxs("div",{className:"w-field",children:[t.jsx("label",{className:"w-label",children:"Email"}),t.jsx(xe,{type:"email",placeholder:"colleague@company.com",value:m,onChange:k=>c(k.target.value),onKeyDown:k=>{k.key==="Enter"&&m&&d&&v()},autoFocus:!0,"aria-label":"Email address for invitation"})]}),t.jsxs("div",{className:"w-field",children:[t.jsx("label",{className:"w-label",children:"Role"}),t.jsx(dn,{options:b,value:d==null?void 0:d.id,onChange:k=>p(s.find(N=>N.id===k)),placeholder:"Select a role","aria-label":"Select role for invited member"})]}),t.jsxs("div",{className:"w-flex w-gap-2",children:[t.jsx(se,{$size:"sm",$outline:!0,$fullWidth:!0,onClick:e,children:"Cancel"}),t.jsx(se,{$size:"sm",$fullWidth:!0,onClick:v,disabled:!m||!d||u,children:u?t.jsx(ye,{size:12}):"Send invite"})]})]}):null},j4=()=>{const{activeWorkspace:e,loading:a,getRoles:s,getInvitations:n,inviteMember:i,discardInvitation:l,resendInvitation:m}=zt(),{toast:c}=_t(),[d,p]=o.useState(!0),[u,h]=o.useState(!0),[f,g]=o.useState([]),[x,w]=o.useState([]),[b,_]=o.useState(!1),v=o.useRef(null),k=async()=>{if(e){p(!0),h(!0);try{const[C,y]=await Promise.all([s(),n()]);w(C),g(y)}catch{}finally{p(!1),h(!1)}}};o.useEffect(()=>{k()},[e==null?void 0:e.id]);const N=async C=>{try{await l(C),k(),c("Invitation cancelled","info")}catch{c("Failed to cancel invitation","error")}},j=async C=>{try{await m(C),k(),c("Invitation resent","info")}catch{c("Failed to resend invitation","error")}};return a||d||u?t.jsx(ye,{}):t.jsxs(t.Fragment,{children:[t.jsxs(Qc,{children:[t.jsxs("div",{className:"w-grow",children:[t.jsx("div",{className:"w-sec",children:"Invitations"}),t.jsx("div",{className:"w-secsub",children:"Pending invites to join this workspace."})]}),t.jsx(se,{ref:v,onClick:()=>_(!0),$size:"sm",children:"Invite"})]}),b&&t.jsx(y4,{onClose:()=>_(!1),onSuccess:()=>{k(),_(!1),c("Invitation sent","info")},roles:x,createInvitation:C=>i({email:C.email,workspaceRoleId:C.role_id}),triggerRef:v}),f.length===0?t.jsx(Ct,{title:"No pending invitations",description:"Invite members to your workspace."}):t.jsx(t.Fragment,{children:t.jsx(Pr,{children:t.jsxs($t,{children:[t.jsx(Ot,{children:t.jsxs(it,{children:[t.jsx($e,{children:"Email"}),t.jsx($e,{children:"Role"}),t.jsx($e,{children:"Invited"}),t.jsx($e,{})]})}),t.jsx(Zt,{children:f.map(C=>{var y,E;return t.jsxs(it,{children:[t.jsx(Ke,{children:C.email}),t.jsx(Ke,{children:((y=C.initial_workspace_role)==null?void 0:y.name)||((E=C.initial_organization_role)==null?void 0:E.name)||"No role"}),t.jsx(Ke,{children:new Date(C.created_at).toLocaleDateString()}),t.jsx(Ht,{children:t.jsx(_4,{onResend:()=>j(C.id),onCancel:()=>N(C.id)})})]},C.id)})})]})})})]})},_4=({onResend:e,onCancel:a})=>t.jsxs(js,{children:[t.jsx(ks,{children:t.jsx(Qs,{children:"•••"})}),t.jsxs(_s,{children:[t.jsxs(ea,{onClick:e,children:[t.jsx(Nl,{size:16})," Resend"]}),t.jsxs(ea,{$destructive:!0,onClick:a,children:[t.jsx(gr,{size:16})," Cancel"]})]})]}),zi=({onClose:e,onSuccess:a,role:s,triggerRef:n})=>{var C,y;const i=o.useRef(null),[l,m]=o.useState((s==null?void 0:s.name)||""),[c,d]=o.useState((s==null?void 0:s.permissions)||[]),[p,u]=o.useState(!1),[h,f]=o.useState(!1),{deployment:g}=_e(),{toast:x}=_t(),w=xt({contentRef:i,triggerRef:n??{current:null},isOpen:h,minWidth:400,defaultMaxHeight:500}),b=!!s,_=((C=g==null?void 0:g.b2b_settings)==null?void 0:C.workspace_permissions)||((y=g==null?void 0:g.b2b_settings)==null?void 0:y.organization_permissions)||[],v=Array.isArray(_)?_.map(E=>({value:E,label:E})):[];o.useEffect(()=>{f(!0);const E=A=>{i.current&&!i.current.contains(A.target)&&(e==null||e())},R=A=>{A.key==="Escape"&&(e==null||e())},F=setTimeout(()=>{document.addEventListener("mousedown",E),document.addEventListener("keydown",R)},100);return()=>{clearTimeout(F),document.removeEventListener("mousedown",E),document.removeEventListener("keydown",R)}},[e]);const k=E=>E.trim().replace(/[<>"'&]/g,""),N=E=>E.length>=2&&E.length<=50&&/^[a-zA-Z0-9\s_-]+$/.test(E),j=async()=>{const E=k(l);if(!E){x("Please enter a role name","error");return}if(!N(E)){x("Role name must be 2–50 characters, letters/numbers/spaces only.","error");return}if(c.length===0){x("Please select at least one permission","error");return}u(!0);try{const R={id:s==null?void 0:s.id,name:E,permissions:c};a==null||a(R)}catch(R){x(R.message||`Failed to ${b?"update":"create"} role. Please try again.`,"error")}finally{u(!1)}};return h?t.jsxs("div",{ref:i,className:"w-pop w-pop--wide",style:{position:"fixed",zIndex:1001,top:(w==null?void 0:w.top)!==void 0?`${w.top}px`:void 0,bottom:(w==null?void 0:w.bottom)!==void 0?`${w.bottom}px`:void 0,left:(w==null?void 0:w.left)!==void 0?`${w.left}px`:void 0,right:(w==null?void 0:w.right)!==void 0?`${w.right}px`:void 0,visibility:w?"visible":"hidden"},onClick:E=>E.stopPropagation(),role:"dialog","aria-labelledby":"role-dialog-title","aria-modal":"true",children:[t.jsxs("div",{className:"w-pop-body",children:[t.jsx("div",{className:"w-pop-title",id:"role-dialog-title",children:b?"Edit role":"New role"}),t.jsxs("label",{className:"w-field",children:[t.jsx("span",{className:"w-label",children:"Name"}),t.jsx(xe,{type:"text",placeholder:"e.g. Admin, Editor, Viewer",value:l,onChange:E=>m(E.target.value),autoFocus:!0,"aria-label":"Role name"})]}),t.jsxs("label",{className:"w-field",children:[t.jsx("span",{className:"w-label",children:"Permissions"}),t.jsx(Dc,{options:v,value:c,onChange:d,placeholder:"Select permissions","aria-label":"Select permissions for role"})]})]}),t.jsxs("div",{className:"w-pop-foot",children:[t.jsx("button",{type:"button",className:"w-btn w-btn--ghost w-btn--sm",onClick:e,children:"Cancel"}),t.jsx("button",{type:"button",className:"w-btn w-btn--primary w-btn--sm",onClick:j,disabled:!l||p,children:p?t.jsx(ye,{size:12}):b?"Update":"Create"})]})]}):null},k4=()=>{var N;const{activeWorkspace:e,loading:a,getRoles:s,createRole:n,deleteRole:i}=zt(),{deployment:l}=_e(),{toast:m}=_t(),[c,d]=o.useState({isOpen:!1}),[p,u]=o.useState(null),[h,f]=o.useState(null),g=o.useRef(null),x=o.useRef(new Map),{data:w=[],isLoading:b,mutate:_}=ke(e?`wacht-api-workspaces:${e.id}:roles`:null,()=>s()||[]),v=async j=>{try{await n(j.name,j.permissions||[]),m("Role saved successfully","info"),d({isOpen:!1}),_()}catch{m("Failed to save role","error")}},k=async j=>{try{await i(j),m("Role deleted","info"),u(null),_()}catch{m("Failed to delete role","error")}};return a||b?t.jsx(ye,{}):t.jsxs(t.Fragment,{children:[t.jsxs(Qc,{children:[t.jsxs("div",{className:"w-grow",children:[t.jsx("div",{className:"w-sec",children:"Roles"}),t.jsx("div",{className:"w-secsub",children:"Define granular permissions for this workspace."})]}),((N=l==null?void 0:l.b2b_settings)==null?void 0:N.custom_workspace_role_enabled)&&t.jsx(se,{ref:g,onClick:()=>d({isOpen:!0,triggerElement:g.current}),$size:"sm",children:"Add role"})]}),c.isOpen&&!c.role&&t.jsx(zi,{triggerRef:{current:c.triggerElement||null},onClose:()=>d({isOpen:!1}),onSuccess:v}),w.length===0?t.jsx(Ct,{title:"No roles yet",description:"Create workspace-specific roles to manage access."}):t.jsx(t.Fragment,{children:t.jsx(Pr,{children:t.jsxs($t,{children:[t.jsx(Ot,{children:t.jsxs(it,{children:[t.jsx($e,{children:"Role"}),t.jsx($e,{children:"Permissions"}),t.jsx($e,{})]})}),t.jsx(Zt,{children:w.map(j=>{var C;return t.jsxs(it,{children:[t.jsx(Ke,{children:t.jsxs("div",{className:"w-flex w-items-center w-gap-2 w-wrap",children:[t.jsx("span",{className:"w-sec",children:j.name}),!dr(j)&&t.jsx("span",{className:"w-pill",children:"Default"})]})}),t.jsx(Ke,{children:t.jsxs("span",{className:"w-text-secondary",children:[(C=j.permissions)==null?void 0:C.join(", "),!dr(j)&&" • Cannot be edited or deleted"]})}),t.jsx(Ht,{children:t.jsx(C4,{role:j,onEdit:y=>d({isOpen:!0,role:j,triggerElement:y}),onDelete:()=>u(j.id),open:h===j.id,onOpenChange:y=>f(y?j.id:null),dropdownButtonRefs:x})})]},j.id)})})]})})}),p&&t.jsx(Ya,{title:"Delete role?",description:"Are you sure? This will remove the role from all workspace members.",onConfirm:()=>{const j=w.find(C=>C.id===p);j&&k(j)},onCancel:()=>u(null)}),c.isOpen&&c.role&&t.jsx(zi,{role:c.role,triggerRef:{current:c.triggerElement||null},onClose:()=>d({isOpen:!1}),onSuccess:v})]})},C4=({role:e,onEdit:a,onDelete:s,open:n,onOpenChange:i,dropdownButtonRefs:l})=>dr(e)?t.jsxs(js,{open:n,openChange:i,children:[t.jsx(ks,{children:t.jsx(Qs,{ref:c=>{c&&l.current.set(e.id,c)},children:"•••"})}),t.jsxs(_s,{children:[t.jsx(ea,{onClick:()=>a(l.current.get(e.id)??null),children:"Edit Role"}),t.jsxs(ea,{$destructive:!0,onClick:s,children:[t.jsx(gr,{size:16})," Remove Role"]})]})]}):t.jsx(Qs,{disabled:!0,title:"Deployment roles cannot be edited","aria-label":"Deployment roles cannot be edited",children:"•••"}),N4=e=>(e||"").slice(0,2).toUpperCase()||"W",Jc=()=>{var b,_;const{activeWorkspace:e,loading:a,updateWorkspace:s}=zt(),{deployment:n}=_e(),[i,l]=o.useState("general"),[m,c]=o.useState(null),[d,p]=o.useState("info"),[u,h]=o.useState(!1),f=o.useRef(null),g=o.useCallback((v,k="info")=>{c(v),p(k),setTimeout(()=>c(null),3e3)},[]),x=async v=>{var N;const k=(N=v.target.files)==null?void 0:N[0];if(k){if(k.size>2*1024*1024){g("File size cannot exceed 2MB","error");return}if(!k.type.startsWith("image/")){g("Please select a valid image file","error");return}try{h(!0),await s({image:k}),g("Logo updated","info")}catch(j){g((j==null?void 0:j.message)||"Failed to update logo","error")}finally{h(!1),f.current&&(f.current.value="")}}};if(a&&!e)return t.jsx(Me,{children:t.jsx(Hi,{className:"w-items-center w-justify-center",children:t.jsx(ye,{})})});if(!e)return null;const w=(b=e.organization)==null?void 0:b.name;return t.jsx(Me,{children:t.jsx(l4,{children:t.jsx(Sr.Provider,{value:{screen:null,setScreen:()=>{},toast:g},children:t.jsxs(Hi,{className:"w-relative",children:[t.jsxs(m4,{children:[t.jsxs("button",{type:"button",className:"w-avatar w-avatar--lg w-avatar-edit",onClick:()=>{var v;return(v=f.current)==null?void 0:v.click()},disabled:u,"data-busy":u?"":void 0,title:"Change logo","aria-label":"Change workspace logo",children:[e.image_url?t.jsx("img",{src:e.image_url,alt:e.name}):N4(e.name),t.jsx("span",{className:"w-avatar-veil",children:u?t.jsx(ye,{size:14}):t.jsx(an,{size:16})})]}),t.jsx("input",{ref:f,type:"file",accept:"image/*",className:"w-none",hidden:!0,onChange:x}),t.jsxs(p4,{children:[t.jsx(h4,{children:e.name}),t.jsx(f4,{children:w?`${w} · Workspace settings`:"Workspace settings"})]})]}),t.jsx(c4,{children:t.jsxs(d4,{children:[t.jsx(Os,{$isActive:i==="general",onClick:()=>l("general"),children:t.jsxs(Zs,{children:[t.jsx(Sa,{size:14})," General"]})}),t.jsx(Os,{$isActive:i==="members",onClick:()=>l("members"),children:t.jsxs(Zs,{children:[t.jsx(ls,{size:14})," Members"]})}),t.jsx(Os,{$isActive:i==="invitations",onClick:()=>l("invitations"),children:t.jsxs(Zs,{children:[t.jsx(Nl,{size:14})," Invitations"]})}),((_=n==null?void 0:n.b2b_settings)==null?void 0:_.custom_workspace_role_enabled)&&t.jsx(Os,{$isActive:i==="roles",onClick:()=>l("roles"),children:t.jsxs(Zs,{children:[t.jsx(Xt,{size:14})," Roles"]})})]})}),t.jsxs(u4,{children:[i==="general"&&t.jsx(w4,{}),i==="members"&&t.jsx(x4,{}),i==="invitations"&&t.jsx(j4,{}),i==="roles"&&t.jsx(k4,{})]}),m&&t.jsxs("div",{className:`w-toast w-toast--contained ${d==="error"?"w-toast--error":"w-toast--success"}`,children:[t.jsx("span",{className:"w-toast-ic",children:d==="error"?t.jsx(Ha,{size:14}):t.jsx(Ge,{size:14})}),t.jsx("span",{className:"w-toast-msg",children:m})]})]})})})})},$r=({isOpen:e,onClose:a,title:s,showHeader:n,headerContent:i,footerContent:l,customContent:m,children:c,showCloseButton:d})=>t.jsx(ze,{isOpen:e,onClose:a,children:t.jsx(ze.Overlay,{children:t.jsxs(ze.Content,{className:"w-dialog--panel",children:[n&&t.jsx(ze.Header,{showCloseButton:d,children:i||s}),m||c||t.jsx(Jc,{}),l&&t.jsx(ze.Footer,{children:l})]})})}),Xc=["organization:admin"],e0=["organization:admin","organization:manage"],t0=["workspace:admin"],a0=["workspace:admin","workspace:manage"];function Or(e,a){return e!=null&&e.roles?e.roles.some(s=>{var n;return(n=s.permissions)==null?void 0:n.some(i=>a.includes(i))}):!1}function Zr(e){return Or(e,e0)}function S4(e){return Or(e,Xc)}function Hr(e,a){return e!=null&&e.roles?e.roles.some(s=>{var n;return(n=s.permissions)==null?void 0:n.some(i=>a.includes(i))}):!1}function Fr(e){return Hr(e,a0)}function E4(e){return Hr(e,t0)}const s0=({showPersonal:e=!0})=>{var Se,qe,le;const[a,s]=o.useState(!1),[n,i]=o.useState(!1),[l,m]=o.useState(new Set),c=o.useRef(null),d=o.useRef(null),p=xt({triggerRef:c,isOpen:a,minWidth:300}),u=Kt(!1),h=Kt(!1),f=Kt(!1),g=Kt(!1),[x,w]=o.useState(null),[b,_]=o.useState(null),{organizationMemberships:v,loading:k,refetch:N}=fa(),{activeOrganization:j,activeMembership:C,leave:y}=ha(),{activeWorkspace:E,activeMembership:R,leave:F}=zt(),{workspaces:A,loading:I}=wa(),{session:L,switchOrganization:S,switchWorkspace:O}=ot(),{deployment:P}=_e(),$=P==null?void 0:P.b2b_settings.organizations_enabled,Z=$&&(P==null?void 0:P.b2b_settings.workspaces_enabled),H=P==null?void 0:P.b2b_settings.allow_users_to_create_orgs,M=!C,B=o.useMemo(()=>{var Y,q;return M?{name:"Personal account",image_url:(q=(Y=L==null?void 0:L.active_signin)==null?void 0:Y.user)==null?void 0:q.profile_picture_url,isPersonal:!0}:{name:Z&&E?`${j==null?void 0:j.name} / ${E.name}`:(j==null?void 0:j.name)||"",image_url:j==null?void 0:j.image_url,isPersonal:!1}},[M,j,E,L,Z]);if(o.useEffect(()=>{j&&Z&&m(V=>{if(V.has(j.id))return V;const Y=new Set(V);return Y.add(j.id),Y})},[j,Z]),o.useEffect(()=>{if(!a)return;let V=null;const Y=setTimeout(()=>{const q=G=>{var z,me;const de=G.target;(z=c.current)!=null&&z.contains(de)||(me=d.current)!=null&&me.contains(de)||(s(!1),_(null))};document.addEventListener("mousedown",q),V=()=>document.removeEventListener("mousedown",q)},50);return()=>{clearTimeout(Y),V==null||V()}},[a]),o.useEffect(()=>{if(!b)return;const V=setTimeout(()=>_(null),5e3);return()=>clearTimeout(V)},[b]),!$)return null;const D=V=>V.split(" ").map(Y=>Y[0]).join("").toUpperCase().slice(0,2),W=V=>{i(!0),S(V).finally(()=>i(!1))},K=V=>{i(!0),O(V).finally(()=>i(!1))},ee=V=>{m(Y=>{const q=new Set(Y);return q.has(V)?q.delete(V):q.add(V),q})},ce=()=>{h.open(),s(!1)},be=()=>{g.open(),s(!1)},Q=async()=>{if(y){_(null);try{await y(),await N(),s(!1)}catch(V){_(V instanceof Error?V.message:"Failed to leave organization")}}},ie=async()=>{if(F){_(null);try{await F(),s(!1)}catch(V){_(V instanceof Error?V.message:"Failed to leave workspace")}}},ne=!!((Se=C==null?void 0:C.eligibility_restriction)!=null&&Se.type)&&C.eligibility_restriction.type!=="none",U=!!j&&!ne&&Zr(C),Qe=!!Z&&!!E&&!ne&&Fr(R);return!!!L||k||Z&&I?t.jsx(Me,{children:t.jsx("div",{className:"w-full w-relative",children:t.jsxs("div",{className:"w-combo",children:[t.jsx("span",{className:"w-skel",style:{width:20,height:20}}),t.jsx("span",{className:"w-skel w-grow",style:{height:12}})]})})}):t.jsx(Me,{children:t.jsxs("div",{className:"w-full w-relative",children:[t.jsxs("button",{ref:c,className:"w-orgtrigger","data-open":a?"":void 0,onClick:()=>{s(!a),a||_(null)},disabled:n,children:[t.jsx("span",{className:`w-avatar w-avatar--sm${B.isPersonal,""}`,children:B.image_url?t.jsx("img",{src:B.image_url,alt:B.name}):B.isPersonal?t.jsx(ps,{size:11}):D(B.name)}),t.jsx("span",{className:"w-grow w-truncate",children:B.name}),t.jsx(yu,{size:13})]}),typeof window<"u"&&Xs.createPortal(t.jsxs("div",{ref:d,className:"wacht-root w-menu w-flex-col",style:{position:"fixed",width:300,maxWidth:"calc(100vw - 16px)",maxHeight:p!=null&&p.maxHeight?`${p.maxHeight}px`:420,padding:0,zIndex:99999,top:(p==null?void 0:p.top)!==void 0?`${p.top}px`:void 0,bottom:(p==null?void 0:p.bottom)!==void 0?`${p.bottom}px`:void 0,left:(p==null?void 0:p.left)!==void 0?`${p.left}px`:void 0,right:(p==null?void 0:p.right)!==void 0?`${p.right}px`:void 0,visibility:p&&a?"visible":"hidden",opacity:a&&p?1:0,transform:a?"translateY(0)":"translateY(-4px)",pointerEvents:a?"auto":"none",transition:`opacity 0.15s ease, transform 0.15s ease, visibility 0s linear ${a?"0s":"0.15s"}`},children:[b&&t.jsxs("div",{className:"w-banner w-banner--error w-switch-banner",children:[t.jsx(Aa,{size:13}),t.jsx("span",{className:"w-banner-txt w-text-error",children:b})]}),t.jsx("div",{className:"w-grow w-switch-body",children:k||I?t.jsx(t.Fragment,{children:[1,2,3].map(V=>t.jsxs("div",{className:"w-flex w-items-center w-gap-3",style:{padding:"0 8px",height:34},children:[t.jsx("span",{className:"w-skel",style:{width:22,height:22}}),t.jsx("span",{className:"w-skel",style:{width:V===2?"60%":"80%",height:11}})]},V))}):t.jsxs(t.Fragment,{children:[e&&t.jsxs("button",{className:"w-menu-item",onClick:()=>{M||W()},disabled:n||M,children:[t.jsx("span",{className:"w-avatar w-avatar--sm",children:(le=(qe=L==null?void 0:L.active_signin)==null?void 0:qe.user)!=null&&le.profile_picture_url?t.jsx("img",{src:L.active_signin.user.profile_picture_url,alt:"Personal"}):t.jsx(ps,{size:12})}),t.jsx("span",{className:"w-grow w-truncate",children:"Personal account"}),M&&t.jsx(Ge,{size:13,className:"w-text-primary w-none"})]}),((v==null?void 0:v.length)??0)>0&&t.jsxs(t.Fragment,{children:[t.jsx("hr",{className:"w-hr"}),t.jsx("div",{className:"w-menu-label",children:"Organizations"})]}),v==null?void 0:v.map(V=>{var me,st;const Y=V.organization,q=Y.id===(j==null?void 0:j.id),G=l.has(Y.id),de=Z?(A==null?void 0:A.filter(Oe=>Oe.organization.id===Y.id))||[]:[],z=!!((me=V.eligibility_restriction)!=null&&me.type)&&V.eligibility_restriction.type!=="none";return t.jsxs(o.Fragment,{children:[t.jsxs("button",{className:"w-menu-item",onClick:()=>{z||(Z?ee(Y.id):q||W(Y.id))},disabled:n,style:z?{opacity:.55,cursor:"not-allowed"}:void 0,title:(st=V.eligibility_restriction)==null?void 0:st.message,children:[t.jsx("span",{className:"w-avatar w-avatar--sm",children:Y.image_url?t.jsx("img",{src:Y.image_url,alt:Y.name}):D(Y.name)}),t.jsx("span",{className:"w-grow w-truncate",children:Y.name}),t.jsxs("span",{className:"w-inline w-gap-1 w-none",children:[z&&t.jsx(Aa,{size:12,className:"w-text-error"}),q&&U&&t.jsx("span",{className:"w-rowact",role:"button",title:"Organization settings","aria-label":"Organization settings",onClick:Oe=>{Oe.stopPropagation(),ce()},children:t.jsx(Sa,{size:13})}),q&&!z&&t.jsx("span",{className:"w-rowact",role:"button",title:"Leave organization","aria-label":"Leave organization",onClick:Oe=>{Oe.stopPropagation(),Q()},children:t.jsx(Ea,{size:13})}),q&&!Z&&t.jsx(Ge,{size:13,className:"w-text-primary"}),Z&&t.jsx(Dt,{size:11,className:"w-text-muted",style:{transition:"transform 0.2s ease",transform:G?"rotate(0deg)":"rotate(-90deg)"}})]})]}),Z&&G&&!z&&t.jsxs("div",{className:"w-switch-nest",children:[de.map(Oe=>{var J,re;const Ze=q&&(E==null?void 0:E.id)===Oe.id,mt=((J=Oe.eligibility_restriction)==null?void 0:J.type)&&Oe.eligibility_restriction.type!=="none";return t.jsxs("button",{className:"w-menu-item",onClick:()=>{!Ze&&!mt&&K(Oe.id)},disabled:n,style:mt?{opacity:.55,cursor:"not-allowed"}:void 0,title:(re=Oe.eligibility_restriction)==null?void 0:re.message,children:[t.jsx("span",{className:"w-avatar w-avatar--sm",children:Oe.image_url?t.jsx("img",{src:Oe.image_url,alt:Oe.name}):D(Oe.name).charAt(0)}),t.jsx("span",{className:"w-grow w-truncate",children:Oe.name}),t.jsxs("span",{className:"w-inline w-gap-1 w-none",children:[mt&&t.jsx(Aa,{size:12,className:"w-text-error"}),Ze&&Qe&&t.jsx("span",{className:"w-rowact",role:"button",title:"Workspace settings","aria-label":"Workspace settings",onClick:ue=>{ue.stopPropagation(),be()},children:t.jsx(Sa,{size:13})}),Ze&&t.jsx("span",{className:"w-rowact",role:"button",title:"Leave workspace","aria-label":"Leave workspace",onClick:ue=>{ue.stopPropagation(),ie()},children:t.jsx(Ea,{size:13})}),Ze&&t.jsx(Ge,{size:12,className:"w-text-primary"})]})]},Oe.id)}),t.jsxs("button",{className:"w-menu-item w-menu-item--muted",onClick:()=>{w(Y.id),f.open()},disabled:n,children:[t.jsx(Nt,{size:13}),t.jsx("span",{className:"w-grow w-truncate",children:"New workspace"})]})]})]},Y.id)}),H&&t.jsxs(t.Fragment,{children:[t.jsx("hr",{className:"w-hr"}),t.jsxs("button",{className:"w-menu-item w-menu-item--muted",onClick:()=>u.open(),disabled:n,children:[t.jsx(Nt,{size:13}),t.jsx("span",{className:"w-grow w-truncate",children:"New organization"})]})]})]})})]}),document.body),$&&H&&t.jsx(Wc,{isOpen:u.isOpen,onClose:u.close,onCreated:N}),t.jsx(Yc,{isOpen:h.isOpen,onClose:h.close}),Z&&t.jsxs(t.Fragment,{children:[t.jsx($r,{isOpen:g.isOpen,onClose:g.close}),t.jsx(Lr,{isOpen:f.isOpen,onClose:()=>{f.close(),w(null)},organizationId:x||void 0})]})]})})},n0=o.createContext(void 0),ta=()=>{const e=o.useContext(n0);if(!e)throw new Error("useScreenContext must be used within a ScreenProvider");return e},he=(...e)=>e.filter(Boolean).join(" "),r0=o.forwardRef(({className:e,...a},s)=>t.jsx("div",{ref:s,className:he("w-contents",e),...a}));r0.displayName="TypographyProvider";const ur=o.forwardRef(({className:e,...a},s)=>t.jsx("div",{ref:s,className:he("w-card","w-flex-col","w-full","w-minh-full",e),...a}));ur.displayName="Container";const i0=o.forwardRef(({className:e,...a},s)=>t.jsx("div",{ref:s,className:he("w-tabsbar",e),...a}));i0.displayName="TabsContainer";const o0=o.forwardRef(({className:e,...a},s)=>t.jsx("div",{ref:s,className:he("w-flex","w-items-center","w-gap-1","w-tabs",e),...a}));o0.displayName="TabsList";const _a=o.forwardRef(({$isActive:e,className:a,...s},n)=>t.jsx("button",{ref:n,className:he("w-tab",e&&"w-tab--active",a),...s}));_a.displayName="Tab";const ka=o.forwardRef(({className:e,...a},s)=>t.jsx("span",{ref:s,className:he("w-inline","w-gap-1",e),...a}));ka.displayName="TabIcon";const l0=o.forwardRef(({className:e,children:a,...s},n)=>t.jsx("div",{ref:n,className:he("w-tabbody",e),...s,children:t.jsx("div",{className:"w-tabpane",children:a})}));l0.displayName="TabContent";const A4=o.forwardRef(({className:e,...a},s)=>t.jsx("button",{ref:s,className:he("w-btn","w-btn--icon",e),...a}));A4.displayName="IconButton";const c0=o.forwardRef(({className:e,...a},s)=>t.jsx("div",{ref:s,className:he("w-flex","w-items-center","w-justify-between","w-wrap","w-gap-3",e),...a}));c0.displayName="HeaderCTAContainer";const M4=o.forwardRef(({className:e,...a},s)=>t.jsx("div",{ref:s,className:he("w-flex","w-items-start","w-gap-6",e),...a}));M4.displayName="ProfileSectionLayout";const R4=o.forwardRef(({className:e,...a},s)=>t.jsx("div",{ref:s,className:he("w-none",e),...a}));R4.displayName="ProfileImageContainer";const d0=o.forwardRef(({className:e,...a},s)=>t.jsx("div",{ref:s,className:he("w-vrow",e),...a}));d0.displayName="SecurityItemRow";const u0=o.forwardRef(({className:e,...a},s)=>t.jsx("div",{ref:s,className:he("w-grow",e),...a}));u0.displayName="SecurityItemContent";const m0=o.forwardRef(({className:e,...a},s)=>t.jsx("div",{ref:s,className:he("w-flex","w-items-center","w-gap-2","w-none",e),...a}));m0.displayName="SecurityItemActions";const Tr=o.forwardRef(({className:e,...a},s)=>t.jsx("div",{ref:s,className:he("w-sechead",e),...a}));Tr.displayName="ResponsiveHeaderContainer";const pn=o.forwardRef(({className:e,...a},s)=>t.jsx("div",{ref:s,className:he("w-full",e),...a}));pn.displayName="DesktopTableContainer";const p0=o.forwardRef(({className:e,...a},s)=>t.jsx("div",{ref:s,className:he("w-flex","w-gap-3",e),...a}));p0.displayName="FormRow";const L4=o.forwardRef(({className:e,...a},s)=>t.jsx("div",{ref:s,className:he("w-vrow",e),...a}));L4.displayName="ConnectionItemRow";const P4=o.forwardRef(({className:e,...a},s)=>t.jsx("div",{ref:s,className:he("w-flex","w-items-center","w-gap-2","w-grow",e),...a}));P4.displayName="ConnectionLeft";const $4=o.forwardRef(({className:e,...a},s)=>t.jsx("div",{ref:s,className:he("w-flex","w-items-center","w-justify-end","w-gap-1","w-none",e),...a}));$4.displayName="ConnectionRight";const Ir=o.forwardRef(({className:e,...a},s)=>t.jsx("div",{ref:s,className:he("w-iconbox",e),...a}));Ir.displayName="IconWrapper";const O4=o.forwardRef(({className:e,...a},s)=>t.jsx("div",{ref:s,className:he("w-flex","w-wrap","w-gap-2",e),...a}));O4.displayName="ButtonActions";const h0=o.forwardRef(({className:e,...a},s)=>t.jsx("div",{ref:s,className:he("w-page-head",e),...a}));h0.displayName="PageHeader";const Z4=o.forwardRef(({className:e,...a},s)=>t.jsx("div",{ref:s,className:he("w-avatar",e),...a}));Z4.displayName="PageHeaderAvatar";const f0=o.forwardRef(({className:e,...a},s)=>t.jsx("div",{ref:s,className:he("w-flex-col","w-gap-1","w-grow",e),...a}));f0.displayName="PageHeaderInfo";const w0=o.forwardRef(({className:e,...a},s)=>t.jsx("div",{ref:s,className:he("w-sec","w-truncate",e),...a}));w0.displayName="PageHeaderName";const g0=o.forwardRef(({className:e,...a},s)=>t.jsx("div",{ref:s,className:he("w-secsub","w-truncate",e),...a}));g0.displayName="PageHeaderSub";const H4=o.forwardRef(({className:e,...a},s)=>t.jsx("div",{ref:s,className:he("w-flex","w-items-center","w-gap-1","w-none",e),...a}));H4.displayName="PageHeaderActions";const F4=o.forwardRef(({className:e,...a},s)=>t.jsx("div",{ref:s,className:he("w-flex-col","w-gap-4",e),...a}));F4.displayName="PageContent";const T4=o.forwardRef(({className:e,...a},s)=>t.jsx("section",{ref:s,className:he("w-card",e),...a}));T4.displayName="Card";const I4=o.forwardRef(({className:e,...a},s)=>t.jsx("section",{ref:s,className:he("w-card","w-danger",e),...a}));I4.displayName="DangerCard";const V4=o.forwardRef(({className:e,...a},s)=>t.jsx("div",{ref:s,className:he("w-card-head",e),...a}));V4.displayName="CardHeader";const z4=o.forwardRef(({className:e,...a},s)=>t.jsx("div",{ref:s,className:he("w-flex-col","w-gap-1","w-grow",e),...a}));z4.displayName="CardTitleBlock";const D4=o.forwardRef(({className:e,...a},s)=>t.jsx("h3",{ref:s,className:he("w-sec",e),...a}));D4.displayName="CardTitle";const U4=o.forwardRef(({className:e,...a},s)=>t.jsx("p",{ref:s,className:he("w-secsub",e),...a}));U4.displayName="CardSubtitle";const W4=o.forwardRef(({className:e,...a},s)=>t.jsx("div",{ref:s,className:he("w-flex","w-items-center","w-wrap","w-gap-2","w-none",e),...a}));W4.displayName="CardActions";const B4=o.forwardRef(({className:e,...a},s)=>t.jsx("div",{ref:s,className:he("w-hr",e),...a}));B4.displayName="CardDivider";const G4=o.forwardRef(({className:e,...a},s)=>t.jsx("div",{ref:s,className:he("w-card-body",e),...a}));G4.displayName="CardBody";const q4=o.forwardRef(({className:e,...a},s)=>t.jsx("div",{ref:s,className:he("w-card-foot",e),...a}));q4.displayName="CardFooter";const K4=o.forwardRef(({className:e,...a},s)=>t.jsx("div",{ref:s,className:he("w-list",e),...a}));K4.displayName="RowList";const Y4=o.forwardRef(({className:e,...a},s)=>t.jsx("div",{ref:s,className:he("w-rowitem",e),...a}));Y4.displayName="RowItem";const Q4=o.forwardRef(({className:e,...a},s)=>t.jsx("div",{ref:s,className:he("w-flex-col","w-gap-1","w-grow",e),...a}));Q4.displayName="RowInfo";const J4=o.forwardRef(({className:e,...a},s)=>t.jsx("div",{ref:s,className:he("w-sec",e),...a}));J4.displayName="RowTitle";const X4=o.forwardRef(({className:e,...a},s)=>t.jsx("div",{ref:s,className:he("w-secsub",e),...a}));X4.displayName="RowSub";const e6=o.forwardRef(({className:e,...a},s)=>t.jsx("div",{ref:s,className:he("w-flex","w-items-center","w-wrap","w-gap-2","w-none",e),...a}));e6.displayName="RowActions";const t6={primary:"w-pill--current",success:"w-pill--success",warning:"w-pill--pending",danger:"w-pill--error",neutral:""},Ga=({$variant:e="neutral",className:a,children:s,...n})=>t.jsxs("span",{className:he("w-pill",t6[e],a),...n,children:[t.jsx("span",{className:"w-dot"}),s]}),a6=o.forwardRef(({className:e,...a},s)=>t.jsx("div",{ref:s,className:he("w-list",e),...a}));a6.displayName="Table";const s6=o.forwardRef(({$cols:e,className:a,style:s,...n},i)=>t.jsx("div",{ref:i,className:he("w-listhead","w-gap-4",a),style:{gridTemplateColumns:e||"1fr 1fr auto",...s},...n}));s6.displayName="TableHead";const n6=o.forwardRef(({className:e,...a},s)=>t.jsx("div",{ref:s,className:e,...a}));n6.displayName="Th";const r6=o.forwardRef(({$cols:e,className:a,style:s,...n},i)=>t.jsx("div",{ref:i,className:he("w-row","w-gap-4",a),style:{gridTemplateColumns:e||"1fr 1fr auto",...s},...n}));r6.displayName="Tr";const i6=o.forwardRef(({className:e,...a},s)=>t.jsx("div",{ref:s,className:he("w-truncate","w-text-secondary",e),...a}));i6.displayName="Td";const o6=o.forwardRef(({className:e,...a},s)=>t.jsx("div",{ref:s,className:he("w-grid-2",e),...a}));o6.displayName="FieldGrid";const l6=o.forwardRef(({className:e,...a},s)=>t.jsx("div",{ref:s,className:he("w-field",e),...a}));l6.displayName="Field";const c6=o.forwardRef(({className:e,...a},s)=>t.jsx("label",{ref:s,className:he("w-label",e),...a}));c6.displayName="FieldLabel";const d6=()=>{var I,L;const{deployment:e}=_e(),{refetch:a}=ot(),{user:s,updateProfile:n,deleteAccount:i}=ga(),{toast:l}=ta(),[m,c]=o.useState(""),[d,p]=o.useState(""),[u,h]=o.useState(""),[f,g]=o.useState(!1),[x,w]=o.useState(!1),[b,_]=o.useState(!1),[v,k]=o.useState("");o.useEffect(()=>{s&&!f&&(c(s.first_name||""),p(s.last_name||""),h(s.username||""),g(!0))},[s,f]);const N=o.useCallback(async()=>{if(s)try{const S={};m!==s.first_name&&(S.first_name=m),d!==s.last_name&&(S.last_name=d),u!==s.username&&(S.username=u),Object.keys(S).length>0&&await n(S)}catch(S){l(S.message||"Failed to save profile changes","error")}},[s,n,m,d,u,l]),j=S=>{c(S.target.value)},C=S=>{p(S.target.value)},y=S=>{h(S.target.value)},E=()=>{N()},R=()=>{N()},F=()=>{N()};if(!s)return t.jsx("div",{className:"w-loading",children:t.jsx(ye,{})});const A=async()=>{if(!(!s||v!=="delete this account")){_(!0);try{await i(""),l("Account deleted successfully","info"),await a()}catch(S){l(S.message||"Failed to delete account","error")}finally{_(!1),k(""),w(!1)}}};return t.jsxs("div",{className:"w-flex-col w-gap-6",children:[t.jsxs("div",{className:"w-flex-col w-gap-4",children:[t.jsx("p",{className:"w-secsub",children:"Basic information about your profile"}),t.jsxs("div",{className:"w-flex-col w-gap-4",children:[t.jsxs(p0,{children:[t.jsxs(We,{className:"w-grow",children:[t.jsx(Ve,{htmlFor:"firstName",children:"First Name"}),t.jsx(xe,{id:"firstName",type:"text",value:m,onChange:j,onBlur:E,placeholder:"Enter your first name",required:!0})]}),t.jsxs(We,{className:"w-grow",children:[t.jsx(Ve,{htmlFor:"lastName",children:"Last Name"}),t.jsx(xe,{id:"lastName",type:"text",value:d,onChange:C,onBlur:R,placeholder:"Enter your last name",required:!0})]})]}),((L=(I=e==null?void 0:e.auth_settings)==null?void 0:I.username)==null?void 0:L.enabled)&&t.jsxs(We,{children:[t.jsx(Ve,{htmlFor:"username",children:"Username"}),t.jsx(xe,{id:"username",type:"text",value:u,onChange:y,onBlur:F,placeholder:"Enter your username",required:!0})]})]})]}),t.jsx("div",{className:"w-hr"}),t.jsxs("div",{className:"w-flex-col w-gap-4",children:[t.jsxs("div",{className:"w-flex-col w-gap-1",children:[t.jsx("h3",{className:"w-sec",children:"Danger Zone"}),t.jsx("p",{className:"w-secsub",children:"Irreversible and destructive actions"})]}),t.jsxs("div",{className:"w-danger w-flex-col w-items-start",children:[t.jsxs("div",{className:"w-flex w-items-center w-justify-between w-gap-4 w-full",children:[t.jsxs("div",{className:"w-flex-col w-gap-1",children:[t.jsx("div",{className:"w-sec",children:"Delete Account"}),t.jsx("div",{className:"w-secsub",children:"Once you delete your account, there is no going back. Please be certain."})]}),t.jsx(se,{$destructive:!0,$size:"sm",onClick:()=>{x?(w(!1),k("")):w(!0)},children:x?"Cancel":"Delete"})]}),x&&t.jsxs("div",{className:"w-full w-flex-col w-gap-3",children:[t.jsxs(We,{children:[t.jsx(Ve,{htmlFor:"confirm_username",children:'Type "delete this account" to confirm'}),t.jsx(xe,{id:"confirm_username",type:"text",value:v,onChange:S=>k(S.target.value),placeholder:"delete this account"})]}),t.jsx(se,{$destructive:!0,$fullWidth:!0,onClick:A,disabled:v!=="delete this account"||b,children:b?t.jsx(ye,{size:12}):"Delete Forever"})]})]})]})]})},Di=({onClose:e,onAddEmail:a,onAttemptVerification:s,onPrepareVerification:n,existingEmail:i,triggerRef:l})=>{const m=o.useRef(null),[c,d]=o.useState(!1),{toast:p}=ta(),u=xt({contentRef:m,triggerRef:l??{current:null},isOpen:c,minWidth:340,defaultMaxHeight:360});o.useEffect(()=>{d(!0);const j=y=>{m.current&&!m.current.contains(y.target)&&e()},C=y=>{y.key==="Escape"&&e()};return document.addEventListener("mousedown",j),document.addEventListener("keydown",C),()=>{document.removeEventListener("mousedown",j),document.removeEventListener("keydown",C)}},[e]);const[h,f]=o.useState(i?"otp":"email"),[g,x]=o.useState(i||""),[w,b]=o.useState(""),[_,v]=o.useState(!1),k=async()=>{if(!(!g||_)){v(!0);try{await a(g),f("otp")}catch(j){p(j.message||"Failed to add email. Please try again.","error")}finally{v(!1)}}},N=async()=>{v(!0);try{await s(w),e()}catch(j){p(j.message||"Failed to verify email. Check the code and try again.","error")}finally{v(!1)}};return c?t.jsx("div",{ref:m,className:"w-pop",style:{position:"fixed",zIndex:1001,maxWidth:"calc(100vw - 24px)",top:(u==null?void 0:u.top)!==void 0?`${u.top}px`:void 0,bottom:(u==null?void 0:u.bottom)!==void 0?`${u.bottom}px`:void 0,left:(u==null?void 0:u.left)!==void 0?`${u.left}px`:void 0,right:(u==null?void 0:u.right)!==void 0?`${u.right}px`:void 0,visibility:u?"visible":"hidden"},onClick:j=>j.stopPropagation(),children:h==="email"?t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"w-pop-body",children:[t.jsx("div",{className:"w-pop-title",children:"Add email address"}),t.jsxs("label",{className:"w-field",children:[t.jsx("span",{className:"w-label",children:"Email address"}),t.jsx(xe,{id:"email-input",type:"email",placeholder:"you@company.com",value:g,onChange:j=>x(j.target.value),onKeyDown:j=>{j.key==="Enter"&&k()},autoFocus:!0})]})]}),t.jsxs("div",{className:"w-pop-foot",children:[t.jsx("button",{type:"button",className:"w-btn w-btn--ghost w-btn--sm",onClick:e,children:"Cancel"}),t.jsx("button",{type:"button",className:"w-btn w-btn--primary w-btn--sm",onClick:k,disabled:!g||_,children:_?"Sending…":"Send code"})]})]}):t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"w-pop-body",children:[!i&&t.jsxs("button",{type:"button",className:"w-link w-link--muted w-inline w-gap-1",style:{alignSelf:"flex-start",background:"none",border:0,cursor:"pointer"},onClick:()=>f("email"),children:[t.jsx(sn,{size:11})," Back"]}),t.jsxs("div",{className:"w-flex-col w-gap-1",children:[t.jsx("div",{className:"w-pop-title",children:"Verify your email"}),t.jsxs("p",{className:"w-pop-sub",children:["Enter the 6-digit code sent to ",t.jsx("strong",{children:g})]})]}),t.jsx(xa,{onComplete:async j=>b(j),onResend:n,isSubmitting:_})]}),t.jsxs("div",{className:"w-pop-foot",children:[t.jsx("button",{type:"button",className:"w-btn w-btn--ghost w-btn--sm",onClick:e,children:"Cancel"}),t.jsx("button",{type:"button",className:"w-btn w-btn--primary w-btn--sm",onClick:N,disabled:w.length<6||_,children:_?"Verifying…":"Verify"})]})]})}):null},u6=()=>{var R,F,A,I;const{deployment:e}=_e(),{toast:a}=ta(),[s,n]=o.useState(""),[i,l]=o.useState(!1),[m,c]=o.useState(null),[d,p]=o.useState(new Set),u=o.useRef(null),h=o.useRef({}),{user:f,createEmailAddress:g,deleteEmailAddress:x,prepareEmailVerification:w,attemptEmailVerification:b,makeEmailPrimary:_}=ga();if(!((F=(R=e==null?void 0:e.auth_settings)==null?void 0:R.email_address)!=null&&F.enabled))return null;const v=(L,S)=>{p(O=>{const P=new Set(O);return S?P.add(L):P.delete(L),P})},k=async L=>{v(L,!0);try{await _(L),await f.refetch(),a("Primary email updated","info")}catch(S){a(S.message||"Failed to update primary email","error")}finally{v(L,!1)}},N=async L=>{if(L===(f==null?void 0:f.primary_email_address_id)){a("Cannot delete primary email. Set another email as primary first.","error");return}v(L,!0);try{await x(L),await f.refetch(),a("Email removed","info")}catch(S){a(S.message||"Failed to delete email address. Please try again.","error")}finally{v(L,!1)}},j=async L=>{v(L,!0);try{await w(L),await f.refetch(),c(L)}catch(S){a(S.message||"Failed to send verification","error")}finally{v(L,!1)}},C=(f==null?void 0:f.user_email_addresses)||[],y=L=>L.id===(f==null?void 0:f.primary_email_address_id)?t.jsx(Ga,{$variant:"success",children:"Primary"}):L.verified?t.jsx(Ga,{$variant:"neutral",children:"Backup"}):t.jsx(Ga,{$variant:"warning",children:"Pending verification"}),E=L=>{const S=L.id===(f==null?void 0:f.primary_email_address_id),O=d.has(L.id);return S?t.jsx("span",{className:"w-secsub",children:"Cannot remove"}):t.jsxs("div",{className:"w-actions",children:[L.verified&&t.jsx(se,{$size:"sm",$outline:!0,disabled:O,onClick:()=>k(L.id),children:"Make primary"}),!L.verified&&t.jsx(se,{ref:P=>{P&&(h.current[L.id]=P)},$size:"sm",$outline:!0,disabled:O,onClick:()=>j(L.id),children:"Resend"}),t.jsx(se,{$size:"sm",$destructive:!0,disabled:O,onClick:()=>N(L.id),children:O?t.jsx(ye,{size:12}):"Remove"})]})};return t.jsxs(t.Fragment,{children:[t.jsxs(Tr,{children:[t.jsxs("div",{className:"w-grow w-flex-col w-gap-1",children:[t.jsx("div",{className:"w-sec",children:"Email addresses"}),t.jsx("div",{className:"w-secsub",children:"Sign in and receive notifications at these addresses."})]}),t.jsxs("div",{className:"w-none w-relative",children:[t.jsx(se,{ref:u,$size:"sm",onClick:()=>l(!0),children:"Add email"}),i&&t.jsx(Di,{triggerRef:u,onClose:()=>l(!1),onAddEmail:async L=>{const S=await g(L);n(S.data.id),await w(S.data.id),f.refetch()},onPrepareVerification:async()=>{await w(s),f.refetch()},onAttemptVerification:async L=>{await b(s,L),f.refetch(),l(!1),n(""),a("Email added and verified","info")}})]})]}),C.length?t.jsx(t.Fragment,{children:t.jsx(pn,{children:t.jsxs($t,{children:[t.jsx(Ot,{children:t.jsxs(it,{children:[t.jsx($e,{children:"Email address"}),t.jsx($e,{children:"Status"}),t.jsx($e,{})]})}),t.jsx(Zt,{children:C.map(L=>t.jsxs(it,{children:[t.jsx(Ke,{children:L.email}),t.jsx(Ke,{children:y(L)}),t.jsx(Ht,{children:E(L)})]},L.id))})]})})}):t.jsx(Ct,{title:"No email addresses",description:"Add an email address to get started."}),m&&t.jsx(Di,{existingEmail:(I=(A=f==null?void 0:f.user_email_addresses)==null?void 0:A.find(L=>L.id===m))==null?void 0:I.email,triggerRef:{current:h.current[m]},onClose:()=>c(null),onAddEmail:async()=>{},onPrepareVerification:async()=>{await w(m),f.refetch()},onAttemptVerification:async L=>{await b(m,L),f.refetch(),c(null),a("Email verified","info")}})]})},Ui=({onClose:e,onAddPhone:a,onAttemptVerification:s,existingPhone:n,onPrepareVerification:i,triggerRef:l})=>{var y;const m=o.useRef(null),[c,d]=o.useState(!1),{toast:p}=ta(),u=xt({contentRef:m,triggerRef:l??{current:null},isOpen:c,minWidth:340,defaultMaxHeight:360});o.useEffect(()=>{d(!0);const E=F=>{m.current&&!m.current.contains(F.target)&&e()},R=F=>{F.key==="Escape"&&e()};return document.addEventListener("mousedown",E),document.addEventListener("keydown",R),()=>{document.removeEventListener("mousedown",E),document.removeEventListener("keydown",R)}},[e]);const[h,f]=o.useState(n?"otp":"phone"),[g,x]=o.useState((n==null?void 0:n.replace(/^\+\d+/,""))||""),[w,b]=o.useState((y=Intl.DateTimeFormat().resolvedOptions().locale.split("-"))==null?void 0:y.pop()),[_,v]=o.useState(""),[k,N]=o.useState(!1),j=async()=>{if(!(!g||k)){N(!0);try{await a(g,w||""),f("otp")}catch(E){p(E.message||"Failed to add phone number. Please try again.","error")}finally{N(!1)}}},C=async()=>{N(!0);try{await s(_),e()}catch(E){p(E.message||"Failed to verify phone. Check the code and try again.","error")}finally{N(!1)}};return c?t.jsx("div",{ref:m,className:"w-pop",style:{position:"fixed",zIndex:1001,maxWidth:"calc(100vw - 24px)",top:(u==null?void 0:u.top)!==void 0?`${u.top}px`:void 0,bottom:(u==null?void 0:u.bottom)!==void 0?`${u.bottom}px`:void 0,left:(u==null?void 0:u.left)!==void 0?`${u.left}px`:void 0,right:(u==null?void 0:u.right)!==void 0?`${u.right}px`:void 0,visibility:u?"visible":"hidden"},onClick:E=>E.stopPropagation(),children:h==="phone"?t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"w-pop-body",children:[t.jsx("div",{className:"w-pop-title",children:"Add phone number"}),t.jsxs("label",{className:"w-field",children:[t.jsx("span",{className:"w-label",children:"Phone number"}),t.jsx(bs,{value:g,onChange:E=>x(E.target.value),error:"",countryCode:w,setCountryCode:b})]})]}),t.jsxs("div",{className:"w-pop-foot",children:[t.jsx("button",{type:"button",className:"w-btn w-btn--ghost w-btn--sm",onClick:e,children:"Cancel"}),t.jsx("button",{type:"button",className:"w-btn w-btn--primary w-btn--sm",onClick:j,disabled:!g||k,children:k?"Sending…":"Send code"})]})]}):t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"w-pop-body",children:[!n&&t.jsxs("button",{type:"button",className:"w-link w-link--muted w-inline w-gap-1",style:{alignSelf:"flex-start",background:"none",border:0,cursor:"pointer"},onClick:()=>f("phone"),children:[t.jsx(sn,{size:11})," Back"]}),t.jsxs("div",{className:"w-flex-col w-gap-1",children:[t.jsx("div",{className:"w-pop-title",children:"Verify phone number"}),t.jsxs("p",{className:"w-pop-sub",children:["Enter the 6-digit code sent to ",t.jsx("strong",{children:n||g})]})]}),t.jsx(xa,{onComplete:E=>v(E),onResend:async()=>i(),isSubmitting:k})]}),t.jsxs("div",{className:"w-pop-foot",children:[t.jsx("button",{type:"button",className:"w-btn w-btn--ghost w-btn--sm",onClick:e,children:"Cancel"}),t.jsx("button",{type:"button",className:"w-btn w-btn--primary w-btn--sm",onClick:C,disabled:_.length!==6||k,children:k?"Verifying…":"Verify"})]})]})}):null},m6=()=>{var F,A,I,L;const{deployment:e}=_e(),{toast:a}=ta(),[s,n]=o.useState(""),[i,l]=o.useState(!1),[m,c]=o.useState(null),[d,p]=o.useState(new Set),u=o.useRef(null),h=o.useRef({}),{user:f,createPhoneNumber:g,deletePhoneNumber:x,preparePhoneVerification:w,attemptPhoneVerification:b,makePhonePrimary:_}=ga();if(!((A=(F=e==null?void 0:e.auth_settings)==null?void 0:F.phone_number)!=null&&A.enabled))return null;const v=(S,O)=>{p(P=>{const $=new Set(P);return O?$.add(S):$.delete(S),$})},k=S=>{const O=Bs.find(P=>P.dialCode===S);return(O==null?void 0:O.flag)||"🌍"},N=async S=>{v(S,!0);try{await _(S),await f.refetch(),a("Primary phone updated","info")}catch(O){a(O.message||"Failed to update primary phone","error")}finally{v(S,!1)}},j=async S=>{if(S===(f==null?void 0:f.primary_phone_number_id)){a("Cannot delete primary phone. Set another phone as primary first.","error");return}v(S,!0);try{await x(S),await f.refetch(),a("Phone removed","info")}catch(O){a(O.message||"Failed to delete phone. Please try again.","error")}finally{v(S,!1)}},C=async S=>{v(S,!0);try{await w(S),await f.refetch(),c(S)}catch(O){a(O.message||"Failed to send verification","error")}finally{v(S,!1)}},y=(f==null?void 0:f.user_phone_numbers)||[],E=S=>S.id===(f==null?void 0:f.primary_phone_number_id)?t.jsx(Ga,{$variant:"success",children:"Primary"}):S.verified?t.jsx(Ga,{$variant:"neutral",children:"Backup"}):t.jsx(Ga,{$variant:"warning",children:"Pending verification"}),R=S=>{const O=S.id===(f==null?void 0:f.primary_phone_number_id),P=d.has(S.id);return O?t.jsx("span",{className:"w-secsub",children:"Cannot remove"}):t.jsxs("div",{className:"w-actions",children:[S.verified&&t.jsx(se,{$size:"sm",$outline:!0,disabled:P,onClick:()=>N(S.id),children:"Make primary"}),!S.verified&&t.jsx(se,{ref:$=>{$&&(h.current[S.id]=$)},$size:"sm",$outline:!0,disabled:P,onClick:()=>C(S.id),children:"Resend"}),t.jsx(se,{$size:"sm",$destructive:!0,disabled:P,onClick:()=>j(S.id),children:P?t.jsx(ye,{size:12}):"Remove"})]})};return t.jsxs(t.Fragment,{children:[t.jsxs(Tr,{children:[t.jsxs("div",{className:"w-grow w-flex-col w-gap-1",children:[t.jsx("div",{className:"w-sec",children:"Phone numbers"}),t.jsx("div",{className:"w-secsub",children:"Used for sign-in and two-factor authentication."})]}),t.jsxs("div",{className:"w-none w-relative",children:[t.jsx(se,{ref:u,$size:"sm",onClick:()=>l(!0),children:"Add phone"}),i&&t.jsx(Ui,{triggerRef:u,onClose:()=>l(!1),onAddPhone:async(S,O)=>{const P=await g(S,O);n(P.data.id),await w(P.data.id)},onPrepareVerification:async()=>{await w(s),f.refetch()},onAttemptVerification:async S=>{await b(s,S),f.refetch(),l(!1),n(""),a("Phone added and verified","info")}}),m&&t.jsx(Ui,{existingPhone:(L=(I=f==null?void 0:f.user_phone_numbers)==null?void 0:I.find(S=>S.id===m))==null?void 0:L.phone_number,triggerRef:{current:h.current[m]},onClose:()=>c(null),onAddPhone:async()=>{},onPrepareVerification:async()=>{await w(m),f.refetch()},onAttemptVerification:async S=>{await b(m,S),f.refetch(),c(null),a("Phone verified","info")}})]})]}),y.length?t.jsx(t.Fragment,{children:t.jsx(pn,{children:t.jsxs($t,{children:[t.jsx(Ot,{children:t.jsxs(it,{children:[t.jsx($e,{children:"Phone number"}),t.jsx($e,{children:"Status"}),t.jsx($e,{})]})}),t.jsx(Zt,{children:y.map(S=>t.jsxs(it,{children:[t.jsx(Ke,{children:t.jsxs("span",{className:"w-inline w-gap-2",children:[t.jsx("span",{children:k(S.country_code)}),t.jsx("span",{className:"w-text-secondary",children:S.country_code}),t.jsx("span",{children:S.phone_number})]})}),t.jsx(Ke,{children:E(S)}),t.jsx(Ht,{children:R(S)})]},S.id))})]})})}):t.jsx(Ct,{title:"No phone numbers",description:"Add a phone number to get started."})]})},p6=e=>t.jsxs("svg",{width:"800px",height:"800px",viewBox:"0 0 16 16",xmlns:"http://www.w3.org/2000/svg",fill:"none",...e,children:[t.jsx("path",{fill:"#F35325",d:"M1 1h6.5v6.5H1V1z"}),t.jsx("path",{fill:"#81BC06",d:"M8.5 1H15v6.5H8.5V1z"}),t.jsx("path",{fill:"#05A6F0",d:"M1 8.5h6.5V15H1V8.5z"}),t.jsx("path",{fill:"#FFBA08",d:"M8.5 8.5H15V15H8.5V8.5z"})]}),h6={google_oauth:{icon:t.jsx(bc,{}),label:"Google"},microsoft_oauth:{icon:t.jsx(p6,{}),label:"Microsoft"},github_oauth:{icon:t.jsx(vc,{}),label:"GitHub"},gitlab_oauth:{icon:t.jsx(_c,{}),label:"GitLab"},linkedin_oauth:{icon:t.jsx(jc,{}),label:"LinkedIn"},discord_oauth:{icon:t.jsx(kc,{}),label:"Discord"},x_oauth:{icon:t.jsx(yc,{}),label:"X"}},f6=()=>{const{user:e,disconnectSocialConnection:a,connectSocialAccount:s}=ga(),{deployment:n}=_e(),i=(n==null?void 0:n.social_connections.filter(c=>c.enabled))||[],l=c=>{s({provider:c,redirectUri:window.location.href})},m=async c=>{await a(c.toString()),e.refetch()};return i.length===0?t.jsx(Ct,{title:"No providers available",description:"Social sign-in providers have not been configured for this app."}):t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"w-flex w-items-center w-gap-3",children:t.jsxs("div",{className:"w-grow w-flex-col w-gap-1",children:[t.jsx("div",{className:"w-sec",children:"Connected accounts"}),t.jsx("div",{className:"w-secsub",children:"Sign in faster by linking third-party accounts."})]})}),t.jsx("div",{className:"w-list",children:i.map(c=>{var h;const d=h6[c.provider];if(!d)return null;const p=((h=e==null?void 0:e.social_connections)==null?void 0:h.filter(f=>f.provider===c.provider))||[],u=p.length>0;return t.jsxs("div",{className:"w-vrow",children:[t.jsxs("div",{className:"w-flex w-items-center w-gap-3 w-grow",children:[t.jsx(Ir,{children:d.icon}),t.jsxs("div",{className:"w-flex-col w-gap-1 w-grow",children:[t.jsx("div",{className:"w-sec",children:d.label}),u?t.jsx("div",{className:"w-flex w-wrap w-gap-1",children:p.map(f=>t.jsxs("span",{className:"w-chip",children:[t.jsx("span",{className:"w-truncate",children:f.email_address}),t.jsx("span",{className:"w-chip-x",role:"button",onClick:()=>m(f.id),title:"Remove connection","aria-label":"Remove connection",children:t.jsx(Ra,{size:10,weight:"bold"})})]},f.id))}):t.jsx("span",{className:"w-secsub",children:"Not linked"})]})]}),t.jsx("div",{className:`w-flex w-justify-end w-none${u?" w-row-act-top":""}`,children:t.jsx(se,{$size:"sm",$outline:!0,onClick:()=>l(c.provider),children:u?"Link another":"Link"})})]},c.provider)})})]})};var w6=Object.defineProperty,Js=Object.getOwnPropertySymbols,x0=Object.prototype.hasOwnProperty,v0=Object.prototype.propertyIsEnumerable,Wi=(e,a,s)=>a in e?w6(e,a,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[a]=s,mr=(e,a)=>{for(var s in a||(a={}))x0.call(a,s)&&Wi(e,s,a[s]);if(Js)for(var s of Js(a))v0.call(a,s)&&Wi(e,s,a[s]);return e},pr=(e,a)=>{var s={};for(var n in e)x0.call(e,n)&&a.indexOf(n)<0&&(s[n]=e[n]);if(e!=null&&Js)for(var n of Js(e))a.indexOf(n)<0&&v0.call(e,n)&&(s[n]=e[n]);return s};/**
109
109
  * @license QR Code generator library (TypeScript)
110
110
  * Copyright (c) Project Nayuki.
111
111
  * SPDX-License-Identifier: MIT