1import{hD as Wn,hE as st,r as i,hF as re,j as s,hG as $n,hH as sn,X as wt,hI as xt,hJ as Bn,t as K,H as an,a as Ie,bX as on,b_ as rn,Q as se,T as O,u as ie,hK as cn,bZ as ln,f as Kn,dE as Me,aC as ne,hL as dn,B as fe,aO as Tt,at as Fe,i as q,dr as Z,bt as St,bc as Je,a0 as we,eA as Nt,hM as un,p as We,bR as zn,Z as Hn,_ as fn,aT as Vn,M as Rt,bq as qn,e3 as ae,c0 as hn,hN as ve,gE as R,d as Ue,aA as Gn,aB as Jn,aJ as Yn,gY as Qn,aH as Xn,eH as Zn,hO as Ye,eq as es,hP as ts,br as ns,hQ as ss,c2 as mn}from"./index-BFAzTc87.js";import{K as At,C as pn,S as as,a as Qe,b as Xe,c as Cn,d as os,e as rs,f as Ot,T as is}from"./constants-CdypHeE3.js";import{L as cs}from"./ListItem-fiSirjrn.js";import{a as gn}from"./NotificationsAlert-Dbie7KCY.js";import{u as ls}from"./searchParams-CH3xKqBs.js";import{C as xn}from"./Checkbox-D2nrjcz_.js";import"./SwitchBase-CDKKcANQ.js";function Sn(e){return Wn(e.authStore,t=>t)}function ds(e,t,n){let{t:a}=st(),{userId:r}=Sn(e),[o,c]=i.useState("connecting"),[d,l]=i.useState(null),[g,u]=i.useState(null),S=i.useRef(r);return i.useEffect(()=>{S.current!==r&&(S.current=r,c("connecting"),l(null),u(null))},[r]),i.useEffect(()=>{let p=!1;return(async()=>{if(o==="connecting")try{let f=await e.msTeams.authCheck({tenant:n,knockChannelId:t});if(p)return;if(f.connection?.ok===!0)return c("connected");if(f.connection?.ok===!1)return c("disconnected");let C=f.response?.status;if(typeof C=="number"&&C>=400&&C<500&&f.response?.data?.message===a("msTeamsTenantIdNotSet"))return c("disconnected");c("error")}catch{if(p)return;c("error")}})(),()=>{p=!0}},[o,n,t,e.msTeams,a,r]),{connectionStatus:o,setConnectionStatus:c,errorLabel:d,setErrorLabel:l,actionLabel:g,setActionLabel:u}}var En=i.createContext(null),us=({knockMsTeamsChannelId:e,tenantId:t,children:n})=>{let a=re(),r=i.useRef(null),{connectionStatus:o,setConnectionStatus:c,errorLabel:d,setErrorLabel:l,actionLabel:g,setActionLabel:u}=ds(a,e,t);return s.jsx(En.Provider,{value:{connectionStatus:o,setConnectionStatus:c,errorLabel:d,setErrorLabel:l,actionLabel:g,setActionLabel:u,knockMsTeamsChannelId:e,tenantId:t,popupWindowRef:r},children:n},$n({userId:a.userId,knockMsTeamsChannelId:e,tenantId:t,connectionStatus:o,errorLabel:d}))},$e=()=>{let e=i.useContext(En);if(!e)throw Error("useKnockMsTeamsClient must be used within a KnockMsTeamsProvider");return e},fs="https://login.microsoftonline.com/organizations/adminconsent",hs="/providers/ms-teams/authenticate";function ms(e,t){let n=re(),{setConnectionStatus:a,knockMsTeamsChannelId:r,tenantId:o,setActionLabel:c}=$e(),d=i.useMemo(()=>n.host+hs,[n.host]);return{buildMsTeamsAuthUrl:i.useCallback(()=>{let l={state:JSON.stringify({redirect_url:t,ms_teams_tenant_object:{object_id:o,collection:sn},channel_id:r,public_key:n.apiKey,user_token:n.userToken,branch_slug:n.branch}),client_id:e,redirect_uri:d};return`${fs}?${new URLSearchParams(l)}`},[t,o,r,n.apiKey,n.userToken,n.branch,e,d]),disconnectFromMsTeams:i.useCallback(async()=>{c(null),a("disconnecting");try{let l=await n.msTeams.revokeAccessToken({tenant:o,knockChannelId:r});a(l==="ok"?"disconnected":"error")}catch{a("error")}},[a,n.msTeams,o,r,c])}}var Kt=Object.prototype.hasOwnProperty;function Et(e,t){var n,a;if(e===t)return!0;if(e&&t&&(n=e.constructor)===t.constructor){if(n===Date)return e.getTime()===t.getTime();if(n===RegExp)return e.toString()===t.toString();if(n===Array){if((a=e.length)===t.length)for(;a--&&Et(e[a],t[a]););return a===-1}if(!n||typeof e=="object"){a=0;for(n in e)if(Kt.call(e,n)&&++a&&!Kt.call(t,n)||!(n in t)||!Et(e[n],t[n]))return!1;return Object.keys(t).length===a}}return e!==e&&t!==t}const _n=0,yn=1,kn=2,zt=3,bn=4,le=new WeakMap,Se=()=>{},$=Se(),_t=Object,w=e=>e===$,ue=e=>typeof e=="function",Ee=(e,t)=>({...e,...t}),yt=e=>ue(e.then),dt={},ze={},Lt="undefined",Be=typeof window!=Lt,kt=typeof document!=Lt,ps=Be&&"Deno"in window,Cs=()=>Be&&typeof window.requestAnimationFrame!=Lt,be=(e,t)=>{const n=le.get(e);return[()=>!w(t)&&e.get(t)||dt,a=>{if(!w(t)){const r=e.get(t);t in ze||(ze[t]=r),n[5](t,Ee(r,a),r||dt)}},n[6],()=>!w(t)&&t in ze?ze[t]:!w(t)&&e.get(t)||dt]};let bt=!0;const gs=()=>bt,[vt,It]=Be&&window.addEventListener?[window.addEventListener.bind(window),window.removeEventListener.bind(window)]:[Se,Se],xs=()=>{const e=kt&&document.visibilityState;return w(e)||e!=="hidden"},Ss=e=>(kt&&document.addEventListener("visibilitychange",e),vt("focus",e),()=>{kt&&document.removeEventListener("visibilitychange",e),It("focus",e)}),Es=e=>{const t=()=>{bt=!0,e()},n=()=>{bt=!1};
1return vt("online",t),vt("offline",n),()=>{It("online",t),It("offline",n)}},_s={isOnline:gs,isVisible:xs},ys={initFocus:Ss,initReconnect:Es},Ht=!wt.useId,je=!Be||ps,ks=e=>Cs()?window.requestAnimationFrame(e):setTimeout(e,1),Ae=je?i.useEffect:i.useLayoutEffect,ut=typeof navigator<"u"&&navigator.connection,Vt=!je&&ut&&(["slow-2g","2g"].includes(ut.effectiveType)||ut.saveData),He=new WeakMap,bs=e=>_t.prototype.toString.call(e),ft=(e,t)=>e===`[object ${t}]`;let vs=0;const jt=e=>{const t=typeof e,n=bs(e),a=ft(n,"Date"),r=ft(n,"RegExp"),o=ft(n,"Object");let c,d;if(_t(e)===e&&!a&&!r){if(c=He.get(e),c)return c;if(c=++vs+"~",He.set(e,c),Array.isArray(e)){for(c="@",d=0;d<e.length;d++)c+=jt(e[d])+",";He.set(e,c)}if(o){c="#";const l=_t.keys(e).sort();for(;!w(d=l.pop());)w(e[d])||(c+=d+":"+jt(e[d])+",");He.set(e,c)}}else c=a?e.toJSON():t=="symbol"?e.toString():t=="string"?JSON.stringify(e):""+e;return c},Le=e=>{if(ue(e))try{e=e()}catch{e=""}const t=e;return e=typeof e=="string"?e:(Array.isArray(e)?e.length:e)?jt(e):"",[e,t]};let Is=0;const Ze=()=>++Is;async function vn(...e){const[t,n,a,r]=e,o=Ee({populateCache:!0,throwOnError:!0},typeof r=="boolean"?{revalidate:r}:r||{});let c=o.populateCache;const d=o.rollbackOnError;let l=o.optimisticData;const g=p=>typeof d=="function"?d(p):d!==!1,u=o.throwOnError;if(ue(n)){const p=n,f=[],C=t.keys();for(const m of C)!/^\$(inf|sub)\$/.test(m)&&p(t.get(m)._k)&&f.push(m);return Promise.all(f.map(S))}return S(n);async function S(p){const[f]=Le(p);if(!f)return;const[C,m]=be(t,f),[I,N,h,T]=le.get(t),A=()=>{const U=I[f];return(ue(o.revalidate)?o.revalidate(C().data,p):o.revalidate!==!1)&&(delete h[f],delete T[f],U&&U[0])?U[0](kn).then(()=>C().data):C().data};if(e.length<3)return A();let E=a,b,L=!1;const _=Ze();N[f]=[_,0];const y=!w(l),j=C(),v=j.data,F=j._c,z=w(F)?v:F;if(y&&(l=ue(l)?l(z,v):l,m({data:l,_c:z})),ue(E))try{E=E(z)}catch(U){b=U,L=!0}if(E&&yt(E))if(E=await E.catch(U=>{b=U,L=!0}),_!==N[f][0]){if(L)throw b;return E}else L&&y&&g(b)&&(c=!0,m({data:z,_c:$}));if(c&&!L)if(ue(c)){const U=c(E,z);m({data:U,error:$,_c:$})}else m({data:E,error:$,_c:$});if(N[f][1]=Ze(),Promise.resolve(A()).then(()=>{m({_c:$})}),L){if(u)throw b;return}return E}}const qt=(e,t)=>{for(const n in e)e[n][0]&&e[n][0](t)},js=(e,t)=>{if(!le.has(e)){const a=Ee(ys,t),r=Object.create(null),o=vn.bind($,e);let c=Se;const d=Object.create(null),l=(p,f)=>{const C=d[p]||[];return d[p]=C,C.push(f),()=>{const m=C.indexOf(f);m>=0&&(C[m]=C[C.length-1],C.pop())}},g=(p,f,C)=>{e.set(p,f);const m=d[p];if(m)for(const I of m)I(f,C)},u=p=>{const f=le.get(e),[,C,m,I]=f,N=Ze();f[8]++;for(const A in m)delete m[A];for(const A in I)delete I[A];for(const A in C)C[A]=[N,N];const h={};for(const A of[...e.keys()]){const E=e.get(A);e.delete(A);const b=d[A];if(b)for(const L of b)L(h,E)}const T=!p||p.revalidate!==!1;for(const A in r){const E=r[A];for(let b=0;b<E.length;b++)E[b](bn,{revalidate:T&&!b})}},S=()=>{if(!le.has(e)&&(le.set(e,[r,Object.create(null),Object.create(null),Object.create(null),o,g,l,u,0]),!je)){const p=a.initFocus(setTimeout.bind($,qt.bind($,r,_n))),f=a.initReconnect(setTimeout.bind($,qt.bind($,r,yn)));c=()=>{p&&p(),f&&f(),le.delete(e)}}};return S(),[e,o,S,c,u]}const n=le.get(e);return[e,n[4],$,$,n[7]]},ws=(e,t,n,a,r)=>{const o=n.errorRetryCount,c=r.retryCount,d=~~((Math.random()+.5)*(1<<(c<8?c:8)))*n.errorRetryInterval;!w(o)&&c>o||setTimeout(a,d,r)},Ts=Et,[Dt,Ns,,,Rs]=js(new Map),As=Ee({onLoadingSlow:Se,onSuccess:Se,onError:Se,onErrorRetry:ws,onDiscarded:Se,revalidateOnFocus:!0,revalidateOnReconnect:!0,revalidateIfStale:!0,shouldRetryOnError:!0,errorRetryInterval:Vt?1e4:5e3,focusThrottleInterval:5*1e3,dedupingInterval:2*1e3,loadingTimeout:Vt?5e3:3e3,compare:Ts,isPaused:()=>!1,cache:Dt,mutate:Ns,unload:Rs,fallback:{}},_s),Os=(e,t)=>{const n=Ee(e,t);if(t){const{use:a,fallback:r,cacheData:o}=e,{use:c,fallback:d,cacheData:l}=t;a&&c&&(n.use=a.concat(c)),r&&d&&(n.fallback=Ee(r,d)),o&&l&&(n.cacheData=Ee(o,l))}return n},Ls=i.createContext({}),In="$inf$",jn=Be&&window.__SWR_DEVTOOLS_USE__,Ds=jn?window.__SWR_DEVTOOLS_USE__:[],Ps=()=>{jn&&(window.__SWR_DEVTOOLS_REACT__=wt)},wn=e=>ue(e[1])?[e[0],e[1],e[2]||{}]:[e[0],null,(e[1]===null?e[2]:e[1])||{}],Ms=()=>{const e=i.useContext(Ls);return i.useMemo(()=>Ee(As,e),[e])},Fs=e=>(t,n,a)=>e(t,n&&((...o)=>{const[c]=Le(t),[,,,d]=le.get(Dt);if(c.startsWith(In))return n(...o);const l=d[c];return w(l)?n(...o):(delete d[c],l)}),a),Us=Ds.concat(Fs),Ws=e=>function(...n){const a=Ms(),[r,o,c]=wn(n),d=Os(a,c);let l=e;const{use:g}=d,u=(g||[]).concat(Us);for(let S=u.length;S--;)l=u[S](l);return l(r,o||d.fetcher||null,d)},$s=(e,t,n)=>{const a=t[e]||(t[e]=[]);return a.push(n),()=>{const r=a.indexOf(n);r>=0&&(a[r]=a[a.length-1],a.pop())}},Bs=(e,t)=>(...n)=>{const[a,r,o]=wn(n),c=(o.use||[]).concat(t);return e(a,r,{...o,use:c})};Ps();const Ve=wt.use||(e=>
1{switch(e.status){case"pending":throw e;case"fulfilled":return e.value;case"rejected":throw e.reason;default:throw e.status="pending",e.then(t=>{e.status="fulfilled",e.value=t},t=>{e.status="rejected",e.reason=t}),e}}),ht={dedupe:!0},Gt=(e,t,n)=>{var a;return t?((a=e.get(t))==null?void 0:a.has(n))===!0:!1},mt=(e,t,n)=>{if(!t)return;let a=e.get(t);a||(a=new Set,e.set(t,a)),a.add(n)},Ks=({value:e,getCacheData:t,canCommit:n,setCache:a})=>{const r=o=>{n()&&w(t())&&a(o)};Promise.resolve(e).then(o=>{r({data:o,error:$})},o=>{r({error:o})})},et=Promise.resolve($);et.status="fulfilled";et.value=$;const zs=()=>Se,Hs=(e,t,n)=>{const{cache:a,compare:r,suspense:o,fallbackData:c,revalidateOnMount:d,revalidateIfStale:l,refreshInterval:g,refreshWhenHidden:u,refreshWhenOffline:S,keepPreviousData:p,strictServerPrefetchWarning:f}=n,[C,m,I,N]=le.get(a),[h,T]=Le(e),A=i.useRef(!1),E=i.useRef(!1),b=i.useRef(h),L=i.useRef(t),_=i.useRef(n),y=()=>_.current,j=()=>y().isVisible()&&y().isOnline(),[v,F,z,U]=be(a,h),H=i.useRef({}).current,W=w(c)?w(n.fallback)?$:n.fallback[h]:c,V=n.cacheData,me=h?V?.[h]:$,he=h?N[h]:$,Y=w(he)&&!w(me),J=Y?me:he,x=(P,B)=>{for(const Q in H){const G=Q;if(G==="data"){if(!r(P[G],B[G])&&(!w(P[G])||!r(De,B[G])))return!1}else if(B[G]!==P[G])return!1}return!0},k=!A.current,M=i.useMemo(()=>{const P=v(),B=U(),Q=ee=>{const Ce=Ee(ee);return delete Ce._k,(()=>{if(!h||!t||y().isPaused())return!1;if(k&&!w(d))return d;const ke=w(W)?Ce.data:W;return o&&Y&&w(ke)?!1:w(ke)||l})()?{isValidating:!0,isLoading:!0,...Ce}:Ce},G=Q(P),de=P===B?G:Q(B);let oe=G;return[()=>{const ee=Q(v());return x(ee,oe)?(oe.data=ee.data,oe.isLoading=ee.isLoading,oe.isValidating=ee.isValidating,oe.error=ee.error,oe):(oe=ee,ee)},()=>de]},[a,h]),D=xt.useSyncExternalStore(i.useCallback(P=>z(h,(B,Q)=>{x(Q,B)||P()}),[a,h]),M[0],M[1]),te=C[h]&&C[h].length>0,X=D.data;let pe=w(X)?W&&yt(W)?Ve(W):W:X;const Te=D.error,Ke=i.useRef(pe),Pt=i.useRef($);let _e=Pt.current;_e||(_e=new WeakMap,Pt.current=_e);const it=i.useRef(null);let De=p?w(X)?w(Ke.current)?pe:Ke.current:X:pe;const ye=h&&w(pe),Pe=i.useRef(null);!je&&xt.useSyncExternalStore(zs,()=>(Pe.current=!1,Pe),()=>(Pe.current=!0,Pe));const Pn=Pe.current;f&&Pn&&!o&&ye&&console.warn(`Missing pre-initiated data for serialized key "${h}" during server-side rendering. Data fetching should be initiated on the server and provided to SWR via fallback data. You can set "strictServerPrefetchWarning: false" to disable this warning.`);const Mt=!h||!t||y().isPaused()||te&&!w(Te)?!1:k&&!w(d)?d:o&&Y&&ye?!1:o?w(pe)?!1:l:w(pe)||l,Ft=k&&Mt,Mn=w(D.isValidating)?Ft:D.isValidating,Fn=w(D.isLoading)?Ft:D.isLoading,Ne=i.useCallback(async P=>{const B=L.current;if(!h||!B||E.current||y().isPaused())return!1;let Q,G,de=!0;const oe=P||{},ee=!I[h]||!oe.dedupe,Ce=Y&&!Gt(_e,V,h)&&!w(J)&&w(v().data),Re=()=>Ht?!E.current&&h===b.current&&A.current:h===b.current,ke={isValidating:!1,isLoading:!1},Wt=()=>{F(ke)},$t=()=>{const ce=I[h];ce&&ce[1]===G&&delete I[h]},Bt={isValidating:!0};w(v().data)&&(Bt.isLoading=!0);try{if(ee&&(F(Bt),n.loadingTimeout&&w(v().data)&&setTimeout(()=>{de&&Re()&&y().onLoadingSlow(h,n)},n.loadingTimeout),Ce&&mt(_e,V,h),I[h]=[Ce?J:B(T),Ze()],Ce&&N[h]&&delete N[h]),[Q,G]=I[h],Q=await Q,ee&&setTimeout($t,n.dedupingInterval),!I[h]||I[h][1]!==G)return ee&&Re()&&y().onDiscarded(h),!1;ke.error=$;const ce=m[h];if(!w(ce)&&(G<=ce[0]||G<=ce[1]||ce[1]===0))return Wt(),ee&&Re()&&y().onDiscarded(h),!1;const ge=v().data;ke.data=r(ge,Q)?ge:Q,ee&&Re()&&y().onSuccess(Q,h,n)}catch(ce){$t();const ge=y(),{shouldRetryOnError:ct}=ge;ge.isPaused()||(ke.error=ce,ee&&Re()&&(ge.onError(ce,h,ge),(ct===!0||ue(ct)&&ct(ce))&&(!y().revalidateOnFocus||!y().revalidateOnReconnect||j())&&ge.onErrorRetry(ce,h,ge,Un=>{const lt=C[h];lt&<[0]&<[0](zt,Un)},{retryCount:(oe.retryCount||0)+1,dedupe:!0})))}return de=!1,Wt(),!0},[h,a]),Ut=i.useCallback((...P)=>vn(a,b.current,...P),[]);if(Ae(()=>{const P=it.current;P&&(it.current=null,mt(_e,P.cacheData,P.key),w(v().data)&&F({data:P.data,error:$,_k:P._k}),N[P.key]&&delete N[P.key])}),Ae(()=>{L.current=t,_.current=n,w(X)||(Ke.current=X)}),Ae(()=>{if(t||!Y||w(J)||Gt(_e,V,h)||!w(v().data))return;mt(_e,V,h);const P=m[h];Ks({value:J,getCacheData:()=>v().data,canCommit:()=>
1!E.current&&h===b.current&&m[h]===P,setCache:B=>F({...B,_k:T})})}),Ae(()=>{if(!h)return;const P=Ne.bind($,ht);let B=0;y().revalidateOnFocus&&(B=Date.now()+y().focusThrottleInterval);const G=$s(h,C,(de,oe={})=>{if(de==_n){const ee=Date.now();y().revalidateOnFocus&&ee>B&&j()&&(B=ee+y().focusThrottleInterval,P())}else if(de==yn)y().revalidateOnReconnect&&j()&&P();else{if(de==kn)return Ne();if(de==zt)return Ne(oe);if(de==bn&&(Ke.current=$,oe.revalidate))return Ne()}});return E.current=!1,b.current=h,A.current=!0,F({_k:T}),Mt&&(I[h]||(w(pe)||je?P():ks(P))),()=>{E.current=!0,G()}},[h]),Ae(()=>{let P;function B(){const G=ue(g)?g(v().data):g;G&&P!==-1&&(P=setTimeout(Q,G))}function Q(){!v().error&&(u||y().isVisible())&&(S||y().isOnline())?Ne(ht).then(B):B()}return B(),()=>{P&&(clearTimeout(P),P=-1)}},[g,u,S,h]),i.useDebugValue(De),o){if(!Ht&&je&&ye&&w(J))throw new Error("Fallback data is required when using Suspense in SSR.");ye&&(L.current=t,_.current=n,E.current=!1);const P=!w(J)&&ye;let B=$;if(P&&Y)B=J&&yt(J)?Ve(J):J,pe=B,De=B,je||(it.current={data:B,_k:T,key:h,cacheData:V});else{const G=P?Ut(J):et;Ve(G)}if(!w(Te)&&ye)throw Te;const Q=ye&&w(B)?Ne(ht):et;!w(De)&&ye&&(Q.status="fulfilled",Q.value=!0),Ve(Q)}return{mutate:Ut,get data(){return H.data=!0,De},get error(){return H.error=!0,Te},get isValidating(){return H.isValidating=!0,Mn},get isLoading(){return H.isLoading=!0,Fn}}},at=Ws(Hs),Vs=e=>Le(e?e(0,null):null)[0],pt=Promise.resolve(),qs=e=>(t,n,a)=>{const r=i.useRef(!1),{cache:o,initialSize:c=1,revalidateAll:d=!1,persistSize:l=!1,revalidateFirstPage:g=!0,revalidateOnMount:u=!1,parallel:S=!1}=a,[,,,p]=le.get(Dt);let f;try{f=Vs(t),f&&(f=In+f)}catch{}const[C,m,I]=be(o,f),N=i.useCallback(()=>w(C()._l)?c:C()._l,[o,f,c]);xt.useSyncExternalStore(i.useCallback(_=>f?I(f,()=>{_()}):()=>{},[o,f]),N,N);const h=i.useCallback(()=>{const _=C()._l;return w(_)?c:_},[f,c]),T=i.useRef(h());Ae(()=>{if(!r.current){r.current=!0;return}f&&m({_l:l?T.current:h()})},[f,o]);const A=u&&!r.current,E=e(f,async _=>{const y=C()._i,j=C()._r,v=le.get(o),F=v[8],z=()=>v[8]!==F;m({_r:$});const U=[],H=h(),[W]=be(o,_),V=W().data,me=[];let he=null;for(let Y=0;Y<H;++Y){const[J,x]=Le(t(Y,S?null:he));if(!J)break;const[k,M]=be(o,J);let D=k().data;const te=d||y||w(D)||g&&!Y&&!w(V)||A||V&&!w(V[Y])&&!a.compare(V[Y],D);if(n&&(typeof j=="function"?j(D,x):te)){const X=async()=>{if(!(J in p))D=await n(x);else{const Te=p[J];delete p[J],D=await Te}z()||M({data:D,_k:x}),U[Y]=D};S?me.push(X):await X()}else U[Y]=D;S||(he=D)}return S&&await Promise.all(me.map(Y=>Y())),z()||m({_i:$}),U},a),b=i.useCallback(function(_,y){const j=typeof y=="boolean"?{revalidate:y}:y||{},v=j.revalidate!==!1;return f?(v&&(w(_)?m({_i:!0,_r:j.revalidate}):m({_i:!1,_r:j.revalidate})),arguments.length?E.mutate(_,{...j,revalidate:v}):E.mutate()):pt},[f,o]),L=i.useCallback(_=>{if(!f)return pt;const[,y]=be(o,f);let j;if(ue(_)?j=_(h()):typeof _=="number"&&(j=_),typeof j!="number")return pt;y({_l:j}),T.current=j;const v=[],[F]=be(o,f);let z=null;for(let U=0;U<j;++U){const[H]=Le(t(U,z)),[W]=be(o,H),V=H?W().data:$;if(w(V))return b(F().data);v.push(V),z=V}return b(v)},[f,o,b,h]);return{size:h(),setSize:L,mutate:b,get data(){return E.data},get error(){return E.error},get isValidating(){return E.isValidating},get isLoading(){return E.isLoading}}},Tn=Bs(at,qs);var Gs=1e3,Jt="MS_TEAMS_TEAMS";function Js({queryOptions:e={}}){let t=re(),{knockMsTeamsChannelId:n,tenantId:a,connectionStatus:r}=$e(),o=i.useRef(a),c=i.useRef(n),d=i.useRef(r),{data:l,error:g,isLoading:u,isValidating:S,setSize:p,mutate:f}=Tn(i.useCallback((h,T)=>r==="connected"?h===0?[Jt,a,n,""]:T&&["",null].includes(T.skip_token)?null:[Jt,a,n,T?.skip_token??""]:null,[a,n,r]),i.useCallback(h=>t.msTeams.getTeams({knockChannelId:n,tenant:a,queryOptions:{$skiptoken:h?.[3],$top:e?.limitPerPage,$filter:e?.filter,$select:e?.select}}),[t.msTeams,n,a,e]),{initialSize:0,revalidateOnFocus:!1,revalidateFirstPage:!1});i.useEffect(()=>{let h=o.current!==a,T=c.current!==n,A=d.current!=="connected"&&r==="connected";(h||T||A)&&(f(void 0,{revalidate:!1}),p(0)),o.current=a,c.current=n,d.current=r},[a,n,r,f,p]);let C=l?.at(-1),m=C===void 0||!!C.skip_token,I=i.useMemo(()=>(l??[]).flatMap(h=>h?.ms_teams_teams).filter(h=>!!h),[l]),N=e?.maxCount||Gs;return i.useEffect(()=>{r==="connected"&&!g&&m&&!u&&!S&&I.length<N&&p(h=>h+1)},[I.length,p,m,u,S,N,g,r]),{data:I,isLoading:u||S,refetch:()=>f()}}var Ys="MS_TEAMS_CHANNELS";function Qs({teamId:e,queryOptions:t}){let n=re(),{knockMsTeamsChannelId:a,tenantId:r,connectionStatus:o}=$e(),c=i.useRef(r),d=i.useRef(a),l=i.useRef(o),g=i.useCallback(()=>n.msTeams.getChannels({knockChannelId:a,tenant:r,teamId:e,queryOptions:{$filter:t?.filter,$select:t?.select}}),[n.msTeams,a,r,e,t]),{data:u,isLoading:S,isValidating:p,mutate:f}=at(e&&o==="connected"?[Ys,r,a,e]:null,g,{revalidateOnFocus:!1});return i.useEffect(()=>{let C=c.current!==r,m=d.current!==a,I=l.current!=="connected"&&o==="connected";(C||m||I)&&f(void 0,{revalidate:!1}),c.current=r,d.current=a,l.current=o},[r,a,o,f]),{data:u?.ms_teams_channels??[],isLoading:S||p,refetch:()=>f()}}var Xs="MS_TEAMS_CONNECTED_CHANNELS";function Zs({msTeamsChannelsRecipientObject:{objectId:e,collection:t}}){let{t:n}=st(),a=re(),{connectionStatus:r,knockMsTeamsChannelId:o}=$e(),[c,d]=i.useState(null),[l,g]=i.useState(!1),{data:u,mutate:S,isValidating:p,isLoading:f}=at(r==="connected"?[Xs,o,t,e]:null,async()=>a.objects.getChannelData({collection:t,objectId:e,channelId:o}).then(C=>C.data?.connections??[]).catch(()=>[]),{onSuccess:()=>{d(null)}});return{data:u??null,updateConnectedChannels:async C=>{g(!0);try{await S(()=>a.objects.setChannelData({objectId:e,collection:t,channelId:o,data:{connections:C}}).then(m=>m.data?.connections??[]),{populateCache:!0,revalidate:!1,optimisticData:C})}catch{d(n("msTeamsChannelSetError")||"")}g(!1)},updating:l,loading:f||p,error:c}}var ea=e=>{let t=e.substring(0,1).toUpperCase(),n=e.substring(1);return t?.concat(n).replace("_"," ")};function ta(e,t,n){let{t:a}=st(),{userId:r}=Sn(e),[o,c]=i.useState("connecting"),[d,l]=i.useState(null),[g,u]=i.useState(null),S=i.useRef(r);return i.useEffect(()=>{S.current!==r&&(S.current=r,c("connecting"),l(null),u(null))},[r]),i.useEffect(()=>{let p=!1;return(async()=>
1{if(o==="connecting")try{let f=await e.slack.authCheck({tenant:n,knockChannelId:t});if(p)return;if(f.connection?.ok)return c("connected");let C=f.response?.status;if(typeof C=="number"&&C>=400&&C<500&&f.response?.data?.message===a("slackAccessTokenNotSet"))return c("disconnected");if(f.connection&&f.connection.error){let m=ea(f.connection.error);l(m),c("error");return}if(f.connection)return c("disconnected");c("error")}catch{if(p)return;c("error")}})(),()=>{p=!0}},[o,n,t,e.slack,a,r]),{connectionStatus:o,setConnectionStatus:c,errorLabel:d,setErrorLabel:l,actionLabel:g,setActionLabel:u}}var Nn=i.createContext(null),na=e=>{let{knockSlackChannelId:t,children:n}=e,a="tenantId"in e?e.tenantId:e.tenant,r=re(),o=i.useRef(null),{connectionStatus:c,setConnectionStatus:d,errorLabel:l,setErrorLabel:g,actionLabel:u,setActionLabel:S}=ta(r,t,a);return s.jsx(Nn.Provider,{value:{connectionStatus:c,setConnectionStatus:d,errorLabel:l,setErrorLabel:g,actionLabel:u,setActionLabel:S,knockSlackChannelId:t,tenant:a,tenantId:a,popupWindowRef:o},children:n},Bn({userId:r.userId,knockSlackChannelId:t,tenantId:a,connectionStatus:c,errorLabel:l}))},ot=()=>{let e=i.useContext(Nn);if(e===void 0)throw Error("useKnockSlackClient must be used within a KnockSlackProvider");return e},sa=1e3,aa=200,oa="private_channel,public_channel",Yt="SLACK_CHANNELS";function ra({queryOptions:e}){let t=re(),{knockSlackChannelId:n,tenantId:a,connectionStatus:r}=ot(),o=i.useRef(a),c=i.useRef(n),d=i.useRef(r),{data:l,error:g,isLoading:u,isValidating:S,setSize:p,mutate:f}=Tn(i.useCallback((h,T)=>r==="connected"?h===0?[Yt,a,n,""]:T&&["",null].includes(T.next_cursor)?null:[Yt,a,n,T?.next_cursor??""]:null,[a,n,r]),i.useCallback(h=>t.slack.getChannels({tenant:a,knockChannelId:n,queryOptions:{...e,cursor:h?.[3],limit:e?.limitPerPage||aa,types:e?.types||oa}}),[t.slack,a,n,e]),{initialSize:0,revalidateFirstPage:!1});i.useEffect(()=>{let h=o.current!==a,T=c.current!==n,A=d.current!=="connected"&&r==="connected";(h||T||A)&&(f(void 0,{revalidate:!1}),p(0)),o.current=a,c.current=n,d.current=r},[a,n,r,f,p]);let C=l?.at(-1),m=C===void 0||!!C.next_cursor,I=i.useMemo(()=>(l??[]).flatMap(h=>h?.slack_channels).filter(h=>!!h),[l]),N=e?.maxCount||sa;return i.useEffect(()=>{r==="connected"&&!g&&m&&!u&&!S&&I.length<N&&p(h=>h+1)},[I.length,p,m,u,S,N,g,r]),{data:I,isLoading:u||S,refetch:()=>f()}}var ia="SLACK_CONNECTED_CHANNELS";function ca({slackChannelsRecipientObject:{objectId:e,collection:t}}){let{t:n}=st(),a=re(),{connectionStatus:r,knockSlackChannelId:o}=ot(),[c,d]=i.useState(null),[l,g]=i.useState(!1),{data:u,mutate:S,isValidating:p,isLoading:f}=at(r==="connected"?[ia,o,t,e]:null,async()=>a.objects.getChannelData({collection:t,objectId:e,channelId:o}).then(C=>C.data?.connections??[]).catch(()=>[]),{onSuccess:()=>{d(null)}});return{data:u??null,updateConnectedChannels:async C=>{g(!0);try{await S(()=>a.objects.setChannelData({objectId:e,collection:t,channelId:o,data:{connections:C}}).then(m=>m.data?.connections??[]),{populateCache:!0,revalidate:!1,optimisticData:C})}catch{d(n("slackChannelSetError")||"")}g(!1)},updating:l,loading:f||p,error:c}}var la="https://slack.com/oauth/v2/authorize",Ct=["chat:write","chat:write.public","channels:read","groups:read"];function da(e,t){return`knock:slack-auth-nonce:${e}:${t}`}function ua(e){return e?Array.isArray(e)?{scopes:Ct,additionalScopes:e}:{scopes:e.scopes??Ct,additionalScopes:e.additionalScopes??[]}:{scopes:Ct,additionalScopes:[]}}function fa(e,t,n){let a=re(),{setConnectionStatus:r,knockSlackChannelId:o,tenantId:c,setActionLabel:d}=ot(),{scopes:l,additionalScopes:g}=ua(n),u=Array.from(new Set(l.concat(g))),S=i.useCallback(async()=>{d(null),r("disconnecting");try{await a.slack.revokeAccessToken({tenant:c,knockChannelId:o})==="ok"?r("disconnected"):r("error")}catch{r("error")}},[r,a.slack,c,o,d]);return{buildSlackAuthUrl:i.useCallback(()=>{let p=crypto.randomUUID();sessionStorage.setItem(da(o,a.userId),p);let f={state:JSON.stringify({nonce:p,redirect_url:t,access_token_object:{object_id:c,collection:sn},channel_id:o,public_key:a.apiKey,user_token:a.userToken,branch_slug:a.branch}),client_id:e,scope:u.join(",")};return`${la}?${new URLSearchParams(f)}`},[t,c,o,a.apiKey,a.userId,a.userToken,a.branch,e,u]),disconnectFromSlack:S}}const rt=({channelHeading:e})=>s.jsxs(K,{sx:{gap:2,width:"100%"},children:[e,s.jsx(an,{variant:"rectangular",height:36,sx:{borderRadius:1,maxWidth:135}})]}),Oe="preview",tt="count",nt=28;function ha(e){return e.map(t=>({channel_id:t}))}function ma(e,t){if(e.length!==t.length)return!1;const n=new Set(e);return t.every(a=>n.has(a))}
1async function pa(e,t,n){await e.objects.setChannelData({objectId:t.objectId,collection:t.collection,channelId:At,data:{connections:n}})}function Ca(e){return s.jsxs(s.Fragment,{children:[e.name,e.is_private&&" ð"]})}const ga=({data:e,index:t,style:n,selectedChannels:a})=>{const[r,o]=e[t];if(!o)return null;const c=a.includes(o.id);return i.createElement(se,{component:"li",...r,key:o.id,style:n,sx:{height:40}},s.jsxs(K,{direction:"row",sx:{justifyContent:"space-between",width:"100%",alignItems:"center"},children:[s.jsx(q,{variant:"body2",sx:{height:24},children:Ca(o)}),c&&s.jsx(we,{label:s.jsx(O,{id:"QHcLEN"}),size:"small",color:"primary",variant:"outlined"})]}))},xa=e=>i.forwardRef((t,n)=>s.jsx(se,{sx:{p:1},children:s.jsx(Nt,{ref:n,...t,itemSize:40,maxItems:8,ListItemComponent:a=>s.jsx(ga,{...a,selectedChannels:e})})})),Sa=({slackChannelsRecipientObject:e,onChannelsCountChange:t,isEditMode:n,onSlackChannelsEmpty:a,orgName:r})=>{const{_:o}=ie(),c=re(),{rootUIDP:d}=Ie(),{data:l}=ra({}),{data:g}=ca({slackChannelsRecipientObject:e}),[u,S]=i.useState([]),[p,f]=i.useState(!1),C=i.useRef(null),m=i.useRef(!1);i.useEffect(()=>{const _=u.length;t&&t(_)},[u,t]);const I=i.useMemo(()=>g?.map(_=>_.channel_id).filter(Boolean)||[],[g]);i.useEffect(()=>{m.current||ma(I,u)||S(I)},[I,u]);const N=i.useMemo(()=>new Map(l.map(_=>[_.id,_])),[l]),h=i.useMemo(()=>new Set(u),[u]),T=i.useMemo(()=>[...l].sort((_,y)=>{const j=h.has(_.id),v=h.has(y.id);return j&&!v?-1:!j&&v?1:_.name.toLowerCase().localeCompare(y.name.toLowerCase())}),[l,h]),A=(_,y)=>{const j=ha(_);pa(c,e,j).then(()=>{const v=_.filter(z=>!y.includes(z)),F=y.filter(z=>!_.includes(z));ne.track("SlackChannelsUpdated",{orgId:d,previousChannelCount:y.length,currentChannelCount:_.length,channelsAdded:v.length,channelsRemoved:F.length}),v.length>0&&Me("/knockworkflows",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({workflowId:rs,recipients:[{id:e.objectId,collection:e.collection}],data:{orgId:d,orgName:r},tenant:d})}).catch(()=>{ne.track("FailedSlackInitialNotificationWorkflow",{orgId:d,orgName:r})})}).catch(()=>{S(y),Z({message:o({id:"XTURNj"}),variant:"error"})}).finally(()=>{m.current=!1})},E=(_,y)=>{const j=y.filter(F=>F!==void 0).map(F=>F.id),v=u;S(j),m.current=!0,A(j,v)},b=i.useMemo(()=>u.map(_=>N.get(_)).filter(_=>_!==void 0),[u,N]);i.useEffect(()=>{const _=(C.current?.scrollHeight||0)>nt;f(_)},[b]);const L=i.useMemo(()=>xa(u),[u]);return i.useEffect(()=>{l.length===0&&a(!0)},[l,a]),l.length===0?null:s.jsx(K,{sx:{gap:2,width:400},children:s.jsx(St,{multiple:!0,disableCloseOnSelect:!0,openOnFocus:!0,forcePopupIcon:!1,options:T,value:b,onChange:E,disabled:!n,getOptionLabel:_=>_?_.is_private?`${_.name} ð`:_.name:"",isOptionEqualToValue:(_,y)=>_?.id===y?.id&&_?.id!==void 0,sx:{[`.Mui-focused .${Oe}`]:{opacity:.25,pointerEvents:"none"},[`.${tt}`]:{position:"absolute",right:42},"& .MuiAutocomplete-endAdornment":{visibility:b.length>0?"visible":"hidden"}},filterOptions:(_,y)=>{const j=y.inputValue?.toLowerCase()??"";return _.filter(v=>v&&v.name.toLowerCase().includes(j))},slots:{listbox:L},renderOption:(_,y)=>[_,y],renderInput:_=>s.jsx(Je,{..._,autoComplete:"off",label:o({id:"ffQweM"}),placeholder:b?.length?"":o({id:"PLeYjq"}),size:"medium",slotProps:{input:{..._.InputProps,startAdornment:s.jsxs(s.Fragment,{children:[s.jsx(K,{alignSelf:"center",alignItems:"start",className:Oe,direction:"row",flexWrap:"wrap",left:14,maxHeight:nt,overflow:"hidden",position:"absolute",ref:C,right:p?70:42,children:_.InputProps.startAdornment}),p&&s.jsx(we,{className:[Oe,tt].join(" "),label:b?.length,size:"small"})]})}}}),clearOnBlur:!1})})},Ea=({channelHeading:e,isEditMode:t})=>{const{_:n}=ie(),{rootUIDP:a}=Ie(),{getName:r}=cn(),{user:o,refreshKnockToken:c}=ln(),{usersMap:d,usersFetching:l}=Kn(),g=i.useMemo(()=>({id:a,name:r(a)}),[a,r]),u=re(),{buildSlackAuthUrl:S,disconnectFromSlack:p}=fa(os,Cn,{additionalScopes:["users:read","users:read.email"]}),{connectionStatus:f,setConnectionStatus:C}=ot(),[m,I]=i.useState(!1),[N,h]=i.useState(!1),[T,A]=i.useState(0),[E,b]=i.useState(null),[L,_]=i.useState(null),[y,j]=i.useState(!1),v=i.useRef(null),[F,z]=i.useState(null),U=!E||o&&E===o.id;i.useEffect(()=>{if(f==="connected"){const x=new URLSearchParams({orgId:g.id});Me(`/knockslackresolution?${x.toString()}`).then(async k=>
1{if(!k.ok){if(k.status===503&&(await k.json().catch(()=>({}))).error==="SOLE_CONNECTION_INDETERMINATE"){_(null),ne.track("SlackConnectedByFailure",{org:g.id});return}throw new Error("Failed to resolve Slack workspace status")}const M=await k.json();b(M.connectedById),_(M.isSoleConnection)}).catch(()=>{ne.track("SlackConnectedByFailure",{org:g.id})})}},[f,g.id]);const H=async()=>{try{const x=await Me("/knockslackresolution",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({orgId:g.id})});if(!x.ok){if(x.status===409&&(await x.json()).error==="CROSS_WORKSPACE_CONFLICT"){ne.track("SlackCrossWorkspaceConflict",{orgId:a,userId:o?o.id:void 0}),Z({message:n({id:"22S7rT"}),variant:"error"}),C("disconnected");return}throw new Error("Failed to resolve Slack id.")}const k=await x.json();b(k.connectedById),c(),C("connected"),ne.track("SlackWorkspaceConnected",{orgId:a,userId:o?o.id:void 0,connectedById:E})}catch{C("disconnected"),ne.track("SlackUserIdFailure",{org:a}),Z({message:n({id:"kqI-w2"}),variant:"error"})}},W=async()=>{if(!u.slack){ne.track("SlackClientFailure",{org:a}),Z({message:n({id:"3RxVMx"}),variant:"error"});return}try{if(!(await u.slack.authCheck({tenant:g.id,knockChannelId:At})).connection)throw new Error("No Slack auth connection");await H()}catch{Z({message:n({id:"H8z_Bc"}),variant:"error"})}},V=async()=>{v.current=null;try{await W()}finally{I(!1)}};dn(()=>{v.current?.closed&&V()},m?un:null);const me=()=>{const x=S();I(!0);const k=window.screenX+(window.outerWidth-Qe)/2,M=window.screenY+(window.outerHeight-Xe)/2.5,D=window.open(x,as,`width=${Qe},height=${Xe},top=${M},left=${k}`);D?v.current=D:(I(!1),Z({message:n({id:"l4ji3l"}),variant:"error"}))},he=async()=>{h(!0);try{const x=E,k=T,M=await Me("/knockslackresolution",{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({orgId:g.id})});if(!M.ok){if(M.status===503&&(await M.json().catch(()=>({}))).error==="SOLE_CONNECTION_INDETERMINATE"){_(null),Z({message:n({id:"W9CXJX"}),variant:"error"});return}throw new Error("Failed to disconnect Slack workspace.")}const{isSoleConnection:D}=await M.json();b(null),D?p():C("disconnected"),ne.track("SlackWorkspaceDisconnected",{orgId:a,userId:o?o.id:void 0,disconnectedById:o?o.id:void 0,connectedById:x,channelCount:k,wasSoleConnection:D})}catch{Z({message:n({id:"8mZTAU"}),variant:"error"})}finally{h(!1)}},Y=()=>{if(L!==null){if(L){j(!0);return}he()}},J=()=>{const x=E&&d.get(E)?.displayName||"";if(!U&&E){const k=x?`: ${x}.`:".";return n({id:"kwExhF",values:{tooltipText:k}})}return T>0?n(x?{id:"Hy9qmh",values:{email:x}}:{id:"6UkTTP"}):""};return l||f==="connecting"?s.jsx(rt,{channelHeading:e}):s.jsxs(s.Fragment,{children:[e,f!=="connected"?s.jsx(fe,{variant:"outlined",onClick:me,disabled:!t||m,children:m?s.jsx(O,{id:"J28zul"}):s.jsx(O,{id:"mmd4az"})}):s.jsx(s.Fragment,{children:s.jsx(Tt,{title:J(),arrow:!0,children:s.jsx("span",{children:s.jsx(fe,{variant:"contained",onClick:Y,disabled:!t||!U||T>0||N||L===null,children:N?s.jsx(O,{id:"P1i39T"}):s.jsx(O,{id:"QjLqfx"})})})})}),f==="connected"&&F!==!1&&s.jsx(Sa,{slackChannelsRecipientObject:{objectId:g.id,collection:pn},onChannelsCountChange:A,isEditMode:t,onSlackChannelsEmpty:z,orgName:g.name},f),s.jsx(Fe,{open:y,onClose:()=>j(!1),onConfirmAsync:he,title:n({id:"2mwXAV"}),confirmButtonText:n({id:"-K0AvT"}),cancelButtonText:n({id:"dEgA5A"}),slotProps:{confirmButton:{color:"error",variant:"contained"}},children:s.jsx(q,{children:s.jsx(O,{id:"1EfRUM"})})})]})},_a=({isEditMode:e})=>{const{rootUIDP:t}=Ie(),{knockConnection:n}=on(),a=s.jsx(se,{children:s.jsx(O,{id:"lyjq5X"})});return n!==rn.READY?s.jsx(rt,{channelHeading:a}):s.jsx(na,{knockSlackChannelId:At,tenantId:t,children:s.jsx(Ea,{channelHeading:a,isEditMode:e})},t)},ya="e47931cd-d10f-4853-beb3-48bd03be5691",Rn="|||";function xe(e,t){return`${e}${Rn}${t}`}function An(e){const[t,n]=e.split(Rn);return{teamId:t,channelId:n}}function ka(e,t){if(e.length!==t.length)return!1;const n=new Set(e);return t.every(a=>n.has(a))}function ba(e,t,n){return e.map(a=>{const r=t.get(a);
1if(r)return{ms_teams_team_id:r.teamId,ms_teams_channel_id:r.id};const{teamId:o,channelId:c}=An(a),d=n?.find(l=>l.ms_teams_team_id===o&&l.ms_teams_channel_id===c);return d?.ms_teams_team_id&&d?.ms_teams_channel_id?{ms_teams_team_id:d.ms_teams_team_id,ms_teams_channel_id:d.ms_teams_channel_id}:null}).filter(Boolean)}async function va(e,t,n){await e.objects.setChannelData({objectId:t.objectId,collection:t.collection,channelId:Ot,data:{connections:n}})}const Ia=({data:e,index:t,style:n,selectedTeamCounts:a})=>{const[r,o]=e[t];if(!o)return null;const c=a.get(o.id)||0,d=c>0;return i.createElement(se,{component:"li",...r,key:o.id,style:n,sx:{height:40}},s.jsxs(K,{direction:"row",sx:{justifyContent:"space-between",width:"100%",alignItems:"center"},children:[s.jsx(q,{variant:"body2",sx:{height:24},children:o.displayName}),d&&s.jsx(we,{label:c,size:"small",color:"primary",variant:"outlined"})]}))},ja=e=>i.forwardRef((t,n)=>s.jsx(se,{sx:{p:1},children:s.jsx(Nt,{ref:n,...t,itemSize:40,maxItems:8,ListItemComponent:a=>s.jsx(Ia,{...a,selectedTeamCounts:e})})})),wa=({data:e,index:t,style:n,selectedChannels:a,selectedTeamId:r})=>{const[o,c]=e[t];if(!c)return null;const d=xe(r,c.id),l=a.includes(d);return i.createElement(se,{component:"li",...o,key:c.id,style:n,sx:{height:40}},s.jsxs(K,{direction:"row",sx:{justifyContent:"space-between",width:"100%",alignItems:"center"},children:[s.jsx(q,{variant:"body2",sx:{height:24},children:c.displayName}),l&&s.jsx(we,{label:s.jsx(O,{id:"QHcLEN"}),size:"small",color:"primary",variant:"outlined"})]}))},Ta=(e,t)=>i.forwardRef((n,a)=>s.jsx(se,{sx:{p:1},children:s.jsx(Nt,{ref:a,...n,itemSize:40,maxItems:8,ListItemComponent:r=>s.jsx(wa,{...r,selectedChannels:e,selectedTeamId:t})})})),Na=({msTeamsChannelsRecipientObject:e,onChannelsCountChange:t,isEditMode:n})=>{const{_:a}=ie(),r=re(),{rootUIDP:o}=Ie(),{data:c,isLoading:d}=Js({}),{data:l,updateConnectedChannels:g}=Zs({msTeamsChannelsRecipientObject:e}),[u,S]=i.useState(""),{data:p,isLoading:f}=Qs({teamId:u}),[C,m]=i.useState([]),[I,N]=i.useState(!1),h=i.useRef(null),T=i.useRef(!1),A=i.useMemo(()=>new Map(c.map(x=>[x.id,x])),[c]),[E,b]=i.useState(new Map);i.useEffect(()=>{if(u&&p.length>0){const k=A.get(u)?.displayName||"";b(M=>{const D=new Map(M);return p.forEach(te=>{const X=xe(u,te.id);D.set(X,{id:te.id,displayName:te.displayName,teamId:u,teamName:k})}),D})}},[u,p,A]),i.useEffect(()=>{const x=l?.length||0;t&&t(x)},[l,t]);const L=i.useMemo(()=>l?.map(x=>
1x.ms_teams_team_id&&x.ms_teams_channel_id?xe(x.ms_teams_team_id,x.ms_teams_channel_id):null).filter(Boolean)||[],[l]),_=i.useMemo(()=>{if(!u)return[];const x=xe(u,"");return C.filter(k=>k.startsWith(x))},[C,u]),y=i.useMemo(()=>{if(!u)return C;const x=xe(u,"");return C.filter(k=>!k.startsWith(x))},[C,u]),j=i.useMemo(()=>{const x=new Map;return C.forEach(k=>{const{teamId:M}=An(k);x.set(M,(x.get(M)||0)+1)}),x},[C]),v=i.useMemo(()=>new Set(_),[_]),F=i.useMemo(()=>[...p].sort((x,k)=>{const M=xe(u,x.id),D=xe(u,k.id),te=v.has(M),X=v.has(D);return te&&!X?-1:!te&&X?1:x.displayName.toLowerCase().localeCompare(k.displayName.toLowerCase())}),[p,v,u]);i.useEffect(()=>{T.current||ka(L,C)||m(L)},[L,C]);const z=i.useRef(!1);i.useEffect(()=>{if(!z.current&&!u&&l&&l.length>0){const x=l[0].ms_teams_team_id;x&&(S(x),z.current=!0)}},[l,u]);const U=i.useMemo(()=>{const x=new Map;return E.forEach((k,M)=>{x.set(M,k)}),u&&p.forEach(k=>{const M=xe(u,k.id),D=A.get(u)?.displayName||"",te={id:k.id,displayName:k.displayName,teamId:u,teamName:D};x.set(M,te)}),x},[E,p,u,A]),H=i.useMemo(()=>_.map(x=>{const k=U.get(x);if(k)return{id:k.id,displayName:k.displayName}}).filter(Boolean),[_,U]);i.useEffect(()=>{const x=(h.current?.scrollHeight||0)>nt;N(x)},[H]);const W=async(x,k)=>{const M=ba(x,U,l||void 0);try{await va(r,e,M),await g(M);const D=x.filter(X=>!k.includes(X)),te=k.filter(X=>!x.includes(X));ne.track("TeamsChannelsUpdated",{orgId:o,previousChannelCount:k.length,currentChannelCount:x.length,channelsAdded:D.length,channelsRemoved:te.length,teamId:u})}catch{m(k),Z({message:a({id:"ZRjB65"}),variant:"error"})}finally{T.current=!1}},V=(x,k)=>{const M=k.filter(Boolean).map(X=>xe(u,X.id)),D=[...y,...M],te=C;m(D),T.current=!0,W(D,te)},me=(x,k)=>{S(k?.id||"")},he=i.useMemo(()=>ja(j),[j]),Y=i.useMemo(()=>Ta(C,u),[C,u]),J=i.useMemo(()=>c.find(x=>x.id===u),[c,u]);return s.jsxs(K,{sx:{gap:2,width:400},children:[s.jsx(St,{options:c,value:J,onChange:me,disableClearable:!0,disabled:!n||d,getOptionLabel:x=>{if(!x)return"";const k=j.get(x.id)||0;return k>0?`${x.displayName} (${k})`:x.displayName},isOptionEqualToValue:(x,k)=>x?.id===k?.id&&x?.id!==void 0,slots:{listbox:he},renderOption:(x,k)=>[x,k],renderInput:x=>s.jsx(Je,{...x,autoComplete:"off",label:a({id:"d_wOtp"}),placeholder:u?"":a({id:"NCTzlr"}),size:"medium"})},J?.id),u&&s.jsx(St,{multiple:!0,disableCloseOnSelect:!0,openOnFocus:!0,forcePopupIcon:!1,options:F,value:H,onChange:V,disabled:!n||f,getOptionLabel:x=>x?x.displayName:"",isOptionEqualToValue:(x,k)=>x?.id===k?.id&&x?.id!==void 0,sx:{[`.Mui-focused .${Oe}`]:{opacity:.25,pointerEvents:"none"},[`.${tt}`]:{position:"absolute",right:42},"& .MuiAutocomplete-endAdornment":{visibility:H.length>0?"visible":"hidden"}},filterOptions:(x,k)=>{const M=k.inputValue?.toLowerCase()??"";return x.filter(D=>D&&D.displayName.toLowerCase().includes(M))},slots:{listbox:Y},renderOption:(x,k)=>[x,k],renderInput:x=>s.jsx(Je,{...x,autoComplete:"off",label:a({id:"7a203s"}),placeholder:H?.length?"":a({id:"PLeYjq"}),size:"medium",slotProps:{input:{...x.InputProps,startAdornment:s.jsxs(s.Fragment,{children:[s.jsx(K,{alignSelf:"center",alignItems:"start",className:Oe,direction:"row",flexWrap:"wrap",left:14,maxHeight:nt,overflow:"hidden",position:"absolute",ref:h,right:I?70:42,children:x.InputProps.startAdornment}),I&&s.jsx(we,{className:[Oe,tt].join(" "),label:H?.length,size:"small"})]})}}}),clearOnBlur:!1})]})},Ra=({channelHeading:e,isEditMode:t})=>{const{_:n}=ie(),{rootUIDP:a}=Ie(),{getName:r}=cn(),o=i.useMemo(()=>({id:a,name:r(a)}),[a,r]),c=re(),{buildMsTeamsAuthUrl:d,disconnectFromMsTeams:l}=ms(ya,Cn),{connectionStatus:g,setConnectionStatus:u}=$e(),[S,p]=i.useState(!1),f=i.useRef(null),[C,m]=i.useState(0),I=async()=>{if(!c.msTeams){Z({message:n({id:"IWYud6"}),variant:"error"});return}try{if(!(await c.msTeams.authCheck({tenant:o.id,knockChannelId:Ot})).connection)throw new Error("No Ms Teams auth connection");u("connected"),ne.track("TeamsWorkspaceConnected",{orgId:a})}catch{Z({message:n({id:"zMfowu"}),variant:"error"})}},N=async()=>{f.current=null;try{await I()}finally{p(!1)}};dn(()=>{f.current?.closed&&N()},S?un:null);const h=()=>{const A=d(),E=window.screenX+(window.outerWidth-Qe)/2,b=window.screenY+(window.outerHeight-Xe)/2.5;p(!0);const L=window.open(A,is,`width=${Qe},height=${Xe},top=${b},left=${E}`);L?f.current=L:(p(!1),Z({message:n({id:"LVy-oc"}),variant:"error"}))},T=()=>{try{const A=C;l(),ne.track("TeamsWorkspaceDisconnected",{orgId:a,channelCount:A})}catch{Z({message:n({id:"6GtxWg"}),variant:"error"})}};return g==="connecting"?s.jsx(rt,{channelHeading:e}):s.jsxs(s.Fragment,{children:[e,g!=="connected"?s.jsx(fe,{variant:"outlined",onClick:h,disabled:!t||S,children:S?s.jsx(O,{id:"J28zul"}):s.jsx(O,{id:"ws65zp"})}):s.jsx(Tt,{title:C>0?n({id:"wMRbHN"}):"",arrow:!0,children:s.jsx("span",{children:s.jsx(fe,{variant:"contained",onClick:T,disabled:!t||C>0,children:s.jsx(O,{id:"Uo5jQc"})})})}),g==="connected"&&s.jsx(Na,{msTeamsChannelsRecipientObject:{objectId:o.id,collection:pn},onChannelsCountChange:m,isEditMode:t},g)]})},Aa=({isEditMode:e})=>{const{rootUIDP:t}=Ie(),{teamsNotifications:n}=We(),{knockConnection:a}
1=on(),r=s.jsx(se,{children:s.jsx(O,{id:"MxACj5"})});return n?a!==rn.READY?s.jsx(rt,{channelHeading:r}):s.jsx(us,{tenantId:t,knockMsTeamsChannelId:Ot,children:s.jsx(Ra,{channelHeading:r,isEditMode:e})},t):null},On=({label:e,value:t,onChange:n,options:a,size:r="medium",sx:o,disabled:c=!1,ariaLabel:d})=>{const l=g=>{n(g.target.value)};return s.jsx(zn,{size:r,sx:o,disabled:c,children:s.jsx(Hn,{value:t,onChange:l,SelectDisplayProps:{"aria-label":d},renderValue:g=>s.jsxs(K,{direction:"row",sx:{gap:.5},children:[s.jsx(q,{variant:"body2",component:"span",sx:{color:"text.secondary"},children:e}),s.jsx(q,{variant:"body2",component:"span",sx:{fontWeight:u=>u.typography.fontWeightMedium},children:a.find(u=>u.value===g)?.label})]}),children:a.map(g=>s.jsx(fn,{value:g.value,children:s.jsx(q,{variant:"body2",children:g.label})},g.value))})})},Ln=()=>s.jsx(q,{variant:"body2",color:"textSecondary",children:s.jsx(O,{id:"xbNnzW",components:{0:s.jsx(Vn,{href:"https://security.chainguard.dev/resources?s=hdft1yllox1qiso2w5ew&name=feature-specific-subprocessors",target:"_blank"})}})}),Oa=({open:e,onClose:t,onConfirm:n,title:a,confirmButtonText:r,cancelButtonText:o,legalNotice:c})=>s.jsxs(Fe,{open:e,onClose:t,onConfirm:n,title:a,confirmButtonText:r,cancelButtonText:o,children:[s.jsx(q,{sx:{marginBottom:1},children:s.jsx(O,{id:"vkWmqA"})}),c&&s.jsx(Ln,{})]}),Qt=[ae[R.BREAKING_CHANGES],ae[R.INCIDENTS],ae[ve],ae[R.PRODUCT_ANNOUNCEMENTS]],Xt=()=>{const{_:e}=ie(),{extraEmailCategories:t}=We(),n=t?Qt:Qt.filter(a=>a!==ae[ve]);return s.jsx(qn,{children:n.map((a,r)=>s.jsx(cs,{disablePadding:!0,sx:{ml:3,display:"list-item",listStyleType:"disc"},children:e(a)},r))})},Zt=({rootUIDP:e,setIsEnableDialogOpen:t,isEmailEnabled:n,setIsEnableEmailLoading:a,setIsEmailNotifsEnabledOrg:r,setShowEditModal:o,refetch:c})=>{const{_:d}=ie(),{refetch:l}=hn(),g=n?{id:"QJvbq2"}:{id:"kYyOJ3"};return s.jsx(fe,{color:n?"error":"primary",onClick:async()=>{a(!0),t(!1);try{const u=await Me("/knockenableemail",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({orgId:e,enableEmail:!n})});if(!u.ok)throw new Error("Failed to enable email notifications.");const S=await u.json();r(S.emailEnabled),l(),S.emailEnabled||c({includeForwardingAddresses:!0})}catch(u){Z({message:d(n?{id:"5mAgVG"}:{id:"6y0-zd"}),variant:"error"}),ne.track(n?"FailedDisableEmailNotifications":"FailedEnableEmailNotifications",{orgId:e,error:u})}finally{a(!1),o(!1)}},children:d(g)})},La=({rootUIDP:e,isEnableDialogOpen:t,setIsEnableDialogOpen:n,isEmailEnabled:a,setIsEnableEmailLoading:r,setIsEmailNotifsEnabledOrg:o,setShowEditModal:c,refetch:d})=>{const{_:l}=ie();return a?s.jsxs(Fe,{open:t,onClose:()=>n(!1),ConfirmButton:s.jsx(Zt,{isEmailEnabled:!0,refetch:d,rootUIDP:e,setIsEmailNotifsEnabledOrg:o,setIsEnableEmailLoading:r,setIsEnableDialogOpen:n,setShowEditModal:c}),title:l({id:"QJvbq2"}),cancelButtonText:l({id:"dEgA5A"}),children:[s.jsx(q,{children:s.jsx(O,{id:"INr862"})}),s.jsx(Xt,{})]}):s.jsxs(Fe,{open:t,onClose:()=>n(!1),ConfirmButton:s.jsx(Zt,{isEmailEnabled:!1,refetch:d,rootUIDP:e,setIsEmailNotifsEnabledOrg:o,setIsEnableEmailLoading:r,setIsEnableDialogOpen:n,setShowEditModal:c}),title:l({id:"kYyOJ3"}),cancelButtonText:l({id:"dEgA5A"}),children:[s.jsx(q,{children:s.jsx(O,{id:"MClELu"})}),s.jsx(Xt,{}),s.jsx(q,{sx:{marginTop:3,marginBottom:1},children:s.jsx(O,{id:"kns5Jx"})}),s.jsx(Rt,{sx:{marginBottom:1.25}}),s.jsx(Ln,{})]})},Da=e=>Xn({email:Zn({error:e({id:"n3Eaz3"})}).trim()});function Pa(e){return e.flatMap(t=>t===ve?Ye:[t])}function en(e){return Ye.every(t=>e.includes(t))}const tn=[{value:R.BREAKING_CHANGES,label:ae[R.BREAKING_CHANGES]},{value:R.INCIDENTS,label:ae[R.INCIDENTS]},{value:ve,label:ae[ve]},{value:R.PRODUCT_ANNOUNCEMENTS,label:ae[R.PRODUCT_ANNOUNCEMENTS]}],Ma=({address:e,onDelete:t,onUpdateCategories:n,availableCategories:a})=>{const[r,o]=i.useState(null),c=!!r,{_:d}=ie(),l=Ue(m=>m.breakpoints.down("sm")),g=Ue(m=>m.breakpoints.down("md")),u=m=>{o(m.currentTarget)},S=()=>{o(null)},p=m=>{const I=m===ve;let N;I?en(e.notificationCategories)?N=e.notificationCategories.filter(T=>!Ye.includes(T)):N=[...e.notificationCategories,...Ye]:N=e.notificationCategories.includes(m)?e.notificationCategories.filter(h=>h!==m):[...e.notificationCategories,m],n(e.id,N)},f=m=>
1m===ve?en(e.notificationCategories):e.notificationCategories.includes(m),C=a.filter(m=>f(m.value)).map(m=>d(m.label)).join(", ");return s.jsxs(K,{direction:"row",sx:{flexDirection:l?"column":"row",gap:1,alignItems:"flex-start",width:"100%"},children:[s.jsxs(K,{sx:{flex:1,gap:0,border:m=>`1px solid ${m.palette.divider}`,borderRadius:1,overflow:"hidden",backgroundColor:"background.paper"},children:[s.jsxs(se,{sx:{display:"flex",alignItems:"center",gap:1.5,px:1.5,py:1},children:[s.jsx(q,{variant:"body2",children:e.email}),e.verified?s.jsx(we,{color:"success",label:d({id:"QDEWii"})}):s.jsx(Tt,{title:d({id:"JoTO0V"}),arrow:!0,children:s.jsx(we,{color:"warning",label:d({id:"VBTGXl"})})})]}),s.jsx(fe,{variant:"text",onClick:u,endIcon:s.jsx(es,{style:{width:16,height:16}}),sx:{justifyContent:"flex-start",borderRadius:0,textTransform:"none",px:1.5,py:.75,borderTop:m=>`1px solid ${m.palette.divider}`,"&:hover":{backgroundColor:"action.hover"}},children:s.jsxs(K,{direction:"row",sx:{gap:1,width:"100%",alignItems:"center"},children:[s.jsx(q,{variant:"body2",sx:{color:"text.dim",fontWeight:m=>m.typography.fontWeightMedium},children:s.jsx(O,{id:"TaA7Fo"})}),s.jsx(q,{variant:"body2",sx:{flex:1,textAlign:"left",fontWeight:m=>m.typography.fontWeightMedium},children:C||s.jsx(O,{id:"-f7hCL"})})]})}),s.jsx(ts,{anchorEl:r,open:c,onClose:S,anchorOrigin:{vertical:"bottom",horizontal:"left"},transformOrigin:{vertical:"top",horizontal:"left"},slotProps:{paper:{sx:{py:.25}}},children:a.map(m=>s.jsxs(fn,{onClick:()=>p(m.value),dense:!0,sx:{py:.25,px:1,gap:.5,minHeight:"auto"},children:[s.jsx(xn,{checked:f(m.value),sx:{p:0}}),s.jsx(ns,{primary:d(m.label),slotProps:{primary:{variant:"body2"}},sx:{my:0}})]},m.value))})]}),s.jsx(fe,{variant:"text",color:"primary",onClick:()=>t(e.id),sx:{minWidth:"auto",px:2,py:1,alignSelf:g?"center":"flex-start"},children:s.jsx(O,{id:"cnGeoo"})})]})},Fa=({forwardingAddresses:e,loading:t,updateObjectPreferences:n,createForwardingAddress:a,deleteForwardingAddress:r,isLocalDev:o,isEmailEnabled:c})=>{const{_:d}=ie(),l=Ue(y=>y.breakpoints.down("md")),{extraEmailCategories:g}=We(),u=g?tn:tn.filter(y=>y.value!==ve),[S,p]=i.useState([]),[f,C]=i.useState(!1),{getSearchParam:m,removeSearchParam:I}=ls(),{refetch:N}=hn(),{control:h,formState:{isValid:T},handleSubmit:A,reset:E}=Gn({resolver:Jn(Da(d)),mode:"onChange",defaultValues:{email:""}});i.useEffect(()=>{e?p(e):!t&&e===null&&p([])},[e,t]),i.useEffect(()=>{const y=m("verified");y==="true"?Z({message:d({id:"aMGkHl"}),variant:"success"}):y==="error"&&Z({message:d({id:"zOjiCP"}),variant:"error"}),y&&I("verified")},[d,m,I]);const b=A(async({email:y})=>{C(!0);try{const j=await a(y);p(j),N(),E()}catch{Z({message:d({id:"hB5Nsh"}),variant:"error"})}finally{C(!1)}}),L=i.useCallback(async(y,j)=>{const v=Pa(j),F=S.find(W=>W.id===y);if(!F)return;const z=F.notificationCategories;p(S.map(W=>W.id===y?{...W,notificationCategories:v}:W));const U=[R.BREAKING_CHANGES,R.INCIDENTS,R.END_OF_LIFE,R.NEW_RELEASES_MAJOR,R.NEW_RELEASES_MINOR,R.PRODUCT_ANNOUNCEMENTS],H={};U.forEach(W=>{H[W]={channel_types:{email:v.includes(W),chat:!0,in_app_feed:!0}}});try{await n(y,"forwarding_addresses",{__persistence_strategy__:"merge",categories:H})}catch{p(S.map(W=>W.id===y?{...W,notificationCategories:z}:W)),Z({message:d({id:"9OYKBX"}),variant:"error"})}},[S,n,d]),_=i.useCallback(async y=>{const j=S;p(S.filter(v=>v.id!==y));try{const v=await r(y);p(v),N()}catch{p(j),Z({message:d({id:"DVEIJG"}),variant:"error"})}},[S,r,N,d]);return s.jsx(se,{sx:{maxWidth:603},children:s.jsxs(K,{sx:{gap:2},children:[s.jsx(Rt,{flexItem:!0}),o&&s.jsx(gn,{children:s.jsx(O,{id:"UQ_dXl"})}),s.jsxs(K,{sx:{gap:.75},children:[s.jsx(q,{variant:"h6",component:"h3",children:s.jsx(O,{id:"OQnvLw"})}),s.jsx(q,{variant:"body2",sx:{color:"text.secondary"},children:s.jsx(O,{id:"4M0QH9"})})]}),s.jsxs(K,{sx:{gap:1,flexDirection:l?"column":"row"},children:[s.jsx(Yn,{name:"email",control:h,render:({field:y,fieldState:j})=>s.jsx(Je,{...y,type:"email",disabled:!c,error:j.invalid&&j.isTouched,helperText:j.isTouched?j.error?.message:void 0,placeholder:"Add email address to forward notifications",size:"small",sx:{flex:1}})}),s.jsx(fe,{variant:"contained",color:"primary",startIcon:s.jsx(Qn,{style:{width:16,height:16}}),onClick:b,disabled:!c||!T||f,sx:{height:40},children:f?s.jsx(O,{id:"5A4TZa"}):s.jsx(O,{id:"BQZNY3"})})]}),s.jsx(K,{sx:{gap:1},children:S.map(y=>s.jsx(Ma,{address:y,onDelete:_,onUpdateCategories:L,availableCategories:u},y.id))})]})})},qe={variable:"recipient.subscription.isOwner",operator:"equal_to",argument:"true"},Ge=e=>{const t=e?.email;return typeof t=="boolean"?t:!0},gt=(e,t)=>e?t==="owners"?{conditions:[qe]}:!0:!1,Ua=({currentValue:e,onSave:t,disabled:n=!1})=>{const{_:a}=ie(),[r,o]=i.useState(e);if(i.useEffect(()=>{o(e)},[e]),r===null)return null;const c=async d=>{const l=r;o(d);try{await t(d)}catch{o(l)}};return s.jsx(K,{sx:{mt:2},children:s.jsx(On,{label:s.jsx(O,{id:"OibEPG"}),ariaLabel:a({id:"5icoS1"}),value:r,onChange:c,options:[{value:"major",label:s.jsx(O,{id:"qHHLOh"})},{value:"major-minor",label:s.jsx(O,{id:"PbS7lz"})}],size:"small",disabled:n,sx:{maxWidth:200}})})},Dn={title:{id:"21Ac8e"},defaultScope:"organization",preferences:[{label:ae[R.END_OF_LIFE],description:{id:"dbLtXX"},knockCategoryKey:R.END_OF_LIFE},{label:ae[R.NEW_RELEASES_MAJOR],description:{id:"aTMP4f"},knockCategoryKey:R.NEW_RELEASES_MAJOR,selectOptions:e=>s.jsx(Ua,{...e})}]},nn=[{title:ae[R.BREAKING_CHANGES],defaultScope:"organization",preferences:[{label:{id:"R3jP9u"},description:{id:"PT4QOI"},knockCategoryKey:R.BREAKING_CHANGES}]},{title:ae[R.INCIDENTS],defaultScope:"organization",preferences:[{label:{id:"X5aBue"},description:{id:"bxuQhe"},knockCategoryKey:R.INCIDENTS}]},{title:ae[R.PRODUCT_ANNOUNCEMENTS],defaultScope:"organization",preferences:[{label:{id:"CKMH_f"},description:{id:"Zye-AM"},knockCategoryKey:R.PRODUCT_ANNOUNCEMENTS}]},Dn];function Wa(e,t,n){const a={breaking_changes:!0,incidents:!0,end_of_life:!0,new_releases_major:!0,new_releases_minor:!0,product_announcements:!0};let r=n;if(!e?.categories)return{checkedStatuses:a,detectedScope:r,detectedNewReleases:"major-minor"};t.forEach(l=>{const g=e.categories[l.knockCategoryKey];if(g){const u=Ge(g.channel_types);a[l.knockCategoryKey]=u;const S=g.channel_types?.email;typeof S=="object"&&S.conditions&&S.conditions.length>0&&S.conditions.find(p=>{const f=p.variable===qe.variable&&p.operator===qe.operator&&p.argument===qe.argument,C=p.variable==="recipient.orgRole"&&p.operator==="equal_to"&&p.argument==="owner";return f||C})&&(r="owners")}});const o=Ge(e.categories[R.NEW_RELEASES_MAJOR]?.channel_types),c=Ge(e.categories[R.NEW_RELEASES_MINOR]?.channel_types);return{checkedStatuses:a,detectedScope:r,detectedNewReleases:o&&!c?"major":"major-minor"}}function $a(e,t,n,a,r){const o=l=>{const g=e.categories?.[l];return{...g,channel_types:{email:g?.channel_types?.email??!0,chat:!0,in_app_feed:!0}}},c={[R.BREAKING_CHANGES]:o(R.BREAKING_CHANGES),[R.INCIDENTS]:o(R.INCIDENTS),[R.END_OF_LIFE]:o(R.END_OF_LIFE),[R.NEW_RELEASES_MAJOR]:o(R.NEW_RELEASES_MAJOR),[R.NEW_RELEASES_MINOR]:o(R.NEW_RELEASES_MINOR),[R.PRODUCT_ANNOUNCEMENTS]:o(R.PRODUCT_ANNOUNCEMENTS)};if(t.forEach(l=>{const g=e.categories[l.knockCategoryKey],u=n[l.knockCategoryKey],S={channel_types:{...g.channel_types,email:gt(u,a)}};c[l.knockCategoryKey]=S}),t.some(l=>l.knockCategoryKey===R.NEW_RELEASES_MAJOR)){const l=Ge(c[R.NEW_RELEASES_MAJOR]?.channel_types),g=c[R.NEW_RELEASES_MAJOR]||{channel_types:{chat:!0,email:!0,in_app_feed:!0}},u=c[R.NEW_RELEASES_MINOR]||{channel_types:{chat:!0,email:!0,in_app_feed:!0}},S=gt(l,a),p=gt(r==="major-minor"?l:!1,a);c[R.NEW_RELEASES_MAJOR]={channel_types:{...g.channel_types,email:S}},c[R.NEW_RELEASES_MINOR]={channel_types:{...u.channel_types,email:p}}}return c}const Ba=({title:e,defaultScope:t="organization",preferences:n,knockPreferences:a,loading:r,onPreferencesUpdate:o,isSaving:c,setIsSaving:d,isEditMode:l})=>{const{_:g}=ie(),{rootUIDP:u}=Ie(),[S,p]=i.useState(t),[f,C]=i.useState(null),[m,I]=i.useState("major-minor");i.useEffect(()=>{if(c)return;const{checkedStatuses:E,detectedScope:b,detectedNewReleases:L}=Wa(a,n,t);C(E),I(L),p(b)},[a,n,t,c]);const N=i.useCallback(async E=>{const b=E?.checked??f,L=E?.scope??S,_=E?.releases??m;if(!b||!a?.categories)return;const y=S,j=m,v=f;d(!0);try{const z={preferences:{__persistence_strategy__:"replace",categories:$a(a,n,b,L,_)}},U=new URLSearchParams({tenantId:u}),H=await fetch(`/knockpreferences?${U.toString()}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(z)});if(!H.ok)throw new Error(`Failed to save preferences: ${H.status}`);const W=await H.json();W.preferences&&(o(W.preferences),E?.scope&&y!==L&&ne.track("UpdateEmailNotificationScope",{orgId:u,previousScope:y,currentScope:L}),E?.releases&&j!==_&&ne.track("UpdateReleaseVersionPreference",{orgId:u,previousVersion:j,currentVersion:_}),E?.checked&&v&&Object.keys(b).forEach(V=>{v[V]!==b[V]&&ne.track("UpdateEmailNotificationPreferences",{orgId:u,category:V,previousState:v[V],currentState:b[V],scope:L})}))}catch{const F=g({id:"Osv0dm"});throw Z({message:F,variant:"error"}),new Error(F)}finally{d(!1)}},[o,f,S,a,m,d,n,u,g]),h=i.useCallback(async(E,b)=>{if(!f)return;const L={...f,[E]:b};C(L);try{await N({checked:L})}catch{C(f)}},[f,N]),T=i.useCallback(async E=>{const b=S;p(E);try{await N({scope:E})}catch{p(b)}},[S,N]),A=!!f&&n.every(E=>
1!f[E.knockCategoryKey]);return s.jsxs(K,{sx:{gap:1,width:"100%"},children:[s.jsxs(se,{children:[s.jsx(q,{variant:"body1",sx:{fontWeight:E=>E.typography.fontWeightMedium,mb:2},children:g(e)}),s.jsx(On,{label:s.jsx(O,{id:"2Y3PBJ"}),ariaLabel:g({id:"wRGkny"}),value:S,onChange:T,options:[{value:"organization",label:s.jsx(O,{id:"ucgZ0o"})},{value:"owners",label:s.jsx(O,{id:"RKucmC"})}],disabled:!l||c||A,sx:{minWidth:180}})]}),s.jsx(K,{sx:{mt:1},children:r?n.map(E=>s.jsx(an,{variant:"rectangular",height:60,sx:{mb:1,borderRadius:1}},E.knockCategoryKey)):f&&n.map(E=>s.jsxs(K,{direction:"row",sx:{alignItems:"flex-start",mb:1},children:[s.jsx(xn,{checked:f[E.knockCategoryKey],onChange:b=>h(E.knockCategoryKey,b.target.checked),slotProps:{input:{"aria-label":g(E.label)}},disableRipple:!0,disabled:!l||r||c,sx:{mt:-.5}}),s.jsxs(K,{sx:{flex:1},children:[s.jsx(q,{variant:"body2",sx:{mt:.5,fontWeight:b=>b.typography.fontWeightMedium},children:g(E.label)}),s.jsx(q,{variant:"caption",sx:{color:"text.secondary"},children:g(E.description)}),E.selectOptions?.({currentValue:f[E.knockCategoryKey]?m:null,onSave:async b=>{await N({releases:b}),I(b)},disabled:!l||r||c})]})]},E.knockCategoryKey))})]})},Ka=({isLocalDev:e,isEmailEnabled:t,isEditMode:n,isEnableEmailLoading:a,onEditClick:r,onToggleEmailClick:o,knockPreferences:c,showLoadingSkeletons:d,onPreferencesUpdate:l,isSaving:g,setIsSaving:u,forwardingAddresses:S,updateObjectPreferences:p,createForwardingAddress:f,deleteForwardingAddress:C})=>{const m=Ue(T=>T.breakpoints.down("md")),I=Ue(T=>T.breakpoints.down("sm")),{extraEmailCategories:N}=We(),h=N?nn:nn.filter(T=>T!==Dn);return s.jsxs(s.Fragment,{children:[s.jsxs(K,{alignItems:"start",sx:{gap:2},children:[s.jsx(Rt,{flexItem:!0}),s.jsxs(se,{sx:{width:"100%"},children:[e&&s.jsx(gn,{children:s.jsx(O,{id:"qtdPTh"})}),s.jsxs(K,{sx:{flexDirection:m?"column":"row",alignItems:m?void 0:"center",justifyContent:"space-between"},children:[s.jsxs(se,{children:[s.jsxs(K,{direction:"row",sx:{alignItems:"center",gap:1},children:[s.jsx(q,{variant:"h6",component:"h3",children:s.jsx(O,{id:"O3oNi5"})}),t&&s.jsx(fe,{variant:"text",size:"small",onClick:r,sx:{textTransform:"none",minWidth:"auto",px:1,py:.5,fontSize:"0.875rem"},children:n?s.jsx(O,{id:"y3aU20"}):s.jsx(O,{id:"ePK91l"})})]}),s.jsx(q,{variant:"body2",color:"textSecondary",sx:{mt:t?0:1},children:s.jsx(O,{id:"3rbNGo"})})]}),s.jsx(fe,{variant:"contained",size:"small",onClick:o,loading:a,sx:{marginTop:I?1:0},children:t?s.jsx(O,{id:"cO9-2L"}):s.jsx(O,{id:"PaQ3df"})})]})]}),h.map(T=>s.jsx(Ba,{...T,knockPreferences:c,loading:d,onPreferencesUpdate:l,isSaving:g,setIsSaving:u,isEditMode:n},T.title.id))]}),s.jsx(Fa,{forwardingAddresses:S,loading:d,updateObjectPreferences:p,createForwardingAddress:f,deleteForwardingAddress:C,isLocalDev:e,isEmailEnabled:t})]})},za=({isEmailNotifsEnabledOrg:e,setIsEmailNotifsEnabledOrg:t})=>{const{_:n}=ie(),[a,r]=i.useState(!1),[o,c]=i.useState(!1),[d,l]=i.useState(!1),{rootUIDP:g}=Ie(),[u,S]=i.useState(!1),[p,f]=i.useState(!1),[C,m]=i.useState(!1),{preferences:I,setPreferences:N,loading:h,forwardingAddresses:T,updateObjectPreferences:A,createForwardingAddress:E,deleteForwardingAddress:b,refetch:L}=ss(g);i.useEffect(()=>{!h&&I&&!u&&S(!0)},[h,I,u]);const _=h&&!u,y=i.useCallback(F=>{N(F)},[N]),j=()=>{o?c(!1):l(!0)},v=()=>{c(!0),l(!1)};return s.jsxs(s.Fragment,{children:[s.jsx(Ka,{isLocalDev:mn,isEmailEnabled:e,isEditMode:o,isEnableEmailLoading:C,onEditClick:j,onToggleEmailClick:()=>f(!0),knockPreferences:I,showLoadingSkeletons:_,onPreferencesUpdate:y,isSaving:a,setIsSaving:r,forwardingAddresses:T,updateObjectPreferences:A,createForwardingAddress:E,deleteForwardingAddress:b}),s.jsx(Oa,{open:d,onClose:()=>l(!1),onConfirm:v,title:n({id:"5LtRmy"}),confirmButtonText:n({id:"xGVfLh"}),cancelButtonText:n({id:"dEgA5A"})}),s.jsx(La,{isEmailEnabled:e,isEnableDialogOpen:p,refetch:L,rootUIDP:g,setIsEmailNotifsEnabledOrg:t,setIsEnableEmailLoading:m,setIsEnableDialogOpen:f,setShowEditModal:l})]})},Ha=({isEditMode:e,showEditModal:t,onEditClick:n,onConfirmEdit:a,onCloseEditModal:r})=>{const{_:o}=ie(),{teamsNotifications:c}=We();return s.jsxs(s.Fragment,{children:[s.jsxs(K,{alignItems:"start",sx:{gap:2},children:[s.jsxs(se,{children:[mn,s.jsxs(K,{direction:"row",sx:{alignItems:"center",gap:1},children:[s.jsx(q,{variant:"h6",component:"h3",children:s.jsx(O,{id:"nbfdhU"})}),s.jsx(fe,{variant:"text",size:"small",onClick:n,sx:{textTransform:"none",minWidth:"auto",px:1,py:.5,fontSize:"0.875rem"},children:e?s.jsx(O,{id:"y3aU20"}):s.jsx(O,{id:"ePK91l"})})]}),s.jsx(q,{variant:"body2",color:"textSecondary",sx:{mt:1},children:s.jsx(O,{id:"Qw4Pz-"})})]}),s.jsx(_a,{isEditMode:e}),c&&s.jsx(Aa,{isEditMode:e})]}),s.jsx(Fe,{open:t,onClose:r,onConfirm:a,title:o({id:"fSPO7O"}),confirmButtonText:o({id:"qAGp2O"}
1),cancelButtonText:o({id:"dEgA5A"}),children:s.jsx(O,{id:"4b7fbc"})})]})},Va=()=>{const[e,t]=i.useState(!1),[n,a]=i.useState(!1),r=()=>{e?t(!1):a(!0)},o=()=>{t(!0),a(!1)};return s.jsx(Ha,{isEditMode:e,showEditModal:n,onEditClick:r,onConfirmEdit:o,onCloseEditModal:()=>a(!1)})},to=()=>{const{isEmailNotifsEnabledOrg:e,setIsEmailNotifsEnabledOrg:t}=ln();return s.jsx(se,{children:s.jsxs(K,{sx:{gap:4},children:[s.jsx(Va,{}),s.jsx(za,{isEmailNotifsEnabledOrg:e,setIsEmailNotifsEnabledOrg:t})]})})};export{Ha as ChatAppIntegrationsSectionView,to as Organization,to as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.