import{r as i,g as l,A as M,z as P,j as s,Q as c,x as g,be as f,ba as y,o as d,cR as k,bh as w,a3 as D,a4 as N,ca as O,aS as z,b as A,E as S,aU as u,aY as R,b3 as b,cU as E,b1 as V,cV as $,a$ as v,aZ as B}from"./index-ea7817a2.js";import{p as C}from"./utils-4af057bd.js";const q=(e,t)=>{const r=i.useMemo(()=>e.map(()=>[l,l,l,M]),[e]),o=i.useMemo(()=>e.map(n=>[{children:n.name},{children:`${Object.keys(n.properties).length} fields`,primary:!0},{children:n.description},{intent:"ghost",icon:P.eye,tooltip:"View",onClick:()=>t(n.name)}]),[e,t]);return i.useMemo(()=>[r,o],[r,o])},Q=({name:e,description:t})=>s.jsxs(c,{flexDirection:"column",children:[s.jsx(l,{children:e}),t&&s.jsx(g,{sx:{mt:"8px"},gray:!0,children:t})]}),H=({required:e,value:t,hasDescription:r})=>{var o;return s.jsxs(c,{flexDirection:"row",...r&&{mt:"-12px"},children:[e&&s.jsx(f,{value:"required",variant:"label",mr:"8px"}),s.jsx(f,{value:t.type==="array"?`Array of ${C.getByValue(((o=t.items)==null?void 0:o.type)||"")}`:C.getByValue(t.type)})]})},I=e=>{const t=i.useMemo(()=>e?Object.keys(e.properties).map(()=>[Q,H]):[],[e]),r=i.useMemo(()=>e?Object.entries(e.properties).map(([o,n])=>[{name:o,description:n.description},{value:n,required:e.required.includes(o),hasDescription:n==null?void 0:n.description}]):[],[e]);return i.useMemo(()=>[t,r],[t,r])},J={tbody:{borderStyle:"solid",borderWidth:"1px",borderColor:"grayShade2"}},U=({data:e,handleToggle:t,isOpen:r})=>{const[o,n]=I(e),{hasAdditionalRules:a,hasNestedTypes:p}=e??{},m=i.useMemo(()=>JSON.stringify(JSON.parse((e==null?void 0:e.value)??"{}"),null,4),[e==null?void 0:e.value]);return s.jsx(y,{isOpen:r,onClose:t,headerSummary:s.jsxs(d,{width:"100%",sx:J,children:[s.jsx(l,{fontSize:"18px",mb:"15px",children:e==null?void 0:e.name}),a||p?s.jsx(d,{maxHeight:"340px",overflowY:"scroll",fontSize:"13px",children:s.jsx(k,{readOnly:!0,copyButton:!0,content:m,title:"tag schema",language:"json"})}):s.jsx(w,{middleColumn:0,groupComponents:o,groupProps:n})]}),children:s.jsx(y.Section,{title:"",children:s.jsx(D,{type:N.neutral,content:"Tag schemas are immutable."})})})},Y={table:{td:{px:"10px",whiteSpace:"nowrap"},"td:nth-of-type(1)":{pl:"20px"},"td:nth-of-type(4)":{pr:"20px"},svg:{fontSize:"14px"}}},T={pb:0},F=({data:e})=>{const[t,r]=i.useState(),{state:o}=O(),n=z(),a=i.useCallback(()=>{n(A.settings.schematisedTags.create)},[n]),p=i.useCallback(j=>{const h=e.find(({name:x})=>x===j);r(h)},[e]),[m,L]=q(e,p);return e.length?s.jsxs(s.Fragment,{children:[s.jsx(U,{data:t,isOpen:!!t,handleToggle:()=>r(void 0)}),s.jsxs(S,{title:"All tags schemas",contentProps:T,actions:o?s.jsx(u,{p:0,intent:"inline",href:o.pathname,children:o.text}):null,children:[s.jsxs(c,{alignItems:"center",justifyContent:"space-between",pb:"15px",children:[s.jsxs(c,{children:[s.jsx(l,{primary:!0,children:e.length}),s.jsx(g,{bold:!0,ml:"5px",children:e.length>1?"tag schemas":"tag schema"})]}),s.jsx(c,{children:s.jsx(u,{onClick:a,children:"New tag schema"})})]}),s.jsx(d,{mx:"-20px",sx:Y,children:s.jsx(w,{onRowClick:(j,h)=>{const{name:x}=e[h];p(x)},middleColumn:2,groupComponents:m,groupProps:L})})]})]}):s.jsx(S,{title:"All tag schemas",contentProps:T,maxHeight:"calc(100vh - 215px)",children:s.jsxs(c,{alignItems:"center",justifyContent:"center",flexDirection:"column",height:"190px",children:[s.jsx(g,{fontSize:"18px",gray:!0,mb:"20px",children:"There are no tag schema defined"}),s.jsx(u,{onClick:a,children:"New tag schemas"})]})})},G=()=>{R(B.schematisedTagsSettings);const e=b(E).sort((o,n)=>o.name.localeCompare(n.name)),t=V();i.useEffect(()=>{t.schematisedTags.fetch()},[t]);const r=b($);return r?s.jsx(v,{}):s.jsx(c,{flexGrow:1,flexDirection:"column",children:!r&&s.jsx(F,{data:e})})},Z=i.memo(G);export{Z as default};
