"use strict";(globalThis.webpackChunk_affine_web=globalThis.webpackChunk_affine_web||[]).push([[2884],{22884:(e,s,a)=>{a.r(s),a.d(s,{AdminPanel:()=>k,Component:()=>C});var l=a(36870),t=a(63234),i=a(21817),r=a(53216),n=a(86326),c=a(69628),d=a(45483),o="zt1q5w8";let u=({modifiedValues:e,onConfirm:s})=>{let{openConfirmModal:a}=(0,t.fl)(),{jumpToIndex:i}=(0,c.P)(),r=(0,n.useCallback)(()=>i(),[i]);return(0,l.jsxs)("div",{className:"zt1q5w0",children:[(0,l.jsx)(d.Logo1Icon,{className:"zt1q5w1",onClick:r}),(0,l.jsxs)("div",{className:"zt1q5w2",children:[(0,l.jsx)("span",{children:"After editing, please click the Save button on the right."}),(0,l.jsx)(d.ArrowRightBigIcon,{})]}),(0,l.jsx)("div",{children:(0,l.jsx)(t.$n,{variant:"primary",disabled:0===e.length,onClick:()=>{a({title:"Save Runtime Configurations ?",description:"Are you sure you want to save the following changes?",confirmText:"Save",confirmButtonOptions:{variant:"primary"},onConfirm:s,children:e.length>0?(0,l.jsxs)("pre",{className:"zt1q5wf",children:[(0,l.jsx)("p",{children:"{"}),e.map(({id:e,expiredValue:s,newValue:a})=>(0,l.jsxs)("p",{children:[" "," ",e,":"," ",(0,l.jsx)("span",{className:"zt1q5wg",children:JSON.stringify(s)}),(0,l.jsx)("span",{className:"zt1q5wh",children:JSON.stringify(a)}),","]},e)),(0,l.jsx)("p",{children:"}"})]}):"There is no change."})},children:"Save"})})]})};var m=a(55137);let h=({items:e,initialOpen:s=!1,title:a,currentModule:t,changeModule:i})=>{let[r,c]=(0,n.useState)(s),u=(0,n.useCallback)((e,s)=>{s?.preventDefault();let l=document.getElementById(e);l&&l.scrollIntoView({behavior:"smooth",block:"center"}),i?.(a)},[i,a]);return(0,l.jsxs)(m.bL,{className:"zt1q5w3",open:r,onOpenChange:c,children:[(0,l.jsxs)("div",{className:"zt1q5w4","data-active":a===t,children:[(0,l.jsx)(m.l9,{className:"zt1q5w5","data-open":r,children:(0,l.jsx)(d.ArrowDownSmallIcon,{})}),(0,l.jsx)("a",{className:o,href:`#${a}`,onClick:e=>u(a,e),children:a})]}),(0,l.jsx)("div",{className:"zt1q5w6",children:e.map((e,s)=>(0,l.jsx)(m.UC,{className:"zt1q5w7",onClick:()=>u(e),children:(0,l.jsx)("a",{className:o,href:`#${e}`,children:e})},s))})]})},p=({id:e,description:s,lastUpdatedTime:a,operation:t,children:i})=>{let r=new Date(a).toLocaleString();return(0,l.jsxs)("div",{id:e,className:"zt1q5w9",children:[(0,l.jsxs)("div",{className:"zt1q5wa",children:[(0,l.jsx)("div",{className:"zt1q5wc",children:s}),(0,l.jsx)("div",{children:(0,l.jsx)("code",{className:"zt1q5wd",children:e})}),(0,l.jsxs)("div",{className:"zt1q5we",children:["last updated at: ",r]})]}),(0,l.jsxs)("div",{className:"zt1q5wb",children:[t,i]})]})};var j=a(14486);let x=()=>{let{data:e}=(0,j.IT)({query:i.in}),s=(0,n.useMemo)(()=>e?.serverRuntimeConfig.sort((e,s)=>e.id.localeCompare(s.id))??[],[e]),a=(0,n.useMemo)(()=>{let e={};return s.forEach(s=>{e[s.module]||(e[s.module]=[]),e[s.module].push(s.key)}),Object.keys(e).sort((e,s)=>e.localeCompare(s)).map(s=>({moduleName:s,keys:e[s].sort((e,s)=>e.localeCompare(s))}))},[s]),l=(0,n.useMemo)(()=>{let e=new Map;return s.forEach(s=>{e.has(s.module)||e.set(s.module,[]),e.get(s.module)?.push(s)}),Array.from(e.entries()).map(([e,s])=>({moduleName:e,configs:s}))},[s]);return{serverRuntimeConfig:s,moduleList:a,configGroup:l}},v=(e,s,a)=>{switch(e){case"Boolean":return(0,l.jsx)(t.dO,{checked:s,onChange:a});case"String":return(0,l.jsx)(t.pd,{type:"text",minLength:1,value:s,onChange:a});case"Number":return(0,l.jsx)("div",{style:{width:"100%"},children:(0,l.jsx)(t.pd,{type:"number",value:s,onChange:a})});default:return null}},f=(e,s)=>typeof e==typeof s&&("object"==typeof e?JSON.stringify(e)===JSON.stringify(s):e===s),w=e=>"object"==typeof e?JSON.stringify(e):e.toString(),y=(e,s)=>{let a=null;switch(s){case"Boolean":a=!!e;break;case"String":a=e;break;case"Number":a=Number(e);break;case"Array":a=e.split(",");break;case"Object":a=JSON.parse(e)}return a};var g=a(4285),N=a(89679);let b=()=>{let{trigger:e,isMutating:s}=(0,N.n)({mutation:i.Ti}),a=(0,N.i)();return{trigger:(0,g.V)(async s=>{try{await e(s),await a(i.in),t.me.success({title:"Saved successfully",message:"Runtime configurations have been saved successfully."})}catch(e){t.me.error({title:"Failed to save",message:"Failed to save runtime configurations, please try again later."}),console.error(e)}},[a,e]),isMutating:s}},k=()=>{let{serverRuntimeConfig:e,moduleList:s,configGroup:a}=x(),[i,r]=(0,n.useState)(s[0].moduleName),{trigger:c}=b(),[d,o]=(0,n.useState)(e.reduce((e,s)=>(e[s.id]=s.value,e),{})),m=(0,n.useCallback)((e,s,a)=>{let l=y(s,a);o(s=>({...s,[e]:l}))},[]),j=(0,n.useMemo)(()=>e.filter(e=>!f(e.value,d[e.id])).map(e=>({id:e.id,key:e.key,expiredValue:e.value,newValue:d[e.id]})),[d,e]),g=(0,n.useCallback)(()=>{let e={};j.forEach(s=>{s.id&&void 0!==s.newValue&&(e[s.id]=s.newValue)}),c({updates:e})},[j,c]);return(0,l.jsx)("div",{className:"wif9yu0",children:(0,l.jsxs)("div",{className:"wif9yu1",children:[(0,l.jsx)("div",{className:"wif9yu2",children:s.map(e=>(0,l.jsx)(h,{items:e.keys,title:e.moduleName,currentModule:i,changeModule:r},e.moduleName))}),(0,l.jsxs)("div",{className:"wif9yu4",children:[(0,l.jsx)(u,{modifiedValues:j,onConfirm:g}),(0,l.jsxs)(t.yE.Root,{children:[(0,l.jsx)(t.yE.Viewport,{children:(0,l.jsx)("div",{className:"wif9yu3",children:a.filter(e=>e.moduleName===i).map(e=>{let{moduleName:s,configs:a}=e;return(0,l.jsxs)("div",{id:s,className:"wif9yu5",children:[(0,l.jsx)("div",{className:"wif9yu6",children:s}),a?.map(e=>{let{id:s,type:a,description:t,updatedAt:i}=e,r=f(e.value,d[s]),n=w(e.value),c=w(d[s]);return l.jsx(p,{id:s,description:t,lastUpdatedTime:i,operation:v(a,d[s],e=>m(s,e,a)),children:l.jsxs("div",{style:{opacity:r?0:1},children:[n," => ",c]})},s)})]},s)})})}),(0,l.jsx)(t.yE.Scrollbar,{})]})]})]})})},C=()=>{let{data:e}=(0,j.IT)({query:i.VM}),{jumpTo404:s}=(0,c.P)(),a=e?.currentUser?.features;return a&&a.includes(r.lo.Admin)?(0,l.jsx)(k,{}):(s(),null)}}}]); //# sourceMappingURL=chunk.2884.6291aecd.js.map