import{r as i,f as p,i as j,C as f,j as s,$ as l,c as d,b8 as b,bR as P,a3 as $,a5 as N,L,cM as O,bW as k,bg as R,bo as v,q as y,b as C,b1 as g,bw as z,bx as B,bI as S,bH as q,D as A}from"./index-46ma1THH.js";import{s as I,a as E}from"./schematised-tags.selectors-WK3AUml0.js";import{p as T}from"./utils-B4WkaoPO.js";import"./complement-Cl658Mix.js";const H=(e,t,r)=>{const o=i.useMemo(()=>e.map(()=>[p,p,p,j,j]),[e]),n=i.useMemo(()=>e.map(c=>[{children:c.name},{children:`${Object.keys(c.properties).length} fields`,primary:!0},{children:c.description},{intent:"ghost",icon:f.copy,mr:"-20px",tooltip:"make a copy",onClick:a=>{r(c.name),a.stopPropagation()}},{intent:"ghost",icon:f.eye,tooltip:"View",onClick:()=>t(c.name)}]),[e,r,t]);return i.useMemo(()=>[o,n],[o,n])},V=({name:e,description:t})=>s.jsxs(l,{flexDirection:"column",children:[s.jsx(p,{children:e}),t&&s.jsx(d,{sx:{mt:"8px"},gray:!0,children:t})]}),_=({required:e,value:t,hasDescription:r})=>{var o;return s.jsxs(l,{flexDirection:"row",...r&&{mt:"-12px"},children:[e&&s.jsx(b,{value:"required",variant:"label",mr:"8px"}),s.jsx(b,{value:t.type==="array"?`Array of ${T.getByValue(((o=t.items)==null?void 0:o.type)||"")}`:T.getByValue(t.type)})]})},F=e=>{const t=i.useMemo(()=>e?Object.keys(e.properties).map(()=>[V,_]):[],[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"},gap:"15px",p:"20px"},W=({data:e,handleToggle:t,isOpen:r})=>{const[o,n]=F(e),{hasAdditionalRules:c,hasNestedTypes:a}=e??{},u=i.useMemo(()=>JSON.stringify(JSON.parse((e==null?void 0:e.value)??"{}"),null,4),[e==null?void 0:e.value]);return s.jsx(P,{isOpen:r,onClose:t,size:"lg",hasCloseButton:!1,children:s.jsxs(l,{flexDirection:"column",width:"100%",sx:J,children:[s.jsx($,{type:N.neutral,content:"Tag schemas are immutable."}),s.jsx(p,{fontSize:"18px",children:e==null?void 0:e.name}),c||a?s.jsx(L,{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(k,{middleColumn:0,groupComponents:o,groupProps:n})]})})},G={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"}}},w={pb:0},Q=({data:e})=>{const[t,r]=i.useState(),{state:o}=R(),n=v(),c=i.useCallback(()=>{n(y.settings.schematisedTags.create)},[n]),a=i.useCallback(x=>{const m=e.find(({name:h})=>h===x);r(m)},[e]),u=i.useCallback(x=>{const m=e.find(({name:h})=>h===x);n(y.settings.schematisedTags.create,{state:{selected:m}})},[e,n]),[M,D]=H(e,a,u);return e.length?s.jsxs(s.Fragment,{children:[s.jsx(W,{data:t,isOpen:!!t,handleToggle:()=>r(void 0)}),s.jsxs(C,{title:"All tag schemas",contentProps:w,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(d,{bold:!0,ml:"5px",children:e.length>1?"tag schemas":"tag schema"})]}),s.jsx(l,{children:s.jsx(g,{onClick:c,children:"New tag schema"})})]}),s.jsx(L,{mx:"-20px",sx:G,children:s.jsx(k,{onRowClick:(x,m)=>{const{name:h}=e[m];a(h)},middleColumn:2,groupComponents:M,groupProps:D})})]})]}):s.jsx(C,{title:"All tag schemas",contentProps:w,maxHeight:"calc(100vh - 215px)",children:s.jsxs(l,{alignItems:"center",justifyContent:"center",flexDirection:"column",height:"190px",children:[s.jsx(d,{fontSize:"18px",gray:!0,mb:"20px",children:"There are no tag schema defined"}),s.jsx(g,{onClick:c,children:"New tag schemas"})]})})},X=()=>{z(B.schematisedTagsSettings);const e=S(I).sort((o,n)=>o.name.localeCompare(n.name)),t=q();i.useEffect(()=>{t.schematisedTags.fetch()},[t]);const r=S(E);return r?s.jsx(A,{}):s.jsx(l,{flexGrow:1,flexDirection:"column",children:!r&&s.jsx(Q,{data:e})})},ee=i.memo(X);export{ee as default};
