import{dk as p,a7 as T,a9 as V,r as s,am as I,an as L,j as e,aT as v,K as D,a_ as N,a as t,b3 as g,aG as C,ax as k,O as H,aH as O,ad as R,bc as a,f as y,V as b,Z as j,bp as U,cC as M,aX as q,W as B,dl as F,dm as $,bb as G,dn as K,z as Q,aY as W}from"./index-d6499a22.js";import{u as A,a as X}from"./index-d13f0052.js";const E=i=>{switch(i){case"Hops user":return p.USER;case"Hops admin":return p.ADMIN;case"Not authenticated":return p.NOTAUTHENTICATED;default:return p.ADMIN}},S=i=>{switch(i){case p.USER:return"Hops user";case p.ADMIN:return"Hops admin";default:return"Not authenticated"}},Z=T().shape({name:V().required(),value:V().required()}),z=({setNewConfiguration:i})=>{const[x,l]=s.useState(p.USER),[r,m]=s.useState(!1),{register:o,handleSubmit:h,formState:{errors:c}}=I({resolver:L(Z)}),[d,{isLoading:f}]=A(),w=s.useCallback(async u=>{const n={...u,visibility:x,hide:r};d(n),i(!1)},[d,x,r,i]);return e.jsxs(e.Fragment,{children:[e.jsx(v,{intent:"ghost",onClick:()=>{i(!1)},children:"⇽ all configurations"}),e.jsx(D,{maxHeight:"700px",title:"New configuration",children:f?e.jsx(N,{}):e.jsxs(e.Fragment,{children:[e.jsxs(t,{children:[e.jsxs(t,{flexDirection:"column",width:1/4,children:[e.jsx(g,{mb:"10px",children:"Name"}),e.jsx(C,{width:"90%",placeholder:"configuration name",...o("name"),...k("name",c)})]}),e.jsxs(t,{flexDirection:"column",width:3/4,children:[e.jsx(g,{mb:"10px",children:"Value"}),e.jsx(C,{width:"100%",placeholder:"configuration value",...o("value"),...k("value",c)})]})]}),e.jsxs(t,{flexDirection:"column",mt:"20px",children:[e.jsx(H,{children:e.jsx(g,{children:"Visibility"})}),e.jsx(H,{mt:"15px",children:e.jsx(O,{pr:"20px",...o("visibilityStr"),onChange:u=>{l(E(u))},options:["Hops user","Hops admin","Not authenticated"],value:S(x),flexDirection:"row"})})]}),e.jsx(t,{mt:"20px",children:e.jsx(R,{label:"Hide the value",checked:r,onChange:()=>{m(u=>!u)}})}),e.jsx(t,{mt:"20px",justifyContent:"right",children:e.jsxs(t,{flexDirection:"row",children:[e.jsx(v,{intent:"secondary",mr:"10px",onClick:()=>{i(!1)},children:"Back"}),e.jsx(v,{onClick:h(w),children:"Create Configuration"})]})})]})})]})},P=s.memo(z),Y=({conf:i})=>{const[x,l]=s.useState(!1),[r,m]=s.useState(i.value),[o,h]=s.useState(i.visibility),[c,d]=s.useState(!1),[f,{isLoading:w}]=A();s.useEffect(()=>{m(i.value),h(i.visibility)},[i.value,i.visibility]);const u=s.useCallback(async()=>{const n={name:i.name,visibility:o,value:r,hide:i.hide};await f(n).unwrap(),l(!1)},[i.name,i.hide,o,r,f]);return x?e.jsxs(a.Row,{children:[e.jsx(a.Cell,{children:e.jsx(y,{children:i.name})}),e.jsx(a.Cell,{children:e.jsx(U,{px:"0px",width:"120px",value:[S(o)],options:["Hops user","Hops admin","Not authenticated"],appendToBody:!0,placeholder:"",onChange:n=>{n.length>0&&h(E(n[0]))}})}),e.jsx(a.Cell,{pr:"10px",children:e.jsx(C,{width:"380px",defaultValue:i.value,onChange:n=>m(n.target.value)})}),e.jsx(a.Cell,{pl:"0px",children:e.jsxs(t,{flexDirection:"row",children:[e.jsx(b,{intent:"ghost",icon:j.cross,tooltip:"cancel",onClick:()=>{l(!1),h(i.visibility)}}),w?e.jsx(M,{ml:"10px",mt:"5px"}):e.jsx(b,{intent:"ghost",icon:j.validate,tooltip:"save",onClick:u})]})})]}):e.jsxs(a.Row,{children:[e.jsx(a.Cell,{children:e.jsx(y,{children:i.name})}),e.jsx(a.Cell,{children:e.jsx(y,{px:"0px",width:"120px",children:S(i.visibility)})}),e.jsx(a.Cell,{pr:"10px",children:e.jsx(C,{width:"380px",value:i.value,variant:"white",type:i.hide&&!c?"password":"text",disabled:!0,sx:{border:"none",fontWeight:"700"}})}),e.jsx(a.Cell,{pl:"0px",children:e.jsxs(t,{flexDirection:"row",children:[i.hide&&e.jsx(b,{icon:j.eye,intent:"ghost",tooltip:"show",onClick:()=>{d(n=>!n)}}),e.jsx(b,{icon:j.edit,intent:"ghost",tooltip:"edit",onClick:()=>{l(!0)}})]})})]})},_=s.memo(Y),J=()=>{q(W.configuration);const{currentData:{items:i}={items:[]},isLoading:x}=X(),[l,r]=s.useState(""),m=s.useCallback(({target:d})=>{r(d.value)},[r]),[o,h]=s.useState(!1),c=s.useMemo(()=>B(K(Q("name")),F($(G(l),"name")))(i??[]),[l,i]);return x?e.jsx(N,{}):o?e.jsx(P,{setNewConfiguration:h}):e.jsxs(D,{maxHeight:"calc(100vh - 230px)",contentProps:{pb:0,overflow:"auto"},title:"All Configuration variables",actions:e.jsx(v,{onClick:()=>{h(!0)},children:"New Variable"}),children:[e.jsx(t,{mb:"10px",children:e.jsxs(t,{width:4/5,children:[e.jsx(g,{color:"primary",mr:"5px",children:c.length}),e.jsxs(g,{children:["variable",c.length>1?"s":""]})]})}),e.jsx(t,{py:"5px",children:e.jsx(C,{width:"100%",value:l,icon:j.glass,placeholder:"Find variable by name",onChange:m})}),c&&e.jsx(a,{legend:["name","visibility","value",""],middleColumn:1,children:c.map(d=>e.jsx(_,{conf:d},d.name))})]})},se=s.memo(J);export{se as default};
