import{j as t,ej as F,aw as k,b8 as O,R as d,az as N,cD as P,E as V,a9 as l,df as c,o as f,l as T,k as L,G as A,aR as G}from"./app-BgLa5dit.js";import{S as R}from"./CcviYpBC.chunk.js";import{S}from"./CReApwJh.chunk.js";import{C as B}from"./BPRDISw7.chunk.js";import{C as D,a as U}from"./8iu0vnCW.chunk.js";import{D as z}from"./C4BcftDO.chunk.js";import{T as E}from"./lZO4aq5x.chunk.js";import{O as _,S as g,a as q,b as H}from"./BPPr_ng0.chunk.js";import"./3nM7jLnE.chunk.js";import"./CPXlV0fg.chunk.js";import"./ChrB5FYK.chunk.js";import"./DNClpFKN.chunk.js";import"./DR2FaZH9.chunk.js";import"./KUnagq9Z.chunk.js";import"./DULWIWQR.chunk.js";import"./CCcwLDvu.chunk.js";import"./DDfKZ_ng.chunk.js";import"./C8_78Eqq.chunk.js";import"./BixyE8L-.chunk.js";const I={table:"w-100 h-auto",header:"",headerCell:"d-none",row:"py-3",cell:"p-3 flex-grow-1"},x=F(),K={name:x.accessor(e=>e,{id:"name",header:"Name",cell:e=>{const s=e.getValue();return t.jsxs("div",{className:"d-flex flex-column gap-2",children:[s.displayName,g[s.name]&&t.jsx("div",{className:"alert alert-danger mb-0",children:g[s.name]})]})},size:800}),value:x.accessor(e=>e,{id:"Value",header:"",cell:e=>{const s=e.getValue();return t.jsx(_,{settingName:s.name})},size:100})};function W(e){return t.jsx(E,{data:e.data,columns:Object.values(K),theme:I})}const j="edit-organisation-options";function J(e,s){return s.reduce((r,n)=>{switch(n.name){case c.Developer:return e;case c.SalesSupport:return{...r,...H.reduce((o,a)=>(e[a]&&(o[a]=e[a]),o),{})};case c.Support:return{...r,...q.reduce((o,a)=>(e[a]&&(o[a]=e[a]),o),{})};default:return r}},{})}function M(e){const s=k(),r=O(),n=()=>r.unlock(j);return d.useEffect(()=>{s.dirty&&r.lock({id:j,title:"Are you sure you want to leave?",text:"The options you are currently editing will not be saved."}),s.dirty||n()},[s.dirty]),t.jsxs(N,{className:"d-flex flex-column gap-3",children:[t.jsx(z,{heading:"Feature flags",children:t.jsx(W,{data:Object.values(J(e.organisationSettings,e.userGroups))})}),t.jsx("div",{className:"d-flex justify-content-end",children:t.jsx(P,{variant:"dark",disabled:!s.dirty,onClick:()=>e.setShowPopup(!0),children:"Save changes"})}),t.jsx("div",{children:e.showPopup&&t.jsxs(V,{title:"Update options",closePopup:()=>e.setShowPopup(!1),children:[t.jsx("p",{className:"m-0 pb-3",children:"Are you sure you want to save your changes?"}),t.jsxs(l,{children:[t.jsx(l.Cancel,{onClick:()=>e.setShowPopup(!1)}),t.jsx(l.Submit,{showSpinner:e.showSpinner,variant:"dark",text:"Save changes",onClick:()=>e.onSubmit(s.values)})]})]})})]})}function he(e){var h;const s=f(S.organisationSettings(e.id)),r=s.data?Object.entries(s.data).filter(([u,i])=>i.kind===R.FeatureFlag).reduce((u,[i,C])=>(u[i]=C,u),{}):{},n=f(G.currentUser()),[o,a]=d.useState(!1),[w,m]=d.useState(!1),p=T(),y=L();async function v(u){try{a(!0);const i=Object.values(u);await y(S.updateSettings(e.id,i)),a(!1),p.success("Customer options updated.")}catch{p.error("Failed to update customer options.")}finally{m(!1)}}const b=s.hasCompleted&&n.hasCompleted;return t.jsx(D,{view:U.Customers,children:t.jsx(B,{title:"Feature Flags",currentTabId:"featureFlags",id:e.id,loading:!b,children:t.jsx(A,{onSubmit:()=>{},initialValues:r,children:t.jsx(M,{organisationSettings:r,showSpinner:o,showPopup:w,userGroups:(h=n.data)==null?void 0:h.groups,setShowPopup:m,setShowSpinner:a,onSubmit:v})})})})}export{he as OrganisationFeatureFlagsView};
//# sourceMappingURL=CIUzQQ6f.chunk.js.map
