import{r as c,f as p,i as f,d as y,j as s,a as l,b8 as d,c as j,bS as N,a3 as D,a5 as P,L as v,cN as O,bX as L,bg as z,bo as A,t as b,W as C,aJ as g,bx as B,by as R,bJ as S,bI as $,D as I}from"./index-_eM6l4Nf.js";import{s as J,a as W}from"./schematised-tags.selectors-WK3AUml0.js";import{p as w}from"./utils-Cwnan-GL.js";import"./complement-CE-nEpWn.js";const q=(e,t,n)=>{const o=c.useMemo(()=>e.map(()=>[p,p,p,f,f]),[e]),r=c.useMemo(()=>e.map(i=>[{children:i.name},{children:`${Object.keys(i.properties).length} fields`,primary:!0},{children:i.description},{intent:"ghost",icon:y.copy,mr:"-20px",tooltip:"make a copy",onClick:a=>{n(i.name),a.stopPropagation()}},{intent:"ghost",icon:y.eye,tooltip:"View",onClick:()=>t(i.name)}]),[e,n,t]);return c.useMemo(()=>[o,r],[o,r])},E=({name:e,description:t,required:n})=>s.jsxs(l,{flexDirection:"column",alignSelf:"start",children:[s.jsx(p,{children:s.jsxs(l,{gap:"8px",justifyContent:"space-between",children:[e,n&&s.jsx(d,{value:"required",variant:"label"})]})}),t&&s.jsx(j,{sx:{mt:"8px"},gray:!0,children:t})]}),V=({enum:e,type:t,items:n})=>s.jsxs(l,{flexDirection:"row",justifyContent:"end",flex:"1",gap:"8px",children:[e&&s.jsx(l,{gap:"2px",flex:"0 1 auto",width:"300px",flexWrap:"wrap",children:e.map(o=>s.jsx(d,{value:o,variant:"notice"}))}),s.jsx(d,{value:t==="array"?`Array of ${w.getByValue((n==null?void 0:n.type)||"")}`:w.getByValue(t)})]}),H=e=>{const t=c.useMemo(()=>e?Object.keys(e.properties).map(()=>[E,V]):[],[e]),n=c.useMemo(()=>e?Object.entries(e.properties).map(([o,r])=>{var i;return[{name:o,description:r.description,required:(i=e.required)==null?void 0:i.includes(o)},r]}):[],[e]);return c.useMemo(()=>[t,n],[t,n])},X={tbody:{borderStyle:"solid",borderWidth:"1px",borderColor:"grayShade2"},gap:"15px",p:"20px"},_=({data:e,handleToggle:t,isOpen:n})=>{const[o,r]=H(e),{hasAdditionalRules:i,hasNestedTypes:a}=e??{},u=c.useMemo(()=>JSON.stringify(JSON.parse((e==null?void 0:e.value)??"{}"),null,4),[e==null?void 0:e.value]);return s.jsx(N,{isOpen:n,onClose:t,size:"lg",hasCloseButton:!1,children:s.jsxs(l,{flexDirection:"column",width:"100%",sx:X,children:[s.jsx(D,{type:P.neutral,content:"Tag schemas are immutable."}),s.jsx(p,{fontSize:"18px",children:e==null?void 0:e.name}),i||a?s.jsx(v,{maxHeight:"calc(100vh - 245px)",overflowY:"scroll",fontSize:"13px",children:s.jsx(O,{readOnly:!0,copyButton:!0,content:u,title:"tag schema",language:"json"})}):s.jsx(L,{middleColumn:0,groupComponents:o,groupProps:r,sx:{td:{verticalAlign:"top",":first-child":{pr:"8px"},":last-child":{pl:"0px"}}}})]})})},F={table:{td:{px:"10px",whiteSpace:"nowrap"},tr:{cursor:"pointer"},"td:nth-of-type(1)":{pl:"20px"},"td:nth-of-type(4)":{pr:"20px"},svg:{fontSize:"14px"}}},T={pb:0},G=({data:e})=>{const[t,n]=c.useState(),{state:o}=z(),r=A(),i=c.useCallback(()=>{r(b.settings.schematisedTags.create)},[r]),a=c.useCallback(m=>{const h=e.find(({name:x})=>x===m);n(h)},[e]),u=c.useCallback(m=>{const h=e.find(({name:x})=>x===m);r(b.settings.schematisedTags.create,{state:{selected:h}})},[e,r]),[k,M]=q(e,a,u);return e.length?s.jsxs(s.Fragment,{children:[s.jsx(_,{data:t,isOpen:!!t,handleToggle:()=>n(void 0)}),s.jsxs(C,{title:"All tag schemas",contentProps:T,actions:o?s.jsx(g,{p:0,intent:"inline",href:o.pathname,children:o.text}):null,children:[s.jsxs(l,{alignItems:"center",justifyContent:"space-between",pb:"15px",children:[s.jsxs(l,{children:[s.jsx(p,{primary:!0,children:e.length}),s.jsx(j,{bold:!0,ml:"5px",children:e.length>1?"tag schemas":"tag schema"})]}),s.jsx(l,{children:s.jsx(g,{onClick:i,children:"New tag schema"})})]}),s.jsx(v,{mx:"-20px",sx:F,children:s.jsx(L,{onRowClick:(m,h)=>{const{name:x}=e[h];a(x)},middleColumn:2,groupComponents:k,groupProps:M})})]})]}):s.jsx(C,{title:"All tag schemas",contentProps:T,maxHeight:"calc(100vh - 215px)",children:s.jsxs(l,{alignItems:"center",justifyContent:"center",flexDirection:"column",height:"190px",children:[s.jsx(j,{fontSize:"18px",gray:!0,mb:"20px",children:"There are no tag schema defined"}),s.jsx(g,{onClick:i,children:"New tag schemas"})]})})},Y=()=>{B(R.schematisedTagsSettings);const e=S(J).sort((o,r)=>o.name.localeCompare(r.name)),t=$();c.useEffect(()=>{t.schematisedTags.fetch()},[t]);const n=S(W);return n?s.jsx(I,{}):s.jsx(l,{flexGrow:1,flexDirection:"column",children:!n&&s.jsx(G,{data:e})})},ee=c.memo(Y);export{ee as default};
