@datawheel/bespoke 0.8.0-rc.7 → 0.8.0-rc.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cms.js CHANGED
@@ -87,12 +87,12 @@ return {
87
87
  dignissim interdum eros. Curabitur non tincidunt libero.
88
88
  Suspendisse quis nibh in massa tincidunt feugiat sit amet vitae nisl.
89
89
  In pulvinar sapien ut tincidunt volutpat. Donec auctor tellus eu augue feugiat,
90
- a viverra sapien pulvinar.`,style:o,append:t?jsx(kt,{content:t,style:{display:"inline-block",verticalAlign:"bottom"}}):jsx(Fragment,{}),isPreview:!0})}var nC=N(()=>{d();Yr();ft();});function Mf({subtitle:e,title:t,value:o,tooltip:r,settings:n,_iconType:i,_iconVariant:a,_icon:s,_iconRadius:l,_iconSize:u,_iconPadding:c}){let p=t||"<span class='cr-block-placeholder'>Title</span>",m=o||"<span class='cr-block-placeholder'>Big Stat</span>",f=e||"<span class='cr-block-placeholder'>Subtitle</span>",g=n&&n.align||"left";return jsx("div",{className:"bespoke-Stat-root",children:jsxs(Group,{className:"bespoke-StatGroup-wrapper",position:Io(g),children:[i!=="none"&&i&&jsx(Et,{blockType:"stat",iconType:i,iconVariant:a,iconRadius:l,iconSize:u,icon:s,iconPadding:c}),jsxs("div",{className:"bespoke-Stat-wrapper",children:[jsx(ye,{component:"div",size:"md",html:p,style:n,isPreview:!0}),jsx(ye,{component:"div",size:"xl",html:m,style:n,isPreview:!0}),jsx(ye,{component:"div",size:"sm",html:f,style:n,isPreview:!0})]},"stat"),r&&jsx(kt,{content:r})]})})}var aC=N(()=>{d();Yr();Ti();ft();_t();});function Bf({subtitle:e,tooltip:t,settings:o}){let r=lt(e)||"<span class='cr-block-placeholder'>Small subtitle.</span>",n=o&&o.align?o.align:"left";return jsxs(Group,{spacing:"sm",position:Io(n),children:[jsx(ye,{size:"sm",html:r,isPreview:!0}),t&&jsx(kt,{content:t,style:{display:"inline-flex"}})]})}var lC=N(()=>{d();Yr();xn();ft();_t();});function Df({title:e,tooltip:t,_iconType:o,_iconVariant:r,_icon:n,settings:i,_iconRadius:a,_iconSize:s,_iconPadding:l}){let u=lt(e)||"Title",c=i&&i.order?parseInt(i.order,10):1,p=c<=6?c:1,m=!!(i&&i.search&&i.search!=="off"),f=i&&i.search?i.search:"",g=i&&i.align?i.align:"left";return jsxs(Group,{spacing:"sm",position:Io(g),children:[o!=="none"&&o&&jsx(Et,{blockType:"title",iconType:o,iconVariant:r,iconRadius:a,iconSize:s,icon:n,iconPadding:l}),jsx(ye,{component:"h",order:p,style:i,html:u,isPreview:!0}),m&&jsx(Tooltip,{label:`Click will open '${f}' report search`,children:jsx(ActionIcon,{variant:"light",children:jsx(IconSearch,{size:20})})}),t&&jsx(kt,{content:t})]})}var cC=N(()=>{d();Yr();xn();Ti();ft();_t();});function zf(e){let{id:t,type:o,defaultValue:r,options:n,name:i,settings:a,hideLabel:s,component:l,resetSectionVars:u,section:c}=e,p=useDispatch(),m=useContext(_e),f=$(M=>M.status.query),{sectionVariables:g,resetSectionVariables:h}=Ze(c),b=G1(t),v=useMemo(()=>f[b]||r,[f[b],o,r]),C=useMemo(()=>H1(f[b],r),[f[b],o,r]),[R,y]=useState(n?.map(M=>({value:M.id,label:M.label,imageUrl:M.imageUrl}))||[]),[A,S]=useState((n||[]).map(M=>M.id).join("-"));useEffect(()=>{let M=n.map(w=>`${w.label}|${w.id}`).join("-");if(A===M)return;S(M);let z=n.map(w=>({value:w.id,label:w.label}));y(z);let I=o===mt.SINGLE?v:C;ti(o,I,n)||p(Ud(m,b));},[JSON.stringify(n),t]);let E=()=>{u==="true"&&g&&h();},L=M=>{p(pi(m,b,M)),E();},P=M=>{p(pi(m,b,M.join())),E();},D=s==="true"?jsx(Fragment,{}):jsx(ye,{component:"div",html:i,size:"sm",style:a,isPreview:!0});return R.length===0?jsx(Text,{c:"dimmed",size:"xs",children:"No options defined yet. Selector hidden in report."}):R.length===1?jsxs(Text,{c:"dimmed",size:"xs",children:["Only one option defined. Selector hidden in report. ",JSON.stringify(R)]}):{[mt.SINGLE]:l===bc.SEGMENTED_CONTROL?jsxs("div",{children:[D,jsx(SegmentedControl,{data:R,value:R.map(M=>M.value).includes(v)?v:"",onChange:L,fullWidth:!0})]}):jsx(Select,{label:D,data:R,value:v,onChange:L,itemComponent:j1,styles:{label:{display:s==="true"?"none":"block"}}}),[mt.MULTI]:jsx(MultiSelect,{label:D,data:R,value:C,onChange:P,styles:{label:{display:s==="true"?"none":"block"}}})}[o]}var G1,H1,j1,dC=N(()=>{d();hr();vc();ge();ie();Lt();ft();he();G1=e=>`selector${e}id`,H1=(e,t)=>e&&typeof e=="string"?e.split(","):t,j1=forwardRef(function({imageUrl:t,label:o,...r},n){return jsx("div",{ref:n,...r,children:jsxs(Group,{noWrap:!0,children:[t&&jsx(Box,{component:"img",w:25,h:25,src:t}),jsx("div",{children:jsx(Text,{size:"sm",children:o})})]})})});});function tz({outputVariables:e,status:t,hasAPI:o=!1,debug:r,type:n}){let[i,a]=useState(!1),s=o&&!Object.keys(e).length&&!t.error,l=Object.keys(e).some(c=>c.startsWith("_"));return r?s?jsxs(Stack,{align:"center",children:[jsx(Loader,{}),jsxs(Text,{size:"sm",children:["Loading ",{type:n}]})]}):jsxs(Fragment,{children:[jsx(Divider,{label:"Output Variables",labelPosition:"center"}),l&&jsx(Switch,{label:"Show internal variables",mb:"xs",size:"xs",checked:i,onChange:c=>a(c.currentTarget.checked)}),jsx(tr,{variables:e,showInternal:i})]}):jsx(Center,{children:jsx(Badge,{color:"gray",variant:"outline",children:n.toUpperCase()},"type")})}var Ff,mC=N(()=>{d();Ba();Ff=tz;});function $f(e){let{alt:t,src:o,desc:r,title:n,settings:i,...a}=e,s=lt(t),l=lt(o),u=lt(r),c=jsx("img",{src:l,alt:s,style:a}),p=i&&i.align?String(i.align):"left";return (u&&u.length||n&&n.length)&&(c=jsxs(Stack,{className:"bespoke-Image-wrapper",align:vr(p),spacing:"sm",children:[n&&jsx(ye,{component:"p",html:n,style:i,isPreview:!0}),c,r&&jsx(ye,{component:"p",size:"sm",html:r,style:i,isPreview:!0})]})),l&&s?c:jsx(Center,{mih:100,bg:"white",children:jsx(Badge,{color:"gray",variant:"outline",children:"IMAGE"},"type")})}var fC=N(()=>{d();xn();ft();_t();});function Hf({headings:e,settings:t}){let{min:o="1",max:r="6",icons:n="yes"}=t||{},i=wa(parseInt(o,10),parseInt(r,10),e),a=n==="yes",s=Fa(t&&t.align?String(t.align):"left"),l=u=>!u||!u?.length?null:jsx(Fragment,{children:u.map(c=>jsxs(Fragment$1,{children:[jsx(Menu.Item,{children:jsx(Anchor,{href:`#bespoke-title-${c.id}`,children:jsxs(Group,{spacing:"sm",children:[a&&jsx(Et,{...c.iconProps,iconSize:"sm"}),jsx(Text,{dangerouslySetInnerHTML:{__html:c.label}})]})})},c.id),jsx(Box,{pl:"xs",children:l(c.children)})]},c.id))});return jsx(Box,{pos:"relative",children:jsxs(List,{sx:u=>({display:"flex",gap:u.spacing.md,justifyContent:s,listStyleType:"none"}),children:[i?.map(u=>jsx(List.Item,{children:jsxs(Menu,{trigger:"hover",openDelay:100,closeDelay:400,children:[jsx(Menu.Target,{children:jsx(Anchor,{href:`#bespoke-title-${u.id}`,children:jsxs(Group,{spacing:"sm",noWrap:!0,children:[a&&jsx(Et,{blockType:"nav",...u.iconProps,iconSize:"sm",iconPadding:"2"}),jsx(Text,{dangerouslySetInnerHTML:{__html:u.label}})]})})}),u?.children?.length?jsx(Menu.Dropdown,{children:l(u.children)}):null]})},u.id)),!i||i.length===0&&jsx(List.Item,{children:jsx(Text,{color:"dimmed",children:"- Include some titles as inputs to see the Nav component -"})})]})})}var yC=N(()=>{d();bi();Ti();_t();});function Wf(e){let{related_reports:t,settings:o}=e;if(!t?.length)return jsx(Text,{children:"There are no available members related to your current selection and report."});let r=Fa(o&&o.align?String(o.align):"left");return jsx(List,{sx:()=>({display:"flex",justifyContent:r}),children:t.map(n=>jsx(List.Item,{children:n.name},n.content_id))})}var SC=N(()=>{d();_t();});function qf({id:e,label:t,settings:o,showIcon:r,fullWidth:n,showWhenDisabled:i}){let a=He(e).data,{sectionVariables:s,resetSectionVariables:l}=Ze(a?.section_id),u=!!Object.keys(s).length,c=vr(o&&o.align?o.align:"left");return jsxs(Stack,{align:c,children:[!u&&!i&&jsx(Text,{size:"xs",ta:o?.align||"left",children:"Reset button will not be shown on its disabled state"}),jsx(Button,{onClick:()=>l(),disabled:!u,fullWidth:n,children:jsxs(Group,{align:"center",children:[t,r&&jsx(IconRefresh,{})]})})]})}var TC=N(()=>{d();he();he();_t();});function Yf({settings:e,label:t,showIcon:o,position:r="center"}){let n=e&&e.search?e.search:"";return jsxs(Group,{position:r,children:[jsx(Tooltip,{label:`Click will open '${n}' report search`,children:jsx(Button,{children:jsxs(Group,{align:"center",children:[t||"Comparison Button",o&&jsx(IconPlus,{})]})})}),jsx(ActionIcon,{variant:"light",children:jsx(IconSearch,{size:20})})]})}var EC=N(()=>{d();});function Xf({columns:e=[],id:t,data:o=[],tableProps:r={}}){let[n,i]=useState({}),{initialState:a}=r,s=a?.pagination?.pageIndex,l=a?.pagination?.pageSize,u=`table-${[t,s,l].filter(g=>g).join("-")}`,c=useMemo(()=>e.map(g=>g.accessorKey),[e]),p=useMemo(()=>o.filter(g=>typeof g=="object"&&g!==null&&!Array.isArray(g)&&Object.keys(g).some(h=>c.includes(h))),[c,o]),m=useMemo(()=>e.map(g=>({...g,Cell:({renderedCellValue:h})=>jsx(ye,{html:`${h}`,isPreview:!0}),filterFn:"contains"})),[e]),f=Sa();return useEffect(()=>{(async()=>{try{let h=f||"en",b=`${h.toUpperCase()}`,v=await import(`mantine-react-table/locales/${h}.js`);i(v[`MRT_Localization_${b}`]);}catch(h){console.error("Error loading translations:",h);}})();},[f]),createElement(MantineReactTable,{...r,autoResetPageIndex:!1,columns:m,data:p,enableColumnFilterModes:!0,enableFilterMatchHighlighting:!1,globalFilterFn:"contains",key:u,layoutMode:"grid",localization:n,state:{...r.state,isFullScreen:!1}})}var RC=N(()=>{d();ft();he();});function Qf({label:e,url:t,settings:o}){let{align:r}=o;return jsx(Group,{position:r,grow:r==="justify",children:jsx(Button,{component:"a",target:"_blank",href:t||"",children:e||"Button"})})}var IC=N(()=>{d();});function eg(e){let t=useDispatch(),o=useContext(_e),r=$(ee=>ee.status.query),n=Uz(e.id),i=useMantineTheme(),{allLabel:a,colorKey:s,data:l,defaultValue:u,defaultValueType:c,iconKey:p,levels:m,limit:f,placeholder:g,searchIndexKey:h,searchIndexSeparator:b,resetSectionVars:v,section:C}=e,[R,y]=useState(!1),[A,S]=useState(!0),[E,L]=useState(""),[P,D]=useState(!1),[M,z]=useState([""].slice(1)),{sectionVariables:I,resetSectionVariables:w}=Ze(C),O=useMemo(()=>Gz(r[`${n}-value`],u),[r,u,n]),_=useMemo(()=>r[`${n}-type`]||c,[r,c,n]),H=useCallback(()=>{v==="true"&&I&&w();},[v,I,w]),G=useCallback(ee=>{H(),t(pi(o,`${n}-value`,ee.join()));},[t,o,n,H]),te=useCallback(ee=>{H(),t(pi(o,`${n}-type`,ee));},[t,o,n,H]),j=useRef(null),W=useRef(!1),q=useRef(!!f&&f<O.length),V=M.length,K=m[V],Z=M.filter(Boolean);M.length>0&&Z.length===0&&Z.push(`${a} ${K?.label}`),useEffect(()=>{let ee=()=>{S(!0);};return window.addEventListener("touchmove",ee),()=>{window.removeEventListener("touchmove",ee);}},[]);let F=useMemo(()=>Vz(l,m,s,p,h,b),[s,l,p,m,h,b]),J=useMemo(()=>{let ee=Fz(E),Ce=Array.from($z(F,ee)).reverse();return P?Ce:M.reduce((Y,B)=>Y.filter(X=>!B||X.searchindex.indexOf(B)>-1),Ce.filter(Y=>Y.type===K?.value))},[K,F,E,P,M]),[se,re]=useState(-1),ce=Math.min(se,J.length-1),fe=useCallback(ee=>{let Ce=M.concat(ee);P&&D(!1),z(Ce);},[P,M]),Ie=useCallback(()=>{let ee=M.slice(0,V-1);P&&D(!1),z(ee);},[P,M,V]),xe=useCallback(ee=>{L(ee.currentTarget.value),!q.current&&l.length>0&&y(!0);},[l,L,q,y]),U=useCallback(()=>{L(""),G([]),j.current?.focus(),f&&(q.current=!1);},[L,G,j,f,q]),oe=useCallback(ee=>{let Ce=O.filter(Y=>Y!==ee);G(Ce),f&&Ce.length<f&&(q.current=!1);},[O,G,f,q]),pe=useCallback(ee=>{_||te(ee.type),_!==ee.type?(te(ee.type),G([ee.value])):O.includes(ee.value)?oe(ee.value):f?(O.length<f&&G([...O,ee.value]),O.length===f&&G([...O.slice(1),ee.value])):G([...O,ee.value]);},[_,te,G,O,oe,f]),Ne=useCallback(()=>{O.length>0&&E.length===0&&(G(O.slice(0,-1)),y(!0),f&&(q.current=!1)),E.length>0&&L(E.slice(0,-1));},[O,E,G,L,y,f,q]),Be=useCallback(()=>{S(ee=>ee&&(W.current=ee,!ee)),re(ee=>ee+1>=J.length?ee:ee+1);},[re,J]),ze=useCallback(()=>{let ee=J[ce];ee&&pe(ee);},[J,ce,pe]),at=useCallback(()=>{y(!1);},[y]),Qt=useCallback(()=>{re(()=>(Ie(),0));},[re,Ie]),zr=useCallback(()=>{let ee=J[ce];!P&&ee&&ee.type!==m[m.length-1]?.value&&re(()=>(fe(ee.name),0));},[J,ce,P,m,re,fe]),jo=useCallback(()=>{S(ee=>ee&&(W.current=ee,!ee)),re(ee=>ee-1<0?0:ee-1);},[re]),cr=useRef(null),Zt=du({count:J.length,estimateSize:()=>30,getScrollElement:useCallback(()=>cr.current,[]),overscan:10,rangeExtractor:useCallback(ee=>dl(ee),[])}),dn=({label:ee,onRemove:Ce,...Y})=>jsxs("div",{style:{alignItems:"center",backgroundColor:i.colorScheme==="dark"?i.colors.dark[7]:i.colors.gray[1],borderRadius:i.radius.sm,cursor:"default",color:i.colorScheme==="dark"?i.colors.dark[0]:i.colors.gray[7],display:"flex",fontSize:rem(12),fontWeight:500,height:rem(22),margin:`calc(${i.spacing.xs} / 2 - ${rem(2)}) calc(${i.spacing.xs} / 2)`,maxWidth:`calc(100% - ${rem(10)})`,paddingLeft:`calc(${i.spacing.sm} / 1.5)`,paddingRight:0,userSelect:"none"},...Y,children:[jsx("span",{style:{display:"block",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:ee}),jsx(CloseButton,{"aria-hidden":!0,iconSize:"70%",onMouseDown:Ce,radius:2,size:"sm",sx:{color:i.colorScheme==="dark"?i.colors.dark[0]:i.colors.gray[7],marginLeft:`calc(${i.spacing.sm} / 6)`},tabIndex:-1})]}),mn=useMemo(()=>O.map(ee=>F.find(Ce=>Ce.value===ee)).filter(ee=>!!ee).map((ee,Ce)=>createElement(dn,{...ee,index:Ce,key:ee.value,onRemove:Y=>{Y.preventDefault(),Y.stopPropagation(),oe(ee.value);}})),[O]),Vr=forwardRef(function({color:Ce,icon:Y,label:B,value:X,...le},ue){return jsx("div",{ref:ue,style:{cursor:"pointer",width:"100%"},...le,children:jsxs(Group,{align:"center",noWrap:!0,spacing:"xs",w:"100%",children:[Y&&jsx(Box,{bg:Ce??"transparent",component:"img",w:20,h:20,src:Y}),jsx(Text,{lineClamp:1,size:"sm",children:B||X})]})})}),{settings:Wo}=e,Cs=e.hideLabel==="true"||!e.label?jsx(Fragment,{}):jsx(ye,{component:"div",html:e.label,size:"sm",style:Wo,isPreview:!0});return jsx(Input.Wrapper,{label:Cs,children:jsxs(Popover,{closeOnClickOutside:!0,keepMounted:!0,opened:R,onChange:y,onClose:()=>{re(0),L("");},onOpen:()=>{Zt.scrollToIndex(0);},shadow:"sm",width:"target",withinPortal:!0,children:[jsx(Popover.Target,{children:jsxs(Box,{"aria-haspopup":"listbox",component:"div",onMouseLeave:()=>re(0),sx:{position:"relative","& .defaultValue":{backgroundColor:i.colorScheme==="dark"?i.colors.dark[5]:i.colors.gray[3],color:i.colorScheme==="dark"?i.colors.dark[1]:i.colors.gray[7]}},tabIndex:-1,children:[jsx("input",{type:"hidden",value:O.join(",")}),jsx(Input,{component:"div",multiline:!0,onMouseDown:ee=>{ee.preventDefault(),!q.current&&l.length>0&&y(!R),j.current?.focus();},rightSection:O.length>0?jsx(CloseButton,{onClick:U,onMouseDown:ee=>ee.preventDefault(),variant:"transparent"}):jsx(IconSelector,{color:i.colors.gray[6],size:18,stroke:1.5}),style:{overflow:"hidden"},w:"100%",children:jsxs(Box,{component:"div","data-clearable":!0,sx:{alignItems:"center",boxSizing:"border-box",display:"flex",flexWrap:"wrap",marginLeft:`calc(-${i.spacing.xs} / 2)`,minHeight:`calc(${rem(36)} - ${rem(2)})`,"&[data-clearable]":{marginRight:rem(36)},"&::placeholder":{color:i.colorScheme==="dark"?i.colors.dark[3]:i.colors.gray[5],opacity:1}},children:[mn,jsx("input",{autoComplete:"off","data-mantine-stop-propagation":R,onChange:xe,onKeyDown:getHotkeyHandler([["ArrowDown",Be],["ArrowLeft",Qt],["ArrowRight",zr],["ArrowUp",jo],["Backspace",Ne],["Enter",ze],["Escape",at]]),placeholder:O.length===0?g:void 0,ref:j,readOnly:q.current,style:{appearance:"none",backgroundColor:"transparent",border:0,color:"inherit",flex:1,fontSize:i.fontSizes.sm,marginLeft:`calc(${i.spacing.xs} / 2)`,maxHeight:rem(22),minWidth:rem(60),outline:0,padding:0},type:"search",value:E})]})})]})}),jsx(Popover.Dropdown,{onMouseDown:ee=>ee.preventDefault(),p:0,children:jsx("div",{style:{display:"flex",maxHeight:rem(300)},children:jsx(Box,{component:"div","data-combobox-popover":!0,onMouseDown:ee=>ee.preventDefault(),role:"listbox",sx:{width:"100%"},tabIndex:-1,children:jsxs(Stack,{h:"100%",py:"xs",spacing:"xs",w:"100%",children:[m.length>1&&jsxs(Stack,{spacing:"xs",children:[jsxs(Group,{onClick:ee=>{ee.stopPropagation();},px:"xs",position:"center",spacing:"xs",children:[jsx(Button,{onClick:()=>{re(0),D(!0),z([]),J.length>0&&Zt.scrollToIndex(0);},size:"xs",variant:P?"filled":"outline",children:a}),m.map((ee,Ce)=>jsx(Button,{onClick:()=>{P&&D(!1);let Y=[""].slice(1),B=Ce;for(;B--;)Y[B]=M[B]||"";re(0),z(Y),J.length>0&&Zt.scrollToIndex(0);},size:"xs",variant:!P&&M.length===m.findIndex(Y=>Y.value===ee?.value)?"filled":"outline",children:ee?.label},ee?.value))]}),jsx(Divider,{})]}),V>0&&jsxs(Group,{align:"center",noWrap:!0,px:"xs",children:[jsx(ActionIcon,{onClick:Ie,size:"sm",children:jsx(IconChevronLeft,{})}),jsx("div",{children:Z.map(ee=>jsx(Text,{lineClamp:1,size:"xs",children:ee},`${ee}`))})]}),jsx(ScrollArea,{mah:250,onWheel:()=>S(!0),px:"xs",style:{overflow:"auto",width:"100%"},viewportRef:cr,viewportProps:{tabIndex:-1},w:"100%",children:jsx("div",{style:{height:`${Zt.getTotalSize()}px`,position:"relative",width:"100%"},children:Zt.getVirtualItems().map(ee=>{let Ce=J[ee.index],Y=ce===ee.index,B=O.includes(Ce.value);return J.length>0&&Y&&!A&&Zt.scrollToIndex(ce),jsxs(Group,{"aria-selected":Y,align:"center","data-hovered":Y||void 0,"data-index":ee.index,"data-selected":B,id:Ce.vale,noWrap:!0,onMouseEnter:X=>{X.preventDefault(),X.stopPropagation(),A&&(re(ee.index),S(!1));},onMouseMove:X=>{X.preventDefault(),X.stopPropagation(),S(!0);},onMouseDown:X=>{X.preventDefault(),pe(Ce);},position:"apart",ref:Zt.measureElement,role:"option",spacing:"xs",sx:X=>({borderRadius:X.radius.xs,padding:"15px 5px 15px",paddingLeft:P&&10*m.findIndex(le=>le?.value===Ce.type)||5,position:"absolute",top:0,left:0,height:`${ee.size}px`,transform:`translateY(${ee.start}px)`,width:"100%","&[data-hovered]":{backgroundColor:X.colorScheme==="dark"?X.colors.dark[4]:X.colors.gray[1]},"&:hover":{backgroundColor:X.colorScheme==="dark"?X.colors.dark[4]:X.colors.gray[1]}}),tabIndex:-1,children:[jsx(Vr,{index:ee.index,...Ce}),!P&&Ce.type!==m[m.length-1]?.value&&jsx(ActionIcon,{onMouseDown:X=>{X.preventDefault(),X.stopPropagation(),fe(Ce.name);},size:"sm",tabIndex:-1,children:jsx(IconChevronRight,{})})]},Ce.value)})})})]})})})})]})})}var Vz,Fz,$z,Uz,Gz,DC=N(()=>{d();Ym();ft();Lt();ie();he();hr();Vz=(e=[],t=[],o="",r="",n="",i="|")=>{let a=t.map(h=>h.value).slice(),s=`${a.pop()}`,l=h=>h[o],u=h=>h[r],c=h=>{if(h[n])return typeof h[n]=="string"?h[n].split(i):h[n]},p=new Set,m=[],f=[],g=nest().rollup(h=>{let b=h[0],v=P=>P&&P.value&&!p.has(P.value),C=a.map(P=>b[`${P} ID`]),R=a.map(P=>b[P]),y=a.map((P,D)=>{if(f[D]!==R[D]){f[D]=R[D];let M=l[D]||l[l.length-1]||l,z=u[D]||u[u.length-1]||u,I=c[D]||c[c.length-1]||c;return {color:M(b,P)||void 0,icon:z(b,P)||void 0,value:`${C[D]}`,label:R[D],name:R[D],type:P,searchindex:R.slice(0,D+1).concat(I(b,P)).join("|")}}return {}}).filter(v);y.forEach(P=>p.add(P.value));let A=l[l.length-1]||l,S=u[u.length-1]||u,E=c[c.length-1]||c,L=h.map(P=>({color:A(P,s)||void 0,icon:S(P,s)||void 0,value:`${P[`${s} ID`]}`,label:P[s],name:P[s],type:s,searchindex:R.concat(P[s]).concat(E(P,s)).join("|")}));m.push(...y.concat(L));});return a.forEach(h=>{g.key(b=>`${b[`${h} ID`]}|${b[h]}`);}),g.entries(e),m},Fz=e=>{if(!e)return /./i;let t=e.normalize("NFD").replace(/[.*+?^${}()|[\]\\]/g,"\\$&").replace(/[\u0300-\u036f]/g,"").replace(/\s+/g,"[^|]+");return RegExp(t,"i")},$z=(e,t)=>{let o=e.length,r,n=s=>r&&r.searchindex.includes(s.searchindex),a={next:()=>{for(let s=o-1;s>-1;s--){let l=e[s];if(t.test(`${l.value} ${l.label} ${l.searchindex}`)||n(l))return r=l,o=s,{done:!1,value:l}}return {done:!0,value:void 0}},[Symbol.iterator]:()=>a};return a},Uz=e=>`multihierarchySelector${e}`,Gz=(e,t)=>e&&typeof e=="string"?e.split(","):t;});var NC={};Zp(NC,{default:()=>eV});function Zz({block:e,active:t,locale:o,variables:r,debug:n,configOverride:i={}}){let a=Xz(),s=so(e),l=po(o),u={variables:r},c=useRouter(),{sectionVariables:p,setSectionVariables:m,resetSectionVariables:f}=Ze(e.section_id),g=useMemo(()=>{if(!t)return {error:"Activate to View"};if(!s?.logic)return {error:"Add a Configuration"};let P=mr({logic:s.logic},l,u).logic,D={router:c,section:{variables:p,setVariables:m,resetVariables:f}};return Ga(P,l,r,o,e.id,{},D)},[s?.logic,t,r,p]);useMemo(()=>{if(!t||!s?.logic)return {};let{logic:P}=s,{vars:D}=To("variables",r,P,l,void 0,u);return D},[e,t]);let {type:b}=g.config||{},v=b&&tg[b]?b:"Treemap";b||(g.config={error:'Visualization missing "type"'}),tg[b]||(g.config={error:`"${b}" is not a valid Visualization Type`});let C=tg[v],R=g.error||g.config?.error||!1;if(R)return jsx(Center,{style:{height:"100%"},children:jsx(Badge,{color:"gray",variant:"outline",children:R},"type")});let{_data:y,...A}=g.config,S={locale:o,variables:r,...A,...i};a.print&&(S.detectVisible=!1);!a.print&&b!=="Graphic"&&b!=="HTML";return jsx("div",{style:{display:"flex",flex:"1 1 100%"},children:jsx(Qr,{fallback:jsx("p",{children:"Error in d3plus viz config."}),children:jsx(C,{style:{flex:1},dataFormat:P=>{g.data&&Array.isArray(g.data)&&g.data.length>1&&g.data.some(I=>typeof I=="string")?P:[P];let z;try{z=g.dataFormat(P);}catch(I){console.log("Error in dataFormat: ",I),z=[];}return z},linksFormat:g.linksFormat,nodesFormat:g.nodesFormat,topojsonFormat:g.topojsonFormat,config:{...S}},"viz-key")})})}var Xz,Qz,tg,eV,zC=N(()=>{d();ca();ei();df();vu();ko();he();Su();Xz=()=>({}),Qz={},tg={HTML:gl,...w_,...Qz};eV=memo(Zz,(e,t)=>e.block.contentByLocale.logic.content===t.block.contentByLocale.logic.content&&e.active===t.active&&e.locale===t.locale&&JSON.stringify(e.variables)===JSON.stringify(t.variables)&&JSON.stringify(e.configOverride)===JSON.stringify(t.configOverride));});var oV,ct,VC=N(()=>{d();ge();nC();aC();lC();cC();dC();mC();fC();yC();SC();TC();EC();RC();IC();DC();oV=P_(()=>Promise.resolve().then(()=>(zC(),NC)),{ssr:!1}),ct={[k.PARAGRAPH]:Lf,[k.STAT]:Mf,[k.SUBTITLE]:Bf,[k.TITLE]:Df,[k.SELECTOR]:zf,[k.VIZ]:oV,[k.GENERATOR]:Ff,[k.SECTION_FLAG]:Ff,[k.IMAGE]:$f,[k.NAV]:Hf,[k.RELATED]:Wf,[k.RESET_BUTTON]:qf,[k.COMPARISON_BUTTON]:Yf,[k.TABLE]:Xf,[k.BUTTON]:Qf,[k.MULTIHIERARCHY_SELECTOR]:eg};});function rg(e){return og[e]||IconDice}var og,ng=N(()=>{d();ge();og={[k.TITLE]:IconHeading,[k.GENERATOR]:IconApi,[k.SECTION_FLAG]:IconFlag,[k.STAT]:IconPercentage,[k.VIZ]:IconChartBar,[k.PARAGRAPH]:IconAlignLeft,[k.SELECTOR]:IconSelector,[k.IMAGE]:IconPhoto,[k.TABLE]:IconTable,[k.MULTIHIERARCHY_SELECTOR]:IconListTree};});function ag(e){return ig[e]}var ig,sg=N(()=>{d();ge();ig={[k.TITLE]:"Title",[k.GENERATOR]:"Data",[k.STAT]:"Stat",[k.VIZ]:"Visualization",[k.PARAGRAPH]:"Paragraph",[k.SELECTOR]:"Selector",[k.SUBTITLE]:"Subtitle",[k.RESET_BUTTON]:"Reset Button",[k.COMPARISON_BUTTON]:"Comparison Button",[k.RELATED]:"Related Reports",[k.NAV]:"Navigation",[k.IMAGE]:"Image",[k.TABLE]:"Table",[k.BUTTON]:"Button",[k.FALLBACK]:"Fallback",[k.SECTION_FLAG]:"Section Flag",[k.MULTIHIERARCHY_SELECTOR]:"Multihierarchy Selector"};});var fV,Ha,bl=N(()=>{d();ge();Im();VC();ng();sg();fV={[k.GENERATOR]:{type:k.GENERATOR,renderer:ct[k.GENERATOR],renderPreviewOnEdit:!1},[k.SECTION_FLAG]:{type:k.SECTION_FLAG,renderer:ct[k.SECTION_FLAG],renderPreviewOnEdit:!1},[k.IMAGE]:{type:k.IMAGE,renderer:ct[k.IMAGE],renderPreviewOnEdit:!1},[k.PARAGRAPH]:{type:k.PARAGRAPH,renderer:ct[k.PARAGRAPH],renderPreviewOnEdit:!0,evalWhenNonActive:!0},[k.RELATED]:{type:k.RELATED,renderer:ct[k.RELATED],renderPreviewOnEdit:!1,evalWhenNonActive:!0},[k.SELECTOR]:{type:k.SELECTOR,renderer:ct[k.SELECTOR],adapter:Ao[k.SELECTOR],nonActiveAdapter:()=>Ao[k.SELECTOR]({name:"Selector Preview"}),renderPreviewOnEdit:!1},[k.STAT]:{type:k.STAT,renderer:ct[k.STAT],renderPreviewOnEdit:!0,evalWhenNonActive:!0},[k.SUBTITLE]:{type:k.SUBTITLE,renderer:ct[k.SUBTITLE],renderPreviewOnEdit:!0,evalWhenNonActive:!0},[k.TITLE]:{type:k.TITLE,renderer:ct[k.TITLE],renderPreviewOnEdit:!0,evalWhenNonActive:!0},[k.VIZ]:{type:k.VIZ,renderer:ct[k.VIZ],renderPreviewOnEdit:!1},[k.NAV]:{type:k.NAV,renderer:ct[k.NAV],renderPreviewOnEdit:!0,evalWhenNonActive:!0},[k.RESET_BUTTON]:{type:k.RESET_BUTTON,renderer:ct[k.RESET_BUTTON],renderPreviewOnEdit:!0,evalWhenNonActive:!0},[k.COMPARISON_BUTTON]:{type:k.COMPARISON_BUTTON,renderer:ct[k.COMPARISON_BUTTON],renderPreviewOnEdit:!0,evalWhenNonActive:!0},[k.TABLE]:{type:k.TABLE,renderer:ct[k.TABLE],renderPreviewOnEdit:!1,evalWhenNonActive:!1},[k.BUTTON]:{type:k.BUTTON,renderer:ct[k.BUTTON],renderPreviewOnEdit:!0,evalWhenNonActive:!0},[k.MULTIHIERARCHY_SELECTOR]:{type:k.MULTIHIERARCHY_SELECTOR,renderer:ct[k.MULTIHIERARCHY_SELECTOR],adapter:Ao[k.MULTIHIERARCHY_SELECTOR],nonActiveAdapter:()=>Ao[k.MULTIHIERARCHY_SELECTOR]({label:"Multihierarchy Selector Preview"}),renderPreviewOnEdit:!1}},Ha=fV;});d();d();d();function Pb(e){let{onlyIcon:t,href:o,version:r}=e,n=jsx(Text,{c:"blue.5",ta:"left",children:jsxs(Group,{position:"left",spacing:"xs",children:[jsx(IconCircleDashed,{size:30}),!t&&jsxs(Text,{c:"black",fs:"lg",children:["Bespoke CMS",jsx(Text,{span:!0,c:"dimmed",size:"xs",ml:3,children:r})]})]})});return o?jsx(gM,{href:o,passHref:!0,children:jsx(UnstyledButton,{p:10,w:"100%",children:n})}):n}d();var Db=Jr__default.createContext(void 0);function _b(e){let[t,o]=useState(!1),[r,n]=useState(null),i=Jr__default.useMemo(()=>{function u(c,p){return p?{show:()=>u(c)}:new Promise((m,f)=>{n({request:c,onResolve:m,onReject:f}),o(!0);})}return {newConfirmation:u}},[]),a=()=>{o(!1),setTimeout(()=>n(null),200);},s=useCallback(u=>{!t||!r||(r.onResolve(u),a());},[t,r]),l=useCallback(u=>{!t||!r||(r.onReject(u),a());},[t,r]);return jsxs(Db.Provider,{value:i,children:[r&&jsx(fI,{opened:t,request:r.request,onConfirm:s,onCancel:l}),e.children]})}function fI(e){let{request:t,opened:o,onCancel:r,onConfirm:n}=e,i=useMantineTheme();return jsxs(Modal,{centered:!0,zIndex:1002,opened:o,title:t.title,onClose:r,children:[t.message,jsxs(Group,{position:"right",style:{marginTop:i.spacing.sm},children:[jsx(Button,{onClick:r,children:t.cancelText||"Cancel"}),jsx(Button,{color:"red",onClick:n,children:t.confirmText||"Confirm"})]})]})}function Pt(){let e=useContext(Db);if(e===void 0)throw new Error("useConfirmationDialog must be used within ConfirmationDialogProvider.");return e}Lt();Nc();d();d();d();function ka(e){return jsxs("span",{style:{display:"flex",alignItems:"center",gap:"0.5rem"},children:[e.icon,e.children]})}ie();Lt();he();bi();bi();d();d();ie();ao();br();function E0(){let{user:e,update:t,status:o}=xt(),r=o==="loading",{localeDefault:n}=Ve(),i=ne();return useEffect(function(){!r&&e&&e.bespoke_user_metadata&&typeof e.bespoke_user_metadata.preferredLocale=="string"&&i(Q.setPreferredLocale(e.bespoke_user_metadata.preferredLocale||n));},[r,e]),{user:e,isLoading:r,update:t,status:o}}var Hs=E0;function js(e){let{user:t}=Hs();return useMemo(()=>{if(t&&t.bespoke_app_metadata&&t.bespoke_app_metadata.reports&&Array.isArray(t.bespoke_app_metadata.reports)){let r=t.bespoke_app_metadata.reports.find(n=>n.reportId===e);if(r&&r.favorites)return r.favorites}},[t,e])}d();function Sv(e){let{left:t,center:o,right:r}=e;return jsx(Header,{height:50,p:"xs",pos:"sticky",zIndex:98,children:jsxs(Group,{position:"apart",children:[jsx("div",{className:"left",children:t}),jsx("div",{className:"center",children:o}),jsx("div",{className:"right",children:r})]})})}d();d();ie();var P0=e=>e.status.locales.map(t=>({value:t,label:t.toUpperCase()}));function xv(){return $(P0)}ie();var N0=e=>({input:{border:"none",background:e.colors.blue[0],borderRadius:e.radius.sm,color:e.colors.blue[7],fontSize:12,fontWeight:700,width:80},item:{fontSize:12},rightSection:{pointerEvents:"none"}});function Ws({value:e,onChange:t,defaultValue:o,selectProps:r={},loading:n=!1}){let i=xv(),a=$(c=>c.status.localeDefault),[s,l]=useUncontrolled({value:e,defaultValue:o||a,finalValue:a,onChange:t}),u=useMantineTheme();return jsx(Select,{...r,data:i,value:s,onChange:l,styles:{...N0(u),...r?.styles},icon:jsx(IconLanguage,{size:"0.8rem",color:u.colors.blue[7]}),rightSection:n?jsx(Loader,{size:"0.8rem"}):jsx(IconChevronDown,{size:"0.8rem",color:u.colors.blue[7]})})}d();ie();d();d();ao();Ks();Ic();d();Ic();function $t(e){let t=Number.parseInt(`${e||""}`,10);if(Number.isNaN(t)||!Number.isFinite(t))throw new ni(400,`Invalid numeric parameter: ${e}`);return t}function Me(e){return e==null||e===""?[]:Array.isArray(e)?e:e.toString().split(",")}d();var mo={ADMIN:"Admin",EDITOR:"Editor",WRITER:"Writer"};var{localeDefault:vn}=Ve();function Tv(e){let t=Me(e.locale)[0]||vn||"en",o=t==="all"||Fc(e.all),r=Me(e.mode)[0],i=(Me(e.output)[0]||"full")==="lite"?"lite":"full",a=parseInt(Me(e.related)[0],10)||5,s=Me(e.variant).map($t);if(s.length===0&&(s=Me(e["variant[]"]).map($t)),r==="ids")return {all:o,mode:r,variant:s,output:i,locale:o?vn:Ft(t),ids:Me(e.ids||e["ids[]"])};if(r==="content_ids")return {all:o,mode:r,variant:s,output:i,locale:o?vn:Ft(t),content_ids:Me(e.content_ids||e["content_ids[]"]).map($t)};if(r==="slugs")return {all:o,mode:r,variant:s,output:i,locale:o?vn:Ft(t),slugs:Me(e.slugs||e["slugs[]"]).map(l=>{let[u,c]=l.split("/");return {variantSlug:u,memberSlug:c}})};if(r==="related")return {all:o,mode:r,locale:o?vn:Ft(t),related:a,current_ids:Me(e.current_ids||e["current_ids[]"]).map($t),report_ids:Me(e.report_ids||e["report_ids[]"]).map($t),dimension_ids:Me(e.dimension_ids||e["dimension_ids[]"]).map($t),variant_ids:Me(e.variant_ids||e["variant_ids[]"]).map($t),output:i};if(r==="whole")return {all:o,mode:r,variant:s,locale:o?vn:Ft(t),output:i};throw new ni(400,`Invalid mode: '${r}'`)}function $c(e){let t=Me(e.locale)[0]||vn||"en",o=t==="all",r=Me(e.format)[0],n=r?r==="nested":o,i=Me(e.variant).map($t);i.length===0&&(i=Me(e["variant[]"]).map($t));let a=Me(e.dimension).map($t);a.length===0&&(a=Me(e["dimension[]"]).map($t));let s=Me(e.report).map($t);return s.length===0&&(s=Me(e["report[]"]).map($t)),{query:Me(e.query||e.q)[0]||"",locale:o?vn:t,preferredLocale:Me(e.preferredLocale)[0],limit:Me(e.limit).map($t)[0]??5,format:n?"nested":"plain",includes:Fc(e.includes,{default:!0}),visible:Fc(e.visible,{default:!0}),noImage:Fc(e.noImage,{default:!1}),variant:i,dimension:a,report:s,all:o,sort:Me(e.sort)[0],direction:Me(e.direction)[0],offset:Number(e.offset||0)}}ie();d();he();ie();d();var H0={maxWidth:100,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"};function Ys({children:e,tooltip:t=!1,onClick:o=()=>{},textProps:r={},clickable:n=!1}){return jsx(Tooltip,{label:e,disabled:!t,children:jsx(UnstyledButton,{onClick:o,children:jsxs(Group,{spacing:"xs",align:"center",noWrap:!0,children:[jsx(Text,{fz:"0.675rem",tt:"uppercase",fw:700,color:"gray.7",sx:H0,...r,children:e}),n&&jsx(ThemeIcon,{color:"gray.7",size:"0.4rem",bg:"transparent",variant:"default",sx:{border:"none"},children:jsx(IconTriangleInvertedFilled,{})})]})})})}ao();d();var Uc=e=>t=>({input:{border:"none !important",outline:"none",background:t.colors.gray[1]},dropdown:{padding:0,background:t.fn.lighten(t.colors.gray[1],.8),borderColor:t.colors.gray[4],borderRadius:t.radius.md,width:"280px !important",gap:t.spacing.xs,":before":{display:"block",content:`"${e}"`,fontSize:t.fontSizes.xs,color:t.colors.gray[5],paddingLeft:t.spacing.sm,paddingRight:t.spacing.sm,paddingBottom:t.spacing.xs,paddingTop:t.spacing.xs}}});function oP(e,t,o){return o===t?e.map(r=>({id:r.id,value:`${r.id}`,name:r.name})):e.map(r=>{let n=r.contentByLocale.find(i=>i.locale===o);return {id:r.id,value:`${r.id}`,name:r.name,refName:n?n.name:null}})}var Cv={overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},rP=forwardRef(function({id:t,name:o,refName:r,...n},i){return jsxs(Group,{position:"apart",ref:i,...n,children:[jsxs(Stack,{spacing:0,children:[jsx(Text,{maw:"200px",sx:Cv,children:o}),r&&jsx(Text,{fz:10,c:"#666",maw:"140px",sx:Cv,children:r})]}),jsx(Text,{color:"gray.5",size:"sm",children:t})]},`${t}-${o}`)});function Qd(e){let{dimensionId:t,variantId:o,value:r,defaultValue:n,onChange:i,locale:a}=e,s=ne(),{localeDefault:l}=Ve(),u=xa(),c=a||l,[p,m]=useState([]),[f,g]=useState(""),[h]=useDebouncedValue(f,500),[b,v]=useState(!1),[C,R]=useState(!1),[y,A]=useUncontrolled({value:r,defaultValue:n,finalValue:void 0,onChange:i?M=>i(M):void 0}),S=useRef(null),E=useClickOutside(()=>R(!1)),L=useMergedRef(S,E),P=M=>{let z=p.find(I=>I.id===M.id);z&&(g(z.name?z.name:""),A(z),R(!1));};useEffect(function(){v(!0);let z={query:h,locale:c===u?c:"all",variant:[o],dimension:[t],limit:5,visible:!1,includes:!0,noImage:!1,format:"plain",all:!0,preferredLocale:u,report:[]};s(Q.searchMember(z)).then(I=>{if(I&&I.results){let w=I.results.map(O=>({...O,currentLocale:c,name:(O.contentByLocale&&O.contentByLocale.find(_=>_.locale===c)||O).name}));m(w),v(!1),w.length===0&&h===""&&(m([]),v(!1));}});},[s,h,c,o,t,u]),useEffect(()=>{p.length&&!y?.name&&i&&i(p[0]);},[p,i]);let D=oP(p,c,u);return useEffect(()=>{setTimeout(()=>{S.current&&S.current.focus();},200);},[C]),C||!y?.name?jsx(Autocomplete,{ref:L,value:f,onChange:g,data:D,itemComponent:rP,placeholder:"Search members.",nothingFound:"No members found.",rightSection:b&&jsx(Loader,{size:"xs"}),filter:()=>!0,onItemSubmit:P,size:"xs",w:130,styles:Uc("Members")}):jsx(Ys,{onClick:()=>R(!0),textProps:{color:"gray.6"},tooltip:!0,clickable:!0,children:y.name})}d();ie();function Zd(e){let o=fi(e).data,r=Hd(o?.variants);return r.isSuccess?r.data.map(n=>({value:`${n.id}`,label:n.name})):[]}function em(e){let{dimension:t,value:o,onChange:r}=e,[n,i]=useState(!1),a=Zd(t),s=useClickOutside(()=>i(!1)),l=a.length===1||!n,[u,c]=useUncontrolled({value:o?String(o):void 0,defaultValue:a[0]?a[0].value:"",finalValue:void 0,onChange:r?f=>r(Number(f)):void 0}),p=f=>c(f),m=a.find(f=>f.value===u)||a[0];return l?jsx(Ys,{onClick:()=>i(!0),clickable:a.length>1,children:m?m.label:"No Variant"}):jsx(Select,{ref:s,data:a,value:u,onChange:p,w:140,size:"xs",styles:Uc("Variants"),initiallyOpened:!0})}function Hc(e){let{dimensionId:t,locale:o,onSelect:r,value:n}=e,i=ne(),a=Zd(t),[s,l]=useUncontrolled({defaultValue:void 0,finalValue:void 0,onChange:r?m=>r(m):void 0}),[u,c]=useUncontrolled({value:void 0,defaultValue:n?.variantId,finalValue:a[0]?Number(a[0].value):0,onChange:()=>{l({});}}),p=n?.memberId;return useEffect(function(){p&&i(Q.readMember(Tv({locale:o,content_ids:[`${p}`],all:"false",mode:"content_ids"}))).then(f=>{if(f&&f.results&&f.results[0]){let g=f.results[0];l({locale:o,name:g.name,contentByLocale:g.contentByLocale,contentId:g.content_id});}else console.error("default member is not found");});},[p]),jsxs(Flex,{gap:"xs",px:"xs",align:"center",children:[jsx(em,{dimension:t,value:u,onChange:c},`dimension-${t}`),jsx(Text,{fz:"xs",tt:"uppercase",color:"gray.6",fw:700,children:"/"}),u&&jsx(Qd,{variantId:u,dimensionId:t,value:s,onChange:l,locale:o},`variant-${u}`)]})}Lt();bi();function rm({report:e,defaultMembers:t,locale:o}){let[r,n]=useState(!1),i=ne(),a=ro(),s=useContext(_e),l=e&&e.dimensions?e.dimensions:[],u=$(g=>g.status.previews),c=u.map(g=>({variantId:g.variant_id,memberId:g.content_id})),p=a.query.preview,m=Array.isArray(p)?p.join("!"):p||"",f=g=>{let b=e.dimensions.map(C=>{let R;if(g)if(g.dimension_id===C)R=g;else {let y=u.find(A=>A?A.dimension_id===C:!1);y&&(R=y);}return R}).map(C=>C?{...C,report_name:C.report?.name||C.report_name,report_id:C.report?.id||C.report_id,dimension_id:C.dimension?.id||C.dimension_id,dimension_name:C.dimension?.name||C.dimension_name,variant_id:C.variant?.id||C.variant_id,variant_name:C.variant?.name||C.variant_name,variant_slug:C.variant?.slug||C.variant_slug}:{}),v=b.map(yP).join("!");if(v&&m!==v){let C=b.filter(R=>R.content_id).length===l.length;i(Q.setPreviews(b)),C&&(a.setSearchParam("preview",v),i(Q.recalculateVariables(s,{previews:b})));}};return useEffect(function(){let h=m.split("!").filter(Boolean);h.length===l.length&&l.length>0?i(Q.readMember({mode:"slugs",slugs:h.map(b=>{let[v,C]=b.split("/");return {variantSlug:v,memberSlug:C}}),locale:o,output:"full"})).then(b=>i(Q.recalculateVariables(s,{previews:b.results}))).then(()=>n(!0)):t&&t.length===l.length?i(Q.readMember({mode:"content_ids",variant:t.map(b=>b.variantId),content_ids:t.map(b=>b.memberId),locale:o,output:"full"})).then(b=>i(Q.recalculateVariables(s,{previews:b.results}))).then(()=>n(!0)):n(!0);},[]),jsx(Group,{spacing:"xs",children:r&&l.map((g,h)=>jsxs(Fragment$1,{children:[jsx(Text,{fw:700,fz:"xs",children:"/"}),jsx(Hc,{dimensionId:g,onSelect:f,value:c[h]?c[h]:void 0,locale:o},g)]},g))})}function yP(e){return `${"variant_slug"in e?e.variant_slug:e?.variant?.slug}/${e.slug}`}d();ie();d();ie();d();d();hn();d();fc();var Js="dimension",wv="Dimension";d();var nm="formatter",Pv="Formatter";d();hn();fc();ad();d();var im="variant",Ov="Variant";var Mv={[gc]:ay,[Js]:wv,[nm]:Pv,[Zn]:ty,[Ls]:ry,[im]:Ov};ie();function yr({id:e,type:t,warning:o,disabled:r=!1}){let n=useDispatch(),{newConfirmation:i}=Pt(),a=useCallback(async()=>{let s=Mv[t]||"Entity",l=o||`Delete this ${s} and all its contents? This action cannot be undone.`;try{r||(await i({title:"Are you sure?",message:l,confirmText:"Yes, Delete it."}),n(Q.deleteEntity(t,e)));}catch{console.debug(`${s} deletion aborted:`,e);}},[e,t,o,r,n]);return jsx(ActionIcon,{disabled:r,color:"red",variant:"transparent",onClick:a,children:jsx(IconTrash,{size:18})})}function _P({for:e,onEdit:t}){let o=useMantineTheme(),{newConfirmation:r}=Pt(),n=o.colorScheme==="dark"?o.colors.dark[1]:o.colors.gray[7],i=useCallback(async()=>{try{await r({title:"Are you sure?",message:"Modifying dimensions can be destructive and break the site. Make sure you know what you're doing!",confirmText:"Continue"}),t(e.id);}catch{console.debug("Dimension edition aborted.");}},[t]),{name:a,ordering:s}=e;return jsxs(Card,{shadow:"xs",withBorder:!0,style:{margin:o.spacing.sm},children:[jsx(Group,{position:"apart",children:jsxs(Center,{children:[jsx(IconDatabase,{size:22}),jsx(Space,{w:"xs"}),jsx(Text,{weight:"bold",children:a})]})}),jsxs(Text,{size:"sm",style:{color:n,lineHeight:2},children:["Order:",s]}),jsx(Space,{w:"xs"}),jsxs(Group,{position:"apart",children:[jsxs(Center,{children:[jsx(IconServer,{size:22}),jsx(Space,{w:"xs"}),jsx(Text,{weight:"bold",children:"Variants"})]}),jsx(Badge,{variant:"light",children:0})]}),jsx("ul",{children:e.variants.map(l=>jsx("li",{style:{color:n},children:jsx(zP,{id:l})},l))}),jsxs(Group,{position:"apart",children:[jsx(Button,{onClick:i,leftIcon:jsx(IconPencil,{}),compact:!0,children:"Edit"}),jsx(yr,{id:e.id,type:"dimension",warning:"Deleting dimensions can be destructive and break the site. Make sure you know what you're doing!"})]})]})}var _v=oo(_P,fi);function NP({for:e}){return jsx(Text,{size:"sm",children:`${e.name}: /${e.slug}`})}var zP=oo(NP,gi);d();Xs();ie();d();function Pa(e){let{target:t,fields:o,onSubmit:r}=e,[n,i,a]=XP(o||[]),[s,l]=useDisclosure(!1,{onClose:a}),u=useCallback(c=>{s&&(c.preventDefault(),typeof r=="function"&&r(i),l.close());},[i,s]);return useHotkeys([["enter",u]]),n.length===0?t:jsxs(Popover,{onClose:l.close,opened:s,position:"right",trapFocus:!0,withArrow:!0,withinPortal:!0,zIndex:1001,children:[jsx(Popover.Target,{children:Jr__default.cloneElement(e.target,{onClick:l.open})}),jsx(Popover.Dropdown,{children:jsxs("form",{onSubmit:u,children:[n,jsx(Button,{type:"submit",children:"Submit"})]})})]})}function XP(e){let[t,o]=useState({}),r=e.map(a=>encodeURIComponent(`${a.name}:${a.type}/${a.label}`)).join("&"),n=useCallback(()=>{o({});},[]);return [useMemo(()=>e.map(a=>{let s=`${t[a.name]??(a.initialValue||"")}`;return a.type==="checkbox"?jsx(Checkbox,{label:a.label,name:a.name,checked:s=="true"},a.name):a.type==="radio"?jsx(Radio.Group,{label:a.label,value:s,children:a.options.map(l=>jsx(Radio,{label:l.label,value:`${l.value}`},l.label))},a.name):a.type==="select"?jsx(Select,{data:a.options.map(l=>({value:`${l.value}`,label:l.label})),label:a.label,onChange:l=>{o({...t,[a.name]:l});},value:s,zIndex:1002},a.name):a.type==="switch"?jsx(Switch,{label:a.label,name:a.name,checked:s=="true"},a.name):a.type==="text"?jsx(TextInput,{label:a.label,onChange:l=>{o({...t,[a.name]:l.target.value});},placeholder:a.placeholder,value:s},a.name):null}),[r,t]),t,n]}d();ie();d();var Wc=e=>({overrideNames:e&&typeof e.overrideNames<"u"?e.overrideNames:!1,overrideRelevance:e&&typeof e.overrideRelevance<"u"?e.overrideRelevance:!1,regenerateSlugs:e&&typeof e.regenerateSlugs<"u"?e.regenerateSlugs:!1,keepOldMembers:e&&typeof e.keepOldMembers<"u"?e.keepOldMembers:!0,doIngest:e&&typeof e.doIngest<"u"?e.doIngest:!1,overrideAttributes:e&&typeof e.overrideAttributes<"u"?e.overrideAttributes:!1,order:e&&typeof e.order<"u"?e.order:0});function aO({for:e,onEdit:t}){let o=useMantineTheme(),{newConfirmation:r}=Pt();o.colorScheme==="dark"?o.colors.dark[1]:o.colors.gray[7];let i=useCallback(async()=>{try{await r({title:"Are you sure?",message:"Modifying variants can be destructive and break the site. Make sure you know what you're doing!",confirmText:"Continue"}),t(e.id);}catch{console.debug("Variant edition aborted.");}},[t]),{slug:a,name:s,settings:l}=e,u=Wc(l);return jsxs(Card,{shadow:"xs",withBorder:!0,style:{margin:o.spacing.sm},children:[jsxs(Group,{position:"apart",children:[jsxs(Center,{children:[jsx(IconServer,{size:22}),jsx(Space,{w:"xs"}),jsx(Text,{weight:"bold",children:s}),jsxs(Text,{size:"xs",ml:"xs",children:["Order: ",u.order]})]}),jsxs(Badge,{variant:"light",children:["/",a]})]}),jsx(Space,{h:"xs"}),jsxs(Group,{position:"apart",children:[jsx(Button,{onClick:()=>i(),leftIcon:jsx(IconPencil,{}),compact:!0,children:"Edit"}),jsx(yr,{id:e.id,type:"variant",warning:"Deleting variants can be destructive and break the site. Make sure you know what you're doing!"})]})]})}var Hv=oo(aO,gi);d();gd();d();var Kc=e=>e.replace(/^\s+|\s+$/gm,"").replace(/[^a-zA-ZÀ-ž0-9-\ _]/g,"");ie();Ba();d();function Ro({content:e,buttons:t,size:o}){let[r,n]=useState(500);return useEffect(()=>{let{innerHeight:i}=window;n(i-o);},[]),jsxs("div",{style:{height:"100%"},children:[jsx(ScrollArea,{offsetScrollbars:!0,type:"always",style:{height:r},children:e}),jsx(Space,{h:"xs"}),jsx(Divider,{}),jsx(Group,{mt:"xs",grow:!0,style:{height:45},children:t})]})}d();d();function CO({member:e,height:t="auto",width:o="100%",size:r="thumb",forceRefreshTimestamp:n=!1}){let i="";n&&(i=`&t=${new Date().getTime()}`);let a=e&&e.image_id?`/api/cms/member/image?member=${e.content_id}&size=${r}${i}`:"https://placehold.jp/cccccc/ffffff/900x600.png?text=None";return jsx(Image,{alt:`Image for ${e.id}`,height:t,width:o,radius:"md",src:a})}var Qs=CO;ie();function Da({members:e,onClickEdit:t,onSort:o,colsToRender:r=[],dataTableProps:n={}}){let[i,a]=useState([]),[s,l]=useState([]),{state:u,...c}=n;useEffect(()=>{typeof o<"u"&&i&&i.length&&o(i);},[i]),useEffect(()=>{l(e);},[e]),useEffect(()=>{l(e);},[]);let p=$(g=>g.status.localeDefault),m=jsx(Badge,{color:"gray",children:"None"}),f=[{header:"",accessorKey:"visible",enableResizing:!1,enableSorting:!1,size:10,Cell:({row:g})=>jsx(Fragment,{children:g.original.visible?jsx("span",{}):jsx(Tooltip,{label:"Visible: false",children:jsx("span",{children:jsx(IconEyeOff,{size:20})})})})},{header:"ID",accessorKey:"id",enableSorting:typeof o<"u",mantineTableHeadCellProps:{align:"right",sx:{"& .mantine-TableHeadCell-Content-Labels":{flexDirection:"row"}}},mantineTableBodyCellProps:{align:"right"},size:100},{header:"Report",accessorKey:"report.name",enableSorting:!1,size:100},{header:"Dimension",accessorKey:"dimension.name",enableSorting:!1,size:100},{header:"Variant",accessorKey:"variant.name",enableSorting:!1,size:100},{header:"Relevance",accessorKey:"zvalue",enableSorting:typeof o<"u",size:100},{header:"Slug",accessorKey:"slug",Cell:({row:g})=>jsxs("span",{children:["/",g.original.variant.slug,"/",g.original.slug]}),enableSorting:!1},{header:`Name ${p.toUpperCase()}`,accessorKey:"name",enableSorting:typeof o<"u",Cell:({row:g})=>{let h=g.original.contentByLocale.find(C=>C.locale===p),b=g.original.contentByLocale.filter(C=>C.locale!==p),v=b.reduce((C,R)=>{let y=`${R.locale.toUpperCase()}: ${R.name}`;return `${C}${C!==""?`
90
+ a viverra sapien pulvinar.`,style:o,append:t?jsx(kt,{content:t,style:{display:"inline-block",verticalAlign:"bottom"}}):jsx(Fragment,{}),isPreview:!0})}var nC=N(()=>{d();Yr();ft();});function Mf({subtitle:e,title:t,value:o,tooltip:r,settings:n,_iconType:i,_iconVariant:a,_icon:s,_iconRadius:l,_iconSize:u,_iconPadding:c}){let p=t||"<span class='cr-block-placeholder'>Title</span>",m=o||"<span class='cr-block-placeholder'>Big Stat</span>",f=e||"<span class='cr-block-placeholder'>Subtitle</span>",g=n&&n.align||"left";return jsx("div",{className:"bespoke-Stat-root",children:jsxs(Group,{className:"bespoke-StatGroup-wrapper",position:Io(g),children:[i!=="none"&&i&&jsx(Et,{blockType:"stat",iconType:i,iconVariant:a,iconRadius:l,iconSize:u,icon:s,iconPadding:c}),jsxs("div",{className:"bespoke-Stat-wrapper",children:[jsx(ye,{component:"div",size:"md",html:p,style:n,isPreview:!0}),jsx(ye,{component:"div",size:"xl",html:m,style:n,isPreview:!0}),jsx(ye,{component:"div",size:"sm",html:f,style:n,isPreview:!0})]},"stat"),r&&jsx(kt,{content:r})]})})}var aC=N(()=>{d();Yr();Ti();ft();_t();});function Bf({subtitle:e,tooltip:t,settings:o}){let r=lt(e)||"<span class='cr-block-placeholder'>Small subtitle.</span>",n=o&&o.align?o.align:"left";return jsxs(Group,{spacing:"sm",position:Io(n),children:[jsx(ye,{size:"sm",html:r,isPreview:!0}),t&&jsx(kt,{content:t,style:{display:"inline-flex"}})]})}var lC=N(()=>{d();Yr();xn();ft();_t();});function Df({title:e,tooltip:t,_iconType:o,_iconVariant:r,_icon:n,settings:i,_iconRadius:a,_iconSize:s,_iconPadding:l}){let u=lt(e)||"Title",c=i&&i.order?parseInt(i.order,10):1,p=c<=6?c:1,m=!!(i&&i.search&&i.search!=="off"),f=i&&i.search?i.search:"",g=i&&i.align?i.align:"left";return jsxs(Group,{spacing:"sm",position:Io(g),children:[o!=="none"&&o&&jsx(Et,{blockType:"title",iconType:o,iconVariant:r,iconRadius:a,iconSize:s,icon:n,iconPadding:l}),jsx(ye,{component:"h",order:p,style:i,html:u,isPreview:!0}),m&&jsx(Tooltip,{label:`Click will open '${f}' report search`,children:jsx(ActionIcon,{variant:"light",children:jsx(IconSearch,{size:20})})}),t&&jsx(kt,{content:t})]})}var cC=N(()=>{d();Yr();xn();Ti();ft();_t();});function zf(e){let{id:t,type:o,defaultValue:r,options:n,name:i,settings:a,hideLabel:s,component:l,resetSectionVars:u,section:c}=e,p=useDispatch(),m=useContext(_e),f=$(M=>M.status.query),{sectionVariables:g,resetSectionVariables:h}=Ze(c),b=G1(t),v=useMemo(()=>f[b]||r,[f[b],o,r]),C=useMemo(()=>H1(f[b],r),[f[b],o,r]),[R,y]=useState(n?.map(M=>({value:M.id,label:M.label,imageUrl:M.imageUrl}))||[]),[A,S]=useState((n||[]).map(M=>M.id).join("-"));useEffect(()=>{let M=n.map(w=>`${w.label}|${w.id}`).join("-");if(A===M)return;S(M);let z=n.map(w=>({value:w.id,label:w.label}));y(z);let I=o===mt.SINGLE?v:C;ti(o,I,n)||p(Ud(m,b));},[JSON.stringify(n),t]);let E=()=>{u==="true"&&g&&h();},L=M=>{p(pi(m,b,M)),E();},P=M=>{p(pi(m,b,M.join())),E();},D=s==="true"?jsx(Fragment,{}):jsx(ye,{component:"div",html:i,size:"sm",style:a,isPreview:!0});return R.length===0?jsx(Text,{c:"dimmed",size:"xs",children:"No options defined yet. Selector hidden in report."}):R.length===1?jsxs(Text,{c:"dimmed",size:"xs",children:["Only one option defined. Selector hidden in report. ",JSON.stringify(R)]}):{[mt.SINGLE]:l===bc.SEGMENTED_CONTROL?jsxs("div",{children:[D,jsx(SegmentedControl,{data:R,value:R.map(M=>M.value).includes(v)?v:"",onChange:L,fullWidth:!0})]}):jsx(Select,{label:D,data:R,value:v,onChange:L,itemComponent:j1,styles:{label:{display:s==="true"?"none":"block"}}}),[mt.MULTI]:jsx(MultiSelect,{label:D,data:R,value:C,onChange:P,styles:{label:{display:s==="true"?"none":"block"}}})}[o]}var G1,H1,j1,dC=N(()=>{d();hr();vc();ge();ie();Lt();ft();he();G1=e=>`selector${e}id`,H1=(e,t)=>e&&typeof e=="string"?e.split(","):t,j1=forwardRef(function({imageUrl:t,label:o,...r},n){return jsx("div",{ref:n,...r,children:jsxs(Group,{noWrap:!0,children:[t&&jsx(Box,{component:"img",w:25,h:25,src:t}),jsx("div",{children:jsx(Text,{size:"sm",children:o})})]})})});});function tz({outputVariables:e,status:t,hasAPI:o=!1,debug:r,type:n}){let[i,a]=useState(!1),s=o&&!Object.keys(e).length&&!t.error,l=Object.keys(e).some(c=>c.startsWith("_"));return r?s?jsxs(Stack,{align:"center",children:[jsx(Loader,{}),jsxs(Text,{size:"sm",children:["Loading ",n]})]}):jsxs(Fragment,{children:[jsx(Divider,{label:"Output Variables",labelPosition:"center"}),l&&jsx(Switch,{label:"Show internal variables",mb:"xs",size:"xs",checked:i,onChange:c=>a(c.currentTarget.checked)}),jsx(tr,{variables:e,showInternal:i})]}):jsx(Center,{children:jsx(Badge,{color:"gray",variant:"outline",children:n.toUpperCase()},"type")})}var Ff,mC=N(()=>{d();Ba();Ff=tz;});function $f(e){let{alt:t,src:o,desc:r,title:n,settings:i,...a}=e,s=lt(t),l=lt(o),u=lt(r),c=jsx("img",{src:l,alt:s,style:a}),p=i&&i.align?String(i.align):"left";return (u&&u.length||n&&n.length)&&(c=jsxs(Stack,{className:"bespoke-Image-wrapper",align:vr(p),spacing:"sm",children:[n&&jsx(ye,{component:"p",html:n,style:i,isPreview:!0}),c,r&&jsx(ye,{component:"p",size:"sm",html:r,style:i,isPreview:!0})]})),l&&s?c:jsx(Center,{mih:100,bg:"white",children:jsx(Badge,{color:"gray",variant:"outline",children:"IMAGE"},"type")})}var fC=N(()=>{d();xn();ft();_t();});function Hf({headings:e,settings:t}){let{min:o="1",max:r="6",icons:n="yes"}=t||{},i=wa(parseInt(o,10),parseInt(r,10),e),a=n==="yes",s=Fa(t&&t.align?String(t.align):"left"),l=u=>!u||!u?.length?null:jsx(Fragment,{children:u.map(c=>jsxs(Fragment$1,{children:[jsx(Menu.Item,{children:jsx(Anchor,{href:`#bespoke-title-${c.id}`,children:jsxs(Group,{spacing:"sm",children:[a&&jsx(Et,{...c.iconProps,iconSize:"sm"}),jsx(Text,{dangerouslySetInnerHTML:{__html:c.label}})]})})},c.id),jsx(Box,{pl:"xs",children:l(c.children)})]},c.id))});return jsx(Box,{pos:"relative",children:jsxs(List,{sx:u=>({display:"flex",gap:u.spacing.md,justifyContent:s,listStyleType:"none"}),children:[i?.map(u=>jsx(List.Item,{children:jsxs(Menu,{trigger:"hover",openDelay:100,closeDelay:400,children:[jsx(Menu.Target,{children:jsx(Anchor,{href:`#bespoke-title-${u.id}`,children:jsxs(Group,{spacing:"sm",noWrap:!0,children:[a&&jsx(Et,{blockType:"nav",...u.iconProps,iconSize:"sm",iconPadding:"2"}),jsx(Text,{dangerouslySetInnerHTML:{__html:u.label}})]})})}),u?.children?.length?jsx(Menu.Dropdown,{children:l(u.children)}):null]})},u.id)),!i||i.length===0&&jsx(List.Item,{children:jsx(Text,{color:"dimmed",children:"- Include some titles as inputs to see the Nav component -"})})]})})}var yC=N(()=>{d();bi();Ti();_t();});function Wf(e){let{related_reports:t,settings:o}=e;if(!t?.length)return jsx(Text,{children:"There are no available members related to your current selection and report."});let r=Fa(o&&o.align?String(o.align):"left");return jsx(List,{sx:()=>({display:"flex",justifyContent:r}),children:t.map(n=>jsx(List.Item,{children:n.name},n.content_id))})}var SC=N(()=>{d();_t();});function qf({id:e,label:t,settings:o,showIcon:r,fullWidth:n,showWhenDisabled:i}){let a=He(e).data,{sectionVariables:s,resetSectionVariables:l}=Ze(a?.section_id),u=!!Object.keys(s).length,c=vr(o&&o.align?o.align:"left");return jsxs(Stack,{align:c,children:[!u&&!i&&jsx(Text,{size:"xs",ta:o?.align||"left",children:"Reset button will not be shown on its disabled state"}),jsx(Button,{onClick:()=>l(),disabled:!u,fullWidth:n,children:jsxs(Group,{align:"center",children:[t,r&&jsx(IconRefresh,{})]})})]})}var TC=N(()=>{d();he();he();_t();});function Yf({settings:e,label:t,showIcon:o,position:r="center"}){let n=e&&e.search?e.search:"";return jsxs(Group,{position:r,children:[jsx(Tooltip,{label:`Click will open '${n}' report search`,children:jsx(Button,{children:jsxs(Group,{align:"center",children:[t||"Comparison Button",o&&jsx(IconPlus,{})]})})}),jsx(ActionIcon,{variant:"light",children:jsx(IconSearch,{size:20})})]})}var EC=N(()=>{d();});function Xf({columns:e=[],id:t,data:o=[],tableProps:r={}}){let[n,i]=useState({}),{initialState:a}=r,s=a?.pagination?.pageIndex,l=a?.pagination?.pageSize,u=`table-${[t,s,l].filter(g=>g).join("-")}`,c=useMemo(()=>e.map(g=>g.accessorKey),[e]),p=useMemo(()=>o.filter(g=>typeof g=="object"&&g!==null&&!Array.isArray(g)&&Object.keys(g).some(h=>c.includes(h))),[c,o]),m=useMemo(()=>e.map(g=>({...g,Cell:({renderedCellValue:h})=>jsx(ye,{html:`${h}`,isPreview:!0}),filterFn:"contains"})),[e]),f=Sa();return useEffect(()=>{(async()=>{try{let h=f||"en",b=`${h.toUpperCase()}`,v=await import(`mantine-react-table/locales/${h}.js`);i(v[`MRT_Localization_${b}`]);}catch(h){console.error("Error loading translations:",h);}})();},[f]),createElement(MantineReactTable,{...r,autoResetPageIndex:!1,columns:m,data:p,enableColumnFilterModes:!0,enableFilterMatchHighlighting:!1,globalFilterFn:"contains",key:u,layoutMode:"grid",localization:n,state:{...r.state,isFullScreen:!1}})}var RC=N(()=>{d();ft();he();});function Qf({label:e,url:t,settings:o}){let{align:r}=o;return jsx(Group,{position:r,grow:r==="justify",children:jsx(Button,{component:"a",target:"_blank",href:t||"",children:e||"Button"})})}var IC=N(()=>{d();});function eg(e){let t=useDispatch(),o=useContext(_e),r=$(ee=>ee.status.query),n=Uz(e.id),i=useMantineTheme(),{allLabel:a,colorKey:s,data:l,defaultValue:u,defaultValueType:c,iconKey:p,levels:m,limit:f,placeholder:g,searchIndexKey:h,searchIndexSeparator:b,resetSectionVars:v,section:C}=e,[R,y]=useState(!1),[A,S]=useState(!0),[E,L]=useState(""),[P,D]=useState(!1),[M,z]=useState([""].slice(1)),{sectionVariables:I,resetSectionVariables:w}=Ze(C),O=useMemo(()=>Gz(r[`${n}-value`],u),[r,u,n]),_=useMemo(()=>r[`${n}-type`]||c,[r,c,n]),H=useCallback(()=>{v==="true"&&I&&w();},[v,I,w]),G=useCallback(ee=>{H(),t(pi(o,`${n}-value`,ee.join()));},[t,o,n,H]),te=useCallback(ee=>{H(),t(pi(o,`${n}-type`,ee));},[t,o,n,H]),j=useRef(null),W=useRef(!1),q=useRef(!!f&&f<O.length),V=M.length,K=m[V],Z=M.filter(Boolean);M.length>0&&Z.length===0&&Z.push(`${a} ${K?.label}`),useEffect(()=>{let ee=()=>{S(!0);};return window.addEventListener("touchmove",ee),()=>{window.removeEventListener("touchmove",ee);}},[]);let F=useMemo(()=>Vz(l,m,s,p,h,b),[s,l,p,m,h,b]),J=useMemo(()=>{let ee=Fz(E),Ce=Array.from($z(F,ee)).reverse();return P?Ce:M.reduce((Y,B)=>Y.filter(X=>!B||X.searchindex.indexOf(B)>-1),Ce.filter(Y=>Y.type===K?.value))},[K,F,E,P,M]),[se,re]=useState(-1),ce=Math.min(se,J.length-1),fe=useCallback(ee=>{let Ce=M.concat(ee);P&&D(!1),z(Ce);},[P,M]),Ie=useCallback(()=>{let ee=M.slice(0,V-1);P&&D(!1),z(ee);},[P,M,V]),xe=useCallback(ee=>{L(ee.currentTarget.value),!q.current&&l.length>0&&y(!0);},[l,L,q,y]),U=useCallback(()=>{L(""),G([]),j.current?.focus(),f&&(q.current=!1);},[L,G,j,f,q]),oe=useCallback(ee=>{let Ce=O.filter(Y=>Y!==ee);G(Ce),f&&Ce.length<f&&(q.current=!1);},[O,G,f,q]),pe=useCallback(ee=>{_||te(ee.type),_!==ee.type?(te(ee.type),G([ee.value])):O.includes(ee.value)?oe(ee.value):f?(O.length<f&&G([...O,ee.value]),O.length===f&&G([...O.slice(1),ee.value])):G([...O,ee.value]);},[_,te,G,O,oe,f]),Ne=useCallback(()=>{O.length>0&&E.length===0&&(G(O.slice(0,-1)),y(!0),f&&(q.current=!1)),E.length>0&&L(E.slice(0,-1));},[O,E,G,L,y,f,q]),Be=useCallback(()=>{S(ee=>ee&&(W.current=ee,!ee)),re(ee=>ee+1>=J.length?ee:ee+1);},[re,J]),ze=useCallback(()=>{let ee=J[ce];ee&&pe(ee);},[J,ce,pe]),at=useCallback(()=>{y(!1);},[y]),Qt=useCallback(()=>{re(()=>(Ie(),0));},[re,Ie]),zr=useCallback(()=>{let ee=J[ce];!P&&ee&&ee.type!==m[m.length-1]?.value&&re(()=>(fe(ee.name),0));},[J,ce,P,m,re,fe]),jo=useCallback(()=>{S(ee=>ee&&(W.current=ee,!ee)),re(ee=>ee-1<0?0:ee-1);},[re]),cr=useRef(null),Zt=du({count:J.length,estimateSize:()=>30,getScrollElement:useCallback(()=>cr.current,[]),overscan:10,rangeExtractor:useCallback(ee=>dl(ee),[])}),dn=({label:ee,onRemove:Ce,...Y})=>jsxs("div",{style:{alignItems:"center",backgroundColor:i.colorScheme==="dark"?i.colors.dark[7]:i.colors.gray[1],borderRadius:i.radius.sm,cursor:"default",color:i.colorScheme==="dark"?i.colors.dark[0]:i.colors.gray[7],display:"flex",fontSize:rem(12),fontWeight:500,height:rem(22),margin:`calc(${i.spacing.xs} / 2 - ${rem(2)}) calc(${i.spacing.xs} / 2)`,maxWidth:`calc(100% - ${rem(10)})`,paddingLeft:`calc(${i.spacing.sm} / 1.5)`,paddingRight:0,userSelect:"none"},...Y,children:[jsx("span",{style:{display:"block",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:ee}),jsx(CloseButton,{"aria-hidden":!0,iconSize:"70%",onMouseDown:Ce,radius:2,size:"sm",sx:{color:i.colorScheme==="dark"?i.colors.dark[0]:i.colors.gray[7],marginLeft:`calc(${i.spacing.sm} / 6)`},tabIndex:-1})]}),mn=useMemo(()=>O.map(ee=>F.find(Ce=>Ce.value===ee)).filter(ee=>!!ee).map((ee,Ce)=>createElement(dn,{...ee,index:Ce,key:ee.value,onRemove:Y=>{Y.preventDefault(),Y.stopPropagation(),oe(ee.value);}})),[O]),Vr=forwardRef(function({color:Ce,icon:Y,label:B,value:X,...le},ue){return jsx("div",{ref:ue,style:{cursor:"pointer",width:"100%"},...le,children:jsxs(Group,{align:"center",noWrap:!0,spacing:"xs",w:"100%",children:[Y&&jsx(Box,{bg:Ce??"transparent",component:"img",w:20,h:20,src:Y}),jsx(Text,{lineClamp:1,size:"sm",children:B||X})]})})}),{settings:Wo}=e,Cs=e.hideLabel==="true"||!e.label?jsx(Fragment,{}):jsx(ye,{component:"div",html:e.label,size:"sm",style:Wo,isPreview:!0});return jsx(Input.Wrapper,{label:Cs,children:jsxs(Popover,{closeOnClickOutside:!0,keepMounted:!0,opened:R,onChange:y,onClose:()=>{re(0),L("");},onOpen:()=>{Zt.scrollToIndex(0);},shadow:"sm",width:"target",withinPortal:!0,children:[jsx(Popover.Target,{children:jsxs(Box,{"aria-haspopup":"listbox",component:"div",onMouseLeave:()=>re(0),sx:{position:"relative","& .defaultValue":{backgroundColor:i.colorScheme==="dark"?i.colors.dark[5]:i.colors.gray[3],color:i.colorScheme==="dark"?i.colors.dark[1]:i.colors.gray[7]}},tabIndex:-1,children:[jsx("input",{type:"hidden",value:O.join(",")}),jsx(Input,{component:"div",multiline:!0,onMouseDown:ee=>{ee.preventDefault(),!q.current&&l.length>0&&y(!R),j.current?.focus();},rightSection:O.length>0?jsx(CloseButton,{onClick:U,onMouseDown:ee=>ee.preventDefault(),variant:"transparent"}):jsx(IconSelector,{color:i.colors.gray[6],size:18,stroke:1.5}),style:{overflow:"hidden"},w:"100%",children:jsxs(Box,{component:"div","data-clearable":!0,sx:{alignItems:"center",boxSizing:"border-box",display:"flex",flexWrap:"wrap",marginLeft:`calc(-${i.spacing.xs} / 2)`,minHeight:`calc(${rem(36)} - ${rem(2)})`,"&[data-clearable]":{marginRight:rem(36)},"&::placeholder":{color:i.colorScheme==="dark"?i.colors.dark[3]:i.colors.gray[5],opacity:1}},children:[mn,jsx("input",{autoComplete:"off","data-mantine-stop-propagation":R,onChange:xe,onKeyDown:getHotkeyHandler([["ArrowDown",Be],["ArrowLeft",Qt],["ArrowRight",zr],["ArrowUp",jo],["Backspace",Ne],["Enter",ze],["Escape",at]]),placeholder:O.length===0?g:void 0,ref:j,readOnly:q.current,style:{appearance:"none",backgroundColor:"transparent",border:0,color:"inherit",flex:1,fontSize:i.fontSizes.sm,marginLeft:`calc(${i.spacing.xs} / 2)`,maxHeight:rem(22),minWidth:rem(60),outline:0,padding:0},type:"search",value:E})]})})]})}),jsx(Popover.Dropdown,{onMouseDown:ee=>ee.preventDefault(),p:0,children:jsx("div",{style:{display:"flex",maxHeight:rem(300)},children:jsx(Box,{component:"div","data-combobox-popover":!0,onMouseDown:ee=>ee.preventDefault(),role:"listbox",sx:{width:"100%"},tabIndex:-1,children:jsxs(Stack,{h:"100%",py:"xs",spacing:"xs",w:"100%",children:[m.length>1&&jsxs(Stack,{spacing:"xs",children:[jsxs(Group,{onClick:ee=>{ee.stopPropagation();},px:"xs",position:"center",spacing:"xs",children:[jsx(Button,{onClick:()=>{re(0),D(!0),z([]),J.length>0&&Zt.scrollToIndex(0);},size:"xs",variant:P?"filled":"outline",children:a}),m.map((ee,Ce)=>jsx(Button,{onClick:()=>{P&&D(!1);let Y=[""].slice(1),B=Ce;for(;B--;)Y[B]=M[B]||"";re(0),z(Y),J.length>0&&Zt.scrollToIndex(0);},size:"xs",variant:!P&&M.length===m.findIndex(Y=>Y.value===ee?.value)?"filled":"outline",children:ee?.label},ee?.value))]}),jsx(Divider,{})]}),V>0&&jsxs(Group,{align:"center",noWrap:!0,px:"xs",children:[jsx(ActionIcon,{onClick:Ie,size:"sm",children:jsx(IconChevronLeft,{})}),jsx("div",{children:Z.map(ee=>jsx(Text,{lineClamp:1,size:"xs",children:ee},`${ee}`))})]}),jsx(ScrollArea,{mah:250,onWheel:()=>S(!0),px:"xs",style:{overflow:"auto",width:"100%"},viewportRef:cr,viewportProps:{tabIndex:-1},w:"100%",children:jsx("div",{style:{height:`${Zt.getTotalSize()}px`,position:"relative",width:"100%"},children:Zt.getVirtualItems().map(ee=>{let Ce=J[ee.index],Y=ce===ee.index,B=O.includes(Ce.value);return J.length>0&&Y&&!A&&Zt.scrollToIndex(ce),jsxs(Group,{"aria-selected":Y,align:"center","data-hovered":Y||void 0,"data-index":ee.index,"data-selected":B,id:Ce.vale,noWrap:!0,onMouseEnter:X=>{X.preventDefault(),X.stopPropagation(),A&&(re(ee.index),S(!1));},onMouseMove:X=>{X.preventDefault(),X.stopPropagation(),S(!0);},onMouseDown:X=>{X.preventDefault(),pe(Ce);},position:"apart",ref:Zt.measureElement,role:"option",spacing:"xs",sx:X=>({borderRadius:X.radius.xs,padding:"15px 5px 15px",paddingLeft:P&&10*m.findIndex(le=>le?.value===Ce.type)||5,position:"absolute",top:0,left:0,height:`${ee.size}px`,transform:`translateY(${ee.start}px)`,width:"100%","&[data-hovered]":{backgroundColor:X.colorScheme==="dark"?X.colors.dark[4]:X.colors.gray[1]},"&:hover":{backgroundColor:X.colorScheme==="dark"?X.colors.dark[4]:X.colors.gray[1]}}),tabIndex:-1,children:[jsx(Vr,{index:ee.index,...Ce}),!P&&Ce.type!==m[m.length-1]?.value&&jsx(ActionIcon,{onMouseDown:X=>{X.preventDefault(),X.stopPropagation(),fe(Ce.name);},size:"sm",tabIndex:-1,children:jsx(IconChevronRight,{})})]},Ce.value)})})})]})})})})]})})}var Vz,Fz,$z,Uz,Gz,DC=N(()=>{d();Ym();ft();Lt();ie();he();hr();Vz=(e=[],t=[],o="",r="",n="",i="|")=>{let a=t.map(h=>h.value).slice(),s=`${a.pop()}`,l=h=>h[o],u=h=>h[r],c=h=>{if(h[n])return typeof h[n]=="string"?h[n].split(i):h[n]},p=new Set,m=[],f=[],g=nest().rollup(h=>{let b=h[0],v=P=>P&&P.value&&!p.has(P.value),C=a.map(P=>b[`${P} ID`]),R=a.map(P=>b[P]),y=a.map((P,D)=>{if(f[D]!==R[D]){f[D]=R[D];let M=l[D]||l[l.length-1]||l,z=u[D]||u[u.length-1]||u,I=c[D]||c[c.length-1]||c;return {color:M(b,P)||void 0,icon:z(b,P)||void 0,value:`${C[D]}`,label:R[D],name:R[D],type:P,searchindex:R.slice(0,D+1).concat(I(b,P)).join("|")}}return {}}).filter(v);y.forEach(P=>p.add(P.value));let A=l[l.length-1]||l,S=u[u.length-1]||u,E=c[c.length-1]||c,L=h.map(P=>({color:A(P,s)||void 0,icon:S(P,s)||void 0,value:`${P[`${s} ID`]}`,label:P[s],name:P[s],type:s,searchindex:R.concat(P[s]).concat(E(P,s)).join("|")}));m.push(...y.concat(L));});return a.forEach(h=>{g.key(b=>`${b[`${h} ID`]}|${b[h]}`);}),g.entries(e),m},Fz=e=>{if(!e)return /./i;let t=e.normalize("NFD").replace(/[.*+?^${}()|[\]\\]/g,"\\$&").replace(/[\u0300-\u036f]/g,"").replace(/\s+/g,"[^|]+");return RegExp(t,"i")},$z=(e,t)=>{let o=e.length,r,n=s=>r&&r.searchindex.includes(s.searchindex),a={next:()=>{for(let s=o-1;s>-1;s--){let l=e[s];if(t.test(`${l.value} ${l.label} ${l.searchindex}`)||n(l))return r=l,o=s,{done:!1,value:l}}return {done:!0,value:void 0}},[Symbol.iterator]:()=>a};return a},Uz=e=>`multihierarchySelector${e}`,Gz=(e,t)=>e&&typeof e=="string"?e.split(","):t;});var NC={};Zp(NC,{default:()=>eV});function Zz({block:e,active:t,locale:o,variables:r,debug:n,configOverride:i={}}){let a=Xz(),s=so(e),l=po(o),u={variables:r},c=useRouter(),{sectionVariables:p,setSectionVariables:m,resetSectionVariables:f}=Ze(e.section_id),g=useMemo(()=>{if(!t)return {error:"Activate to View"};if(!s?.logic)return {error:"Add a Configuration"};let P=mr({logic:s.logic},l,u).logic,D={router:c,section:{variables:p,setVariables:m,resetVariables:f}};return Ga(P,l,r,o,e.id,{},D)},[s?.logic,t,r,p]);useMemo(()=>{if(!t||!s?.logic)return {};let{logic:P}=s,{vars:D}=To("variables",r,P,l,void 0,u);return D},[e,t]);let {type:b}=g.config||{},v=b&&tg[b]?b:"Treemap";b||(g.config={error:'Visualization missing "type"'}),tg[b]||(g.config={error:`"${b}" is not a valid Visualization Type`});let C=tg[v],R=g.error||g.config?.error||!1;if(R)return jsx(Center,{style:{height:"100%"},children:jsx(Badge,{color:"gray",variant:"outline",children:R},"type")});let{_data:y,...A}=g.config,S={locale:o,variables:r,...A,...i};a.print&&(S.detectVisible=!1);!a.print&&b!=="Graphic"&&b!=="HTML";return jsx("div",{style:{display:"flex",flex:"1 1 100%"},children:jsx(Qr,{fallback:jsx("p",{children:"Error in d3plus viz config."}),children:jsx(C,{style:{flex:1},dataFormat:P=>{g.data&&Array.isArray(g.data)&&g.data.length>1&&g.data.some(I=>typeof I=="string")?P:[P];let z;try{z=g.dataFormat(P);}catch(I){console.log("Error in dataFormat: ",I),z=[];}return z},linksFormat:g.linksFormat,nodesFormat:g.nodesFormat,topojsonFormat:g.topojsonFormat,config:{...S}},"viz-key")})})}var Xz,Qz,tg,eV,zC=N(()=>{d();ca();ei();df();vu();ko();he();Su();Xz=()=>({}),Qz={},tg={HTML:gl,...w_,...Qz};eV=memo(Zz,(e,t)=>e.block.contentByLocale.logic.content===t.block.contentByLocale.logic.content&&e.active===t.active&&e.locale===t.locale&&JSON.stringify(e.variables)===JSON.stringify(t.variables)&&JSON.stringify(e.configOverride)===JSON.stringify(t.configOverride));});var oV,ct,VC=N(()=>{d();ge();nC();aC();lC();cC();dC();mC();fC();yC();SC();TC();EC();RC();IC();DC();oV=P_(()=>Promise.resolve().then(()=>(zC(),NC)),{ssr:!1}),ct={[k.PARAGRAPH]:Lf,[k.STAT]:Mf,[k.SUBTITLE]:Bf,[k.TITLE]:Df,[k.SELECTOR]:zf,[k.VIZ]:oV,[k.GENERATOR]:Ff,[k.SECTION_FLAG]:Ff,[k.IMAGE]:$f,[k.NAV]:Hf,[k.RELATED]:Wf,[k.RESET_BUTTON]:qf,[k.COMPARISON_BUTTON]:Yf,[k.TABLE]:Xf,[k.BUTTON]:Qf,[k.MULTIHIERARCHY_SELECTOR]:eg};});function rg(e){return og[e]||IconDice}var og,ng=N(()=>{d();ge();og={[k.TITLE]:IconHeading,[k.GENERATOR]:IconApi,[k.SECTION_FLAG]:IconFlag,[k.STAT]:IconPercentage,[k.VIZ]:IconChartBar,[k.PARAGRAPH]:IconAlignLeft,[k.SELECTOR]:IconSelector,[k.IMAGE]:IconPhoto,[k.TABLE]:IconTable,[k.MULTIHIERARCHY_SELECTOR]:IconListTree};});function ag(e){return ig[e]}var ig,sg=N(()=>{d();ge();ig={[k.TITLE]:"Title",[k.GENERATOR]:"Data",[k.STAT]:"Stat",[k.VIZ]:"Visualization",[k.PARAGRAPH]:"Paragraph",[k.SELECTOR]:"Selector",[k.SUBTITLE]:"Subtitle",[k.RESET_BUTTON]:"Reset Button",[k.COMPARISON_BUTTON]:"Comparison Button",[k.RELATED]:"Related Reports",[k.NAV]:"Navigation",[k.IMAGE]:"Image",[k.TABLE]:"Table",[k.BUTTON]:"Button",[k.FALLBACK]:"Fallback",[k.SECTION_FLAG]:"Section Flag",[k.MULTIHIERARCHY_SELECTOR]:"Multihierarchy Selector"};});var fV,Ha,bl=N(()=>{d();ge();Im();VC();ng();sg();fV={[k.GENERATOR]:{type:k.GENERATOR,renderer:ct[k.GENERATOR],renderPreviewOnEdit:!1},[k.SECTION_FLAG]:{type:k.SECTION_FLAG,renderer:ct[k.SECTION_FLAG],renderPreviewOnEdit:!1},[k.IMAGE]:{type:k.IMAGE,renderer:ct[k.IMAGE],renderPreviewOnEdit:!1},[k.PARAGRAPH]:{type:k.PARAGRAPH,renderer:ct[k.PARAGRAPH],renderPreviewOnEdit:!0,evalWhenNonActive:!0},[k.RELATED]:{type:k.RELATED,renderer:ct[k.RELATED],renderPreviewOnEdit:!1,evalWhenNonActive:!0},[k.SELECTOR]:{type:k.SELECTOR,renderer:ct[k.SELECTOR],adapter:Ao[k.SELECTOR],nonActiveAdapter:()=>Ao[k.SELECTOR]({name:"Selector Preview"}),renderPreviewOnEdit:!1},[k.STAT]:{type:k.STAT,renderer:ct[k.STAT],renderPreviewOnEdit:!0,evalWhenNonActive:!0},[k.SUBTITLE]:{type:k.SUBTITLE,renderer:ct[k.SUBTITLE],renderPreviewOnEdit:!0,evalWhenNonActive:!0},[k.TITLE]:{type:k.TITLE,renderer:ct[k.TITLE],renderPreviewOnEdit:!0,evalWhenNonActive:!0},[k.VIZ]:{type:k.VIZ,renderer:ct[k.VIZ],renderPreviewOnEdit:!1},[k.NAV]:{type:k.NAV,renderer:ct[k.NAV],renderPreviewOnEdit:!0,evalWhenNonActive:!0},[k.RESET_BUTTON]:{type:k.RESET_BUTTON,renderer:ct[k.RESET_BUTTON],renderPreviewOnEdit:!0,evalWhenNonActive:!0},[k.COMPARISON_BUTTON]:{type:k.COMPARISON_BUTTON,renderer:ct[k.COMPARISON_BUTTON],renderPreviewOnEdit:!0,evalWhenNonActive:!0},[k.TABLE]:{type:k.TABLE,renderer:ct[k.TABLE],renderPreviewOnEdit:!1,evalWhenNonActive:!1},[k.BUTTON]:{type:k.BUTTON,renderer:ct[k.BUTTON],renderPreviewOnEdit:!0,evalWhenNonActive:!0},[k.MULTIHIERARCHY_SELECTOR]:{type:k.MULTIHIERARCHY_SELECTOR,renderer:ct[k.MULTIHIERARCHY_SELECTOR],adapter:Ao[k.MULTIHIERARCHY_SELECTOR],nonActiveAdapter:()=>Ao[k.MULTIHIERARCHY_SELECTOR]({label:"Multihierarchy Selector Preview"}),renderPreviewOnEdit:!1}},Ha=fV;});d();d();d();function Pb(e){let{onlyIcon:t,href:o,version:r}=e,n=jsx(Text,{c:"blue.5",ta:"left",children:jsxs(Group,{position:"left",spacing:"xs",children:[jsx(IconCircleDashed,{size:30}),!t&&jsxs(Text,{c:"black",fs:"lg",children:["Bespoke CMS",jsx(Text,{span:!0,c:"dimmed",size:"xs",ml:3,children:r})]})]})});return o?jsx(gM,{href:o,passHref:!0,children:jsx(UnstyledButton,{p:10,w:"100%",children:n})}):n}d();var Db=Jr__default.createContext(void 0);function _b(e){let[t,o]=useState(!1),[r,n]=useState(null),i=Jr__default.useMemo(()=>{function u(c,p){return p?{show:()=>u(c)}:new Promise((m,f)=>{n({request:c,onResolve:m,onReject:f}),o(!0);})}return {newConfirmation:u}},[]),a=()=>{o(!1),setTimeout(()=>n(null),200);},s=useCallback(u=>{!t||!r||(r.onResolve(u),a());},[t,r]),l=useCallback(u=>{!t||!r||(r.onReject(u),a());},[t,r]);return jsxs(Db.Provider,{value:i,children:[r&&jsx(fI,{opened:t,request:r.request,onConfirm:s,onCancel:l}),e.children]})}function fI(e){let{request:t,opened:o,onCancel:r,onConfirm:n}=e,i=useMantineTheme();return jsxs(Modal,{centered:!0,zIndex:1002,opened:o,title:t.title,onClose:r,children:[t.message,jsxs(Group,{position:"right",style:{marginTop:i.spacing.sm},children:[jsx(Button,{onClick:r,children:t.cancelText||"Cancel"}),jsx(Button,{color:"red",onClick:n,children:t.confirmText||"Confirm"})]})]})}function Pt(){let e=useContext(Db);if(e===void 0)throw new Error("useConfirmationDialog must be used within ConfirmationDialogProvider.");return e}Lt();Nc();d();d();d();function ka(e){return jsxs("span",{style:{display:"flex",alignItems:"center",gap:"0.5rem"},children:[e.icon,e.children]})}ie();Lt();he();bi();bi();d();d();ie();ao();br();function E0(){let{user:e,update:t,status:o}=xt(),r=o==="loading",{localeDefault:n}=Ve(),i=ne();return useEffect(function(){!r&&e&&e.bespoke_user_metadata&&typeof e.bespoke_user_metadata.preferredLocale=="string"&&i(Q.setPreferredLocale(e.bespoke_user_metadata.preferredLocale||n));},[r,e]),{user:e,isLoading:r,update:t,status:o}}var Hs=E0;function js(e){let{user:t}=Hs();return useMemo(()=>{if(t&&t.bespoke_app_metadata&&t.bespoke_app_metadata.reports&&Array.isArray(t.bespoke_app_metadata.reports)){let r=t.bespoke_app_metadata.reports.find(n=>n.reportId===e);if(r&&r.favorites)return r.favorites}},[t,e])}d();function Sv(e){let{left:t,center:o,right:r}=e;return jsx(Header,{height:50,p:"xs",pos:"sticky",zIndex:98,children:jsxs(Group,{position:"apart",children:[jsx("div",{className:"left",children:t}),jsx("div",{className:"center",children:o}),jsx("div",{className:"right",children:r})]})})}d();d();ie();var P0=e=>e.status.locales.map(t=>({value:t,label:t.toUpperCase()}));function xv(){return $(P0)}ie();var N0=e=>({input:{border:"none",background:e.colors.blue[0],borderRadius:e.radius.sm,color:e.colors.blue[7],fontSize:12,fontWeight:700,width:80},item:{fontSize:12},rightSection:{pointerEvents:"none"}});function Ws({value:e,onChange:t,defaultValue:o,selectProps:r={},loading:n=!1}){let i=xv(),a=$(c=>c.status.localeDefault),[s,l]=useUncontrolled({value:e,defaultValue:o||a,finalValue:a,onChange:t}),u=useMantineTheme();return jsx(Select,{...r,data:i,value:s,onChange:l,styles:{...N0(u),...r?.styles},icon:jsx(IconLanguage,{size:"0.8rem",color:u.colors.blue[7]}),rightSection:n?jsx(Loader,{size:"0.8rem"}):jsx(IconChevronDown,{size:"0.8rem",color:u.colors.blue[7]})})}d();ie();d();d();ao();Ks();Ic();d();Ic();function $t(e){let t=Number.parseInt(`${e||""}`,10);if(Number.isNaN(t)||!Number.isFinite(t))throw new ni(400,`Invalid numeric parameter: ${e}`);return t}function Me(e){return e==null||e===""?[]:Array.isArray(e)?e:e.toString().split(",")}d();var mo={ADMIN:"Admin",EDITOR:"Editor",WRITER:"Writer"};var{localeDefault:vn}=Ve();function Tv(e){let t=Me(e.locale)[0]||vn||"en",o=t==="all"||Fc(e.all),r=Me(e.mode)[0],i=(Me(e.output)[0]||"full")==="lite"?"lite":"full",a=parseInt(Me(e.related)[0],10)||5,s=Me(e.variant).map($t);if(s.length===0&&(s=Me(e["variant[]"]).map($t)),r==="ids")return {all:o,mode:r,variant:s,output:i,locale:o?vn:Ft(t),ids:Me(e.ids||e["ids[]"])};if(r==="content_ids")return {all:o,mode:r,variant:s,output:i,locale:o?vn:Ft(t),content_ids:Me(e.content_ids||e["content_ids[]"]).map($t)};if(r==="slugs")return {all:o,mode:r,variant:s,output:i,locale:o?vn:Ft(t),slugs:Me(e.slugs||e["slugs[]"]).map(l=>{let[u,c]=l.split("/");return {variantSlug:u,memberSlug:c}})};if(r==="related")return {all:o,mode:r,locale:o?vn:Ft(t),related:a,current_ids:Me(e.current_ids||e["current_ids[]"]).map($t),report_ids:Me(e.report_ids||e["report_ids[]"]).map($t),dimension_ids:Me(e.dimension_ids||e["dimension_ids[]"]).map($t),variant_ids:Me(e.variant_ids||e["variant_ids[]"]).map($t),output:i};if(r==="whole")return {all:o,mode:r,variant:s,locale:o?vn:Ft(t),output:i};throw new ni(400,`Invalid mode: '${r}'`)}function $c(e){let t=Me(e.locale)[0]||vn||"en",o=t==="all",r=Me(e.format)[0],n=r?r==="nested":o,i=Me(e.variant).map($t);i.length===0&&(i=Me(e["variant[]"]).map($t));let a=Me(e.dimension).map($t);a.length===0&&(a=Me(e["dimension[]"]).map($t));let s=Me(e.report).map($t);return s.length===0&&(s=Me(e["report[]"]).map($t)),{query:Me(e.query||e.q)[0]||"",locale:o?vn:t,preferredLocale:Me(e.preferredLocale)[0],limit:Me(e.limit).map($t)[0]??5,format:n?"nested":"plain",includes:Fc(e.includes,{default:!0}),visible:Fc(e.visible,{default:!0}),noImage:Fc(e.noImage,{default:!1}),variant:i,dimension:a,report:s,all:o,sort:Me(e.sort)[0],direction:Me(e.direction)[0],offset:Number(e.offset||0)}}ie();d();he();ie();d();var H0={maxWidth:100,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"};function Ys({children:e,tooltip:t=!1,onClick:o=()=>{},textProps:r={},clickable:n=!1}){return jsx(Tooltip,{label:e,disabled:!t,children:jsx(UnstyledButton,{onClick:o,children:jsxs(Group,{spacing:"xs",align:"center",noWrap:!0,children:[jsx(Text,{fz:"0.675rem",tt:"uppercase",fw:700,color:"gray.7",sx:H0,...r,children:e}),n&&jsx(ThemeIcon,{color:"gray.7",size:"0.4rem",bg:"transparent",variant:"default",sx:{border:"none"},children:jsx(IconTriangleInvertedFilled,{})})]})})})}ao();d();var Uc=e=>t=>({input:{border:"none !important",outline:"none",background:t.colors.gray[1]},dropdown:{padding:0,background:t.fn.lighten(t.colors.gray[1],.8),borderColor:t.colors.gray[4],borderRadius:t.radius.md,width:"280px !important",gap:t.spacing.xs,":before":{display:"block",content:`"${e}"`,fontSize:t.fontSizes.xs,color:t.colors.gray[5],paddingLeft:t.spacing.sm,paddingRight:t.spacing.sm,paddingBottom:t.spacing.xs,paddingTop:t.spacing.xs}}});function oP(e,t,o){return o===t?e.map(r=>({id:r.id,value:`${r.id}`,name:r.name})):e.map(r=>{let n=r.contentByLocale.find(i=>i.locale===o);return {id:r.id,value:`${r.id}`,name:r.name,refName:n?n.name:null}})}var Cv={overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},rP=forwardRef(function({id:t,name:o,refName:r,...n},i){return jsxs(Group,{position:"apart",ref:i,...n,children:[jsxs(Stack,{spacing:0,children:[jsx(Text,{maw:"200px",sx:Cv,children:o}),r&&jsx(Text,{fz:10,c:"#666",maw:"140px",sx:Cv,children:r})]}),jsx(Text,{color:"gray.5",size:"sm",children:t})]},`${t}-${o}`)});function Qd(e){let{dimensionId:t,variantId:o,value:r,defaultValue:n,onChange:i,locale:a}=e,s=ne(),{localeDefault:l}=Ve(),u=xa(),c=a||l,[p,m]=useState([]),[f,g]=useState(""),[h]=useDebouncedValue(f,500),[b,v]=useState(!1),[C,R]=useState(!1),[y,A]=useUncontrolled({value:r,defaultValue:n,finalValue:void 0,onChange:i?M=>i(M):void 0}),S=useRef(null),E=useClickOutside(()=>R(!1)),L=useMergedRef(S,E),P=M=>{let z=p.find(I=>I.id===M.id);z&&(g(z.name?z.name:""),A(z),R(!1));};useEffect(function(){v(!0);let z={query:h,locale:c===u?c:"all",variant:[o],dimension:[t],limit:5,visible:!1,includes:!0,noImage:!1,format:"plain",all:!0,preferredLocale:u,report:[]};s(Q.searchMember(z)).then(I=>{if(I&&I.results){let w=I.results.map(O=>({...O,currentLocale:c,name:(O.contentByLocale&&O.contentByLocale.find(_=>_.locale===c)||O).name}));m(w),v(!1),w.length===0&&h===""&&(m([]),v(!1));}});},[s,h,c,o,t,u]),useEffect(()=>{p.length&&!y?.name&&i&&i(p[0]);},[p,i]);let D=oP(p,c,u);return useEffect(()=>{setTimeout(()=>{S.current&&S.current.focus();},200);},[C]),C||!y?.name?jsx(Autocomplete,{ref:L,value:f,onChange:g,data:D,itemComponent:rP,placeholder:"Search members.",nothingFound:"No members found.",rightSection:b&&jsx(Loader,{size:"xs"}),filter:()=>!0,onItemSubmit:P,size:"xs",w:130,styles:Uc("Members")}):jsx(Ys,{onClick:()=>R(!0),textProps:{color:"gray.6"},tooltip:!0,clickable:!0,children:y.name})}d();ie();function Zd(e){let o=fi(e).data,r=Hd(o?.variants);return r.isSuccess?r.data.map(n=>({value:`${n.id}`,label:n.name})):[]}function em(e){let{dimension:t,value:o,onChange:r}=e,[n,i]=useState(!1),a=Zd(t),s=useClickOutside(()=>i(!1)),l=a.length===1||!n,[u,c]=useUncontrolled({value:o?String(o):void 0,defaultValue:a[0]?a[0].value:"",finalValue:void 0,onChange:r?f=>r(Number(f)):void 0}),p=f=>c(f),m=a.find(f=>f.value===u)||a[0];return l?jsx(Ys,{onClick:()=>i(!0),clickable:a.length>1,children:m?m.label:"No Variant"}):jsx(Select,{ref:s,data:a,value:u,onChange:p,w:140,size:"xs",styles:Uc("Variants"),initiallyOpened:!0})}function Hc(e){let{dimensionId:t,locale:o,onSelect:r,value:n}=e,i=ne(),a=Zd(t),[s,l]=useUncontrolled({defaultValue:void 0,finalValue:void 0,onChange:r?m=>r(m):void 0}),[u,c]=useUncontrolled({value:void 0,defaultValue:n?.variantId,finalValue:a[0]?Number(a[0].value):0,onChange:()=>{l({});}}),p=n?.memberId;return useEffect(function(){p&&i(Q.readMember(Tv({locale:o,content_ids:[`${p}`],all:"false",mode:"content_ids"}))).then(f=>{if(f&&f.results&&f.results[0]){let g=f.results[0];l({locale:o,name:g.name,contentByLocale:g.contentByLocale,contentId:g.content_id});}else console.error("default member is not found");});},[p]),jsxs(Flex,{gap:"xs",px:"xs",align:"center",children:[jsx(em,{dimension:t,value:u,onChange:c},`dimension-${t}`),jsx(Text,{fz:"xs",tt:"uppercase",color:"gray.6",fw:700,children:"/"}),u&&jsx(Qd,{variantId:u,dimensionId:t,value:s,onChange:l,locale:o},`variant-${u}`)]})}Lt();bi();function rm({report:e,defaultMembers:t,locale:o}){let[r,n]=useState(!1),i=ne(),a=ro(),s=useContext(_e),l=e&&e.dimensions?e.dimensions:[],u=$(g=>g.status.previews),c=u.map(g=>({variantId:g.variant_id,memberId:g.content_id})),p=a.query.preview,m=Array.isArray(p)?p.join("!"):p||"",f=g=>{let b=e.dimensions.map(C=>{let R;if(g)if(g.dimension_id===C)R=g;else {let y=u.find(A=>A?A.dimension_id===C:!1);y&&(R=y);}return R}).map(C=>C?{...C,report_name:C.report?.name||C.report_name,report_id:C.report?.id||C.report_id,dimension_id:C.dimension?.id||C.dimension_id,dimension_name:C.dimension?.name||C.dimension_name,variant_id:C.variant?.id||C.variant_id,variant_name:C.variant?.name||C.variant_name,variant_slug:C.variant?.slug||C.variant_slug}:{}),v=b.map(yP).join("!");if(v&&m!==v){let C=b.filter(R=>R.content_id).length===l.length;i(Q.setPreviews(b)),C&&(a.setSearchParam("preview",v),i(Q.recalculateVariables(s,{previews:b})));}};return useEffect(function(){let h=m.split("!").filter(Boolean);h.length===l.length&&l.length>0?i(Q.readMember({mode:"slugs",slugs:h.map(b=>{let[v,C]=b.split("/");return {variantSlug:v,memberSlug:C}}),locale:o,output:"full"})).then(b=>i(Q.recalculateVariables(s,{previews:b.results}))).then(()=>n(!0)):t&&t.length===l.length?i(Q.readMember({mode:"content_ids",variant:t.map(b=>b.variantId),content_ids:t.map(b=>b.memberId),locale:o,output:"full"})).then(b=>i(Q.recalculateVariables(s,{previews:b.results}))).then(()=>n(!0)):n(!0);},[]),jsx(Group,{spacing:"xs",children:r&&l.map((g,h)=>jsxs(Fragment$1,{children:[jsx(Text,{fw:700,fz:"xs",children:"/"}),jsx(Hc,{dimensionId:g,onSelect:f,value:c[h]?c[h]:void 0,locale:o},g)]},g))})}function yP(e){return `${"variant_slug"in e?e.variant_slug:e?.variant?.slug}/${e.slug}`}d();ie();d();ie();d();d();hn();d();fc();var Js="dimension",wv="Dimension";d();var nm="formatter",Pv="Formatter";d();hn();fc();ad();d();var im="variant",Ov="Variant";var Mv={[gc]:ay,[Js]:wv,[nm]:Pv,[Zn]:ty,[Ls]:ry,[im]:Ov};ie();function yr({id:e,type:t,warning:o,disabled:r=!1}){let n=useDispatch(),{newConfirmation:i}=Pt(),a=useCallback(async()=>{let s=Mv[t]||"Entity",l=o||`Delete this ${s} and all its contents? This action cannot be undone.`;try{r||(await i({title:"Are you sure?",message:l,confirmText:"Yes, Delete it."}),n(Q.deleteEntity(t,e)));}catch{console.debug(`${s} deletion aborted:`,e);}},[e,t,o,r,n]);return jsx(ActionIcon,{disabled:r,color:"red",variant:"transparent",onClick:a,children:jsx(IconTrash,{size:18})})}function _P({for:e,onEdit:t}){let o=useMantineTheme(),{newConfirmation:r}=Pt(),n=o.colorScheme==="dark"?o.colors.dark[1]:o.colors.gray[7],i=useCallback(async()=>{try{await r({title:"Are you sure?",message:"Modifying dimensions can be destructive and break the site. Make sure you know what you're doing!",confirmText:"Continue"}),t(e.id);}catch{console.debug("Dimension edition aborted.");}},[t]),{name:a,ordering:s}=e;return jsxs(Card,{shadow:"xs",withBorder:!0,style:{margin:o.spacing.sm},children:[jsx(Group,{position:"apart",children:jsxs(Center,{children:[jsx(IconDatabase,{size:22}),jsx(Space,{w:"xs"}),jsx(Text,{weight:"bold",children:a})]})}),jsxs(Text,{size:"sm",style:{color:n,lineHeight:2},children:["Order:",s]}),jsx(Space,{w:"xs"}),jsxs(Group,{position:"apart",children:[jsxs(Center,{children:[jsx(IconServer,{size:22}),jsx(Space,{w:"xs"}),jsx(Text,{weight:"bold",children:"Variants"})]}),jsx(Badge,{variant:"light",children:0})]}),jsx("ul",{children:e.variants.map(l=>jsx("li",{style:{color:n},children:jsx(zP,{id:l})},l))}),jsxs(Group,{position:"apart",children:[jsx(Button,{onClick:i,leftIcon:jsx(IconPencil,{}),compact:!0,children:"Edit"}),jsx(yr,{id:e.id,type:"dimension",warning:"Deleting dimensions can be destructive and break the site. Make sure you know what you're doing!"})]})]})}var _v=oo(_P,fi);function NP({for:e}){return jsx(Text,{size:"sm",children:`${e.name}: /${e.slug}`})}var zP=oo(NP,gi);d();Xs();ie();d();function Pa(e){let{target:t,fields:o,onSubmit:r}=e,[n,i,a]=XP(o||[]),[s,l]=useDisclosure(!1,{onClose:a}),u=useCallback(c=>{s&&(c.preventDefault(),typeof r=="function"&&r(i),l.close());},[i,s]);return useHotkeys([["enter",u]]),n.length===0?t:jsxs(Popover,{onClose:l.close,opened:s,position:"right",trapFocus:!0,withArrow:!0,withinPortal:!0,zIndex:1001,children:[jsx(Popover.Target,{children:Jr__default.cloneElement(e.target,{onClick:l.open})}),jsx(Popover.Dropdown,{children:jsxs("form",{onSubmit:u,children:[n,jsx(Button,{type:"submit",children:"Submit"})]})})]})}function XP(e){let[t,o]=useState({}),r=e.map(a=>encodeURIComponent(`${a.name}:${a.type}/${a.label}`)).join("&"),n=useCallback(()=>{o({});},[]);return [useMemo(()=>e.map(a=>{let s=`${t[a.name]??(a.initialValue||"")}`;return a.type==="checkbox"?jsx(Checkbox,{label:a.label,name:a.name,checked:s=="true"},a.name):a.type==="radio"?jsx(Radio.Group,{label:a.label,value:s,children:a.options.map(l=>jsx(Radio,{label:l.label,value:`${l.value}`},l.label))},a.name):a.type==="select"?jsx(Select,{data:a.options.map(l=>({value:`${l.value}`,label:l.label})),label:a.label,onChange:l=>{o({...t,[a.name]:l});},value:s,zIndex:1002},a.name):a.type==="switch"?jsx(Switch,{label:a.label,name:a.name,checked:s=="true"},a.name):a.type==="text"?jsx(TextInput,{label:a.label,onChange:l=>{o({...t,[a.name]:l.target.value});},placeholder:a.placeholder,value:s},a.name):null}),[r,t]),t,n]}d();ie();d();var Wc=e=>({overrideNames:e&&typeof e.overrideNames<"u"?e.overrideNames:!1,overrideRelevance:e&&typeof e.overrideRelevance<"u"?e.overrideRelevance:!1,regenerateSlugs:e&&typeof e.regenerateSlugs<"u"?e.regenerateSlugs:!1,keepOldMembers:e&&typeof e.keepOldMembers<"u"?e.keepOldMembers:!0,doIngest:e&&typeof e.doIngest<"u"?e.doIngest:!1,overrideAttributes:e&&typeof e.overrideAttributes<"u"?e.overrideAttributes:!1,order:e&&typeof e.order<"u"?e.order:0});function aO({for:e,onEdit:t}){let o=useMantineTheme(),{newConfirmation:r}=Pt();o.colorScheme==="dark"?o.colors.dark[1]:o.colors.gray[7];let i=useCallback(async()=>{try{await r({title:"Are you sure?",message:"Modifying variants can be destructive and break the site. Make sure you know what you're doing!",confirmText:"Continue"}),t(e.id);}catch{console.debug("Variant edition aborted.");}},[t]),{slug:a,name:s,settings:l}=e,u=Wc(l);return jsxs(Card,{shadow:"xs",withBorder:!0,style:{margin:o.spacing.sm},children:[jsxs(Group,{position:"apart",children:[jsxs(Center,{children:[jsx(IconServer,{size:22}),jsx(Space,{w:"xs"}),jsx(Text,{weight:"bold",children:s}),jsxs(Text,{size:"xs",ml:"xs",children:["Order: ",u.order]})]}),jsxs(Badge,{variant:"light",children:["/",a]})]}),jsx(Space,{h:"xs"}),jsxs(Group,{position:"apart",children:[jsx(Button,{onClick:()=>i(),leftIcon:jsx(IconPencil,{}),compact:!0,children:"Edit"}),jsx(yr,{id:e.id,type:"variant",warning:"Deleting variants can be destructive and break the site. Make sure you know what you're doing!"})]})]})}var Hv=oo(aO,gi);d();gd();d();var Kc=e=>e.replace(/^\s+|\s+$/gm,"").replace(/[^a-zA-ZÀ-ž0-9-\ _]/g,"");ie();Ba();d();function Ro({content:e,buttons:t,size:o}){let[r,n]=useState(500);return useEffect(()=>{let{innerHeight:i}=window;n(i-o);},[]),jsxs("div",{style:{height:"100%"},children:[jsx(ScrollArea,{offsetScrollbars:!0,type:"always",style:{height:r},children:e}),jsx(Space,{h:"xs"}),jsx(Divider,{}),jsx(Group,{mt:"xs",grow:!0,style:{height:45},children:t})]})}d();d();function CO({member:e,height:t="auto",width:o="100%",size:r="thumb",forceRefreshTimestamp:n=!1}){let i="";n&&(i=`&t=${new Date().getTime()}`);let a=e&&e.image_id?`/api/cms/member/image?member=${e.content_id}&size=${r}${i}`:"https://placehold.jp/cccccc/ffffff/900x600.png?text=None";return jsx(Image,{alt:`Image for ${e.id}`,height:t,width:o,radius:"md",src:a})}var Qs=CO;ie();function Da({members:e,onClickEdit:t,onSort:o,colsToRender:r=[],dataTableProps:n={}}){let[i,a]=useState([]),[s,l]=useState([]),{state:u,...c}=n;useEffect(()=>{typeof o<"u"&&i&&i.length&&o(i);},[i]),useEffect(()=>{l(e);},[e]),useEffect(()=>{l(e);},[]);let p=$(g=>g.status.localeDefault),m=jsx(Badge,{color:"gray",children:"None"}),f=[{header:"",accessorKey:"visible",enableResizing:!1,enableSorting:!1,size:10,Cell:({row:g})=>jsx(Fragment,{children:g.original.visible?jsx("span",{}):jsx(Tooltip,{label:"Visible: false",children:jsx("span",{children:jsx(IconEyeOff,{size:20})})})})},{header:"ID",accessorKey:"id",enableSorting:typeof o<"u",mantineTableHeadCellProps:{align:"right",sx:{"& .mantine-TableHeadCell-Content-Labels":{flexDirection:"row"}}},mantineTableBodyCellProps:{align:"right"},size:100},{header:"Report",accessorKey:"report.name",enableSorting:!1,size:100},{header:"Dimension",accessorKey:"dimension.name",enableSorting:!1,size:100},{header:"Variant",accessorKey:"variant.name",enableSorting:!1,size:100},{header:"Relevance",accessorKey:"zvalue",enableSorting:typeof o<"u",size:100},{header:"Slug",accessorKey:"slug",Cell:({row:g})=>jsxs("span",{children:["/",g.original.variant.slug,"/",g.original.slug]}),enableSorting:!1},{header:`Name ${p.toUpperCase()}`,accessorKey:"name",enableSorting:typeof o<"u",Cell:({row:g})=>{let h=g.original.contentByLocale.find(C=>C.locale===p),b=g.original.contentByLocale.filter(C=>C.locale!==p),v=b.reduce((C,R)=>{let y=`${R.locale.toUpperCase()}: ${R.name}`;return `${C}${C!==""?`
91
91
  `:""}${y}`},"");return jsxs(Group,{children:[jsx("span",{children:h?.name||m}),b.length>0&&jsx(Tooltip,{label:v,children:jsxs(Avatar,{size:"sm",color:"pink",radius:"xl",children:["+",b.length]})})]})}},{header:`Keywords ${p.toUpperCase()}`,accessorKey:"keywords",Cell:({row:g})=>{let h=g.original.contentByLocale.find(R=>R.locale===p),b=g.original.contentByLocale.filter(R=>R.locale!==p),v=(h.keywords?h.keywords:[]).map(R=>jsx(Badge,{children:R},R)),C=b.reduce((R,y)=>{let A=y.keywords||[],S=`${y.locale.toUpperCase()}: ${A.length>0?A.join(","):"None"}`;return `${R}${R!==""?`
92
92
  `:""}${S}`},"");return jsxs(Group,{children:[jsx("span",{children:v.length>0?v:m}),b.length>0&&jsx(Tooltip,{label:C,children:jsxs(Avatar,{size:"sm",color:"pink",radius:"xl",children:["+",b.length]})})]})},enableSorting:!1,size:100},{header:"Image",accessorKey:"image",Cell:({row:g})=>jsx(Qs,{member:g.original,height:"50px",forceRefreshTimestamp:!0}),enableSorting:!1,size:80},{header:"",accessorKey:"actions",Cell:({row:g})=>jsx(ActionIcon,{onClick:()=>t?t(g.original):!1,children:jsx(IconPencil,{size:20})},"edit"),enableResizing:!1,enableSorting:!1,size:50,mantineTableHeadCellProps:{align:"center"},mantineTableBodyCellProps:{align:"center"}}];return jsx(MantineReactTable,{columns:f.filter(g=>r&&r.length===0||r.includes(g.accessorKey)),data:s,enableBottomToolbar:!1,enableColumnActions:!1,enableColumnResizing:!0,enablePagination:!1,enableStickyHeader:!0,enableTopToolbar:!1,initialState:{density:"xs"},layoutMode:"grid",mantineTableContainerProps:{sx:{minHeight:150,maxHeight:"95vh"}},mantineTableProps:{striped:!0},manualSorting:!0,onSortingChange:a,state:{sorting:i,...u},...c})}d();function DO({switchProps:e,yesText:t,noText:o}){let r={size:"md",onLabel:"YES",offLabel:"NO",label:"Switch Label",my:"xs",checked:!1,onChange:n=>console.log(n.currentTarget.checked),...e};return jsxs(Group,{children:[jsx(Switch,{...r}),jsx(Tooltip,{label:r.checked?t:o,withArrow:!0,multiline:!0,width:200,children:jsx(ActionIcon,{variant:"filled",radius:"50%",size:"xs",children:jsx(IconQuestionMark,{size:"xs"})})})]})}var el=DO;d();function Zc(e){try{return new URL(e),!0}catch{return !1}}function YO({for:e,onClose:t}){let o=ne(),r=$(U=>U.status.localeDefault),n=$(U=>U.status.locales),i=n.map(U=>({value:U,label:U.toUpperCase()})),[a,s]=useState(),[l,u]=useState(r),[c,p]=useState(()=>{let U={...e};return n.forEach(oe=>{U.config={...U.config,[oe]:{attributes:[],idKey:"",labelKey:"",accessor:"",path:"",...U.config[oe]||{}}};}),U}),[m,f]=useState(!1),[g,h]=useState(!1),[b,v]=useState(!1),[C,R]=useState(!1),[y,A]=useState({valid:!1,suggestion:""}),[S,E]=useState(),[L,P]=useState([]),[D,M]=useState(!1),[z,I]=useState([]),w=U=>{Zc(U)&&(h(!0),o(Q.urlProxy(U)).then(oe=>{if(E(oe),oe){let pe=Cy(oe);P(pe),c.config[l].accessor&&oe[c.config[l].accessor]?_(oe[c.config[l].accessor][0],c.config[l].accessor):pe.length===0&&oe&&oe[0]&&_(oe[0]);}v(!1),h(!1);}).catch(oe=>{console.error(oe),v(`Fetch error: ${oe.message}`),E(void 0),h(!1);}));},O=U=>{M(!0);let oe=$c({variant:U,limit:"5",locale:"all",visible:"true",includes:"true",noImage:"false",format:"plain",all:"true"});o(Q.searchMember(oe)).then(pe=>{if(pe&&pe.results){let Ne=pe.results;I(Ne),Ne.length===0&&K("doIngest",!0);}M(!1);}).catch(pe=>{console.error(pe),M(!1);});},_=(U,oe="")=>{if(U){let pe=Object.keys(U),Ne=pe.find(ze=>ze.toLowerCase().includes("id"))||pe[0],Be=pe.find(ze=>!ze.toLowerCase().includes("id"))||pe[0];(!c.config[l].idKey||c.config[l].idKey===""||!c.config[l].labelKey||c.config[l].labelKey==="")&&p({...c,config:{...c.config,[l]:{...c.config[l],idKey:Ne,labelKey:Be,accessor:oe}}});}s(U);};useEffect(()=>{c.id&&O(c.id),W(c.slug),c.config[l]&&c.config[l].path&&w(c.config[l].path);},[]);let H=U=>{E(void 0),v(!1);let oe=[];if(U!==r){let pe=c.config[r]?[...c.config[r].attributes].map(Be=>{let ze={...Be};return ze.value="",ze}):[];c.config[U]&&c.config[U].attributes?oe=pe.map(Be=>{let ze=c.config[U].attributes.find(at=>Be.name===at.name);return ze&&(Be.value=ze.value),Be}):oe=pe;let Ne={...c.config,[U]:{...c.config[U],attributes:oe}};p({...c,config:Ne});}c.config[U]&&c.config[U].path&&w(c.config[U].path),u(U);},G=useMemo(()=>Wc(c.settings),[c.settings]),te=useMemo(()=>[{label:"Replace names",key:"overrideNames",yesText:"Names from new source will update the previously ingested members.",noText:"Original names will be keep."},{label:"Replace slugs",key:"regenerateSlugs",yesText:"Slugs will be regenerated based on new member's names and updated on previously ingested members.",noText:"Original slugs will be keep.",disabled:!G.overrideNames},{label:"Replace relevance value",key:"overrideRelevance",yesText:"Relevance index will be recalculated and updated on previously ingested members.",noText:"Original numbers will be keep."},{label:"Replace attributes",key:"overrideAttributes",yesText:"Attributes will be regenerated and override the current ones. Different ones will be kept.",noText:"Original attributes will be keep, ignoring the changes"},{label:"Keep all existing members",key:"keepOldMembers",yesText:"All the the existing members will be keep even if they are not in the new API members list",noText:"Members that are not in the API members list will be deleted, keeping both lists on sync."}],[G.overrideNames]),j=U=>{let oe=Tc(S,U);oe[0]&&_(oe[0],U);},W=U=>{o(Q.variantValidateSlug(c.dimension_id,U)).then(A).then(()=>{R(!1);},oe=>{console.error(oe);});},q=(U,oe)=>{let pe=oe;U==="slug"&&(pe=Kc(oe),pe&&(R(!0),W(oe))),p({...c,[U]:pe});},V=(U,oe)=>{U==="path"&&v(!1),p({...c,config:{...c.config,[l]:{...c.config[l],[U]:oe}}});},K=(U,oe)=>{let pe=U==="overrideNames"&&!oe?{regenerateSlugs:!1}:{};p({...c,settings:{...c.settings,...pe,[U]:oe}});},Z=()=>{f(!0),o(Q.updateEntity("variant",c)).then(()=>{f(!1),t();}).catch(U=>{console.error(U),f(!1);});},F=U=>{p({...c,config:{...c.config,[l]:{...c.config[l],attributes:U}}});},J=()=>{if(a&&Object.keys(a)[0]){let pe=c.config[l]?.attributes||[],Ne=pe.length||0;F([...pe,{type:"constant",name:`attr${Ne+1}`,value:""}]);}},se=(U,oe,pe)=>{let Ne=c.config[l].attributes.map((Be,ze)=>ze===oe?{...Be,[U]:pe}:Be);F(Ne);},re=U=>{let oe=c.config[l].attributes.filter((pe,Ne)=>Ne!==U);F(oe);},ce=a?Object.keys(a).map(U=>({value:U,label:`${U}: ${a[U]}`})):[],fe=L.map(U=>({value:U,label:U})),Ie=!Zc(c.config[l].path),xe=useMemo(()=>b||(Ie&&c.config[l].path!==""?"Format error: Invalid URL.":!1),[b,Ie,c.config,l]);return jsx(Ro,{content:jsxs(Fragment,{children:[jsx(Title,{order:2,children:`Editing Variant: ${c.name}`}),jsx(Space,{h:"xs"}),jsxs(Tabs,{defaultValue:"variant",children:[jsxs(Tabs.List,{grow:!0,children:[jsx(Tabs.Tab,{value:"variant",children:"Variant"}),jsx(Tabs.Tab,{value:"members",children:"Members"})]}),jsxs(Tabs.Panel,{value:"variant",py:"md",children:[jsx(Title,{order:3,children:"Variant Settings"}),jsx(Space,{h:"xs"}),jsx(TextInput,{value:c.name,label:"Name",onChange:U=>q("name",U.target.value)}),jsx(Space,{h:"xs"}),jsx(TextInput,{value:c.slug,icon:!C&&!y.valid?jsx(IconAlertCircle,{}):jsx(IconCircleCheck,{}),label:"Slug",description:C?"Validating slug...":y.valid?"Valid slug.":"Invalid slug.",error:!C&&!y.valid?jsxs(Text,{children:["Duplicated slug. Suggestion:",jsx(Code,{onClick:()=>q("slug",y.suggestion),style:{cursor:"pointer"},children:y.suggestion})]}):!1,onChange:U=>q("slug",U.target.value)}),jsx(Space,{h:"xs"}),jsx(NumberInput,{value:G.order||0,description:"It affects on explore options order",placeholder:"Order",label:"Order",onChange:U=>{K("order",U);}})]}),jsxs(Tabs.Panel,{value:"members",py:"md",children:[jsx(Title,{order:3,children:"Members Settings"}),jsx(Text,{size:"sm",children:"Members, once ingested, become pages for this variant."}),jsx(el,{switchProps:{label:`${!D&&z.length>0?"Re-":""}Ingest members`,checked:G.doIngest,onChange:U=>K("doIngest",U.currentTarget.checked)},yesText:`Run the ingestion process and save the variant details.
93
93
  Remember include the ingestion information for all the locales.`,noText:"Ingestion is not going to run and the current members are not going to suffer any change."}),G.doIngest&&!D&&z.length>0&&jsxs(Box,{ml:"lg",children:[jsx(Text,{size:"sm",children:"Settings that are going to be applied for members reingestions and for all available languages, matching by unique identificator. All new members are going to be ingested. Images and tags for existing members will be safe."}),te.map(U=>jsx(el,{switchProps:{disabled:U.disabled,label:U.label,checked:G[U.key],onChange:oe=>K(U.key,oe.currentTarget.checked)},yesText:U.yesText,noText:U.noText},U.key))]}),!G.doIngest&&jsxs(Fragment,{children:[jsx(Title,{order:2,size:"h4",children:"Ingested members preview"}),jsx(Space,{h:"xs"}),jsxs(Stack,{spacing:0,justify:"center",children:[D&&jsx(Loader,{m:"0 auto"}),!D&&z.length>0&&jsxs(Fragment,{children:[jsx(Da,{members:z,colsToRender:["id","name","slug"]}),jsx(gM,{href:"metadata",passHref:!0,children:jsx(Text,{c:"dimmed",align:"center",td:"underline",size:"xs",children:"See the full list in Metadata View"})})]})]}),!D&&z.length===0&&jsx(Text,{c:"dimmed",align:"center",children:"No members ingested yet."}),jsx(Space,{h:"xs"})]}),G.doIngest&&jsxs(Fragment,{children:[jsx(Divider,{my:"sm"}),jsx(Title,{order:2,size:"h4",children:"Members ingestion"}),jsx(Space,{h:"xs"}),jsx(SegmentedControl,{value:l,fullWidth:!0,onChange:H,data:i,disabled:g}),c.config[l]&&jsxs(Fragment,{children:[jsx(Space,{h:"lg"}),jsx(Group,{children:jsx(TextInput,{onChange:U=>V("path",U.target.value),title:"Api endpoint",description:"Enter the url to retrieve a member list to ingest. (JSON) and click Fetch.",value:c.config[l].path,error:xe,rightSectionWidth:"105px",w:"100%",rightSection:g?jsxs(Group,{align:"center",children:[jsx(Loader,{size:"xs"}),jsx(Text,{span:!0,variant:"subtle",size:"xs",children:"Fetching..."})]}):jsx(Button,{disabled:g||Ie,onClick:()=>w(c.config[l].path),leftIcon:jsx(IconPlayerPlay,{}),children:"Fetch"}),readOnly:g})}),S&&jsxs("div",{children:[jsx(Space,{h:"md"}),jsx(Select,{value:c.config[l].accessor,label:"Elements",description:`Choose the key that returns the array of elements that
94
94
  are going to be ingested as members.`,data:fe,disabled:fe.length===0,placeholder:fe.length===0?"Root is an array":"",onChange:U=>j(U)}),jsx(Divider,{label:"First element preview",labelPosition:"center"}),S[c.config[l].accessor]&&!Array.isArray(S)&&jsx(tr,{variables:S[c.config[l].accessor][0]}),Array.isArray(S)&&S[0]&&jsx(tr,{variables:S[0]}),jsx(Space,{h:"md"}),jsx(Select,{value:c.config[l].idKey,label:"Unique identificator",description:"Choose the field that is a unique identification for a single member.",data:ce,onChange:U=>V("idKey",U)}),jsx(Space,{h:"md"}),jsx(Select,{value:c.config[l].labelKey,label:"Members' name",description:"Choose the field that contains the members name.",data:ce,onChange:U=>V("labelKey",U)}),jsx(Space,{h:"md"}),jsx(Select,{value:c.config[l].zValueKey||"",label:"Member's relevance (optional)",description:`Choose a field that will be converted to a number and
95
- normalized from 0 to 1 to determine the member's relevance.`,data:[{value:"null",label:"None"},...ce],onChange:U=>V("zValueKey",U)}),jsx(Space,{h:"md"}),jsx(Title,{order:3,size:"h5",children:"Attributes"}),jsx(Text,{size:"sm",children:"Attributes are properties to be ingested as metadata with the member element. Could be constants (same value for every member) or dynamic (based on a property of the data)"}),jsx(Space,{h:"xs"}),c.config[l].attributes&&c.config[l].attributes.map((U,oe)=>jsxs(Group,{align:"end",grow:!0,children:[jsx(Select,{value:c.config[l].attributes[oe].type,label:"Type",data:[{value:"variable",label:"Data based"},{value:"constant",label:"Constant"}],readOnly:l!==r,disabled:l!==r,onChange:pe=>se("type",oe,pe)}),jsx(TextInput,{value:c.config[l].attributes[oe].name,label:"Name",readOnly:l!==r,disabled:l!==r,onChange:pe=>se("name",oe,pe.target.value)}),U.type==="variable"&&jsx(Select,{value:c.config[l].attributes[oe].value,label:"Value",data:ce,onChange:pe=>se("value",oe,pe)}),U.type==="constant"&&jsx(TextInput,{value:c.config[l].attributes[oe].value,label:"Value",onChange:pe=>se("value",oe,pe.target.value)}),jsx(ActionIcon,{color:"red",onClick:()=>re(oe),disabled:l!==r,children:jsx(IconTrash,{size:20})})]},oe)),jsx(Space,{h:"md"}),jsx(Button,{onClick:J,leftIcon:"+",disabled:m||l!==r,children:"Add Attribute"})]})]}),jsx(Space,{h:"md"})]})]})]})]}),buttons:jsxs(Fragment,{children:[jsx(Button,{disabled:m||g||!C&&!y.valid,onClick:t,variant:"outline",children:"Cancel"}),jsx(Button,{disabled:m||g||!C&&!y.valid,loading:m||g,onClick:Z,children:`${G.doIngest?`${!D&&z.length>0?"Re-":""}Ingest & `:""}Save`})]}),size:165})}var Zv=oo(YO,gi);function aS({id:e,onClose:t}){let o=ne(),r=fi(e),[n,i]=useState({id:e}),[a,s]=useState(null);useEffect(()=>{r.isSuccess&&i(r.data);},[r.status]);let l=useCallback(f=>{o(Q.createEntity("variant",{dimension_id:e,name:f.name,slug:Wr(f.name)}));},[e]),u=useCallback(()=>{o(Q.updateEntity("dimension",{...n,id:e})).then(t);},[n]),c=useCallback((f,g)=>{i({...n,[f]:f==="slug"?Wr(g):g});},[]);if(a)return jsx(Zv,{id:a,onClose:()=>s(null)});let p=r.isFetching,m=r.isSuccess?r.data.variants:[];return jsx(Ro,{content:jsxs(Fragment,{children:[jsx(Title,{order:2,children:`Dimension metadata: ${n.name}`}),jsx(Space,{h:"xs"}),jsx(TextInput,{value:n.name,label:"Name",onChange:f=>c("name",f.target.value)}),jsx(Space,{h:"xs"}),jsx(NumberInput,{value:n.ordering?parseInt(n.ordering,10):0,type:"number",label:"Order",onChange:f=>c("ordering",f)}),jsx(Divider,{my:"xl"}),jsx(ka,{icon:jsx(IconServer,{size:22}),children:jsx(Title,{order:2,size:"h4",children:"Variants"})}),m.map(f=>jsx(Hv,{id:f,onEdit:s},f)),jsx(Pa,{fields:[{name:"name",type:"text",label:"Add Variant"}],onSubmit:l,target:jsx(ActionIcon,{size:"xl",radius:"xl",children:jsx(IconCirclePlus,{size:30})})})]}),buttons:jsxs(Fragment,{children:[jsx(Button,{variant:"outline",disabled:p,loading:p,onClick:t,children:"Cancel"}),jsx(Button,{disabled:p,loading:p,onClick:u,children:"Save Dimension"})]}),size:165})}Xs();function mS({id:e,onClose:t}){let o=ne(),r=Vt(e),[n,i]=useState({id:e}),[a,s]=useState(null);useEffect(()=>{r.isSuccess&&i(r.data);},[r.status]);let l=useCallback(v=>{o(Q.createEntity("dimension",{report_id:e,name:v.name})).then(C=>{C.ok&&o(Q.createEntity("variant",{dimension_id:C.data.id,name:C.data.name,slug:Wr(C.data.name)}));});},[e]),u=useCallback(()=>{o(Q.updateEntity("report",{...n,id:e})).then(t);},[e,n]),c=useCallback((v,C)=>{i({...n,[v]:C});},[]),p=(v,C)=>{i({...n,settings:{...n.settings,[v]:C}});};if(a)return jsx(aS,{id:a,onClose:()=>s(null)});let m=r.isFetching,f=r.isSuccess?r.data.dimensions:[],g=n.settings,h=g&&typeof g.order=="number"?g.order:0,b=g&&typeof g.hide=="boolean"?g.hide:!1;return jsx(Ro,{content:jsxs(Fragment,{children:[jsx(Title,{order:2,children:`Report metadata: ${n.name}`}),jsx(Space,{h:"xs"}),jsx(TextInput,{value:n.name,label:"Name",onChange:v=>c("name",v.target.value)}),jsx(Space,{h:"xs"}),jsxs(Group,{grow:!0,children:[jsx(el,{switchProps:{label:"Show in Explore & Search",checked:!b,onChange:v=>p("hide",!v.currentTarget.checked)},yesText:"Profile appears in Explore search and members are listed in search results",noText:"Profile is hidden in Explore search and members are not included in search results"}),jsx(NumberInput,{defaultValue:0,value:h,description:"It affects the Explore search options order",placeholder:"Order in Explore",label:"Order",disabled:b,onChange:v=>{p("order",v);}})]}),jsx(Divider,{my:"sm"}),jsx(ka,{icon:jsx(IconDatabase,{size:22}),children:jsx(Title,{order:2,size:"h4",children:"Dimensions"})}),jsx(Grid,{children:f.map(v=>jsx(Grid.Col,{span:6,children:jsx(_v,{id:v,onEdit:s})},v))}),jsx(Pa,{fields:[{type:"text",name:"name",label:"Add Dimension"}],onSubmit:l,target:jsx(ActionIcon,{size:"xl",radius:"xl",children:jsx(IconCirclePlus,{size:30})})})]}),buttons:jsxs(Fragment,{children:[jsx(Button,{variant:"outline",disabled:m,loading:m,onClick:t,children:"Cancel"}),jsx(Button,{disabled:m,loading:m,onClick:u,children:"Save Report"})]}),size:165})}function bS(e){let{report:t}=e,{newConfirmation:o}=Pt(),{selectEntity:r}=Ot(),n=useContext(_e),i=ne(),a=$(E=>E.status.previews),s=ro(),l=Number.parseInt(s.params[0]),u=Vt(l),c=va(),p=qd(),m=$(E=>E.status.localeDefault),f=to("settings"),g=to("reportEditor"),h=js(l),b=t&&t.dimensions?t.dimensions:[],v=b.length>0,C=a.filter(E=>E.variant_slug).reduce((E,L)=>E.concat([L.variant_slug,L.slug]),[]),R=p===m?"":`/${p}`,y=C.length?`${R}${c}/${C.join("/")}`:"",A=E=>{s.setSearchParam("locale",E),i(Q.readMember({mode:"content_ids",variant:a.map(L=>L.variant_id),content_ids:a.map(L=>L.content_id),locale:E,output:"full"})).then(({results:L})=>{i(Q.setCurrentLocale(E)),L&&L.length===b.length&&b.length?i(Q.recalculateVariables(n,{previews:L})):i(Q.recalculateVariables(n,{previews:[]}));});},S=useCallback(async()=>{try{await o({title:"Are you sure?",message:`Revalidate action will force to regenerate page: ${y}.`,confirmText:"Revalidate now!"}),await i(Q.revalidateUrl({target:y})).then(E=>{let L=`Revalidated page ${E.target} you will see the changes in the following minutes.`;notifications.show({autoClose:!1,color:"green",id:"revalidate-results",message:L,title:"Revalidate Results"});}).catch(E=>{notifications.show({autoClose:!1,color:"red",id:"revalidate-error",message:E.message,title:"Revalidate Error"});});}catch{console.debug("Revalidate error.");}},[y]);return jsxs(Fragment,{children:[jsx(Sv,{left:jsxs(Group,{children:[jsx(ActionIcon,{color:"blue",variant:"filled",onClick:()=>{r({type:"report",id:t.id}),f.handlers.open();},children:jsx(IconSettingsFilled,{size:20})}),jsx(Ws,{value:p,onChange:A,selectProps:{size:"xs",maw:80}})]}),center:jsxs(Group,{children:[jsx(rm,{report:t,defaultMembers:h?.map(E=>({variantId:E.variantId,memberId:E.contentId})),locale:p}),y&&jsx(Tooltip,{label:"Preview Report",children:jsx(ActionIcon,{component:"a",href:y,target:"_blank",radius:2,bg:"#E9ECEF",title:"Open report in new tab",color:"dark",disabled:!y,children:jsx(IconEye,{size:20})})})]}),right:jsxs(Group,{children:[a.length>0&&jsx(Button,{variant:"light",fw:700,radius:"sm",fz:12,pr:10,pl:5,mih:"1.875rem",onClick:S,leftIcon:jsx(IconWorldUpload,{size:14}),compact:!0,children:"Publish"}),!v&&jsx(Button,{size:"xs",variant:"outline",onClick:g.handlers.open,children:"Import Data"})]})}),jsx(Drawer,{opened:g.opened,onClose:g.handlers.close,title:jsx(ka,{icon:jsx(IconFileAnalytics,{size:24}),children:`Editing Report: ${u.data?u.data.name:""}`}),size:"50%",padding:"xl",position:"right",children:jsx(mS,{id:l,onClose:g.handlers.close})})]})}d();d();d();ie();ge();function CL({type:e,id:t,warning:o=""}){let r=py[e]||"Entity",n=o||`Delete this ${r} and all its contents? This action cannot be undone.`,i=useDispatch(),{newConfirmation:a}=Pt();return jsx(ActionIcon,{color:"red",onClick:async()=>{try{await a({title:"Are you sure?",message:n,confirmText:"Yes, Delete it."}),i(Q.deleteEntity(e,t));}catch{}},children:jsx(IconTrash,{size:20})})}var vS=CL;nl();d();ie();d();ge();d();la();he();function ZL({defaultValue:e,id:t,onChange:o,onEnterPress:r,onDelete:n}){let i=po(),a=_c(t),[s,l]=useState(()=>Co(e,i,a)),[u,c]=useState(!1),p=g=>{u&&(g.preventDefault(),r&&r(),c(!1));},m=useRef(null),f=g=>{let{value:h}=g.target;l(Co(h,i,a)),o(h);};return jsxs(Group,{noWrap:!0,position:"apart",spacing:"xs",py:5,children:[jsx(Text,{lineClamp:1,size:"xs",children:jsx("a",{href:s,target:"_blank",rel:"noreferrer",children:s||"--Add API Url--"})}),jsxs(Group,{noWrap:!0,spacing:0,children:[jsxs(Popover,{onClose:()=>c(!1),opened:u,position:"right",radius:"xs",withArrow:!0,children:[jsx(Popover.Target,{children:jsx(ActionIcon,{size:"xs",onClick:()=>c(g=>!g),children:u?jsx(IconCircleCheck,{}):jsx(IconPencil,{})})}),jsx(Popover.Dropdown,{children:jsx(TextInput,{placeholder:"API",defaultValue:e,ref:m,type:"url",onChange:f,size:"xs",style:{maxWidth:800,width:"60vw"},onKeyDown:getHotkeyHandler([["enter",p]])},"text-input")})]}),jsx(ActionIcon,{size:"xs",onClick:()=>n(),children:jsx(IconTrash,{color:"red"})})]})]})}var MS=ZL;d();function nM({monacoOptions:e,variables:t={}}){let o=useMonaco();return useEffect(()=>{if(o){let r="Monokai";import(`monaco-themes/themes/${r}.json`).then(n=>{o.editor.defineTheme(r,n),o.editor.setTheme(r);}).catch(()=>{throw new Error("Invalid Monaco theme")});}},[o]),jsx(Box,{className:"cr-monaco-container",w:"100%",children:jsx(tM,{defaultLanguage:"javascript",theme:"Monokai",...e})})}var ru=nM;d();Gr();ko();bl();Im();bl();ge();ie();he();Gr();la();ei();Ei();ua();fr();sg();var Du={api:null,duration:null,error:null,log:[],responseSize:null,resp:null,allowed:!0};function IV({block:e,status:t,estimatedOutputSize:o,slugsInterceptor:r,sectionFlag:n,sectionAllowed:i}){let a=useMemo(()=>n?jsx(ThemeIcon,{variant:"filled",radius:"xl",size:"sm",color:"orange",children:jsx(IconFlag,{size:"0.8rem"})}):jsx(ThemeIcon,{variant:"filled",radius:"xl",size:"sm",color:"yellow",children:jsx(IconBraces,{size:"0.8rem"})}),[n]);return jsxs(Fragment,{children:[jsxs(Group,{position:"left",pt:"xl",children:[jsxs(Group,{children:[a,jsxs(Title,{order:6,children:[ig[e.type]," ",e.id]})]}),jsxs(Group,{spacing:"xs",my:"xs",children:[t.duration&&jsx(Tooltip,{label:`Api Call Duration: ${t.duration} ms`,children:jsx(ThemeIcon,{size:"sm",radius:"xl",color:Iy(t.duration),children:jsx(IconClockHour2,{size:rem(12)})})}),t.responseSize&&jsx(Tooltip,{label:`Api Response Size: \u2248${t.responseSize.toFixed(2)} Kb`,children:jsx(ThemeIcon,{size:"sm",radius:"xl",color:Sd(t.responseSize),children:jsx(IconApi,{size:rem(12)})})}),o&&jsx(Tooltip,{label:`Block Output Size: \u2248${o.toFixed(2)} Kb`,children:jsx(ThemeIcon,{size:"sm",radius:"xl",color:Sd(o),children:jsx(IconAugmentedReality,{size:rem(12)})})}),r&&jsx(Tooltip,{label:"Slugs Interceptor Enabled",children:jsx(ThemeIcon,{size:"sm",radius:"xl",color:"green",children:jsx(IconGitMerge,{size:rem(12)})})}),n&&jsx(Tooltip,{label:`Section #${e.section_id} Allowed Flag: ${i?"YES":"NO"}`,children:jsx(ThemeIcon,{size:"sm",radius:"xl",color:i?"green":"red",children:jsx(IconFlag,{size:rem(12)})})})]})]}),jsx(Divider,{})]})}function AV(e){let{active:t,allowed:o,blockStateContent:r,blockStateSettings:n,debug:i,for:a,locale:s,isFetching:l}=e,u=je(a.id),c=po(),p=_c(a.id,s),m=$(w=>([k.SECTION_FLAG].includes(a.type)&&console.log(a.id,w.variables),w.variables.variables[a.id]||{}));[k.SECTION_FLAG].includes(a.type)&&console.log(a.id,m);let f=$(w=>w.variables.status[a.id]||{}),g=Ha[a.type].renderPreviewOnEdit&&r?r:so(a,s),h=Ha[a.type].renderPreviewOnEdit&&n?n:a.settings,[b,v]=useState(null),[C,R]=useState(Du),y=[k.GENERATOR,k.SECTION_FLAG].includes(a.type)&&b&&b.outputVariables?JSON.stringify(b.outputVariables).length/1024:void 0,A=!!([k.GENERATOR,k.SECTION_FLAG].includes(a.type)&&C.api&&C.api.indexOf("bespoke_slugs=")>-1),S=Jo(a),E=Cr();useEffect(()=>{(async()=>{if(a.type===k.VIZ){v({block:a,locale:s,variables:u,active:t}),R(Du);return}if(!t&&!Ha[a.type].evalWhenNonActive){let{nonActiveAdapter:j}=Ha[a.type],W=j&&typeof j=="function"?j():{};v(W),R(Du);return}if([k.GENERATOR,k.SECTION_FLAG].includes(a.type)){let j=!!a.contentByLocale?.logic?.content?.api,W=S?m[Eo]:!1;v({outputVariables:m,hasAPI:j,sectionAllowed:W,type:a.type}),R(f),console.log("PARSE BLOCK",f,m);return}if([k.SELECTOR,k.MULTIHIERARCHY_SELECTOR].includes(a.type)){let{renderVariables:j,status:W}=await Ms(a,c,p,E),q=Ao[a.type]&&typeof Ao[a.type]=="function"?Ao[a.type](j,a.id):j;v(q),R(W);return}if(a.type===k.NAV){v({headings:a.inputs,settings:a.settings});return}if(a.type===k.RELATED){let{outputVariables:j}=await Ms(a,c,p,E),{related_reports:W}=j;v({related_reports:W});return}if(a.type===k.RESET_BUTTON||a.type===k.COMPARISON_BUTTON){v(g.simple||{});return}let O=Co(g?.logic,c,p),{vars:_,error:H,log:G}=To("variables",u,O,c,void 0,p),te=Ao[a.type]&&typeof Ao[a.type]=="function"?Ao[a.type](_,a.id):_;v(te),R({...Du,error:H,log:G});})();},[g,u,S]),useEffect(()=>{f&&f.error&&f.error!==""&&notifications.show({autoClose:1e4,color:"red",id:"block-error",message:f.error,title:`Block error ID: ${a.id}`});},[f.error]);let L=ct[a.type],D=jsx("div",{style:{...{width:"100%",height:"100%",position:"absolute",top:0,left:0,opacity:.9,zIndex:4,pointerEvents:"none"},backgroundColor:"pink"},children:jsx(Center,{h:"100%",children:jsx(Text,{size:"sm",tt:"capitalize",italic:!0,children:f.hiddenByCascade===a.id?`${a.type} not allowed`:`${a.type} hidden by block ${f.hiddenByCascade}`})})});if(l)return jsx(Center,{style:{minHeight:100},w:"100%",children:jsx(Loader,{})});if(!b)return null;let{error:M,log:z}=C,I=z?z.join(`
95
+ normalized from 0 to 1 to determine the member's relevance.`,data:[{value:"null",label:"None"},...ce],onChange:U=>V("zValueKey",U)}),jsx(Space,{h:"md"}),jsx(Title,{order:3,size:"h5",children:"Attributes"}),jsx(Text,{size:"sm",children:"Attributes are properties to be ingested as metadata with the member element. Could be constants (same value for every member) or dynamic (based on a property of the data)"}),jsx(Space,{h:"xs"}),c.config[l].attributes&&c.config[l].attributes.map((U,oe)=>jsxs(Group,{align:"end",grow:!0,children:[jsx(Select,{value:c.config[l].attributes[oe].type,label:"Type",data:[{value:"variable",label:"Data based"},{value:"constant",label:"Constant"}],readOnly:l!==r,disabled:l!==r,onChange:pe=>se("type",oe,pe)}),jsx(TextInput,{value:c.config[l].attributes[oe].name,label:"Name",readOnly:l!==r,disabled:l!==r,onChange:pe=>se("name",oe,pe.target.value)}),U.type==="variable"&&jsx(Select,{value:c.config[l].attributes[oe].value,label:"Value",data:ce,onChange:pe=>se("value",oe,pe)}),U.type==="constant"&&jsx(TextInput,{value:c.config[l].attributes[oe].value,label:"Value",onChange:pe=>se("value",oe,pe.target.value)}),jsx(ActionIcon,{color:"red",onClick:()=>re(oe),disabled:l!==r,children:jsx(IconTrash,{size:20})})]},oe)),jsx(Space,{h:"md"}),jsx(Button,{onClick:J,leftIcon:"+",disabled:m||l!==r,children:"Add Attribute"})]})]}),jsx(Space,{h:"md"})]})]})]})]}),buttons:jsxs(Fragment,{children:[jsx(Button,{disabled:m||g||!C&&!y.valid,onClick:t,variant:"outline",children:"Cancel"}),jsx(Button,{disabled:m||g||!C&&!y.valid,loading:m||g,onClick:Z,children:`${G.doIngest?`${!D&&z.length>0?"Re-":""}Ingest & `:""}Save`})]}),size:165})}var Zv=oo(YO,gi);function aS({id:e,onClose:t}){let o=ne(),r=fi(e),[n,i]=useState({id:e}),[a,s]=useState(null);useEffect(()=>{r.isSuccess&&i(r.data);},[r.status]);let l=useCallback(f=>{o(Q.createEntity("variant",{dimension_id:e,name:f.name,slug:Wr(f.name)}));},[e]),u=useCallback(()=>{o(Q.updateEntity("dimension",{...n,id:e})).then(t);},[n]),c=useCallback((f,g)=>{i({...n,[f]:f==="slug"?Wr(g):g});},[]);if(a)return jsx(Zv,{id:a,onClose:()=>s(null)});let p=r.isFetching,m=r.isSuccess?r.data.variants:[];return jsx(Ro,{content:jsxs(Fragment,{children:[jsx(Title,{order:2,children:`Dimension metadata: ${n.name}`}),jsx(Space,{h:"xs"}),jsx(TextInput,{value:n.name,label:"Name",onChange:f=>c("name",f.target.value)}),jsx(Space,{h:"xs"}),jsx(NumberInput,{value:n.ordering?parseInt(n.ordering,10):0,type:"number",label:"Order",onChange:f=>c("ordering",f)}),jsx(Divider,{my:"xl"}),jsx(ka,{icon:jsx(IconServer,{size:22}),children:jsx(Title,{order:2,size:"h4",children:"Variants"})}),m.map(f=>jsx(Hv,{id:f,onEdit:s},f)),jsx(Pa,{fields:[{name:"name",type:"text",label:"Add Variant"}],onSubmit:l,target:jsx(ActionIcon,{size:"xl",radius:"xl",children:jsx(IconCirclePlus,{size:30})})})]}),buttons:jsxs(Fragment,{children:[jsx(Button,{variant:"outline",disabled:p,loading:p,onClick:t,children:"Cancel"}),jsx(Button,{disabled:p,loading:p,onClick:u,children:"Save Dimension"})]}),size:165})}Xs();function mS({id:e,onClose:t}){let o=ne(),r=Vt(e),[n,i]=useState({id:e}),[a,s]=useState(null);useEffect(()=>{r.isSuccess&&i(r.data);},[r.status]);let l=useCallback(v=>{o(Q.createEntity("dimension",{report_id:e,name:v.name})).then(C=>{C.ok&&o(Q.createEntity("variant",{dimension_id:C.data.id,name:C.data.name,slug:Wr(C.data.name)}));});},[e]),u=useCallback(()=>{o(Q.updateEntity("report",{...n,id:e})).then(t);},[e,n]),c=useCallback((v,C)=>{i({...n,[v]:C});},[]),p=(v,C)=>{i({...n,settings:{...n.settings,[v]:C}});};if(a)return jsx(aS,{id:a,onClose:()=>s(null)});let m=r.isFetching,f=r.isSuccess?r.data.dimensions:[],g=n.settings,h=g&&typeof g.order=="number"?g.order:0,b=g&&typeof g.hide=="boolean"?g.hide:!1;return jsx(Ro,{content:jsxs(Fragment,{children:[jsx(Title,{order:2,children:`Report metadata: ${n.name}`}),jsx(Space,{h:"xs"}),jsx(TextInput,{value:n.name,label:"Name",onChange:v=>c("name",v.target.value)}),jsx(Space,{h:"xs"}),jsxs(Group,{grow:!0,children:[jsx(el,{switchProps:{label:"Show in Explore & Search",checked:!b,onChange:v=>p("hide",!v.currentTarget.checked)},yesText:"Profile appears in Explore search and members are listed in search results",noText:"Profile is hidden in Explore search and members are not included in search results"}),jsx(NumberInput,{defaultValue:0,value:h,description:"It affects the Explore search options order",placeholder:"Order in Explore",label:"Order",disabled:b,onChange:v=>{p("order",v);}})]}),jsx(Divider,{my:"sm"}),jsx(ka,{icon:jsx(IconDatabase,{size:22}),children:jsx(Title,{order:2,size:"h4",children:"Dimensions"})}),jsx(Grid,{children:f.map(v=>jsx(Grid.Col,{span:6,children:jsx(_v,{id:v,onEdit:s})},v))}),jsx(Pa,{fields:[{type:"text",name:"name",label:"Add Dimension"}],onSubmit:l,target:jsx(ActionIcon,{size:"xl",radius:"xl",children:jsx(IconCirclePlus,{size:30})})})]}),buttons:jsxs(Fragment,{children:[jsx(Button,{variant:"outline",disabled:m,loading:m,onClick:t,children:"Cancel"}),jsx(Button,{disabled:m,loading:m,onClick:u,children:"Save Report"})]}),size:165})}function bS(e){let{report:t}=e,{newConfirmation:o}=Pt(),{selectEntity:r}=Ot(),n=useContext(_e),i=ne(),a=$(E=>E.status.previews),s=ro(),l=Number.parseInt(s.params[0]),u=Vt(l),c=va(),p=qd(),m=$(E=>E.status.localeDefault),f=to("settings"),g=to("reportEditor"),h=js(l),b=t&&t.dimensions?t.dimensions:[],v=b.length>0,C=a.filter(E=>E.variant_slug).reduce((E,L)=>E.concat([L.variant_slug,L.slug]),[]),R=p===m?"":`/${p}`,y=C.length?`${R}${c}/${C.join("/")}`:"",A=E=>{s.setSearchParam("locale",E),i(Q.readMember({mode:"content_ids",variant:a.map(L=>L.variant_id),content_ids:a.map(L=>L.content_id),locale:E,output:"full"})).then(({results:L})=>{i(Q.setCurrentLocale(E)),L&&L.length===b.length&&b.length?i(Q.recalculateVariables(n,{previews:L})):i(Q.recalculateVariables(n,{previews:[]}));});},S=useCallback(async()=>{try{await o({title:"Are you sure?",message:`Revalidate action will force to regenerate page: ${y}.`,confirmText:"Revalidate now!"}),await i(Q.revalidateUrl({target:y})).then(E=>{let L=`Revalidated page ${E.target} you will see the changes in the following minutes.`;notifications.show({autoClose:!1,color:"green",id:"revalidate-results",message:L,title:"Revalidate Results"});}).catch(E=>{notifications.show({autoClose:!1,color:"red",id:"revalidate-error",message:E.message,title:"Revalidate Error"});});}catch{console.debug("Revalidate error.");}},[y]);return jsxs(Fragment,{children:[jsx(Sv,{left:jsxs(Group,{children:[jsx(ActionIcon,{color:"blue",variant:"filled",onClick:()=>{r({type:"report",id:t.id}),f.handlers.open();},children:jsx(IconSettingsFilled,{size:20})}),jsx(Ws,{value:p,onChange:A,selectProps:{size:"xs",maw:80}})]}),center:jsxs(Group,{children:[jsx(rm,{report:t,defaultMembers:h?.map(E=>({variantId:E.variantId,memberId:E.contentId})),locale:p}),y&&jsx(Tooltip,{label:"Preview Report",children:jsx(ActionIcon,{component:"a",href:y,target:"_blank",radius:2,bg:"#E9ECEF",title:"Open report in new tab",color:"dark",disabled:!y,children:jsx(IconEye,{size:20})})})]}),right:jsxs(Group,{children:[a.length>0&&jsx(Button,{variant:"light",fw:700,radius:"sm",fz:12,pr:10,pl:5,mih:"1.875rem",onClick:S,leftIcon:jsx(IconWorldUpload,{size:14}),compact:!0,children:"Publish"}),!v&&jsx(Button,{size:"xs",variant:"outline",onClick:g.handlers.open,children:"Import Data"})]})}),jsx(Drawer,{opened:g.opened,onClose:g.handlers.close,title:jsx(ka,{icon:jsx(IconFileAnalytics,{size:24}),children:`Editing Report: ${u.data?u.data.name:""}`}),size:"50%",padding:"xl",position:"right",children:jsx(mS,{id:l,onClose:g.handlers.close})})]})}d();d();d();ie();ge();function CL({type:e,id:t,warning:o=""}){let r=py[e]||"Entity",n=o||`Delete this ${r} and all its contents? This action cannot be undone.`,i=useDispatch(),{newConfirmation:a}=Pt();return jsx(ActionIcon,{color:"red",onClick:async()=>{try{await a({title:"Are you sure?",message:n,confirmText:"Yes, Delete it."}),i(Q.deleteEntity(e,t));}catch{}},children:jsx(IconTrash,{size:20})})}var vS=CL;nl();d();ie();d();ge();d();la();he();function ZL({defaultValue:e,id:t,onChange:o,onEnterPress:r,onDelete:n}){let i=po(),a=_c(t),[s,l]=useState(()=>Co(e,i,a)),[u,c]=useState(!1),p=g=>{u&&(g.preventDefault(),r&&r(),c(!1));},m=useRef(null),f=g=>{let{value:h}=g.target;l(Co(h,i,a)),o(h);};return jsxs(Group,{noWrap:!0,position:"apart",spacing:"xs",py:5,children:[jsx(Text,{lineClamp:1,size:"xs",children:jsx("a",{href:s,target:"_blank",rel:"noreferrer",children:s||"--Add API Url--"})}),jsxs(Group,{noWrap:!0,spacing:0,children:[jsxs(Popover,{onClose:()=>c(!1),opened:u,position:"right",radius:"xs",withArrow:!0,children:[jsx(Popover.Target,{children:jsx(ActionIcon,{size:"xs",onClick:()=>c(g=>!g),children:u?jsx(IconCircleCheck,{}):jsx(IconPencil,{})})}),jsx(Popover.Dropdown,{children:jsx(TextInput,{placeholder:"API",defaultValue:e,ref:m,type:"url",onChange:f,size:"xs",style:{maxWidth:800,width:"60vw"},onKeyDown:getHotkeyHandler([["enter",p]])},"text-input")})]}),jsx(ActionIcon,{size:"xs",onClick:()=>n(),children:jsx(IconTrash,{color:"red"})})]})]})}var MS=ZL;d();function nM({monacoOptions:e,variables:t={}}){let o=useMonaco();return useEffect(()=>{if(o){let r="Monokai";import(`monaco-themes/themes/${r}.json`).then(n=>{o.editor.defineTheme(r,n),o.editor.setTheme(r);}).catch(()=>{throw new Error("Invalid Monaco theme")});}},[o]),jsx(Box,{className:"cr-monaco-container",w:"100%",children:jsx(tM,{defaultLanguage:"javascript",theme:"Monokai",...e})})}var ru=nM;d();Gr();ko();bl();Im();bl();ge();ie();he();Gr();la();ei();Ei();ua();fr();sg();var Du={api:null,duration:null,error:null,log:[],responseSize:null,resp:null,allowed:!0};function IV({block:e,status:t,estimatedOutputSize:o,slugsInterceptor:r,sectionFlag:n,sectionAllowed:i}){let a=useMemo(()=>n?jsx(ThemeIcon,{variant:"filled",radius:"xl",size:"sm",color:"orange",children:jsx(IconFlag,{size:"0.8rem"})}):jsx(ThemeIcon,{variant:"filled",radius:"xl",size:"sm",color:"yellow",children:jsx(IconBraces,{size:"0.8rem"})}),[n]);return jsxs(Fragment,{children:[jsxs(Group,{position:"left",pt:"xl",children:[jsxs(Group,{children:[a,jsxs(Title,{order:6,children:[ig[e.type]," ",e.id]})]}),jsxs(Group,{spacing:"xs",my:"xs",children:[t.duration&&jsx(Tooltip,{label:`Api Call Duration: ${t.duration} ms`,children:jsx(ThemeIcon,{size:"sm",radius:"xl",color:Iy(t.duration),children:jsx(IconClockHour2,{size:rem(12)})})}),t.responseSize&&jsx(Tooltip,{label:`Api Response Size: \u2248${t.responseSize.toFixed(2)} Kb`,children:jsx(ThemeIcon,{size:"sm",radius:"xl",color:Sd(t.responseSize),children:jsx(IconApi,{size:rem(12)})})}),o&&jsx(Tooltip,{label:`Block Output Size: \u2248${o.toFixed(2)} Kb`,children:jsx(ThemeIcon,{size:"sm",radius:"xl",color:Sd(o),children:jsx(IconAugmentedReality,{size:rem(12)})})}),r&&jsx(Tooltip,{label:"Slugs Interceptor Enabled",children:jsx(ThemeIcon,{size:"sm",radius:"xl",color:"green",children:jsx(IconGitMerge,{size:rem(12)})})}),n&&jsx(Tooltip,{label:`Section #${e.section_id} Allowed Flag: ${i?"YES":"NO"}`,children:jsx(ThemeIcon,{size:"sm",radius:"xl",color:i?"green":"red",children:jsx(IconFlag,{size:rem(12)})})})]})]}),jsx(Divider,{})]})}function AV(e){let{active:t,allowed:o,blockStateContent:r,blockStateSettings:n,debug:i,for:a,locale:s,isFetching:l}=e,u=je(a.id),c=po(),p=_c(a.id,s),m=$(w=>w.variables.variables[a.id]||{}),f=$(w=>w.variables.status[a.id]||{}),g=Ha[a.type].renderPreviewOnEdit&&r?r:so(a,s),h=Ha[a.type].renderPreviewOnEdit&&n?n:a.settings,[b,v]=useState(null),[C,R]=useState(Du),y=[k.GENERATOR,k.SECTION_FLAG].includes(a.type)&&b&&b.outputVariables?JSON.stringify(b.outputVariables).length/1024:void 0,A=!!([k.GENERATOR,k.SECTION_FLAG].includes(a.type)&&C.api&&C.api.indexOf("bespoke_slugs=")>-1),S=Jo(a),E=Cr();useEffect(()=>{(async()=>{if(a.type===k.VIZ){v({block:a,locale:s,variables:u,active:t}),R(Du);return}if(!t&&!Ha[a.type].evalWhenNonActive){let{nonActiveAdapter:j}=Ha[a.type],W=j&&typeof j=="function"?j():{};v(W),R(Du);return}if([k.GENERATOR,k.SECTION_FLAG].includes(a.type)){let j=!!a.contentByLocale?.logic?.content?.api,W=S?m[Eo]:!1;v({outputVariables:m,hasAPI:j,sectionAllowed:W,type:a.type}),R(f);return}if([k.SELECTOR,k.MULTIHIERARCHY_SELECTOR].includes(a.type)){let{renderVariables:j,status:W}=await Ms(a,c,p,E),q=Ao[a.type]&&typeof Ao[a.type]=="function"?Ao[a.type](j,a.id):j;v(q),R(W);return}if(a.type===k.NAV){v({headings:a.inputs,settings:a.settings});return}if(a.type===k.RELATED){let{outputVariables:j}=await Ms(a,c,p,E),{related_reports:W}=j;v({related_reports:W});return}if(a.type===k.RESET_BUTTON||a.type===k.COMPARISON_BUTTON){v(g.simple||{});return}let O=Co(g?.logic,c,p),{vars:_,error:H,log:G}=To("variables",u,O,c,void 0,p),te=Ao[a.type]&&typeof Ao[a.type]=="function"?Ao[a.type](_,a.id):_;v(te),R({...Du,error:H,log:G});})();},[g,u,S]),useEffect(()=>{f&&f.error&&f.error!==""&&notifications.show({autoClose:1e4,color:"red",id:"block-error",message:f.error,title:`Block error ID: ${a.id}`});},[f.error]);let L=ct[a.type],D=jsx("div",{style:{...{width:"100%",height:"100%",position:"absolute",top:0,left:0,opacity:.9,zIndex:4,pointerEvents:"none"},backgroundColor:"pink"},children:jsx(Center,{h:"100%",children:jsx(Text,{size:"sm",tt:"capitalize",italic:!0,children:f.hiddenByCascade===a.id?`${a.type} not allowed`:`${a.type} hidden by block ${f.hiddenByCascade}`})})});if(l)return jsx(Center,{style:{minHeight:100},w:"100%",children:jsx(Loader,{})});if(!b)return null;let{error:M,log:z}=C,I=z?z.join(`
96
96
  `):"";return jsxs("div",{id:`bespoke-${a.type}-${a.id}`,className:"cms-block-preview bespoke-block-area",style:{width:"100%",minHeight:a.type===k.VIZ?400:"auto"},children:[!o&&D,[k.GENERATOR,k.SECTION_FLAG].includes(a.type)&&jsx(IV,{block:a,status:C,estimatedOutputSize:y,slugsInterceptor:A,sectionFlag:S,sectionAllowed:b.sectionAllowed}),L?jsx(Fragment$1,{children:jsx(L,{id:a.id,debug:i,section:a.section_id,...b,settings:h,status:C})},"renderer"):jsx(Center,{style:{minHeight:100},children:jsx(Badge,{color:"gray",variant:"outline",children:a.type},"type")}),i&&I&&jsx(Textarea,{label:"Console",minRows:3,readOnly:!0,autosize:!0,maxRows:10,value:I,error:M}),i&&M&&jsx(Textarea,{label:"Error",readOnly:!0,autosize:!0,minRows:3,maxRows:10,value:M})]})}var _u=oo(AV,He);d();ge();ie();he();function _V({id:e,setBlockSettings:t,setBlockContent:o}){let{newConfirmation:r}=Pt(),n=ne(),i=He(e).data,[a,s]=useState(i.settings[dr.ACCESS]||["public"]),[l,u]=useState(i.settings[dr.FALLBACK]||!1),[c,p]=useState([]),m=je(e),f=useMemo(()=>[{value:"always",label:"always",group:"Static"},{value:"never",label:"never",group:"Static"}].concat(Object.keys(m).map(M=>({value:M,label:`${M}: ${m[M]}`,group:"Based on variable"}))),[m]),g=useMemo(()=>[{value:"public",label:"Public block, (all visitors)",group:"Exclusive"},{value:"guest",label:"Guest only block, (non logged visitors)",group:"Exclusive"},{value:"private",label:"Private block, (session required, any role)",group:"Exclusive"}],[]),h=useMemo(()=>c.map(M=>({value:`role.${M.name}`,label:`Role ${M.name} (${M.type})`,group:`${M.type} Roles`})),[c]),b=[{label:"Section-wide",value:"false"},{label:"Report-wide",value:"true"}];useEffect(()=>{n(Q.searchRole()).then(M=>{p(M.roles);});},[]),useEffect(()=>{t({[dr.ACCESS]:a}),a.includes("public")&&u(!1);},[a]),useEffect(()=>{t({[dr.FALLBACK]:l});},[l]);let v=async()=>{try{await r({title:"Are you sure?",message:"Delete this block and all its contents? This action cannot be undone.",confirmText:"Yes, Delete it."}),n(Q.deleteEntity("block",e));}catch{}},C=(M,z)=>{t({[M]:z});},R=M=>{let z=[];if(M.length===0)z=M.length===0?[g[0].value]:M;else {let I=M.slice(-1)[0],w=g.map(_=>_.value);z=w.includes(I)?[I]:M.filter(_=>!w.includes(_));}s(z);},y=M=>{let z=`return variables.${M}`;M==="always"&&(z="return true;"),M==="never"&&(z="return false;"),t({[dr.ALLOWED]:M,[dr.ALLOWED_LOGIC]:z});},A=M=>{t({[dr.IGNORE_CASCADE]:M});},S=$(M=>M.records.entities.block),E=i.consumers.filter(M=>S[M].section_id!==i.section_id),L=!!E.length,P=E.slice(0,3).map((M,z)=>jsxs(Fragment,{children:[z===E.length-1&&E.length>1?"and ":"",jsx("strong",{children:`${S[M].type} ${M} [Section ${S[M].section_id}]`},M),z<E.length-1&&E.length>1?", ":""]})),D=i.inputs.map(M=>({label:`${S[M]?.type} - ${S[M]?.id}`,value:M}));return jsx(Group,{grow:!0,align:"flex-start",children:jsxs(Stack,{justify:"flex-start",children:[jsx(Title,{order:4,children:"Visibility"}),jsx(Select,{label:"Show",description:"Set visibility setting for this block. A hidden block will not run or export variables to its consumers. As a result, all its consumers will be hidden too.",defaultValue:i.settings[dr.ALLOWED]||"always",onChange:y,data:f}),[k.GENERATOR,k.VIZ,k.SECTION_FLAG].includes(i.type)&&jsx(MultiSelect,{label:"Ignore cascade",description:"Set block as visible even if the selected inputs are hidden.",defaultValue:i.settings[dr.IGNORE_CASCADE]||[],data:D,onChange:A}),jsx(MultiSelect,{label:"Privacy",description:"This block will be shown based on the selected roles.",data:[...g,...h],value:a,onChange:R}),jsx(Checkbox,{checked:l,disabled:a.includes("public"),label:"Show fallback block when block is not allowed",onChange:M=>u(M.currentTarget.checked)}),jsx(Title,{order:4,children:"Output"}),L&&i.shared&&jsxs(Text,{size:"xs",color:"red.4",sx:{display:"flex",alignItems:"flex-start",gap:"0.4rem"},children:[jsx(IconAlertCircle,{size:"1.2rem"}),jsxs(Text,{color:"black",span:!0,inherit:!0,children:["This block is being consumed by ",P,E.length>3&&" and others",". Please, make sure you remove this block dependencies before changing this setting."]})]}),jsx(Select,{label:"Block scope",description:"Select the scope for the variables exported by this block. Section-wide (available only to blocks in the same section) or Report-wide (available to any block inside the report).",defaultValue:String(i.shared),disabled:L&&i.shared,onChange:M=>C("shared",M==="true"),data:b}),jsx(Title,{order:4,children:"Danger zone"}),jsx(Button,{variant:"outline",color:"red",onClick:v,children:"Delete Block"})]})})}var KC=_V;d();Ba();ie();hr();Lt();ge();var gg={Consumer:jsx(ThemeIcon,{size:"xs",radius:"xl",color:"red",variant:"light",children:jsx(IconLogout,{})}),Input:jsx(ThemeIcon,{size:"xs",radius:"xl",color:"green",children:jsx(IconCircleCheck,{})}),None:jsx(ThemeIcon,{size:"xs",radius:"xl",color:"gray",children:jsx(IconCirclePlus,{})})};function XV({id:e}){let t=ne(),o=useContext(_e),[r,n]=useState(""),[i]=useDebouncedValue(r,200),a=$(h=>{if(h.records.reports&&h.records.reports[0]){let b=h.records.reports[0],v=h.records.entities.report[b].sections;return Object.values(h.records.entities.block).filter(C=>v.includes(C.section_id))}return []}),s=He(e).data,l=$(h=>h.variables.variables),u=useMemo(()=>s?s.inputs.reduce((h,b)=>({...h,[b]:a[b]}),{}):[],[s]),c=(h,b)=>{if(!s)return 0;let v=s.inputs.includes(h.id),C=s.inputs.includes(b.id);if(v!==C)return v?1:-1;let R=Object.keys(l[h.id]||{}).length,y=Object.keys(l[b.id]||{}).length;return R!==y?y-R:h.shared?1:-1},p=useMemo(()=>a.filter(h=>h.id!==s.id&&(h.section_id===s.section_id||h.shared)&&h.type!==k.SECTION_FLAG).sort(c),[a]),m=useMemo(()=>p.filter(h=>{let b=String(h.id).includes(i.trim()),v=Object.keys(l[h.id]||{}).some(C=>C.includes(i.trim()));return b||v}),[p,i,l]),f=h=>{let b=u[h]?"delete":"create";t(Q.updateEntity("block",{id:e,inputAction:{operation:b,input:{input_id:h,block_id:e}}})).then(()=>{t(uo(o));});};if(!s)return null;let g=h=>s.consumers.includes(h)?gg.Consumer:s.inputs.includes(h)?gg.Input:gg.None;return jsxs(Menu,{width:"425px",children:[jsx(Menu.Target,{children:jsx(Button,{fullWidth:!0,sx:{marginBottom:"15px"},leftIcon:jsx(IconLogin,{size:"1rem",style:{transform:"scaleX(-1)"}}),children:"Add New Input"})}),jsxs(Menu.Dropdown,{children:[jsx(TextInput,{placeholder:"Search by variable name or block id.",size:"xs",value:r,onChange:h=>n(h.target.value)}),m.map(({id:h,shared:b})=>jsx(Menu.Item,{disabled:s.consumers.includes(h),onClick:()=>f(h),icon:g(h),rightSection:jsxs(Stack,{ml:"xs",spacing:"xs",align:"flex-end",children:[jsxs(Text,{size:"xs",color:"gray.6",children:["[",h,"]"]}),b?jsx(ThemeIcon,{size:"xs",radius:"xl",children:jsx(IconGlobe,{})}):null]}),children:jsx(Box,{style:{maxWidth:"400px"},children:jsx(tr,{id:`${h}`,variables:l[h]})})},h))]})]})}var qC=XV;fm();d();he();ge();d();ge();d();d();var hg=e=>`
97
97
  `.padEnd(e*2+1," "),YC=(e,t=0)=>{let o=e instanceof Array;return `${o?"[":"{"}${hg(t+1)}${Object.keys(e).sort((r,n)=>r.localeCompare(n)).map(r=>{let n=o?"":`${r}: `,i=e[r];return typeof i=="object"?n+=`${YC(i,t+1)}`:typeof i=="string"&&(i.includes("=>")||i.startsWith("variables["))?n+=`${i}`:typeof i=="string"&&!i.length?n+="false":i===void 0?n=null:["boolean","number"].includes(typeof i)?n+=i:n+=`"${i}"`,n}).filter(r=>r!==null).join(`,${hg(t+1)}`)}${hg(t)}${o?"]":"}"}`},Xa=YC;he();d();xn();d();var JC=e=>{if(!e)return e;let t=Array.isArray(e)?[]:{};return Object.keys(e).forEach(o=>{t[o]=typeof e[o]=="object"?JC(e[o]):e[o];}),t},$u=JC;d();var QV=e=>{let t=/([A-z0-9]*)\{\{([^}]+)\}\}/g,o=(i,a,s)=>a?`\${formatters.${a}(variables.${s})}`:`\${variables.${s}}`,r=i=>typeof i=="string"?i.trim()===""?!1:i.replace(t,o):Array.isArray(i)?i.map(a=>r(a)):typeof i=="object"&&i!==null?Object.keys(i).sort((a,s)=>a.localeCompare(s)).reduce((a,s)=>({...a,[s]:r(i[s])}),{}):typeof i=="boolean"||typeof i=="number"?i:JSON.stringify(i),n=r(e);return Array.isArray(e)?`return ${JSON.stringify(n)};`:Object.keys(n).sort((i,a)=>i.localeCompare(a)).reduce((i,a)=>{let s;return typeof n[a]=="string"?n[a].includes("=>")||n[a].startsWith("variables[")?s=n[a]:s=`\`${n[a]}\``:typeof n[a]=="boolean"||typeof n[a]=="number"?s=n[a]:s=JSON.stringify(n[a]),i.concat(`"${a}": ${s},
98
98
  `)},"return {").concat("};")},Ln=QV;d();d();d();function nk(e){let{state:t,transaction:o}=e,{selection:r}=o,{doc:n}=o,{storedMarks:i}=o;return {...t,apply:t.apply.bind(t),applyTransaction:t.applyTransaction.bind(t),plugins:t.plugins,schema:t.schema,reconfigure:t.reconfigure.bind(t),toJSON:t.toJSON.bind(t),get storedMarks(){return i},get selection(){return r},get doc(){return n},get tr(){return r=o.selection,n=o.doc,i=o.storedMarks,o}}}var Sg=class{constructor(t){this.editor=t.editor,this.rawCommands=this.editor.extensionManager.commands,this.customState=t.state;}get hasCustomState(){return !!this.customState}get state(){return this.customState||this.editor.state}get commands(){let{rawCommands:t,editor:o,state:r}=this,{view:n}=o,{tr:i}=r,a=this.buildProps(i);return Object.fromEntries(Object.entries(t).map(([s,l])=>[s,(...c)=>{let p=l(...c)(a);return !i.getMeta("preventDispatch")&&!this.hasCustomState&&n.dispatch(i),p}]))}get chain(){return ()=>this.createChain()}get can(){return ()=>this.createCan()}createChain(t,o=!0){let{rawCommands:r,editor:n,state:i}=this,{view:a}=n,s=[],l=!!t,u=t||i.tr,c=()=>(!l&&o&&!u.getMeta("preventDispatch")&&!this.hasCustomState&&a.dispatch(u),s.every(m=>m===!0)),p={...Object.fromEntries(Object.entries(r).map(([m,f])=>[m,(...h)=>{let b=this.buildProps(u,o),v=f(...h)(b);return s.push(v),p}])),run:c};return p}createCan(t){let{rawCommands:o,state:r}=this,n=!1,i=t||r.tr,a=this.buildProps(i,n);return {...Object.fromEntries(Object.entries(o).map(([l,u])=>[l,(...c)=>u(...c)({...a,dispatch:void 0})])),chain:()=>this.createChain(i,n)}}buildProps(t,o=!0){let{rawCommands:r,editor:n,state:i}=this,{view:a}=n,s={tr:t,editor:n,view:a,state:nk({state:i,transaction:t}),dispatch:o?()=>{}:void 0,chain:()=>this.createChain(t,o),can:()=>this.createCan(t),get commands(){return Object.fromEntries(Object.entries(r).map(([l,u])=>[l,(...c)=>u(...c)(s)]))}};return s}};function qt(e,t,o){return e.config[t]===void 0&&e.parent?qt(e.parent,t,o):typeof e.config[t]=="function"?e.config[t].bind({...o,parent:e.parent?qt(e.parent,t,o):null}):e.config[t]}function EF(e){let t=e.filter(n=>n.type==="extension"),o=e.filter(n=>n.type==="node"),r=e.filter(n=>n.type==="mark");return {baseExtensions:t,nodeExtensions:o,markExtensions:r}}function zt(e,t){if(typeof e=="string"){if(!t.nodes[e])throw Error(`There is no node type named '${e}'. Maybe you forgot to add the extension?`);return t.nodes[e]}return e}function ik(...e){return e.filter(t=>!!t).reduce((t,o)=>{let r={...t};return Object.entries(o).forEach(([n,i])=>{if(!r[n]){r[n]=i;return}if(n==="class"){let s=i?i.split(" "):[],l=r[n]?r[n].split(" "):[],u=s.filter(c=>!l.includes(c));r[n]=[...l,...u].join(" ");}else if(n==="style"){let s=i?i.split(";").map(c=>c.trim()).filter(Boolean):[],l=r[n]?r[n].split(";").map(c=>c.trim()).filter(Boolean):[],u=new Map;l.forEach(c=>{let[p,m]=c.split(":").map(f=>f.trim());u.set(p,m);}),s.forEach(c=>{let[p,m]=c.split(":").map(f=>f.trim());u.set(p,m);}),r[n]=Array.from(u.entries()).map(([c,p])=>`${c}: ${p}`).join("; ");}else r[n]=i;}),r},{})}function RF(e){return typeof e=="function"}function Nt(e,t=void 0,...o){return RF(e)?t?e.bind(t)(...o):e(...o):e}function wF(e){return Object.prototype.toString.call(e)==="[object RegExp]"}var Ku=class{constructor(t){this.find=t.find,this.handler=t.handler;}};function IF(e){return Object.prototype.toString.call(e).slice(8,-1)}function Uu(e){return IF(e)!=="Object"?!1:e.constructor===Object&&Object.getPrototypeOf(e)===Object.prototype}function Ju(e,t){let o={...e};return Uu(e)&&Uu(t)&&Object.keys(t).forEach(r=>{Uu(t[r])&&Uu(e[r])?o[r]=Ju(e[r],t[r]):o[r]=t[r];}),o}var Mi=class{constructor(t={}){this.type="mark",this.name="mark",this.parent=null,this.child=null,this.config={name:this.name,defaultOptions:{}},this.config={...this.config,...t},this.name=this.config.name,t.defaultOptions&&Object.keys(t.defaultOptions).length>0&&console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${this.name}".`),this.options=this.config.defaultOptions,this.config.addOptions&&(this.options=Nt(qt(this,"addOptions",{name:this.name}))),this.storage=Nt(qt(this,"addStorage",{name:this.name,options:this.options}))||{};}static create(t={}){return new Mi(t)}configure(t={}){let o=this.extend({...this.config,addOptions:()=>Ju(this.options,t)});return o.name=this.name,o.parent=this.parent,o}extend(t={}){let o=new Mi(t);return o.parent=this,this.child=o,o.name=t.name?t.name:o.parent.name,t.defaultOptions&&Object.keys(t.defaultOptions).length>0&&console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${o.name}".`),o.options=Nt(qt(o,"addOptions",{name:o.name})),o.storage=Nt(qt(o,"addStorage",{name:o.name,options:o.options})),o}static handleExit({editor:t,mark:o}){let{tr:r}=t.state,n=t.state.selection.$from;if(n.pos===n.end()){let a=n.marks();if(!!!a.find(u=>u?.type.name===o.name))return !1;let l=a.find(u=>u?.type.name===o.name);return l&&r.removeStoredMark(l),r.insertText(" ",n.pos),t.view.dispatch(r),!0}return !1}};var xg=class{constructor(t){this.find=t.find,this.handler=t.handler;}};var Yt=class{constructor(t={}){this.type="extension",this.name="extension",this.parent=null,this.child=null,this.config={name:this.name,defaultOptions:{}},this.config={...this.config,...t},this.name=this.config.name,t.defaultOptions&&Object.keys(t.defaultOptions).length>0&&console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${this.name}".`),this.options=this.config.defaultOptions,this.config.addOptions&&(this.options=Nt(qt(this,"addOptions",{name:this.name}))),this.storage=Nt(qt(this,"addStorage",{name:this.name,options:this.options}))||{};}static create(t={}){return new Yt(t)}configure(t={}){let o=this.extend({...this.config,addOptions:()=>Ju(this.options,t)});return o.name=this.name,o.parent=this.parent,o}extend(t={}){let o=new Yt({...this.config,...t});return o.parent=this,this.child=o,o.name=t.name?t.name:o.parent.name,t.defaultOptions&&Object.keys(t.defaultOptions).length>0&&console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${o.name}".`),o.options=Nt(qt(o,"addOptions",{name:o.name})),o.storage=Nt(qt(o,"addStorage",{name:o.name,options:o.options})),o}};function AF(e,t,o){let{from:r,to:n}=t,{blockSeparator:i=`
@@ -119,7 +119,7 @@ return {
119
119
  `,`1) content: element.innerHTML
120
120
  `,"2) content: () => element.cloneNode(true)"].join(" "));}var s=n.reduce(function(l,u){var c=u&&iG(u,r);return c&&l.push(c),l},[]);return Dl(e)?s[0]:s}Nl.defaultProps=ho;Nl.setDefaultProps=tG;Nl.currentInput=Or;Object.assign({},wl,{effect:function(t){var o=t.state,r={popper:{position:o.options.strategy,left:"0",top:"0",margin:"0"},arrow:{position:"absolute"},reference:{}};Object.assign(o.elements.popper.style,r.popper),o.styles=r,o.elements.arrow&&Object.assign(o.elements.arrow.style,r.arrow);}});Nl.setDefaultProps({render:oE});var rE=Nl;d();var hG=forwardRef(function(t,o){let r=useMantineTheme(),[n,i]=useState(0),a=c=>{let p=t.items[c];p&&t.command({id:p});},s=()=>{i((n+t.items.length-1)%t.items.length);},l=()=>{i((n+1)%t.items.length);},u=()=>{a(n);};return useEffect(()=>i(0),[t.items]),useImperativeHandle(o,()=>({onKeyDown:({event:c})=>c.key==="ArrowUp"?(s(),!0):c.key==="ArrowDown"?(l(),!0):c.key==="Enter"||c.key==="Tab"?(u(),!0):!1})),jsx(List,{className:"items",bg:"white",listStyleType:"none",styles:c=>({root:{boxShadow:c.shadows.md,borderRadius:c.radius.xs,overflow:"hidden"},item:{span:{display:"block",width:"100%"}},itemWrapper:{display:"block"}}),children:t.items.length?t.items.map((c,p)=>jsx(List.Item,{children:jsx(UnstyledButton,{className:`item ${p===n?"is-selected":""}`,sx:m=>({backgroundColor:p===n?m.colors.blue[0]:"none"}),py:2,px:4,fz:12,w:"100%",onClick:()=>a(p),children:jsxs(Group,{spacing:"xs",children:[jsx(Center,{h:"1rem",w:"1rem",sx:{borderRadius:"100%",background:r.colors.blue[6]},children:jsx(IconBraces,{size:"0.8rem",color:"white"})}),jsx(Text,{ff:"monospace",component:"code",color:"gray.7",children:`${c}`})]})})},p)):null})}),iE=hG;var vG=e=>({char:"{{",allowedPrefixes:[" "],items:({query:t,editor:o})=>o.storage.VariablesStorage.suggestions.filter(r=>r.toLowerCase().startsWith(t.toLowerCase())).slice(0,5),render:()=>{let t,o;return {onStart:r=>{t=new ReactRenderer(iE,{props:r,editor:r.editor}),r.clientRect&&(o=rE("body",{getReferenceClientRect:r.clientRect,appendTo:()=>document.body,content:t.element,showOnCreate:!0,interactive:!0,trigger:"manual",placement:"bottom-start"}));},onUpdate(r){t.updateProps(r),r.clientRect&&o[0].setProps({getReferenceClientRect:r.clientRect});},onKeyDown(r){return r.event.key==="Escape"?(o[0].hide(),!0):t.ref?.onKeyDown(r)},onExit(){o[0].destroy(),t.destroy();}}}}),aE=vG;d();function Xg(e){return e.replace(/<code[^>]*>([^<>]*)<\/code>/g,"$1")}d();function Qg(e){return e.replace(/({{.*?}})/g,'<code class="bespoke-var">$1</code>')}var GG=createStyles(e=>({bespokeEditor:{fontSize:14,lineHeight:1.2,backgroundColor:e.fn.lighten(e.colors.gray[0],.3),borderColor:e.colors.gray[4],borderWidth:1,borderStyle:"solid",borderRadius:e.radius.md,paddingLeft:e.spacing.xs,paddingRight:e.spacing.xs,fontWeight:400,"&.disabled":{color:e.colors.gray[7],backgroundColor:e.colors.gray[1]},":focus-visible":{outlineColor:e.colors.blue[5],backgroundColor:e.fn.lighten(e.colors.gray[0],.5)},code:{fontFamily:"monospace",color:e.colors.blue[6],fontWeight:700,letterSpacing:.02},".is-editor-empty:first-of-type::before":{color:e.colors.gray[6],content:"attr(data-placeholder)",float:"left",height:0,pointerEvents:"none"}}})),lE=()=>{let{editor:e}=useCurrentEditor(),t=useMantineTheme();return e?jsxs(Button.Group,{children:[jsx(Button,{onClick:o=>{o.preventDefault(),e.chain().focus().toggleBold().focus().run();},size:"xs",variant:"default",compact:!0,children:jsx(IconBold,{size:"0.8rem",stroke:e.isActive("bold")?4:2,color:t.colors.gray[7]})}),jsx(Button,{onClick:()=>e.chain().focus().toggleItalic().run(),size:"xs",variant:"default",compact:!0,children:jsx(IconItalic,{size:"0.8rem",stroke:e.isActive("italic")?4:2,color:t.colors.gray[7]})}),jsx(Button,{onClick:()=>e.chain().focus().toggleUnderline().run(),size:"xs",variant:"default",compact:!0,children:jsx(IconUnderline,{size:"0.8rem",stroke:e.isActive("underline")?4:2,color:t.colors.gray[7]})})]}):null},HG=()=>{let{editor:e}=useCurrentEditor();return jsx("div",{children:jsx(BubbleMenu,{tippyOptions:{placement:"bottom"},editor:e,children:jsx(lE,{})})})},jG=()=>{let{editor:e}=useCurrentEditor(),t=useMantineTheme();return e?jsxs(Button.Group,{children:[jsx(Button,{onClick:()=>e.chain().focus().setTextAlign("left").run(),size:"xs",variant:"default",compact:!0,children:jsx(IconAlignLeft,{size:"0.8rem",stroke:e.isActive({textAlign:"left"})?4:2,color:t.colors.gray[7]})}),jsx(Button,{onClick:()=>e.chain().focus().setTextAlign("center").run(),size:"xs",variant:"default",compact:!0,children:jsx(IconAlignCenter,{size:"0.8rem",stroke:e.isActive({textAlign:"center"})?4:2,color:t.colors.gray[7]})}),jsx(Button,{onClick:()=>e.chain().focus().setTextAlign("right").run(),size:"xs",variant:"default",compact:!0,children:jsx(IconAlignRight,{size:"0.8rem",stroke:e.isActive({textAlign:"right"})?4:2,color:t.colors.gray[7]})}),jsx(Button,{onClick:()=>e.chain().focus().setTextAlign("justify").run(),size:"xs",variant:"default",compact:!0,children:jsx(IconAlignJustified,{size:"0.8rem",stroke:e.isActive({textAlign:"justify"})?4:2,color:t.colors.gray[7]})})]}):null},WG=()=>{let{editor:e}=useCurrentEditor(),t=useMantineTheme();return e?jsxs(Button.Group,{children:[jsx(Button,{onClick:()=>e.commands.undo(),size:"xs",variant:"default",compact:!0,children:jsx(IconArrowBackUp,{size:"0.8rem",color:t.colors.gray[7]})}),jsx(Button,{onClick:()=>e.commands.redo(),size:"xs",variant:"default",compact:!0,children:jsx(IconArrowForwardUp,{size:"0.8rem",color:t.colors.gray[7]})})]}):null},KG=({toolbarActive:e=!0,toolbarLeftSection:t=null,toolbarRightSection:o=null,toolbarOptions:r={}})=>{let n=r.history??!0,i=r.alignment??!1,a=r.format??!0;return jsxs(Group,{mb:"0.25rem",position:"apart",children:[t,e&&jsxs(Group,{children:[n&&jsx(WG,{}),i&&jsx(jG,{}),a&&jsx(lE,{})]}),o]})};function ap(e){let{id:t,value:o,onChange:r=()=>{},variables:n,toolbarLeftSection:i,toolbarRightSection:a,toolbarOptions:s={},tipTapExtensions:l=[],bubbleMenu:u=!0,disabled:c=!1,editorProps:p,placeholder:m="This looks empty! Start writing some content"}=e,[f,g]=useState(!1),h=useClickOutside(()=>g(!1)),{classes:b}=GG(),v=JSON.stringify(n||{}),C=useMemo(()=>{let A=JSON.parse(v),S=[RG.configure({heading:!1,bold:!1,history:{depth:20},code:!1,hardBreak:!1,codeBlock:!1}),mk.extend({spanning:!0}),IG.extend({addKeyboardShortcuts(){return {Enter:()=>this.editor.commands.setHardBreak()}}}),AG.configure({types:["paragraph"]}),EG,fk,PG.configure({placeholder:m}),UG,...l];return A&&(S.push(gk),S.push(wG.configure({HTMLAttributes:{type:null},renderText({node:E}){return `{{${E.attrs.label??E.attrs.id}}}`},renderHTML({node:E}){return ["code",{},`{{${E.attrs.label??E.attrs.id}}}`]},suggestion:aE()}))),S},[v,l,m]),R=({editor:A})=>{let S=Xg(A.getHTML());r(S);},y=({editor:A})=>{let S=JSON.parse(v);A.storage.VariablesStorage.suggestions=Object.keys(S);};return jsx(Box,{ref:h,className:"bespoke-editor",onClickCapture:()=>g(!0),children:jsx(EditorProvider,{extensions:C,content:o?Qg(o):void 0,onUpdate:R,onFocus:y,editable:!c,slotBefore:jsx(KG,{toolbarActive:f,toolbarLeftSection:i,toolbarRightSection:a,toolbarOptions:s}),editorProps:{editable:()=>!c,attributes:{id:t||"",class:`${b.bespokeEditor}${c?" disabled":""}`}},...p,children:u&&jsx(HG,{})})})}d();ge();he();var cE=createContext({mode:"simple",changeEditorMode:()=>{},reference:{locale:void 0,content:{},activate:()=>{},deactivate:()=>{},setActive:()=>{},active:!1}});function QG(e){let[t,o]=useState(!1),[r,n]=useState({}),i=xa();return useEffect(()=>{if(!t){n(void 0);return}Cc.get(`/api/cms/read/block?&id=${e}&include=true`).then(({data:a})=>{n(a.data[0].contentByLocale[i].content.simple);}).catch(()=>n(void 0));},[t,e,i]),{content:r,locale:i,activate:()=>o(!0),deactivate:()=>o(!1),setActive:o}}function uE({children:e,buttons:t,blockType:o,blockId:r}){let[n,i]=useState(()=>[k.VIZ,k.GENERATOR,k.SECTION_FLAG].includes(o)?"code":"simple"),a=QG(r),s={mode:n,changeEditorMode:i,reference:a,...t};return jsx(cE.Provider,{value:s,children:e})}function Lr(){return useContext(cE)}function mH({locale:e,content:t}){return jsxs(Group,{spacing:"xs",position:"right",children:[jsx(Badge,{variant:"light",size:"xs",rightSection:jsx(Center,{children:jsx(IconLanguage,{size:rem(12)})}),children:e.toUpperCase()}),jsx(mE,{content:t})]})}function mE({content:e}){return jsx(CopyButton,{value:e,timeout:2e3,children:({copied:t,copy:o})=>jsx(Tooltip,{label:t?"Copied":"Copy",withArrow:!0,position:"right",children:jsx(ActionIcon,{size:"xs",color:t?"teal":"gray",variant:"subtle",onClick:()=>{o();let r=new Blob([e],{type:"text/html"}),n=new ClipboardItem({"text/html":r});navigator.clipboard.write([n]);},children:t?jsx(IconCheck,{style:{width:rem(16)}}):jsx(IconCopy,{style:{width:rem(16)}})})})})}function fH({referenceLocale:e,referenceContent:t}){return jsx(Stack,{spacing:"xs",children:jsx(ap,{value:t,toolbarLeftSection:jsx(Text,{size:"0.625rem",tt:"uppercase",fw:700,color:"gray",children:"Reference Content"}),toolbarRightSection:jsx(mH,{locale:e,content:t}),toolbarOptions:{history:!1,format:!1,alignment:!1},disabled:!0})})}function sr({field:e,handleEditor:t,value:o,referenceContent:r,referenceLocale:n,variables:i,editorConfig:a={}}){return jsxs(Stack,{spacing:0,children:[jsx(ap,{id:e,onChange:s=>{t(e,lt(s));},toolbarLeftSection:jsx(Text,{component:"label",htmlFor:e,size:"xs",transform:"uppercase",weight:"bold",color:"gray",mb:"xs",children:titleCase(e)}),toolbarRightSection:jsx(mE,{content:o}),toolbarOptions:{history:!0,alignment:e!=="tooltip",format:!0},value:o,variables:i,placeholder:`This looks empty. Start adding content for the ${e}! You can add automated {{variables}}`,...a}),r&&jsx(Box,{mt:"xs",children:jsx(fH,{referenceContent:r[e],referenceLocale:n})})]})}function gH({fields:e,locale:t,defaultContent:o,onChange:r,variables:n}){let[i,a]=useState(()=>$u(o)),{reference:s}=Lr();useEffect(()=>{r(i,t);},[]);let l=(c,p)=>{a(m=>({...m,[c]:p}));},[u]=useDebouncedValue(i,500);return useEffect(()=>{let c=Object.keys(u).reduce((m,f)=>({...m,[f]:lt(u[f])}),{}),p=Ln(c);r({simple:c,logic:p},t);},[u,t]),jsx(Stack,{spacing:"xl",children:e.map(({field:c,editorConfig:p})=>jsx(sr,{field:c,handleEditor:l,value:i[c]||"",referenceContent:s.content,referenceLocale:s.locale,variables:n,editorConfig:p},c))})}var fE=gH;d();function xH({label:e,...t}){return jsxs(Group,{position:"apart",spacing:"lg",py:"xs",...t,children:[jsx(Text,{children:e}),jsx(Tooltip,{label:"This setting will be saved for all languages.",children:jsx(ThemeIcon,{size:"xs",variant:"light",radius:"xl",color:"yellow",children:jsx(IconLanguageOff,{size:"0.75rem"})})})]})}var It=xH;ge();d();var Wi={SINGLE:"single",MULTI:"multi"},rh={SEGMENTED_CONTROL:"segmented control",SELECTOR:"selector"},_n={STATIC:"static",DYNAMIC:"dynamic"},nh=e=>e&&Array.isArray(e)&&e.length>0,lp=e=>nh(e)&&["string"].includes(typeof e[0]),hE=e=>{let{name:t,type:o,optionsType:r,options:n}=e;return [t,o,r,n].every(Boolean)?r===_n.STATIC?n.static?.length>0&&n.static?.every(i=>i.id):n.dynamic?.isPrimitiveType?!0:!!n.dynamic?.idKey:!1},cp=(e,t,o)=>{let r,n;switch(o){case _n.STATIC:r=e===Wi.SINGLE?t.static.find(i=>i.isDefault)?.id:t.static.filter(i=>i.isDefault).map(i=>i.id),n=t.static.map(({id:i,label:a})=>({id:i,label:a||i}));break;case _n.DYNAMIC:if(t.dynamic){let{optionsVar:i,idKey:a,labelKey:s,imageKey:l,defaultVar:u,isPrimitiveType:c}=t.dynamic;u&&(r=`variables["${u}"]`),n=c?`variables["${i}"]`:`(variables["${i}"] || []).map(d => ({id: String(d["${a}"]), label: String(d["${s||a}"]), imageUrl: String(d["${l||null}"])}))`;}break;}return {logicOptions:n,defaultValue:r}};function IH({option:e,editOption:t,deleteOption:o}){return jsxs("tr",{className:"reports-selector-static-option",children:[jsx("td",{children:jsx(Checkbox,{checked:e.isDefault,onChange:r=>t({isDefault:r.currentTarget.checked})})}),jsx("td",{children:jsx(TextInput,{placeholder:"Option value",value:e.id,onChange:r=>{t({id:r.currentTarget.value});},error:e.id.indexOf(" ")>-1?"Please, avoid the usage of spaces in the ID":!1})}),jsx("td",{children:jsx(TextInput,{placeholder:"Option label",value:e.label,onChange:r=>t({label:r.currentTarget.value})})}),jsx("td",{children:jsx(ActionIcon,{onClick:o,children:jsx(IconTrash,{})})})]})}function AH({staticOptions:e,setStaticOptions:t}){let o=useCallback(()=>t([...e,{isDefault:!e.length,id:"",label:""}]),[e,t]),r=useCallback((i,a)=>{if(!a||i>=e.length||i<0)return;let s=[...e];s.splice(i,1,{...e[i],...a}),t(s);},[e,t]),n=useCallback(i=>{let a=[...e];a.splice(i,1),t(a);},[e,t]);return jsxs(Fragment,{children:[jsx(Input.Wrapper,{required:!0,label:"Static Selector Options",children:jsxs("table",{children:[jsx("thead",{children:e.length>0&&jsx("tr",{children:["Default","ID","Label",""].map((i,a)=>jsx("td",{className:`${a===0?"selector-option-default-col":""} ${a===1?"required":""}`,children:i},`heading-${a}`))})}),jsx("tbody",{children:e.map((i,a)=>jsx(IH,{option:i,editOption:s=>r(a,s),deleteOption:()=>n(a)},`option-${a}`))})]})}),jsx(ActionIcon,{onClick:o,children:jsx(IconPlus,{})})]})}function PH({id:e,dynamicOptions:t,setDynamicOptions:o}){let{optionsVar:r,idKey:n,labelKey:i,defaultVar:a,imageKey:s,isPrimitiveType:l}=t,u=je(e),[c,p]=useState(!1),[m,f]=useState({}),[g,h]=useState([]),[b,v]=useState([]);useEffect(()=>{u||(f({}),h([]));let E=Object.entries(u).filter(([P,D])=>nh(D)).reduce((P,[D,M])=>(P[D]=M,P),{});f(E);let L=Object.keys(u);h(L),p(!0);},[u]);let C=useCallback((E,L)=>{o({...t,[E]:L});},[t]);useEffect(()=>{if(!Object.keys(m).length)return;let E=lp(m[r]);if(E)v([]),C("idKey",null),C("labelKey",null),C("imageKey",null);else {let L=new Set;(m[t.optionsVar]||[]).forEach(D=>Object.keys(typeof D=="object"?D:{}).forEach(M=>L.add(M)));let P=Array.from(L).sort().map(D=>D);v(P);}C("isPrimitiveType",E);},[m,r]);let R=useCallback(E=>{o({...t,optionsVar:E,idKey:null,labelKey:null,imageKey:null});},[t,o]),y=useMemo(()=>{let E=[];return m&&r&&n&&Array.isArray(m[r])&&(E=m[r].filter(L=>`${L[n]}`.indexOf(" ")>0)),E.length>0?`One or more ID's have spaces on it. (
121
121
  ${E.map(L=>`"${L[n]}"`).join(",")}
122
- ) Avoid this, please.`:!1},[m,r,n]);if(!c)return null;let A=Object.keys(m),S=E=>E&&Array.isArray(E)&&E.length;return jsxs(Fragment,{children:[jsx(Select,{label:"Options List Variable",placeholder:"Pick a variable",value:S(A)&&r,required:!0,onChange:R,data:A}),jsx(Select,{label:"Options ID Key",placeholder:"Pick a property key",value:S(b)&&n,required:!l,disabled:l,onChange:E=>C("idKey",E),data:b,error:y}),jsx(Select,{label:"Options Label Key",placeholder:"Pick a property key",disabled:l,clearable:!0,value:S(b)&&i,onChange:E=>C("labelKey",E),data:b}),jsx(Select,{label:"Options Image Key",placeholder:"Pick a property key",disabled:l,clearable:!0,value:S(b)&&s,onChange:E=>C("imageKey",E),data:b}),jsx(Select,{label:"Default ID Variable",placeholder:"Pick a variable",clearable:!0,value:S(g)&&a,onChange:E=>C("defaultVar",E),data:g})]})}function ss(e,t,o){return e&&e[t]||o}function OH(e){let{id:t,executeButton:o,onChange:r,simpleState:n,referenceContent:i,referenceLocale:a,variables:s}=e,[l,u]=useState(()=>{let m=n&&n.options&&Object.prototype.hasOwnProperty.call(n?.options,"dynamic")&&Object.prototype.hasOwnProperty.call(n?.options,"static");return {selectorIdentifier:ss(n,"name",""),selectorType:ss(n,"type",Wi.SINGLE),selectorComponent:ss(n,"component",rh.SELECTOR),options:n&&m?n.options:{static:[],dynamic:{}},optionsType:ss(n,"optionsType","static"),hideLabel:ss(n,"hideLabel","false"),resetSectionVars:ss(n,"resetSectionVars","false")}});useEffect(()=>{let{selectorIdentifier:m,selectorType:f,selectorComponent:g,options:h,optionsType:b,hideLabel:v,resetSectionVars:C}=l,R={name:m,hideLabel:v,resetSectionVars:C,component:g,type:f},{logicOptions:y,defaultValue:A}=cp(f,h,b);A&&(R.defaultValue=A),R.options=y;let S=`return ${Xa(R)};`,E={name:m,type:f,component:g,hideLabel:v,resetSectionVars:C,defaultValue:A,optionsType:b,options:h},L=hE(E);r(E,S,L);},[l]);let c=(m,f)=>u(g=>({...g,[m]:f})),p=pr[k.SELECTOR].find(m=>m.field===ke.SELECTOR_NAME)?.editorConfig;return jsxs(Fragment,{children:[jsxs(Stack,{children:[jsx(sr,{field:"name",value:l.selectorIdentifier,handleEditor:(m,f)=>c("selectorIdentifier",f),referenceContent:i,referenceLocale:a,variables:s,editorConfig:p}),jsx(Checkbox,{label:jsx(It,{label:"Hide Label",py:0}),checked:l.hideLabel==="true",onChange:m=>c("hideLabel",m.currentTarget.checked?"true":"false")})]}),jsx(Select,{label:jsx(It,{label:"Selector Type"}),value:l.selectorType,onChange:m=>c("selectorType",m),data:Object.values(Wi)}),l.selectorType===Wi.SINGLE&&jsx(Select,{label:jsx(It,{label:"Selector Component"}),value:l.selectorComponent,onChange:m=>c("selectorComponent",m),data:Object.values(rh)}),jsx(Select,{label:jsx(It,{label:"Options Type"}),value:l.optionsType,onChange:m=>c("optionsType",m),data:Object.values(_n)}),l.optionsType===_n.STATIC?jsx(AH,{staticOptions:l.options.static,setStaticOptions:m=>c("options",{...l.options,static:m})}):jsx(PH,{dynamicOptions:l.options.dynamic,setDynamicOptions:m=>c("options",{...l.options,dynamic:m}),id:t}),jsx(Checkbox,{my:"md",label:jsx(It,{label:"Reset SectionVariables on change",py:0}),checked:l.resetSectionVars==="true",onChange:m=>c("resetSectionVars",m.currentTarget.checked?"true":"false")}),o]})}var vE=OH;d();function lh(){return jsx(Title,{order:4,children:"Nav UI"})}d();function ch({executeButton:e,onChange:t,simpleState:o}){let[r,n]=useState(o?.compare??"variant"),[i,a]=useState(o?.limit??4);return useEffect(()=>{t({compare:r,limit:i});},[r,i]),jsxs(Stack,{children:[jsx(Radio.Group,{label:"Compare with members of",onChange:n,value:r,children:jsxs(Group,{children:[jsx(Radio,{label:"Same report",value:"report"}),jsx(Radio,{label:"Same dimension",value:"dimension"}),jsx(Radio,{label:"Same variant",value:"variant"})]})}),jsx(NumberInput,{label:"Related reports limit",min:1,onChange:s=>a(s),type:"number",value:i}),e]})}d();function ph({executeButton:e,onChange:t,simpleState:o}){let[r,n]=useState(o?.label??""),[i,a]=useState(o?.showIcon??!0),[s,l]=useState(o?.fullWidth??!1),[u,c]=useState(o?.showWhenDisabled??!1);return useEffect(()=>{t({label:r,showIcon:i,fullWidth:s,showWhenDisabled:u});},[r,i,s,u,t]),jsxs(Stack,{children:[jsx(TextInput,{placeholder:"Label for reset section state button",value:r,onChange:p=>n(p.target.value),label:"Label"}),jsxs(Group,{children:[jsx(Switch,{checked:i,label:"Show icon",onChange:p=>a(p.currentTarget.checked)}),jsx(Switch,{checked:s,label:"Full width",onChange:p=>l(p.currentTarget.checked)}),jsx(Switch,{checked:u,label:"Show when disabled",onChange:p=>c(p.currentTarget.checked)})]}),e]})}d();d();function Ul(e,t){let[o,r]=useState({...t,...e});return {state:o,updateState:(i,a)=>{let s={...o,[i]:a};r(s);}}}d();var kE=["xs","sm","md","lg","xl"],tj=["0","1","2","3","4","5"],an={none:{value:"none",label:"No Icon"},tabler:{value:"tabler",label:"Bespoke (Tabler)",link:"https://tablericons.com",text:"Tabler Icons"},custom:{value:"custom",label:"Custom Icon"}},oj=forwardRef(({value:e,iconType:t="tabler",...o},r)=>jsx("div",{ref:r,...o,children:jsxs(Group,{noWrap:!0,children:[jsx(Image,{width:20,height:20,src:`/api/cms/read/icons/${t}/icon.svg?name=${e}`,alt:`Icon preview ${e}`}),jsx(Text,{size:"sm",children:e})]})}));function hp(e){let[t,o]=useState(e?._iconType??"none"),[r,n]=useState(e?._icon??""),[i,a]=useState([]),[s,l]=useState(""),[u,c]=useState(e?._iconVariant??"transparent"),[p,m]=useState(e?._iconSize??"md"),[f,g]=useState(e?._iconRadius??"md"),[h,b]=useState(e?._iconPadding??"1"),v=[an.none.value,an.custom.value].includes(t),C=useRef(null),R=useMemo(()=>({_icon:r,_iconType:t,_defaultIcon:s,_iconVariant:u,_iconSize:p,_iconRadius:f,_iconPadding:h}),[r,t,s,u,p,f,h]),y=S=>{n(""),o(S);};useEffect(()=>{v||Cc.get(`/api/cms/list/icons/${t}`).then(S=>{a(S.data.data.results),l(S.data.data.results[0]);});},[t]);let A=jsx(Accordion,{variant:"separated",children:jsxs(Accordion.Item,{value:"icon",children:[jsx(Accordion.Control,{icon:jsx(IconPhotoFilled,{}),children:jsxs(Text,{children:["Icon configuration: ",an[t]&&jsx("strong",{children:an[t].label})]})}),jsx(Accordion.Panel,{children:jsxs(Stack,{children:[jsx(Input.Wrapper,{label:"Title's icon",children:jsx(SegmentedControl,{fullWidth:!0,value:t,onChange:y,data:Object.values(an)})}),!v&&jsx(Select,{label:"Choose an icon from the list",searchable:!0,description:jsxs(Fragment,{children:["Powered by"," ",jsx("a",{style:{textDecoration:"underline"},href:an[t].link,target:"_blank",rel:"noreferrer",children:an[t].text}),"."]}),defaultValue:s,value:r,required:!0,onChange:S=>n(S||""),data:i,limit:10,itemComponent:oj,disabled:!i||i.length===0,icon:jsx(Image,{p:5,src:`/api/cms/read/icons/${t}/icon.svg?name=${r||s}`,alt:"Icon preview"})}),t===an.custom.value&&jsxs(Flex,{align:"flex-end",children:[jsx(TextInput,{ref:C,placeholder:"e.g '/image{{id1}}.png' or 'http://site/image.png'",label:"Enter an icon path",required:!0,defaultValue:r,description:"Add an absolute or a relative path url",onBlur:S=>n(S.currentTarget.value),sx:{flexGrow:1}}),jsx(ActionIcon,{maw:36,size:36,onClick:()=>C.current?n(C.current.value??""):void 0,sx:{flexGrow:0},children:jsx(IconFileUpload,{})})]}),t!==an.none.value&&jsxs(Fragment,{children:[jsx(Select,{label:"Variant design",description:jsxs(Fragment,{children:["We are using"," ",jsx("a",{style:{textDecoration:"underline"},href:"https://mantine.dev/core/theme-icon/",target:"_blank",rel:"noreferrer",children:"ThemeIcon variants"}),"."]}),value:u,required:!0,onChange:S=>c(S||"transparent"),data:[{value:"transparent",label:"Transparent"},{value:"default",label:"Default"},{value:"outline",label:"Outline"},{value:"light",label:"Light"},{value:"filled",label:"Filled"}]}),jsx(Input.Wrapper,{label:"Size",children:jsx(SegmentedControl,{fullWidth:!0,value:p,onChange:m,data:kE})}),jsx(Input.Wrapper,{label:"Radius",children:jsx(SegmentedControl,{fullWidth:!0,value:f,onChange:g,data:kE})}),jsx(Input.Wrapper,{label:"Padding",children:jsx(SegmentedControl,{fullWidth:!0,value:h,onChange:b,data:tj})})]})]})})]})});return {simpleIconState:R,panel:A}}ge();var ij={title:"Title",tooltip:"",slug:""};function mh({onChange:e,simpleState:t,variables:o,referenceContent:r,referenceLocale:n}){let{state:i,updateState:a}=Ul(t,ij),{simpleIconState:s,panel:l}=hp(t);return useEffect(()=>{let u={...i,...s},c=Ln(u);e(u,c);},[s,i]),jsxs(Stack,{children:[pr[k.TITLE].map(({field:u,editorConfig:c})=>jsx(sr,{field:u,value:i[u],handleEditor:a,referenceContent:r,referenceLocale:n,variables:o,editorConfig:c},u)),l]})}d();var mj=[{value:"left",label:"Left"},{value:"center",label:"Center"},{value:"right",label:"Right"}];function fh({executeButton:e,onChange:t,simpleState:o}){let[r,n]=useState(o?.label??""),[i,a]=useState(o?.removeLabel??""),[s,l]=useState(o?.showIcon??!0),[u,c]=useState(o?.position??"center");return useEffect(()=>{t({label:r,removeLabel:i,showIcon:s,position:u});},[r,s,i,u,t]),jsxs(Stack,{children:[jsx(TextInput,{placeholder:"Label for comparison button",value:r,onChange:p=>n(p.target.value),label:"Label"}),jsx(TextInput,{placeholder:"Label for remove comparison button",value:i,onChange:p=>a(p.target.value),label:"Remove Label"}),jsx(Group,{children:jsx(Switch,{checked:s,label:"Show icon",onChange:p=>l(p.currentTarget.checked)})}),jsx(Select,{label:"Button position",data:mj,value:u,onChange:c}),e]})}d();ge();function gh({simpleState:e,onChange:t,variables:o,referenceContent:r,referenceLocale:n}){let{state:i,updateState:a}=Ul(e,{title:"",value:"",subtitle:"",tooltip:""}),{simpleIconState:s,panel:l}=hp(e);return useEffect(()=>{let u={...i,...s},c=Ln(u);t(u,c);},[s,i]),jsxs(Stack,{children:[pr[k.STAT].map(({field:u,editorConfig:c})=>jsx(sr,{field:u,value:i[u],handleEditor:a,referenceContent:r,referenceLocale:n,variables:o,editorConfig:c},u)),l]})}d();he();var _j={enableBottomToolbar:!0,enableColumnActions:!0,enableColumnFilters:!0,enableColumnResizing:!0,enableDensityToggle:!0,enableFullScreenToggle:!1,enableGlobalFilter:!0,enableHiding:!0,enablePagination:!0,enableSorting:!0,enableStickyHeader:!0,enableTopToolbar:!0},OE={enableBottomToolbar:{label:"Enable bottom toolbar",desc:"Show or hide the bottom toolbar. By disabling it, pagination will also be hidden."},enableColumnActions:{label:"Enable column actions",desc:"Enables or disables column actions for all columns. Column actions include sort, filter, show/hide column and reset column size."},enableColumnFilters:{label:"Enable column filters",desc:"Enables or disables the filter options available on columns."},enableColumnResizing:{label:"Enable column resizing",desc:"Enables the column resizing feature for all columns."},enableDensityToggle:{label:"Enable density toggle",desc:"Enable the density toggle that allows users to modify the height of each row. Disabling it will hide the density toggle button in the top toolbar."},enableFullScreenToggle:{label:"Enable full screen toggle",desc:"Enable or disable the full screen toggle feature. Disabling it will hide the full screen toggle button in the top toolbar."},enableGlobalFilter:{label:"Enable global filter",desc:"Enable global filter feature to filter data on all columns and rows. Disabling it will hide the global filter button in the top toolbar."},enableHiding:{label:"Enable hiding",desc:"Enable hiding columns feature. Disabling it will hide the hiding button in the top toolbar."},enablePagination:{label:"Enable pagination",desc:"Enable pagination feature. Disabling it will hide the pagination options in the bottom toolbar."},enableSorting:{label:"Enable sorting",desc:"Enable sorting feature for all columns."},enableStickyHeader:{label:"Enable sticky header",desc:"Allows you to maintain the column headers when scrolling through the rows of the table."},enableTopToolbar:{label:"Enable top toolbar",desc:"Show or hide the top toolbar. By disabling it, globar filter, hiding, density and full screen toggles will also be hidden."}},Nj={density:"xs"},LE=["5","10","15","20","25","30","50","100"],ME={pageIndex:0,pageSize:10},BE=e=>e&&Array.isArray(e)&&e.some(t=>typeof t=="object"&&t!==null),zj=forwardRef(function({customLabels:t,customLabelsHandler:o,index:r,isActiveRefenceContent:n=!1,option:i,referenceColumns:a=[],selectedColumnsHandler:s,...l},u){let c=t.find(f=>f.key===i.label)?.label||"",m=a.find(f=>f.accessorKey===i.label)?.header||i.label;return jsxs(Group,{grow:!0,ref:u,...l,children:[jsxs(Group,{children:[jsx(IconGripVertical,{}),jsx(Checkbox,{checked:i.checked,label:i.label,onChange:f=>s.setItemProp(r,"checked",f.currentTarget.checked)})]}),jsx(Input,{disabled:!i.checked,onChange:f=>o.setItemProp(r,"label",f.currentTarget.value),value:c}),n&&jsx(Input,{disabled:!0,value:m})]},`table-group-${i.label}-${r}`)});function xh(e){let{executeButton:t,id:o,onChange:r,referenceContent:n={},referenceLocale:i,simpleState:a}=e,{columns:s}=n,l=Sa(),u=useMemo(()=>l!==i&&n&&Object.keys(n).length>0,[l,n,i]),c=je(o),[p,m]=useState([]),[f,g]=useListState([]),[h,b]=useState([]),[v,C]=useState(!1),[R,y]=useState({}),[A,S]=useState(ME),[E,L]=useState({rowsPerPageOptions:LE}),[P,D]=useListState([]),[M,z]=useState(null),[I,w]=useSetState(_j),[O,_]=useState(Nj),[H,G]=useState({}),te=useMemo(()=>P.every(V=>V.checked),[P]),j=useMemo(()=>P.some(V=>V.checked)&&!te,[te,P]);useEffect(()=>{if(!a||!Object.keys(a).length)return;let V=c[a.variable]||[],K=new Set;V.filter(U=>typeof U=="object"&&U!==null).forEach(U=>{Object.keys(U).forEach(oe=>K.add(oe));});let Z={},F=[];a.columns&&Object.keys(a.columns)&&a.columns.forEach(U=>{Z[U.accessorKey]=U.header;});let J=[],se=[];Array.from(K).forEach(U=>{se.push({key:U,label:Z[U]||U}),J.push({checked:!!Z[U],key:randomId(),label:U}),F.push(U);}),g.setState(se),D.setState(J);let{initialState:re={},state:ce={},mantinePaginationProps:fe={},...Ie}=a.tableProps||{},xe=ce.columnOrder.filter(U=>F.includes(U));xe.push(F.filter(U=>!ce.columnOrder.includes(U))),m(xe.flat()||[]),L(fe),S(re.pagination),w({...Ie}),G(ce),_(re),z(a.variable||"");},[]),useEffect(()=>{if(!c){y({});return}let V=Object.entries(c).filter(([Z,F])=>BE(F)).reduce((Z,[F,J])=>(Z[F]=J,Z),{});y(V);let K=Object.keys(V);b(K);},[c]);let W=V=>{if(z(V),!V||!BE(R[V])){C(!1),D.setState([]);return}let K=R[V];if(K.every(re=>typeof re=="object"&&re===null)){C(!1),D.setState([]);return}K.every(re=>typeof re=="object"&&re!==null)?C(!1):C(!0);let Z=new Set;K.filter(re=>typeof re=="object"&&re!==null).forEach(re=>{Object.keys(re).forEach(ce=>Z.add(ce));});let F=[],J=[],se=[];Array.from(Z).forEach(re=>{F.push({checked:!0,key:randomId(),label:re}),J.push({key:re,label:re}),se.push(re);}),D.setState(F),g.setState(J),m(se);};useEffect(()=>{let V={};f.forEach(ce=>{V[ce.key]=ce.label;});let K=P.filter(ce=>ce.checked).map(ce=>({accessorKey:ce.label,header:V[ce.label]})),Z={...O,pagination:A},F={...H,columnOrder:p},J={columns:K,data:M?`variables["${M}"]`:[],tableProps:{...I,initialState:Z,state:F,mantinePaginationProps:E},variable:M||""},se=`return ${Xa(J)};`,re={columns:K,data:M?`variables["${M}"]`:[],tableProps:{...I,initialState:Z,state:F,mantinePaginationProps:E},variable:M||""};r(re,se);},[p,f,E,A,P,M,I,H,O]);let q=useCallback(V=>{if(!V.destination||V.source.index===V.destination.index)return;let K=[...p],[Z]=K.splice(V.source.index,1);K.splice(V.destination.index,0,Z),m(K),G(F=>{let J=F;return J.columnOrder=K,J});},[p]);return jsxs(Fragment,{children:[jsxs(Stack,{mb:"sm",children:[jsx(Select,{clearable:!0,data:h,description:"Select an array of data available in the block inputs to use as data input for the table.",label:"Data input",onChange:V=>W(V),searchable:!0,value:M}),M&&R[M]&&P.length>0&&jsxs(Fragment,{children:[jsx(Input.Wrapper,{description:"Select the columns to display in the table.",error:v&&"There is a mix of types in the input data. Only object types rows will be kept.",label:"Selected columns",children:jsxs(Stack,{mt:"xs",children:[jsxs(Group,{grow:!0,children:[jsx(Text,{fz:"xs",children:"Selected"}),jsx(Text,{fz:"xs",children:"Label"}),u&&jsxs(Group,{spacing:"xs",children:[jsx(Text,{fz:"xs",children:"Reference Label"}),jsx(Badge,{variant:"light",size:"xs",rightSection:jsx(Center,{children:jsx(IconLanguage,{size:rem(12)})}),children:i.toUpperCase()})]})]}),jsx(Checkbox,{checked:te,indeterminate:j,label:"All",onChange:()=>D.setState(V=>V.map(K=>({...K,checked:!te})))}),jsx(ScrollArea.Autosize,{mah:300,children:jsx(DragDropContext,{onDragEnd:q,children:jsx(Droppable,{droppableId:"columns",children:V=>jsx("div",{ref:V.innerRef,...V.droppableProps,children:p.map((K,Z)=>{let F=P.findIndex(se=>se.label===K),J=P[F];return jsx(Draggable,{draggableId:`${J.label}`,index:Z,isDragDisabled:!J.checked,children:se=>jsx(zj,{customLabels:f,customLabelsHandler:g,index:F,isActiveRefenceContent:u,option:J,ref:se.innerRef,referenceColumns:s,selectedColumnsHandler:D,...se.draggableProps,...se.dragHandleProps})},J.label)})})})})})]})}),jsx(Accordion,{variant:"separated",children:jsxs(Accordion.Item,{value:"custom-props",children:[jsx(Accordion.Control,{children:"Custom properties"}),jsx(Accordion.Panel,{children:jsx(Stack,{children:jsxs(Input.Wrapper,{description:"Select the needed table options.",label:"Table options",children:[jsx(Group,{mt:"xs",children:Object.keys(I).map(V=>jsx(Checkbox,{checked:I[V],label:jsx(Tooltip,{label:OE[V]?.desc||V,multiline:!0,children:jsx(Text,{children:OE[V]?.label||V})}),onChange:()=>w({[V]:!I[V]})},`table-prop-${V}`))}),I?.enablePagination&&jsxs(Fragment,{children:[jsx(Divider,{mt:"xs"}),jsxs(Input.Wrapper,{description:"Customize initial pagination properties.",label:"Pagination props",mt:"xs",children:[jsxs(Group,{grow:!0,children:[jsx(NumberInput,{label:"Initial page",min:0,onChange:V=>{S(K=>({...K,pageIndex:V}));},value:A.pageIndex}),jsx(Select,{data:E.rowsPerPageOptions||[],getCreateLabel:V=>`+ Create ${V}`,label:"Initial page size",onChange:V=>{S(K=>({...K,pageSize:parseInt(V,10)}));},searchable:!0,value:A.pageSize.toString()})]}),jsxs(Group,{align:"flex-end",grow:!0,children:[jsx(MultiSelect,{clearable:!0,creatable:!0,data:E.rowsPerPageOptions||[],getCreateLabel:V=>`+ Create ${V}`,label:"Page size options",onChange:V=>{L(K=>({...K,rowsPerPageOptions:V.sort((Z,F)=>parseInt(Z,10)-parseInt(F,10))})),V&&V.length>0&&!V.includes(A.pageSize.toString())&&S(K=>({...K,pageSize:parseInt(V[0],10)}));},onCreate:V=>(L(K=>({...K,rowsPerPageOptions:[...K.rowsPerPageOptions||[],V].sort((Z,F)=>parseInt(Z,10)-parseInt(F,10))})),V),searchable:!0,value:E.rowsPerPageOptions||[]}),jsx(Button,{color:"yellow",onClick:()=>{L(V=>({...V,rowsPerPageOptions:LE})),S(ME);},children:"Reset page sizes values"})]})]})]})]})})})]})})]})]}),t]})}d();he();ge();d();var DE=e=>{let{dataVar:t,levelsVar:o}=e;return !![t,o].every(Boolean)},Sp=e=>{let t,o,{colorKey:r,dataVar:n,iconKey:i,defaultVar:a,isPrimitiveType:s,levelsVar:l,searchIndexKey:u}=e;a&&typeof a=="string"&&(t=`variables["${a}"].value`,o=`variables["${a}"].type`);let c=s?`variables["${n}"]`:`(variables["${n}"] || []).map((d) => ({...d, colorKey: String(d["${r}"]), iconKey: String(d["${i}"]), searchIndexKey: String(d["${u}"])}))`;return {logicLevels:`variables["${l}"]`,logicOptions:c,defaultValue:t,defaultValueType:o}};Ks();var Ch=e=>pr[k.MULTIHIERARCHY_SELECTOR].find(t=>t.field===e)?.editorConfig,$j=e=>e&&Array.isArray(e)&&e.some(t=>typeof t=="object"&&t!==null),Uj=e=>e&&e.type&&e.value,us=e=>e&&Array.isArray(e)&&e.length;function io(e,t,o){return e&&e[t]||o}function kh(e){let{executeButton:t,id:o,onChange:r,referenceContent:n,referenceLocale:i,simpleState:a}=e,s=je(o),[l,u]=useState(!1),[c,p]=useState(()=>({allLabel:io(a,"allLabel","All"),colorKey:io(a,"colorKey",""),dataVar:io(a,"dataVar",""),defaultVar:io(a,"defaultVar",""),hideLabel:io(a,"hideLabel","false"),resetSectionVars:io(a,"resetSectionVars","false"),iconKey:io(a,"iconKey",""),isPrimitiveType:io(a,"isPrimiteType",!1),levelsVar:io(a,"levelsVar",""),limit:io(a,"limit",0),placeholder:io(a,"placeholder",""),searchIndexKey:io(a,"searchIndexKey",""),searchIndexSeparator:io(a,"searchIndexSeparator","|"),selectorIdentifier:io(a,"label","")})),[m,f]=useState([]),[g,h]=useState([]),[b,v]=useState({}),[C,R]=useState({}),[y,A]=useState([]),S=useCallback((I,w,O=!1)=>p(_=>({..._,[I]:!w&&O?"":w})),[]);useEffect(()=>{if(!s){f([]),h([]),v({}),R({});return}let I=Object.entries(s).filter(([H,G])=>$j(G)).reduce((H,[G,te])=>(H[G]=te,H),{}),w=Object.entries(s).filter(([H,G])=>Uj(G)).reduce((H,[G,te])=>(H[G]=te,H),{});R(I),v(w);let O=Object.keys(I),_=Object.keys(w);f(O),h(_),u(!0);},[s]),useEffect(()=>{if(!Object.keys(C).length)return;let I=lp(C[c.dataVar]);if(I)A([]),S("colorKey",""),S("iconKey",""),S("searchIndexKey","");else {let w=new Set;(C[c.dataVar]||[]).forEach(_=>Object.keys(typeof _=="object"?_:{}).forEach(H=>w.add(H)));let O=Array.from(w).sort().map(_=>_);A(O);}S("isPrimitiveType",I);},[C,c.dataVar]),useEffect(()=>{let{allLabel:I,colorKey:w,dataVar:O,defaultVar:_,hideLabel:H,resetSectionVars:G,iconKey:te,levelsVar:j,limit:W,placeholder:q,searchIndexKey:V,searchIndexSeparator:K,selectorIdentifier:Z}=c,F={allLabel:I,colorKey:w,dataVar:O,defaultVar:_,label:Z,hideLabel:H,resetSectionVars:G,iconKey:te,levelsVar:j,limit:W,placeholder:q,searchIndexKey:V,searchIndexSeparator:K},{logicOptions:J,logicLevels:se,defaultValue:re,defaultValueType:ce}=Sp(F);re&&ce&&(F.defaultValue=re,F.defaultValueType=ce),F.data=J,F.levels=se;let fe=`return ${Xa(F)};`,Ie=F,xe=DE(Ie);r(Ie,fe,xe);},[c]);let E=useCallback(I=>{S("dataVar",I),S("defaultVar",{}),S("colorKey",""),S("iconKey",""),S("searchIndexKey","");},[S]);if(!l)return null;let L=Object.keys(C),P=Object.keys(b),D=Ch(ke.MULTIHIERARCHY_SELECTOR_ALL_LABEL),M=Ch(ke.MULTIHIERARCHY_SELECTOR_NAME),z=Ch(ke.MULTIHIERARCHY_SELECTOR_PLACEHOLDER);return jsxs(Fragment,{children:[jsxs(Stack,{mb:"sm",spacing:"xs",children:[jsx(sr,{field:"label",value:c.selectorIdentifier,handleEditor:(I,w)=>{S("selectorIdentifier",w);},referenceContent:n,referenceLocale:i,variables:s,editorConfig:M}),jsx(Checkbox,{label:jsx(It,{label:"Hide Label",py:0}),checked:c.hideLabel==="true",onChange:I=>S("hideLabel",I.currentTarget.checked?"true":"false")}),jsx(Select,{data:m,description:"(Required) Select an array of data available in the block inputs to use as data input.",label:jsx(It,{label:"Data Input"}),onChange:I=>E(I),value:us(L)&&c.dataVar}),jsx(Select,{data:m,description:"(Required) Select an array of {label, value} items in the block inputs to use as levels.",label:jsx(It,{label:"Levels Input"}),onChange:I=>S("levelsVar",I),value:us(L)&&c.levelsVar}),jsx(Select,{clearable:!0,data:g,description:"(Optional) Select an object with {type, value} keys in the block inputs to use as default value.",label:jsx(It,{label:"Default Value"}),onChange:I=>{if(!I){S("defaultVar","");return}S("defaultVar",I);},value:us(P)&&c.defaultVar}),jsx(NumberInput,{description:"(Optional) Sets a limit for selected values. Set 0 for no limit.",label:jsx(It,{label:"Limit"}),min:0,onChange:I=>S("limit",I),value:c.limit}),jsx(Accordion,{mt:"md",variant:"separated",children:jsxs(Accordion.Item,{value:"customization",children:[jsx(Accordion.Control,{children:"Customization"}),jsx(Accordion.Panel,{children:jsxs(Stack,{spacing:"xs",children:[jsx(sr,{field:"allLabel",value:c.allLabel,handleEditor:(I,w)=>S("allLabel",Ft(w)),referenceContent:n,referenceLocale:i,variables:s,editorConfig:D}),jsx(sr,{field:"placeholder",value:c.placeholder,handleEditor:(I,w)=>S("placeholder",Ft(w)),referenceContent:n,referenceLocale:i,variables:s,editorConfig:z}),jsx(Select,{clearable:!0,data:y,description:"(Optional) Select a property key to use as item's icon background color. Requires defining an icon key.",disabled:c.isPrimitiveType,label:jsx(It,{label:"Color property key"}),onChange:I=>S("colorKey",I,!0),value:us(y)&&c.colorKey}),jsx(Select,{clearable:!0,data:y,description:"(Optional) Select a property key to use as item's icon src.",disabled:c.isPrimitiveType,label:jsx(It,{label:"Icon property key"}),onChange:I=>S("iconKey",I,!0),value:us(y)&&c.iconKey}),jsx(Select,{clearable:!0,data:y,description:"(Optional) Select a property key to extend the search functionality. The selected key MUST only contain text elements.",disabled:c.isPrimitiveType,label:jsx(It,{label:"Search index key"}),onChange:I=>S("searchIndexKey",I,!0),value:us(y)&&c.searchIndexKey}),jsx(TextInput,{description:'(Optional) Provide a search index separator in case each row contains more than one record. Default: "|".',disabled:!c.searchIndexKey,error:c.searchIndexSeparator===""?"Separator cannot be empty!":"",label:jsx(It,{label:"Search index separator"}),onChange:I=>S("searchIndexSeparator",I.currentTarget.value),value:c.searchIndexSeparator})]})})]})})]}),jsx(Checkbox,{my:"md",label:jsx(It,{label:"Reset SectionVariables on change",py:0}),checked:c.resetSectionVars==="true",onChange:I=>S("resetSectionVars",I.currentTarget.checked?"true":"false")}),t]})}var Hj={[k.SELECTOR]:vE,[k.NAV]:lh,[k.RELATED]:ch,[k.RESET_BUTTON]:ph,[k.COMPARISON_BUTTON]:fh,[k.TITLE]:mh,[k.STAT]:gh,[k.TABLE]:xh,[k.MULTIHIERARCHY_SELECTOR]:kh},VE=Hj;function jj(e){let{blockType:t,id:o,locale:r,setBlockContent:n,simpleState:i}=e,a=Lr(),s=je(o),l=VE[t],u=jsx(fE,{fields:pr[t],locale:r,defaultContent:i,variables:s,onChange:n},"text-editor");return l?jsx(l,{id:o,executeButton:a.executeButton,onChange:(c,p,m=!0)=>n({simple:c,logic:p},r,!0,m),simpleState:i,richTextEditor:u,variables:s,referenceContent:a.reference.content,referenceLocale:a.reference.locale}):u}var $E=jj;d();Ba();ge();ie();he();Lt();gm();function tW({id:e,variables:t,reserved:o,hasInternalKeys:r}){let[n,i]=useState(!1);return jsxs(Fragment,{children:[r&&jsx(Switch,{label:"Show internal variables",size:"xs",checked:n,onChange:a=>i(a.currentTarget.checked)}),jsx(tr,{id:e,variables:t,reserved:o,showInternal:n})]})}function oW({id:e,setInlineId:t}){let o=$(l=>l.records.entities.block),r=ne(),n=av(e),i=Object.keys(n.attributes),a=useContext(_e),s=l=>{r(Q.updateEntity("block",{id:e,inputAction:{operation:"delete",input:{input_id:l,block_id:e}}})).then(()=>{r(Q.recalculateVariables(a));});};return jsx("div",{style:{display:"flex",flex:"1 1 auto",flexDirection:"column",width:"100%"},children:Object.keys(n).sort(l=>l==="attributes"?-1:1).map(l=>{let u=o[l],c=u&&[k.GENERATOR,k.SECTION_FLAG].includes(u.type),p=u?.type&&u?.id?`${u.type}${u.id}`:"",m=Object.keys(n[l]).some(Yc(p));return jsxs(Stack,{className:"cr-variable-group",style:{position:"relative"},children:[jsx(Divider,{}),jsxs(Group,{position:"apart",noWrap:!0,grow:!0,children:[jsx(Title,{order:6,children:u?`${titleCase(u.type)} ${u.id} Variables`:"Dimension Variables"}),u&&jsxs(Group,{position:"right",noWrap:!0,children:[c&&jsx(Tooltip,{label:"Edit this generator",children:jsx(ActionIcon,{size:"xs",onClick:()=>t(l),variant:"subtle",color:"gray",children:jsx(IconPencil,{size:15})})}),jsx(Tooltip,{label:"Remove as input",children:jsx(ActionIcon,{size:"xs",onClick:()=>s(l),variant:"light",color:"red",children:jsx(IconLinkOff,{size:15})})})]})]}),jsx(tW,{id:l,variables:n[l],reserved:i,hasInternalKeys:m})]},l)})})}var jE=oW;nl();fr();he();function bW({blockType:e,fullscreen:t,toggle:o,codeEditor:r}){let n=Lr(),i=[k.GENERATOR,k.VIZ].includes(e);return jsxs(Fragment,{children:[jsxs(Alert,{p:"xs",mb:"xs",icon:jsx(IconInfoCircle,{}),color:"gray",children:["You can access ",jsx(Code,{children:"variables"}),", ",jsx(Code,{children:"formatters"}),",",jsx(Code,{children:"locale"}),", ",jsx(Code,{children:"libs"}),",",e===k.GENERATOR&&jsxs(Fragment,{children:[jsx(Code,{children:"resp"}),", "]}),e===k.VIZ&&jsxs(Fragment,{children:[jsx(Code,{children:"section"}),", "]}),"and ",jsx(Code,{children:"router"})," in the scope of this generator.",i&&jsxs(Fragment,{children:[" Return a property called",jsx(Code,{children:"_api"})," as string, to let the user download that data and override api value."]})]}),r,jsx(Divider,{my:"sm",color:"gray.8"}),jsxs(Group,{px:"xs",h:"fit-content",position:"right",children:[jsx(Button,{variant:"light",color:"grey",size:"xs",onClick:o,leftIcon:t?jsx(IconMinimize,{size:rem(12)}):jsx(IconMaximize,{size:rem(12)}),compact:!0,children:t?"Minimize":"Maximize"}),n.executeButton]})]})}function yW(){let e=Lr(),t=Sa(),o=xa(),r=t!==o;return jsx(Group,{position:"right",my:"xs",children:jsxs(Stack,{align:"flex-end",spacing:"xs",children:[jsx(Switch,{label:e.mode==="simple"?"Code":"No Code",size:"xs",labelPosition:"left",checked:e.mode==="code",onChange:n=>e.changeEditorMode(n.currentTarget.checked?"code":"simple"),onLabel:jsx(IconCode,{size:rem(12)}),offLabel:jsx(IconCode,{size:rem(12)})}),e.mode!=="code"&&r&&jsx(Switch,{checked:e.reference.active,onChange:n=>e.reference.setActive(n.currentTarget.checked),size:"xs",label:"See reference language",labelPosition:"left",onLabel:jsx(IconLanguage,{size:"0.7rem"}),offLabel:jsx(IconLanguage,{size:"0.7rem"})})]})})}function vW({header:e,blockContent:t,blockSettings:o,blockType:r,id:n,locale:i,onSave:a,setBlockContent:s,setBlockSettings:l,setInlineId:u,sid:c}){let[p,m]=useState("Content"),f=Dc(n),g=Lr(),h=useMemo(()=>{let w=null;return f&&f.resp&&(w=f.resp),w},[f]),b=je(n),{ref:v,toggle:C,fullscreen:R}=useFullscreen(),y=t&&(t.api||t.api==="")?t.api.split(Ur):[],A=(w,O)=>s({logic:w},O),S=(w,O)=>{let _=[...y];_[O]=w,s({api:_.join(Ur)});},E=()=>{s({api:[...y,""].join(Ur)});},L=w=>{s({api:y.length===1&&y[0]===""?null:y.filter((O,_)=>_!==w).join(Ur)});},P=(w,O)=>{l({[w]:O});},D=jsx(ru,{monacoOptions:{onChange:w=>A(w,i),value:t?.logic||"",height:R?"85vh":"61vh",width:"100%"},variables:b},"code-editor"),M=t?.simple||{},z=jsx($E,{blockType:r,id:n,locale:i,simpleState:M,setBlockContent:s,variables:b}),I=jsx(Col,{span:4,sx:w=>({display:"flex",flexDirection:"column",borderLeft:`2px solid ${w.colors.gray[0]}`}),children:jsxs(Stack,{children:[jsx(Text,{inline:!0,size:"xs",transform:"uppercase",weight:"bold",color:"gray",children:"Preview"}),jsx(_u,{id:n,active:!0,blockStateContent:t,blockStateSettings:o,locale:i,allowed:!0,debug:!0},"block-preview")]})});return jsxs(Grid,{h:"100%",children:[jsxs(Col,{span:3,sx:{alignSelf:"stretch",display:"flex",flexDirection:"column",height:"100%",position:"relative"},children:[k.SECTION_FLAG!==r&&jsx(qC,{id:n}),jsx("div",{style:{width:"100%",maxHeight:"80vh",overflowY:"auto"},children:jsx(jE,{id:n,setInlineId:u})}),[k.GENERATOR,k.SECTION_FLAG].includes(r)&&jsxs("div",{children:[jsx(Divider,{label:`${y.length} API's`,labelPosition:"center",mt:"md"}),y.map((w,O)=>jsx(MS,{defaultValue:w,id:n,onChange:_=>S(_,O),onEnterPress:()=>a(!0),onDelete:()=>L(O)},`${n}-${O}-${y.length}`)),jsx(Button,{size:"xs",compact:!0,onClick:E,variant:"light",color:"blue",fullWidth:!0,leftIcon:jsx(IconPlus,{size:15}),my:5,children:"Add API"}),h&&jsxs(Fragment,{children:[jsx(Divider,{label:"Response data preview (resp)",labelPosition:"center",my:"sm"}),jsx("div",{style:{maxHeight:200,overflowY:"scroll"},children:jsx(qc,{value:h,root:!0,label:"resp"})})]})]})]}),jsxs(Col,{span:9,sx:w=>({alignSelf:"stretch",display:"flex",flexDirection:"column",height:"100%",borderLeft:`2px solid ${w.colors.gray[0]}`}),children:[e,jsxs(Tabs,{value:p,onTabChange:m,keepMounted:!1,styles:{root:{flexGrow:1,display:"flex",flexDirection:"column"},panel:{flexGrow:1}},children:[jsxs(Tabs.List,{position:"left",children:[jsx(Tabs.Tab,{value:"Content",icon:jsx(IconPencil,{}),children:"Edit"}),jsx(Tabs.Tab,{value:"Style",icon:jsx(IconPalette,{}),children:"Style"}),jsx(Tabs.Tab,{value:"Settings",icon:jsx(IconSettings,{}),children:"Settings"})]}),jsx(Tabs.Panel,{value:"Content",children:jsx(Box,{ref:v,pos:"relative",bg:"white",h:"100%",children:jsxs(Grid,{className:"cr-block-output",style:{flex:1,width:"100%",height:R?"100vh":"100%",margin:0},children:[jsxs(Col,{span:8,className:`cr-block-output-editor ${g.mode}`,children:[![k.VIZ,k.GENERATOR,k.SECTION_FLAG].includes(r)&&jsx(yW,{}),jsxs(Box,{bg:g.mode==="code"?"#272822":"none",p:"xs",children:[g.mode==="code"&&jsx(bW,{blockType:r,fullscreen:R,toggle:C,codeEditor:D}),g.mode!=="code"&&z]})]},"content-col"),I]})})}),jsx(Tabs.Panel,{value:"Style",pt:"xs",children:jsx(Box,{ref:v,pos:"relative",bg:"white",h:"100%",children:jsxs(Grid,{children:[jsxs(Col,{span:8,children:[jsx(Title,{order:4,children:"Style settings"}),jsx(ou,{id:n,display:"inline",handleChange:P})]},"content-col"),I]})})}),jsx(Tabs.Panel,{value:"Settings",pt:"xs",children:jsx(KC,{id:n,setBlockSettings:l,setBlockContent:s})})]})]})]})}var QE=vW;ko();hr();ge();Lt();d();var ZE=e=>(!e||!e.contentByLocale||Object.keys(e.contentByLocale).forEach(t=>{let o=e.contentByLocale[t]?.content;o&&Object.keys(o).length===0&&(o.simpleEnabled=!0,o.simple={});}),e);var eR=["_icon","_iconType","_iconVariant","_iconSize","_iconRadius","_iconPadding"],tR={[k.SELECTOR]:["hideLabel","resetSectionVars","component","optionsType","type"],[k.TITLE]:[...eR],[k.STAT]:[...eR],[k.TABLE]:["data","tableProps","variable"],[k.MULTIHIERARCHY_SELECTOR]:["colorKey","dataVar","defaultVar","hideLabel","resetSectionVars","iconKey","levelsVar","limit","searchIndexKey","searchIndexSeparator"]},PW=(e,t)=>({...e,[t.locale]:{...t,content:t.content}});function OW({block:e,inline:t,localeDerived:o}){let r=Lr(),n=er(e.section_id).data,i=Vt(n.report_id).data,a=n?.settings.name||`Section ${n?.id}`,s=`${e.type} ${e.id}`,l=i?.name||`Report ${i.id}`;return jsxs(Group,{w:"100%",children:[jsx(Alert,{color:"gray",sx:{flexGrow:1},py:"0.325rem",children:jsxs(Group,{position:"apart",children:[jsxs(Breadcrumbs,{separator:">",children:[jsx(Text,{size:"xs",children:l}),jsx(Text,{size:"xs",children:a}),jsx(Text,{size:"xs",children:s})]}),jsx(Badge,{size:"sm",radius:"sm",rightSection:jsx(Center,{children:o==="logic"?jsx(IconCode,{size:"0.6rem"}):jsx(IconLanguage,{size:"0.6rem"})}),children:o})]})}),jsxs(Group,{children:[r.cancelButton,r.closeAndSaveButton]})]})}function LW({id:e,modified:t,callbacks:o,inline:r}){let n=ne(),i=useContext(_e),{setOpened:a,setModified:s,maybeCloseWithoutSaving:l,setInlineId:u}=o,c=He(e).data,p=$(O=>O.status.currentLocale),m=$(O=>O.status.localeDefault),f=$(O=>O.status.locales),g=Yo(c,p).locale,[h,b]=useState(),[v,C]=useState(!1),[R,y]=useState(!0);if(useEffect(()=>{b(ZE($u(c))),C(!0);},[]),!c||!v||!h)return null;let A=so(h,p),S=h.settings,E=(O={},_=m,H=!0,G=void 0)=>{let{locale:te}=Yo(c,_);if(H&&!t&&s(!0),G!==void 0&&R!==G&&y(G),!O||Object.keys(O).length<1)return;let j=h.contentByLocale[te]||{id:e,locale:te,content:{}};b({...h,contentByLocale:{...h.contentByLocale,[te]:{...j,content:{...j.content,...O}}}});},L=(O,_)=>{if(g!=="logic"&&Object.keys(tR).includes(c.type)){let H={...O},G=O[_].content;return f.forEach(te=>{if(te===g)return;let W={...O[te].content.simple};Object.keys(G.simple).map(V=>{tR[c.type].includes(V)&&(W[V]=G.simple[V]);});let q={...W};if(c.type===k.SELECTOR){let{selectorType:V=Wi.SINGLE,options:K={static:[]},optionsType:Z=_n.STATIC}=O[te].content.simple,{logicOptions:F,defaultValue:J}=cp(V,K,Z);J&&(q.defaultValue=J),q.options=F;}if(c.type===k.MULTIHIERARCHY_SELECTOR){let V=O[te].content.simple,{logicLevels:K,logicOptions:Z,defaultValue:F,defaultValueType:J}=Sp(V);F&&J&&(q.defaultValue=F,q.defaultValueType=J),q.data=Z,q.levels=K;}H[te].content={...H[te].content,simple:W,logic:Ln(q)};}),H}return O},P=()=>{let{settings:O}=h,_=Object.values(h.contentByLocale).reduce(PW,{}),H=["id","api","shared","type"].reduce((te,j)=>({...te,[j]:h[j]}),{}),G=L(_,p);return {...H,id:h.id,contentByLocale:G,settings:O}},D=async O=>{let _=P();n(Q.updateEntity("block",_)).then(()=>{n(uo(i)),s(!1),O||(r?u(null):a(!1));});},M=O=>{t||s(!0),O.type||O.shared!==void 0?b({...h,...O}):b({...h,settings:{...h.settings,...O}});};return jsx(Fragment,{children:jsx(uE,{buttons:{cancelButton:jsx(Button,{leftIcon:jsx(IconCircleX,{size:"0.8rem"}),size:"xs",variant:"outline",onClick:l,color:"red",children:"Cancel"},"cancel"),closeAndSaveButton:jsx(Button,{leftIcon:jsx(IconDeviceFloppy,{size:"0.8rem"}),size:"xs",disabled:!R,onClick:()=>D(!1),children:`Save & ${r?"Return":"Close"}`},"save"),executeButton:jsx(Button,{disabled:!R,onClick:()=>D(!0),size:"xs",compact:!0,children:"Save & Execute"})},blockType:c.type,blockId:c.id,children:jsx(QE,{header:jsx(OW,{inline:r,localeDerived:g,block:c}),blockContent:A,blockSettings:S,blockType:c.type,id:e,sid:c.section_id,locale:p,onSave:D,setBlockContent:E,setBlockSettings:M,setInlineId:u},"be")})})}var oR=LW;Lt();ie();he();hr();Pu();ge();Ko();function KW({id:e,setHoverBlock:t,isInput:o,isConsumer:r,active:n,showOutline:i=!0}){let[a,s]=useState(!1),{newConfirmation:l}=Pt(),[u,c]=useState(!1),[p,m]=useState(!1),[f,g]=useState(null),h=useContext(_e),b=useMantineTheme(),v=je(e),C=Dc(e),R=useCallback(()=>{c(!1),m(!1),g(null);},[]),y=useDispatch(),A=$(q=>q.status.currentLocale),{data:S}=He(e),E=$(q=>q.records.entities.block),{isFetching:L}=Us("block",e),{allowed:P,allowedMessage:D}=useMemo(()=>{let q=!C?.hiddenByCascade,V="";return S&&(V=C?.hiddenByCascade===e?`Hidden by ${S.settings.allowed}: ${S.settings.allowed?v[S.settings.allowed]:null}`:`Hidden by ${C?.hiddenByCascade}`),{allowed:q,allowedMessage:V}},[v,C,S,e]);if(!S)return null;let{blockcol:M,type:z,section_id:I,contentByLocale:w,settings:O,inputs:_}=S,H=async()=>{if(p)try{await l({title:"Are you sure?",message:"Close editor without saving?",confirmText:"Yes, abandon changes."}),R();}catch{}else R();},G={centered:!0,withCloseButton:!1,opened:u,onClose:H,overflow:"inside",padding:b.spacing.sm,size:"95%",styles:{body:{height:"100%"}}},te={onMouseEnter:()=>t(e),onMouseLeave:()=>t(!1)},j={setOpened:c,setModified:m,setInlineId:g,maybeCloseWithoutSaving:H},W=()=>{let q=Object.keys(E).filter(Z=>E[Z].section_id===S.section_id&&E[Z].blockcol===S.blockcol).map(Z=>E[Z].blockrow),V=ea(q),K={create:{blockrow:Rs(V),blockcol:M,locales:Object.keys(w).map(Z=>Z),section_id:I,type:z},update:{contentByLocale:w,settings:O,inputs:_.map(Z=>E[Z])}};y(Q.cloneEntity("block",K)).then(()=>{[k.GENERATOR,k.SECTION_FLAG].includes(S.type)&&y(uo(h,{sid:I}));});};return jsxs(Fragment,{children:[jsxs(Group,{id:`block-${e}`,onMouseOver:()=>s(!0),onMouseOut:()=>s(!1),className:"cr-section-block",pos:"relative",py:On.block.padding,...te,sx:q=>({border:"1px solid transparent",resize:"horizontal","&:hover":{border:i?`1px solid ${q.colors.blue[2]}`:"1px solid transparent"},...i?{"&:hover::before":{position:"absolute",top:0,left:0,fontSize:8,color:q.colors.blue[5],transform:"translateY(-100%)",content:`"Block ${e}"`,width:"fit-content"}}:{}}),children:[jsx(_u,{style:{color:"red"},id:e,debug:[k.VIZ,k.GENERATOR,k.SECTION_FLAG].includes(S.type),active:n,locale:A,allowed:P,isFetching:L},"bp"),(a||o||r)&&jsxs(Group,{spacing:0,className:"cr-block-controls export-hidden",style:{position:"absolute",right:px(b.spacing.xs)/2,top:px(b.spacing.xs)/2,backgroundColor:b.colors.gray[2],borderRadius:b.radius.sm,zIndex:5},children:[o||r?jsx(ActionIcon,{children:o?jsx(IconLogout,{size:20,color:b.colors.red[5]}):jsx(IconLogin,{size:20,color:b.colors.green[5]})},"globe"):null,S.shared&&jsx(Tooltip,{withArrow:!0,label:"Sharing: Enabled",children:jsx(ActionIcon,{variant:"transparent",children:jsx(IconWorld,{size:20})},"globe")},"tt"),"access"in S.settings&&!["public","guest"].some(q=>!S.settings.access||S.settings.access.includes(q))&&jsx(Tooltip,{withArrow:!0,label:"Private Block",children:jsx(ActionIcon,{variant:"transparent",children:jsx(IconLock,{size:20})},"lock")},"tt"),!P&&jsx(Tooltip,{withArrow:!0,label:D,children:jsx(ActionIcon,{variant:"transparent",children:jsx(IconEyeOff,{size:20})})},"allowed"),![k.GENERATOR,k.SECTION_FLAG].includes(S.type)&&jsx(ou,{id:e,display:"button"},"design"),jsx(ActionIcon,{onClick:()=>c(!0),children:jsx(IconPencil,{size:20})},"edit"),![k.SECTION_FLAG].includes(S.type)&&jsx(ActionIcon,{onClick:W,children:jsx(IconCopy,{size:20})},"copy"),jsx(vS,{type:Fr.BLOCK,id:e},"cog")]},"bc")]},"block"),jsx(Modal,{fullScreen:!0,...G,children:jsx(oR,{callbacks:j,id:f||e,inline:f,modified:p},f||e)},"d")]})}var ds=KW;Ko();Pu();ie();ko();d();d();he();ie();var aR=({id:e,disabled:t=!1})=>{let{sectionVariables:o,resetSectionVariables:r}=Ze(e);return !Object.keys(o).length?null:jsx(ActionIcon,{disabled:t,onClick:r,variant:"filled",size:"xs",children:jsx(IconRefresh,{size:20})})},e2=({sectionId:e,onActivate:t})=>{let{activeEntity:o}=Ot(),{handlers:r}=to("settings");return o.type==="section"&&o.id===e?jsx(Button,{size:"xs",radius:"xl",leftIcon:jsx(IconPencil,{size:14}),fw:400,onClick:r.open,compact:!0,children:"Edit"}):jsx(ActionIcon,{variant:"transparent",onClick:()=>{t(),r.open();},children:jsx(IconPencil,{size:18})})};function t2({sectionId:e,onActivate:t}){let o=useDispatch(),r=er(e),{data:n}=r,i=$(a=>a.records.entities.block);return n?jsxs(Group,{spacing:2,children:[jsx(e2,{sectionId:e,onActivate:t}),jsx(ActionIcon,{variant:"transparent",onClick:()=>{let a=o2(n,i);o(Q.cloneEntity("section",a));},children:jsx(IconCopy,{size:18})}),jsx(yr,{type:"section",id:e})]}):null}function o2(e,t){let{heading:o,report_id:r,ordering:n,settings:i}=e,a=[];return {create:{ordering:n,report_id:r},update:{settings:i,heading:o,report_id:r,blocks:e?.blocks.map(l=>{let u=t[l],{blockcol:c,blockrow:p,contentByLocale:m,type:f,settings:g,section_id:h,shared:b,inputs:v,consumers:C}=u;return {blockcol:c,blockrow:p,contentByLocale:m,id:l,type:f,settings:g,section_id:h,shared:b,inputs:v.map(R=>{let y=t[R],{id:A,section_id:S,blockcol:E,blockrow:L,contentByLocale:P,settings:D,shared:M,type:z}=y;return {id:A,section_id:S,blockcol:E,blockrow:L,contentByLocale:P,settings:D,shared:M,type:z}}),consumers:C.reduce((R,y)=>{let A=t[y];if(A){let{id:S,section_id:E,blockcol:L,blockrow:P,contentByLocale:D,settings:M,shared:z,type:I}=A;return [...R,{id:S,section_id:E,blockcol:L,blockrow:P,contentByLocale:D,settings:M,shared:z,type:I}]}return R},a)}})}}}var sR=t2;ie();ge();ko();Rf();function lR({active:e,isDragging:t,id:o,dragHandleProps:r,hidden:n="",onActivate:i,sectionSettings:a}){let s=$(c=>c.records.entities.section[o]||null);if(!s)return null;let l=s&&s.settings?.name?.length?s.settings.name:`section-${s.id}`,u=n!=="";return jsxs(Group,{className:`cms-section-header${e||t?" active":""}`,position:"apart",bg:u?"red.1":"gray.3",sx:{overflow:"hidden",borderRadius:4},children:[jsx(Group,{className:"cms-section-header-editor",spacing:0,children:jsxs(Group,{spacing:0,children:[jsx(ActionIcon,{variant:"transparent",...r,w:16,sx:{cursor:"grab"},children:jsx(IconGripHorizontal,{size:16})},"b1"),jsxs(Text,{size:"xs",fw:400,color:"dark.9",children:[l,u&&` ${n}`]})]})}),jsxs(Group,{children:[jsxs(Flex,{justify:"flex-end",mx:16,align:"center",gap:"xs",children:[jsx(aR,{id:s.id,disabled:!e}),a.optionsMenu&&jsx(Ef,{sectionId:s.id,disabled:!e})]}),jsx(sR,{sectionId:o,onActivate:i})]})]})}hf();ge();nl();Pf();bl();he();Pi();ua();fr();var x2=Object.values(k),fR=({columns:e,columnIndex:t,section:o})=>{let r=ne(),{settings:n}=Au(o.report_id),[i,a]=useDisclosure(!1),s=(u,c=!1)=>{let p=Yn,m=Yn;typeof c=="string"?(m=c,p=ea(Object.keys(e[c]),!0)):Object.keys(e).length>0&&(m=ea(Object.keys(e),!0));let{locales:f}=Yo({type:u});r(Q.createEntity("block",{blockrow:p,blockcol:m,type:u,section_id:o.id,locales:f}));},l=x2.filter(u=>![k.GENERATOR,k.SECTION_FLAG].includes(u)&&(n.comparison?!0:u!==k.COMPARISON_BUTTON)).map(u=>{let c=rg(u);return {label:jsx(UnstyledButton,{p:"xs",w:"100%",onClick:()=>{s(u,t),a.close();},sx:{":hover":{backgroundColor:"#EBEBEB"}},children:jsxs(Group,{spacing:"xs",children:[jsx(ThemeIcon,{color:"blue",variant:"filled",size:"sm",radius:"xl",children:jsx(c,{size:"0.8rem"})}),jsx(Text,{size:"xs",children:ag(u)||u})]})}),value:u}});return jsx(Center,{w:"100%",py:"sm",children:jsxs(Popover,{position:"right",withinPortal:!0,zIndex:100,opened:i,onClose:a.close,children:[jsx(Popover.Target,{children:jsx(ActionIcon,{size:"lg",radius:"xl",variant:"light",bg:"#E5E5E5 !important",onClick:a.toggle,children:jsx(IconPlus,{size:24,color:"white",strokeWidth:1})})}),jsxs(Popover.Dropdown,{p:0,children:[jsx(Text,{bg:"#E5E5E5",size:"xs",p:"xs",children:"Add Block"}),jsx(ScrollArea,{h:230,children:jsx(List,{listStyleType:"none",styles:{itemWrapper:{width:"100%"}},children:l.map(({label:u,value:c})=>jsx(List.Item,{w:"100%",children:u},c))})})]})]})})},T2=({columns:e,section:t,show:o=!1})=>o?jsx(Center,{w:"100%",children:jsxs("div",{children:[jsx(Text,{ta:"center",fw:700,size:"sm",color:"gray.8",children:"Add your first block!"}),jsx(fR,{columnIndex:!1,columns:e,section:t})]})}):null,C2=({active:e=!1})=>jsx(Droppable,{droppableId:"newColumn",children:(t,o)=>jsx(Center,{ref:t.innerRef,pos:"absolute",top:16,right:e?0:-140,bottom:16,w:140,sx:r=>({boxSizing:"border-box",zIndex:99,transition:"right 0.4s",overflow:"hidden",background:o.isDraggingOver?r.colors[r.primaryColor][0]:r.colors.gray[0]}),...t.droppableProps,children:jsxs(Stack,{p:"md",align:"center",children:[jsx(Text,{size:"xs",ta:"center",children:"Drop here to add new column"}),jsx(IconPlus,{})]})})}),k2=({onActivate:e,section:t,show:o=!1})=>o?jsx(Overlay,{className:"cms-section-overlay",onClick:()=>e(t.id),opacity:.6,color:"#E9ECEF",style:{cursor:"pointer",zIndex:3},sx:r=>({transition:"background-color .45s",".bespoke-Section-edit":{opacity:0,transition:"opacity .45s"},"&:hover":{backgroundColor:r.fn.rgba("#E9ECEF",.9),".bespoke-Section-edit":{opacity:1}}}),center:!0,children:jsxs(Group,{className:"bespoke-Section-edit",align:"center",spacing:"xs",children:[jsx(Text,{fw:700,children:"Click to Edit"}),jsx(IconPencil,{size:"1rem"})]})}):null;function E2({for:e,isDragging:t,onActivate:o,dragHandleProps:r}){let n=ne(),{activeEntity:i}=Ot(),[a,s]=useState(!1),[l,u]=useState(),c=useRef(null),p=$(I=>I.records.entities.block),m=$(I=>I.status.previews),f=Us("section",e.id),{memberImageBg:g,hidden:h,columnSettings:b={}}=e.settings,v=i.type==="section"&&i.id===e.id,{inputs:C,consumers:R}=useMemo(()=>{if(l){let I=p[l],{inputs:w,consumers:O}=I;return {inputs:w,consumers:O}}return {inputs:[],consumers:[]}},[l]),y=Object.values(p||{}).filter(I=>I.section_id===e.id&&![k.GENERATOR,k.SECTION_FLAG].includes(I.type)).reduce((I,w)=>(I[w.blockcol]?I[w.blockcol][w.blockrow]=w:I[w.blockcol]={[w.blockrow]:w},I),{}),A=useMantineTheme(),S=()=>s(!0),E=I=>{if(s(!1),!I.destination)return;let{source:w,destination:O}=I;if(w.droppableId===O.droppableId&&w.index===O.index)return;let _=O.droppableId==="newColumn",H=Number(I.draggableId),G=w.droppableId,te=_?ea(Object.keys(y),!0):O.droppableId,j={id:H,blockrow:Yn,blockcol:Yn},W=G!==te;j.blockcol=W?te:G;let q=Object.values(y[j.blockcol]||{}),V=q.reduce((F,J)=>({...F,[J.id]:J}),{}),K=q.sort((F,J)=>eo(F,J,"blockrow")).map(F=>F.id),Z=O.index>w.index;j.blockrow=Jn(V,K,O.index,W,Z,"blockrow"),n(Q.updateEntity("block",j));},L=useMemo(()=>{let I=Object.values(p||{}).filter(w=>w.section_id===e.id&&Jo(w));return I.length>1&&console.error(`Error, there are more than one Section Flag Generator in section ${e.id}`),I.length>0?I[0]:!1},[p,v,e.id]),P=$(I=>L&&I.variables.variables[L.id]&&!I.variables.variables[L.id][Eo]||!1),D=useMemo(()=>{let I="";return P&&L&&(I+=`(Not allowed by Section Flag #${L.id})`),h&&(I+="(Hidden by Section Settings)"),I},[h,P]),M=Object.keys(y).sort((I,w)=>-ws(I,w)),z=Object.keys(y).length;return f.isFetching?jsxs(Box,{p:"lg",m:"lg",bg:On.section.backgroundColor,sx:I=>({borderRadius:I.radius.md,border:`1px solid ${I.colors.gray[4]}`}),children:[jsx(Skeleton,{height:50,circle:!0,mb:"xl"}),jsx(Skeleton,{height:8,radius:"xl"}),jsx(Skeleton,{height:8,mt:6,radius:"xl"}),jsx(Skeleton,{height:8,mt:6,width:"70%",radius:"xl"})]}):jsxs(Box,{px:"md",mt:"md",children:[jsx(lR,{active:v,id:e.id,isDragging:t,hidden:D,dragHandleProps:r,onActivate:()=>o(e.id),sectionSettings:e.settings}),jsxs(Box,{pos:"relative",sx:I=>({border:v?`1px solid ${I.colors.blue[4]}`:"none",borderRadius:2}),children:[jsx(Paper,{id:`section-${e.id}`,className:`cms-section${t||v?" active":""}`,bg:e.settings.style==="card"?On.section.backgroundColor:"transparent",p:0,mih:100,maw:e.settings.width==="center"?A.breakpoints.xl:"none",w:"100%",mx:"auto",pos:"relative",shadow:e.settings.style==="card"?On.section.boxShadow:"none",radius:On.section.borderRadius,sx:{overflow:"hidden"},children:jsxs(Box,{pos:"relative",children:[g&&jsx(gf,{previews:m}),jsx(Af,{ref:c,containerProps:{mih:!v||!z?120:"none",p:e.settings.margin||"md",style:{zIndex:2},gap:e.settings.columnGutter||"md",wrap:"wrap"},children:jsxs(DragDropContext,{onDragEnd:E,onDragStart:S,children:[M.map(I=>{let w=Object.values(y[I]).sort((O,_)=>eo(O,_,"blockrow"));return jsx(Droppable,{droppableId:I,children:(O,_)=>jsxs(If,{column:y[I],columnSettings:b[I],ref:O.innerRef,basis:`calc(${100/z}% - (10px * ${z}))`,sx:{background:_.isDraggingOver?A.colors[A.primaryColor][0]:"inherit",border:"1px solid transparent","& .bespoke-resize-col":{visibility:"hidden"},"&:hover .bespoke-resize-col":{visibility:"visible"},"&:hover":{border:`1px solid ${A.colors.teal[1]}`}},...O.droppableProps,children:[jsx(eC,{sectionId:e.id,columnIndex:I}),w.map((H,G)=>{if(!p[H.id])return null;let{settings:te,type:j}=p[H.id],W=te.width&&!te.width.stretch&&te.width.unit?rl[te.width.unit](te.width.value):te.display==="inline"?"auto":"100%",q={alignSelf:j===k.VIZ?"stretch":"flex-start",flexGrow:0,margin:"0",width:W,minWidth:120};return jsx(Draggable,{draggableId:String(H.id),index:G,children:(V,K)=>jsx(Box,{ref:V.innerRef,...V.draggableProps,...V.dragHandleProps,sx:[q,{boxShadow:K.isDragging?A.shadows.lg:"none",...V.draggableProps.style}],children:jsx(ds,{id:Number(H.id),active:v,isInput:C.includes(Number(H.id)),isConsumer:R.includes(Number(H.id)),setHoverBlock:u},`block-${H.id}`)})},H.id)}),v&&jsx(fR,{section:e,columnIndex:I,columns:y}),O.placeholder]})},I)}),jsx(C2,{active:a&&v})]})}),jsx(T2,{columns:y,section:e,show:v&&!z})]})}),jsx(k2,{onActivate:o,section:e,show:!v})]})]})}var gR=oo(E2,er);Lt();Ko();ie();hr();jr();d();d();Ko();Ko();ie();d();ge();ie();ng();Pi();ua();fr();function hR(e,t,o){let r=document.getElementById(`${t}-${o}`),n=55;if(r){let a=r.getBoundingClientRect().top+e.current.scrollTop-n;e.current.scrollTo({top:a,behavior:"smooth"});}}function N2({section:e,onEnd:t}){let[o,r]=useState(e.settings?.name?.length?e.settings.name:`section-${e.id}`),n=a=>{[13,27].includes(a.keyCode)&&t(o);},i=useClickOutside(()=>t(o));return useEffect(()=>{setTimeout(()=>{i?.current&&i?.current?.focus();},200);},[i]),jsx(Input,{ref:i,bg:"gray.3",styles:{input:{display:"block",height:"100%",minHeight:"auto",lineHeight:"1rem",padding:0,boxSizing:"border-box"}},mih:"auto",type:"text",variant:"unstyled",value:o,onChange:a=>r(a.target.value),onKeyDown:n})}var z2=forwardRef(function({scrollContainer:t,section:o,isActive:r,...n},i){let a=$(S=>S?.records.entities.block),{settings:s,updateSettings:l}=Zr(o.id),u=useMantineTheme(),[c,p]=useState(!1),[m,f]=useState(!1),g=$(S=>{let E=o.blocks.map(L=>S.records.entities.block[L]).filter(L=>Jo(L));return E.length>0?S.variables.variables[E[0].id]:!1}),h=g?u.colors[g[Eo]===!1?"red":"green"][3]:"",b=useCallback(S=>{l("name",S),f(!1);},[l]),v=useRef(!1);useEffect(()=>{p(!!r);},[r]);let C=s?.name||`section-${o.id}`,R=S=>{S.detail===1&&(v.current=!1,setTimeout(()=>{v.current||hR(t,"section",o.id);},200)),S.detail===2&&(v.current=!0,f(E=>!E));},y=r?u.colors.blue[5]:"black",A=o?.blocks.map(S=>a[S]).filter(S=>![k.GENERATOR,k.SECTION_FLAG].includes(S.type)).map(S=>{let E=og[S.type]||IconDice;return jsx(List.Item,{pl:"lg",sx:{border:"1px solid transparent","&:hover":{border:"1px solid blue",cursor:"default"}},icon:jsx(E,{size:"0.8rem"}),onClick:()=>hR(t,"block",S.id),children:jsx(Text,{size:"sm",children:`${S.type} ${S.id}`})},S.id)});return jsxs(List.Item,{ref:i,w:"100%",...n,children:[jsxs(Group,{position:"apart",noWrap:!0,px:"sm",bg:r?u.colors.gray[2]:"transparent",sx:S=>({cursor:"default",border:`1px solid ${r?S.colors.gray[2]:"transparent"}`,".section-icon":{color:y},":hover":{border:`1px solid ${S.colors.blue[5]}`}}),children:[jsxs(Group,{spacing:"xs",miw:0,onClick:R,noWrap:!0,children:[jsx(IconBoxMultiple,{className:"section-icon",size:"0.8rem",style:{flexShrink:0}}),m?jsx(N2,{section:o,onEnd:b}):jsxs(Group,{spacing:4,align:"flex-end",children:[jsxs(Text,{size:"sm",fw:500,color:"gray.5",span:!0,children:[o.id," -"]}),jsx(Text,{size:"sm",c:y,maw:220,sx:{whiteSpace:"nowrap",textOverflow:"ellipsis",overflow:"hidden"},span:!0,children:C})]})]}),jsxs(Group,{spacing:"xs",children:[o.settings.hidden&&jsx(IconEyeOff,{size:"0.8rem",color:u.colors.red[3]}),g&&jsx(IconFlag,{size:"0.8rem",color:h,fill:h}),A.length&&jsx(IconChevronDown,{size:"0.8rem",style:{transform:`rotate(${c?-180:0}deg)`,flexShrink:0},onClick:()=>p(S=>!S)})]})]}),c&&A.length?jsx(List,{listStyleType:"none",children:A}):null]})}),yR=z2;function $h({activeSection:e,scrollContainer:t}){let o=$(s=>s?.records.entities.section),r=ne(),n=Object.values(o).sort(eo),i=n.map(s=>s?.id),a=useCallback(s=>{if(!s.destination||s.source.index===s.destination.index)return;let l=Number.parseInt(s.draggableId,10),u=s.destination.index>s.source.index,c=Jn(o,i,s.destination.index,!1,u),p=i.slice(),m=p.splice(s.source.index,1);p.splice(s.destination.index,0,...m),r(Q.updateEntity("section",{id:l,ordering:c}));},[r,o,i]);return jsxs(ScrollArea.Autosize,{mah:"80vh",pb:"sm",sx:{borderBottom:"1px solid rgba(0, 0, 0, 0.1)"},children:[jsx(Text,{fw:700,size:"sm",px:"sm",children:jsxs(Center,{inline:!0,children:[jsx(IconIndentIncrease,{size:"1rem"}),jsx(Text,{ml:"xs",span:!0,children:"Navigation"})]})}),jsx(DragDropContext,{onDragEnd:a,children:jsx(List,{styles:{itemWrapper:{width:"100%"}},mt:"sm",listStyleType:"none",children:jsx(Droppable,{droppableId:"sections",children:s=>jsx("div",{ref:s.innerRef,...s.droppableProps,children:n.map((l,u)=>jsx(Draggable,{draggableId:`${l?.id}`,index:u,children:c=>jsx(yR,{scrollContainer:t,ref:c.innerRef,section:l,isActive:l.id===e,...c.draggableProps,...c.dragHandleProps})},l?.id))})})})})]})}ie();Ba();d();ie();ko();ge();fr();var Q2=e=>t=>Object.values(t.records.entities.block||{}).filter(o=>o.section_id===e&&[k.GENERATOR].includes(o.type));function Uh({activeSection:e}){let t=$(Q2(e)),o=ne(),r=()=>{let{locales:n}=Yo({type:k.GENERATOR});o(Q.createEntity("block",{blockrow:void 0,blockcol:void 0,type:k.GENERATOR,section_id:e,locales:n})).then(i=>{o(Q.updateEntity("block",{id:i.data.id,contentByLocale:{logic:{...i.data.contentByLocale.logic,content:{simpleEnabled:!0,simple:{},logic:ky}}}}));});};return jsx(ScrollArea.Autosize,{mah:"80vh",w:"330px",sx:{borderBottom:"1px solid rgba(0, 0, 0, 0.1)"},children:jsxs(Stack,{pos:"relative",w:330,pr:"md",children:[jsxs(Group,{position:"apart",children:[jsx(Text,{fw:700,children:"Generators"}),jsx(ActionIcon,{c:"black",onClick:r,children:jsx(IconPlus,{})})]}),t.length?t.map(n=>jsx("div",{children:jsx(ds,{id:Number(n.id),active:!!e,isInput:!1,isConsumer:!1,setHoverBlock:()=>{},showOutline:!1})},`block-${n.id}`)):jsx(Text,{align:"center",size:"sm",children:"Click '+' to add a generator"})]})})}he();d();ie();function wR({sectionId:e}){let[t,o]=useState(window.innerWidth-40),[r,n]=useState(window.innerHeight-150);useEffect(()=>{let g=()=>{o(window.innerWidth-40),n(window.innerHeight-120);};return window.addEventListener("resize",g),()=>{window.removeEventListener("resize",g);}},[]);let i=jd(),a=ya(),[s,l]=useState(`${e}`),u=useMemo(()=>a.isSuccess?a.data.map(h=>({value:`${h.id}`,label:h.settings.name?`${h.settings.name} (${h.id})`:`Section ${h.id}`})):[],[a.isLoading]),c=useMemo(()=>{if(i.isSuccess&&s){let g={id:"root",label:"section",size:40,parentIds:[]},h={id:"wide",label:"report",size:40,parentIds:[]},b=i.data.filter(C=>`${C.section_id}`==`${s}`),v=b.map(C=>C.id);return [g,h,...b.map(C=>{let R=C.consumers.length>0?C.consumers.length*20:40,y=C.inputs.length>0?C.inputs.map(A=>v.includes(A)?`${A}`:`${h.id}`):[`${g.id}`];return {id:`${C.id}`,label:`${C.type}`,size:R>50?50:R,parentIds:[...Array.from(new Set(y))]}})]}else return []},[i.isLoading,s]),p=useRef(null);return useEffect(()=>{let g=Pp.dagStratify()(c),h=40,b=Pp.sugiyama().nodeSize(w=>{let O=w?w.data:null,_=O?O.size:h;return [(w?3.6:.25)*_,3*_]}),{width:v,height:C}=b(g),R=Uo.select(p.current);R.selectAll("*").remove(),R.attr("viewBox",[0,0,v,C].join(" "));let y=R.append("defs"),A=g.size(),S=Uo.interpolateRainbow,E=new Map;c.forEach((w,O)=>{E.set(w.id,S(O/A));});let L=Uo.line().curve(Uo.curveCatmullRom).x(w=>w.x).y(w=>w.y);R.append("g").selectAll("g").data(g.links()).enter().append("g").append("path").attr("class","curve").attr("d",({points:w})=>L(w)).attr("fill","none").attr("stroke-width",3).attr("stroke",({source:w,target:O})=>{let _=encodeURIComponent(`${w.data.id}--${O.data.id}`),H=y.append("linearGradient").attr("id",_).attr("gradientUnits","userSpaceOnUse").attr("x1",w.x).attr("x2",O.x).attr("y1",w.y).attr("y2",O.y);return H.append("stop").attr("offset","0%").attr("stop-color",E.get(w.data.id)),H.append("stop").attr("offset","100%").attr("stop-color",E.get(O.data.id)),`url(#${_})`}),R.append("g").selectAll("g").data(g.descendants()).enter().append("g").attr("transform",({x:w,y:O})=>`translate(${w}, ${O})`).append("circle").attr("r",w=>w.data.size).attr("fill",w=>E.get(w.data.id));let M=R.append("g").selectAll("g").data(g.links()).enter().append("g"),z=Uo.symbol().type(Uo.symbolTriangle).size(h*1.5);M.append("path").attr("class","arrow").attr("d",z).attr("transform",w=>{let{points:O,target:_}=w,[H,G]=O.reverse(),te=G.x-H.x,j=G.y-H.y,W=_.data.size*1/Math.sqrt(te*te+j*j),q=Math.atan2(-j,-te)*180/Math.PI+90;return `translate(${H.x+te*W}, ${H.y+j*W}) rotate(${q})`}).attr("fill",({target:w})=>E.get(w.data.id)).attr("stroke","white");let I=R.append("g").selectAll("g").data(g.descendants()).enter().append("g").attr("transform",({x:w,y:O})=>`translate(${w}, ${O})`);I.append("text").text(w=>w.data.id).attr("font-weight","bold").attr("font-family","sans-serif").attr("text-anchor","middle").attr("font-size","10px").style("transform","translate(0px,10px)").attr("alignment-baseline","middle").attr("fill","black"),I.append("text").text(w=>w.data.label).attr("font-weight","bold").attr("font-family","sans-serif").attr("font-size","15px").style("transform","translate(0px,-5px)").attr("text-anchor","middle").attr("alignment-baseline","middle").attr("fill","black");},[c]),jsxs(Stack,{spacing:0,children:[jsxs(Group,{align:"flex-end",w:"100%",position:"apart",children:[jsx(Select,{label:"Choose a section",placeholder:"Pick one",value:s,onChange:l,data:u,width:"80%"}),jsxs(Group,{grow:!0,maw:100,children:[jsx(ActionIcon,{onClick:()=>{let g=u.findIndex(h=>h.value===s);g>0&&l(u[g-1].value);},variant:"outline",children:jsx(IconChevronLeft,{size:"1.125rem"})}),jsx(ActionIcon,{onClick:()=>{let g=u.findIndex(h=>h.value===s);g<u.length-1&&l(u[g+1].value);},variant:"outline",children:jsx(IconChevronRight,{size:"1.125rem"})})]})]}),jsx("svg",{ref:p,width:t,height:r})]})}function IR({name:e,id:t,variables:o}){return jsxs(Flex,{gap:"xs",children:[jsx(ThemeIcon,{bg:"blue.5",color:"white",size:"sm",radius:"xl",sx:{flexGrow:0},children:jsx(IconCodeDots,{size:"0.8rem"})}),jsxs(Stack,{sx:{flexGrow:1},children:[jsx(Text,{size:"sm",children:e}),jsx(tr,{id:t,variables:o})]})]})}function bK({sectionId:e}){let[t,o]=useDisclosure(!1);return jsxs(Fragment,{children:[jsx(Button,{onClick:o.open,variant:"outline",radius:2,leftIcon:jsx(IconBinaryTree,{}),children:"Section Graph"}),jsx(Modal,{opened:t,onClose:o.close,title:"Block Graph",fullScreen:!0,children:jsx(wR,{sectionId:e})})]})}function yK({activeSection:e}){let t=$(i=>i.records.entities.block),o=$(i=>i.variables.attributes),r=$(i=>i.variables.variables),n=Object.values(t).filter(i=>(i.section_id===e||i.shared)&&Object.keys(r[i.id]||{}).length);return jsxs(Box,{px:"sm",w:"100%",children:[jsx(Text,{fw:700,size:"sm",children:jsxs(Center,{inline:!0,children:[jsx(IconCodeDots,{size:"1rem"}),jsx(Text,{ml:"xs",span:!0,children:"Variables"})]})}),jsx(ScrollArea.Autosize,{mah:"40vh",mx:"sm",w:"240px",children:jsxs(Stack,{mt:"sm",children:[jsx(IR,{name:"Report Variables",id:"attributes",variables:o}),n.map(i=>jsx(IR,{id:i.id,name:`${i.type} ${i.id}`,variables:r[i.id]},i.id))]})})]})}function vK(){return jsx(Title,{children:"Formatters"})}var SK={section:[{label:"Navigation",value:"navigation"},{label:"Generators",value:"generators"}],block:[{label:"Navigation",value:"navigation"},{label:"Variables",value:"variables"},{label:"Formatters",value:"formatters"}]};function qh({scrollContainer:e}){let{opened:t,handlers:o}=to("tools"),{toggle:r}=o,[n,i]=useState("navigation"),{activeEntity:a}=Ot(),s=c=>i(c),l=a.type==="section"?a.id:null,u=t&&jsxs(Fragment,{children:[l&&jsx(SegmentedControl,{sx:{flexShrink:0},data:SK.section,value:n,onChange:s}),jsxs(Stack,{sx:{flexGrow:1},spacing:"sm",mt:32,children:[(n==="navigation"||!l)&&jsx($h,{activeSection:l,scrollContainer:e}),n==="generators"&&l&&jsx(Uh,{activeSection:l}),n==="variables"&&jsx(yK,{activeSection:l}),n==="formatters"&&jsx(vK,{})]})]});return jsxs(Flex,{direction:"column",justify:t?"space-between":"flex-end",bg:"white",pb:30,pt:"sm",px:"xs",mah:"100vh",w:t?"350px":"50px",sx:c=>({overflow:"hidden",borderRight:`1px solid ${c.colors.gray[2]}`,flexShrink:0,flexGrow:0}),children:[u,jsxs(Flex,{justify:t?"space-between":"center",px:"sm",children:[a.type==="section"&&t&&jsx(bK,{sectionId:l}),jsx(UnstyledButton,{onClick:r,sx:{transform:`rotate(${t?0:180}deg)`},children:jsx(IconChevronLeft,{size:24})})]})]})}d();d();ie();d();function Dr({target:e,dropdown:t}){let[o,{open:r,close:n}]=useDisclosure(!1),i=useRef(!0),a=()=>{setTimeout(()=>{i.current&&n();},1e3);},s=()=>{i.current=!1;},l=()=>{i.current=!0,n();};return jsxs(Group,{children:[e,jsxs(Popover,{opened:o,trapFocus:!0,children:[jsx(Popover.Target,{children:jsx(ActionIcon,{variant:"subtle",color:"blue",onMouseEnter:r,onMouseLeave:a,children:jsx(IconInfoCircle,{})})}),jsx(Popover.Dropdown,{maw:350,onMouseEnter:s,onMouseLeave:l,children:jsxs(Group,{align:"flex-start",noWrap:!0,children:[jsx("div",{children:jsx(ThemeIcon,{variant:"outline",sx:{border:"none"},children:jsx(IconInfoCircle,{})})}),jsx("div",{children:t})]})})]})]})}Pi();he();ua();ge();ko();fr();hr();Lt();function PK({activeSection:e}){let{settings:t,updateSettings:o}=Zr(e),r=t.name||`section-${e}`,[n,i]=useState(r),[a,s]=useState(!1);return jsx(TextInput,{label:"Section Name",description:"Section name. Only for organization purposes. Won't be displayed on the final report.",value:a?n:r,onChange:l=>i(l.target.value),onFocusCapture:()=>{i(r),s(!0);},onBlurCapture:()=>{o("name",n),s(!1);},withAsterisk:!0,radius:2})}function Qh(){let{activeEntity:e}=Ot(),t=e.id,o=$(v=>t&&v.records.entities.section[t]),r=$(v=>t&&o&&v.records.entities.report[o.report_id]),n=$(v=>{if(t&&o){let C=o.blocks.map(R=>v.records.entities.block[R]).filter(R=>Jo(R));return C.length>1&&console.error(`Error, there is more than one section flag generator in section ${e.id}`),C.length>0?C[0]:!1}return !1}),i=ne(),a=useContext(_e),s=v=>{v==="always"&&n?l(n.id):v==="section-flag"&&u();},l=v=>{i(Q.deleteEntity("block",v)).then(()=>{i(uo(a)),console.log(`Flag generator with ID ${v} deleted.`);});},u=()=>{let{locales:v}=Yo({type:k.SECTION_FLAG});i(Q.createEntity("block",{blockrow:void 0,blockcol:void 0,type:k.SECTION_FLAG,section_id:t,locales:v})).then(C=>{i(Q.updateEntity("block",{id:C.data.id,contentByLocale:{logic:{...C.data.contentByLocale.logic,content:{simpleEnabled:!0,simple:{},logic:`return {
122
+ ) Avoid this, please.`:!1},[m,r,n]);if(!c)return null;let A=Object.keys(m),S=E=>E&&Array.isArray(E)&&E.length;return jsxs(Fragment,{children:[jsx(Select,{label:"Options List Variable",placeholder:"Pick a variable",value:S(A)&&r,required:!0,onChange:R,data:A}),jsx(Select,{label:"Options ID Key",placeholder:"Pick a property key",value:S(b)&&n,required:!l,disabled:l,onChange:E=>C("idKey",E),data:b,error:y}),jsx(Select,{label:"Options Label Key",placeholder:"Pick a property key",disabled:l,clearable:!0,value:S(b)&&i,onChange:E=>C("labelKey",E),data:b}),jsx(Select,{label:"Options Image Key",placeholder:"Pick a property key",disabled:l,clearable:!0,value:S(b)&&s,onChange:E=>C("imageKey",E),data:b}),jsx(Select,{label:"Default ID Variable",placeholder:"Pick a variable",clearable:!0,value:S(g)&&a,onChange:E=>C("defaultVar",E),data:g})]})}function ss(e,t,o){return e&&e[t]||o}function OH(e){let{id:t,executeButton:o,onChange:r,simpleState:n,referenceContent:i,referenceLocale:a,variables:s}=e,[l,u]=useState(()=>{let m=n&&n.options&&Object.prototype.hasOwnProperty.call(n?.options,"dynamic")&&Object.prototype.hasOwnProperty.call(n?.options,"static");return {selectorIdentifier:ss(n,"name",""),selectorType:ss(n,"type",Wi.SINGLE),selectorComponent:ss(n,"component",rh.SELECTOR),options:n&&m?n.options:{static:[],dynamic:{}},optionsType:ss(n,"optionsType","static"),hideLabel:ss(n,"hideLabel","false"),resetSectionVars:ss(n,"resetSectionVars","false")}});useEffect(()=>{let{selectorIdentifier:m,selectorType:f,selectorComponent:g,options:h,optionsType:b,hideLabel:v,resetSectionVars:C}=l,R={name:m,hideLabel:v,resetSectionVars:C,component:g,type:f},{logicOptions:y,defaultValue:A}=cp(f,h,b);A&&(R.defaultValue=A),R.options=y;let S=`return ${Xa(R)};`,E={name:m,type:f,component:g,hideLabel:v,resetSectionVars:C,defaultValue:A,optionsType:b,options:h},L=hE(E);r(E,S,L);},[l]);let c=(m,f)=>u(g=>({...g,[m]:f})),p=pr[k.SELECTOR].find(m=>m.field===ke.SELECTOR_NAME)?.editorConfig;return jsxs(Fragment,{children:[jsxs(Stack,{children:[jsx(sr,{field:"name",value:l.selectorIdentifier,handleEditor:(m,f)=>c("selectorIdentifier",f),referenceContent:i,referenceLocale:a,variables:s,editorConfig:p}),jsx(Checkbox,{label:jsx(It,{label:"Hide Label",py:0}),checked:l.hideLabel==="true",onChange:m=>c("hideLabel",m.currentTarget.checked?"true":"false")})]}),jsx(Select,{label:jsx(It,{label:"Selector Type"}),value:l.selectorType,onChange:m=>c("selectorType",m),data:Object.values(Wi)}),l.selectorType===Wi.SINGLE&&jsx(Select,{label:jsx(It,{label:"Selector Component"}),value:l.selectorComponent,onChange:m=>c("selectorComponent",m),data:Object.values(rh)}),jsx(Select,{label:jsx(It,{label:"Options Type"}),value:l.optionsType,onChange:m=>c("optionsType",m),data:Object.values(_n)}),l.optionsType===_n.STATIC?jsx(AH,{staticOptions:l.options.static,setStaticOptions:m=>c("options",{...l.options,static:m})}):jsx(PH,{dynamicOptions:l.options.dynamic,setDynamicOptions:m=>c("options",{...l.options,dynamic:m}),id:t}),jsx(Checkbox,{my:"md",label:jsx(It,{label:"Reset SectionVariables on change",py:0}),checked:l.resetSectionVars==="true",onChange:m=>c("resetSectionVars",m.currentTarget.checked?"true":"false")}),o]})}var vE=OH;d();function lh(){return jsx(Title,{order:4,children:"Nav UI"})}d();function ch({executeButton:e,onChange:t,simpleState:o}){let[r,n]=useState(o?.compare??"variant"),[i,a]=useState(o?.limit??4);return useEffect(()=>{t({compare:r,limit:i});},[r,i]),jsxs(Stack,{children:[jsx(Radio.Group,{label:"Compare with members of",onChange:n,value:r,children:jsxs(Group,{children:[jsx(Radio,{label:"Same report",value:"report"}),jsx(Radio,{label:"Same dimension",value:"dimension"}),jsx(Radio,{label:"Same variant",value:"variant"})]})}),jsx(NumberInput,{label:"Related reports limit",min:1,onChange:s=>a(s),type:"number",value:i}),e]})}d();function ph({executeButton:e,onChange:t,simpleState:o}){let[r,n]=useState(o?.label??""),[i,a]=useState(o?.showIcon??!0),[s,l]=useState(o?.fullWidth??!1),[u,c]=useState(o?.showWhenDisabled??!1);return useEffect(()=>{t({label:r,showIcon:i,fullWidth:s,showWhenDisabled:u});},[r,i,s,u,t]),jsxs(Stack,{children:[jsx(TextInput,{placeholder:"Label for reset section state button",value:r,onChange:p=>n(p.target.value),label:"Label"}),jsxs(Group,{children:[jsx(Switch,{checked:i,label:"Show icon",onChange:p=>a(p.currentTarget.checked)}),jsx(Switch,{checked:s,label:"Full width",onChange:p=>l(p.currentTarget.checked)}),jsx(Switch,{checked:u,label:"Show when disabled",onChange:p=>c(p.currentTarget.checked)})]}),e]})}d();d();function Ul(e,t){let[o,r]=useState({...t,...e});return {state:o,updateState:(i,a)=>{let s={...o,[i]:a};r(s);}}}d();var kE=["xs","sm","md","lg","xl"],tj=["0","1","2","3","4","5"],an={none:{value:"none",label:"No Icon"},tabler:{value:"tabler",label:"Bespoke (Tabler)",link:"https://tablericons.com",text:"Tabler Icons"},custom:{value:"custom",label:"Custom Icon"}},oj=forwardRef(({value:e,iconType:t="tabler",...o},r)=>jsx("div",{ref:r,...o,children:jsxs(Group,{noWrap:!0,children:[jsx(Image,{width:20,height:20,src:`/api/cms/read/icons/${t}/icon.svg?name=${e}`,alt:`Icon preview ${e}`}),jsx(Text,{size:"sm",children:e})]})}));function hp(e){let[t,o]=useState(e?._iconType??"none"),[r,n]=useState(e?._icon??""),[i,a]=useState([]),[s,l]=useState(""),[u,c]=useState(e?._iconVariant??"transparent"),[p,m]=useState(e?._iconSize??"md"),[f,g]=useState(e?._iconRadius??"md"),[h,b]=useState(e?._iconPadding??"1"),v=[an.none.value,an.custom.value].includes(t),C=useRef(null),R=useMemo(()=>({_icon:r,_iconType:t,_defaultIcon:s,_iconVariant:u,_iconSize:p,_iconRadius:f,_iconPadding:h}),[r,t,s,u,p,f,h]),y=S=>{n(""),o(S);};useEffect(()=>{v||Cc.get(`/api/cms/list/icons/${t}`).then(S=>{a(S.data.data.results),l(S.data.data.results[0]);});},[t]);let A=jsx(Accordion,{variant:"separated",children:jsxs(Accordion.Item,{value:"icon",children:[jsx(Accordion.Control,{icon:jsx(IconPhotoFilled,{}),children:jsxs(Text,{children:["Icon configuration: ",an[t]&&jsx("strong",{children:an[t].label})]})}),jsx(Accordion.Panel,{children:jsxs(Stack,{children:[jsx(Input.Wrapper,{label:"Title's icon",children:jsx(SegmentedControl,{fullWidth:!0,value:t,onChange:y,data:Object.values(an)})}),!v&&jsx(Select,{label:"Choose an icon from the list",searchable:!0,description:jsxs(Fragment,{children:["Powered by"," ",jsx("a",{style:{textDecoration:"underline"},href:an[t].link,target:"_blank",rel:"noreferrer",children:an[t].text}),"."]}),defaultValue:s,value:r,required:!0,onChange:S=>n(S||""),data:i,limit:10,itemComponent:oj,disabled:!i||i.length===0,icon:jsx(Image,{p:5,src:`/api/cms/read/icons/${t}/icon.svg?name=${r||s}`,alt:"Icon preview"})}),t===an.custom.value&&jsxs(Flex,{align:"flex-end",children:[jsx(TextInput,{ref:C,placeholder:"e.g '/image{{id1}}.png' or 'http://site/image.png'",label:"Enter an icon path",required:!0,defaultValue:r,description:"Add an absolute or a relative path url",onBlur:S=>n(S.currentTarget.value),sx:{flexGrow:1}}),jsx(ActionIcon,{maw:36,size:36,onClick:()=>C.current?n(C.current.value??""):void 0,sx:{flexGrow:0},children:jsx(IconFileUpload,{})})]}),t!==an.none.value&&jsxs(Fragment,{children:[jsx(Select,{label:"Variant design",description:jsxs(Fragment,{children:["We are using"," ",jsx("a",{style:{textDecoration:"underline"},href:"https://mantine.dev/core/theme-icon/",target:"_blank",rel:"noreferrer",children:"ThemeIcon variants"}),"."]}),value:u,required:!0,onChange:S=>c(S||"transparent"),data:[{value:"transparent",label:"Transparent"},{value:"default",label:"Default"},{value:"outline",label:"Outline"},{value:"light",label:"Light"},{value:"filled",label:"Filled"}]}),jsx(Input.Wrapper,{label:"Size",children:jsx(SegmentedControl,{fullWidth:!0,value:p,onChange:m,data:kE})}),jsx(Input.Wrapper,{label:"Radius",children:jsx(SegmentedControl,{fullWidth:!0,value:f,onChange:g,data:kE})}),jsx(Input.Wrapper,{label:"Padding",children:jsx(SegmentedControl,{fullWidth:!0,value:h,onChange:b,data:tj})})]})]})})]})});return {simpleIconState:R,panel:A}}ge();var ij={title:"Title",tooltip:"",slug:""};function mh({onChange:e,simpleState:t,variables:o,referenceContent:r,referenceLocale:n}){let{state:i,updateState:a}=Ul(t,ij),{simpleIconState:s,panel:l}=hp(t);return useEffect(()=>{let u={...i,...s},c=Ln(u);e(u,c);},[s,i]),jsxs(Stack,{children:[pr[k.TITLE].map(({field:u,editorConfig:c})=>jsx(sr,{field:u,value:i[u],handleEditor:a,referenceContent:r,referenceLocale:n,variables:o,editorConfig:c},u)),l]})}d();var mj=[{value:"left",label:"Left"},{value:"center",label:"Center"},{value:"right",label:"Right"}];function fh({executeButton:e,onChange:t,simpleState:o}){let[r,n]=useState(o?.label??""),[i,a]=useState(o?.removeLabel??""),[s,l]=useState(o?.showIcon??!0),[u,c]=useState(o?.position??"center");return useEffect(()=>{t({label:r,removeLabel:i,showIcon:s,position:u});},[r,s,i,u,t]),jsxs(Stack,{children:[jsx(TextInput,{placeholder:"Label for comparison button",value:r,onChange:p=>n(p.target.value),label:"Label"}),jsx(TextInput,{placeholder:"Label for remove comparison button",value:i,onChange:p=>a(p.target.value),label:"Remove Label"}),jsx(Group,{children:jsx(Switch,{checked:s,label:"Show icon",onChange:p=>l(p.currentTarget.checked)})}),jsx(Select,{label:"Button position",data:mj,value:u,onChange:c}),e]})}d();ge();function gh({simpleState:e,onChange:t,variables:o,referenceContent:r,referenceLocale:n}){let{state:i,updateState:a}=Ul(e,{title:"",value:"",subtitle:"",tooltip:""}),{simpleIconState:s,panel:l}=hp(e);return useEffect(()=>{let u={...i,...s},c=Ln(u);t(u,c);},[s,i]),jsxs(Stack,{children:[pr[k.STAT].map(({field:u,editorConfig:c})=>jsx(sr,{field:u,value:i[u],handleEditor:a,referenceContent:r,referenceLocale:n,variables:o,editorConfig:c},u)),l]})}d();he();var _j={enableBottomToolbar:!0,enableColumnActions:!0,enableColumnFilters:!0,enableColumnResizing:!0,enableDensityToggle:!0,enableFullScreenToggle:!1,enableGlobalFilter:!0,enableHiding:!0,enablePagination:!0,enableSorting:!0,enableStickyHeader:!0,enableTopToolbar:!0},OE={enableBottomToolbar:{label:"Enable bottom toolbar",desc:"Show or hide the bottom toolbar. By disabling it, pagination will also be hidden."},enableColumnActions:{label:"Enable column actions",desc:"Enables or disables column actions for all columns. Column actions include sort, filter, show/hide column and reset column size."},enableColumnFilters:{label:"Enable column filters",desc:"Enables or disables the filter options available on columns."},enableColumnResizing:{label:"Enable column resizing",desc:"Enables the column resizing feature for all columns."},enableDensityToggle:{label:"Enable density toggle",desc:"Enable the density toggle that allows users to modify the height of each row. Disabling it will hide the density toggle button in the top toolbar."},enableFullScreenToggle:{label:"Enable full screen toggle",desc:"Enable or disable the full screen toggle feature. Disabling it will hide the full screen toggle button in the top toolbar."},enableGlobalFilter:{label:"Enable global filter",desc:"Enable global filter feature to filter data on all columns and rows. Disabling it will hide the global filter button in the top toolbar."},enableHiding:{label:"Enable hiding",desc:"Enable hiding columns feature. Disabling it will hide the hiding button in the top toolbar."},enablePagination:{label:"Enable pagination",desc:"Enable pagination feature. Disabling it will hide the pagination options in the bottom toolbar."},enableSorting:{label:"Enable sorting",desc:"Enable sorting feature for all columns."},enableStickyHeader:{label:"Enable sticky header",desc:"Allows you to maintain the column headers when scrolling through the rows of the table."},enableTopToolbar:{label:"Enable top toolbar",desc:"Show or hide the top toolbar. By disabling it, globar filter, hiding, density and full screen toggles will also be hidden."}},Nj={density:"xs"},LE=["5","10","15","20","25","30","50","100"],ME={pageIndex:0,pageSize:10},BE=e=>e&&Array.isArray(e)&&e.some(t=>typeof t=="object"&&t!==null),zj=forwardRef(function({customLabels:t,customLabelsHandler:o,index:r,isActiveRefenceContent:n=!1,option:i,referenceColumns:a=[],selectedColumnsHandler:s,...l},u){let c=t.find(f=>f.key===i.label)?.label||"",m=a.find(f=>f.accessorKey===i.label)?.header||i.label;return jsxs(Group,{grow:!0,ref:u,...l,children:[jsxs(Group,{children:[jsx(IconGripVertical,{}),jsx(Checkbox,{checked:i.checked,label:i.label,onChange:f=>s.setItemProp(r,"checked",f.currentTarget.checked)})]}),jsx(Input,{disabled:!i.checked,onChange:f=>o.setItemProp(r,"label",f.currentTarget.value),value:c}),n&&jsx(Input,{disabled:!0,value:m})]},`table-group-${i.label}-${r}`)});function xh(e){let{executeButton:t,id:o,onChange:r,referenceContent:n={},referenceLocale:i,simpleState:a}=e,{columns:s}=n,l=Sa(),u=useMemo(()=>l!==i&&n&&Object.keys(n).length>0,[l,n,i]),c=je(o),[p,m]=useState([]),[f,g]=useListState([]),[h,b]=useState([]),[v,C]=useState(!1),[R,y]=useState({}),[A,S]=useState(ME),[E,L]=useState({rowsPerPageOptions:LE}),[P,D]=useListState([]),[M,z]=useState(null),[I,w]=useSetState(_j),[O,_]=useState(Nj),[H,G]=useState({}),te=useMemo(()=>P.every(V=>V.checked),[P]),j=useMemo(()=>P.some(V=>V.checked)&&!te,[te,P]);useEffect(()=>{if(!a||!Object.keys(a).length)return;let V=c[a.variable]||[],K=new Set;V.filter(U=>typeof U=="object"&&U!==null).forEach(U=>{Object.keys(U).forEach(oe=>K.add(oe));});let Z={},F=[];a.columns&&Object.keys(a.columns)&&a.columns.forEach(U=>{Z[U.accessorKey]=U.header;});let J=[],se=[];Array.from(K).forEach(U=>{se.push({key:U,label:Z[U]||U}),J.push({checked:!!Z[U],key:randomId(),label:U}),F.push(U);}),g.setState(se),D.setState(J);let{initialState:re={},state:ce={},mantinePaginationProps:fe={},...Ie}=a.tableProps||{},xe=ce.columnOrder.filter(U=>F.includes(U));xe.push(F.filter(U=>!ce.columnOrder.includes(U))),m(xe.flat()||[]),L(fe),S(re.pagination),w({...Ie}),G(ce),_(re),z(a.variable||"");},[]),useEffect(()=>{if(!c){y({});return}let V=Object.entries(c).filter(([Z,F])=>BE(F)).reduce((Z,[F,J])=>(Z[F]=J,Z),{});y(V);let K=Object.keys(V);b(K);},[c]);let W=V=>{if(z(V),!V||!BE(R[V])){C(!1),D.setState([]);return}let K=R[V];if(K.every(re=>typeof re=="object"&&re===null)){C(!1),D.setState([]);return}K.every(re=>typeof re=="object"&&re!==null)?C(!1):C(!0);let Z=new Set;K.filter(re=>typeof re=="object"&&re!==null).forEach(re=>{Object.keys(re).forEach(ce=>Z.add(ce));});let F=[],J=[],se=[];Array.from(Z).forEach(re=>{F.push({checked:!0,key:randomId(),label:re}),J.push({key:re,label:re}),se.push(re);}),D.setState(F),g.setState(J),m(se);};useEffect(()=>{let V={};f.forEach(ce=>{V[ce.key]=ce.label;});let K=P.filter(ce=>ce.checked).map(ce=>({accessorKey:ce.label,header:V[ce.label]})),Z={...O,pagination:A},F={...H,columnOrder:p},J={columns:K,data:M?`variables["${M}"]`:[],tableProps:{...I,initialState:Z,state:F,mantinePaginationProps:E},variable:M||""},se=`return ${Xa(J)};`,re={columns:K,data:M?`variables["${M}"]`:[],tableProps:{...I,initialState:Z,state:F,mantinePaginationProps:E},variable:M||""};r(re,se);},[p,f,E,A,P,M,I,H,O]);let q=useCallback(V=>{if(!V.destination||V.source.index===V.destination.index)return;let K=[...p],[Z]=K.splice(V.source.index,1);K.splice(V.destination.index,0,Z),m(K),G(F=>{let J=F;return J.columnOrder=K,J});},[p]);return jsxs(Fragment,{children:[jsxs(Stack,{mb:"sm",children:[jsx(Select,{clearable:!0,data:h,description:"Select an array of data available in the block inputs to use as data input for the table.",label:"Data input",onChange:V=>W(V),searchable:!0,value:M}),M&&R[M]&&P.length>0&&jsxs(Fragment,{children:[jsx(Input.Wrapper,{description:"Select the columns to display in the table.",error:v&&"There is a mix of types in the input data. Only object types rows will be kept.",label:"Selected columns",children:jsxs(Stack,{mt:"xs",children:[jsxs(Group,{grow:!0,children:[jsx(Text,{fz:"xs",children:"Selected"}),jsx(Text,{fz:"xs",children:"Label"}),u&&jsxs(Group,{spacing:"xs",children:[jsx(Text,{fz:"xs",children:"Reference Label"}),jsx(Badge,{variant:"light",size:"xs",rightSection:jsx(Center,{children:jsx(IconLanguage,{size:rem(12)})}),children:i.toUpperCase()})]})]}),jsx(Checkbox,{checked:te,indeterminate:j,label:"All",onChange:()=>D.setState(V=>V.map(K=>({...K,checked:!te})))}),jsx(ScrollArea.Autosize,{mah:300,children:jsx(DragDropContext,{onDragEnd:q,children:jsx(Droppable,{droppableId:"columns",children:V=>jsx("div",{ref:V.innerRef,...V.droppableProps,children:p.map((K,Z)=>{let F=P.findIndex(se=>se.label===K),J=P[F];return jsx(Draggable,{draggableId:`${J.label}`,index:Z,isDragDisabled:!J.checked,children:se=>jsx(zj,{customLabels:f,customLabelsHandler:g,index:F,isActiveRefenceContent:u,option:J,ref:se.innerRef,referenceColumns:s,selectedColumnsHandler:D,...se.draggableProps,...se.dragHandleProps})},J.label)})})})})})]})}),jsx(Accordion,{variant:"separated",children:jsxs(Accordion.Item,{value:"custom-props",children:[jsx(Accordion.Control,{children:"Custom properties"}),jsx(Accordion.Panel,{children:jsx(Stack,{children:jsxs(Input.Wrapper,{description:"Select the needed table options.",label:"Table options",children:[jsx(Group,{mt:"xs",children:Object.keys(I).map(V=>jsx(Checkbox,{checked:I[V],label:jsx(Tooltip,{label:OE[V]?.desc||V,multiline:!0,children:jsx(Text,{children:OE[V]?.label||V})}),onChange:()=>w({[V]:!I[V]})},`table-prop-${V}`))}),I?.enablePagination&&jsxs(Fragment,{children:[jsx(Divider,{mt:"xs"}),jsxs(Input.Wrapper,{description:"Customize initial pagination properties.",label:"Pagination props",mt:"xs",children:[jsxs(Group,{grow:!0,children:[jsx(NumberInput,{label:"Initial page",min:0,onChange:V=>{S(K=>({...K,pageIndex:V}));},value:A.pageIndex}),jsx(Select,{data:E.rowsPerPageOptions||[],getCreateLabel:V=>`+ Create ${V}`,label:"Initial page size",onChange:V=>{S(K=>({...K,pageSize:parseInt(V,10)}));},searchable:!0,value:A.pageSize.toString()})]}),jsxs(Group,{align:"flex-end",grow:!0,children:[jsx(MultiSelect,{clearable:!0,creatable:!0,data:E.rowsPerPageOptions||[],getCreateLabel:V=>`+ Create ${V}`,label:"Page size options",onChange:V=>{L(K=>({...K,rowsPerPageOptions:V.sort((Z,F)=>parseInt(Z,10)-parseInt(F,10))})),V&&V.length>0&&!V.includes(A.pageSize.toString())&&S(K=>({...K,pageSize:parseInt(V[0],10)}));},onCreate:V=>(L(K=>({...K,rowsPerPageOptions:[...K.rowsPerPageOptions||[],V].sort((Z,F)=>parseInt(Z,10)-parseInt(F,10))})),V),searchable:!0,value:E.rowsPerPageOptions||[]}),jsx(Button,{color:"yellow",onClick:()=>{L(V=>({...V,rowsPerPageOptions:LE})),S(ME);},children:"Reset page sizes values"})]})]})]})]})})})]})})]})]}),t]})}d();he();ge();d();var DE=e=>{let{dataVar:t,levelsVar:o}=e;return !![t,o].every(Boolean)},Sp=e=>{let t,o,{colorKey:r,dataVar:n,iconKey:i,defaultVar:a,isPrimitiveType:s,levelsVar:l,searchIndexKey:u}=e;a&&typeof a=="string"&&(t=`variables["${a}"].value`,o=`variables["${a}"].type`);let c=s?`variables["${n}"]`:`(variables["${n}"] || []).map((d) => ({...d, colorKey: String(d["${r}"]), iconKey: String(d["${i}"]), searchIndexKey: String(d["${u}"])}))`;return {logicLevels:`variables["${l}"]`,logicOptions:c,defaultValue:t,defaultValueType:o}};Ks();var Ch=e=>pr[k.MULTIHIERARCHY_SELECTOR].find(t=>t.field===e)?.editorConfig,$j=e=>e&&Array.isArray(e)&&e.some(t=>typeof t=="object"&&t!==null),Uj=e=>e&&e.type&&e.value,us=e=>e&&Array.isArray(e)&&e.length;function io(e,t,o){return e&&e[t]||o}function kh(e){let{executeButton:t,id:o,onChange:r,referenceContent:n,referenceLocale:i,simpleState:a}=e,s=je(o),[l,u]=useState(!1),[c,p]=useState(()=>({allLabel:io(a,"allLabel","All"),colorKey:io(a,"colorKey",""),dataVar:io(a,"dataVar",""),defaultVar:io(a,"defaultVar",""),hideLabel:io(a,"hideLabel","false"),resetSectionVars:io(a,"resetSectionVars","false"),iconKey:io(a,"iconKey",""),isPrimitiveType:io(a,"isPrimiteType",!1),levelsVar:io(a,"levelsVar",""),limit:io(a,"limit",0),placeholder:io(a,"placeholder",""),searchIndexKey:io(a,"searchIndexKey",""),searchIndexSeparator:io(a,"searchIndexSeparator","|"),selectorIdentifier:io(a,"label","")})),[m,f]=useState([]),[g,h]=useState([]),[b,v]=useState({}),[C,R]=useState({}),[y,A]=useState([]),S=useCallback((I,w,O=!1)=>p(_=>({..._,[I]:!w&&O?"":w})),[]);useEffect(()=>{if(!s){f([]),h([]),v({}),R({});return}let I=Object.entries(s).filter(([H,G])=>$j(G)).reduce((H,[G,te])=>(H[G]=te,H),{}),w=Object.entries(s).filter(([H,G])=>Uj(G)).reduce((H,[G,te])=>(H[G]=te,H),{});R(I),v(w);let O=Object.keys(I),_=Object.keys(w);f(O),h(_),u(!0);},[s]),useEffect(()=>{if(!Object.keys(C).length)return;let I=lp(C[c.dataVar]);if(I)A([]),S("colorKey",""),S("iconKey",""),S("searchIndexKey","");else {let w=new Set;(C[c.dataVar]||[]).forEach(_=>Object.keys(typeof _=="object"?_:{}).forEach(H=>w.add(H)));let O=Array.from(w).sort().map(_=>_);A(O);}S("isPrimitiveType",I);},[C,c.dataVar]),useEffect(()=>{let{allLabel:I,colorKey:w,dataVar:O,defaultVar:_,hideLabel:H,resetSectionVars:G,iconKey:te,levelsVar:j,limit:W,placeholder:q,searchIndexKey:V,searchIndexSeparator:K,selectorIdentifier:Z}=c,F={allLabel:I,colorKey:w,dataVar:O,defaultVar:_,label:Z,hideLabel:H,resetSectionVars:G,iconKey:te,levelsVar:j,limit:W,placeholder:q,searchIndexKey:V,searchIndexSeparator:K},{logicOptions:J,logicLevels:se,defaultValue:re,defaultValueType:ce}=Sp(F);re&&ce&&(F.defaultValue=re,F.defaultValueType=ce),F.data=J,F.levels=se;let fe=`return ${Xa(F)};`,Ie=F,xe=DE(Ie);r(Ie,fe,xe);},[c]);let E=useCallback(I=>{S("dataVar",I),S("defaultVar",{}),S("colorKey",""),S("iconKey",""),S("searchIndexKey","");},[S]);if(!l)return null;let L=Object.keys(C),P=Object.keys(b),D=Ch(ke.MULTIHIERARCHY_SELECTOR_ALL_LABEL),M=Ch(ke.MULTIHIERARCHY_SELECTOR_NAME),z=Ch(ke.MULTIHIERARCHY_SELECTOR_PLACEHOLDER);return jsxs(Fragment,{children:[jsxs(Stack,{mb:"sm",spacing:"xs",children:[jsx(sr,{field:"label",value:c.selectorIdentifier,handleEditor:(I,w)=>{S("selectorIdentifier",w);},referenceContent:n,referenceLocale:i,variables:s,editorConfig:M}),jsx(Checkbox,{label:jsx(It,{label:"Hide Label",py:0}),checked:c.hideLabel==="true",onChange:I=>S("hideLabel",I.currentTarget.checked?"true":"false")}),jsx(Select,{data:m,description:"(Required) Select an array of data available in the block inputs to use as data input.",label:jsx(It,{label:"Data Input"}),onChange:I=>E(I),value:us(L)&&c.dataVar}),jsx(Select,{data:m,description:"(Required) Select an array of {label, value} items in the block inputs to use as levels.",label:jsx(It,{label:"Levels Input"}),onChange:I=>S("levelsVar",I),value:us(L)&&c.levelsVar}),jsx(Select,{clearable:!0,data:g,description:"(Optional) Select an object with {type, value} keys in the block inputs to use as default value.",label:jsx(It,{label:"Default Value"}),onChange:I=>{if(!I){S("defaultVar","");return}S("defaultVar",I);},value:us(P)&&c.defaultVar}),jsx(NumberInput,{description:"(Optional) Sets a limit for selected values. Set 0 for no limit.",label:jsx(It,{label:"Limit"}),min:0,onChange:I=>S("limit",I),value:c.limit}),jsx(Accordion,{mt:"md",variant:"separated",children:jsxs(Accordion.Item,{value:"customization",children:[jsx(Accordion.Control,{children:"Customization"}),jsx(Accordion.Panel,{children:jsxs(Stack,{spacing:"xs",children:[jsx(sr,{field:"allLabel",value:c.allLabel,handleEditor:(I,w)=>S("allLabel",Ft(w)),referenceContent:n,referenceLocale:i,variables:s,editorConfig:D}),jsx(sr,{field:"placeholder",value:c.placeholder,handleEditor:(I,w)=>S("placeholder",Ft(w)),referenceContent:n,referenceLocale:i,variables:s,editorConfig:z}),jsx(Select,{clearable:!0,data:y,description:"(Optional) Select a property key to use as item's icon background color. Requires defining an icon key.",disabled:c.isPrimitiveType,label:jsx(It,{label:"Color property key"}),onChange:I=>S("colorKey",I,!0),value:us(y)&&c.colorKey}),jsx(Select,{clearable:!0,data:y,description:"(Optional) Select a property key to use as item's icon src.",disabled:c.isPrimitiveType,label:jsx(It,{label:"Icon property key"}),onChange:I=>S("iconKey",I,!0),value:us(y)&&c.iconKey}),jsx(Select,{clearable:!0,data:y,description:"(Optional) Select a property key to extend the search functionality. The selected key MUST only contain text elements.",disabled:c.isPrimitiveType,label:jsx(It,{label:"Search index key"}),onChange:I=>S("searchIndexKey",I,!0),value:us(y)&&c.searchIndexKey}),jsx(TextInput,{description:'(Optional) Provide a search index separator in case each row contains more than one record. Default: "|".',disabled:!c.searchIndexKey,error:c.searchIndexSeparator===""?"Separator cannot be empty!":"",label:jsx(It,{label:"Search index separator"}),onChange:I=>S("searchIndexSeparator",I.currentTarget.value),value:c.searchIndexSeparator})]})})]})})]}),jsx(Checkbox,{my:"md",label:jsx(It,{label:"Reset SectionVariables on change",py:0}),checked:c.resetSectionVars==="true",onChange:I=>S("resetSectionVars",I.currentTarget.checked?"true":"false")}),t]})}var Hj={[k.SELECTOR]:vE,[k.NAV]:lh,[k.RELATED]:ch,[k.RESET_BUTTON]:ph,[k.COMPARISON_BUTTON]:fh,[k.TITLE]:mh,[k.STAT]:gh,[k.TABLE]:xh,[k.MULTIHIERARCHY_SELECTOR]:kh},VE=Hj;function jj(e){let{blockType:t,id:o,locale:r,setBlockContent:n,simpleState:i}=e,a=Lr(),s=je(o),l=VE[t],u=jsx(fE,{fields:pr[t],locale:r,defaultContent:i,variables:s,onChange:n},"text-editor");return l?jsx(l,{id:o,executeButton:a.executeButton,onChange:(c,p,m=!0)=>n({simple:c,logic:p},r,!0,m),simpleState:i,richTextEditor:u,variables:s,referenceContent:a.reference.content,referenceLocale:a.reference.locale}):u}var $E=jj;d();Ba();ge();ie();he();Lt();gm();function tW({id:e,variables:t,reserved:o,hasInternalKeys:r}){let[n,i]=useState(!1);return jsxs(Fragment,{children:[r&&jsx(Switch,{label:"Show internal variables",size:"xs",checked:n,onChange:a=>i(a.currentTarget.checked)}),jsx(tr,{id:e,variables:t,reserved:o,showInternal:n})]})}function oW({id:e,setInlineId:t}){let o=$(l=>l.records.entities.block),r=ne(),n=av(e),i=Object.keys(n.attributes),a=useContext(_e),s=l=>{r(Q.updateEntity("block",{id:e,inputAction:{operation:"delete",input:{input_id:l,block_id:e}}})).then(()=>{r(Q.recalculateVariables(a));});};return jsx("div",{style:{display:"flex",flex:"1 1 auto",flexDirection:"column",width:"100%"},children:Object.keys(n).sort(l=>l==="attributes"?-1:1).map(l=>{let u=o[l],c=u&&[k.GENERATOR,k.SECTION_FLAG].includes(u.type),p=u?.type&&u?.id?`${u.type}${u.id}`:"",m=Object.keys(n[l]).some(Yc(p));return jsxs(Stack,{className:"cr-variable-group",style:{position:"relative"},children:[jsx(Divider,{}),jsxs(Group,{position:"apart",noWrap:!0,grow:!0,children:[jsx(Title,{order:6,children:u?`${titleCase(u.type)} ${u.id} Variables`:"Dimension Variables"}),u&&jsxs(Group,{position:"right",noWrap:!0,children:[c&&jsx(Tooltip,{label:"Edit this generator",children:jsx(ActionIcon,{size:"xs",onClick:()=>t(l),variant:"subtle",color:"gray",children:jsx(IconPencil,{size:15})})}),jsx(Tooltip,{label:"Remove as input",children:jsx(ActionIcon,{size:"xs",onClick:()=>s(l),variant:"light",color:"red",children:jsx(IconLinkOff,{size:15})})})]})]}),jsx(tW,{id:l,variables:n[l],reserved:i,hasInternalKeys:m})]},l)})})}var jE=oW;nl();fr();he();function bW({blockType:e,fullscreen:t,toggle:o,codeEditor:r}){let n=Lr(),i=[k.GENERATOR,k.VIZ].includes(e);return jsxs(Fragment,{children:[jsxs(Alert,{p:"xs",mb:"xs",icon:jsx(IconInfoCircle,{}),color:"gray",children:["You can access ",jsx(Code,{children:"variables"}),", ",jsx(Code,{children:"formatters"}),",",jsx(Code,{children:"locale"}),", ",jsx(Code,{children:"libs"}),",",e===k.GENERATOR&&jsxs(Fragment,{children:[jsx(Code,{children:"resp"}),", "]}),e===k.VIZ&&jsxs(Fragment,{children:[jsx(Code,{children:"section"}),", "]}),"and ",jsx(Code,{children:"router"})," in the scope of this generator.",i&&jsxs(Fragment,{children:[" Return a property called",jsx(Code,{children:"_api"})," as string, to let the user download that data and override api value."]})]}),r,jsx(Divider,{my:"sm",color:"gray.8"}),jsxs(Group,{px:"xs",h:"fit-content",position:"right",children:[jsx(Button,{variant:"light",color:"grey",size:"xs",onClick:o,leftIcon:t?jsx(IconMinimize,{size:rem(12)}):jsx(IconMaximize,{size:rem(12)}),compact:!0,children:t?"Minimize":"Maximize"}),n.executeButton]})]})}function yW(){let e=Lr(),t=Sa(),o=xa(),r=t!==o;return jsx(Group,{position:"right",my:"xs",children:jsxs(Stack,{align:"flex-end",spacing:"xs",children:[jsx(Switch,{label:e.mode==="simple"?"Code":"No Code",size:"xs",labelPosition:"left",checked:e.mode==="code",onChange:n=>e.changeEditorMode(n.currentTarget.checked?"code":"simple"),onLabel:jsx(IconCode,{size:rem(12)}),offLabel:jsx(IconCode,{size:rem(12)})}),e.mode!=="code"&&r&&jsx(Switch,{checked:e.reference.active,onChange:n=>e.reference.setActive(n.currentTarget.checked),size:"xs",label:"See reference language",labelPosition:"left",onLabel:jsx(IconLanguage,{size:"0.7rem"}),offLabel:jsx(IconLanguage,{size:"0.7rem"})})]})})}function vW({header:e,blockContent:t,blockSettings:o,blockType:r,id:n,locale:i,onSave:a,setBlockContent:s,setBlockSettings:l,setInlineId:u,sid:c}){let[p,m]=useState("Content"),f=Dc(n),g=Lr(),h=useMemo(()=>{let w=null;return f&&f.resp&&(w=f.resp),w},[f]),b=je(n),{ref:v,toggle:C,fullscreen:R}=useFullscreen(),y=t&&(t.api||t.api==="")?t.api.split(Ur):[],A=(w,O)=>s({logic:w},O),S=(w,O)=>{let _=[...y];_[O]=w,s({api:_.join(Ur)});},E=()=>{s({api:[...y,""].join(Ur)});},L=w=>{s({api:y.length===1&&y[0]===""?null:y.filter((O,_)=>_!==w).join(Ur)});},P=(w,O)=>{l({[w]:O});},D=jsx(ru,{monacoOptions:{onChange:w=>A(w,i),value:t?.logic||"",height:R?"85vh":"61vh",width:"100%"},variables:b},"code-editor"),M=t?.simple||{},z=jsx($E,{blockType:r,id:n,locale:i,simpleState:M,setBlockContent:s,variables:b}),I=jsx(Col,{span:4,sx:w=>({display:"flex",flexDirection:"column",borderLeft:`2px solid ${w.colors.gray[0]}`}),children:jsxs(Stack,{children:[jsx(Text,{inline:!0,size:"xs",transform:"uppercase",weight:"bold",color:"gray",children:"Preview"}),jsx(_u,{id:n,active:!0,blockStateContent:t,blockStateSettings:o,locale:i,allowed:!0,debug:!0},"block-preview")]})});return jsxs(Grid,{h:"100%",children:[jsxs(Col,{span:3,sx:{alignSelf:"stretch",display:"flex",flexDirection:"column",height:"100%",position:"relative"},children:[k.SECTION_FLAG!==r&&jsx(qC,{id:n}),jsx("div",{style:{width:"100%",maxHeight:"80vh",overflowY:"auto"},children:jsx(jE,{id:n,setInlineId:u})}),[k.GENERATOR,k.SECTION_FLAG].includes(r)&&jsxs("div",{children:[jsx(Divider,{label:`${y.length} API's`,labelPosition:"center",mt:"md"}),y.map((w,O)=>jsx(MS,{defaultValue:w,id:n,onChange:_=>S(_,O),onEnterPress:()=>a(!0),onDelete:()=>L(O)},`${n}-${O}-${y.length}`)),jsx(Button,{size:"xs",compact:!0,onClick:E,variant:"light",color:"blue",fullWidth:!0,leftIcon:jsx(IconPlus,{size:15}),my:5,children:"Add API"}),h&&jsxs(Fragment,{children:[jsx(Divider,{label:"Response data preview (resp)",labelPosition:"center",my:"sm"}),jsx("div",{style:{maxHeight:200,overflowY:"scroll"},children:jsx(qc,{value:h,root:!0,label:"resp"})})]})]})]}),jsxs(Col,{span:9,sx:w=>({alignSelf:"stretch",display:"flex",flexDirection:"column",height:"100%",borderLeft:`2px solid ${w.colors.gray[0]}`}),children:[e,jsxs(Tabs,{value:p,onTabChange:m,keepMounted:!1,styles:{root:{flexGrow:1,display:"flex",flexDirection:"column"},panel:{flexGrow:1}},children:[jsxs(Tabs.List,{position:"left",children:[jsx(Tabs.Tab,{value:"Content",icon:jsx(IconPencil,{}),children:"Edit"}),jsx(Tabs.Tab,{value:"Style",icon:jsx(IconPalette,{}),children:"Style"}),jsx(Tabs.Tab,{value:"Settings",icon:jsx(IconSettings,{}),children:"Settings"})]}),jsx(Tabs.Panel,{value:"Content",children:jsx(Box,{ref:v,pos:"relative",bg:"white",h:"100%",children:jsxs(Grid,{className:"cr-block-output",style:{flex:1,width:"100%",height:R?"100vh":"100%",margin:0},children:[jsxs(Col,{span:8,className:`cr-block-output-editor ${g.mode}`,children:[![k.VIZ,k.GENERATOR,k.SECTION_FLAG].includes(r)&&jsx(yW,{}),jsxs(Box,{bg:g.mode==="code"?"#272822":"none",p:"xs",children:[g.mode==="code"&&jsx(bW,{blockType:r,fullscreen:R,toggle:C,codeEditor:D}),g.mode!=="code"&&z]})]},"content-col"),I]})})}),jsx(Tabs.Panel,{value:"Style",pt:"xs",children:jsx(Box,{ref:v,pos:"relative",bg:"white",h:"100%",children:jsxs(Grid,{children:[jsxs(Col,{span:8,children:[jsx(Title,{order:4,children:"Style settings"}),jsx(ou,{id:n,display:"inline",handleChange:P})]},"content-col"),I]})})}),jsx(Tabs.Panel,{value:"Settings",pt:"xs",children:jsx(KC,{id:n,setBlockSettings:l,setBlockContent:s})})]})]})]})}var QE=vW;ko();hr();ge();Lt();d();var ZE=e=>(!e||!e.contentByLocale||Object.keys(e.contentByLocale).forEach(t=>{let o=e.contentByLocale[t]?.content;o&&Object.keys(o).length===0&&(o.simpleEnabled=!0,o.simple={});}),e);var eR=["_icon","_iconType","_iconVariant","_iconSize","_iconRadius","_iconPadding"],tR={[k.SELECTOR]:["hideLabel","resetSectionVars","component","optionsType","type"],[k.TITLE]:[...eR],[k.STAT]:[...eR],[k.TABLE]:["data","tableProps","variable"],[k.MULTIHIERARCHY_SELECTOR]:["colorKey","dataVar","defaultVar","hideLabel","resetSectionVars","iconKey","levelsVar","limit","searchIndexKey","searchIndexSeparator"]},PW=(e,t)=>({...e,[t.locale]:{...t,content:t.content}});function OW({block:e,inline:t,localeDerived:o}){let r=Lr(),n=er(e.section_id).data,i=Vt(n.report_id).data,a=n?.settings.name||`Section ${n?.id}`,s=`${e.type} ${e.id}`,l=i?.name||`Report ${i.id}`;return jsxs(Group,{w:"100%",children:[jsx(Alert,{color:"gray",sx:{flexGrow:1},py:"0.325rem",children:jsxs(Group,{position:"apart",children:[jsxs(Breadcrumbs,{separator:">",children:[jsx(Text,{size:"xs",children:l}),jsx(Text,{size:"xs",children:a}),jsx(Text,{size:"xs",children:s})]}),jsx(Badge,{size:"sm",radius:"sm",rightSection:jsx(Center,{children:o==="logic"?jsx(IconCode,{size:"0.6rem"}):jsx(IconLanguage,{size:"0.6rem"})}),children:o})]})}),jsxs(Group,{children:[r.cancelButton,r.closeAndSaveButton]})]})}function LW({id:e,modified:t,callbacks:o,inline:r}){let n=ne(),i=useContext(_e),{setOpened:a,setModified:s,maybeCloseWithoutSaving:l,setInlineId:u}=o,c=He(e).data,p=$(O=>O.status.currentLocale),m=$(O=>O.status.localeDefault),f=$(O=>O.status.locales),g=Yo(c,p).locale,[h,b]=useState(),[v,C]=useState(!1),[R,y]=useState(!0);if(useEffect(()=>{b(ZE($u(c))),C(!0);},[]),!c||!v||!h)return null;let A=so(h,p),S=h.settings,E=(O={},_=m,H=!0,G=void 0)=>{let{locale:te}=Yo(c,_);if(H&&!t&&s(!0),G!==void 0&&R!==G&&y(G),!O||Object.keys(O).length<1)return;let j=h.contentByLocale[te]||{id:e,locale:te,content:{}};b({...h,contentByLocale:{...h.contentByLocale,[te]:{...j,content:{...j.content,...O}}}});},L=(O,_)=>{if(g!=="logic"&&Object.keys(tR).includes(c.type)){let H={...O},G=O[_].content;return f.forEach(te=>{if(te===g)return;let W={...O[te].content.simple};Object.keys(G.simple).map(V=>{tR[c.type].includes(V)&&(W[V]=G.simple[V]);});let q={...W};if(c.type===k.SELECTOR){let{selectorType:V=Wi.SINGLE,options:K={static:[]},optionsType:Z=_n.STATIC}=O[te].content.simple,{logicOptions:F,defaultValue:J}=cp(V,K,Z);J&&(q.defaultValue=J),q.options=F;}if(c.type===k.MULTIHIERARCHY_SELECTOR){let V=O[te].content.simple,{logicLevels:K,logicOptions:Z,defaultValue:F,defaultValueType:J}=Sp(V);F&&J&&(q.defaultValue=F,q.defaultValueType=J),q.data=Z,q.levels=K;}H[te].content={...H[te].content,simple:W,logic:Ln(q)};}),H}return O},P=()=>{let{settings:O}=h,_=Object.values(h.contentByLocale).reduce(PW,{}),H=["id","api","shared","type"].reduce((te,j)=>({...te,[j]:h[j]}),{}),G=L(_,p);return {...H,id:h.id,contentByLocale:G,settings:O}},D=async O=>{let _=P();n(Q.updateEntity("block",_)).then(()=>{n(uo(i)),s(!1),O||(r?u(null):a(!1));});},M=O=>{t||s(!0),O.type||O.shared!==void 0?b({...h,...O}):b({...h,settings:{...h.settings,...O}});};return jsx(Fragment,{children:jsx(uE,{buttons:{cancelButton:jsx(Button,{leftIcon:jsx(IconCircleX,{size:"0.8rem"}),size:"xs",variant:"outline",onClick:l,color:"red",children:"Cancel"},"cancel"),closeAndSaveButton:jsx(Button,{leftIcon:jsx(IconDeviceFloppy,{size:"0.8rem"}),size:"xs",disabled:!R,onClick:()=>D(!1),children:`Save & ${r?"Return":"Close"}`},"save"),executeButton:jsx(Button,{disabled:!R,onClick:()=>D(!0),size:"xs",compact:!0,children:"Save & Execute"})},blockType:c.type,blockId:c.id,children:jsx(QE,{header:jsx(OW,{inline:r,localeDerived:g,block:c}),blockContent:A,blockSettings:S,blockType:c.type,id:e,sid:c.section_id,locale:p,onSave:D,setBlockContent:E,setBlockSettings:M,setInlineId:u},"be")})})}var oR=LW;Lt();ie();he();hr();Pu();ge();Ko();function KW({id:e,setHoverBlock:t,isInput:o,isConsumer:r,active:n,showOutline:i=!0}){let[a,s]=useState(!1),{newConfirmation:l}=Pt(),[u,c]=useState(!1),[p,m]=useState(!1),[f,g]=useState(null),h=useContext(_e),b=useMantineTheme(),v=je(e),C=Dc(e),R=useCallback(()=>{c(!1),m(!1),g(null);},[]),y=useDispatch(),A=$(q=>q.status.currentLocale),{data:S}=He(e),E=$(q=>q.records.entities.block),{isFetching:L}=Us("block",e),{allowed:P,allowedMessage:D}=useMemo(()=>{let q=!C?.hiddenByCascade,V="";return S&&(V=C?.hiddenByCascade===e?`Hidden by ${S.settings.allowed}: ${S.settings.allowed?v[S.settings.allowed]:null}`:`Hidden by ${C?.hiddenByCascade}`),{allowed:q,allowedMessage:V}},[v,C,S,e]);if(!S)return null;let{blockcol:M,type:z,section_id:I,contentByLocale:w,settings:O,inputs:_}=S,H=async()=>{if(p)try{await l({title:"Are you sure?",message:"Close editor without saving?",confirmText:"Yes, abandon changes."}),R();}catch{}else R();},G={centered:!0,withCloseButton:!1,opened:u,onClose:H,overflow:"inside",padding:b.spacing.sm,size:"95%",styles:{body:{height:"100%"}}},te={onMouseEnter:()=>t(e),onMouseLeave:()=>t(!1)},j={setOpened:c,setModified:m,setInlineId:g,maybeCloseWithoutSaving:H},W=()=>{let q=Object.keys(E).filter(Z=>E[Z].section_id===S.section_id&&E[Z].blockcol===S.blockcol).map(Z=>E[Z].blockrow),V=ea(q),K={create:{blockrow:Rs(V),blockcol:M,locales:Object.keys(w).map(Z=>Z),section_id:I,type:z},update:{contentByLocale:w,settings:O,inputs:_.map(Z=>E[Z])}};y(Q.cloneEntity("block",K)).then(()=>{[k.GENERATOR,k.SECTION_FLAG].includes(S.type)&&y(uo(h,{sid:I}));});};return jsxs(Fragment,{children:[jsxs(Group,{id:`block-${e}`,onMouseOver:()=>s(!0),onMouseOut:()=>s(!1),className:"cr-section-block",pos:"relative",py:On.block.padding,...te,sx:q=>({border:"1px solid transparent",resize:"horizontal","&:hover":{border:i?`1px solid ${q.colors.blue[2]}`:"1px solid transparent"},...i?{"&:hover::before":{position:"absolute",top:0,left:0,fontSize:8,color:q.colors.blue[5],transform:"translateY(-100%)",content:`"Block ${e}"`,width:"fit-content"}}:{}}),children:[jsx(_u,{style:{color:"red"},id:e,debug:[k.VIZ,k.GENERATOR,k.SECTION_FLAG].includes(S.type),active:n,locale:A,allowed:P,isFetching:L},"bp"),(a||o||r)&&jsxs(Group,{spacing:0,className:"cr-block-controls export-hidden",style:{position:"absolute",right:px(b.spacing.xs)/2,top:px(b.spacing.xs)/2,backgroundColor:b.colors.gray[2],borderRadius:b.radius.sm,zIndex:5},children:[o||r?jsx(ActionIcon,{children:o?jsx(IconLogout,{size:20,color:b.colors.red[5]}):jsx(IconLogin,{size:20,color:b.colors.green[5]})},"globe"):null,S.shared&&jsx(Tooltip,{withArrow:!0,label:"Sharing: Enabled",children:jsx(ActionIcon,{variant:"transparent",children:jsx(IconWorld,{size:20})},"globe")},"tt"),"access"in S.settings&&!["public","guest"].some(q=>!S.settings.access||S.settings.access.includes(q))&&jsx(Tooltip,{withArrow:!0,label:"Private Block",children:jsx(ActionIcon,{variant:"transparent",children:jsx(IconLock,{size:20})},"lock")},"tt"),!P&&jsx(Tooltip,{withArrow:!0,label:D,children:jsx(ActionIcon,{variant:"transparent",children:jsx(IconEyeOff,{size:20})})},"allowed"),![k.GENERATOR,k.SECTION_FLAG].includes(S.type)&&jsx(ou,{id:e,display:"button"},"design"),jsx(ActionIcon,{onClick:()=>c(!0),children:jsx(IconPencil,{size:20})},"edit"),![k.SECTION_FLAG].includes(S.type)&&jsx(ActionIcon,{onClick:W,children:jsx(IconCopy,{size:20})},"copy"),jsx(vS,{type:Fr.BLOCK,id:e},"cog")]},"bc")]},"block"),jsx(Modal,{fullScreen:!0,...G,children:jsx(oR,{callbacks:j,id:f||e,inline:f,modified:p},f||e)},"d")]})}var ds=KW;Ko();Pu();ie();ko();d();d();he();ie();var aR=({id:e,disabled:t=!1})=>{let{sectionVariables:o,resetSectionVariables:r}=Ze(e);return !Object.keys(o).length?null:jsx(ActionIcon,{disabled:t,onClick:r,variant:"filled",size:"xs",children:jsx(IconRefresh,{size:20})})},e2=({sectionId:e,onActivate:t})=>{let{activeEntity:o}=Ot(),{handlers:r}=to("settings");return o.type==="section"&&o.id===e?jsx(Button,{size:"xs",radius:"xl",leftIcon:jsx(IconPencil,{size:14}),fw:400,onClick:r.open,compact:!0,children:"Edit"}):jsx(ActionIcon,{variant:"transparent",onClick:()=>{t(),r.open();},children:jsx(IconPencil,{size:18})})};function t2({sectionId:e,onActivate:t}){let o=useDispatch(),r=er(e),{data:n}=r,i=$(a=>a.records.entities.block);return n?jsxs(Group,{spacing:2,children:[jsx(e2,{sectionId:e,onActivate:t}),jsx(ActionIcon,{variant:"transparent",onClick:()=>{let a=o2(n,i);o(Q.cloneEntity("section",a));},children:jsx(IconCopy,{size:18})}),jsx(yr,{type:"section",id:e})]}):null}function o2(e,t){let{heading:o,report_id:r,ordering:n,settings:i}=e,a=[];return {create:{ordering:n,report_id:r},update:{settings:i,heading:o,report_id:r,blocks:e?.blocks.map(l=>{let u=t[l],{blockcol:c,blockrow:p,contentByLocale:m,type:f,settings:g,section_id:h,shared:b,inputs:v,consumers:C}=u;return {blockcol:c,blockrow:p,contentByLocale:m,id:l,type:f,settings:g,section_id:h,shared:b,inputs:v.map(R=>{let y=t[R],{id:A,section_id:S,blockcol:E,blockrow:L,contentByLocale:P,settings:D,shared:M,type:z}=y;return {id:A,section_id:S,blockcol:E,blockrow:L,contentByLocale:P,settings:D,shared:M,type:z}}),consumers:C.reduce((R,y)=>{let A=t[y];if(A){let{id:S,section_id:E,blockcol:L,blockrow:P,contentByLocale:D,settings:M,shared:z,type:I}=A;return [...R,{id:S,section_id:E,blockcol:L,blockrow:P,contentByLocale:D,settings:M,shared:z,type:I}]}return R},a)}})}}}var sR=t2;ie();ge();ko();Rf();function lR({active:e,isDragging:t,id:o,dragHandleProps:r,hidden:n="",onActivate:i,sectionSettings:a}){let s=$(c=>c.records.entities.section[o]||null);if(!s)return null;let l=s&&s.settings?.name?.length?s.settings.name:`section-${s.id}`,u=n!=="";return jsxs(Group,{className:`cms-section-header${e||t?" active":""}`,position:"apart",bg:u?"red.1":"gray.3",sx:{overflow:"hidden",borderRadius:4},children:[jsx(Group,{className:"cms-section-header-editor",spacing:0,children:jsxs(Group,{spacing:0,children:[jsx(ActionIcon,{variant:"transparent",...r,w:16,sx:{cursor:"grab"},children:jsx(IconGripHorizontal,{size:16})},"b1"),jsxs(Text,{size:"xs",fw:400,color:"dark.9",children:[l,u&&` ${n}`]})]})}),jsxs(Group,{children:[jsxs(Flex,{justify:"flex-end",mx:16,align:"center",gap:"xs",children:[jsx(aR,{id:s.id,disabled:!e}),a.optionsMenu&&jsx(Ef,{sectionId:s.id,disabled:!e})]}),jsx(sR,{sectionId:o,onActivate:i})]})]})}hf();ge();nl();Pf();bl();he();Pi();ua();fr();var x2=Object.values(k),fR=({columns:e,columnIndex:t,section:o})=>{let r=ne(),{settings:n}=Au(o.report_id),[i,a]=useDisclosure(!1),s=(u,c=!1)=>{let p=Yn,m=Yn;typeof c=="string"?(m=c,p=ea(Object.keys(e[c]),!0)):Object.keys(e).length>0&&(m=ea(Object.keys(e),!0));let{locales:f}=Yo({type:u});r(Q.createEntity("block",{blockrow:p,blockcol:m,type:u,section_id:o.id,locales:f}));},l=x2.filter(u=>![k.GENERATOR,k.SECTION_FLAG].includes(u)&&(n.comparison?!0:u!==k.COMPARISON_BUTTON)).map(u=>{let c=rg(u);return {label:jsx(UnstyledButton,{p:"xs",w:"100%",onClick:()=>{s(u,t),a.close();},sx:{":hover":{backgroundColor:"#EBEBEB"}},children:jsxs(Group,{spacing:"xs",children:[jsx(ThemeIcon,{color:"blue",variant:"filled",size:"sm",radius:"xl",children:jsx(c,{size:"0.8rem"})}),jsx(Text,{size:"xs",children:ag(u)||u})]})}),value:u}});return jsx(Center,{w:"100%",py:"sm",children:jsxs(Popover,{position:"right",withinPortal:!0,zIndex:100,opened:i,onClose:a.close,children:[jsx(Popover.Target,{children:jsx(ActionIcon,{size:"lg",radius:"xl",variant:"light",bg:"#E5E5E5 !important",onClick:a.toggle,children:jsx(IconPlus,{size:24,color:"white",strokeWidth:1})})}),jsxs(Popover.Dropdown,{p:0,children:[jsx(Text,{bg:"#E5E5E5",size:"xs",p:"xs",children:"Add Block"}),jsx(ScrollArea,{h:230,children:jsx(List,{listStyleType:"none",styles:{itemWrapper:{width:"100%"}},children:l.map(({label:u,value:c})=>jsx(List.Item,{w:"100%",children:u},c))})})]})]})})},T2=({columns:e,section:t,show:o=!1})=>o?jsx(Center,{w:"100%",children:jsxs("div",{children:[jsx(Text,{ta:"center",fw:700,size:"sm",color:"gray.8",children:"Add your first block!"}),jsx(fR,{columnIndex:!1,columns:e,section:t})]})}):null,C2=({active:e=!1})=>jsx(Droppable,{droppableId:"newColumn",children:(t,o)=>jsx(Center,{ref:t.innerRef,pos:"absolute",top:16,right:e?0:-140,bottom:16,w:140,sx:r=>({boxSizing:"border-box",zIndex:99,transition:"right 0.4s",overflow:"hidden",background:o.isDraggingOver?r.colors[r.primaryColor][0]:r.colors.gray[0]}),...t.droppableProps,children:jsxs(Stack,{p:"md",align:"center",children:[jsx(Text,{size:"xs",ta:"center",children:"Drop here to add new column"}),jsx(IconPlus,{})]})})}),k2=({onActivate:e,section:t,show:o=!1})=>o?jsx(Overlay,{className:"cms-section-overlay",onClick:()=>e(t.id),opacity:.6,color:"#E9ECEF",style:{cursor:"pointer",zIndex:3},sx:r=>({transition:"background-color .45s",".bespoke-Section-edit":{opacity:0,transition:"opacity .45s"},"&:hover":{backgroundColor:r.fn.rgba("#E9ECEF",.9),".bespoke-Section-edit":{opacity:1}}}),center:!0,children:jsxs(Group,{className:"bespoke-Section-edit",align:"center",spacing:"xs",children:[jsx(Text,{fw:700,children:"Click to Edit"}),jsx(IconPencil,{size:"1rem"})]})}):null;function E2({for:e,isDragging:t,onActivate:o,dragHandleProps:r}){let n=ne(),{activeEntity:i}=Ot(),[a,s]=useState(!1),[l,u]=useState(),c=useRef(null),p=$(I=>I.records.entities.block),m=$(I=>I.status.previews),f=Us("section",e.id),{memberImageBg:g,hidden:h,columnSettings:b={}}=e.settings,v=i.type==="section"&&i.id===e.id,{inputs:C,consumers:R}=useMemo(()=>{if(l){let I=p[l],{inputs:w,consumers:O}=I;return {inputs:w,consumers:O}}return {inputs:[],consumers:[]}},[l]),y=Object.values(p||{}).filter(I=>I.section_id===e.id&&![k.GENERATOR,k.SECTION_FLAG].includes(I.type)).reduce((I,w)=>(I[w.blockcol]?I[w.blockcol][w.blockrow]=w:I[w.blockcol]={[w.blockrow]:w},I),{}),A=useMantineTheme(),S=()=>s(!0),E=I=>{if(s(!1),!I.destination)return;let{source:w,destination:O}=I;if(w.droppableId===O.droppableId&&w.index===O.index)return;let _=O.droppableId==="newColumn",H=Number(I.draggableId),G=w.droppableId,te=_?ea(Object.keys(y),!0):O.droppableId,j={id:H,blockrow:Yn,blockcol:Yn},W=G!==te;j.blockcol=W?te:G;let q=Object.values(y[j.blockcol]||{}),V=q.reduce((F,J)=>({...F,[J.id]:J}),{}),K=q.sort((F,J)=>eo(F,J,"blockrow")).map(F=>F.id),Z=O.index>w.index;j.blockrow=Jn(V,K,O.index,W,Z,"blockrow"),n(Q.updateEntity("block",j));},L=useMemo(()=>{let I=Object.values(p||{}).filter(w=>w.section_id===e.id&&Jo(w));return I.length>1&&console.error(`Error, there are more than one Section Flag Generator in section ${e.id}`),I.length>0?I[0]:!1},[p,v,e.id]),P=$(I=>L&&I.variables.variables[L.id]&&!I.variables.variables[L.id][Eo]||!1),D=useMemo(()=>{let I="";return P&&L&&(I+=`(Not allowed by Section Flag #${L.id})`),h&&(I+="(Hidden by Section Settings)"),I},[h,P]),M=Object.keys(y).sort((I,w)=>-ws(I,w)),z=Object.keys(y).length;return f.isFetching?jsxs(Box,{p:"lg",m:"lg",bg:On.section.backgroundColor,sx:I=>({borderRadius:I.radius.md,border:`1px solid ${I.colors.gray[4]}`}),children:[jsx(Skeleton,{height:50,circle:!0,mb:"xl"}),jsx(Skeleton,{height:8,radius:"xl"}),jsx(Skeleton,{height:8,mt:6,radius:"xl"}),jsx(Skeleton,{height:8,mt:6,width:"70%",radius:"xl"})]}):jsxs(Box,{px:"md",mt:"md",children:[jsx(lR,{active:v,id:e.id,isDragging:t,hidden:D,dragHandleProps:r,onActivate:()=>o(e.id),sectionSettings:e.settings}),jsxs(Box,{pos:"relative",sx:I=>({border:v?`1px solid ${I.colors.blue[4]}`:"none",borderRadius:2}),children:[jsx(Paper,{id:`section-${e.id}`,className:`cms-section${t||v?" active":""}`,bg:e.settings.style==="card"?On.section.backgroundColor:"transparent",p:0,mih:100,maw:e.settings.width==="center"?A.breakpoints.xl:"none",w:"100%",mx:"auto",pos:"relative",shadow:e.settings.style==="card"?On.section.boxShadow:"none",radius:On.section.borderRadius,sx:{overflow:"hidden"},children:jsxs(Box,{pos:"relative",children:[g&&jsx(gf,{previews:m}),jsx(Af,{ref:c,containerProps:{mih:!v||!z?120:"none",p:e.settings.margin||"md",style:{zIndex:2},gap:e.settings.columnGutter||"md",wrap:"wrap"},children:jsxs(DragDropContext,{onDragEnd:E,onDragStart:S,children:[M.map(I=>{let w=Object.values(y[I]).sort((O,_)=>eo(O,_,"blockrow"));return jsx(Droppable,{droppableId:I,children:(O,_)=>jsxs(If,{column:y[I],columnSettings:b[I],ref:O.innerRef,basis:`calc(${100/z}% - (10px * ${z}))`,sx:{background:_.isDraggingOver?A.colors[A.primaryColor][0]:"inherit",border:"1px solid transparent","& .bespoke-resize-col":{visibility:"hidden"},"&:hover .bespoke-resize-col":{visibility:"visible"},"&:hover":{border:`1px solid ${A.colors.teal[1]}`}},...O.droppableProps,children:[jsx(eC,{sectionId:e.id,columnIndex:I}),w.map((H,G)=>{if(!p[H.id])return null;let{settings:te,type:j}=p[H.id],W=te.width&&!te.width.stretch&&te.width.unit?rl[te.width.unit](te.width.value):te.display==="inline"?"auto":"100%",q={alignSelf:j===k.VIZ?"stretch":"flex-start",flexGrow:0,margin:"0",width:W,minWidth:120};return jsx(Draggable,{draggableId:String(H.id),index:G,children:(V,K)=>jsx(Box,{ref:V.innerRef,...V.draggableProps,...V.dragHandleProps,sx:[q,{boxShadow:K.isDragging?A.shadows.lg:"none",...V.draggableProps.style}],children:jsx(ds,{id:Number(H.id),active:v,isInput:C.includes(Number(H.id)),isConsumer:R.includes(Number(H.id)),setHoverBlock:u},`block-${H.id}`)})},H.id)}),v&&jsx(fR,{section:e,columnIndex:I,columns:y}),O.placeholder]})},I)}),jsx(C2,{active:a&&v})]})}),jsx(T2,{columns:y,section:e,show:v&&!z})]})}),jsx(k2,{onActivate:o,section:e,show:!v})]})]})}var gR=oo(E2,er);Lt();Ko();ie();hr();jr();d();d();Ko();Ko();ie();d();ge();ie();ng();Pi();ua();fr();function hR(e,t,o){let r=document.getElementById(`${t}-${o}`),n=55;if(r){let a=r.getBoundingClientRect().top+e.current.scrollTop-n;e.current.scrollTo({top:a,behavior:"smooth"});}}function N2({section:e,onEnd:t}){let[o,r]=useState(e.settings?.name?.length?e.settings.name:`section-${e.id}`),n=a=>{[13,27].includes(a.keyCode)&&t(o);},i=useClickOutside(()=>t(o));return useEffect(()=>{setTimeout(()=>{i?.current&&i?.current?.focus();},200);},[i]),jsx(Input,{ref:i,bg:"gray.3",styles:{input:{display:"block",height:"100%",minHeight:"auto",lineHeight:"1rem",padding:0,boxSizing:"border-box"}},mih:"auto",type:"text",variant:"unstyled",value:o,onChange:a=>r(a.target.value),onKeyDown:n})}var z2=forwardRef(function({scrollContainer:t,section:o,isActive:r,...n},i){let a=$(S=>S?.records.entities.block),{settings:s,updateSettings:l}=Zr(o.id),u=useMantineTheme(),[c,p]=useState(!1),[m,f]=useState(!1),g=$(S=>{let E=o.blocks.map(L=>S.records.entities.block[L]).filter(L=>Jo(L));return E.length>0?S.variables.variables[E[0].id]:!1}),h=g?u.colors[g[Eo]===!1?"red":"green"][3]:"",b=useCallback(S=>{l("name",S),f(!1);},[l]),v=useRef(!1);useEffect(()=>{p(!!r);},[r]);let C=s?.name||`section-${o.id}`,R=S=>{S.detail===1&&(v.current=!1,setTimeout(()=>{v.current||hR(t,"section",o.id);},200)),S.detail===2&&(v.current=!0,f(E=>!E));},y=r?u.colors.blue[5]:"black",A=o?.blocks.map(S=>a[S]).filter(S=>![k.GENERATOR,k.SECTION_FLAG].includes(S.type)).map(S=>{let E=og[S.type]||IconDice;return jsx(List.Item,{pl:"lg",sx:{border:"1px solid transparent","&:hover":{border:"1px solid blue",cursor:"default"}},icon:jsx(E,{size:"0.8rem"}),onClick:()=>hR(t,"block",S.id),children:jsx(Text,{size:"sm",children:`${S.type} ${S.id}`})},S.id)});return jsxs(List.Item,{ref:i,w:"100%",...n,children:[jsxs(Group,{position:"apart",noWrap:!0,px:"sm",bg:r?u.colors.gray[2]:"transparent",sx:S=>({cursor:"default",border:`1px solid ${r?S.colors.gray[2]:"transparent"}`,".section-icon":{color:y},":hover":{border:`1px solid ${S.colors.blue[5]}`}}),children:[jsxs(Group,{spacing:"xs",miw:0,onClick:R,noWrap:!0,children:[jsx(IconBoxMultiple,{className:"section-icon",size:"0.8rem",style:{flexShrink:0}}),m?jsx(N2,{section:o,onEnd:b}):jsxs(Group,{spacing:4,align:"flex-end",children:[jsxs(Text,{size:"sm",fw:500,color:"gray.5",span:!0,children:[o.id," -"]}),jsx(Text,{size:"sm",c:y,maw:220,sx:{whiteSpace:"nowrap",textOverflow:"ellipsis",overflow:"hidden"},span:!0,children:C})]})]}),jsxs(Group,{spacing:"xs",children:[o.settings.hidden&&jsx(IconEyeOff,{size:"0.8rem",color:u.colors.red[3]}),g&&jsx(IconFlag,{size:"0.8rem",color:h,fill:h}),A.length&&jsx(IconChevronDown,{size:"0.8rem",style:{transform:`rotate(${c?-180:0}deg)`,flexShrink:0},onClick:()=>p(S=>!S)})]})]}),c&&A.length?jsx(List,{listStyleType:"none",children:A}):null]})}),yR=z2;function $h({activeSection:e,scrollContainer:t}){let o=$(s=>s?.records.entities.section),r=ne(),n=Object.values(o).sort(eo),i=n.map(s=>s?.id),a=useCallback(s=>{if(!s.destination||s.source.index===s.destination.index)return;let l=Number.parseInt(s.draggableId,10),u=s.destination.index>s.source.index,c=Jn(o,i,s.destination.index,!1,u),p=i.slice(),m=p.splice(s.source.index,1);p.splice(s.destination.index,0,...m),r(Q.updateEntity("section",{id:l,ordering:c}));},[r,o,i]);return jsxs(ScrollArea.Autosize,{mah:"80vh",pb:"sm",sx:{borderBottom:"1px solid rgba(0, 0, 0, 0.1)"},children:[jsx(Text,{fw:700,size:"sm",px:"sm",children:jsxs(Center,{inline:!0,children:[jsx(IconIndentIncrease,{size:"1rem"}),jsx(Text,{ml:"xs",span:!0,children:"Navigation"})]})}),jsx(DragDropContext,{onDragEnd:a,children:jsx(List,{styles:{itemWrapper:{width:"100%"}},mt:"sm",listStyleType:"none",children:jsx(Droppable,{droppableId:"sections",children:s=>jsx("div",{ref:s.innerRef,...s.droppableProps,children:n.map((l,u)=>jsx(Draggable,{draggableId:`${l?.id}`,index:u,children:c=>jsx(yR,{scrollContainer:t,ref:c.innerRef,section:l,isActive:l.id===e,...c.draggableProps,...c.dragHandleProps})},l?.id))})})})})]})}ie();Ba();d();ie();ko();ge();fr();var Q2=e=>t=>Object.values(t.records.entities.block||{}).filter(o=>o.section_id===e&&k.GENERATOR===o.type);function Uh({activeSection:e}){let t=$(Q2(e)),o=ne(),r=()=>{let{locales:n}=Yo({type:k.GENERATOR});o(Q.createEntity("block",{blockrow:void 0,blockcol:void 0,type:k.GENERATOR,section_id:e,locales:n})).then(i=>{o(Q.updateEntity("block",{id:i.data.id,contentByLocale:{logic:{...i.data.contentByLocale.logic,content:{simpleEnabled:!0,simple:{},logic:ky}}}}));});};return console.log(t),jsx(ScrollArea.Autosize,{mah:"80vh",w:"330px",sx:{borderBottom:"1px solid rgba(0, 0, 0, 0.1)"},children:jsxs(Stack,{pos:"relative",w:330,pr:"md",children:[jsxs(Group,{position:"apart",children:[jsx(Text,{fw:700,children:"Generators"}),jsx(ActionIcon,{c:"black",onClick:r,children:jsx(IconPlus,{})})]}),t.length?t.map(n=>jsx("div",{children:jsx(ds,{id:Number(n.id),active:!!e,isInput:!1,isConsumer:!1,setHoverBlock:()=>{},showOutline:!1})},`block-${n.id}`)):jsx(Text,{align:"center",size:"sm",children:"Click '+' to add a generator"})]})})}he();d();ie();function wR({sectionId:e}){let[t,o]=useState(window.innerWidth-40),[r,n]=useState(window.innerHeight-150);useEffect(()=>{let g=()=>{o(window.innerWidth-40),n(window.innerHeight-120);};return window.addEventListener("resize",g),()=>{window.removeEventListener("resize",g);}},[]);let i=jd(),a=ya(),[s,l]=useState(`${e}`),u=useMemo(()=>a.isSuccess?a.data.map(h=>({value:`${h.id}`,label:h.settings.name?`${h.settings.name} (${h.id})`:`Section ${h.id}`})):[],[a.isLoading]),c=useMemo(()=>{if(i.isSuccess&&s){let g={id:"root",label:"section",size:40,parentIds:[]},h={id:"wide",label:"report",size:40,parentIds:[]},b=i.data.filter(C=>`${C.section_id}`==`${s}`),v=b.map(C=>C.id);return [g,h,...b.map(C=>{let R=C.consumers.length>0?C.consumers.length*20:40,y=C.inputs.length>0?C.inputs.map(A=>v.includes(A)?`${A}`:`${h.id}`):[`${g.id}`];return {id:`${C.id}`,label:`${C.type}`,size:R>50?50:R,parentIds:[...Array.from(new Set(y))]}})]}else return []},[i.isLoading,s]),p=useRef(null);return useEffect(()=>{let g=Pp.dagStratify()(c),h=40,b=Pp.sugiyama().nodeSize(w=>{let O=w?w.data:null,_=O?O.size:h;return [(w?3.6:.25)*_,3*_]}),{width:v,height:C}=b(g),R=Uo.select(p.current);R.selectAll("*").remove(),R.attr("viewBox",[0,0,v,C].join(" "));let y=R.append("defs"),A=g.size(),S=Uo.interpolateRainbow,E=new Map;c.forEach((w,O)=>{E.set(w.id,S(O/A));});let L=Uo.line().curve(Uo.curveCatmullRom).x(w=>w.x).y(w=>w.y);R.append("g").selectAll("g").data(g.links()).enter().append("g").append("path").attr("class","curve").attr("d",({points:w})=>L(w)).attr("fill","none").attr("stroke-width",3).attr("stroke",({source:w,target:O})=>{let _=encodeURIComponent(`${w.data.id}--${O.data.id}`),H=y.append("linearGradient").attr("id",_).attr("gradientUnits","userSpaceOnUse").attr("x1",w.x).attr("x2",O.x).attr("y1",w.y).attr("y2",O.y);return H.append("stop").attr("offset","0%").attr("stop-color",E.get(w.data.id)),H.append("stop").attr("offset","100%").attr("stop-color",E.get(O.data.id)),`url(#${_})`}),R.append("g").selectAll("g").data(g.descendants()).enter().append("g").attr("transform",({x:w,y:O})=>`translate(${w}, ${O})`).append("circle").attr("r",w=>w.data.size).attr("fill",w=>E.get(w.data.id));let M=R.append("g").selectAll("g").data(g.links()).enter().append("g"),z=Uo.symbol().type(Uo.symbolTriangle).size(h*1.5);M.append("path").attr("class","arrow").attr("d",z).attr("transform",w=>{let{points:O,target:_}=w,[H,G]=O.reverse(),te=G.x-H.x,j=G.y-H.y,W=_.data.size*1/Math.sqrt(te*te+j*j),q=Math.atan2(-j,-te)*180/Math.PI+90;return `translate(${H.x+te*W}, ${H.y+j*W}) rotate(${q})`}).attr("fill",({target:w})=>E.get(w.data.id)).attr("stroke","white");let I=R.append("g").selectAll("g").data(g.descendants()).enter().append("g").attr("transform",({x:w,y:O})=>`translate(${w}, ${O})`);I.append("text").text(w=>w.data.id).attr("font-weight","bold").attr("font-family","sans-serif").attr("text-anchor","middle").attr("font-size","10px").style("transform","translate(0px,10px)").attr("alignment-baseline","middle").attr("fill","black"),I.append("text").text(w=>w.data.label).attr("font-weight","bold").attr("font-family","sans-serif").attr("font-size","15px").style("transform","translate(0px,-5px)").attr("text-anchor","middle").attr("alignment-baseline","middle").attr("fill","black");},[c]),jsxs(Stack,{spacing:0,children:[jsxs(Group,{align:"flex-end",w:"100%",position:"apart",children:[jsx(Select,{label:"Choose a section",placeholder:"Pick one",value:s,onChange:l,data:u,width:"80%"}),jsxs(Group,{grow:!0,maw:100,children:[jsx(ActionIcon,{onClick:()=>{let g=u.findIndex(h=>h.value===s);g>0&&l(u[g-1].value);},variant:"outline",children:jsx(IconChevronLeft,{size:"1.125rem"})}),jsx(ActionIcon,{onClick:()=>{let g=u.findIndex(h=>h.value===s);g<u.length-1&&l(u[g+1].value);},variant:"outline",children:jsx(IconChevronRight,{size:"1.125rem"})})]})]}),jsx("svg",{ref:p,width:t,height:r})]})}function IR({name:e,id:t,variables:o}){return jsxs(Flex,{gap:"xs",children:[jsx(ThemeIcon,{bg:"blue.5",color:"white",size:"sm",radius:"xl",sx:{flexGrow:0},children:jsx(IconCodeDots,{size:"0.8rem"})}),jsxs(Stack,{sx:{flexGrow:1},children:[jsx(Text,{size:"sm",children:e}),jsx(tr,{id:t,variables:o})]})]})}function bK({sectionId:e}){let[t,o]=useDisclosure(!1);return jsxs(Fragment,{children:[jsx(Button,{onClick:o.open,variant:"outline",radius:2,leftIcon:jsx(IconBinaryTree,{}),children:"Section Graph"}),jsx(Modal,{opened:t,onClose:o.close,title:"Block Graph",fullScreen:!0,children:jsx(wR,{sectionId:e})})]})}function yK({activeSection:e}){let t=$(i=>i.records.entities.block),o=$(i=>i.variables.attributes),r=$(i=>i.variables.variables),n=Object.values(t).filter(i=>(i.section_id===e||i.shared)&&Object.keys(r[i.id]||{}).length);return jsxs(Box,{px:"sm",w:"100%",children:[jsx(Text,{fw:700,size:"sm",children:jsxs(Center,{inline:!0,children:[jsx(IconCodeDots,{size:"1rem"}),jsx(Text,{ml:"xs",span:!0,children:"Variables"})]})}),jsx(ScrollArea.Autosize,{mah:"40vh",mx:"sm",w:"240px",children:jsxs(Stack,{mt:"sm",children:[jsx(IR,{name:"Report Variables",id:"attributes",variables:o}),n.map(i=>jsx(IR,{id:i.id,name:`${i.type} ${i.id}`,variables:r[i.id]},i.id))]})})]})}function vK(){return jsx(Title,{children:"Formatters"})}var SK={section:[{label:"Navigation",value:"navigation"},{label:"Generators",value:"generators"}],block:[{label:"Navigation",value:"navigation"},{label:"Variables",value:"variables"},{label:"Formatters",value:"formatters"}]};function qh({scrollContainer:e}){let{opened:t,handlers:o}=to("tools"),{toggle:r}=o,[n,i]=useState("navigation"),{activeEntity:a}=Ot(),s=c=>i(c),l=a.type==="section"?a.id:null,u=t&&jsxs(Fragment,{children:[l&&jsx(SegmentedControl,{sx:{flexShrink:0},data:SK.section,value:n,onChange:s}),jsxs(Stack,{sx:{flexGrow:1},spacing:"sm",mt:32,children:[(n==="navigation"||!l)&&jsx($h,{activeSection:l,scrollContainer:e}),n==="generators"&&l&&jsx(Uh,{activeSection:l}),n==="variables"&&jsx(yK,{activeSection:l}),n==="formatters"&&jsx(vK,{})]})]});return jsxs(Flex,{direction:"column",justify:t?"space-between":"flex-end",bg:"white",pb:30,pt:"sm",px:"xs",mah:"100vh",w:t?"350px":"50px",sx:c=>({overflow:"hidden",borderRight:`1px solid ${c.colors.gray[2]}`,flexShrink:0,flexGrow:0}),children:[u,jsxs(Flex,{justify:t?"space-between":"center",px:"sm",children:[a.type==="section"&&t&&jsx(bK,{sectionId:l}),jsx(UnstyledButton,{onClick:r,sx:{transform:`rotate(${t?0:180}deg)`},children:jsx(IconChevronLeft,{size:24})})]})]})}d();d();ie();d();function Dr({target:e,dropdown:t}){let[o,{open:r,close:n}]=useDisclosure(!1),i=useRef(!0),a=()=>{setTimeout(()=>{i.current&&n();},1e3);},s=()=>{i.current=!1;},l=()=>{i.current=!0,n();};return jsxs(Group,{children:[e,jsxs(Popover,{opened:o,trapFocus:!0,children:[jsx(Popover.Target,{children:jsx(ActionIcon,{variant:"subtle",color:"blue",onMouseEnter:r,onMouseLeave:a,children:jsx(IconInfoCircle,{})})}),jsx(Popover.Dropdown,{maw:350,onMouseEnter:s,onMouseLeave:l,children:jsxs(Group,{align:"flex-start",noWrap:!0,children:[jsx("div",{children:jsx(ThemeIcon,{variant:"outline",sx:{border:"none"},children:jsx(IconInfoCircle,{})})}),jsx("div",{children:t})]})})]})]})}Pi();he();ua();ge();ko();fr();hr();Lt();function PK({activeSection:e}){let{settings:t,updateSettings:o}=Zr(e),r=t.name||`section-${e}`,[n,i]=useState(r),[a,s]=useState(!1);return jsx(TextInput,{label:"Section Name",description:"Section name. Only for organization purposes. Won't be displayed on the final report.",value:a?n:r,onChange:l=>i(l.target.value),onFocusCapture:()=>{i(r),s(!0);},onBlurCapture:()=>{o("name",n),s(!1);},withAsterisk:!0,radius:2})}function Qh(){let{activeEntity:e}=Ot(),t=e.id,o=$(v=>t&&v.records.entities.section[t]),r=$(v=>t&&o&&v.records.entities.report[o.report_id]),n=$(v=>{if(t&&o){let C=o.blocks.map(R=>v.records.entities.block[R]).filter(R=>Jo(R));return C.length>1&&console.error(`Error, there is more than one section flag generator in section ${e.id}`),C.length>0?C[0]:!1}return !1}),i=ne(),a=useContext(_e),s=v=>{v==="always"&&n?l(n.id):v==="section-flag"&&u();},l=v=>{i(Q.deleteEntity("block",v)).then(()=>{i(uo(a)),console.log(`Flag generator with ID ${v} deleted.`);});},u=()=>{let{locales:v}=Yo({type:k.SECTION_FLAG});i(Q.createEntity("block",{blockrow:void 0,blockcol:void 0,type:k.SECTION_FLAG,section_id:t,locales:v})).then(C=>{i(Q.updateEntity("block",{id:C.data.id,contentByLocale:{logic:{...C.data.contentByLocale.logic,content:{simpleEnabled:!0,simple:{},logic:`return {
123
123
  ${Eo}: true
124
124
  }`}}}})).then(R=>{i(uo(a)),console.log("DONE!"),console.log(R);});});},c=r?.settings,{settings:p,updateSettings:m}=Zr(t),f=useMemo(()=>[{key:"optionData",label:"Download data (csv, xls, json)"},{key:"optionImage",label:"Save Image"},{key:"optionShare",label:"Share link"}],[]),g=useMemo(()=>f.map(v=>jsxs(List.Item,{children:[v.label,"."]},`item-${v.key}`)),[f]),h=useMemo(()=>[{value:"always",label:"Always"},{value:"section-flag",label:"Use Section Flag"}],[]),b=n?"section-flag":"always";return e.type!=="section"||!e.id?null:jsxs("div",{children:[jsx(PK,{activeSection:t}),jsx(Divider,{my:"sm"}),jsxs(Stack,{mt:"sm",children:[jsxs(Stack,{spacing:"0.4rem",children:[jsx(Dr,{target:jsx(Switch,{radius:"sm",label:"Show export menu.",checked:p.optionsMenu,onChange:v=>m("optionsMenu",v.currentTarget.checked)}),dropdown:jsxs(Box,{children:[jsx(Text,{size:"sm",fw:700,children:"Export Menu"}),jsx(Text,{size:"sm",children:"The Export Menu will allow users to:"}),jsx(List,{withPadding:!0,size:"sm",children:g})]})}),p.optionsMenu&&jsx(Stack,{spacing:"0.5rem",pl:"md",children:f.map(v=>jsx(Switch,{radius:"sm",label:v.label,checked:typeof p[v.key]>"u"?p.optionsMenu:p[v.key],onChange:C=>m(v.key,C.currentTarget.checked)},v.key))})]}),jsx(Dr,{target:jsx(Switch,{radius:"sm",label:"Show section.",checked:!p.hidden,onChange:v=>m("hidden",!v.currentTarget.checked)}),dropdown:jsx(Text,{size:"sm",maw:200,children:"Softly hide or show the section on the rendered report (Still running the queries)"})}),jsx(Dr,{target:jsx(Select,{label:"Allow section",placeholder:"Select an option",description:n?`Controlled by Section Flag #${n.id}`:"Section always visible",value:b,data:h,onChange:s}),dropdown:jsx(Text,{size:"sm",maw:200,children:"You can control section visibility (allow) creating a Section Flag Block"})}),n&&jsx(Stack,{spacing:"xs",children:jsx(ds,{id:Number(n.id),active:!!t,isInput:!1,isConsumer:!1,setHoverBlock:()=>{},showOutline:!1})}),c.comparison&&jsx(Accordion,{children:jsxs(Accordion.Item,{value:"compare",children:[jsx(Accordion.Control,{children:"Compare Settings"}),jsx(Accordion.Panel,{children:jsxs(Stack,{children:[jsx(Switch,{radius:"sm",label:"Hide on comparison.",checked:p.comparisonHide,onChange:v=>m("comparisonHide",v.currentTarget.checked)}),jsx(Switch,{radius:"sm",label:"Show once in comparison",checked:p.comparisonMerge,onChange:v=>m("comparisonMerge",v.currentTarget.checked)})]})})]})})]})]},`settings-${t}`)}d();d();function Zh(e){let{label:t,labelProps:o,...r}=e;return jsxs(Stack,{spacing:"md",children:[jsx(Text,{...o,children:t}),jsx(SegmentedControl,{...r})]})}yl();Pi();he();function tb(){let{activeEntity:e}=Ot(),t=e.id,{settings:o,updateSettings:r}=Zr(t);return e.type!=="section"||!e.id?null:jsxs(Fragment,{children:[jsxs(Stack,{spacing:"md",children:[jsx(Text,{children:"Image"}),jsx(Dr,{target:jsx(Switch,{radius:"sm",label:"Show image background",checked:o.memberImageBg,onChange:n=>r("memberImageBg",n.currentTarget.checked)}),dropdown:jsxs(Box,{maw:300,children:[jsx(Text,{size:"sm",fw:700,children:"Image Background"}),jsxs(Text,{size:"sm",children:["Set up a background image for every profile on the",jsx(Anchor,{href:"/cms/metadata",color:"blue",fw:700,children:" Metadata "}),"tab."]})]})})]}),Object.keys(Ii).map(n=>jsx(Zh,{label:Ii[n].label,data:Ii[n].options,value:String(o[n]||Ii[n].defaultValue),onChange:i=>r(n,i)},n))]})}he();d();he();Pi();bi();function rb(){let e=ro(),t=Number.parseInt(e.params[0]),o=Vt(t).data,{settings:r,updateSettings:n}=Au(t),{handlers:i}=to("reportEditor"),a=o?.dimensions&&o.dimensions.length>0;return jsx(Fragment,{children:jsxs(Stack,{children:[jsx(Button,{variant:"outline",radius:0,onClick:i.open,children:"Edit Report"}),a&&jsx(Accordion,{children:jsxs(Accordion.Item,{value:"comparison",children:[jsx(Accordion.Control,{children:"Profile Comparison"}),jsxs(Accordion.Panel,{children:[jsx(Dr,{target:jsx(Switch,{label:"Enable comparison",checked:!!r.comparison,onChange:s=>n("comparison",s.currentTarget.checked)}),dropdown:jsxs(Fragment,{children:[jsx(Text,{fw:700,children:"Comparisons"}),jsx(Text,{fw:400,children:"This feature will allow user visiting this profile to compare it side by side to another choosen profile"})]})}),r.comparison&&jsx(Dr,{target:jsx(Switch,{label:"With different levels",checked:!!r.compareLevels,onChange:s=>n("compareLevels",s.currentTarget.checked)}),dropdown:jsxs(Fragment,{children:[jsx(Text,{fw:700,children:"Compare with different Levels"}),jsx(Text,{fw:400,children:"Allow users to compare profiles from differet Levels."})]})})]})]})})]})})}var zR={report:[{label:"Settings",value:"settings",component:jsx(rb,{})}],section:[{label:"Style",value:"style",component:jsx(tb,{})},{label:"Settings",value:"settings",component:jsx(Qh,{})}],block:[{label:"Content",value:"content",component:null},{label:"Style",value:"style",component:null},{label:"Settings",value:"settings",component:null}]};function nb(){let{opened:e,handlers:t}=to("settings"),[o,r]=useState("settings"),n=l=>r(l),{activeEntity:i}=Ot();if(!i.type)return null;let a=zR[i.type].find(l=>l.value===o)?.component||null,s=e&&jsx(Fragment,{children:jsxs("div",{children:[i.type==="report"?jsx(Text,{children:"Report Settings"}):jsx(SegmentedControl,{value:o,data:zR[i.type],onChange:n,fullWidth:!0}),jsx(Stack,{sx:{flexGrow:1},spacing:"sm",mt:32,children:a})]})});return jsxs(Flex,{direction:"column",justify:e?"space-between":"flex-end",bg:"white",pt:"sm",pb:30,p:"sm",w:e?"350px !important":"50px",sx:l=>({overflow:"hidden",borderLeft:`1px solid ${l.colors.gray[2]}`,flexShrink:0,flexGrow:0}),children:[s,jsx(Flex,{justify:e?"flex-start":"center",children:jsx(UnstyledButton,{onClick:t.toggle,sx:{transform:`rotate(${e?0:180}deg)`},children:jsx(IconChevronRight,{size:24})})})]})}he();function HR(e){let{id:t}=e,o=Vt(t);return useMemo(()=>o.isError?jsx(Center,{style:{height:300},children:jsx(Alert,{icon:jsx(IconCircleX,{size:20}),title:`Error ${o.error.code}`,color:"red",children:o.error.message})}):o.isUninitialized||!o.data?jsx(Loader,{}):jsx(c5,{report:o.data,locale:e.locale,isLoading:!1}),[o.status,o.data?.sections])}function c5(e){let {report:t,isLoading:o}=e,r=useMantineTheme(),n=ne(),i=useContext(_e),{newConfirmation:a}=Pt(),s=$(S=>S.status.previews),l=$(bv);$(S=>S.status.currentLocale);let {activeEntity:c,selectEntity:p}=Ot(),m=to("tools"),f=to("settings"),g=useMemo(()=>t.sections,[t.sections]),h=useRef(null),b=useCallback(S=>{let E=()=>{p({type:"section",id:S}),n(uo(i,{sid:S}));};s.length<t.dimensions.length?a({title:"You haven't chosen a member!",message:"You may want to choose a member before editing this section.",cancelText:"OK, I'll choose one.",confirmText:"Don't tell me what to do!"}).then(E,()=>{}):E();},[t.dimensions,s]),v=useCallback(S=>{if(!S.destination||S.source.index===S.destination.index)return;let E=Number.parseInt(S.draggableId,10),L=S.destination.index>S.source.index,P=Jn(l,g,S.destination.index,!1,L),D=g.slice(),M=D.splice(S.source.index,1);D.splice(S.destination.index,0,...M),n(Q.updateEntity("section",{id:E,ordering:P})).then(()=>{n(Q.readEntity("report",{id:t.id,include:!0}));});},[l,g]),C=useCallback(S=>jsxs("div",{ref:S.innerRef,className:"cms-droppable-container",...S.droppableProps,children:[g.map((E,L)=>jsx(Draggable,{draggableId:`${E}`,index:L,children:(P,D)=>jsxs("div",{className:`cms-section-container${D.isDragging?" isDragging":""}`,ref:P.innerRef,...P.draggableProps,style:{...P.draggableProps.style,boxShadow:D.isDragging?r.shadows.sm:void 0},children:[jsx(gR,{id:E,isDragging:D.isDragging,onActivate:b,dragHandleProps:P.dragHandleProps}),jsx(Center,{className:"cms-section-controls",m:"md",children:jsx($R,{index:L+1,report:t})})]},`section-${E}`)},E)),S.placeholder]}),[g,c.id,b]),y=!!c.id?50:0,A=50+(m.opened?350:50)+(f.opened?350:y);return jsxs(Box,{children:[jsx(bS,{report:t}),jsxs(Flex,{children:[jsx(qh,{scrollContainer:h}),jsx(Box,{sx:{flexGrow:1},pos:"relative",children:jsx(ScrollArea,{w:`calc(100vw - ${A}px)`,viewportRef:h,h:"calc(100vh - 50px)",styles:{scrollbar:{zIndex:9999}},offsetScrollbars:!0,children:jsxs(Stack,{styles:{backgroundColor:r.colors.gray[2]},spacing:0,children:[jsx(LoadingOverlay,{visible:o}),t.sections.length===0&&jsx(Center,{className:"cms-section-controls",my:"md",children:jsx($R,{index:0,report:t})}),jsx(DragDropContext,{onDragEnd:v,children:jsx(Droppable,{droppableId:"sections",children:C})})]})})}),c.type&&jsx(nb,{})]})]})}function $R({index:e,report:t}){let o=useMantineTheme(),r=ne(),n=$(a=>a.records.entities.section),i=useCallback(()=>{r(Q.createEntity("section",{report_id:t.id,ordering:Jn(n,t.sections,e,!0)}));},[e]);return jsx(ActionIcon,{onClick:i,size:"lg",radius:"xl",variant:"light",bg:"#E5E5E5 !important",style:{boxShadow:o.shadows.xs},children:jsx(IconPlus,{size:24,color:"white",strokeWidth:1})})}d();d();ie();ge();var KR={value:"all",label:"All"},y5=e=>{if(!e)return [];let t=Object.keys(e).map(o=>({value:String(o),label:String(e[o])}));return [KR,...t]};function qR({onChange:e,loading:t,onEditCreation:o}){let r=ne(),[n,i]=useState(""),[a,s]=useState(!1),[l]=useDebouncedValue(n,500),u={type:KR.value},[c,p]=useState(u),m=()=>{i(""),p(u);},f=useMemo(()=>({type:y5(sa)}),[]);useEffect(()=>{e({...c,query:l});},[c.type,l]);let g=()=>{s(!0);let b=Math.random().toString(16).substring(2,10);r(Q.createEntity("formatter",{name:`formatter_${b}`,content:{type:"formatter",logic:"return n;",inputType:"string",testValue:"123456",description:"New formatter"}})).then(v=>{s(!1),m(),v.ok&&o(v.data.id);});},h=useCallback((b,v)=>{let C={...c,[b]:v};p(C);},[c]);return jsxs("div",{children:[jsx(TextInput,{label:"Search by name or description",value:n,onChange:b=>i(b.currentTarget.value),disabled:t}),jsx(Select,{label:"Type",data:f.type,value:c.type,onChange:b=>h("type",b),disabled:t}),jsx(Space,{h:"md"}),jsx(Button,{fullWidth:!0,disabled:t,leftIcon:jsx(IconCircleX,{}),onClick:m,children:"Clear filters"}),jsx(Space,{h:"md"}),jsx(Button,{fullWidth:!0,disabled:t,leftIcon:jsx(IconPlus,{}),onClick:g,variant:"light",loading:a,children:"New formatter"})]})}d();ie();ge();dc();he();var ow=e=>e?Object.keys(e).map(t=>({value:String(t),label:String(e[t])})):[],E5=(e,t)=>{switch(e){case $r.OBJECT:return JSON.parse(t);default:return `${t}`}};function nw({formatterId:e,onEditEnd:t}){let o=$(_=>_.status.localeDefault);$(_=>_.status.locales).map(_=>({value:_,label:`${_.toUpperCase()}`}));let i=!!e,[a,s]=useState(),[l,u]=useState(""),[c,p]=useState([]),[m,f]=useState(!0),[g,h]=useState(!1),[b,v]=useState(!0),[C,R]=useState(!0),[y,A]=useState(!1),S=ne(),E=Wd(e),L=mi(),P=lv(E.data?.name),D=m||g;useEffect(()=>{E.isLoading||s(E.data);},[E.isLoading]),useEffect(()=>{if(!E.isLoading&&!L.isLoading){let _=E.isSuccess?E.data:void 0,H=L.isSuccess?L.data:[];if(_){let G=H.filter(te=>te.id!==_.id).map(te=>te.name);p(G);}w(),f(!1);}},[E.isLoading,L.isLoading]);let M=a&&!c.includes(a.name)&&a.name!=="",z=_=>{M&&R(!1),a&&s({...a,name:Kc(_).replace("-","")});},I=(_,H)=>{_!=="description"&&v(!0),a&&s({...a,content:{...a.content,[_]:H}});},w=()=>{if(a){let _="";try{let H=ta({vars:["n"],logic:a.content.logic},{},o,{}),G=E5(a.content.inputType,a.content.testValue);_=H(G),R(!0);}catch(H){_=`ERROR: ${H.message}`,console.log(H),R(!1);}v(!1),u(`${_}`);}},O=()=>{h(!0),C&&M&&S(Q.updateEntity("formatter",a)).then(t);};return jsx(Drawer,{opened:i,onClose:()=>t(),title:`Edit formatter ID ${e}`,padding:"lg",closeOnClickOutside:!1,closeOnEscape:!1,position:"right",size:"50%",lockScroll:!0,withCloseButton:!1,children:jsx(Ro,{content:jsxs(Fragment,{children:[jsx(LoadingOverlay,{visible:m,overlayBlur:2,overlayOpacity:.5}),y&&jsx(Alert,{title:"Formatter Form",color:"red",children:"Error, please try again."}),a&&!y&&jsxs(Stack,{justify:"space-between",children:[jsxs(Group,{grow:!0,align:"flex-start",children:[jsx(TextInput,{label:`Name ${M&&P>0?`(Read only, used in ${P} blocks)`:""}`,value:a.name,icon:M?jsx(IconCircleCheck,{}):jsx(IconAlertCircle,{}),readOnly:M&&P>0,disabled:M&&P>0,onChange:_=>z(_.target.value),error:M?!1:"Duplicate or empty name, choose a different one."}),jsx(Select,{label:"Type",data:ow(sa),value:a.content.type,onChange:_=>I("type",_)})]}),jsx(Textarea,{label:"Description",value:a.content.description,onChange:_=>I("description",_.target.value)}),jsx(ru,{monacoOptions:{onChange:_=>I("logic",_),height:"30vh",value:a.content.logic}},"formatter-code-editor"),jsxs(Group,{grow:!0,align:"flex-end",children:[jsx(Select,{label:"Input Type",data:ow(yc),value:a.content.inputType,onChange:_=>I("inputType",_)}),jsx(TextInput,{label:"Test Value",value:a.content.testValue,onChange:_=>I("testValue",_.target.value),error:a.content.testValue===""&&!C})]}),jsx(Textarea,{readOnly:!0,icon:C?jsx(IconCircleCheck,{}):jsx(IconAlertCircle,{}),label:"Test Results",value:l,error:l.includes("ERROR")&&!C?"There is a problem in the function, input type or test value. Please check and run again.":!1})]})]}),buttons:jsxs(Fragment,{children:[jsx(Button,{variant:"outline",disabled:D,onClick:()=>t(),children:"Cancel"}),jsx(Button,{onClick:w,disabled:!b,color:b?"blue":C?"green":"red",leftIcon:jsx(IconPlayerPlay,{}),children:"Run Test"}),jsx(Button,{onClick:O,loading:D,disabled:D||!C||b||!M,children:"Save"})]}),size:165})})}d();ie();he();ge();var D5=(e,t)=>{switch(e){case $r.OBJECT:return JSON.parse(t);default:return `${t}`}};function sw({filters:e,onClickEdit:t}){let[o,r]=useState([]),n=mi(),i=n.isSuccess?n.data:[],a=po(),s=cv(),l=useMemo(()=>i.map(p=>{let m=s[p.name]?s[p.name]:0,f="";try{let g=D5(p.content.inputType,p.content.testValue);f=a[p.name](g);}catch(g){f=`ERROR: ${g.message}`,console.log(`Error in ${p.name}`),console.log(g);}return {...p,result:f,usageCount:m}}),[i]),u=()=>{let p=l.filter(m=>{let f=!0,g=!0;return e.query&&(f=m.name.toLowerCase().indexOf(e.query.toLowerCase())>-1||m.content.description.indexOf(e.query)>-1),e.type!=="all"&&(g=m.content.type===e.type),f&&g});r(p);};return useEffect(()=>{u();},[e,l]),jsx(MantineReactTable,{columns:[{header:"ID",accessorKey:"id",minSize:55,size:55,maxSize:55},{header:"Name",accessorKey:"name",Cell:({row:p})=>{let m=p.original.content.type===hc.FORMATTER?jsx(IconVariable,{size:"1.3em"}):jsx(IconMathFunction,{size:"1.3em"});return jsxs(Group,{noWrap:!0,align:"center",spacing:2,children:[jsx("span",{children:p.original.name}),jsx(Tooltip,{label:sa[p.original.content.type],children:jsx("span",{children:m})})]})},minSize:80,size:80},{header:"Description",accessorKey:"content.description",enableSorting:!1,mantineTableBodyCellProps:{sx:{textWrap:"wrap"}},minSize:100},{header:"Demo",accessorKey:"content.testValue",Cell:({row:p})=>{let m=p.original.content.testValue;p.original.content.inputType===$r.STRING&&(m=`"${m}"`);let f=p.original.result;return typeof p.original.result=="string"&&(f=`"${f}"`),jsxs(Group,{spacing:2,children:[jsx(Tooltip,{label:`Input Type: ${yc[p.original.content.inputType]}`,children:jsx(Code,{color:"blue",children:m})}),jsx(IconArrowRightCircle,{}),jsx(Code,{color:p.original.result&&`${p.original.result}`.includes("ERROR")?"red":"teal",children:f})]})},enableSorting:!1,minSize:100,size:100},{header:"Usage",accessorKey:"usageCount",mantineTableHeadCellProps:{align:"right",sx:{"& .mantine-TableHeadCell-Content-Labels":{flexDirection:"row"}}},mantineTableBodyCellProps:{align:"right"},minSize:85,size:85,maxSize:85},{header:"Actions",accessorKey:"actions",Cell:({row:p})=>jsxs(Group,{position:"center",spacing:"xs",noWrap:!0,children:[jsx(ActionIcon,{onClick:()=>t(p.original),children:jsx(IconPencil,{size:20})},"edit"),jsx(yr,{id:p.original.id,type:"formatter",disabled:p.original.usageCount>0,warning:`Delete formatter called "${p.original.name}" (id:${p.original.id}) ? It is not used in any block.`})]}),enableSorting:!1,minSize:80,size:80,maxSize:80,mantineTableHeadCellProps:{align:"center"},mantineTableBodyCellProps:{align:"center"}}],data:o,enableBottomToolbar:!1,enableColumnActions:!1,enableColumnResizing:!0,enablePagination:!1,enableTopToolbar:!1,initialState:{density:"xs"},layoutMode:"grid",mantineTableContainerProps:{sx:{minHeight:150}},mantineTableProps:{striped:!0}})}function cw(){let[e,t]=useState(null),[o,r]=useState(!0),n=l=>{r(l);},i=l=>{t(l);},a=l=>{l&&t(l.id);},s=()=>{t(null);};return jsxs(Container,{fluid:!0,children:[jsxs(Grid,{children:[jsxs(Grid.Col,{span:2,children:[jsx(Text,{ml:"xl",my:"sm",weight:"bold",children:"Formatters"}),jsx(qR,{onChange:n,onEditCreation:i,loading:!1})]}),jsxs(Grid.Col,{span:10,style:{height:"100vh"},children:[jsx(Space,{h:"xs"}),jsx(sw,{filters:o,onClickEdit:a})]})]}),e&&jsx(nw,{formatterId:e,onEditEnd:s})]})}d();br();function pw(){let{user:e}=xt();return jsxs(Flex,{mih:"100vh",gap:"md",justify:"center",align:"center",direction:"column",wrap:"wrap",children:[jsxs(Title,{children:["Hi, ",e?.name||e?.email,"!"]}),jsx(Text,{children:"Welcome to Bespoke CMS. Have fun creating some amazing automated reports here!"})]})}d();d();ie();var yo={value:"all",label:"All"},db=e=>{if(!e)return [];let t=e.map(o=>({value:String(o.id),label:o.name}));return [yo,...t]};function fw({onChange:e,loading:t}){let o=ne(),r=$(v=>Object.values(v.records.entities.report).map(C=>({id:C.id,name:C.name,dimensions:C.dimensions.map(R=>{let y=v.records.entities.dimension[R];return {id:y.id,name:y.name,variants:y.variants.map(A=>{let S=v.records.entities.variant[A];return {id:S.id,name:S.name}})}})}))),n=$(v=>v.status.localeDefault),[i,a]=useState(""),[s,l]=useState(!1),[u]=useDebouncedValue(i,500),c={report:yo.value,dimension:yo.value,variant:yo.value,visible:!1,noImage:!1,limit:"10",paginationVariants:[]},[p,m]=useState(c),f=useMemo(()=>({report:db(r),dimension:db(r.filter(v=>p.report===yo.value||p.report===`${v.id}`).reduce((v,C)=>v.concat(C.dimensions),[])),variant:db(r.filter(v=>p.report===yo.value||p.report===`${v.id}`).reduce((v,C)=>(C.dimensions.filter(R=>p.dimension===yo.value||p.dimension===`${R.id}`).forEach(R=>{v=v.concat(R.variants);}),v),[])),limit:[10,25,50,100].map(v=>({value:String(v),label:String(v)}))}),[r,p]),g=useCallback((v,C)=>{let R={...p,[v]:C};switch(v){case"report":R.dimension=yo.value,R.variant=yo.value;break;case"dimension":R.variant=yo.value;break;}m(R);},[p]),h=()=>{a(""),m(c);},b=()=>{l(!0),o(Q.searchRegenerate()).then(()=>{l(!1),e(p);});};return useEffect(()=>{let v=[];if(p.variant!==yo.value)v=[`${p.variant}`];else if(p.dimension!==yo.value)r.forEach(C=>{let R=C.dimensions.find(y=>`${y.id}`===p.dimension);R&&(v=R.variants.map(y=>`${y.id}`));});else if(p.report!==yo.value){let C=r.find(R=>`${R.id}`===p.report);C&&C.dimensions.forEach(R=>{v=[...v,...R.variants.map(y=>`${y.id}`)];});}e({...p,paginationVariants:v,query:u});},[p.report,p.dimension,p.variant,p.visible,p.limit,p.noImage,u]),jsxs("div",{children:[jsx(TextInput,{label:`Search item by name (${n.toUpperCase()})`,value:i,onChange:v=>a(v.currentTarget.value),disabled:t}),jsx(Select,{label:"Reports",data:f.report,value:p.report,onChange:v=>g("report",v),disabled:t}),jsx(Select,{label:"Dimensions",data:f.dimension,value:p.dimension,onChange:v=>g("dimension",v),disabled:t}),jsx(Select,{label:"Variants",data:f.variant,value:p.variant,onChange:v=>g("variant",v),disabled:t}),jsx(Select,{label:"Rows limit",data:f.limit,value:p.limit,onChange:v=>g("limit",v),disabled:t}),jsx(Space,{h:"md"}),jsx(Checkbox,{label:"Show visible members only",checked:p.visible,onChange:v=>g("visible",v.currentTarget.checked)}),jsx(Space,{h:"md"}),jsx(Checkbox,{label:"Show members with no image",checked:p.noImage,onChange:v=>g("noImage",v.currentTarget.checked)}),jsx(Space,{h:"md"}),jsx(Button,{fullWidth:!0,disabled:t,leftIcon:jsx(IconCircleX,{}),onClick:h,children:"Clear filters"}),jsx(Space,{h:"md"}),jsx(Button,{fullWidth:!0,disabled:t,leftIcon:jsx(IconRefresh,{}),onClick:b,variant:"light",loading:s,children:"Re-Index Search"})]})}d();ie();d();var uq=e=>{let t=process.env.NEXT_PUBLIC_IMAGE_PROVIDERS?process.env.NEXT_PUBLIC_IMAGE_PROVIDERS.split(","):[];return typeof process.env.NEXT_PUBLIC_IMAGE_PROVIDERS>"u"||t.indexOf(e)>-1};function pq({member:e,onEditEnd:t}){let o=e.contentByLocale&&e.contentByLocale[0]?e.contentByLocale[0].name:"",r=useMemo(()=>({upload:{title:"Upload",key:"upload",input:"file",forceSearch:!1,pagination:!1,getAxiosSearchConfig:(I,w,O)=>({})},local:{title:"Gallery",key:"local",input:"text",forceSearch:!0,pagination:!1,getAxiosSearchConfig:(I,w,O)=>({url:"/api/cms/images/search/local",method:"get",params:{prompt:I,page:O}})},flickr:{title:"Flickr",key:"flickr",input:"text",forceSearch:!0,pagination:!0,getAxiosSearchConfig:(I,w,O)=>({url:"/api/cms/images/search/flickr",method:"get",params:{prompt:I,page:O}})},unsplash:{title:"Unsplash",key:"unsplash",input:"text",forceSearch:!0,pagination:!0,getAxiosSearchConfig:(I,w,O)=>({url:"/api/cms/images/search/unsplash",method:"get",params:{prompt:I,page:O}})}}),[]),n=useMemo(()=>Object.values(r).filter(I=>uq(I.key)).map(I=>({value:I.key,label:I.title})),[]),[i,a]=useState(!1),[s,l]=useState(Object.values(r)[0]),[u,c]=useState(500),[p,m]=useState(o),[f,g]=useState(),[h,b]=useState([]),[v,C]=useState(),[R,y]=useState(!1),[A,S]=useState(1),E=async(I=void 0)=>{if(I&&I!==A)S(1);else {y(!1),a(!0);let w=s.getAxiosSearchConfig(p,f,I||A),O=await Cc(w).then(_=>_.data.data&&_.data.data.results?_.data.data.results:[]).catch(_=>{console.error(_),y(!0);});b(O),a(!1);}},L=I=>{C(I);},P=async()=>{a(!0);let I=new FormData;I.append("content_id",e.content_id),v&&f&&(I.append("file",f),delete v.file),v&&(I.append("image_id",v.id),I.append("image_source",v.source)),await Cc({method:"post",url:`/api/cms/images/save/${s.key}`,data:I}).then(w=>{t(!0);}).catch(w=>{console.error(w),y(!0);}),a(!1);},D=I=>{y(!1),l(r[I]),C(void 0),b([]),S(1);};useEffect(()=>{let{innerHeight:I}=window;c(I-280);},[]),useEffect(()=>{!i&&s.forceSearch&&E();},[A,s]);let M=h&&h.length===0&&!i&&s.key!=="upload",z=h&&h.length===0&&!i&&s.key==="upload";return jsx(Drawer,{opened:!0,onClose:t,title:`Image selection for ${o} (${e.id}) `,padding:"lg",closeOnClickOutside:!1,closeOnEscape:!1,position:"left",size:"50%",lockScroll:!0,withCloseButton:!1,children:jsx("div",{style:{height:"100%"},children:jsxs(Stack,{spacing:"sm",children:[jsxs(Stack,{spacing:"xs",children:[jsxs(Group,{position:"apart",grow:!0,align:"flex-end",children:[s.input==="text"&&jsx(TextInput,{placeholder:"Search term",label:"Search term",value:p,onChange:I=>m(I.target.value),onKeyDown:getHotkeyHandler([["Enter",()=>E(1)]])}),s.input==="file"&&jsx(FileInput,{label:"Upload image",placeholder:"Choose an image from your computer (png, jpg, jpeg, webp)",accept:"image/png,image/jpeg,image/jpg,image/webp",value:f,onChange:I=>{if(C(void 0),I){let w=URL.createObjectURL(I);b([{id:"custom",source:w,file:I}]),g(I),C("custom");}},icon:jsx(IconUpload,{size:14})}),s.forceSearch&&jsx(Button,{fullWidth:!0,disabled:i||!p||p==="",onClick:()=>E(1),leftIcon:jsx(IconPlayerPlay,{}),children:"Search"})]}),jsx(SegmentedControl,{disabled:i,value:s.key,onChange:I=>D(I),data:n,fullWidth:!0})]}),jsx(Group,{mt:"xs",grow:!0,children:jsxs(ScrollArea,{offsetScrollbars:!0,type:"always",style:{height:u},children:[jsx(LoadingOverlay,{visible:i,overlayBlur:2,overlayOpacity:.5,overlayColor:"#fff"}),R&&jsx(Alert,{title:`${s.title}`,color:"red",children:"Error, please try again."}),M&&jsx(Alert,{title:`${s.title}`,color:"blue",children:"No results, for try another prompt or provider."}),z&&jsx(Alert,{icon:jsx(IconPhoto,{size:"1rem"}),title:"Welcome to image selector!",color:"blue",children:"Upload an image or select a provider."}),h&&h.length>0&&!i&&jsxs(Fragment,{children:[jsx(SimpleGrid,{cols:3,children:h.map(I=>jsx(Image,{alt:`${s.title}-image-${I.id}`,radius:"md",src:I.source,style:{cursor:"pointer",borderRadius:15,border:v&&v.id===I.id?"5px solid black":""},onClick:()=>L(I)},I.id))}),jsx(Space,{h:"md"}),s.pagination&&jsx(Button,{variant:"outline",fullWidth:!0,onClick:()=>S(A+1),children:"Load more images"})]})]})}),jsxs(Group,{mt:"xs",grow:!0,style:{height:45},children:[jsx(Button,{variant:"outline",disabled:i,onClick:()=>t(!1),children:"Cancel"}),jsx(Button,{onClick:P,loading:i,disabled:i||!v,children:"Save"})]})]})})})}var vw=pq;bf();function Rw({memberId:e,onEditEnd:t}){let o=$(j=>j.status.localeDefault),r=$(j=>j.status.locales),n=r.map(j=>({value:j,label:`${j.toUpperCase()}`})),i=!!e,[a,s]=useState(o),[l,u]=useState(null),[c,p]=useState(!0),[m,f]=useState(!1),[g,h]=useState(!1),[b,v]=useState("member"),[C,R]=useState(!1),[y,A]=useState([]),[S,E]=useState({}),L=useForm(),P=r.reduce((j,W)=>(j[W]=useForm({}),j),{}),D=useForm(),M=r.reduce((j,W)=>(j[W]=useForm({}),j),{}),z=ne(),I=async()=>{p(!0),h(!1);let j=await z(Q.readMember({locale:"all",content_ids:[e],all:!0,mode:"content_ids",output:"full"})).then(W=>{let q;return W.results&&W.results[0]?(h(!1),q=W.results[0]):h(!0),q}).catch(W=>{console.error(W),h(!0);});j&&(u(j),L.setValues(j),j.contentByLocale.forEach(W=>{P[W.locale].setValues({name:W.name,keywords:W.keywords?W.keywords:[],attributes:W.attributes?Object.keys(W.attributes).map(q=>({key:q,value:W.attributes[q]})):[]});}),j.image&&(D.setValues(j.image),j.image.contentByLocale.forEach(W=>{M[W.locale].setValues({meta:W.meta});}))),p(!1);},w=async()=>{if(l&&l.contentByLocale){let j=l.contentByLocale.find(W=>W.locale===a);if(j){R(!0);let W=$c({q:j.name,limit:"10",locale:a,visible:"true",includes:"true",noImage:"false",format:"plain",all:"true"});z(Q.searchMember(W)).then(q=>{if(q&&q.results){let V=q.results.filter(K=>K.content_id!==e);A(V);}R(!1);}).catch(q=>{console.error(q),R(!1);});}}};useEffect(()=>{e?I():u(null);},[e]),useEffect(()=>{l&&w();},[l,a]);let O=async j=>{j&&I(),f(!1);},_=()=>{u({...l,image:null,image_id:null});},H=async()=>{p(!0);let j={...L.values,contentByLocale:l.contentByLocale.map(V=>{let K=P[V.locale]?{...P[V.locale].values}:{};return K.keywords=K.keywords&&K.keywords.length>0?K.keywords:null,{...V,...K}}),image:l.image?{...D.values,contentByLocale:r.map(V=>{let K=l.image.contentByLocale.find(F=>F.locale===V),Z=M[K.locale]?M[K.locale].values:{};return {...K,...Z}})}:null,image_id:l.image_id},W=[Cc.post("/api/cms/update/member",j)],q=Object.keys(S);q.length>0&&q.forEach(V=>{W.push(Cc.post("/api/cms/update/member",{content_id:y[V].content_id,image_id:l.image_id}));}),Promise.all(W).then(()=>{t();}).catch(V=>{console.error(V),h(!0);});},G=Object.keys(P[a].values).length>0,te={state:{rowSelection:S},onRowSelectionChange:E,enableRowSelection:j=>l.image_id&&j.original.image_id!==l.image_id};return jsxs(Fragment,{children:[jsx(Drawer,{opened:i,onClose:()=>t(),title:`Edit member ID ${e}`,padding:"lg",closeOnClickOutside:!1,closeOnEscape:!1,position:"right",size:"50%",lockScroll:!0,withCloseButton:!1,children:jsx(Ro,{content:jsxs(Fragment,{children:[jsx(LoadingOverlay,{visible:c,overlayBlur:2,overlayOpacity:.5}),g&&jsx(Alert,{title:"Member Form",color:"red",children:"Error, please try again."}),l&&!g&&jsxs(Tabs,{defaultValue:"member",value:b,onTabChange:v,children:[jsxs(Tabs.List,{grow:!0,children:[jsx(Tabs.Tab,{value:"member",icon:jsx(IconListCheck,{}),children:"Member"}),jsx(Tabs.Tab,{value:"image",icon:jsx(IconPhoto,{}),children:"Image"})]}),jsx(Tabs.Panel,{value:"member",py:"md",children:jsxs(Stack,{justify:"space-between",children:[jsxs(Group,{position:"apart",grow:!0,children:[jsx(TextInput,{mt:"xs",disabled:!0,label:"Original ID",...L.getInputProps("id")}),jsx(TextInput,{mt:"xs",disabled:!0,label:"Content ID",...L.getInputProps("content_id")})]}),jsxs(Group,{position:"apart",grow:!0,children:[jsx(TextInput,{mt:"xs",icon:"/",disabled:!0,label:"Variant Slug",...L.getInputProps("variant_slug")}),jsx(TextInput,{mt:"xs",icon:"/",disabled:!0,label:"Member Slug",...L.getInputProps("slug")})]}),jsxs(Group,{position:"apart",grow:!0,children:[jsx(TextInput,{mt:"xs",disabled:!0,label:"Report",...L.getInputProps("report_name")}),jsx(TextInput,{mt:"xs",disabled:!0,label:"Dimension",...L.getInputProps("dimension_name")}),jsx(TextInput,{mt:"xs",disabled:!0,label:"Variant",...L.getInputProps("variant_name")})]}),jsxs(Group,{grow:!0,children:[jsxs(Box,{onClick:()=>v("image"),style:{cursor:"pointer"},pos:"relative",children:[jsx(Overlay,{opacity:0,center:!0,sx:{backdropFilter:"none","& button":{display:"none"},"&:hover":{backdropFilter:"blur(0.2375rem)",button:{display:"flex"}}},children:jsx(Button,{size:"xs",radius:"sm",variant:"filled",leftIcon:jsx(IconPhoto,{size:"0.9rem"}),children:"Edit"})}),jsx(Qs,{member:l,forceRefreshTimestamp:!0})]}),jsx(Input.Wrapper,{label:"Search relevance",description:`
125
125
  Relevance index to be used with search. Values from 0 (less relevant) to 1 (more relevant)