@datawheel/bespoke 0.9.11 → 0.9.12-rc.2

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
@@ -1,38 +1,38 @@
1
- import {b,a as a$3}from'./chunk-G6UW4ISL.js';import {g,f as f$1,e as e$2}from'./chunk-A4E2IRNO.js';import {a}from'./chunk-5NVVEPZQ.js';import {a as a$4}from'./chunk-7K6SKRXP.js';import {h,N,J,l,R,c,o,M,G,B as B$1,F,D,E,m,H as H$1,A as A$1,f,O as O$1,Q,a as a$2,P as P$1,p as p$1,C,n,i as i$1,j,k,I as I$1,d as d$1,e as e$1,t,b as b$2,g as g$2}from'./chunk-PGBDZWWY.js';import'./chunk-2D75X364.js';import {i,g as g$1,a as a$5}from'./chunk-JU4YILPF.js';import {cb,Ga as Ga$1,Ha,Fa as Fa$1,z,Ea as Ea$1,va as va$1,W,T,Da as Da$1,ua,ta as ta$1,La as La$1,Oa as Oa$1,Pa as Pa$1,Sa as Sa$1,O,_,I,H,A,_a,B,Ka,ab,b as b$1,c as c$1,db as db$1,Ya,Aa as Aa$1,p,m as m$1,s,P,Q as Q$1,f as f$2,e,Na as Na$1,u,ba,ca,o as o$1,l as l$1,r,Va,d,v,N as N$1,V,Za,$a as $a$1,Ma as Ma$1,C as C$1,ea,eb,fa as fa$1,wa as wa$1,Ba as Ba$1,Ua,D as D$1,E as E$1,F as F$1,G as G$1,Ia as Ia$1,Ta as Ta$1,i as i$2,X,Ca,Ja,j as j$1,Qa as Qa$1,Ra as Ra$1,xa,U,za as za$1,ya as ya$1,a as a$6}from'./chunk-EYRXKCMJ.js';import {a as a$1}from'./chunk-P6ORTCRN.js';import'./chunk-QZ5NBDGE.js';import {Group,Stack,Text,ThemeIcon,useMantineTheme,List,UnstyledButton,Center,createStyles,Image,Checkbox,Input,Card,Space,Badge,Button,Title,Tabs,TextInput,Code,NumberInput,Box,Loader,Divider,SegmentedControl,Select,ActionIcon,Textarea,Accordion,rem,ScrollArea,Tooltip,MultiSelect,Switch,Radio,Skeleton,Paper,Anchor,Avatar,Flex,px,Modal,Popover,Overlay,CopyButton,Col,Grid,Collapse,Alert,Breadcrumbs,Menu,MantineProvider,Navbar,AppShell,Container,LoadingOverlay,Pagination,Drawer,FileInput,SimpleGrid,Header,Autocomplete}from'@mantine/core';import {useListState,useSetState,randomId,useClickOutside,useDisclosure,useFullscreen,useDebouncedValue,getHotkeyHandler,useUncontrolled,useHotkeys,useMergedRef}from'@mantine/hooks';import {notifications,Notifications}from'@mantine/notifications';import {IconCirclePlus,IconCircleCheck,IconLogout,IconBraces,IconGripVertical,IconDice,IconBoxMultiple,IconEyeOff,IconFlag,IconChevronDown,IconBallpen,IconDatabase,IconMathFunction,IconNetwork,IconUsers,IconServer,IconPencil,IconAlertCircle,IconPlayerPlay,IconTrash,IconLanguage,IconCircleX,IconCircleCheckFilled,IconFileAnalytics,IconQuestionMark,IconLanguageOff,IconPhotoFilled,IconFileUpload,IconGripHorizontal,IconLogin,IconWorld,IconLock,IconCopy,IconPlus,IconAlertTriangle,IconCloudNetwork,IconGitMerge,IconClockHour2,IconApi,IconAugmentedReality,IconCheck,IconRefresh,IconDeviceFloppy,IconPalette,IconSettings,IconChevronRight,IconCode,IconBold,IconItalic,IconUnderline,IconArrowBackUp,IconArrowForwardUp,IconAlignLeft,IconAlignCenter,IconAlignRight,IconAlignJustified,IconGlobe,IconLinkOff,IconX,IconHelp,IconMinimize,IconMaximize,IconCircleDashed,IconHome,IconListCheck,IconPhoto,IconPolaroid,IconCircleMinus,IconVariable,IconArrowRightCircle,IconSlash,IconHelpCircle,IconUpload,IconFileCode,IconWorldUpload,IconSettingsFilled,IconChevronLeft,IconIndentIncrease,IconCodeDots,IconBinaryTree}from'@tabler/icons-react';import _D from'next/head';import Vb from'next/link';import lv,{forwardRef,useState,useEffect,useImperativeHandle,createContext,useCallback,useRef,useMemo,Fragment as Fragment$1,useContext}from'react';import {signOut}from'next-auth/react';import {jsxs,jsx,Fragment}from'react/jsx-runtime';import {DragDropContext,Droppable,Draggable}from'@hello-pangea/dnd';import {useDispatch}from'react-redux';import {MantineReactTable}from'mantine-react-table';import jS,{useMonaco}from'@monaco-editor/react';import {titleCase}from'd3plus-text';import {EditorProvider,useCurrentEditor,BubbleMenu,ReactRenderer}from'@tiptap/react';import bw from'@tiptap/extension-underline';import yw from'@tiptap/starter-kit';import vw from'@tiptap/extension-mention';import Sw from'@tiptap/extension-hard-break';import {Plugin,PluginKey,Selection,TextSelection,NodeSelection}from'@tiptap/pm/state';import'@tiptap/pm/view';import'@tiptap/pm/keymap';import {Fragment as Fragment$2,Slice,Schema,DOMParser}from'@tiptap/pm/model';import {canSplit,joinPoint,liftTarget,canJoin,ReplaceStep,ReplaceAroundStep}from'@tiptap/pm/transform';import {wrapIn,setBlockType,selectTextblockStart,selectTextblockEnd,selectParentNode,selectNodeForward,selectNodeBackward,newlineInCode,liftEmptyBlock,lift,joinUp,joinTextblockForward,joinTextblockBackward,joinForward,joinDown,joinBackward,exitCode,deleteSelection,createParagraphNear}from'@tiptap/pm/commands';import {wrapInList,sinkListItem,liftListItem}from'@tiptap/pm/schema-list';import xw from'@tiptap/extension-text-align';import Cw from'@tiptap/extension-placeholder';import Lw from'@tiptap/extension-typography';import Gh from'axios';import*as Ut from'd3';import*as ds from'd3-dag';import {csvParse}from'd3-dsv';import {useForm}from'@mantine/form';function Fp(e){let{onlyIcon:t,href:o,version:n}=e,r=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:true,c:"dimmed",size:"xs",ml:3,children:n})]})]})});return o?jsx(Vb,{href:o,passHref:true,children:jsx(UnstyledButton,{p:10,w:"100%",children:r})}):r}function Dn(e){return jsxs("span",{style:{display:"flex",alignItems:"center",gap:"0.5rem"},children:[e.icon,e.children]})}function _p(e){let{left:t,center:o,right:n}=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:n})]})})}var Yb=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 Lr({value:e,onChange:t,defaultValue:o,selectProps:n={},loading:r=false}){let i=e$1(),s=va$1(c=>c.status.localeDefault),[l,a]=useUncontrolled({value:e,defaultValue:o||s,finalValue:s,onChange:t}),u=useMantineTheme();return jsx(Select,{...n,data:i,value:l,onChange:a,styles:{...Yb(u),...n?.styles},icon:jsx(IconLanguage,{size:"0.8rem",color:u.colors.blue[7]}),rightSection:r?jsx(Loader,{size:"0.8rem"}):jsx(IconChevronDown,{size:"0.8rem",color:u.colors.blue[7]})})}var oy={maxWidth:100,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"};function zr({children:e,tooltip:t=false,onClick:o=()=>{},textProps:n={},clickable:r=false}){return jsx(Tooltip,{label:e,disabled:!t,children:jsx(UnstyledButton,{onClick:o,children:jsxs(Group,{spacing:"3px",align:"center",noWrap:true,children:[jsx(Text,{fz:"0.675rem",tt:"uppercase",fw:700,color:"gray.7",sx:oy,...n,children:e}),r&&jsx(ThemeIcon,{color:"gray.7",size:"1rem",bg:"transparent",variant:"default",sx:{border:"none"},children:jsx(IconChevronDown,{size:"xl"})})]})})})}var Zi=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 my(e,t,o){return o===t?e.map(n=>({id:n.id,value:`${n.id}`,name:n.name})):e.map(n=>{let r=n.contentByLocale.find(i=>i.locale===o);return {id:n.id,value:`${n.id}`,name:n.name,refName:r?r.name:null}})}var $p={overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},gy=forwardRef(function({id:t,name:o,refName:n,...r},i){return jsxs(Group,{position:"apart",ref:i,...r,children:[jsxs(Stack,{spacing:0,children:[jsx(Text,{maw:"200px",sx:$p,children:o}),n&&jsx(Text,{fz:10,c:"#666",maw:"140px",sx:$p,children:n})]}),jsx(Text,{color:"gray.5",size:"sm",children:t})]},`${t}-${o}`)});function Us(e){let{dimensionId:t,variantId:o,value:n,defaultValue:r,onChange:i,locale:s}=e,l=ua(),{localeDefault:a}=a$6(),u=$a$1(),c=s||a,[p,f]=useState([]),[m,g]=useState(""),[S]=useDebouncedValue(m,500),[v,h]=useState(false),[b,C]=useState(false),[d,y]=useUncontrolled({value:n,defaultValue:r,finalValue:void 0,onChange:i?$=>i($):void 0}),x=useRef(null),k=useClickOutside(()=>C(false)),R=useMergedRef(x,k),B=$=>{let K=p.find(T=>T.id===$.id);K&&(g(K.name?K.name:""),y(K),C(false));};useEffect(function(){h(true);let K={query:S,locale:c===u?c:"all",variant:[o],dimension:[t],limit:5,visible:false,includes:true,noImage:false,format:"plain",all:true,preferredLocale:u,report:[]};l(ta$1.searchMember(K)).then(T=>{if(T&&T.results){let M=T.results.map(I=>({...I,currentLocale:c,name:(I.contentByLocale&&I.contentByLocale.find(O=>O.locale===c)||I).name}));f(M),h(false),M.length===0&&S===""&&(f([]),h(false));}});},[l,S,c,o,t,u]),useEffect(()=>{p.length&&!d?.id&&i&&i(p[0]);},[p,i]);let N=my(p,c,u);return useEffect(()=>{setTimeout(()=>{x.current&&x.current.focus();},200);},[b]),b||!d?.name?jsx(Autocomplete,{ref:R,value:m,onChange:g,data:N,itemComponent:gy,placeholder:"Search members.",nothingFound:"No members found.",rightSection:v&&jsx(Loader,{size:"xs"}),filter:()=>true,onItemSubmit:B,size:"xs",w:130,styles:Zi("Members")}):jsx(zr,{onClick:()=>C(true),textProps:{color:"gray.6"},tooltip:true,clickable:true,children:d.name})}function Hs(e){let o=Ga$1(e).data,n=ya$1(o?.variants);return n.isSuccess?n.data.map(r=>({value:`${r.id}`,label:r.name})):[]}function js(e){let{dimension:t,value:o,onChange:n}=e,[r,i]=useState(false),s=Hs(t),l=useClickOutside(()=>i(false)),a=s.length===1||!r,[u,c]=useUncontrolled({value:o?String(o):void 0,defaultValue:s[0]?s[0].value:"",finalValue:void 0,onChange:n?m=>n(Number(m)):void 0}),p=m=>c(m),f=s.find(m=>m.value===u)||s[0];return a?jsx(zr,{onClick:()=>i(true),clickable:s.length>1,children:f?f.label:"No Variant"}):jsx(Select,{ref:l,data:s,value:u,onChange:p,w:140,size:"xs",styles:Zi("Variants"),initiallyOpened:true})}function ta(e){let{dimensionId:t,locale:o,onSelect:n,value:r}=e,i=ua(),s=Hs(t),[l,a]=useUncontrolled({defaultValue:r?{id:`${r.memberId}`}:void 0,finalValue:void 0,onChange:n?f=>n(f):void 0}),[u,c]=useUncontrolled({value:void 0,defaultValue:r?.variantId,finalValue:s[0]?Number(s[0].value):0,onChange:()=>{a({});}}),p=r?.memberId;return useEffect(function(){p&&i(ta$1.readMember(e$2({locale:o,content_ids:[`${p}`],all:"false",mode:"content_ids"}))).then(m=>{if(m&&m.results&&m.results[0]){let g=m.results[0];a({...g});}else console.error("default member is not found");});},[p]),jsxs(Flex,{gap:"xs",px:"xs",align:"center",children:[jsx(js,{dimension:t,value:u,onChange:c},`dimension-${t}`),jsx(Text,{fz:"xs",tt:"uppercase",color:"gray.6",fw:700,children:"/"}),u&&jsx(Us,{variantId:u,dimensionId:t,value:l,onChange:a,locale:o},`variant-${u}`)]})}function qs({report:e,defaultMembers:t,locale:o}){let[n,r]=useState(false),i=ua(),s=a$2(),l=useContext(db$1),a=Ya(l),u=e&&e.dimensions?e.dimensions:[],c=va$1(S=>S.status.previews),p=c.map(S=>({variantId:S.variant_id,memberId:S.content_id})),f=s.query.preview,m=Array.isArray(f)?f.join("!"):f||"",g=S=>{let h=e.dimensions.map(C=>{let d;if(S)if(S.dimension_id===C)d=S;else {let y=c.find(x=>x?x.dimension_id===C:false);y&&(d=y);}return d}).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}:{}),b=h.map(Ry).join("!");if(b&&m!==b){let C=h.filter(d=>d.content_id).length===u.length;i(ta$1.setPreviews(h)),C&&(s.setSearchParam("preview",b),a({previews:h}));}};return useEffect(function(){let v=m.split("!").filter(Boolean);v.length===u.length&&u.length>0?i(ta$1.readMember({mode:"slugs",slugs:v.map(h=>{let[b,C]=h.split("/");return {variantSlug:b,memberSlug:C}}),locale:o,output:"full"})).then(h=>a({previews:h.results})).then(()=>r(true)):t&&t.length===u.length?i(ta$1.readMember({mode:"content_ids",variant:t.map(h=>h.variantId),content_ids:t.map(h=>h.memberId),locale:o,output:"full"})).then(h=>a({previews:h.results})).then(()=>r(true)):r(true);},[]),jsx(Group,{spacing:"xs",children:n&&u.map((S,v)=>jsxs(Fragment$1,{children:[jsx(Text,{fw:700,fz:"xs",children:"/"}),jsx(ta,{dimensionId:S,onSelect:g,value:p[v]?p[v]:void 0,locale:o},S)]},S))})}function Ry(e){return `${"variant_slug"in e?e.variant_slug:e?.variant?.slug}/${e.slug}`}var Nr="dimension",jp="Dimension";var Ys="formatter",qp="Formatter";var Xs="variant",Yp="Variant";var Js="datasource",Jp="Data Source";var Qp={[r]:s,[Nr]:jp,[Ys]:qp,[l$1]:m$1,[o$1]:p,[Xs]:Yp,[Js]:Jp};function Bt({id:e,type:t,warning:o,disabled:n=false}){let r=useDispatch(),{newConfirmation:i}=b(),s=useCallback(async()=>{let l=Qp[t]||"Entity",a=o||`Delete this ${l} and all its contents? This action cannot be undone.`;try{n||(await i({title:"Are you sure?",message:a,confirmText:"Yes, Delete it."}),r(ta$1.deleteEntity(t,e)));}catch{console.error(`${l} deletion aborted:`,e);}},[e,t,o,n,r]);return jsx(ActionIcon,{disabled:n,color:"red",variant:"transparent",onClick:s,children:jsx(IconTrash,{size:18})})}function Qy({for:e,onEdit:t}){let o=useMantineTheme(),{newConfirmation:n}=b(),r=o.colorScheme==="dark"?o.colors.dark[1]:o.colors.gray[7],i=useCallback(async()=>{try{await n({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.error("Dimension edition aborted.");}},[t]),{name:s,ordering:l}=e;return jsxs(Card,{shadow:"xs",withBorder:true,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:s})]})}),jsxs(Text,{size:"sm",style:{color:r,lineHeight:2},children:["Order:",l]}),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:e.variants.length})]}),jsx("ul",{children:e.variants.map(a=>jsx("li",{style:{color:r},children:jsx(ev,{id:a})},a))}),jsxs(Group,{position:"apart",children:[jsx(Button,{onClick:i,leftIcon:jsx(IconPencil,{}),compact:true,children:"Edit"}),jsx(Bt,{id:e.id,type:"dimension",warning:"Deleting dimensions can be destructive and break the site. Make sure you know what you're doing!"})]})]})}var td=cb(Qy,Ga$1);function Zy({for:e}){let t=g(e.settings);return jsx(Text,{size:"sm",children:`${e.name}: /${e.slug} - Order: ${t.order}`})}var ev=cb(Zy,Ha);function zn(e){let{target:t,fields:o,onSubmit:n}=e,[r,i,s]=pv(o||[]),[l,a]=useDisclosure(false,{onClose:s}),u=useCallback(c=>{l&&(c.preventDefault(),typeof n=="function"&&n(i),a.close());},[i,l]);return useHotkeys([["enter",u]]),r.length===0?t:jsxs(Popover,{onClose:a.close,opened:l,position:"right",trapFocus:true,withArrow:true,withinPortal:true,zIndex:1001,children:[jsx(Popover.Target,{children:lv.cloneElement(e.target,{onClick:a.open})}),jsx(Popover.Dropdown,{children:jsxs("form",{onSubmit:u,children:[r,jsx(Button,{type:"submit",children:"Submit"})]})})]})}function pv(e){let[t,o]=useState({}),n=e.map(s=>encodeURIComponent(`${s.name}:${s.type}/${s.label}`)).join("&"),r=useCallback(()=>{o({});},[]);return [useMemo(()=>e.map(s=>{let l=`${t[s.name]??(s.initialValue||"")}`;return s.type==="checkbox"?jsx(Checkbox,{label:s.label,name:s.name,checked:l=="true"},s.name):s.type==="radio"?jsx(Radio.Group,{label:s.label,value:l,children:s.options.map(a=>jsx(Radio,{label:a.label,value:`${a.value}`},a.label))},s.name):s.type==="select"?jsx(Select,{data:s.options.map(a=>({value:`${a.value}`,label:a.label})),label:s.label,onChange:a=>{o({...t,[s.name]:a});},value:l,zIndex:1002},s.name):s.type==="switch"?jsx(Switch,{label:s.label,name:s.name,checked:l=="true"},s.name):s.type==="text"?jsx(TextInput,{label:s.label,onChange:a=>{o({...t,[s.name]:a.target.value});},placeholder:s.placeholder,value:l},s.name):null}),[n,t]),t,r]}function Sv({for:e,onEdit:t}){let o=useMantineTheme(),{newConfirmation:n}=b(),r=useCallback(async()=>{try{await n({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.error("Variant edition aborted.");}},[t]),{slug:i,name:s,settings:l}=e,a=g(l);return jsxs(Card,{shadow:"xs",withBorder:true,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: ",a.order]})]}),jsxs(Badge,{variant:"light",children:["/",i]})]}),jsx(Space,{h:"xs"}),jsxs(Group,{position:"apart",children:[jsx(Button,{onClick:()=>r(),leftIcon:jsx(IconPencil,{}),compact:true,children:"Edit"}),jsx(Bt,{id:e.id,type:"variant",warning:"Deleting variants can be destructive and break the site. Make sure you know what you're doing!"})]})]})}var ld=cb(Sv,Ha);var xv=e=>e.replace(/^\s+|\s+$/gm,"").replace(/[^a-zA-ZÀ-ž0-9- _]/g,""),na=xv;function bt({content:e,buttons:t,size:o}){let[n,r]=useState(500);return useEffect(()=>{let{innerHeight:i}=window;r(i-o);},[]),jsxs("div",{style:{height:"100%"},children:[jsx(ScrollArea,{offsetScrollbars:true,type:"always",style:{height:n},styles:{viewport:{"& > div:first-of-type":{display:"block !important"}}},children:e}),jsx(Space,{h:"xs"}),jsx(Divider,{}),jsx(Group,{mt:"xs",grow:true,style:{height:45},children:t})]})}function Rv({member:e,height:t="auto",width:o="100%",size:n="thumb",forceRefreshTimestamp:r=false}){let i="";r&&(i=`&t=${new Date().getTime()}`);let s=e&&e.image_id?`/api/cms/member/image?member=${e.content_id}&size=${n}${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:s})}var Vr=Rv;function Vn({members:e,onClickEdit:t,onSort:o,colsToRender:n=[],dataTableProps:r={}}){let[i,s]=useState([]),[l,a]=useState([]),{state:u,...c}=r;useEffect(()=>{typeof o<"u"&&i&&i.length&&o(i);},[i]),useEffect(()=>{a(e);},[e]),useEffect(()=>{a(e);},[]);let p=va$1(g=>g.status.localeDefault),f=jsx(Badge,{color:"gray",children:"None"}),m=[{header:"",accessorKey:"visible",enableResizing:false,enableSorting:false,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:false,size:100},{header:"Dimension",accessorKey:"dimension.name",enableSorting:false,size:100},{header:"Variant",accessorKey:"variant.name",enableSorting:false,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:false},{header:`Name ${p.toUpperCase()}`,accessorKey:"name",enableSorting:typeof o<"u",Cell:({row:g})=>{let S=g.original.contentByLocale.find(b=>b.locale===p),v=g.original.contentByLocale.filter(b=>b.locale!==p),h=v.reduce((b,C)=>{let d=`${C.locale.toUpperCase()}: ${C.name}`;return `${b}${b!==""?`
2
- `:""}${d}`},"");return jsxs(Group,{children:[jsx("span",{children:S?.name||f}),v.length>0&&jsx(Tooltip,{label:h,children:jsxs(Avatar,{size:"sm",color:"pink",radius:"xl",children:["+",v.length]})})]})}},{header:`Keywords ${p.toUpperCase()}`,accessorKey:"keywords",Cell:({row:g})=>{let S=g.original.contentByLocale.find(C=>C.locale===p),v=g.original.contentByLocale.filter(C=>C.locale!==p),h=(S.keywords?S.keywords:[]).map(C=>jsx(Badge,{children:C},C)),b=v.reduce((C,d)=>{let y=d.keywords||[],x=`${d.locale.toUpperCase()}: ${y.length>0?y.join(","):"None"}`;return `${C}${C!==""?`
3
- `:""}${x}`},"");return jsxs(Group,{children:[jsx("span",{children:h.length>0?h:f}),v.length>0&&jsx(Tooltip,{label:b,children:jsxs(Avatar,{size:"sm",color:"pink",radius:"xl",children:["+",v.length]})})]})},enableSorting:false,size:100},{header:"Image",accessorKey:"image",Cell:({row:g})=>jsx(Vr,{member:g.original,height:"50px",forceRefreshTimestamp:true}),enableSorting:false,size:80},{header:"",accessorKey:"actions",Cell:({row:g})=>jsx(ActionIcon,{onClick:()=>t?t(g.original):false,children:jsx(IconPencil,{size:20})},"edit"),enableResizing:false,enableSorting:false,size:50,mantineTableHeadCellProps:{align:"center"},mantineTableBodyCellProps:{align:"center"}}];return jsx(MantineReactTable,{columns:m.filter(g=>n&&n.length===0||n.includes(g.accessorKey)),data:l,enableBottomToolbar:false,enableColumnActions:false,enableColumnResizing:true,enablePagination:false,enableStickyHeader:true,enableTopToolbar:false,initialState:{density:"xs"},layoutMode:"grid",mantineTableContainerProps:{sx:{minHeight:150,maxHeight:"90vh"}},mantineTableProps:{striped:true},manualSorting:true,onSortingChange:s,state:{sorting:i,...u},...c})}function Gv({switchProps:e,yesText:t,noText:o}){let n={size:"md",onLabel:"YES",offLabel:"NO",label:"Switch Label",my:"xs",checked:false,onChange:r=>console.info(r.currentTarget.checked),...e};return jsxs(Group,{children:[jsx(Switch,{...n}),jsx(Tooltip,{label:n.checked?t:o,withArrow:true,multiline:true,width:200,children:jsx(ActionIcon,{variant:"filled",radius:"50%",size:"xs",children:jsx(IconQuestionMark,{size:"xs"})})})]})}var _r=Gv;function Fn(e){try{return new URL(e),!0}catch{return false}}function oS({for:e,onClose:t}){let o=ua(),n=va$1(z=>z.status.localeDefault),r=va$1(z=>z.status.locales),i=r.map(z=>({value:z,label:z.toUpperCase()})),[s,l$1]=useState(),[a,u]=useState(n),[c,p]=useState(()=>{let z={...e};return r.forEach(X=>{z.config={...z.config,[X]:{attributes:[],idKey:"",labelKey:"",accessor:"",path:"",...z.config[X]||{}}};}),z}),[f,m]=useState(false),[g$1,S]=useState(false),[v,h]=useState(false),[b,C]=useState(false),[d,y]=useState({valid:false,suggestion:""}),[x,k]=useState(),[R,B]=useState([]),[N,$]=useState(false),[K,T]=useState([]),M=z=>{Fn(z)&&(S(true),o(ta$1.urlProxy({url:z})).then(X=>{if(k(X),X){let ie=P(X);B(ie),c.config[a].accessor&&X[c.config[a].accessor]?O(X[c.config[a].accessor][0],c.config[a].accessor):ie.length===0&&X&&X[0]&&O(X[0]);}h(false),S(false);}).catch(X=>{console.error(X),h(`Fetch error: ${X.message}`),k(void 0),S(false);}));},I=z=>{$(true);let X=f$1({variant:z,limit:"5",locale:"all",visible:"true",includes:"true",noImage:"false",format:"plain",all:"true"});o(ta$1.searchMember(X)).then(ie=>{if(ie&&ie.results){let Ve=ie.results;T(Ve),Ve.length===0&&_("doIngest",true);}$(false);}).catch(ie=>{console.error(ie),$(false);});},O=(z,X="")=>{if(z){let ie=Object.keys(z),Ve=ie.find(Ye=>Ye.toLowerCase().includes("id"))||ie[0],at=ie.find(Ye=>!Ye.toLowerCase().includes("id"))||ie[0];(!c.config[a].idKey||c.config[a].idKey===""||!c.config[a].labelKey||c.config[a].labelKey==="")&&p({...c,config:{...c.config,[a]:{...c.config[a],idKey:Ve,labelKey:at,accessor:X}}});}l$1(z);};useEffect(()=>{c.id&&I(c.id),U(c.slug),c.config[a]&&c.config[a].path&&M(c.config[a].path);},[]);let G=z=>{k(void 0),h(false);let X=[];if(z!==n){let ie=c.config[n]?[...c.config[n].attributes].map(at=>{let Ye={...at};return Ye.value="",Ye}):[];c.config[z]&&c.config[z].attributes?X=ie.map(at=>{let Ye=c.config[z].attributes.find(Wt=>at.name===Wt.name);return Ye&&(at.value=Ye.value),at}):X=ie;let Ve={...c.config,[z]:{...c.config[z],attributes:X}};p({...c,config:Ve});}c.config[z]&&c.config[z].path&&M(c.config[z].path),u(z);},W=useMemo(()=>g(c.settings),[c.settings]),F=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:!W.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."}],[W.overrideNames]),L=z=>{let X=Q$1(x,z);X[0]&&O(X[0],z);},U=z=>{o(ta$1.variantValidateSlug(c.dimension_id,z)).then(y).then(()=>{C(false);},X=>{console.error(X);});},P$1=(z,X)=>{let ie=X;z==="slug"&&(ie=na(X),ie&&(C(true),U(X))),p({...c,[z]:ie});},A=(z,X)=>{z==="path"&&h(false),p({...c,config:{...c.config,[a]:{...c.config[a],[z]:X}}});},_=(z,X)=>{let ie=z==="overrideNames"&&!X?{regenerateSlugs:false}:{};p({...c,settings:{...c.settings,...ie,[z]:X}});},Q=()=>{m(true),o(ta$1.updateEntity("variant",c)).then(()=>{m(false),t();}).catch(z=>{console.error(z),m(false);});},Y=z=>{p({...c,config:{...c.config,[a]:{...c.config[a],attributes:z}}});},ce=()=>{if(s&&Object.keys(s)[0]){let ie=c.config[a]?.attributes||[],Ve=ie.length||0;Y([...ie,{type:"constant",name:`attr${Ve+1}`,value:""}]);}},re=(z,X,ie)=>{let Ve=c.config[a].attributes.map((at,Ye)=>Ye===X?{...at,[z]:ie}:at);Y(Ve);},ae=z=>{let X=c.config[a].attributes.filter((ie,Ve)=>Ve!==z);Y(X);},me=s?Object.keys(s).map(z=>({value:z,label:`${z}: ${s[z]}`})):[],gt=R.map(z=>({value:z,label:z})),kt=!Fn(c.config[a].path),Rt=useMemo(()=>v||(kt&&c.config[a].path!==""?"Format error: Invalid URL.":false),[v,kt,c.config,a]);return jsx(bt,{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:true,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:z=>P$1("name",z.target.value)}),jsx(Space,{h:"xs"}),jsx(TextInput,{value:c.slug,icon:!b&&!d.valid?jsx(IconAlertCircle,{}):jsx(IconCircleCheck,{}),label:"Slug",description:b?"Validating slug...":d.valid?"Valid slug.":"Invalid slug.",error:!b&&!d.valid?jsxs(Text,{children:["Duplicated slug. Suggestion:",jsx(Code,{onClick:()=>P$1("slug",d.suggestion),style:{cursor:"pointer"},children:d.suggestion})]}):false,onChange:z=>P$1("slug",z.target.value)}),jsx(Space,{h:"xs"}),jsx(NumberInput,{value:W.order||0,description:"It affects on explore options order",placeholder:"Order",label:"Order",onChange:z=>{_("order",z);}})]}),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(_r,{switchProps:{label:`${!N&&K.length>0?"Re-":""}Ingest members`,checked:W.doIngest,onChange:z=>_("doIngest",z.currentTarget.checked)},yesText:`Run the ingestion process and save the variant details.
4
- 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."}),W.doIngest&&!N&&K.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."}),F.map(z=>jsx(_r,{switchProps:{disabled:z.disabled,label:z.label,checked:W[z.key],onChange:X=>_(z.key,X.currentTarget.checked)},yesText:z.yesText,noText:z.noText},z.key))]}),!W.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:[N&&jsx(Loader,{m:"0 auto"}),!N&&K.length>0&&jsxs(Fragment,{children:[jsx(Vn,{members:K,colsToRender:["id","name","slug"]}),jsx(Vb,{href:"metadata",passHref:true,children:jsx(Text,{c:"dimmed",align:"center",td:"underline",size:"xs",children:"See the full list in Metadata View"})})]})]}),!N&&K.length===0&&jsx(Text,{c:"dimmed",align:"center",children:"No members ingested yet."}),jsx(Space,{h:"xs"})]}),W.doIngest&&jsxs(Fragment,{children:[jsx(Divider,{my:"sm"}),jsx(Title,{order:2,size:"h4",children:"Members ingestion"}),jsx(Space,{h:"xs"}),jsx(SegmentedControl,{value:a,fullWidth:true,onChange:G,data:i,disabled:g$1}),c.config[a]&&jsxs(Fragment,{children:[jsx(Space,{h:"lg"}),jsx(Group,{children:jsx(TextInput,{onChange:z=>A("path",z.target.value),title:"Api endpoint",description:"Enter the url to retrieve a member list to ingest. (JSON) and click Fetch.",value:c.config[a].path,error:Rt,rightSectionWidth:"105px",w:"100%",rightSection:g$1?jsxs(Group,{align:"center",children:[jsx(Loader,{size:"xs"}),jsx(Text,{span:true,variant:"subtle",size:"xs",children:"Fetching..."})]}):jsx(Button,{disabled:g$1||kt,onClick:()=>M(c.config[a].path),leftIcon:jsx(IconPlayerPlay,{}),children:"Fetch"}),readOnly:g$1})}),x&&jsxs("div",{children:[jsx(Space,{h:"md"}),jsx(Select,{value:c.config[a].accessor,label:"Elements",description:`Choose the key that returns the array of elements that
5
- are going to be ingested as members.`,data:gt,disabled:gt.length===0,placeholder:gt.length===0?"Root is an array":"",onChange:z=>L(z)}),jsx(Divider,{label:"First element preview",labelPosition:"center"}),x[c.config[a].accessor]&&!Array.isArray(x)&&jsx(l,{variables:x[c.config[a].accessor][0]}),Array.isArray(x)&&x[0]&&jsx(l,{variables:x[0]}),jsx(Space,{h:"md"}),jsx(Select,{value:c.config[a].idKey,label:"Unique identificator",description:"Choose the field that is a unique identification for a single member.",data:me,onChange:z=>A("idKey",z)}),jsx(Space,{h:"md"}),jsx(Select,{value:c.config[a].labelKey,label:"Members' name",description:"Choose the field that contains the members name.",data:me,onChange:z=>A("labelKey",z)}),jsx(Space,{h:"md"}),jsx(Select,{value:c.config[a].zValueKey||"",label:"Member's relevance (optional)",description:`Choose a field that will be converted to a number and
6
- normalized from 0 to 1 to determine the member's relevance.`,data:[{value:"null",label:"None"},...me],onChange:z=>A("zValueKey",z)}),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[a].attributes&&c.config[a].attributes.map((z,X)=>jsxs(Group,{align:"end",grow:true,children:[jsx(Select,{value:c.config[a].attributes[X].type,label:"Type",data:[{value:"variable",label:"Data based"},{value:"constant",label:"Constant"}],readOnly:a!==n,disabled:a!==n,onChange:ie=>re("type",X,ie)}),jsx(TextInput,{value:c.config[a].attributes[X].name,label:"Name",readOnly:a!==n,disabled:a!==n,onChange:ie=>re("name",X,ie.target.value)}),z.type==="variable"&&jsx(Select,{value:c.config[a].attributes[X].value,label:"Value",data:me,onChange:ie=>re("value",X,ie)}),z.type==="constant"&&jsx(TextInput,{value:c.config[a].attributes[X].value,label:"Value",onChange:ie=>re("value",X,ie.target.value)}),jsx(ActionIcon,{color:"red",onClick:()=>ae(X),disabled:a!==n,children:jsx(IconTrash,{size:20})})]},X)),jsx(Space,{h:"md"}),jsx(Button,{onClick:ce,leftIcon:"+",disabled:f||a!==n,children:"Add Attribute"})]})]}),jsx(Space,{h:"md"})]})]})]})]}),buttons:jsxs(Fragment,{children:[jsx(Button,{disabled:f||g$1||!b&&!d.valid,onClick:t,variant:"outline",children:"Cancel"}),jsx(Button,{disabled:f||g$1||!b&&!d.valid,loading:f||g$1,onClick:Q,children:`${W.doIngest?`${!N&&K.length>0?"Re-":""}Ingest & `:""}Save`})]}),size:165})}var gd=cb(oS,Ha);function Cd({id:e,onClose:t}){let o=ua(),n=Ga$1(e),[r,i$1]=useState({id:e}),[s,l]=useState(null);useEffect(()=>{n.isSuccess&&i$1(n.data);},[n.status]);let a=useCallback(m=>{o(ta$1.createEntity("variant",{dimension_id:e,name:m.name,slug:i(m.name)}));},[e]),u=useCallback(()=>{o(ta$1.updateEntity("dimension",{...r,id:e})).then(t);},[r]),c=useCallback((m,g)=>{i$1({...r,[m]:m==="slug"?i(g):g});},[]);if(s)return jsx(gd,{id:s,onClose:()=>l(null)});let p=n.isFetching,f=n.isSuccess?n.data.variants:[];return jsx(bt,{content:jsxs(Fragment,{children:[jsx(Title,{order:2,children:`Dimension metadata: ${r.name}`}),jsx(Space,{h:"xs"}),jsx(TextInput,{value:r.name,label:"Name",onChange:m=>c("name",m.target.value)}),jsx(Space,{h:"xs"}),jsx(NumberInput,{value:r.ordering?parseInt(`${r.ordering||0}`,10):0,type:"number",label:"Order",onChange:m=>c("ordering",m)}),jsx(Divider,{my:"xl"}),jsx(Dn,{icon:jsx(IconServer,{size:22}),children:jsx(Title,{order:2,size:"h4",children:"Variants"})}),f.map(m=>jsx(ld,{id:m,onEdit:l},m)),jsx(zn,{fields:[{name:"name",type:"text",label:"Add Variant"}],onSubmit:a,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})}function Pd({id:e,onClose:t}){let o=ua(),n=Da$1(e),[r,i$1]=useState({id:e}),[s,l]=useState(null);useEffect(()=>{n.isSuccess&&i$1(n.data);},[n.status]);let a=useCallback((h,b)=>{o(ta$1.createEntity("dimension",{report_id:e,name:h.name,ordering:b.length+1})).then(C=>{C.ok&&o(ta$1.createEntity("variant",{dimension_id:C.data.id,name:C.data.name,slug:i(C.data.name)}));});},[e]),u=useCallback(()=>{o(ta$1.updateEntity("report",{...r,id:e})).then(t);},[e,r]),c=useCallback((h,b)=>{i$1({...r,[h]:b});},[]),p=(h,b)=>{i$1({...r,settings:{...r.settings,[h]:b}});};if(s)return jsx(Cd,{id:s,onClose:()=>l(null)});let f=n.isFetching,m=n.isSuccess?n.data.dimensions:[],g=r.settings,S=g&&typeof g.order=="number"?g.order:0,v=g&&typeof g.hide=="boolean"?g.hide:false;return jsx(bt,{content:jsxs(Fragment,{children:[jsx(Title,{order:2,children:`Report metadata: ${r.name}`}),jsx(Space,{h:"xs"}),jsx(TextInput,{value:r.name,label:"Name",onChange:h=>c("name",h.target.value)}),jsx(Space,{h:"xs"}),jsxs(Group,{grow:true,children:[jsx(_r,{switchProps:{label:"Show in Explore & Search",checked:!v,onChange:h=>p("hide",!h.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:S,description:"It affects the Explore search options order",placeholder:"Order in Explore",label:"Order",disabled:v,onChange:h=>{p("order",h);}})]}),jsx(Divider,{my:"sm"}),jsx(Dn,{icon:jsx(IconDatabase,{size:22}),children:jsx(Title,{order:2,size:"h4",children:"Dimensions"})}),jsx(Grid,{children:m.map(h=>jsx(Grid.Col,{span:6,children:jsx(td,{id:h,onEdit:l})},h))}),jsx(zn,{fields:[{type:"text",name:"name",label:"Add Dimension"}],onSubmit:(h=>a(h,m)),target:jsx(ActionIcon,{size:"xl",radius:"xl",children:jsx(IconCirclePlus,{size:30})})})]}),buttons:jsxs(Fragment,{children:[jsx(Button,{variant:"outline",disabled:f,loading:f,onClick:t,children:"Cancel"}),jsx(Button,{disabled:f,loading:f,onClick:u,children:"Save Report"})]}),size:165})}function Ld(e){let{report:t}=e,{newConfirmation:o}=b(),{selectEntity:n}=Ka(),r=useContext(db$1),i=Ya(r),s=ua(),l=va$1(F=>F.status.previews),a=a$2(),u=Number.parseInt(a.params[0]),c=Da$1(u),p=Qa$1(),f=Ra$1(),m=b$2(),g=va$1(F=>F.status.localeDefault),S=Za("settings"),v=Za("reportEditor"),h=Za("tools"),b$1=Za("debugView"),C=g$2(u),d=t&&t.dimensions?t.dimensions:[],y=d.length>0,x=l.filter(F=>F.variant_slug).reduce((F,L)=>F.concat([L.variant_slug,L.slug]),[]),k=m===g?"":`/${m}`,R=f||p,B=x.length?`${k}${R}/${x.join("/")}`:"",N=x.length?`${k}${p}/${x.join("/")}`:"",[$,K]=useState(null),T=useMemo(()=>{let F=[];return B&&f&&F.push({value:"preview",label:"Open Preview",url:B,Icon:IconFileCode}),N&&F.push({value:"report",label:"Open Report",url:N,Icon:IconFileAnalytics}),F},[B,N,f]);useEffect(()=>{!$&&T.length>0&&K(T[0].value);},[T,$]);let M=useMemo(()=>T.find(F=>F.value===$)||null,[T,$]),I=useCallback(()=>{M?.url&&window.open(M.url,"_blank","noopener,noreferrer");},[M]),O=useCallback(F=>{K(F);},[]),G=F=>{a.setSearchParam("locale",F),s(ta$1.readMember({mode:"content_ids",variant:l.map(L=>L.variant_id),content_ids:l.map(L=>L.content_id),locale:F,output:"full"})).then(({results:L})=>{s(ta$1.setCurrentLocale(F)),L&&L.length===d.length&&d.length?i({previews:L}):i({previews:[]});});},W=useCallback(async()=>{try{let F=N;await o({title:"Are you sure?",message:`Revalidate action will force to regenerate page: ${F}.`,confirmText:"Revalidate now!"}),await s(ta$1.revalidateUrl({target:F})).then(L=>{let U=`Revalidated page ${L.target} you will see the changes in the following minutes.`;notifications.show({autoClose:!1,color:"green",id:"revalidate-results",message:U,title:"Revalidate Results"});}).catch(L=>{notifications.show({autoClose:!1,color:"red",id:"revalidate-error",message:L.message,title:"Revalidate Error"});});}catch{console.error("Revalidate error.");}},[B,N,f]);return jsxs(Fragment,{children:[jsx(_p,{left:jsxs(Group,{children:[jsx(ActionIcon,{color:"blue",variant:"filled",onClick:()=>{n({type:"report",id:t.id}),S.handlers.open();},children:jsx(IconSettingsFilled,{size:20})}),jsx(Lr,{value:m,onChange:G,selectProps:{size:"xs",maw:80}}),jsx(SegmentedControl,{size:"xs",radius:"sm",sx:F=>({background:F.colors.blue[0]}),data:[{label:"Editor",value:"editor"},{label:"Debug",value:"debug"}],onChange:F=>{F==="editor"?b$1.handlers.close():(h.handlers.close(),v.handlers.close(),S.handlers.close(),b$1.handlers.open());}})]}),center:jsxs(Group,{children:[jsx(qs,{report:t,defaultMembers:C?.map(F=>({variantId:F.variantId,memberId:F.contentId})),locale:m}),(B||N)&&T.length>0&&jsxs(Group,{spacing:0,children:[jsx(Button,{onClick:I,disabled:!M,variant:"light",fw:700,radius:"sm",fz:12,pr:10,pl:5,mih:"1.875rem",compact:true,leftIcon:M?.Icon?jsx(M.Icon,{size:14}):null,sx:{borderTopRightRadius:0,borderBottomRightRadius:0},children:M?.label||"Select view"}),jsxs(Menu,{position:"bottom",withArrow:true,children:[jsx(Menu.Target,{children:jsx(ActionIcon,{variant:"light",radius:"sm",sx:F=>({borderTopLeftRadius:0,borderBottomLeftRadius:0,borderLeft:"1px solid #fff",backgroundColor:"#e7f5ff",minHeight:"1.875rem",height:"1.875rem",width:"1.875rem",fontSize:"12px"}),children:jsx(IconChevronDown,{size:14,color:"#228be6"})})}),jsx(Menu.Dropdown,{children:T.map(F=>{let L=F.Icon;return jsx(Menu.Item,{onClick:()=>O(F.value),icon:L?jsx(L,{size:20}):null,children:F.label},F.value)})})]})]})]}),right:jsxs(Group,{children:[l.length>0&&$!=="preview"&&jsx(Button,{variant:"light",fw:700,radius:"sm",fz:12,pr:10,pl:5,mih:"1.875rem",onClick:W,leftIcon:jsx(IconWorldUpload,{size:14}),compact:true,children:"Publish"}),!y&&jsx(Button,{size:"xs",variant:"outline",onClick:v.handlers.open,children:"Import Data"})]})}),jsx(Drawer,{opened:v.opened,onClose:v.handlers.close,title:jsx(Dn,{icon:jsx(IconFileAnalytics,{size:24}),children:`Editing Report: ${c.data?c.data.name:""}`}),size:"50%",padding:"xl",position:"right",children:jsx(Pd,{id:u,onClose:v.handlers.close})})]})}function OS({type:e,id:t,warning:o=""}){let n=v[e]||"Entity",r=o||`Delete this ${n} and all its contents? This action cannot be undone.`,i=useDispatch(),{newConfirmation:s}=b();return jsx(ActionIcon,{color:"red",onClick:async()=>{try{await s({title:"Are you sure?",message:r,confirmText:"Yes, Delete it."}),i(ta$1.deleteEntity(e,t));}catch{}},children:jsx(IconTrash,{size:20})})}var zd=OS;var Fd=e=>!e||e.trim()===""?false:e.trim().startsWith("/")?true:Fn(e);function US({defaultValue:e,id:t,onChangeAPI:o,onDelete:n,finalUrl:r,dataSource:i,pos:s}){let l=Oa$1(),a=Sa$1(t),[u,c]=useState(()=>I(e,l,a)),[p,f]=useState(e),[m,g]=useState(false),S=B=>{m&&!k&&(B.preventDefault(),o(p),g(false));},v=B=>{let{value:N}=B.target;c(I(N,l,a)),f(N);},h=()=>{g(false),c(I(e,l,a));},b=()=>{g(!m);},C=()=>{n();},d=useMemo(()=>(u||"").indexOf("bespoke_slugs=")>-1,[u]),y=useMemo(()=>!(u&&(u.trim()===""||Fd(u))),[u,Fd]),x=useMemo(()=>u.includes("N/A"),[u]),k=useMemo(()=>y||x,[y,x]),R=useMemo(()=>{let B=[];return y&&B.push("Invalid URL format"),x&&B.push("URL contains 'N/A', probably you are using a variable that is not in scope"),B.join(". ")},[y,x]);return jsxs(Stack,{spacing:0,p:m?"xs":0,mb:m?3:0,bg:m?"gray.0":"transparent",children:[jsxs(Group,{noWrap:true,position:"apart",spacing:"xs",children:[jsxs(Text,{lineClamp:1,size:"xs",children:[s,". ",jsx(Anchor,{href:r||u,target:"_blank",rel:"noreferrer",children:r||u||"--Add API Url--"})]}),jsx(Group,{noWrap:true,spacing:0,children:m?jsxs(Fragment,{children:[jsx(Tooltip,{label:k?"Invalid URL format":"Apply changes",children:jsx(ActionIcon,{size:"md",onClick:S,color:"green",sx:{opacity:k?.4:1},children:jsx(IconCheck,{size:rem(20)})})}),jsx(ActionIcon,{size:"md",onClick:h,color:"red",children:jsx(IconX,{size:rem(20)})})]}):jsxs(Fragment,{children:[d&&jsx(Tooltip,{multiline:true,label:"Slugs Interceptor Enabled",children:jsx(IconGitMerge,{size:rem(18),color:"gray"})}),i&&jsx(Tooltip,{multiline:true,label:`Datasource Interceptor Enabled called "${i}"`,children:jsx(IconNetwork,{size:rem(18),color:"gray"})}),x&&jsx(Tooltip,{multiline:true,label:"API URL contains 'N/A', probably you are using a variable that is not in scope",children:jsx(IconAlertTriangle,{size:rem(20),color:"red"})}),jsx(ActionIcon,{size:"md",onClick:b,children:jsx(IconPencil,{size:rem(20)})}),jsx(ActionIcon,{size:"md",onClick:C,children:jsx(IconTrash,{color:"red"})})]})})]}),m&&jsx(Stack,{spacing:"xs",children:jsx(Textarea,{placeholder:"API URL here: https://api.example.com/v1/data?id={{id1}}",defaultValue:p,onChange:v,onKeyDown:getHotkeyHandler([["enter",S]]),size:"sm",minRows:2,maxRows:6,autosize:true,sx:{width:"100%"},error:k?`${R} ${u}`:false},"textarea")})]})}var $d=US;function qS({monacoOptions:e}){let t=useMonaco();return useEffect(()=>{if(t){let o="Monokai";import(`monaco-themes/themes/${o}.json`).then(n=>{t.editor.defineTheme(o,n),t.editor.setTheme(o);}).catch(()=>{throw new Error("Invalid Monaco theme")});}},[t]),jsx(Box,{className:"cr-monaco-container",w:"100%",children:jsx(jS,{defaultLanguage:"javascript",theme:"Monokai",...e})})}var rn=qS;function ax({status:e,block:t,variables:o}){let{settings:n,contentByLocale:r}=t,i=!!(n&&n.useProxy&&n.useProxy==="true"),s=r?.logic?.content?.api&&r.logic.content.api!==""?r.logic.content.api.split("|||").length:0,l=e&&e.apiDataSources?e.apiDataSources.some(m=>m!==false):false,a=useMemo(()=>e.apiFinalUrls?typeof e.apiFinalUrls=="string"?e.apiFinalUrls.includes("N/A")?1:0:Array.isArray(e.apiFinalUrls)?e.apiFinalUrls.filter(m=>m.includes("N/A")).length:0:0,[e.apiFinalUrls]),u=!!([z.GENERATOR,z.SECTION_FLAG].includes(t.type)&&e.api&&e.api.indexOf("bespoke_slugs=")>-1),c=W(t),p=c?o[T]:false,f=[z.GENERATOR,z.SECTION_FLAG].includes(t.type)&&o?JSON.stringify(o).length/1024:void 0;return jsxs(Group,{spacing:5,children:[jsx(Tooltip,{multiline:true,label:`Number of requests: ${s}`,children:jsx(ThemeIcon,{size:"sm",radius:"xl",color:"blue",children:jsx(Text,{size:rem(12),span:true,fw:"bold",children:s})})}),a>0&&jsx(Tooltip,{multiline:true,label:`${a} of your URLs in this generator contains 'N/A', probably you are using a variable that is not in scope`,children:jsx(ThemeIcon,{size:"sm",radius:"xl",color:"orange",children:jsx(IconAlertTriangle,{size:rem(12)})})}),i&&jsx(Tooltip,{multiline:true,label:`Use Proxy Setting (avoid CORS): ${i?"YES":"NO"}`,children:jsx(ThemeIcon,{size:"sm",radius:"xl",color:"blue",children:jsx(IconCloudNetwork,{size:rem(12)})})}),l&&jsx(Tooltip,{multiline:true,label:"Data Source Interceptor Active at least in one request",children:jsx(ThemeIcon,{size:"sm",radius:"xl",color:"blue",children:jsx(IconNetwork,{size:rem(12)})})}),u&&jsx(Tooltip,{multiline:true,label:"Slugs Interceptor Enabled at least in one request",children:jsx(ThemeIcon,{size:"sm",radius:"xl",color:"blue",children:jsx(IconGitMerge,{size:rem(12)})})}),e.duration&&jsx(Tooltip,{multiline:true,label:`Api Call Duration: ${e.duration} ms`,children:jsx(ThemeIcon,{size:"sm",radius:"xl",color:ba(e.duration),children:jsx(IconClockHour2,{size:rem(12)})})}),e.responseSize&&jsx(Tooltip,{multiline:true,label:`Api Response Size: \u2248${e.responseSize.toFixed(2)} Kb`,children:jsx(ThemeIcon,{size:"sm",radius:"xl",color:ca(e.responseSize),children:jsx(IconApi,{size:rem(12)})})}),f&&jsx(Tooltip,{multiline:true,label:`Block Output Size: \u2248${f.toFixed(2)} Kb`,children:jsx(ThemeIcon,{size:"sm",radius:"xl",color:ca(f),children:jsx(IconAugmentedReality,{size:rem(12)})})}),c&&jsx(Tooltip,{multiline:true,label:`Section #${t.section_id} Allowed Flag: ${p?"YES":"NO"}`,children:jsx(ThemeIcon,{size:"sm",radius:"xl",color:p?"green":"red",children:jsx(IconFlag,{size:rem(12)})})})]})}var pa=ax;var da={api:null,duration:null,error:null,log:[],responseSize:null,resp:null,allowed:true};function yx({block:e,status:t,sectionFlag:o,variables:n}){let r=useMemo(()=>o?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"})}),[o]);return jsxs(Fragment,{children:[jsxs(Group,{position:"left",pt:"xl",children:[jsxs(Group,{children:[r,jsxs(Title,{order:6,children:[P$1[e.type]," ",e.id]})]}),jsx(Group,{my:"xs",children:jsx(pa,{status:t,block:e,variables:n})})]}),jsx(Divider,{})]})}function vx(e){let{active:t,allowed:o$1,blockStateContent:n,blockStateSettings:r,debug:i,for:s,locale:l,isFetching:a}=e,u=La$1(s.id),c$1=Oa$1(),p=Pa$1(),f=Sa$1(s.id,l),m=va$1(M=>M.variables.variables[s.id]||{}),g=va$1(M=>M.variables.status[s.id]||{}),S=R[s.type].renderPreviewOnEdit&&n?n:O(s,l),v=R[s.type].renderPreviewOnEdit&&r?r:s.settings,[h,b]=useState(null),[C,d]=useState(da),y=W(s),x=c(),k=a$1();useEffect(()=>{(async()=>{if(s.type===z.VIZ){b({block:s,locale:l,variables:u,active:t}),d(da);return}if(!t&&!R[s.type].evalWhenNonActive){let{nonActiveAdapter:L}=R[s.type],U=L&&typeof L=="function"?L():{};b(U),d(da);return}if([z.GENERATOR,z.SECTION_FLAG].includes(s.type)){let L=!!s.contentByLocale?.logic?.content?.api,U=y?m[T]:false;b({outputVariables:m,hasAPI:L,sectionAllowed:U,type:s.type}),d(g);return}if([z.SELECTOR,z.MULTIHIERARCHY_SELECTOR].includes(s.type)){let{renderVariables:L,status:U}=await _(s,c$1,f,x,p,k),P=o[s.type]&&typeof o[s.type]=="function"?o[s.type](L,s.id):L;b(P),d(U);return}if(s.type===z.RELATED){let{outputVariables:L}=await _(s,c$1,f,x,p,k),{related_reports:U}=L;b({related_reports:U});return}if(s.type===z.RESET_BUTTON||s.type===z.COMPARISON_BUTTON){b(S.simple||{});return}let I$1=I(S?.logic,c$1,f),{vars:O,error:G,log:W}=H("variables",u,I$1,c$1,void 0,f),F=o[s.type]&&typeof o[s.type]=="function"?o[s.type](O,s.id):O;if(s.type===z.NAV){b({headings:s.inputs,settings:s.settings,...F});return}b(F),d({...da,error:G,log:W});})();},[S,u,y]),useEffect(()=>{g&&g.error&&g.error!==""&&notifications.show({autoClose:1e4,color:"red",id:"block-error",message:g.error,title:`Block error ID: ${s.id}`});},[g.error]);let R$1=M[s.type],N=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:true,children:g.hiddenByCascade===s.id?`${s.type} not allowed`:`${s.type} hidden by block ${g.hiddenByCascade}`})})});if(a)return jsx(Center,{style:{minHeight:100},w:"100%",children:jsx(Loader,{})});if(!h)return null;let{error:$,log:K}=C,T$1=K?K.join(`
7
- `):"";return jsxs("div",{id:`bespoke-${s.type}-${s.id}`,className:"cms-block-preview bespoke-block-area",style:{width:"100%",minHeight:s.type===z.VIZ?400:"auto"},children:[!o$1&&N,[z.GENERATOR,z.SECTION_FLAG].includes(s.type)&&jsx(yx,{block:s,status:C,sectionFlag:y,variables:h}),R$1?jsx(Fragment$1,{children:jsx(R$1,{id:s.id,debug:i,section:s.section_id,...h,settings:v,status:C})},"renderer"):jsx(Center,{style:{minHeight:100},children:jsx(Badge,{color:"gray",variant:"outline",children:s.type},"type")}),i&&T$1&&jsx(Textarea,{label:"Console",minRows:3,readOnly:true,autosize:true,maxRows:10,value:T$1,error:$}),i&&$&&jsx(Textarea,{label:"Error",readOnly:true,autosize:true,minRows:3,maxRows:10,value:$})]})}var fa=cb(vx,Fa$1);function Ax({id:e,setBlockSettings:t}){let{newConfirmation:o}=b(),n=ua(),r=Fa$1(e).data,[i,s]=useState(r.settings[C$1.ACCESS]||["public"]),[l,a]=useState(r.settings[C$1.FALLBACK]||false),u=La$1(e),c=useMemo(()=>[{value:"always",label:"always",group:"Static"},{value:"never",label:"never",group:"Static"}].concat(Object.keys(u).map(y=>({value:y,label:`${y}: ${u[y]}`,group:"Based on variable"}))),[u]),p=[{label:"Section-wide",value:"false"},{label:"Report-wide",value:"true"}];useEffect(()=>{t({[C$1.ACCESS]:i}),i.includes("public")&&a(false);},[i]),useEffect(()=>{t({[C$1.FALLBACK]:l});},[l]);let f=async()=>{try{await o({title:"Are you sure?",message:"Delete this block and all its contents? This action cannot be undone.",confirmText:"Yes, Delete it."}),n(ta$1.deleteEntity("block",e));}catch{}},m=(y,x)=>{t({[y]:x});},g=y=>{let x=`return variables.${y}`;y==="always"&&(x="return true;"),y==="never"&&(x="return false;"),t({[C$1.ALLOWED]:y,[C$1.ALLOWED_LOGIC]:x});},S=y=>{t({[C$1.IGNORE_CASCADE]:y});},v=va$1(y=>y.records.entities.block),h=r.consumers.filter(y=>v[y].section_id!==r.section_id),b$1=!!h.length,C=h.slice(0,3).map((y,x)=>jsxs(Fragment,{children:[x===h.length-1&&h.length>1?"and ":"",jsx("strong",{children:`${v[y].type} ${y} [Section ${v[y].section_id}]`},y),x<h.length-1&&h.length>1?", ":""]})),d=r.inputs.map(y=>({label:`${v[y]?.type} - ${v[y]?.id}`,value:y}));return jsx(Group,{grow:true,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:r.settings[C$1.ALLOWED]||"always",onChange:g,data:c}),[z.GENERATOR,z.VIZ,z.SECTION_FLAG].includes(r.type)&&jsx(MultiSelect,{label:"Ignore cascade",description:"Set block as visible even if the selected inputs are hidden.",defaultValue:r.settings[C$1.IGNORE_CASCADE]||[],data:d,onChange:S}),jsx(I$1,{value:i,onChange:s}),jsx(Checkbox,{checked:l,disabled:i.includes("public"),label:"Show fallback block when block is not allowed",onChange:y=>a(y.currentTarget.checked)}),jsx(Title,{order:4,children:"Output"}),b$1&&r.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:true,inherit:true,children:["This block is being consumed by ",C,h.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(r.shared),disabled:b$1&&r.shared,onChange:y=>m("shared",y==="true"),data:p}),jsx(Title,{order:4,children:"Danger zone"}),jsx(Button,{variant:"outline",color:"red",onClick:f,children:"Delete Block"})]})})}var Jd=Ax;var gl={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 Ux({id:e}){let t=ua(),o=useContext(db$1),n=Ya(o),[r,i]=useState(""),[s]=useDebouncedValue(r,200),l$1=va$1(v=>{if(v.records.reports&&v.records.reports[0]){let h=v.records.reports[0],b=v.records.entities.report[h].sections;return Object.values(v.records.entities.block).filter(C=>b.includes(C.section_id))}return []}),a=Fa$1(e).data,u=va$1(v=>v.variables.variables),c=useMemo(()=>a?a.inputs.reduce((v,h)=>({...v,[h]:l$1[h]}),{}):[],[a]),p=(v,h)=>{if(!a)return 0;let b=a.inputs.includes(v.id),C=a.inputs.includes(h.id);if(b!==C)return b?1:-1;let d=Object.keys(u[v.id]||{}).length,y=Object.keys(u[h.id]||{}).length;return d!==y?y-d:v.shared?1:-1},f=useMemo(()=>l$1.filter(v=>v.id!==a.id&&(v.section_id===a.section_id||v.shared)&&v.type!==z.SECTION_FLAG).sort(p),[l$1]),m=useMemo(()=>f.filter(v=>{let h=String(v.id).includes(s.trim()),b=Object.keys(u[v.id]||{}).some(C=>C.includes(s.trim()));return h||b}),[f,s,u]),g=v=>{let h=c[v]?"delete":"create";t(ta$1.updateEntity("block",{id:e,inputAction:{operation:h,input:{input_id:v,block_id:e}}})).then(()=>{n();});};if(!a)return null;let S=v=>a.consumers.includes(v)?gl.Consumer:a.inputs.includes(v)?gl.Input:gl.None;return jsxs(Menu,{width:"425px",children:[jsx(Menu.Target,{children:jsx(Button,{fullWidth:true,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:v=>i(v.target.value)}),m.map(({id:v,shared:h})=>jsx(Menu.Item,{disabled:a.consumers.includes(v),onClick:()=>g(v),icon:S(v),rightSection:jsxs(Stack,{ml:"xs",spacing:"xs",align:"flex-end",children:[jsxs(Text,{size:"xs",color:"gray.6",children:["[",v,"]"]}),h?jsx(ThemeIcon,{size:"xs",radius:"xl",children:jsx(IconGlobe,{})}):null]}),children:jsx(Box,{style:{maxWidth:"400px"},children:jsx(l,{id:`${v}`,variables:u[v]})})},v))]})]})}var Qd=Ux;var hl=e=>`
8
- `.padEnd(e*2+1," "),Zd=(e,t=0)=>{let o=e instanceof Array;return `${o?"[":"{"}${hl(t+1)}${Object.keys(e).sort((n,r)=>n.localeCompare(r)).map(n=>{let r=o?"":`${n}: `,i=e[n];return typeof i=="object"?r+=`${Zd(i,t+1)}`:typeof i=="string"&&(i.includes("=>")||i.startsWith("variables["))?r+=`${i}`:typeof i=="string"&&!i.length?r+="false":i===void 0?r=null:["boolean","number"].includes(typeof i)?r+=i:r+=`"${i}"`,r}).filter(n=>n!==null).join(`,${hl(t+1)}`)}${hl(t)}${o?"]":"}"}`},Wn=Zd;var ef=e=>{if(!e)return e;let t=Array.isArray(e)?[]:{};return Object.keys(e).forEach(o=>{t[o]=typeof e[o]=="object"?ef(e[o]):e[o];}),t},ya=ef;var Hx=(e,t=false)=>{let o=/([A-z0-9]*)\{\{([^}]+)\}\}/g,n=(s,l,a)=>l?`\${formatters.${l}(variables.${a})}`:`\${variables.${a}}`,r=s=>typeof s=="string"?s.trim()===""?false:t?s.replace(o,n):s:Array.isArray(s)?s.map(l=>r(l)):typeof s=="object"&&s!==null?Object.keys(s).sort((l,a)=>l.localeCompare(a)).reduce((l,a)=>({...l,[a]:r(s[a])}),{}):typeof s=="boolean"||typeof s=="number"?s:JSON.stringify(s),i=r(e);return Array.isArray(e)?`return ${JSON.stringify(i)};`:Object.keys(i).sort((s,l)=>s.localeCompare(l)).reduce((s,l)=>{let a;return typeof i[l]=="string"?i[l].includes("=>")||i[l].startsWith("variables[")?a=i[l]:a=`\`${i[l]}\``:typeof i[l]=="boolean"||typeof i[l]=="number"?a=i[l]:a=JSON.stringify(i[l]),s.concat(`"${l}": ${a},
9
- `)},"return {").concat("};")},ro=Hx;function cf(e){let{state:t,transaction:o}=e,{selection:n}=o,{doc:r}=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 n},get doc(){return r},get tr(){return n=o.selection,r=o.doc,i=o.storedMarks,o}}}var Sl=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:n}=this,{view:r}=o,{tr:i}=n,s=this.buildProps(i);return Object.fromEntries(Object.entries(t).map(([l,a])=>[l,(...c)=>{let p=a(...c)(s);return !i.getMeta("preventDispatch")&&!this.hasCustomState&&r.dispatch(i),p}]))}get chain(){return ()=>this.createChain()}get can(){return ()=>this.createCan()}createChain(t,o=true){let{rawCommands:n,editor:r,state:i}=this,{view:s}=r,l=[],a=!!t,u=t||i.tr,c=()=>(!a&&o&&!u.getMeta("preventDispatch")&&!this.hasCustomState&&s.dispatch(u),l.every(f=>f===true)),p={...Object.fromEntries(Object.entries(n).map(([f,m])=>[f,(...S)=>{let v=this.buildProps(u,o),h=m(...S)(v);return l.push(h),p}])),run:c};return p}createCan(t){let{rawCommands:o,state:n}=this,r=false,i=t||n.tr,s=this.buildProps(i,r);return {...Object.fromEntries(Object.entries(o).map(([a,u])=>[a,(...c)=>u(...c)({...s,dispatch:void 0})])),chain:()=>this.createChain(i,r)}}buildProps(t,o=true){let{rawCommands:n,editor:r,state:i}=this,{view:s}=r,l={tr:t,editor:r,view:s,state:cf({state:i,transaction:t}),dispatch:o?()=>{}:void 0,chain:()=>this.createChain(t,o),can:()=>this.createCan(t),get commands(){return Object.fromEntries(Object.entries(n).map(([a,u])=>[a,(...c)=>u(...c)(l)]))}};return l}};function dt(e,t,o){return e.config[t]===void 0&&e.parent?dt(e.parent,t,o):typeof e.config[t]=="function"?e.config[t].bind({...o,parent:e.parent?dt(e.parent,t,o):null}):e.config[t]}function bC(e){let t=e.filter(r=>r.type==="extension"),o=e.filter(r=>r.type==="node"),n=e.filter(r=>r.type==="mark");return {baseExtensions:t,nodeExtensions:o,markExtensions:n}}function rt(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 uf(...e){return e.filter(t=>!!t).reduce((t,o)=>{let n={...t};return Object.entries(o).forEach(([r,i])=>{if(!n[r]){n[r]=i;return}if(r==="class"){let l=i?i.split(" "):[],a=n[r]?n[r].split(" "):[],u=l.filter(c=>!a.includes(c));n[r]=[...a,...u].join(" ");}else if(r==="style"){let l=i?i.split(";").map(c=>c.trim()).filter(Boolean):[],a=n[r]?n[r].split(";").map(c=>c.trim()).filter(Boolean):[],u=new Map;a.forEach(c=>{let[p,f]=c.split(":").map(m=>m.trim());u.set(p,f);}),l.forEach(c=>{let[p,f]=c.split(":").map(m=>m.trim());u.set(p,f);}),n[r]=Array.from(u.entries()).map(([c,p])=>`${c}: ${p}`).join("; ");}else n[r]=i;}),n},{})}function yC(e){return typeof e=="function"}function nt(e,t=void 0,...o){return yC(e)?t?e.bind(t)(...o):e(...o):e}function vC(e){return Object.prototype.toString.call(e)==="[object RegExp]"}var Ta=class{constructor(t){this.find=t.find,this.handler=t.handler;}};var xl=class{constructor(t){this.find=t.find,this.handler=t.handler;}};function SC(e){return Object.prototype.toString.call(e).slice(8,-1)}function va(e){return SC(e)!=="Object"?false:e.constructor===Object&&Object.getPrototypeOf(e)===Object.prototype}function Pa(e,t){let o={...e};return va(e)&&va(t)&&Object.keys(t).forEach(n=>{va(t[n])&&va(e[n])?o[n]=Pa(e[n],t[n]):o[n]=t[n];}),o}var ao=class e{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(dt(this,"addOptions",{name:this.name}))),this.storage=nt(dt(this,"addStorage",{name:this.name,options:this.options}))||{};}static create(t={}){return new e(t)}configure(t={}){let o=this.extend({...this.config,addOptions:()=>Pa(this.options,t)});return o.name=this.name,o.parent=this.parent,o}extend(t={}){let o=new e({...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(dt(o,"addOptions",{name:o.name})),o.storage=nt(dt(o,"addStorage",{name:o.name,options:o.options})),o}};function xC(e,t,o){let{from:n,to:r}=t,{blockSeparator:i=`
10
-
11
- `,textSerializers:s={}}=o||{},l="";return e.nodesBetween(n,r,(a,u,c,p)=>{var f;a.isBlock&&u>n&&(l+=i);let m=s?.[a.type.name];if(m)return c&&(l+=m({node:a,pos:u,parent:c,index:p,range:t})),false;a.isText&&(l+=(f=a?.text)===null||f===void 0?void 0:f.slice(Math.max(n,u)-u,r-u));}),l}function CC(e){return Object.fromEntries(Object.entries(e.nodes).filter(([,t])=>t.spec.toText).map(([t,o])=>[t,o.spec.toText]))}ao.create({name:"clipboardTextSerializer",addOptions(){return {blockSeparator:void 0}},addProseMirrorPlugins(){return [new Plugin({key:new PluginKey("clipboardTextSerializer"),props:{clipboardTextSerializer:()=>{let{editor:e}=this,{state:t,schema:o}=e,{doc:n,selection:r}=t,{ranges:i}=r,s=Math.min(...i.map(c=>c.$from.pos)),l=Math.max(...i.map(c=>c.$to.pos)),a=CC(o);return xC(n,{from:s,to:l},{...this.options.blockSeparator!==void 0?{blockSeparator:this.options.blockSeparator}:{},textSerializers:a})}}})]}});var kC=()=>({editor:e,view:t})=>(requestAnimationFrame(()=>{var o;e.isDestroyed||(t.dom.blur(),(o=window?.getSelection())===null||o===void 0||o.removeAllRanges());}),true),TC=(e=false)=>({commands:t})=>t.setContent("",e),wC=()=>({state:e,tr:t,dispatch:o})=>{let{selection:n}=t,{ranges:r}=n;return o&&r.forEach(({$from:i,$to:s})=>{e.doc.nodesBetween(i.pos,s.pos,(l,a)=>{if(l.type.isText)return;let{doc:u,mapping:c}=t,p=u.resolve(c.map(a)),f=u.resolve(c.map(a+l.nodeSize)),m=p.blockRange(f);if(!m)return;let g=liftTarget(m);if(l.type.isTextblock){let{defaultType:S}=p.parent.contentMatchAt(p.index());t.setNodeMarkup(m.start,S);}(g||g===0)&&t.lift(m,g);});}),true},EC=e=>t=>e(t),IC=()=>({state:e,dispatch:t})=>createParagraphNear(e,t),AC=(e,t)=>({editor:o,tr:n})=>{let{state:r}=o,i=r.doc.slice(e.from,e.to);n.deleteRange(e.from,e.to);let s=n.mapping.map(t);return n.insert(s,i.content),n.setSelection(new TextSelection(n.doc.resolve(s-1))),true},PC=()=>({tr:e,dispatch:t})=>{let{selection:o}=e,n=o.$anchor.node();if(n.content.size>0)return false;let r=e.selection.$anchor;for(let i=r.depth;i>0;i-=1)if(r.node(i).type===n.type){if(t){let l=r.before(i),a=r.after(i);e.delete(l,a).scrollIntoView();}return true}return false},RC=e=>({tr:t,state:o,dispatch:n})=>{let r=rt(e,o.schema),i=t.selection.$anchor;for(let s=i.depth;s>0;s-=1)if(i.node(s).type===r){if(n){let a=i.before(s),u=i.after(s);t.delete(a,u).scrollIntoView();}return true}return false},OC=e=>({tr:t,dispatch:o})=>{let{from:n,to:r}=e;return o&&t.delete(n,r),true},MC=()=>({state:e,dispatch:t})=>deleteSelection(e,t),DC=()=>({commands:e})=>e.keyboardShortcut("Enter"),LC=()=>({state:e,dispatch:t})=>exitCode(e,t);function wa(e,t,o={strict:true}){let n=Object.keys(t);return n.length?n.every(r=>o.strict?t[r]===e[r]:vC(t[r])?t[r].test(e[r]):t[r]===e[r]):true}function Cl(e,t,o={}){return e.find(n=>n.type===t&&wa(n.attrs,o))}function BC(e,t,o={}){return !!Cl(e,t,o)}function kl(e,t,o={}){if(!e||!t)return;let n=e.parent.childAfter(e.parentOffset);if(e.parentOffset===n.offset&&n.offset!==0&&(n=e.parent.childBefore(e.parentOffset)),!n.node)return;let r=Cl([...n.node.marks],t,o);if(!r)return;let i=n.index,s=e.start()+n.offset,l=i+1,a=s+n.node.nodeSize;for(Cl([...n.node.marks],t,o);i>0&&r.isInSet(e.parent.child(i-1).marks);)i-=1,s-=e.parent.child(i).nodeSize;for(;l<e.parent.childCount&&BC([...e.parent.child(l).marks],t,o);)a+=e.parent.child(l).nodeSize,l+=1;return {from:s,to:a}}function zo(e,t){if(typeof e=="string"){if(!t.marks[e])throw Error(`There is no mark type named '${e}'. Maybe you forgot to add the extension?`);return t.marks[e]}return e}var zC=(e,t={})=>({tr:o,state:n,dispatch:r})=>{let i=zo(e,n.schema),{doc:s,selection:l}=o,{$from:a,from:u,to:c}=l;if(r){let p=kl(a,i,t);if(p&&p.from<=u&&p.to>=c){let f=TextSelection.create(s,p.from,p.to);o.setSelection(f);}}return true},NC=e=>t=>{let o=typeof e=="function"?e(t):e;for(let n=0;n<o.length;n+=1)if(o[n](t))return true;return false};function pf(e){return e instanceof TextSelection}function an(e=0,t=0,o=0){return Math.min(Math.max(e,t),o)}function VC(e,t=null){if(!t)return null;let o=Selection.atStart(e),n=Selection.atEnd(e);if(t==="start"||t===true)return o;if(t==="end")return n;let r=o.from,i=n.to;return t==="all"?TextSelection.create(e,an(0,r,i),an(e.content.size,r,i)):TextSelection.create(e,an(t,r,i),an(t,r,i))}function Tl(){return ["iPad Simulator","iPhone Simulator","iPod Simulator","iPad","iPhone","iPod"].includes(navigator.platform)||navigator.userAgent.includes("Mac")&&"ontouchend"in document}var FC=(e=null,t={})=>({editor:o,view:n,tr:r,dispatch:i})=>{t={scrollIntoView:true,...t};let s=()=>{Tl()&&n.dom.focus(),requestAnimationFrame(()=>{o.isDestroyed||(n.focus(),t?.scrollIntoView&&o.commands.scrollIntoView());});};if(n.hasFocus()&&e===null||e===false)return true;if(i&&e===null&&!pf(o.state.selection))return s(),true;let l=VC(r.doc,e)||o.state.selection,a=o.state.selection.eq(l);return i&&(a||r.setSelection(l),a&&r.storedMarks&&r.setStoredMarks(r.storedMarks),s()),true},_C=(e,t)=>o=>e.every((n,r)=>t(n,{...o,index:r})),$C=(e,t)=>({tr:o,commands:n})=>n.insertContentAt({from:o.selection.from,to:o.selection.to},e,t),df=e=>{let t=e.childNodes;for(let o=t.length-1;o>=0;o-=1){let n=t[o];n.nodeType===3&&n.nodeValue&&/^(\n\s\s|\n)$/.test(n.nodeValue)?e.removeChild(n):n.nodeType===1&&df(n);}return e};function Sa(e){let t=`<body>${e}</body>`,o=new window.DOMParser().parseFromString(t,"text/html").body;return df(o)}function Ea(e,t,o){o={slice:true,parseOptions:{},...o};let n=typeof e=="object"&&e!==null,r=typeof e=="string";if(n)try{if(Array.isArray(e)&&e.length>0)return Fragment$2.fromArray(e.map(l=>t.nodeFromJSON(l)));let s=t.nodeFromJSON(e);return o.errorOnInvalidContent&&s.check(),s}catch(i){if(o.errorOnInvalidContent)throw new Error("[tiptap error]: Invalid JSON content",{cause:i});return console.warn("[tiptap warn]: Invalid content.","Passed value:",e,"Error:",i),Ea("",t,o)}if(r){if(o.errorOnInvalidContent){let s=false,l="",a=new Schema({topNode:t.spec.topNode,marks:t.spec.marks,nodes:t.spec.nodes.append({__tiptap__private__unknown__catch__all__node:{content:"inline*",group:"block",parseDOM:[{tag:"*",getAttrs:u=>(s=true,l=typeof u=="string"?u:u.outerHTML,null)}]}})});if(o.slice?DOMParser.fromSchema(a).parseSlice(Sa(e),o.parseOptions):DOMParser.fromSchema(a).parse(Sa(e),o.parseOptions),o.errorOnInvalidContent&&s)throw new Error("[tiptap error]: Invalid HTML content",{cause:new Error(`Invalid element found: ${l}`)})}let i=DOMParser.fromSchema(t);return o.slice?i.parseSlice(Sa(e),o.parseOptions).content:i.parse(Sa(e),o.parseOptions)}return Ea("",t,o)}function GC(e,t,o){let n=e.steps.length-1;if(n<t)return;let r=e.steps[n];if(!(r instanceof ReplaceStep||r instanceof ReplaceAroundStep))return;let i=e.mapping.maps[n],s=0;i.forEach((l,a,u,c)=>{s===0&&(s=c);}),e.setSelection(Selection.near(e.doc.resolve(s),o));}var UC=e=>!("type"in e),HC=(e,t,o)=>({tr:n,dispatch:r,editor:i})=>{var s;if(r){o={parseOptions:{},updateSelection:true,applyInputRules:false,applyPasteRules:false,...o};let l;try{l=Ea(t,i.schema,{parseOptions:{preserveWhitespace:"full",...o.parseOptions},errorOnInvalidContent:(s=o.errorOnInvalidContent)!==null&&s!==void 0?s:i.options.enableContentCheck});}catch(g){return i.emit("contentError",{editor:i,error:g,disableCollaboration:()=>{console.error("[tiptap error]: Unable to disable collaboration at this point in time");}}),false}let{from:a,to:u}=typeof e=="number"?{from:e,to:e}:{from:e.from,to:e.to},c=true,p=true;if((UC(l)?l:[l]).forEach(g=>{g.check(),c=c?g.isText&&g.marks.length===0:false,p=p?g.isBlock:false;}),a===u&&p){let{parent:g}=n.doc.resolve(a);g.isTextblock&&!g.type.spec.code&&!g.childCount&&(a-=1,u+=1);}let m;c?(Array.isArray(t)?m=t.map(g=>g.text||"").join(""):typeof t=="object"&&t&&t.text?m=t.text:m=t,n.insertText(m,a,u)):(m=l,n.replaceWith(a,u,m)),o.updateSelection&&GC(n,n.steps.length-1,-1),o.applyInputRules&&n.setMeta("applyInputRules",{from:a,text:m}),o.applyPasteRules&&n.setMeta("applyPasteRules",{from:a,text:m});}return true},jC=()=>({state:e,dispatch:t})=>joinUp(e,t),WC=()=>({state:e,dispatch:t})=>joinDown(e,t),KC=()=>({state:e,dispatch:t})=>joinBackward(e,t),qC=()=>({state:e,dispatch:t})=>joinForward(e,t),YC=()=>({state:e,dispatch:t,tr:o})=>{try{let n=joinPoint(e.doc,e.selection.$from.pos,-1);return n==null?!1:(o.join(n,2),t&&t(o),!0)}catch{return false}},XC=()=>({state:e,dispatch:t,tr:o})=>{try{let n=joinPoint(e.doc,e.selection.$from.pos,1);return n==null?!1:(o.join(n,2),t&&t(o),!0)}catch{return false}},JC=()=>({state:e,dispatch:t})=>joinTextblockBackward(e,t),QC=()=>({state:e,dispatch:t})=>joinTextblockForward(e,t);function ff(){return typeof navigator<"u"?/Mac/.test(navigator.platform):false}function ZC(e){let t=e.split(/-(?!$)/),o=t[t.length-1];o==="Space"&&(o=" ");let n,r,i,s;for(let l=0;l<t.length-1;l+=1){let a=t[l];if(/^(cmd|meta|m)$/i.test(a))s=true;else if(/^a(lt)?$/i.test(a))n=true;else if(/^(c|ctrl|control)$/i.test(a))r=true;else if(/^s(hift)?$/i.test(a))i=true;else if(/^mod$/i.test(a))Tl()||ff()?s=true:r=true;else throw new Error(`Unrecognized modifier name: ${a}`)}return n&&(o=`Alt-${o}`),r&&(o=`Ctrl-${o}`),s&&(o=`Meta-${o}`),i&&(o=`Shift-${o}`),o}var ek=e=>({editor:t,view:o,tr:n,dispatch:r})=>{let i=ZC(e).split(/-(?!$)/),s=i.find(u=>!["Alt","Ctrl","Meta","Shift"].includes(u)),l=new KeyboardEvent("keydown",{key:s==="Space"?" ":s,altKey:i.includes("Alt"),ctrlKey:i.includes("Ctrl"),metaKey:i.includes("Meta"),shiftKey:i.includes("Shift"),bubbles:true,cancelable:true}),a=t.captureTransaction(()=>{o.someProp("handleKeyDown",u=>u(o,l));});return a?.steps.forEach(u=>{let c=u.map(n.mapping);c&&r&&n.maybeStep(c);}),true};function wl(e,t,o={}){let{from:n,to:r,empty:i}=e.selection,s=t?rt(t,e.schema):null,l=[];e.doc.nodesBetween(n,r,(p,f)=>{if(p.isText)return;let m=Math.max(n,f),g=Math.min(r,f+p.nodeSize);l.push({node:p,from:m,to:g});});let a=r-n,u=l.filter(p=>s?s.name===p.node.type.name:true).filter(p=>wa(p.node.attrs,o,{strict:false}));return i?!!u.length:u.reduce((p,f)=>p+f.to-f.from,0)>=a}var tk=(e,t={})=>({state:o,dispatch:n})=>{let r=rt(e,o.schema);return wl(o,r,t)?lift(o,n):false},ok=()=>({state:e,dispatch:t})=>liftEmptyBlock(e,t),nk=e=>({state:t,dispatch:o})=>{let n=rt(e,t.schema);return liftListItem(n)(t,o)},rk=()=>({state:e,dispatch:t})=>newlineInCode(e,t);function mf(e,t){return t.nodes[e]?"node":t.marks[e]?"mark":null}function of(e,t){let o=typeof t=="string"?[t]:t;return Object.keys(e).reduce((n,r)=>(o.includes(r)||(n[r]=e[r]),n),{})}var ik=(e,t)=>({tr:o,state:n,dispatch:r})=>{let i=null,s=null,l=mf(typeof e=="string"?e:e.name,n.schema);return l?(l==="node"&&(i=rt(e,n.schema)),l==="mark"&&(s=zo(e,n.schema)),r&&o.selection.ranges.forEach(a=>{n.doc.nodesBetween(a.$from.pos,a.$to.pos,(u,c)=>{i&&i===u.type&&o.setNodeMarkup(c,void 0,of(u.attrs,t)),s&&u.marks.length&&u.marks.forEach(p=>{s===p.type&&o.addMark(c,c+u.nodeSize,s.create(of(p.attrs,t)));});});}),true):false},ak=()=>({tr:e,dispatch:t})=>(t&&e.scrollIntoView(),true),sk=()=>({tr:e,commands:t})=>t.setTextSelection({from:0,to:e.doc.content.size}),lk=()=>({state:e,dispatch:t})=>selectNodeBackward(e,t),ck=()=>({state:e,dispatch:t})=>selectNodeForward(e,t),uk=()=>({state:e,dispatch:t})=>selectParentNode(e,t),pk=()=>({state:e,dispatch:t})=>selectTextblockEnd(e,t),dk=()=>({state:e,dispatch:t})=>selectTextblockStart(e,t);function fk(e,t,o={},n={}){return Ea(e,t,{slice:false,parseOptions:o,errorOnInvalidContent:n.errorOnInvalidContent})}var mk=(e,t=false,o={},n={})=>({editor:r,tr:i,dispatch:s,commands:l})=>{var a,u;let{doc:c}=i;if(o.preserveWhitespace!=="full"){let p=fk(e,r.schema,o,{errorOnInvalidContent:(a=n.errorOnInvalidContent)!==null&&a!==void 0?a:r.options.enableContentCheck});return s&&i.replaceWith(0,c.content.size,p).setMeta("preventUpdate",!t),true}return s&&i.setMeta("preventUpdate",!t),l.insertContentAt({from:0,to:c.content.size},e,{parseOptions:o,errorOnInvalidContent:(u=n.errorOnInvalidContent)!==null&&u!==void 0?u:r.options.enableContentCheck})};function gk(e,t){let o=zo(t,e.schema),{from:n,to:r,empty:i}=e.selection,s=[];i?(e.storedMarks&&s.push(...e.storedMarks),s.push(...e.selection.$head.marks())):e.doc.nodesBetween(n,r,a=>{s.push(...a.marks);});let l=s.find(a=>a.type.name===o.name);return l?{...l.attrs}:{}}function hk(e){for(let t=0;t<e.edgeCount;t+=1){let{type:o}=e.edge(t);if(o.isTextblock&&!o.hasRequiredAttrs())return o}return null}function bk(e,t){for(let o=e.depth;o>0;o-=1){let n=e.node(o);if(t(n))return {pos:o>0?e.before(o):0,start:e.start(o),depth:o,node:n}}}function El(e){return t=>bk(t.$from,e)}function gf(e,t,o){let n=[];return e===t?o.resolve(e).marks().forEach(r=>{let i=o.resolve(e),s=kl(i,r.type);s&&n.push({mark:r,...s});}):o.nodesBetween(e,t,(r,i)=>{!r||r?.nodeSize===void 0||n.push(...r.marks.map(s=>({from:i,to:i+r.nodeSize,mark:s})));}),n}function ka(e,t,o){return Object.fromEntries(Object.entries(o).filter(([n])=>{let r=e.find(i=>i.type===t&&i.name===n);return r?r.attribute.keepOnSplit:false}))}function yk(e,t,o={}){let{empty:n,ranges:r}=e.selection,i=t?zo(t,e.schema):null;if(n)return !!(e.storedMarks||e.selection.$from.marks()).filter(p=>i?i.name===p.type.name:true).find(p=>wa(p.attrs,o,{strict:false}));let s=0,l=[];if(r.forEach(({$from:p,$to:f})=>{let m=p.pos,g=f.pos;e.doc.nodesBetween(m,g,(S,v)=>{if(!S.isText&&!S.marks.length)return;let h=Math.max(m,v),b=Math.min(g,v+S.nodeSize),C=b-h;s+=C,l.push(...S.marks.map(d=>({mark:d,from:h,to:b})));});}),s===0)return false;let a=l.filter(p=>i?i.name===p.mark.type.name:true).filter(p=>wa(p.mark.attrs,o,{strict:false})).reduce((p,f)=>p+f.to-f.from,0),u=l.filter(p=>i?p.mark.type!==i&&p.mark.type.excludes(i):true).reduce((p,f)=>p+f.to-f.from,0);return (a>0?a+u:a)>=s}function nf(e,t){let{nodeExtensions:o}=bC(t),n=o.find(s=>s.name===e);if(!n)return false;let r={name:n.name,options:n.options,storage:n.storage},i=nt(dt(n,"group",r));return typeof i!="string"?false:i.split(" ").includes("list")}function hf(e,{checkChildren:t=true,ignoreWhitespace:o=false}={}){var n;if(o){if(e.type.name==="hardBreak")return true;if(e.isText)return /^\s*$/m.test((n=e.text)!==null&&n!==void 0?n:"")}if(e.isText)return !e.text;if(e.isAtom||e.isLeaf)return false;if(e.content.childCount===0)return true;if(t){let r=true;return e.content.forEach(i=>{r!==false&&(hf(i,{ignoreWhitespace:o,checkChildren:t})||(r=false));}),r}return false}function vk(e,t,o){var n;let{selection:r}=t,i=null;if(pf(r)&&(i=r.$cursor),i){let l=(n=e.storedMarks)!==null&&n!==void 0?n:i.marks();return !!o.isInSet(l)||!l.some(a=>a.type.excludes(o))}let{ranges:s}=r;return s.some(({$from:l,$to:a})=>{let u=l.depth===0?e.doc.inlineContent&&e.doc.type.allowsMarkType(o):false;return e.doc.nodesBetween(l.pos,a.pos,(c,p,f)=>{if(u)return false;if(c.isInline){let m=!f||f.type.allowsMarkType(o),g=!!o.isInSet(c.marks)||!c.marks.some(S=>S.type.excludes(o));u=m&&g;}return !u}),u})}var Sk=(e,t={})=>({tr:o,state:n,dispatch:r})=>{let{selection:i}=o,{empty:s,ranges:l}=i,a=zo(e,n.schema);if(r)if(s){let u=gk(n,a);o.addStoredMark(a.create({...u,...t}));}else l.forEach(u=>{let c=u.$from.pos,p=u.$to.pos;n.doc.nodesBetween(c,p,(f,m)=>{let g=Math.max(m,c),S=Math.min(m+f.nodeSize,p);f.marks.find(h=>h.type===a)?f.marks.forEach(h=>{a===h.type&&o.addMark(g,S,a.create({...h.attrs,...t}));}):o.addMark(g,S,a.create(t));});});return vk(n,o,a)},xk=(e,t)=>({tr:o})=>(o.setMeta(e,t),true),Ck=(e,t={})=>({state:o,dispatch:n,chain:r})=>{let i=rt(e,o.schema);return i.isTextblock?r().command(({commands:s})=>setBlockType(i,t)(o)?true:s.clearNodes()).command(({state:s})=>setBlockType(i,t)(s,n)).run():(console.warn('[tiptap warn]: Currently "setNode()" only supports text block nodes.'),false)},kk=e=>({tr:t,dispatch:o})=>{if(o){let{doc:n}=t,r=an(e,0,n.content.size),i=NodeSelection.create(n,r);t.setSelection(i);}return true},Tk=e=>({tr:t,dispatch:o})=>{if(o){let{doc:n}=t,{from:r,to:i}=typeof e=="number"?{from:e,to:e}:e,s=TextSelection.atStart(n).from,l=TextSelection.atEnd(n).to,a=an(r,s,l),u=an(i,s,l),c=TextSelection.create(n,a,u);t.setSelection(c);}return true},wk=e=>({state:t,dispatch:o})=>{let n=rt(e,t.schema);return sinkListItem(n)(t,o)};function rf(e,t){let o=e.storedMarks||e.selection.$to.parentOffset&&e.selection.$from.marks();if(o){let n=o.filter(r=>t?.includes(r.type.name));e.tr.ensureMarks(n);}}var Ek=({keepMarks:e=true}={})=>({tr:t,state:o,dispatch:n,editor:r})=>{let{selection:i,doc:s}=t,{$from:l,$to:a}=i,u=r.extensionManager.attributes,c=ka(u,l.node().type.name,l.node().attrs);if(i instanceof NodeSelection&&i.node.isBlock)return !l.parentOffset||!canSplit(s,l.pos)?false:(n&&(e&&rf(o,r.extensionManager.splittableMarks),t.split(l.pos).scrollIntoView()),true);if(!l.parent.isBlock)return false;let p=a.parentOffset===a.parent.content.size,f=l.depth===0?void 0:hk(l.node(-1).contentMatchAt(l.indexAfter(-1))),m=p&&f?[{type:f,attrs:c}]:void 0,g=canSplit(t.doc,t.mapping.map(l.pos),1,m);if(!m&&!g&&canSplit(t.doc,t.mapping.map(l.pos),1,f?[{type:f}]:void 0)&&(g=true,m=f?[{type:f,attrs:c}]:void 0),n){if(g&&(i instanceof TextSelection&&t.deleteSelection(),t.split(t.mapping.map(l.pos),1,m),f&&!p&&!l.parentOffset&&l.parent.type!==f)){let S=t.mapping.map(l.before()),v=t.doc.resolve(S);l.node(-1).canReplaceWith(v.index(),v.index()+1,f)&&t.setNodeMarkup(t.mapping.map(l.before()),f);}e&&rf(o,r.extensionManager.splittableMarks),t.scrollIntoView();}return g},Ik=(e,t={})=>({tr:o,state:n,dispatch:r,editor:i})=>{var s;let l=rt(e,n.schema),{$from:a,$to:u}=n.selection,c=n.selection.node;if(c&&c.isBlock||a.depth<2||!a.sameParent(u))return false;let p=a.node(-1);if(p.type!==l)return false;let f=i.extensionManager.attributes;if(a.parent.content.size===0&&a.node(-1).childCount===a.indexAfter(-1)){if(a.depth===2||a.node(-3).type!==l||a.index(-2)!==a.node(-2).childCount-1)return false;if(r){let h=Fragment$2.empty,b=a.index(-1)?1:a.index(-2)?2:3;for(let R=a.depth-b;R>=a.depth-3;R-=1)h=Fragment$2.from(a.node(R).copy(h));let C=a.indexAfter(-1)<a.node(-2).childCount?1:a.indexAfter(-2)<a.node(-3).childCount?2:3,d={...ka(f,a.node().type.name,a.node().attrs),...t},y=((s=l.contentMatch.defaultType)===null||s===void 0?void 0:s.createAndFill(d))||void 0;h=h.append(Fragment$2.from(l.createAndFill(null,y)||void 0));let x=a.before(a.depth-(b-1));o.replace(x,a.after(-C),new Slice(h,4-b,0));let k=-1;o.doc.nodesBetween(x,o.doc.content.size,(R,B)=>{if(k>-1)return false;R.isTextblock&&R.content.size===0&&(k=B+1);}),k>-1&&o.setSelection(TextSelection.near(o.doc.resolve(k))),o.scrollIntoView();}return true}let m=u.pos===a.end()?p.contentMatchAt(0).defaultType:null,g={...ka(f,p.type.name,p.attrs),...t},S={...ka(f,a.node().type.name,a.node().attrs),...t};o.delete(a.pos,u.pos);let v=m?[{type:l,attrs:g},{type:m,attrs:S}]:[{type:l,attrs:g}];if(!canSplit(o.doc,a.pos,2))return false;if(r){let{selection:h,storedMarks:b}=n,{splittableMarks:C}=i.extensionManager,d=b||h.$to.parentOffset&&h.$from.marks();if(o.split(a.pos,2,v).scrollIntoView(),!d||!r)return true;let y=d.filter(x=>C.includes(x.type.name));o.ensureMarks(y);}return true},yl=(e,t)=>{let o=El(s=>s.type===t)(e.selection);if(!o)return true;let n=e.doc.resolve(Math.max(0,o.pos-1)).before(o.depth);if(n===void 0)return true;let r=e.doc.nodeAt(n);return o.node.type===r?.type&&canJoin(e.doc,o.pos)&&e.join(o.pos),true},vl=(e,t)=>{let o=El(s=>s.type===t)(e.selection);if(!o)return true;let n=e.doc.resolve(o.start).after(o.depth);if(n===void 0)return true;let r=e.doc.nodeAt(n);return o.node.type===r?.type&&canJoin(e.doc,n)&&e.join(n),true},Ak=(e,t,o,n={})=>({editor:r,tr:i,state:s,dispatch:l,chain:a,commands:u,can:c})=>{let{extensions:p,splittableMarks:f}=r.extensionManager,m=rt(e,s.schema),g=rt(t,s.schema),{selection:S,storedMarks:v}=s,{$from:h,$to:b}=S,C=h.blockRange(b),d=v||S.$to.parentOffset&&S.$from.marks();if(!C)return false;let y=El(x=>nf(x.type.name,p))(S);if(C.depth>=1&&y&&C.depth-y.depth<=1){if(y.node.type===m)return u.liftListItem(g);if(nf(y.node.type.name,p)&&m.validContent(y.node.content)&&l)return a().command(()=>(i.setNodeMarkup(y.pos,m),true)).command(()=>yl(i,m)).command(()=>vl(i,m)).run()}return !o||!d||!l?a().command(()=>c().wrapInList(m,n)?true:u.clearNodes()).wrapInList(m,n).command(()=>yl(i,m)).command(()=>vl(i,m)).run():a().command(()=>{let x=c().wrapInList(m,n),k=d.filter(R=>f.includes(R.type.name));return i.ensureMarks(k),x?true:u.clearNodes()}).wrapInList(m,n).command(()=>yl(i,m)).command(()=>vl(i,m)).run()},Pk=(e,t={},o={})=>({state:n,commands:r})=>{let{extendEmptyMarkRange:i=false}=o,s=zo(e,n.schema);return yk(n,s,t)?r.unsetMark(s,{extendEmptyMarkRange:i}):r.setMark(s,t)},Rk=(e,t,o={})=>({state:n,commands:r})=>{let i=rt(e,n.schema),s=rt(t,n.schema),l=wl(n,i,o),a;return n.selection.$anchor.sameParent(n.selection.$head)&&(a=n.selection.$anchor.parent.attrs),l?r.setNode(s,a):r.setNode(i,{...a,...o})},Ok=(e,t={})=>({state:o,commands:n})=>{let r=rt(e,o.schema);return wl(o,r,t)?n.lift(r):n.wrapIn(r,t)},Mk=()=>({state:e,dispatch:t})=>{let o=e.plugins;for(let n=0;n<o.length;n+=1){let r=o[n],i;if(r.spec.isInputRules&&(i=r.getState(e))){if(t){let s=e.tr,l=i.transform;for(let a=l.steps.length-1;a>=0;a-=1)s.step(l.steps[a].invert(l.docs[a]));if(i.text){let a=s.doc.resolve(i.from).marks();s.replaceWith(i.from,i.to,e.schema.text(i.text,a));}else s.delete(i.from,i.to);}return true}}return false},Dk=()=>({tr:e,dispatch:t})=>{let{selection:o}=e,{empty:n,ranges:r}=o;return n||t&&r.forEach(i=>{e.removeMark(i.$from.pos,i.$to.pos);}),true},Lk=(e,t={})=>({tr:o,state:n,dispatch:r})=>{var i;let{extendEmptyMarkRange:s=false}=t,{selection:l}=o,a=zo(e,n.schema),{$from:u,empty:c,ranges:p}=l;if(!r)return true;if(c&&s){let{from:f,to:m}=l,g=(i=u.marks().find(v=>v.type===a))===null||i===void 0?void 0:i.attrs,S=kl(u,a,g);S&&(f=S.from,m=S.to),o.removeMark(f,m,a);}else p.forEach(f=>{o.removeMark(f.$from.pos,f.$to.pos,a);});return o.removeStoredMark(a),true},Bk=(e,t={})=>({tr:o,state:n,dispatch:r})=>{let i=null,s=null,l=mf(typeof e=="string"?e:e.name,n.schema);return l?(l==="node"&&(i=rt(e,n.schema)),l==="mark"&&(s=zo(e,n.schema)),r&&o.selection.ranges.forEach(a=>{let u=a.$from.pos,c=a.$to.pos;n.doc.nodesBetween(u,c,(p,f)=>{i&&i===p.type&&o.setNodeMarkup(f,void 0,{...p.attrs,...t}),s&&p.marks.length&&p.marks.forEach(m=>{if(s===m.type){let g=Math.max(f,u),S=Math.min(f+p.nodeSize,c);o.addMark(g,S,s.create({...m.attrs,...t}));}});});}),true):false},zk=(e,t={})=>({state:o,dispatch:n})=>{let r=rt(e,o.schema);return wrapIn(r,t)(o,n)},Nk=(e,t={})=>({state:o,dispatch:n})=>{let r=rt(e,o.schema);return wrapInList(r,t)(o,n)},Vk=Object.freeze({__proto__:null,blur:kC,clearContent:TC,clearNodes:wC,command:EC,createParagraphNear:IC,cut:AC,deleteCurrentNode:PC,deleteNode:RC,deleteRange:OC,deleteSelection:MC,enter:DC,exitCode:LC,extendMarkRange:zC,first:NC,focus:FC,forEach:_C,insertContent:$C,insertContentAt:HC,joinBackward:KC,joinDown:WC,joinForward:qC,joinItemBackward:YC,joinItemForward:XC,joinTextblockBackward:JC,joinTextblockForward:QC,joinUp:jC,keyboardShortcut:ek,lift:tk,liftEmptyBlock:ok,liftListItem:nk,newlineInCode:rk,resetAttributes:ik,scrollIntoView:ak,selectAll:sk,selectNodeBackward:lk,selectNodeForward:ck,selectParentNode:uk,selectTextblockEnd:pk,selectTextblockStart:dk,setContent:mk,setMark:Sk,setMeta:xk,setNode:Ck,setNodeSelection:kk,setTextSelection:Tk,sinkListItem:wk,splitBlock:Ek,splitListItem:Ik,toggleList:Ak,toggleMark:Pk,toggleNode:Rk,toggleWrap:Ok,undoInputRule:Mk,unsetAllMarks:Dk,unsetMark:Lk,updateAttributes:Bk,wrapIn:zk,wrapInList:Nk});ao.create({name:"commands",addCommands(){return {...Vk}}});ao.create({name:"editable",addProseMirrorPlugins(){return [new Plugin({key:new PluginKey("editable"),props:{editable:()=>this.editor.options.editable}})]}});ao.create({name:"focusEvents",addProseMirrorPlugins(){let{editor:e}=this;return [new Plugin({key:new PluginKey("focusEvents"),props:{handleDOMEvents:{focus:(t,o)=>{e.isFocused=true;let n=e.state.tr.setMeta("focus",{event:o}).setMeta("addToHistory",false);return t.dispatch(n),false},blur:(t,o)=>{e.isFocused=false;let n=e.state.tr.setMeta("blur",{event:o}).setMeta("addToHistory",false);return t.dispatch(n),false}}}})]}});ao.create({name:"keymap",addKeyboardShortcuts(){let e=()=>this.editor.commands.first(({commands:s})=>[()=>s.undoInputRule(),()=>s.command(({tr:l})=>{let{selection:a,doc:u}=l,{empty:c,$anchor:p}=a,{pos:f,parent:m}=p,g=p.parent.isTextblock&&f>0?l.doc.resolve(f-1):p,S=g.parent.type.spec.isolating,v=p.pos-p.parentOffset,h=S&&g.parent.childCount===1?v===p.pos:Selection.atStart(u).from===f;return !c||!m.type.isTextblock||m.textContent.length||!h||h&&p.parent.type.name==="paragraph"?false:s.clearNodes()}),()=>s.deleteSelection(),()=>s.joinBackward(),()=>s.selectNodeBackward()]),t=()=>this.editor.commands.first(({commands:s})=>[()=>s.deleteSelection(),()=>s.deleteCurrentNode(),()=>s.joinForward(),()=>s.selectNodeForward()]),n={Enter:()=>this.editor.commands.first(({commands:s})=>[()=>s.newlineInCode(),()=>s.createParagraphNear(),()=>s.liftEmptyBlock(),()=>s.splitBlock()]),"Mod-Enter":()=>this.editor.commands.exitCode(),Backspace:e,"Mod-Backspace":e,"Shift-Backspace":e,Delete:t,"Mod-Delete":t,"Mod-a":()=>this.editor.commands.selectAll()},r={...n},i={...n,"Ctrl-h":e,"Alt-Backspace":e,"Ctrl-d":t,"Ctrl-Alt-Backspace":t,"Alt-Delete":t,"Alt-d":t,"Ctrl-a":()=>this.editor.commands.selectTextblockStart(),"Ctrl-e":()=>this.editor.commands.selectTextblockEnd()};return Tl()||ff()?i:r},addProseMirrorPlugins(){return [new Plugin({key:new PluginKey("clearDocument"),appendTransaction:(e,t,o)=>{let n=e.some(S=>S.docChanged)&&!t.doc.eq(o.doc),r=e.some(S=>S.getMeta("preventClearDocument"));if(!n||r)return;let{empty:i,from:s,to:l}=t.selection,a=Selection.atStart(t.doc).from,u=Selection.atEnd(t.doc).to;if(i||!(s===a&&l===u)||!hf(o.doc))return;let f=o.tr,m=cf({state:o,transaction:f}),{commands:g}=new Sl({editor:this.editor,state:m});if(g.clearNodes(),!!f.steps.length)return f}})]}});ao.create({name:"tabindex",addProseMirrorPlugins(){return [new Plugin({key:new PluginKey("tabindex"),props:{attributes:()=>this.editor.isEditable?{tabindex:"0"}:{}}})]}});function Il(e){return new Ta({find:e.find,handler:({state:t,range:o,match:n})=>{let r=nt(e.getAttributes,void 0,n);if(r===false||r===null)return null;let{tr:i}=t,s=n[n.length-1],l=n[0];if(s){let a=l.search(/\S/),u=o.from+l.indexOf(s),c=u+s.length;if(gf(o.from,o.to,t.doc).filter(m=>m.mark.type.excluded.find(S=>S===e.type&&S!==m.mark.type)).filter(m=>m.to>u).length)return null;c<o.to&&i.delete(c,o.to),u>o.from&&i.delete(o.from+a,u);let f=o.from+a+s.length;i.addMark(o.from+a,f,e.type.create(r||{})),i.removeStoredMark(e.type);}}})}function bf(e){return new Ta({find:e.find,handler:({state:t,range:o,match:n})=>{let r=nt(e.getAttributes,void 0,n)||{},{tr:i}=t,s=o.from,l=o.to,a=e.type.create(r);if(n[1]){let u=n[0].lastIndexOf(n[1]),c=s+u;c>l?c=l:l=c+n[1].length;let p=n[0][n[0].length-1];i.insertText(p,s+n[0].length-1),i.replaceWith(c,l,a);}else if(n[0]){let u=e.type.isInline?s:s-1;i.insert(u,e.type.create(r)).delete(i.mapping.map(s),i.mapping.map(l));}i.scrollIntoView();}})}var Ia=class e{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(dt(this,"addOptions",{name:this.name}))),this.storage=nt(dt(this,"addStorage",{name:this.name,options:this.options}))||{};}static create(t={}){return new e(t)}configure(t={}){let o=this.extend({...this.config,addOptions:()=>Pa(this.options,t)});return o.name=this.name,o.parent=this.parent,o}extend(t={}){let o=new e(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(dt(o,"addOptions",{name:o.name})),o.storage=nt(dt(o,"addStorage",{name:o.name,options:o.options})),o}static handleExit({editor:t,mark:o}){let{tr:n}=t.state,r=t.state.selection.$from;if(r.pos===r.end()){let s=r.marks();if(!!!s.find(u=>u?.type.name===o.name))return false;let a=s.find(u=>u?.type.name===o.name);return a&&n.removeStoredMark(a),n.insertText(" ",r.pos),t.view.dispatch(n),true}return false}},Aa=class e{constructor(t={}){this.type="node",this.name="node",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(dt(this,"addOptions",{name:this.name}))),this.storage=nt(dt(this,"addStorage",{name:this.name,options:this.options}))||{};}static create(t={}){return new e(t)}configure(t={}){let o=this.extend({...this.config,addOptions:()=>Pa(this.options,t)});return o.name=this.name,o.parent=this.parent,o}extend(t={}){let o=new e(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(dt(o,"addOptions",{name:o.name})),o.storage=nt(dt(o,"addStorage",{name:o.name,options:o.options})),o}};function Al(e){return new xl({find:e.find,handler:({state:t,range:o,match:n,pasteEvent:r})=>{let i=nt(e.getAttributes,void 0,n,r);if(i===false||i===null)return null;let{tr:s}=t,l=n[n.length-1],a=n[0],u=o.to;if(l){let c=a.search(/\S/),p=o.from+a.indexOf(l),f=p+l.length;if(gf(o.from,o.to,t.doc).filter(g=>g.mark.type.excluded.find(v=>v===e.type&&v!==g.mark.type)).filter(g=>g.to>p).length)return null;f<o.to&&s.delete(f,o.to),p>o.from&&s.delete(o.from+c,p),u=o.from+c+l.length,s.addMark(o.from+c,u,e.type.create(i||{})),s.removeStoredMark(e.type);}}})}var Fk=/(?:^|\s)(\*\*(?!\s+\*\*)((?:[^*]+))\*\*(?!\s+\*\*))$/,_k=/(?:^|\s)(\*\*(?!\s+\*\*)((?:[^*]+))\*\*(?!\s+\*\*))/g,$k=/(?:^|\s)(__(?!\s+__)((?:[^_]+))__(?!\s+__))$/,Gk=/(?:^|\s)(__(?!\s+__)((?:[^_]+))__(?!\s+__))/g,yf=Ia.create({name:"bold",addOptions(){return {HTMLAttributes:{}}},parseHTML(){return [{tag:"strong"},{tag:"b",getAttrs:e=>e.style.fontWeight!=="normal"&&null},{style:"font-weight",getAttrs:e=>/^(bold(er)?|[5-9]\d{2,})$/.test(e)&&null}]},renderHTML({HTMLAttributes:e}){return ["strong",uf(this.options.HTMLAttributes,e),0]},addCommands(){return {setBold:()=>({commands:e})=>e.setMark(this.name),toggleBold:()=>({commands:e})=>e.toggleMark(this.name),unsetBold:()=>({commands:e})=>e.unsetMark(this.name)}},addKeyboardShortcuts(){return {"Mod-b":()=>this.editor.commands.toggleBold(),"Mod-B":()=>this.editor.commands.toggleBold()}},addInputRules(){return [Il({find:Fk,type:this.type}),Il({find:$k,type:this.type})]},addPasteRules(){return [Al({find:_k,type:this.type}),Al({find:Gk,type:this.type})]}});var Uk=/(?:^|\s)((?:\{\{)([a-zA-Z0-9]+)(?:\}\}))$/,Hk=Aa.create({name:"variable",group:"inline",content:"text*",marks:"_",atom:false,inline:true,selectable:true,addAttributes(){return {varName:{default:"",parseHTML:e=>e.innerText}}},addInputRules(){return [bf({find:Uk,type:this.type,getAttributes:e=>({varName:e[0]})})]},renderHTML({node:e}){return ["code",{class:"bespoke-var"},e.attrs.varName.trim()]},parseHTML(){return [{tag:'code[class="bespoke-var"]'}]},toDOM(){return ["code",{class:"bespoke-var"},0]}}),vf=Hk;var Sf=ao.create({name:"VariablesStorage",addStorage(){return {suggestions:[]}}});var Ce="top",Be="bottom",Pe="right",Ee="left",Ra="auto",No=[Ce,Be,Pe,Ee],xo="start",sn="end",xf="clippingParents",Oa="viewport",qn="popper",Cf="reference",Pl=No.reduce(function(e,t){return e.concat([t+"-"+xo,t+"-"+sn])},[]),Ma=[].concat(No,[Ra]).reduce(function(e,t){return e.concat([t,t+"-"+xo,t+"-"+sn])},[]),jk="beforeRead",Wk="read",Kk="afterRead",qk="beforeMain",Yk="main",Xk="afterMain",Jk="beforeWrite",Qk="write",Zk="afterWrite",kf=[jk,Wk,Kk,qk,Yk,Xk,Jk,Qk,Zk];function $e(e){return e?(e.nodeName||"").toLowerCase():null}function ve(e){if(e==null)return window;if(e.toString()!=="[object Window]"){var t=e.ownerDocument;return t&&t.defaultView||window}return e}function Vt(e){var t=ve(e).Element;return e instanceof t||e instanceof Element}function ze(e){var t=ve(e).HTMLElement;return e instanceof t||e instanceof HTMLElement}function Yn(e){if(typeof ShadowRoot>"u")return false;var t=ve(e).ShadowRoot;return e instanceof t||e instanceof ShadowRoot}function eT(e){var t=e.state;Object.keys(t.elements).forEach(function(o){var n=t.styles[o]||{},r=t.attributes[o]||{},i=t.elements[o];!ze(i)||!$e(i)||(Object.assign(i.style,n),Object.keys(r).forEach(function(s){var l=r[s];l===false?i.removeAttribute(s):i.setAttribute(s,l===true?"":l);}));});}function tT(e){var t=e.state,o={popper:{position:t.options.strategy,left:"0",top:"0",margin:"0"},arrow:{position:"absolute"},reference:{}};return Object.assign(t.elements.popper.style,o.popper),t.styles=o,t.elements.arrow&&Object.assign(t.elements.arrow.style,o.arrow),function(){Object.keys(t.elements).forEach(function(n){var r=t.elements[n],i=t.attributes[n]||{},s=Object.keys(t.styles.hasOwnProperty(n)?t.styles[n]:o[n]),l=s.reduce(function(a,u){return a[u]="",a},{});!ze(r)||!$e(r)||(Object.assign(r.style,l),Object.keys(i).forEach(function(a){r.removeAttribute(a);}));});}}var Kr={name:"applyStyles",enabled:true,phase:"write",fn:eT,effect:tT,requires:["computeStyles"]};function Ge(e){return e.split("-")[0]}var Xt=Math.max,ln=Math.min,Co=Math.round;function Xn(){var e=navigator.userAgentData;return e!=null&&e.brands&&Array.isArray(e.brands)?e.brands.map(function(t){return t.brand+"/"+t.version}).join(" "):navigator.userAgent}function qr(){return !/^((?!chrome|android).)*safari/i.test(Xn())}function Ft(e,t,o){t===void 0&&(t=false),o===void 0&&(o=false);var n=e.getBoundingClientRect(),r=1,i=1;t&&ze(e)&&(r=e.offsetWidth>0&&Co(n.width)/e.offsetWidth||1,i=e.offsetHeight>0&&Co(n.height)/e.offsetHeight||1);var s=Vt(e)?ve(e):window,l=s.visualViewport,a=!qr()&&o,u=(n.left+(a&&l?l.offsetLeft:0))/r,c=(n.top+(a&&l?l.offsetTop:0))/i,p=n.width/r,f=n.height/i;return {width:p,height:f,top:c,right:u+p,bottom:c+f,left:u,x:u,y:c}}function cn(e){var t=Ft(e),o=e.offsetWidth,n=e.offsetHeight;return Math.abs(t.width-o)<=1&&(o=t.width),Math.abs(t.height-n)<=1&&(n=t.height),{x:e.offsetLeft,y:e.offsetTop,width:o,height:n}}function Yr(e,t){var o=t.getRootNode&&t.getRootNode();if(e.contains(t))return true;if(o&&Yn(o)){var n=t;do{if(n&&e.isSameNode(n))return true;n=n.parentNode||n.host;}while(n)}return false}function ft(e){return ve(e).getComputedStyle(e)}function Rl(e){return ["table","td","th"].indexOf($e(e))>=0}function We(e){return ((Vt(e)?e.ownerDocument:e.document)||window.document).documentElement}function ko(e){return $e(e)==="html"?e:e.assignedSlot||e.parentNode||(Yn(e)?e.host:null)||We(e)}function Tf(e){return !ze(e)||ft(e).position==="fixed"?null:e.offsetParent}function oT(e){var t=/firefox/i.test(Xn()),o=/Trident/i.test(Xn());if(o&&ze(e)){var n=ft(e);if(n.position==="fixed")return null}var r=ko(e);for(Yn(r)&&(r=r.host);ze(r)&&["html","body"].indexOf($e(r))<0;){var i=ft(r);if(i.transform!=="none"||i.perspective!=="none"||i.contain==="paint"||["transform","perspective"].indexOf(i.willChange)!==-1||t&&i.willChange==="filter"||t&&i.filter&&i.filter!=="none")return r;r=r.parentNode;}return null}function Jt(e){for(var t=ve(e),o=Tf(e);o&&Rl(o)&&ft(o).position==="static";)o=Tf(o);return o&&($e(o)==="html"||$e(o)==="body"&&ft(o).position==="static")?t:o||oT(e)||t}function un(e){return ["top","bottom"].indexOf(e)>=0?"x":"y"}function pn(e,t,o){return Xt(e,ln(t,o))}function wf(e,t,o){var n=pn(e,t,o);return n>o?o:n}function Xr(){return {top:0,right:0,bottom:0,left:0}}function Jr(e){return Object.assign({},Xr(),e)}function Qr(e,t){return t.reduce(function(o,n){return o[n]=e,o},{})}var nT=function(t,o){return t=typeof t=="function"?t(Object.assign({},o.rects,{placement:o.placement})):t,Jr(typeof t!="number"?t:Qr(t,No))};function rT(e){var t,o=e.state,n=e.name,r=e.options,i=o.elements.arrow,s=o.modifiersData.popperOffsets,l=Ge(o.placement),a=un(l),u=[Ee,Pe].indexOf(l)>=0,c=u?"height":"width";if(!(!i||!s)){var p=nT(r.padding,o),f=cn(i),m=a==="y"?Ce:Ee,g=a==="y"?Be:Pe,S=o.rects.reference[c]+o.rects.reference[a]-s[a]-o.rects.popper[c],v=s[a]-o.rects.reference[a],h=Jt(i),b=h?a==="y"?h.clientHeight||0:h.clientWidth||0:0,C=S/2-v/2,d=p[m],y=b-f[c]-p[g],x=b/2-f[c]/2+C,k=pn(d,x,y),R=a;o.modifiersData[n]=(t={},t[R]=k,t.centerOffset=k-x,t);}}function iT(e){var t=e.state,o=e.options,n=o.element,r=n===void 0?"[data-popper-arrow]":n;r!=null&&(typeof r=="string"&&(r=t.elements.popper.querySelector(r),!r)||Yr(t.elements.popper,r)&&(t.elements.arrow=r));}var Ef={name:"arrow",enabled:true,phase:"main",fn:rT,effect:iT,requires:["popperOffsets"],requiresIfExists:["preventOverflow"]};function _t(e){return e.split("-")[1]}var aT={top:"auto",right:"auto",bottom:"auto",left:"auto"};function sT(e,t){var o=e.x,n=e.y,r=t.devicePixelRatio||1;return {x:Co(o*r)/r||0,y:Co(n*r)/r||0}}function If(e){var t,o=e.popper,n=e.popperRect,r=e.placement,i=e.variation,s=e.offsets,l=e.position,a=e.gpuAcceleration,u=e.adaptive,c=e.roundOffsets,p=e.isFixed,f=s.x,m=f===void 0?0:f,g=s.y,S=g===void 0?0:g,v=typeof c=="function"?c({x:m,y:S}):{x:m,y:S};m=v.x,S=v.y;var h=s.hasOwnProperty("x"),b=s.hasOwnProperty("y"),C=Ee,d=Ce,y=window;if(u){var x=Jt(o),k="clientHeight",R="clientWidth";if(x===ve(o)&&(x=We(o),ft(x).position!=="static"&&l==="absolute"&&(k="scrollHeight",R="scrollWidth")),x=x,r===Ce||(r===Ee||r===Pe)&&i===sn){d=Be;var B=p&&x===y&&y.visualViewport?y.visualViewport.height:x[k];S-=B-n.height,S*=a?1:-1;}if(r===Ee||(r===Ce||r===Be)&&i===sn){C=Pe;var N=p&&x===y&&y.visualViewport?y.visualViewport.width:x[R];m-=N-n.width,m*=a?1:-1;}}var $=Object.assign({position:l},u&&aT),K=c===true?sT({x:m,y:S},ve(o)):{x:m,y:S};if(m=K.x,S=K.y,a){var T;return Object.assign({},$,(T={},T[d]=b?"0":"",T[C]=h?"0":"",T.transform=(y.devicePixelRatio||1)<=1?"translate("+m+"px, "+S+"px)":"translate3d("+m+"px, "+S+"px, 0)",T))}return Object.assign({},$,(t={},t[d]=b?S+"px":"",t[C]=h?m+"px":"",t.transform="",t))}function lT(e){var t=e.state,o=e.options,n=o.gpuAcceleration,r=n===void 0?true:n,i=o.adaptive,s=i===void 0?true:i,l=o.roundOffsets,a=l===void 0?true:l,u={placement:Ge(t.placement),variation:_t(t.placement),popper:t.elements.popper,popperRect:t.rects.popper,gpuAcceleration:r,isFixed:t.options.strategy==="fixed"};t.modifiersData.popperOffsets!=null&&(t.styles.popper=Object.assign({},t.styles.popper,If(Object.assign({},u,{offsets:t.modifiersData.popperOffsets,position:t.options.strategy,adaptive:s,roundOffsets:a})))),t.modifiersData.arrow!=null&&(t.styles.arrow=Object.assign({},t.styles.arrow,If(Object.assign({},u,{offsets:t.modifiersData.arrow,position:"absolute",adaptive:false,roundOffsets:a})))),t.attributes.popper=Object.assign({},t.attributes.popper,{"data-popper-placement":t.placement});}var Af={name:"computeStyles",enabled:true,phase:"beforeWrite",fn:lT,data:{}};var Da={passive:true};function cT(e){var t=e.state,o=e.instance,n=e.options,r=n.scroll,i=r===void 0?true:r,s=n.resize,l=s===void 0?true:s,a=ve(t.elements.popper),u=[].concat(t.scrollParents.reference,t.scrollParents.popper);return i&&u.forEach(function(c){c.addEventListener("scroll",o.update,Da);}),l&&a.addEventListener("resize",o.update,Da),function(){i&&u.forEach(function(c){c.removeEventListener("scroll",o.update,Da);}),l&&a.removeEventListener("resize",o.update,Da);}}var Pf={name:"eventListeners",enabled:true,phase:"write",fn:function(){},effect:cT,data:{}};var uT={left:"right",right:"left",bottom:"top",top:"bottom"};function Jn(e){return e.replace(/left|right|bottom|top/g,function(t){return uT[t]})}var pT={start:"end",end:"start"};function La(e){return e.replace(/start|end/g,function(t){return pT[t]})}function dn(e){var t=ve(e),o=t.pageXOffset,n=t.pageYOffset;return {scrollLeft:o,scrollTop:n}}function fn(e){return Ft(We(e)).left+dn(e).scrollLeft}function Ol(e,t){var o=ve(e),n=We(e),r=o.visualViewport,i=n.clientWidth,s=n.clientHeight,l=0,a=0;if(r){i=r.width,s=r.height;var u=qr();(u||!u&&t==="fixed")&&(l=r.offsetLeft,a=r.offsetTop);}return {width:i,height:s,x:l+fn(e),y:a}}function Ml(e){var t,o=We(e),n=dn(e),r=(t=e.ownerDocument)==null?void 0:t.body,i=Xt(o.scrollWidth,o.clientWidth,r?r.scrollWidth:0,r?r.clientWidth:0),s=Xt(o.scrollHeight,o.clientHeight,r?r.scrollHeight:0,r?r.clientHeight:0),l=-n.scrollLeft+fn(e),a=-n.scrollTop;return ft(r||o).direction==="rtl"&&(l+=Xt(o.clientWidth,r?r.clientWidth:0)-i),{width:i,height:s,x:l,y:a}}function mn(e){var t=ft(e),o=t.overflow,n=t.overflowX,r=t.overflowY;return /auto|scroll|overlay|hidden/.test(o+r+n)}function Ba(e){return ["html","body","#document"].indexOf($e(e))>=0?e.ownerDocument.body:ze(e)&&mn(e)?e:Ba(ko(e))}function Vo(e,t){var o;t===void 0&&(t=[]);var n=Ba(e),r=n===((o=e.ownerDocument)==null?void 0:o.body),i=ve(n),s=r?[i].concat(i.visualViewport||[],mn(n)?n:[]):n,l=t.concat(s);return r?l:l.concat(Vo(ko(s)))}function Qn(e){return Object.assign({},e,{left:e.x,top:e.y,right:e.x+e.width,bottom:e.y+e.height})}function dT(e,t){var o=Ft(e,false,t==="fixed");return o.top=o.top+e.clientTop,o.left=o.left+e.clientLeft,o.bottom=o.top+e.clientHeight,o.right=o.left+e.clientWidth,o.width=e.clientWidth,o.height=e.clientHeight,o.x=o.left,o.y=o.top,o}function Rf(e,t,o){return t===Oa?Qn(Ol(e,o)):Vt(t)?dT(t,o):Qn(Ml(We(e)))}function fT(e){var t=Vo(ko(e)),o=["absolute","fixed"].indexOf(ft(e).position)>=0,n=o&&ze(e)?Jt(e):e;return Vt(n)?t.filter(function(r){return Vt(r)&&Yr(r,n)&&$e(r)!=="body"}):[]}function Dl(e,t,o,n){var r=t==="clippingParents"?fT(e):[].concat(t),i=[].concat(r,[o]),s=i[0],l=i.reduce(function(a,u){var c=Rf(e,u,n);return a.top=Xt(c.top,a.top),a.right=ln(c.right,a.right),a.bottom=ln(c.bottom,a.bottom),a.left=Xt(c.left,a.left),a},Rf(e,s,n));return l.width=l.right-l.left,l.height=l.bottom-l.top,l.x=l.left,l.y=l.top,l}function Zr(e){var t=e.reference,o=e.element,n=e.placement,r=n?Ge(n):null,i=n?_t(n):null,s=t.x+t.width/2-o.width/2,l=t.y+t.height/2-o.height/2,a;switch(r){case Ce:a={x:s,y:t.y-o.height};break;case Be:a={x:s,y:t.y+t.height};break;case Pe:a={x:t.x+t.width,y:l};break;case Ee:a={x:t.x-o.width,y:l};break;default:a={x:t.x,y:t.y};}var u=r?un(r):null;if(u!=null){var c=u==="y"?"height":"width";switch(i){case xo:a[u]=a[u]-(t[c]/2-o[c]/2);break;case sn:a[u]=a[u]+(t[c]/2-o[c]/2);break;}}return a}function Qt(e,t){t===void 0&&(t={});var o=t,n=o.placement,r=n===void 0?e.placement:n,i=o.strategy,s=i===void 0?e.strategy:i,l=o.boundary,a=l===void 0?xf:l,u=o.rootBoundary,c=u===void 0?Oa:u,p=o.elementContext,f=p===void 0?qn:p,m=o.altBoundary,g=m===void 0?false:m,S=o.padding,v=S===void 0?0:S,h=Jr(typeof v!="number"?v:Qr(v,No)),b=f===qn?Cf:qn,C=e.rects.popper,d=e.elements[g?b:f],y=Dl(Vt(d)?d:d.contextElement||We(e.elements.popper),a,c,s),x=Ft(e.elements.reference),k=Zr({reference:x,element:C,placement:r}),R=Qn(Object.assign({},C,k)),B=f===qn?R:x,N={top:y.top-B.top+h.top,bottom:B.bottom-y.bottom+h.bottom,left:y.left-B.left+h.left,right:B.right-y.right+h.right},$=e.modifiersData.offset;if(f===qn&&$){var K=$[r];Object.keys(N).forEach(function(T){var M=[Pe,Be].indexOf(T)>=0?1:-1,I=[Ce,Be].indexOf(T)>=0?"y":"x";N[T]+=K[I]*M;});}return N}function Ll(e,t){t===void 0&&(t={});var o=t,n=o.placement,r=o.boundary,i=o.rootBoundary,s=o.padding,l=o.flipVariations,a=o.allowedAutoPlacements,u=a===void 0?Ma:a,c=_t(n),p=c?l?Pl:Pl.filter(function(g){return _t(g)===c}):No,f=p.filter(function(g){return u.indexOf(g)>=0});f.length===0&&(f=p);var m=f.reduce(function(g,S){return g[S]=Qt(e,{placement:S,boundary:r,rootBoundary:i,padding:s})[Ge(S)],g},{});return Object.keys(m).sort(function(g,S){return m[g]-m[S]})}function mT(e){if(Ge(e)===Ra)return [];var t=Jn(e);return [La(e),t,La(t)]}function gT(e){var t=e.state,o=e.options,n=e.name;if(!t.modifiersData[n]._skip){for(var r=o.mainAxis,i=r===void 0?true:r,s=o.altAxis,l=s===void 0?true:s,a=o.fallbackPlacements,u=o.padding,c=o.boundary,p=o.rootBoundary,f=o.altBoundary,m=o.flipVariations,g=m===void 0?true:m,S=o.allowedAutoPlacements,v=t.options.placement,h=Ge(v),b=h===v,C=a||(b||!g?[Jn(v)]:mT(v)),d=[v].concat(C).reduce(function(_,Q){return _.concat(Ge(Q)===Ra?Ll(t,{placement:Q,boundary:c,rootBoundary:p,padding:u,flipVariations:g,allowedAutoPlacements:S}):Q)},[]),y=t.rects.reference,x=t.rects.popper,k=new Map,R=true,B=d[0],N=0;N<d.length;N++){var $=d[N],K=Ge($),T=_t($)===xo,M=[Ce,Be].indexOf(K)>=0,I=M?"width":"height",O=Qt(t,{placement:$,boundary:c,rootBoundary:p,altBoundary:f,padding:u}),G=M?T?Pe:Ee:T?Be:Ce;y[I]>x[I]&&(G=Jn(G));var W=Jn(G),F=[];if(i&&F.push(O[K]<=0),l&&F.push(O[G]<=0,O[W]<=0),F.every(function(_){return _})){B=$,R=false;break}k.set($,F);}if(R)for(var L=g?3:1,U=function(Q){var Y=d.find(function(ce){var re=k.get(ce);if(re)return re.slice(0,Q).every(function(ae){return ae})});if(Y)return B=Y,"break"},P=L;P>0;P--){var A=U(P);if(A==="break")break}t.placement!==B&&(t.modifiersData[n]._skip=true,t.placement=B,t.reset=true);}}var Of={name:"flip",enabled:true,phase:"main",fn:gT,requiresIfExists:["offset"],data:{_skip:false}};function Mf(e,t,o){return o===void 0&&(o={x:0,y:0}),{top:e.top-t.height-o.y,right:e.right-t.width+o.x,bottom:e.bottom-t.height+o.y,left:e.left-t.width-o.x}}function Df(e){return [Ce,Pe,Be,Ee].some(function(t){return e[t]>=0})}function hT(e){var t=e.state,o=e.name,n=t.rects.reference,r=t.rects.popper,i=t.modifiersData.preventOverflow,s=Qt(t,{elementContext:"reference"}),l=Qt(t,{altBoundary:true}),a=Mf(s,n),u=Mf(l,r,i),c=Df(a),p=Df(u);t.modifiersData[o]={referenceClippingOffsets:a,popperEscapeOffsets:u,isReferenceHidden:c,hasPopperEscaped:p},t.attributes.popper=Object.assign({},t.attributes.popper,{"data-popper-reference-hidden":c,"data-popper-escaped":p});}var Lf={name:"hide",enabled:true,phase:"main",requiresIfExists:["preventOverflow"],fn:hT};function bT(e,t,o){var n=Ge(e),r=[Ee,Ce].indexOf(n)>=0?-1:1,i=typeof o=="function"?o(Object.assign({},t,{placement:e})):o,s=i[0],l=i[1];return s=s||0,l=(l||0)*r,[Ee,Pe].indexOf(n)>=0?{x:l,y:s}:{x:s,y:l}}function yT(e){var t=e.state,o=e.options,n=e.name,r=o.offset,i=r===void 0?[0,0]:r,s=Ma.reduce(function(c,p){return c[p]=bT(p,t.rects,i),c},{}),l=s[t.placement],a=l.x,u=l.y;t.modifiersData.popperOffsets!=null&&(t.modifiersData.popperOffsets.x+=a,t.modifiersData.popperOffsets.y+=u),t.modifiersData[n]=s;}var Bf={name:"offset",enabled:true,phase:"main",requires:["popperOffsets"],fn:yT};function vT(e){var t=e.state,o=e.name;t.modifiersData[o]=Zr({reference:t.rects.reference,element:t.rects.popper,placement:t.placement});}var zf={name:"popperOffsets",enabled:true,phase:"read",fn:vT,data:{}};function Bl(e){return e==="x"?"y":"x"}function ST(e){var t=e.state,o=e.options,n=e.name,r=o.mainAxis,i=r===void 0?true:r,s=o.altAxis,l=s===void 0?false:s,a=o.boundary,u=o.rootBoundary,c=o.altBoundary,p=o.padding,f=o.tether,m=f===void 0?true:f,g=o.tetherOffset,S=g===void 0?0:g,v=Qt(t,{boundary:a,rootBoundary:u,padding:p,altBoundary:c}),h=Ge(t.placement),b=_t(t.placement),C=!b,d=un(h),y=Bl(d),x=t.modifiersData.popperOffsets,k=t.rects.reference,R=t.rects.popper,B=typeof S=="function"?S(Object.assign({},t.rects,{placement:t.placement})):S,N=typeof B=="number"?{mainAxis:B,altAxis:B}:Object.assign({mainAxis:0,altAxis:0},B),$=t.modifiersData.offset?t.modifiersData.offset[t.placement]:null,K={x:0,y:0};if(x){if(i){var T,M=d==="y"?Ce:Ee,I=d==="y"?Be:Pe,O=d==="y"?"height":"width",G=x[d],W=G+v[M],F=G-v[I],L=m?-R[O]/2:0,U=b===xo?k[O]:R[O],P=b===xo?-R[O]:-k[O],A=t.elements.arrow,_=m&&A?cn(A):{width:0,height:0},Q=t.modifiersData["arrow#persistent"]?t.modifiersData["arrow#persistent"].padding:Xr(),Y=Q[M],ce=Q[I],re=pn(0,k[O],_[O]),ae=C?k[O]/2-L-re-Y-N.mainAxis:U-re-Y-N.mainAxis,me=C?-k[O]/2+L+re+ce+N.mainAxis:P+re+ce+N.mainAxis,gt=t.elements.arrow&&Jt(t.elements.arrow),kt=gt?d==="y"?gt.clientTop||0:gt.clientLeft||0:0,Rt=(T=$?.[d])!=null?T:0,z=G+ae-Rt-kt,X=G+me-Rt,ie=pn(m?ln(W,z):W,G,m?Xt(F,X):F);x[d]=ie,K[d]=ie-G;}if(l){var Ve,at=d==="x"?Ce:Ee,Ye=d==="x"?Be:Pe,Wt=x[y],Oo=y==="y"?"height":"width",wr=Wt+v[at],Qo=Wt-v[Ye],Er=[Ce,Ee].indexOf(h)!==-1,Ai=(Ve=$?.[y])!=null?Ve:0,Pi=Er?wr:Wt-k[Oo]-R[Oo]-Ai+N.altAxis,Ri=Er?Wt+k[Oo]+R[Oo]-Ai-N.altAxis:Qo,Oi=m&&Er?wf(Pi,Wt,Ri):pn(m?Pi:wr,Wt,m?Ri:Qo);x[y]=Oi,K[y]=Oi-Wt;}t.modifiersData[n]=K;}}var Nf={name:"preventOverflow",enabled:true,phase:"main",fn:ST,requiresIfExists:["offset"]};function zl(e){return {scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}}function Nl(e){return e===ve(e)||!ze(e)?dn(e):zl(e)}function xT(e){var t=e.getBoundingClientRect(),o=Co(t.width)/e.offsetWidth||1,n=Co(t.height)/e.offsetHeight||1;return o!==1||n!==1}function Vl(e,t,o){o===void 0&&(o=false);var n=ze(t),r=ze(t)&&xT(t),i=We(t),s=Ft(e,r,o),l={scrollLeft:0,scrollTop:0},a={x:0,y:0};return (n||!n&&!o)&&(($e(t)!=="body"||mn(i))&&(l=Nl(t)),ze(t)?(a=Ft(t,true),a.x+=t.clientLeft,a.y+=t.clientTop):i&&(a.x=fn(i))),{x:s.left+l.scrollLeft-a.x,y:s.top+l.scrollTop-a.y,width:s.width,height:s.height}}function CT(e){var t=new Map,o=new Set,n=[];e.forEach(function(i){t.set(i.name,i);});function r(i){o.add(i.name);var s=[].concat(i.requires||[],i.requiresIfExists||[]);s.forEach(function(l){if(!o.has(l)){var a=t.get(l);a&&r(a);}}),n.push(i);}return e.forEach(function(i){o.has(i.name)||r(i);}),n}function Fl(e){var t=CT(e);return kf.reduce(function(o,n){return o.concat(t.filter(function(r){return r.phase===n}))},[])}function _l(e){var t;return function(){return t||(t=new Promise(function(o){Promise.resolve().then(function(){t=void 0,o(e());});})),t}}function $l(e){var t=e.reduce(function(o,n){var r=o[n.name];return o[n.name]=r?Object.assign({},r,n,{options:Object.assign({},r.options,n.options),data:Object.assign({},r.data,n.data)}):n,o},{});return Object.keys(t).map(function(o){return t[o]})}var Vf={placement:"bottom",modifiers:[],strategy:"absolute"};function Ff(){for(var e=arguments.length,t=new Array(e),o=0;o<e;o++)t[o]=arguments[o];return !t.some(function(n){return !(n&&typeof n.getBoundingClientRect=="function")})}function _f(e){e===void 0&&(e={});var t=e,o=t.defaultModifiers,n=o===void 0?[]:o,r=t.defaultOptions,i=r===void 0?Vf:r;return function(l,a,u){u===void 0&&(u=i);var c={placement:"bottom",orderedModifiers:[],options:Object.assign({},Vf,i),modifiersData:{},elements:{reference:l,popper:a},attributes:{},styles:{}},p=[],f=false,m={state:c,setOptions:function(h){var b=typeof h=="function"?h(c.options):h;S(),c.options=Object.assign({},i,c.options,b),c.scrollParents={reference:Vt(l)?Vo(l):l.contextElement?Vo(l.contextElement):[],popper:Vo(a)};var C=Fl($l([].concat(n,c.options.modifiers)));return c.orderedModifiers=C.filter(function(d){return d.enabled}),g(),m.update()},forceUpdate:function(){if(!f){var h=c.elements,b=h.reference,C=h.popper;if(Ff(b,C)){c.rects={reference:Vl(b,Jt(C),c.options.strategy==="fixed"),popper:cn(C)},c.reset=false,c.placement=c.options.placement,c.orderedModifiers.forEach(function(N){return c.modifiersData[N.name]=Object.assign({},N.data)});for(var d=0;d<c.orderedModifiers.length;d++){if(c.reset===true){c.reset=false,d=-1;continue}var y=c.orderedModifiers[d],x=y.fn,k=y.options,R=k===void 0?{}:k,B=y.name;typeof x=="function"&&(c=x({state:c,options:R,name:B,instance:m})||c);}}}},update:_l(function(){return new Promise(function(v){m.forceUpdate(),v(c);})}),destroy:function(){S(),f=true;}};if(!Ff(l,a))return m;m.setOptions(u).then(function(v){!f&&u.onFirstUpdate&&u.onFirstUpdate(v);});function g(){c.orderedModifiers.forEach(function(v){var h=v.name,b=v.options,C=b===void 0?{}:b,d=v.effect;if(typeof d=="function"){var y=d({state:c,name:h,instance:m,options:C}),x=function(){};p.push(y||x);}});}function S(){p.forEach(function(v){return v()}),p=[];}return m}}var kT=[Pf,zf,Af,Kr,Bf,Of,Nf,Ef,Lf],Gl=_f({defaultModifiers:kT});var TT="tippy-box",Jf="tippy-content",wT="tippy-backdrop",Qf="tippy-arrow",Zf="tippy-svg-arrow",gn={passive:true,capture:true},em=function(){return document.body};function ET(e,t){return {}.hasOwnProperty.call(e,t)}function Ul(e,t,o){if(Array.isArray(e)){var n=e[t];return n??(Array.isArray(o)?o[t]:o)}return e}function Xl(e,t){var o={}.toString.call(e);return o.indexOf("[object")===0&&o.indexOf(t+"]")>-1}function tm(e,t){return typeof e=="function"?e.apply(void 0,t):e}function $f(e,t){if(t===0)return e;var o;return function(n){clearTimeout(o),o=setTimeout(function(){e(n);},t);}}function IT(e,t){var o=Object.assign({},e);return t.forEach(function(n){delete o[n];}),o}function AT(e){return e.split(/\s+/).filter(Boolean)}function er(e){return [].concat(e)}function Gf(e,t){e.indexOf(t)===-1&&e.push(t);}function PT(e){return e.filter(function(t,o){return e.indexOf(t)===o})}function RT(e){return e.split("-")[0]}function Na(e){return [].slice.call(e)}function Uf(e){return Object.keys(e).reduce(function(t,o){return e[o]!==void 0&&(t[o]=e[o]),t},{})}function ei(){return document.createElement("div")}function ti(e){return ["Element","Fragment"].some(function(t){return Xl(e,t)})}function OT(e){return Xl(e,"NodeList")}function MT(e){return Xl(e,"MouseEvent")}function DT(e){return !!(e&&e._tippy&&e._tippy.reference===e)}function LT(e){return ti(e)?[e]:OT(e)?Na(e):Array.isArray(e)?e:Na(document.querySelectorAll(e))}function Hl(e,t){e.forEach(function(o){o&&(o.style.transitionDuration=t+"ms");});}function Hf(e,t){e.forEach(function(o){o&&o.setAttribute("data-state",t);});}function BT(e){var t,o=er(e),n=o[0];return n!=null&&(t=n.ownerDocument)!=null&&t.body?n.ownerDocument:document}function zT(e,t){var o=t.clientX,n=t.clientY;return e.every(function(r){var i=r.popperRect,s=r.popperState,l=r.props,a=l.interactiveBorder,u=RT(s.placement),c=s.modifiersData.offset;if(!c)return true;var p=u==="bottom"?c.top.y:0,f=u==="top"?c.bottom.y:0,m=u==="right"?c.left.x:0,g=u==="left"?c.right.x:0,S=i.top-n+p>a,v=n-i.bottom-f>a,h=i.left-o+m>a,b=o-i.right-g>a;return S||v||h||b})}function jl(e,t,o){var n=t+"EventListener";["transitionend","webkitTransitionEnd"].forEach(function(r){e[n](r,o);});}function jf(e,t){for(var o=t;o;){var n;if(e.contains(o))return true;o=o.getRootNode==null||(n=o.getRootNode())==null?void 0:n.host;}return false}var so={isTouch:false},Wf=0;function NT(){so.isTouch||(so.isTouch=true,window.performance&&document.addEventListener("mousemove",om));}function om(){var e=performance.now();e-Wf<20&&(so.isTouch=false,document.removeEventListener("mousemove",om)),Wf=e;}function VT(){var e=document.activeElement;if(DT(e)){var t=e._tippy;e.blur&&!t.state.isVisible&&e.blur();}}function FT(){document.addEventListener("touchstart",NT,gn),window.addEventListener("blur",VT);}var _T=typeof window<"u"&&typeof document<"u",$T=_T?!!window.msCrypto:false;function Zn(e){var t=e==="destroy"?"n already-":" ";return [e+"() was called on a"+t+"destroyed instance. This is a no-op but","indicates a potential memory leak."].join(" ")}function Kf(e){var t=/[ \t]{2,}/g,o=/^[ \t]*/gm;return e.replace(t," ").replace(o,"").trim()}function GT(e){return Kf(`
1
+ import {b,a as a$3}from'./chunk-G6UW4ISL.js';import {g,f as f$1,e as e$2}from'./chunk-OIIAFAWL.js';import {a}from'./chunk-5NVVEPZQ.js';import {a as a$4}from'./chunk-7K6SKRXP.js';import {h,N,J,l,R,c,o,M,G,B as B$1,F,D,E,m,H as H$1,A as A$1,f,O as O$1,Q,a as a$2,P as P$1,p as p$1,C,n,i as i$1,j,k,I as I$1,d as d$1,e as e$1,t,b as b$2,g as g$2}from'./chunk-NKCSPYUO.js';import'./chunk-4XIZPGIL.js';import {i,g as g$1,a as a$5}from'./chunk-KUPNLLLT.js';import {cb,Ga as Ga$1,Ha,Fa as Fa$1,z,Ea as Ea$1,va as va$1,W,T,Da as Da$1,ua,ta as ta$1,La as La$1,Oa as Oa$1,Pa as Pa$1,Sa as Sa$1,O,_,I,H,A,_a,B,Ka,ab,b as b$1,c as c$1,db as db$1,Ya,Aa as Aa$1,p,m as m$1,s,P,Q as Q$1,f as f$2,e,Na as Na$1,u,ba,ca,o as o$1,l as l$1,r,Va,d,v,N as N$1,V,Za,$a as $a$1,Ma as Ma$1,C as C$1,ea,eb,fa,wa as wa$1,Ba as Ba$1,Ua,D as D$1,E as E$1,F as F$1,G as G$1,Ia as Ia$1,Ta as Ta$1,i as i$2,X,Ca,Ja,j as j$1,Qa as Qa$1,Ra as Ra$1,xa,U,za as za$1,ya as ya$1,a as a$6}from'./chunk-AA4WMKFB.js';import {a as a$1}from'./chunk-P6ORTCRN.js';import'./chunk-QZ5NBDGE.js';import {Group,Stack,Text,ThemeIcon,useMantineTheme,List,UnstyledButton,Center,createStyles,Image,Checkbox,Input,Card,Space,Badge,Button,Title,Tabs,TextInput,Code,NumberInput,Box,Loader,Divider,SegmentedControl,Select,ActionIcon,Textarea,Accordion,rem,ScrollArea,Tooltip,MultiSelect,Switch,Radio,Skeleton,Paper,Anchor,Avatar,Flex,px,Modal,Popover,Overlay,CopyButton,Col,Grid,Collapse,Alert,Breadcrumbs,Menu,MantineProvider,Navbar,AppShell,Container,LoadingOverlay,Pagination,Drawer,FileInput,SimpleGrid,Header,Autocomplete}from'@mantine/core';import {useListState,useSetState,randomId,useClickOutside,useDisclosure,useFullscreen,useDebouncedValue,getHotkeyHandler,useUncontrolled,useHotkeys,useMergedRef}from'@mantine/hooks';import {notifications,Notifications}from'@mantine/notifications';import {IconCirclePlus,IconCircleCheck,IconLogout,IconBraces,IconGripVertical,IconDice,IconBoxMultiple,IconEyeOff,IconDeviceLaptop,IconFlag,IconChevronDown,IconBallpen,IconDatabase,IconMathFunction,IconNetwork,IconUsers,IconServer,IconPencil,IconAlertCircle,IconPlayerPlay,IconTrash,IconLanguage,IconCircleX,IconCircleCheckFilled,IconFileAnalytics,IconQuestionMark,IconLanguageOff,IconPhotoFilled,IconFileUpload,IconGripHorizontal,IconLogin,IconWorld,IconLock,IconCopy,IconPlus,IconAlertTriangle,IconCloudNetwork,IconGitMerge,IconClockHour2,IconApi,IconAugmentedReality,IconCheck,IconRefresh,IconDeviceFloppy,IconPalette,IconSettings,IconChevronRight,IconCode,IconBold,IconItalic,IconUnderline,IconArrowBackUp,IconArrowForwardUp,IconAlignLeft,IconAlignCenter,IconAlignRight,IconAlignJustified,IconGlobe,IconLinkOff,IconX,IconHelp,IconMinimize,IconMaximize,IconCircleDashed,IconHome,IconListCheck,IconPhoto,IconPolaroid,IconCircleMinus,IconVariable,IconArrowRightCircle,IconSlash,IconHelpCircle,IconUpload,IconFileCode,IconWorldUpload,IconSettingsFilled,IconChevronLeft,IconIndentIncrease,IconCodeDots,IconBinaryTree}from'@tabler/icons-react';import $D from'next/head';import Vb from'next/link';import lv,{forwardRef,useState,useEffect,useImperativeHandle,createContext,useCallback,useRef,useMemo,Fragment as Fragment$1,useContext}from'react';import {signOut}from'next-auth/react';import {jsxs,jsx,Fragment}from'react/jsx-runtime';import {DragDropContext,Droppable,Draggable}from'@hello-pangea/dnd';import {useDispatch}from'react-redux';import {MantineReactTable}from'mantine-react-table';import jS,{useMonaco}from'@monaco-editor/react';import {titleCase}from'd3plus-text';import {EditorProvider,useCurrentEditor,BubbleMenu,ReactRenderer}from'@tiptap/react';import bw from'@tiptap/extension-underline';import yw from'@tiptap/starter-kit';import vw from'@tiptap/extension-mention';import Sw from'@tiptap/extension-hard-break';import {Plugin,PluginKey,Selection,TextSelection,NodeSelection}from'@tiptap/pm/state';import'@tiptap/pm/view';import'@tiptap/pm/keymap';import {Fragment as Fragment$2,Slice,Schema,DOMParser}from'@tiptap/pm/model';import {canSplit,joinPoint,liftTarget,canJoin,ReplaceStep,ReplaceAroundStep}from'@tiptap/pm/transform';import {wrapIn,setBlockType,selectTextblockStart,selectTextblockEnd,selectParentNode,selectNodeForward,selectNodeBackward,newlineInCode,liftEmptyBlock,lift,joinUp,joinTextblockForward,joinTextblockBackward,joinForward,joinDown,joinBackward,exitCode,deleteSelection,createParagraphNear}from'@tiptap/pm/commands';import {wrapInList,sinkListItem,liftListItem}from'@tiptap/pm/schema-list';import xw from'@tiptap/extension-text-align';import Cw from'@tiptap/extension-placeholder';import Lw from'@tiptap/extension-typography';import Gh from'axios';import*as Ht from'd3';import*as ds from'd3-dag';import {csvParse}from'd3-dsv';import {useForm}from'@mantine/form';function _p(e){let{onlyIcon:t,href:o,version:n}=e,r=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:true,c:"dimmed",size:"xs",ml:3,children:n})]})]})});return o?jsx(Vb,{href:o,passHref:true,children:jsx(UnstyledButton,{p:10,w:"100%",children:r})}):r}function zn(e){return jsxs("span",{style:{display:"flex",alignItems:"center",gap:"0.5rem"},children:[e.icon,e.children]})}function $p(e){let{left:t,center:o,right:n}=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:n})]})})}var Yb=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 Lr({value:e,onChange:t,defaultValue:o,selectProps:n={},loading:r=false}){let i=e$1(),a=va$1(c=>c.status.localeDefault),[l,s]=useUncontrolled({value:e,defaultValue:o||a,finalValue:a,onChange:t}),u=useMantineTheme();return jsx(Select,{...n,data:i,value:l,onChange:s,styles:{...Yb(u),...n?.styles},icon:jsx(IconLanguage,{size:"0.8rem",color:u.colors.blue[7]}),rightSection:r?jsx(Loader,{size:"0.8rem"}):jsx(IconChevronDown,{size:"0.8rem",color:u.colors.blue[7]})})}var oy={maxWidth:100,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"};function zr({children:e,tooltip:t=false,onClick:o=()=>{},textProps:n={},clickable:r=false}){return jsx(Tooltip,{label:e,disabled:!t,children:jsx(UnstyledButton,{onClick:o,children:jsxs(Group,{spacing:"3px",align:"center",noWrap:true,children:[jsx(Text,{fz:"0.675rem",tt:"uppercase",fw:700,color:"gray.7",sx:oy,...n,children:e}),r&&jsx(ThemeIcon,{color:"gray.7",size:"1rem",bg:"transparent",variant:"default",sx:{border:"none"},children:jsx(IconChevronDown,{size:"xl"})})]})})})}var Zi=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 fy(e,t,o){return o===t?e.map(n=>({id:n.id,value:`${n.id}`,name:n.name})):e.map(n=>{let r=n.contentByLocale.find(i=>i.locale===o);return {id:n.id,value:`${n.id}`,name:n.name,refName:r?r.name:null}})}var Gp={overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},gy=forwardRef(function({id:t,name:o,refName:n,...r},i){return jsxs(Group,{position:"apart",ref:i,...r,children:[jsxs(Stack,{spacing:0,children:[jsx(Text,{maw:"200px",sx:Gp,children:o}),n&&jsx(Text,{fz:10,c:"#666",maw:"140px",sx:Gp,children:n})]}),jsx(Text,{color:"gray.5",size:"sm",children:t})]},`${t}-${o}`)});function Us(e){let{dimensionId:t,variantId:o,value:n,defaultValue:r,onChange:i,locale:a}=e,l=ua(),{localeDefault:s}=a$6(),u=$a$1(),c=a||s,[p,m]=useState([]),[f,g]=useState(""),[S]=useDebouncedValue(f,500),[v,h]=useState(false),[b,C]=useState(false),[d,y]=useUncontrolled({value:n,defaultValue:r,finalValue:void 0,onChange:i?$=>i($):void 0}),x=useRef(null),k=useClickOutside(()=>C(false)),R=useMergedRef(x,k),B=$=>{let K=p.find(T=>T.id===$.id);K&&(g(K.name?K.name:""),y(K),C(false));};useEffect(function(){h(true);let K={query:S,locale:c===u?c:"all",variant:[o],dimension:[t],limit:5,visible:false,includes:true,noImage:false,format:"plain",all:true,preferredLocale:u,report:[]};l(ta$1.searchMember(K)).then(T=>{if(T&&T.results){let M=T.results.map(I=>({...I,currentLocale:c,name:(I.contentByLocale&&I.contentByLocale.find(O=>O.locale===c)||I).name}));m(M),h(false),M.length===0&&S===""&&(m([]),h(false));}});},[l,S,c,o,t,u]),useEffect(()=>{p.length&&!d?.id&&i&&i(p[0]);},[p,i]);let N=fy(p,c,u);return useEffect(()=>{setTimeout(()=>{x.current&&x.current.focus();},200);},[b]),b||!d?.name?jsx(Autocomplete,{ref:R,value:f,onChange:g,data:N,itemComponent:gy,placeholder:"Search members.",nothingFound:"No members found.",rightSection:v&&jsx(Loader,{size:"xs"}),filter:()=>true,onItemSubmit:B,size:"xs",w:130,styles:Zi("Members")}):jsx(zr,{onClick:()=>C(true),textProps:{color:"gray.6"},tooltip:true,clickable:true,children:d.name})}function Hs(e){let o=Ga$1(e).data,n=ya$1(o?.variants);return n.isSuccess?n.data.map(r=>({value:`${r.id}`,label:r.name})):[]}function js(e){let{dimension:t,value:o,onChange:n}=e,[r,i]=useState(false),a=Hs(t),l=useClickOutside(()=>i(false)),s=a.length===1||!r,[u,c]=useUncontrolled({value:o?String(o):void 0,defaultValue:a[0]?a[0].value:"",finalValue:void 0,onChange:n?f=>n(Number(f)):void 0}),p=f=>c(f),m=a.find(f=>f.value===u)||a[0];return s?jsx(zr,{onClick:()=>i(true),clickable:a.length>1,children:m?m.label:"No Variant"}):jsx(Select,{ref:l,data:a,value:u,onChange:p,w:140,size:"xs",styles:Zi("Variants"),initiallyOpened:true})}function ta(e){let{dimensionId:t,locale:o,onSelect:n,value:r}=e,i=ua(),a=Hs(t),[l,s]=useUncontrolled({defaultValue:r?{id:`${r.memberId}`}:void 0,finalValue:void 0,onChange:n?m=>n(m):void 0}),[u,c]=useUncontrolled({value:void 0,defaultValue:r?.variantId,finalValue:a[0]?Number(a[0].value):0,onChange:()=>{s({});}}),p=r?.memberId;return useEffect(function(){p&&i(ta$1.readMember(e$2({locale:o,content_ids:[`${p}`],all:"false",mode:"content_ids"}))).then(f=>{if(f&&f.results&&f.results[0]){let g=f.results[0];s({...g});}else console.error("default member is not found");});},[p]),jsxs(Flex,{gap:"xs",px:"xs",align:"center",children:[jsx(js,{dimension:t,value:u,onChange:c},`dimension-${t}`),jsx(Text,{fz:"xs",tt:"uppercase",color:"gray.6",fw:700,children:"/"}),u&&jsx(Us,{variantId:u,dimensionId:t,value:l,onChange:s,locale:o},`variant-${u}`)]})}function qs({report:e,defaultMembers:t,locale:o}){let[n,r]=useState(false),i=ua(),a=a$2(),l=useContext(db$1),s=Ya(l),u=e&&e.dimensions?e.dimensions:[],c=va$1(S=>S.status.previews),p=c.map(S=>({variantId:S.variant_id,memberId:S.content_id})),m=a.query.preview,f=Array.isArray(m)?m.join("!"):m||"",g=S=>{let h=e.dimensions.map(C=>{let d;if(S)if(S.dimension_id===C)d=S;else {let y=c.find(x=>x?x.dimension_id===C:false);y&&(d=y);}return d}).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}:{}),b=h.map(Ry).join("!");if(b&&f!==b){let C=h.filter(d=>d.content_id).length===u.length;i(ta$1.setPreviews(h)),C&&(a.setSearchParam("preview",b),s({previews:h}));}};return useEffect(function(){let v=f.split("!").filter(Boolean);v.length===u.length&&u.length>0?i(ta$1.readMember({mode:"slugs",slugs:v.map(h=>{let[b,C]=h.split("/");return {variantSlug:b,memberSlug:C}}),locale:o,output:"full"})).then(h=>s({previews:h.results})).then(()=>r(true)):t&&t.length===u.length?i(ta$1.readMember({mode:"content_ids",variant:t.map(h=>h.variantId),content_ids:t.map(h=>h.memberId),locale:o,output:"full"})).then(h=>s({previews:h.results})).then(()=>r(true)):r(true);},[]),jsx(Group,{spacing:"xs",children:n&&u.map((S,v)=>jsxs(Fragment$1,{children:[jsx(Text,{fw:700,fz:"xs",children:"/"}),jsx(ta,{dimensionId:S,onSelect:g,value:p[v]?p[v]:void 0,locale:o},S)]},S))})}function Ry(e){return `${"variant_slug"in e?e.variant_slug:e?.variant?.slug}/${e.slug}`}var Nr="dimension",Wp="Dimension";var Ys="formatter",Yp="Formatter";var Xs="variant",Xp="Variant";var Js="datasource",Qp="Data Source";var Zp={[r]:s,[Nr]:Wp,[Ys]:Yp,[l$1]:m$1,[o$1]:p,[Xs]:Xp,[Js]:Qp};function Bt({id:e,type:t,warning:o,disabled:n=false}){let r=useDispatch(),{newConfirmation:i}=b(),a=useCallback(async()=>{let l=Zp[t]||"Entity",s=o||`Delete this ${l} and all its contents? This action cannot be undone.`;try{n||(await i({title:"Are you sure?",message:s,confirmText:"Yes, Delete it."}),r(ta$1.deleteEntity(t,e)));}catch{console.error(`${l} deletion aborted:`,e);}},[e,t,o,n,r]);return jsx(ActionIcon,{disabled:n,color:"red",variant:"transparent",onClick:a,children:jsx(IconTrash,{size:18})})}function Qy({for:e,onEdit:t}){let o=useMantineTheme(),{newConfirmation:n}=b(),r=o.colorScheme==="dark"?o.colors.dark[1]:o.colors.gray[7],i=useCallback(async()=>{try{await n({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.error("Dimension edition aborted.");}},[t]),{name:a,ordering:l}=e;return jsxs(Card,{shadow:"xs",withBorder:true,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:r,lineHeight:2},children:["Order:",l]}),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:e.variants.length})]}),jsx("ul",{children:e.variants.map(s=>jsx("li",{style:{color:r},children:jsx(ev,{id:s})},s))}),jsxs(Group,{position:"apart",children:[jsx(Button,{onClick:i,leftIcon:jsx(IconPencil,{}),compact:true,children:"Edit"}),jsx(Bt,{id:e.id,type:"dimension",warning:"Deleting dimensions can be destructive and break the site. Make sure you know what you're doing!"})]})]})}var od=cb(Qy,Ga$1);function Zy({for:e}){let t=g(e.settings);return jsx(Text,{size:"sm",children:`${e.name}: /${e.slug} - Order: ${t.order}`})}var ev=cb(Zy,Ha);function Fn(e){let{target:t,fields:o,onSubmit:n}=e,[r,i,a]=pv(o||[]),[l,s]=useDisclosure(false,{onClose:a}),u=useCallback(c=>{l&&(c.preventDefault(),typeof n=="function"&&n(i),s.close());},[i,l]);return useHotkeys([["enter",u]]),r.length===0?t:jsxs(Popover,{onClose:s.close,opened:l,position:"right",trapFocus:true,withArrow:true,withinPortal:true,zIndex:1001,children:[jsx(Popover.Target,{children:lv.cloneElement(e.target,{onClick:s.open})}),jsx(Popover.Dropdown,{children:jsxs("form",{onSubmit:u,children:[r,jsx(Button,{type:"submit",children:"Submit"})]})})]})}function pv(e){let[t,o]=useState({}),n=e.map(a=>encodeURIComponent(`${a.name}:${a.type}/${a.label}`)).join("&"),r=useCallback(()=>{o({});},[]);return [useMemo(()=>e.map(a=>{let l=`${t[a.name]??(a.initialValue||"")}`;return a.type==="checkbox"?jsx(Checkbox,{label:a.label,name:a.name,checked:l=="true"},a.name):a.type==="radio"?jsx(Radio.Group,{label:a.label,value:l,children:a.options.map(s=>jsx(Radio,{label:s.label,value:`${s.value}`},s.label))},a.name):a.type==="select"?jsx(Select,{data:a.options.map(s=>({value:`${s.value}`,label:s.label})),label:a.label,onChange:s=>{o({...t,[a.name]:s});},value:l,zIndex:1002},a.name):a.type==="switch"?jsx(Switch,{label:a.label,name:a.name,checked:l=="true"},a.name):a.type==="text"?jsx(TextInput,{label:a.label,onChange:s=>{o({...t,[a.name]:s.target.value});},placeholder:a.placeholder,value:l},a.name):null}),[n,t]),t,r]}function Sv({for:e,onEdit:t}){let o=useMantineTheme(),{newConfirmation:n}=b(),r=useCallback(async()=>{try{await n({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.error("Variant edition aborted.");}},[t]),{slug:i,name:a,settings:l}=e,s=g(l);return jsxs(Card,{shadow:"xs",withBorder:true,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:a}),jsxs(Text,{size:"xs",ml:"xs",children:["Order: ",s.order]})]}),jsxs(Badge,{variant:"light",children:["/",i]})]}),jsx(Space,{h:"xs"}),jsxs(Group,{position:"apart",children:[jsx(Button,{onClick:()=>r(),leftIcon:jsx(IconPencil,{}),compact:true,children:"Edit"}),jsx(Bt,{id:e.id,type:"variant",warning:"Deleting variants can be destructive and break the site. Make sure you know what you're doing!"})]})]})}var cd=cb(Sv,Ha);var xv=e=>e.replace(/^\s+|\s+$/gm,"").replace(/[^a-zA-ZÀ-ž0-9- _]/g,""),na=xv;function yt({content:e,buttons:t,size:o}){let[n,r]=useState(500);return useEffect(()=>{let{innerHeight:i}=window;r(i-o);},[]),jsxs("div",{style:{height:"100%"},children:[jsx(ScrollArea,{offsetScrollbars:true,type:"always",style:{height:n},styles:{viewport:{"& > div:first-of-type":{display:"block !important"}}},children:e}),jsx(Space,{h:"xs"}),jsx(Divider,{}),jsx(Group,{mt:"xs",grow:true,style:{height:45},children:t})]})}function Rv({member:e,height:t="auto",width:o="100%",size:n="thumb",forceRefreshTimestamp:r=false}){let i="";r&&(i=`&t=${new Date().getTime()}`);let a=e&&e.image_id?`/api/cms/member/image?member=${e.content_id}&size=${n}${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 Vr=Rv;function $n({members:e,onClickEdit:t,onSort:o,colsToRender:n=[],dataTableProps:r={}}){let[i,a]=useState([]),[l,s]=useState([]),{state:u,...c}=r;useEffect(()=>{typeof o<"u"&&i&&i.length&&o(i);},[i]),useEffect(()=>{s(e);},[e]),useEffect(()=>{s(e);},[]);let p=va$1(g=>g.status.localeDefault),m=jsx(Badge,{color:"gray",children:"None"}),f=[{header:"",accessorKey:"visible",enableResizing:false,enableSorting:false,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:false,size:100},{header:"Dimension",accessorKey:"dimension.name",enableSorting:false,size:100},{header:"Variant",accessorKey:"variant.name",enableSorting:false,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:false},{header:`Name ${p.toUpperCase()}`,accessorKey:"name",enableSorting:typeof o<"u",Cell:({row:g})=>{let S=g.original.contentByLocale.find(b=>b.locale===p),v=g.original.contentByLocale.filter(b=>b.locale!==p),h=v.reduce((b,C)=>{let d=`${C.locale.toUpperCase()}: ${C.name}`;return `${b}${b!==""?`
2
+ `:""}${d}`},"");return jsxs(Group,{children:[jsx("span",{children:S?.name||m}),v.length>0&&jsx(Tooltip,{label:h,children:jsxs(Avatar,{size:"sm",color:"pink",radius:"xl",children:["+",v.length]})})]})}},{header:`Keywords ${p.toUpperCase()}`,accessorKey:"keywords",Cell:({row:g})=>{let S=g.original.contentByLocale.find(C=>C.locale===p),v=g.original.contentByLocale.filter(C=>C.locale!==p),h=(S.keywords?S.keywords:[]).map(C=>jsx(Badge,{children:C},C)),b=v.reduce((C,d)=>{let y=d.keywords||[],x=`${d.locale.toUpperCase()}: ${y.length>0?y.join(","):"None"}`;return `${C}${C!==""?`
3
+ `:""}${x}`},"");return jsxs(Group,{children:[jsx("span",{children:h.length>0?h:m}),v.length>0&&jsx(Tooltip,{label:b,children:jsxs(Avatar,{size:"sm",color:"pink",radius:"xl",children:["+",v.length]})})]})},enableSorting:false,size:100},{header:"Image",accessorKey:"image",Cell:({row:g})=>jsx(Vr,{member:g.original,height:"50px",forceRefreshTimestamp:true}),enableSorting:false,size:80},{header:"",accessorKey:"actions",Cell:({row:g})=>jsx(ActionIcon,{onClick:()=>t?t(g.original):false,children:jsx(IconPencil,{size:20})},"edit"),enableResizing:false,enableSorting:false,size:50,mantineTableHeadCellProps:{align:"center"},mantineTableBodyCellProps:{align:"center"}}];return jsx(MantineReactTable,{columns:f.filter(g=>n&&n.length===0||n.includes(g.accessorKey)),data:l,enableBottomToolbar:false,enableColumnActions:false,enableColumnResizing:true,enablePagination:false,enableStickyHeader:true,enableTopToolbar:false,initialState:{density:"xs"},layoutMode:"grid",mantineTableContainerProps:{sx:{minHeight:150,maxHeight:"90vh"}},mantineTableProps:{striped:true},manualSorting:true,onSortingChange:a,state:{sorting:i,...u},...c})}function Gv({switchProps:e,yesText:t,noText:o}){let n={size:"md",onLabel:"YES",offLabel:"NO",label:"Switch Label",my:"xs",checked:false,onChange:r=>console.info(r.currentTarget.checked),...e};return jsxs(Group,{children:[jsx(Switch,{...n}),jsx(Tooltip,{label:n.checked?t:o,withArrow:true,multiline:true,width:200,children:jsx(ActionIcon,{variant:"filled",radius:"50%",size:"xs",children:jsx(IconQuestionMark,{size:"xs"})})})]})}var _r=Gv;function Gn(e){try{return new URL(e),!0}catch{return false}}function oS({for:e,onClose:t}){let o=ua(),n=va$1(z=>z.status.localeDefault),r=va$1(z=>z.status.locales),i=r.map(z=>({value:z,label:z.toUpperCase()})),[a,l$1]=useState(),[s,u]=useState(n),[c,p]=useState(()=>{let z={...e};return r.forEach(X=>{z.config={...z.config,[X]:{attributes:[],idKey:"",labelKey:"",accessor:"",path:"",...z.config[X]||{}}};}),z}),[m,f]=useState(false),[g$1,S]=useState(false),[v,h]=useState(false),[b,C]=useState(false),[d,y]=useState({valid:false,suggestion:""}),[x,k]=useState(),[R,B]=useState([]),[N,$]=useState(false),[K,T]=useState([]),M=z=>{Gn(z)&&(S(true),o(ta$1.urlProxy({url:z})).then(X=>{if(k(X),X){let ie=P(X);B(ie),c.config[s].accessor&&X[c.config[s].accessor]?O(X[c.config[s].accessor][0],c.config[s].accessor):ie.length===0&&X&&X[0]&&O(X[0]);}h(false),S(false);}).catch(X=>{console.error(X),h(`Fetch error: ${X.message}`),k(void 0),S(false);}));},I=z=>{$(true);let X=f$1({variant:z,limit:"5",locale:"all",visible:"true",includes:"true",noImage:"false",format:"plain",all:"true"});o(ta$1.searchMember(X)).then(ie=>{if(ie&&ie.results){let Ve=ie.results;T(Ve),Ve.length===0&&_("doIngest",true);}$(false);}).catch(ie=>{console.error(ie),$(false);});},O=(z,X="")=>{if(z){let ie=Object.keys(z),Ve=ie.find(Ye=>Ye.toLowerCase().includes("id"))||ie[0],at=ie.find(Ye=>!Ye.toLowerCase().includes("id"))||ie[0];(!c.config[s].idKey||c.config[s].idKey===""||!c.config[s].labelKey||c.config[s].labelKey==="")&&p({...c,config:{...c.config,[s]:{...c.config[s],idKey:Ve,labelKey:at,accessor:X}}});}l$1(z);};useEffect(()=>{c.id&&I(c.id),U(c.slug),c.config[s]&&c.config[s].path&&M(c.config[s].path);},[]);let G=z=>{k(void 0),h(false);let X=[];if(z!==n){let ie=c.config[n]?[...c.config[n].attributes].map(at=>{let Ye={...at};return Ye.value="",Ye}):[];c.config[z]&&c.config[z].attributes?X=ie.map(at=>{let Ye=c.config[z].attributes.find(Kt=>at.name===Kt.name);return Ye&&(at.value=Ye.value),at}):X=ie;let Ve={...c.config,[z]:{...c.config[z],attributes:X}};p({...c,config:Ve});}c.config[z]&&c.config[z].path&&M(c.config[z].path),u(z);},W=useMemo(()=>g(c.settings),[c.settings]),F=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:!W.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."}],[W.overrideNames]),L=z=>{let X=Q$1(x,z);X[0]&&O(X[0],z);},U=z=>{o(ta$1.variantValidateSlug(c.dimension_id,z)).then(y).then(()=>{C(false);},X=>{console.error(X);});},P$1=(z,X)=>{let ie=X;z==="slug"&&(ie=na(X),ie&&(C(true),U(X))),p({...c,[z]:ie});},A=(z,X)=>{z==="path"&&h(false),p({...c,config:{...c.config,[s]:{...c.config[s],[z]:X}}});},_=(z,X)=>{let ie=z==="overrideNames"&&!X?{regenerateSlugs:false}:{};p({...c,settings:{...c.settings,...ie,[z]:X}});},Q=()=>{f(true),o(ta$1.updateEntity("variant",c)).then(()=>{f(false),t();}).catch(z=>{console.error(z),f(false);});},Y=z=>{p({...c,config:{...c.config,[s]:{...c.config[s],attributes:z}}});},ce=()=>{if(a&&Object.keys(a)[0]){let ie=c.config[s]?.attributes||[],Ve=ie.length||0;Y([...ie,{type:"constant",name:`attr${Ve+1}`,value:""}]);}},re=(z,X,ie)=>{let Ve=c.config[s].attributes.map((at,Ye)=>Ye===X?{...at,[z]:ie}:at);Y(Ve);},ae=z=>{let X=c.config[s].attributes.filter((ie,Ve)=>Ve!==z);Y(X);},fe=a?Object.keys(a).map(z=>({value:z,label:`${z}: ${a[z]}`})):[],ht=R.map(z=>({value:z,label:z})),Tt=!Gn(c.config[s].path),Rt=useMemo(()=>v||(Tt&&c.config[s].path!==""?"Format error: Invalid URL.":false),[v,Tt,c.config,s]);return jsx(yt,{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:true,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:z=>P$1("name",z.target.value)}),jsx(Space,{h:"xs"}),jsx(TextInput,{value:c.slug,icon:!b&&!d.valid?jsx(IconAlertCircle,{}):jsx(IconCircleCheck,{}),label:"Slug",description:b?"Validating slug...":d.valid?"Valid slug.":"Invalid slug.",error:!b&&!d.valid?jsxs(Text,{children:["Duplicated slug. Suggestion:",jsx(Code,{onClick:()=>P$1("slug",d.suggestion),style:{cursor:"pointer"},children:d.suggestion})]}):false,onChange:z=>P$1("slug",z.target.value)}),jsx(Space,{h:"xs"}),jsx(NumberInput,{value:W.order||0,description:"It affects on explore options order",placeholder:"Order",label:"Order",onChange:z=>{_("order",z);}})]}),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(_r,{switchProps:{label:`${!N&&K.length>0?"Re-":""}Ingest members`,checked:W.doIngest,onChange:z=>_("doIngest",z.currentTarget.checked)},yesText:`Run the ingestion process and save the variant details.
4
+ 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."}),W.doIngest&&!N&&K.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."}),F.map(z=>jsx(_r,{switchProps:{disabled:z.disabled,label:z.label,checked:W[z.key],onChange:X=>_(z.key,X.currentTarget.checked)},yesText:z.yesText,noText:z.noText},z.key))]}),!W.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:[N&&jsx(Loader,{m:"0 auto"}),!N&&K.length>0&&jsxs(Fragment,{children:[jsx($n,{members:K,colsToRender:["id","name","slug"]}),jsx(Vb,{href:"metadata",passHref:true,children:jsx(Text,{c:"dimmed",align:"center",td:"underline",size:"xs",children:"See the full list in Metadata View"})})]})]}),!N&&K.length===0&&jsx(Text,{c:"dimmed",align:"center",children:"No members ingested yet."}),jsx(Space,{h:"xs"})]}),W.doIngest&&jsxs(Fragment,{children:[jsx(Divider,{my:"sm"}),jsx(Title,{order:2,size:"h4",children:"Members ingestion"}),jsx(Space,{h:"xs"}),jsx(SegmentedControl,{value:s,fullWidth:true,onChange:G,data:i,disabled:g$1}),c.config[s]&&jsxs(Fragment,{children:[jsx(Space,{h:"lg"}),jsx(Group,{children:jsx(TextInput,{onChange:z=>A("path",z.target.value),title:"Api endpoint",description:"Enter the url to retrieve a member list to ingest. (JSON) and click Fetch.",value:c.config[s].path,error:Rt,rightSectionWidth:"105px",w:"100%",rightSection:g$1?jsxs(Group,{align:"center",children:[jsx(Loader,{size:"xs"}),jsx(Text,{span:true,variant:"subtle",size:"xs",children:"Fetching..."})]}):jsx(Button,{disabled:g$1||Tt,onClick:()=>M(c.config[s].path),leftIcon:jsx(IconPlayerPlay,{}),children:"Fetch"}),readOnly:g$1})}),x&&jsxs("div",{children:[jsx(Space,{h:"md"}),jsx(Select,{value:c.config[s].accessor,label:"Elements",description:`Choose the key that returns the array of elements that
5
+ are going to be ingested as members.`,data:ht,disabled:ht.length===0,placeholder:ht.length===0?"Root is an array":"",onChange:z=>L(z)}),jsx(Divider,{label:"First element preview",labelPosition:"center"}),x[c.config[s].accessor]&&!Array.isArray(x)&&jsx(l,{variables:x[c.config[s].accessor][0]}),Array.isArray(x)&&x[0]&&jsx(l,{variables:x[0]}),jsx(Space,{h:"md"}),jsx(Select,{value:c.config[s].idKey,label:"Unique identificator",description:"Choose the field that is a unique identification for a single member.",data:fe,onChange:z=>A("idKey",z)}),jsx(Space,{h:"md"}),jsx(Select,{value:c.config[s].labelKey,label:"Members' name",description:"Choose the field that contains the members name.",data:fe,onChange:z=>A("labelKey",z)}),jsx(Space,{h:"md"}),jsx(Select,{value:c.config[s].zValueKey||"",label:"Member's relevance (optional)",description:`Choose a field that will be converted to a number and
6
+ normalized from 0 to 1 to determine the member's relevance.`,data:[{value:"null",label:"None"},...fe],onChange:z=>A("zValueKey",z)}),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[s].attributes&&c.config[s].attributes.map((z,X)=>jsxs(Group,{align:"end",grow:true,children:[jsx(Select,{value:c.config[s].attributes[X].type,label:"Type",data:[{value:"variable",label:"Data based"},{value:"constant",label:"Constant"}],readOnly:s!==n,disabled:s!==n,onChange:ie=>re("type",X,ie)}),jsx(TextInput,{value:c.config[s].attributes[X].name,label:"Name",readOnly:s!==n,disabled:s!==n,onChange:ie=>re("name",X,ie.target.value)}),z.type==="variable"&&jsx(Select,{value:c.config[s].attributes[X].value,label:"Value",data:fe,onChange:ie=>re("value",X,ie)}),z.type==="constant"&&jsx(TextInput,{value:c.config[s].attributes[X].value,label:"Value",onChange:ie=>re("value",X,ie.target.value)}),jsx(ActionIcon,{color:"red",onClick:()=>ae(X),disabled:s!==n,children:jsx(IconTrash,{size:20})})]},X)),jsx(Space,{h:"md"}),jsx(Button,{onClick:ce,leftIcon:"+",disabled:m||s!==n,children:"Add Attribute"})]})]}),jsx(Space,{h:"md"})]})]})]})]}),buttons:jsxs(Fragment,{children:[jsx(Button,{disabled:m||g$1||!b&&!d.valid,onClick:t,variant:"outline",children:"Cancel"}),jsx(Button,{disabled:m||g$1||!b&&!d.valid,loading:m||g$1,onClick:Q,children:`${W.doIngest?`${!N&&K.length>0?"Re-":""}Ingest & `:""}Save`})]}),size:165})}var hd=cb(oS,Ha);function kd({id:e,onClose:t}){let o=ua(),n=Ga$1(e),[r,i$1]=useState({id:e}),[a,l]=useState(null);useEffect(()=>{n.isSuccess&&i$1(n.data);},[n.status]);let s=useCallback(f=>{o(ta$1.createEntity("variant",{dimension_id:e,name:f.name,slug:i(f.name)}));},[e]),u=useCallback(()=>{o(ta$1.updateEntity("dimension",{...r,id:e})).then(t);},[r]),c=useCallback((f,g)=>{i$1({...r,[f]:f==="slug"?i(g):g});},[]);if(a)return jsx(hd,{id:a,onClose:()=>l(null)});let p=n.isFetching,m=n.isSuccess?n.data.variants:[];return jsx(yt,{content:jsxs(Fragment,{children:[jsx(Title,{order:2,children:`Dimension metadata: ${r.name}`}),jsx(Space,{h:"xs"}),jsx(TextInput,{value:r.name,label:"Name",onChange:f=>c("name",f.target.value)}),jsx(Space,{h:"xs"}),jsx(NumberInput,{value:r.ordering?parseInt(`${r.ordering||0}`,10):0,type:"number",label:"Order",onChange:f=>c("ordering",f)}),jsx(Divider,{my:"xl"}),jsx(zn,{icon:jsx(IconServer,{size:22}),children:jsx(Title,{order:2,size:"h4",children:"Variants"})}),m.map(f=>jsx(cd,{id:f,onEdit:l},f)),jsx(Fn,{fields:[{name:"name",type:"text",label:"Add Variant"}],onSubmit:s,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})}function Rd({id:e,onClose:t}){let o=ua(),n=Da$1(e),[r,i$1]=useState({id:e}),[a,l]=useState(null);useEffect(()=>{n.isSuccess&&i$1(n.data);},[n.status]);let s=useCallback((h,b)=>{o(ta$1.createEntity("dimension",{report_id:e,name:h.name,ordering:b.length+1})).then(C=>{C.ok&&o(ta$1.createEntity("variant",{dimension_id:C.data.id,name:C.data.name,slug:i(C.data.name)}));});},[e]),u=useCallback(()=>{o(ta$1.updateEntity("report",{...r,id:e})).then(t);},[e,r]),c=useCallback((h,b)=>{i$1({...r,[h]:b});},[]),p=(h,b)=>{i$1({...r,settings:{...r.settings,[h]:b}});};if(a)return jsx(kd,{id:a,onClose:()=>l(null)});let m=n.isFetching,f=n.isSuccess?n.data.dimensions:[],g=r.settings,S=g&&typeof g.order=="number"?g.order:0,v=g&&typeof g.hide=="boolean"?g.hide:false;return jsx(yt,{content:jsxs(Fragment,{children:[jsx(Title,{order:2,children:`Report metadata: ${r.name}`}),jsx(Space,{h:"xs"}),jsx(TextInput,{value:r.name,label:"Name",onChange:h=>c("name",h.target.value)}),jsx(Space,{h:"xs"}),jsxs(Group,{grow:true,children:[jsx(_r,{switchProps:{label:"Show in Explore & Search",checked:!v,onChange:h=>p("hide",!h.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:S,description:"It affects the Explore search options order",placeholder:"Order in Explore",label:"Order",disabled:v,onChange:h=>{p("order",h);}})]}),jsx(Divider,{my:"sm"}),jsx(zn,{icon:jsx(IconDatabase,{size:22}),children:jsx(Title,{order:2,size:"h4",children:"Dimensions"})}),jsx(Grid,{children:f.map(h=>jsx(Grid.Col,{span:6,children:jsx(od,{id:h,onEdit:l})},h))}),jsx(Fn,{fields:[{type:"text",name:"name",label:"Add Dimension"}],onSubmit:(h=>s(h,f)),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 Bd(e){let{report:t}=e,{newConfirmation:o}=b(),{selectEntity:n}=Ka(),r=useContext(db$1),i=Ya(r),a=ua(),l=va$1(F=>F.status.previews),s=a$2(),u=Number.parseInt(s.params[0]),c=Da$1(u),p=Qa$1(),m=Ra$1(),f=b$2(),g=va$1(F=>F.status.localeDefault),S=Za("settings"),v=Za("reportEditor"),h=Za("tools"),b$1=Za("debugView"),C=g$2(u),d=t&&t.dimensions?t.dimensions:[],y=d.length>0,x=l.filter(F=>F.variant_slug).reduce((F,L)=>F.concat([L.variant_slug,L.slug]),[]),k=f===g?"":`/${f}`,R=m||p,B=x.length?`${k}${R}/${x.join("/")}`:"",N=x.length?`${k}${p}/${x.join("/")}`:"",[$,K]=useState(null),T=useMemo(()=>{let F=[];return B&&m&&F.push({value:"preview",label:"Open Preview",url:B,Icon:IconFileCode}),N&&F.push({value:"report",label:"Open Report",url:N,Icon:IconFileAnalytics}),F},[B,N,m]);useEffect(()=>{!$&&T.length>0&&K(T[0].value);},[T,$]);let M=useMemo(()=>T.find(F=>F.value===$)||null,[T,$]),I=useCallback(()=>{M?.url&&window.open(M.url,"_blank","noopener,noreferrer");},[M]),O=useCallback(F=>{K(F);},[]),G=F=>{s.setSearchParam("locale",F),a(ta$1.readMember({mode:"content_ids",variant:l.map(L=>L.variant_id),content_ids:l.map(L=>L.content_id),locale:F,output:"full"})).then(({results:L})=>{a(ta$1.setCurrentLocale(F)),L&&L.length===d.length&&d.length?i({previews:L}):i({previews:[]});});},W=useCallback(async()=>{try{let F=N;await o({title:"Are you sure?",message:`Revalidate action will force to regenerate page: ${F}.`,confirmText:"Revalidate now!"}),await a(ta$1.revalidateUrl({target:F})).then(L=>{let U=`Revalidated page ${L.target} you will see the changes in the following minutes.`;notifications.show({autoClose:!1,color:"green",id:"revalidate-results",message:U,title:"Revalidate Results"});}).catch(L=>{notifications.show({autoClose:!1,color:"red",id:"revalidate-error",message:L.message,title:"Revalidate Error"});});}catch{console.error("Revalidate error.");}},[B,N,m]);return jsxs(Fragment,{children:[jsx($p,{left:jsxs(Group,{children:[jsx(ActionIcon,{color:"blue",variant:"filled",onClick:()=>{n({type:"report",id:t.id}),S.handlers.open();},children:jsx(IconSettingsFilled,{size:20})}),jsx(Lr,{value:f,onChange:G,selectProps:{size:"xs",maw:80}}),jsx(SegmentedControl,{size:"xs",radius:"sm",sx:F=>({background:F.colors.blue[0]}),data:[{label:"Editor",value:"editor"},{label:"Debug",value:"debug"}],onChange:F=>{F==="editor"?b$1.handlers.close():(h.handlers.close(),v.handlers.close(),S.handlers.close(),b$1.handlers.open());}})]}),center:jsxs(Group,{children:[jsx(qs,{report:t,defaultMembers:C?.map(F=>({variantId:F.variantId,memberId:F.contentId})),locale:f}),(B||N)&&T.length>0&&jsxs(Group,{spacing:0,children:[jsx(Button,{onClick:I,disabled:!M,variant:"light",fw:700,radius:"sm",fz:12,pr:10,pl:5,mih:"1.875rem",compact:true,leftIcon:M?.Icon?jsx(M.Icon,{size:14}):null,sx:{borderTopRightRadius:0,borderBottomRightRadius:0},children:M?.label||"Select view"}),jsxs(Menu,{position:"bottom",withArrow:true,children:[jsx(Menu.Target,{children:jsx(ActionIcon,{variant:"light",radius:"sm",sx:F=>({borderTopLeftRadius:0,borderBottomLeftRadius:0,borderLeft:"1px solid #fff",backgroundColor:"#e7f5ff",minHeight:"1.875rem",height:"1.875rem",width:"1.875rem",fontSize:"12px"}),children:jsx(IconChevronDown,{size:14,color:"#228be6"})})}),jsx(Menu.Dropdown,{children:T.map(F=>{let L=F.Icon;return jsx(Menu.Item,{onClick:()=>O(F.value),icon:L?jsx(L,{size:20}):null,children:F.label},F.value)})})]})]})]}),right:jsxs(Group,{children:[l.length>0&&$!=="preview"&&jsx(Button,{variant:"light",fw:700,radius:"sm",fz:12,pr:10,pl:5,mih:"1.875rem",onClick:W,leftIcon:jsx(IconWorldUpload,{size:14}),compact:true,children:"Publish"}),!y&&jsx(Button,{size:"xs",variant:"outline",onClick:v.handlers.open,children:"Import Data"})]})}),jsx(Drawer,{opened:v.opened,onClose:v.handlers.close,title:jsx(zn,{icon:jsx(IconFileAnalytics,{size:24}),children:`Editing Report: ${c.data?c.data.name:""}`}),size:"50%",padding:"xl",position:"right",children:jsx(Rd,{id:u,onClose:v.handlers.close})})]})}function OS({type:e,id:t,warning:o=""}){let n=v[e]||"Entity",r=o||`Delete this ${n} and all its contents? This action cannot be undone.`,i=useDispatch(),{newConfirmation:a}=b();return jsx(ActionIcon,{color:"red",onClick:async()=>{try{await a({title:"Are you sure?",message:r,confirmText:"Yes, Delete it."}),i(ta$1.deleteEntity(e,t));}catch{}},children:jsx(IconTrash,{size:20})})}var Nd=OS;var _d=e=>!e||e.trim()===""?false:e.trim().startsWith("/")?true:Gn(e);function US({defaultValue:e,id:t,onChangeAPI:o,onDelete:n,finalUrl:r,dataSource:i,pos:a}){let l=Oa$1(),s=Sa$1(t),[u,c]=useState(()=>I(e,l,s)),[p,m]=useState(e),[f,g]=useState(false),S=B=>{f&&!k&&(B.preventDefault(),o(p),g(false));},v=B=>{let{value:N}=B.target;c(I(N,l,s)),m(N);},h=()=>{g(false),c(I(e,l,s));},b=()=>{g(!f);},C=()=>{n();},d=useMemo(()=>(u||"").indexOf("bespoke_slugs=")>-1,[u]),y=useMemo(()=>!(u&&(u.trim()===""||_d(u))),[u,_d]),x=useMemo(()=>u.includes("N/A"),[u]),k=useMemo(()=>y||x,[y,x]),R=useMemo(()=>{let B=[];return y&&B.push("Invalid URL format"),x&&B.push("URL contains 'N/A', probably you are using a variable that is not in scope"),B.join(". ")},[y,x]);return jsxs(Stack,{spacing:0,p:f?"xs":0,mb:f?3:0,bg:f?"gray.0":"transparent",children:[jsxs(Group,{noWrap:true,position:"apart",spacing:"xs",children:[jsxs(Text,{lineClamp:1,size:"xs",children:[a,". ",jsx(Anchor,{href:r||u,target:"_blank",rel:"noreferrer",children:r||u||"--Add API Url--"})]}),jsx(Group,{noWrap:true,spacing:0,children:f?jsxs(Fragment,{children:[jsx(Tooltip,{label:k?"Invalid URL format":"Apply changes",children:jsx(ActionIcon,{size:"md",onClick:S,color:"green",sx:{opacity:k?.4:1},children:jsx(IconCheck,{size:rem(20)})})}),jsx(ActionIcon,{size:"md",onClick:h,color:"red",children:jsx(IconX,{size:rem(20)})})]}):jsxs(Fragment,{children:[d&&jsx(Tooltip,{multiline:true,label:"Slugs Interceptor Enabled",children:jsx(IconGitMerge,{size:rem(18),color:"gray"})}),i&&jsx(Tooltip,{multiline:true,label:`Datasource Interceptor Enabled called "${i}"`,children:jsx(IconNetwork,{size:rem(18),color:"gray"})}),x&&jsx(Tooltip,{multiline:true,label:"API URL contains 'N/A', probably you are using a variable that is not in scope",children:jsx(IconAlertTriangle,{size:rem(20),color:"red"})}),jsx(ActionIcon,{size:"md",onClick:b,children:jsx(IconPencil,{size:rem(20)})}),jsx(ActionIcon,{size:"md",onClick:C,children:jsx(IconTrash,{color:"red"})})]})})]}),f&&jsx(Stack,{spacing:"xs",children:jsx(Textarea,{placeholder:"API URL here: https://api.example.com/v1/data?id={{id1}}",defaultValue:p,onChange:v,onKeyDown:getHotkeyHandler([["enter",S]]),size:"sm",minRows:2,maxRows:6,autosize:true,sx:{width:"100%"},error:k?`${R} ${u}`:false},"textarea")})]})}var Gd=US;function qS({monacoOptions:e}){let t=useMonaco();return useEffect(()=>{if(t){let o="Monokai";import(`monaco-themes/themes/${o}.json`).then(n=>{t.editor.defineTheme(o,n),t.editor.setTheme(o);}).catch(()=>{throw new Error("Invalid Monaco theme")});}},[t]),jsx(Box,{className:"cr-monaco-container",w:"100%",children:jsx(jS,{defaultLanguage:"javascript",theme:"Monokai",...e})})}var rn=qS;function ax({status:e,block:t,variables:o}){let{settings:n,contentByLocale:r}=t,i=!!(n&&n.useProxy&&n.useProxy==="true"),a=r?.logic?.content?.api&&r.logic.content.api!==""?r.logic.content.api.split("|||").length:0,l=e&&e.apiDataSources?e.apiDataSources.some(f=>f!==false):false,s=useMemo(()=>e.apiFinalUrls?typeof e.apiFinalUrls=="string"?e.apiFinalUrls.includes("N/A")?1:0:Array.isArray(e.apiFinalUrls)?e.apiFinalUrls.filter(f=>f.includes("N/A")).length:0:0,[e.apiFinalUrls]),u=!!([z.GENERATOR,z.SECTION_FLAG].includes(t.type)&&e.api&&e.api.indexOf("bespoke_slugs=")>-1),c=W(t),p=c?o[T]:false,m=[z.GENERATOR,z.SECTION_FLAG].includes(t.type)&&o?JSON.stringify(o).length/1024:void 0;return jsxs(Group,{spacing:5,children:[jsx(Tooltip,{multiline:true,label:`Number of requests: ${a}`,children:jsx(ThemeIcon,{size:"sm",radius:"xl",color:"blue",children:jsx(Text,{size:rem(12),span:true,fw:"bold",children:a})})}),s>0&&jsx(Tooltip,{multiline:true,label:`${s} of your URLs in this generator contains 'N/A', probably you are using a variable that is not in scope`,children:jsx(ThemeIcon,{size:"sm",radius:"xl",color:"orange",children:jsx(IconAlertTriangle,{size:rem(12)})})}),i&&jsx(Tooltip,{multiline:true,label:`Use Proxy Setting (avoid CORS): ${i?"YES":"NO"}`,children:jsx(ThemeIcon,{size:"sm",radius:"xl",color:"blue",children:jsx(IconCloudNetwork,{size:rem(12)})})}),l&&jsx(Tooltip,{multiline:true,label:"Data Source Interceptor Active at least in one request",children:jsx(ThemeIcon,{size:"sm",radius:"xl",color:"blue",children:jsx(IconNetwork,{size:rem(12)})})}),u&&jsx(Tooltip,{multiline:true,label:"Slugs Interceptor Enabled at least in one request",children:jsx(ThemeIcon,{size:"sm",radius:"xl",color:"blue",children:jsx(IconGitMerge,{size:rem(12)})})}),e.duration&&jsx(Tooltip,{multiline:true,label:`Api Call Duration: ${e.duration} ms`,children:jsx(ThemeIcon,{size:"sm",radius:"xl",color:ba(e.duration),children:jsx(IconClockHour2,{size:rem(12)})})}),e.responseSize&&jsx(Tooltip,{multiline:true,label:`Api Response Size: \u2248${e.responseSize.toFixed(2)} Kb`,children:jsx(ThemeIcon,{size:"sm",radius:"xl",color:ca(e.responseSize),children:jsx(IconApi,{size:rem(12)})})}),m&&jsx(Tooltip,{multiline:true,label:`Block Output Size: \u2248${m.toFixed(2)} Kb`,children:jsx(ThemeIcon,{size:"sm",radius:"xl",color:ca(m),children:jsx(IconAugmentedReality,{size:rem(12)})})}),c&&jsx(Tooltip,{multiline:true,label:`Section #${t.section_id} Allowed Flag: ${p?"YES":"NO"}`,children:jsx(ThemeIcon,{size:"sm",radius:"xl",color:p?"green":"red",children:jsx(IconFlag,{size:rem(12)})})})]})}var pa=ax;var da={api:null,duration:null,error:null,log:[],responseSize:null,resp:null,allowed:true};function yx({block:e,status:t,sectionFlag:o,variables:n}){let r=useMemo(()=>o?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"})}),[o]);return jsxs(Fragment,{children:[jsxs(Group,{position:"left",pt:"xl",children:[jsxs(Group,{children:[r,jsxs(Title,{order:6,children:[P$1[e.type]," ",e.id]})]}),jsx(Group,{my:"xs",children:jsx(pa,{status:t,block:e,variables:n})})]}),jsx(Divider,{})]})}function vx(e){let{active:t,allowed:o$1,blockStateContent:n,blockStateSettings:r,debug:i,for:a,locale:l,isFetching:s}=e,u=La$1(a.id),c$1=Oa$1(),p=Pa$1(),m=Sa$1(a.id,l),f=va$1(M=>M.variables.variables[a.id]||{}),g=va$1(M=>M.variables.status[a.id]||{}),S=R[a.type].renderPreviewOnEdit&&n?n:O(a,l),v=R[a.type].renderPreviewOnEdit&&r?r:a.settings,[h,b]=useState(null),[C,d]=useState(da),y=W(a),x=c(),k=a$1();useEffect(()=>{(async()=>{if(a.type===z.VIZ){b({block:a,locale:l,variables:u,active:t}),d(da);return}if(!t&&!R[a.type].evalWhenNonActive){let{nonActiveAdapter:L}=R[a.type],U=L&&typeof L=="function"?L():{};b(U),d(da);return}if([z.GENERATOR,z.SECTION_FLAG].includes(a.type)){let L=!!a.contentByLocale?.logic?.content?.api,U=y?f[T]:false;b({outputVariables:f,hasAPI:L,sectionAllowed:U,type:a.type}),d(g);return}if([z.SELECTOR,z.MULTIHIERARCHY_SELECTOR].includes(a.type)){let{renderVariables:L,status:U}=await _(a,c$1,m,x,p,k),P=o[a.type]&&typeof o[a.type]=="function"?o[a.type](L,a.id):L;b(P),d(U);return}if(a.type===z.RELATED){let{outputVariables:L}=await _(a,c$1,m,x,p,k),{related_reports:U}=L;b({related_reports:U});return}if(a.type===z.RESET_BUTTON||a.type===z.COMPARISON_BUTTON){b(S.simple||{});return}let I$1=I(S?.logic,c$1,m),{vars:O,error:G,log:W}=H("variables",u,I$1,c$1,void 0,m),F=o[a.type]&&typeof o[a.type]=="function"?o[a.type](O,a.id):O;if(a.type===z.NAV){b({headings:a.inputs,settings:a.settings,...F});return}b(F),d({...da,error:G,log:W});})();},[S,u,y]),useEffect(()=>{g&&g.error&&g.error!==""&&notifications.show({autoClose:1e4,color:"red",id:"block-error",message:g.error,title:`Block error ID: ${a.id}`});},[g.error]);let R$1=M[a.type],N=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:true,children:g.hiddenByCascade===a.id?`${a.type} not allowed`:`${a.type} hidden by block ${g.hiddenByCascade}`})})});if(s)return jsx(Center,{style:{minHeight:100},w:"100%",children:jsx(Loader,{})});if(!h)return null;let{error:$,log:K}=C,T$1=K?K.join(`
7
+ `):"";return jsxs("div",{id:`bespoke-${a.type}-${a.id}`,className:"cms-block-preview bespoke-block-area",style:{width:"100%",minHeight:a.type===z.VIZ?400:"auto"},children:[!o$1&&N,[z.GENERATOR,z.SECTION_FLAG].includes(a.type)&&jsx(yx,{block:a,status:C,sectionFlag:y,variables:h}),R$1?jsx(Fragment$1,{children:jsx(R$1,{id:a.id,debug:i,section:a.section_id,...h,settings:v,status:C})},"renderer"):jsx(Center,{style:{minHeight:100},children:jsx(Badge,{color:"gray",variant:"outline",children:a.type},"type")}),i&&T$1&&jsx(Textarea,{label:"Console",minRows:3,readOnly:true,autosize:true,maxRows:10,value:T$1,error:$}),i&&$&&jsx(Textarea,{label:"Error",readOnly:true,autosize:true,minRows:3,maxRows:10,value:$})]})}var ma=cb(vx,Fa$1);function Ax({id:e,setBlockSettings:t}){let{newConfirmation:o}=b(),n=ua(),r=Fa$1(e).data,[i,a]=useState(r.settings[C$1.ACCESS]||["public"]),[l,s]=useState(r.settings[C$1.FALLBACK]||false),u=La$1(e),c=useMemo(()=>[{value:"always",label:"always",group:"Static"},{value:"never",label:"never",group:"Static"}].concat(Object.keys(u).map(y=>({value:y,label:`${y}: ${u[y]}`,group:"Based on variable"}))),[u]),p=[{label:"Section-wide",value:"false"},{label:"Report-wide",value:"true"}];useEffect(()=>{t({[C$1.ACCESS]:i}),i.includes("public")&&s(false);},[i]),useEffect(()=>{t({[C$1.FALLBACK]:l});},[l]);let m=async()=>{try{await o({title:"Are you sure?",message:"Delete this block and all its contents? This action cannot be undone.",confirmText:"Yes, Delete it."}),n(ta$1.deleteEntity("block",e));}catch{}},f=(y,x)=>{t({[y]:x});},g=y=>{let x=`return variables.${y}`;y==="always"&&(x="return true;"),y==="never"&&(x="return false;"),t({[C$1.ALLOWED]:y,[C$1.ALLOWED_LOGIC]:x});},S=y=>{t({[C$1.IGNORE_CASCADE]:y});},v=va$1(y=>y.records.entities.block),h=r.consumers.filter(y=>v[y].section_id!==r.section_id),b$1=!!h.length,C=h.slice(0,3).map((y,x)=>jsxs(Fragment,{children:[x===h.length-1&&h.length>1?"and ":"",jsx("strong",{children:`${v[y].type} ${y} [Section ${v[y].section_id}]`},y),x<h.length-1&&h.length>1?", ":""]})),d=r.inputs.map(y=>({label:`${v[y]?.type} - ${v[y]?.id}`,value:y}));return jsx(Group,{grow:true,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:r.settings[C$1.ALLOWED]||"always",onChange:g,data:c}),[z.GENERATOR,z.VIZ,z.SECTION_FLAG].includes(r.type)&&jsx(MultiSelect,{label:"Ignore cascade",description:"Set block as visible even if the selected inputs are hidden.",defaultValue:r.settings[C$1.IGNORE_CASCADE]||[],data:d,onChange:S}),jsx(I$1,{value:i,onChange:a}),jsx(Checkbox,{checked:l,disabled:i.includes("public"),label:"Show fallback block when block is not allowed",onChange:y=>s(y.currentTarget.checked)}),jsx(Title,{order:4,children:"Output"}),b$1&&r.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:true,inherit:true,children:["This block is being consumed by ",C,h.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(r.shared),disabled:b$1&&r.shared,onChange:y=>f("shared",y==="true"),data:p}),jsx(Title,{order:4,children:"Danger zone"}),jsx(Button,{variant:"outline",color:"red",onClick:m,children:"Delete Block"})]})})}var Qd=Ax;var gl={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 Ux({id:e}){let t=ua(),o=useContext(db$1),n=Ya(o),[r,i]=useState(""),[a]=useDebouncedValue(r,200),l$1=va$1(v=>{if(v.records.reports&&v.records.reports[0]){let h=v.records.reports[0],b=v.records.entities.report[h].sections;return Object.values(v.records.entities.block).filter(C=>b.includes(C.section_id))}return []}),s=Fa$1(e).data,u=va$1(v=>v.variables.variables),c=useMemo(()=>s?s.inputs.reduce((v,h)=>({...v,[h]:l$1[h]}),{}):[],[s]),p=(v,h)=>{if(!s)return 0;let b=s.inputs.includes(v.id),C=s.inputs.includes(h.id);if(b!==C)return b?1:-1;let d=Object.keys(u[v.id]||{}).length,y=Object.keys(u[h.id]||{}).length;return d!==y?y-d:v.shared?1:-1},m=useMemo(()=>l$1.filter(v=>v.id!==s.id&&(v.section_id===s.section_id||v.shared)&&v.type!==z.SECTION_FLAG).sort(p),[l$1]),f=useMemo(()=>m.filter(v=>{let h=String(v.id).includes(a.trim()),b=Object.keys(u[v.id]||{}).some(C=>C.includes(a.trim()));return h||b}),[m,a,u]),g=v=>{let h=c[v]?"delete":"create";t(ta$1.updateEntity("block",{id:e,inputAction:{operation:h,input:{input_id:v,block_id:e}}})).then(()=>{n();});};if(!s)return null;let S=v=>s.consumers.includes(v)?gl.Consumer:s.inputs.includes(v)?gl.Input:gl.None;return jsxs(Menu,{width:"425px",children:[jsx(Menu.Target,{children:jsx(Button,{fullWidth:true,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:v=>i(v.target.value)}),f.map(({id:v,shared:h})=>jsx(Menu.Item,{disabled:s.consumers.includes(v),onClick:()=>g(v),icon:S(v),rightSection:jsxs(Stack,{ml:"xs",spacing:"xs",align:"flex-end",children:[jsxs(Text,{size:"xs",color:"gray.6",children:["[",v,"]"]}),h?jsx(ThemeIcon,{size:"xs",radius:"xl",children:jsx(IconGlobe,{})}):null]}),children:jsx(Box,{style:{maxWidth:"400px"},children:jsx(l,{id:`${v}`,variables:u[v]})})},v))]})]})}var Zd=Ux;var hl=e=>`
8
+ `.padEnd(e*2+1," "),em=(e,t=0)=>{let o=e instanceof Array;return `${o?"[":"{"}${hl(t+1)}${Object.keys(e).sort((n,r)=>n.localeCompare(r)).map(n=>{let r=o?"":`${n}: `,i=e[n];return typeof i=="object"?r+=`${em(i,t+1)}`:typeof i=="string"&&(i.includes("=>")||i.startsWith("variables["))?r+=`${i}`:typeof i=="string"&&!i.length?r+="false":i===void 0?r=null:["boolean","number"].includes(typeof i)?r+=i:r+=`"${i}"`,r}).filter(n=>n!==null).join(`,${hl(t+1)}`)}${hl(t)}${o?"]":"}"}`},Yn=em;var tm=e=>{if(!e)return e;let t=Array.isArray(e)?[]:{};return Object.keys(e).forEach(o=>{t[o]=typeof e[o]=="object"?tm(e[o]):e[o];}),t},ya=tm;var Hx=(e,t=false)=>{let o=/([A-z0-9]*)\{\{([^}]+)\}\}/g,n=(a,l,s)=>l?`\${formatters.${l}(variables.${s})}`:`\${variables.${s}}`,r=a=>typeof a=="string"?a.trim()===""?false:t?a.replace(o,n):a:Array.isArray(a)?a.map(l=>r(l)):typeof a=="object"&&a!==null?Object.keys(a).sort((l,s)=>l.localeCompare(s)).reduce((l,s)=>({...l,[s]:r(a[s])}),{}):typeof a=="boolean"||typeof a=="number"?a:JSON.stringify(a),i=r(e);return Array.isArray(e)?`return ${JSON.stringify(i)};`:Object.keys(i).sort((a,l)=>a.localeCompare(l)).reduce((a,l)=>{let s;return typeof i[l]=="string"?i[l].includes("=>")||i[l].startsWith("variables[")?s=i[l]:s=`\`${i[l]}\``:typeof i[l]=="boolean"||typeof i[l]=="number"?s=i[l]:s=JSON.stringify(i[l]),a.concat(`"${l}": ${s},
9
+ `)},"return {").concat("};")},ro=Hx;function cm(e){let{state:t,transaction:o}=e,{selection:n}=o,{doc:r}=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 n},get doc(){return r},get tr(){return n=o.selection,r=o.doc,i=o.storedMarks,o}}}var Sl=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:n}=this,{view:r}=o,{tr:i}=n,a=this.buildProps(i);return Object.fromEntries(Object.entries(t).map(([l,s])=>[l,(...c)=>{let p=s(...c)(a);return !i.getMeta("preventDispatch")&&!this.hasCustomState&&r.dispatch(i),p}]))}get chain(){return ()=>this.createChain()}get can(){return ()=>this.createCan()}createChain(t,o=true){let{rawCommands:n,editor:r,state:i}=this,{view:a}=r,l=[],s=!!t,u=t||i.tr,c=()=>(!s&&o&&!u.getMeta("preventDispatch")&&!this.hasCustomState&&a.dispatch(u),l.every(m=>m===true)),p={...Object.fromEntries(Object.entries(n).map(([m,f])=>[m,(...S)=>{let v=this.buildProps(u,o),h=f(...S)(v);return l.push(h),p}])),run:c};return p}createCan(t){let{rawCommands:o,state:n}=this,r=false,i=t||n.tr,a=this.buildProps(i,r);return {...Object.fromEntries(Object.entries(o).map(([s,u])=>[s,(...c)=>u(...c)({...a,dispatch:void 0})])),chain:()=>this.createChain(i,r)}}buildProps(t,o=true){let{rawCommands:n,editor:r,state:i}=this,{view:a}=r,l={tr:t,editor:r,view:a,state:cm({state:i,transaction:t}),dispatch:o?()=>{}:void 0,chain:()=>this.createChain(t,o),can:()=>this.createCan(t),get commands(){return Object.fromEntries(Object.entries(n).map(([s,u])=>[s,(...c)=>u(...c)(l)]))}};return l}};function dt(e,t,o){return e.config[t]===void 0&&e.parent?dt(e.parent,t,o):typeof e.config[t]=="function"?e.config[t].bind({...o,parent:e.parent?dt(e.parent,t,o):null}):e.config[t]}function bC(e){let t=e.filter(r=>r.type==="extension"),o=e.filter(r=>r.type==="node"),n=e.filter(r=>r.type==="mark");return {baseExtensions:t,nodeExtensions:o,markExtensions:n}}function rt(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 um(...e){return e.filter(t=>!!t).reduce((t,o)=>{let n={...t};return Object.entries(o).forEach(([r,i])=>{if(!n[r]){n[r]=i;return}if(r==="class"){let l=i?i.split(" "):[],s=n[r]?n[r].split(" "):[],u=l.filter(c=>!s.includes(c));n[r]=[...s,...u].join(" ");}else if(r==="style"){let l=i?i.split(";").map(c=>c.trim()).filter(Boolean):[],s=n[r]?n[r].split(";").map(c=>c.trim()).filter(Boolean):[],u=new Map;s.forEach(c=>{let[p,m]=c.split(":").map(f=>f.trim());u.set(p,m);}),l.forEach(c=>{let[p,m]=c.split(":").map(f=>f.trim());u.set(p,m);}),n[r]=Array.from(u.entries()).map(([c,p])=>`${c}: ${p}`).join("; ");}else n[r]=i;}),n},{})}function yC(e){return typeof e=="function"}function nt(e,t=void 0,...o){return yC(e)?t?e.bind(t)(...o):e(...o):e}function vC(e){return Object.prototype.toString.call(e)==="[object RegExp]"}var Ta=class{constructor(t){this.find=t.find,this.handler=t.handler;}};var xl=class{constructor(t){this.find=t.find,this.handler=t.handler;}};function SC(e){return Object.prototype.toString.call(e).slice(8,-1)}function va(e){return SC(e)!=="Object"?false:e.constructor===Object&&Object.getPrototypeOf(e)===Object.prototype}function Pa(e,t){let o={...e};return va(e)&&va(t)&&Object.keys(t).forEach(n=>{va(t[n])&&va(e[n])?o[n]=Pa(e[n],t[n]):o[n]=t[n];}),o}var ao=class e{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(dt(this,"addOptions",{name:this.name}))),this.storage=nt(dt(this,"addStorage",{name:this.name,options:this.options}))||{};}static create(t={}){return new e(t)}configure(t={}){let o=this.extend({...this.config,addOptions:()=>Pa(this.options,t)});return o.name=this.name,o.parent=this.parent,o}extend(t={}){let o=new e({...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(dt(o,"addOptions",{name:o.name})),o.storage=nt(dt(o,"addStorage",{name:o.name,options:o.options})),o}};function xC(e,t,o){let{from:n,to:r}=t,{blockSeparator:i=`
10
+
11
+ `,textSerializers:a={}}=o||{},l="";return e.nodesBetween(n,r,(s,u,c,p)=>{var m;s.isBlock&&u>n&&(l+=i);let f=a?.[s.type.name];if(f)return c&&(l+=f({node:s,pos:u,parent:c,index:p,range:t})),false;s.isText&&(l+=(m=s?.text)===null||m===void 0?void 0:m.slice(Math.max(n,u)-u,r-u));}),l}function CC(e){return Object.fromEntries(Object.entries(e.nodes).filter(([,t])=>t.spec.toText).map(([t,o])=>[t,o.spec.toText]))}ao.create({name:"clipboardTextSerializer",addOptions(){return {blockSeparator:void 0}},addProseMirrorPlugins(){return [new Plugin({key:new PluginKey("clipboardTextSerializer"),props:{clipboardTextSerializer:()=>{let{editor:e}=this,{state:t,schema:o}=e,{doc:n,selection:r}=t,{ranges:i}=r,a=Math.min(...i.map(c=>c.$from.pos)),l=Math.max(...i.map(c=>c.$to.pos)),s=CC(o);return xC(n,{from:a,to:l},{...this.options.blockSeparator!==void 0?{blockSeparator:this.options.blockSeparator}:{},textSerializers:s})}}})]}});var kC=()=>({editor:e,view:t})=>(requestAnimationFrame(()=>{var o;e.isDestroyed||(t.dom.blur(),(o=window?.getSelection())===null||o===void 0||o.removeAllRanges());}),true),TC=(e=false)=>({commands:t})=>t.setContent("",e),wC=()=>({state:e,tr:t,dispatch:o})=>{let{selection:n}=t,{ranges:r}=n;return o&&r.forEach(({$from:i,$to:a})=>{e.doc.nodesBetween(i.pos,a.pos,(l,s)=>{if(l.type.isText)return;let{doc:u,mapping:c}=t,p=u.resolve(c.map(s)),m=u.resolve(c.map(s+l.nodeSize)),f=p.blockRange(m);if(!f)return;let g=liftTarget(f);if(l.type.isTextblock){let{defaultType:S}=p.parent.contentMatchAt(p.index());t.setNodeMarkup(f.start,S);}(g||g===0)&&t.lift(f,g);});}),true},EC=e=>t=>e(t),IC=()=>({state:e,dispatch:t})=>createParagraphNear(e,t),AC=(e,t)=>({editor:o,tr:n})=>{let{state:r}=o,i=r.doc.slice(e.from,e.to);n.deleteRange(e.from,e.to);let a=n.mapping.map(t);return n.insert(a,i.content),n.setSelection(new TextSelection(n.doc.resolve(a-1))),true},PC=()=>({tr:e,dispatch:t})=>{let{selection:o}=e,n=o.$anchor.node();if(n.content.size>0)return false;let r=e.selection.$anchor;for(let i=r.depth;i>0;i-=1)if(r.node(i).type===n.type){if(t){let l=r.before(i),s=r.after(i);e.delete(l,s).scrollIntoView();}return true}return false},RC=e=>({tr:t,state:o,dispatch:n})=>{let r=rt(e,o.schema),i=t.selection.$anchor;for(let a=i.depth;a>0;a-=1)if(i.node(a).type===r){if(n){let s=i.before(a),u=i.after(a);t.delete(s,u).scrollIntoView();}return true}return false},OC=e=>({tr:t,dispatch:o})=>{let{from:n,to:r}=e;return o&&t.delete(n,r),true},MC=()=>({state:e,dispatch:t})=>deleteSelection(e,t),DC=()=>({commands:e})=>e.keyboardShortcut("Enter"),LC=()=>({state:e,dispatch:t})=>exitCode(e,t);function wa(e,t,o={strict:true}){let n=Object.keys(t);return n.length?n.every(r=>o.strict?t[r]===e[r]:vC(t[r])?t[r].test(e[r]):t[r]===e[r]):true}function Cl(e,t,o={}){return e.find(n=>n.type===t&&wa(n.attrs,o))}function BC(e,t,o={}){return !!Cl(e,t,o)}function kl(e,t,o={}){if(!e||!t)return;let n=e.parent.childAfter(e.parentOffset);if(e.parentOffset===n.offset&&n.offset!==0&&(n=e.parent.childBefore(e.parentOffset)),!n.node)return;let r=Cl([...n.node.marks],t,o);if(!r)return;let i=n.index,a=e.start()+n.offset,l=i+1,s=a+n.node.nodeSize;for(Cl([...n.node.marks],t,o);i>0&&r.isInSet(e.parent.child(i-1).marks);)i-=1,a-=e.parent.child(i).nodeSize;for(;l<e.parent.childCount&&BC([...e.parent.child(l).marks],t,o);)s+=e.parent.child(l).nodeSize,l+=1;return {from:a,to:s}}function zo(e,t){if(typeof e=="string"){if(!t.marks[e])throw Error(`There is no mark type named '${e}'. Maybe you forgot to add the extension?`);return t.marks[e]}return e}var zC=(e,t={})=>({tr:o,state:n,dispatch:r})=>{let i=zo(e,n.schema),{doc:a,selection:l}=o,{$from:s,from:u,to:c}=l;if(r){let p=kl(s,i,t);if(p&&p.from<=u&&p.to>=c){let m=TextSelection.create(a,p.from,p.to);o.setSelection(m);}}return true},NC=e=>t=>{let o=typeof e=="function"?e(t):e;for(let n=0;n<o.length;n+=1)if(o[n](t))return true;return false};function pm(e){return e instanceof TextSelection}function an(e=0,t=0,o=0){return Math.min(Math.max(e,t),o)}function VC(e,t=null){if(!t)return null;let o=Selection.atStart(e),n=Selection.atEnd(e);if(t==="start"||t===true)return o;if(t==="end")return n;let r=o.from,i=n.to;return t==="all"?TextSelection.create(e,an(0,r,i),an(e.content.size,r,i)):TextSelection.create(e,an(t,r,i),an(t,r,i))}function Tl(){return ["iPad Simulator","iPhone Simulator","iPod Simulator","iPad","iPhone","iPod"].includes(navigator.platform)||navigator.userAgent.includes("Mac")&&"ontouchend"in document}var FC=(e=null,t={})=>({editor:o,view:n,tr:r,dispatch:i})=>{t={scrollIntoView:true,...t};let a=()=>{Tl()&&n.dom.focus(),requestAnimationFrame(()=>{o.isDestroyed||(n.focus(),t?.scrollIntoView&&o.commands.scrollIntoView());});};if(n.hasFocus()&&e===null||e===false)return true;if(i&&e===null&&!pm(o.state.selection))return a(),true;let l=VC(r.doc,e)||o.state.selection,s=o.state.selection.eq(l);return i&&(s||r.setSelection(l),s&&r.storedMarks&&r.setStoredMarks(r.storedMarks),a()),true},_C=(e,t)=>o=>e.every((n,r)=>t(n,{...o,index:r})),$C=(e,t)=>({tr:o,commands:n})=>n.insertContentAt({from:o.selection.from,to:o.selection.to},e,t),dm=e=>{let t=e.childNodes;for(let o=t.length-1;o>=0;o-=1){let n=t[o];n.nodeType===3&&n.nodeValue&&/^(\n\s\s|\n)$/.test(n.nodeValue)?e.removeChild(n):n.nodeType===1&&dm(n);}return e};function Sa(e){let t=`<body>${e}</body>`,o=new window.DOMParser().parseFromString(t,"text/html").body;return dm(o)}function Ea(e,t,o){o={slice:true,parseOptions:{},...o};let n=typeof e=="object"&&e!==null,r=typeof e=="string";if(n)try{if(Array.isArray(e)&&e.length>0)return Fragment$2.fromArray(e.map(l=>t.nodeFromJSON(l)));let a=t.nodeFromJSON(e);return o.errorOnInvalidContent&&a.check(),a}catch(i){if(o.errorOnInvalidContent)throw new Error("[tiptap error]: Invalid JSON content",{cause:i});return console.warn("[tiptap warn]: Invalid content.","Passed value:",e,"Error:",i),Ea("",t,o)}if(r){if(o.errorOnInvalidContent){let a=false,l="",s=new Schema({topNode:t.spec.topNode,marks:t.spec.marks,nodes:t.spec.nodes.append({__tiptap__private__unknown__catch__all__node:{content:"inline*",group:"block",parseDOM:[{tag:"*",getAttrs:u=>(a=true,l=typeof u=="string"?u:u.outerHTML,null)}]}})});if(o.slice?DOMParser.fromSchema(s).parseSlice(Sa(e),o.parseOptions):DOMParser.fromSchema(s).parse(Sa(e),o.parseOptions),o.errorOnInvalidContent&&a)throw new Error("[tiptap error]: Invalid HTML content",{cause:new Error(`Invalid element found: ${l}`)})}let i=DOMParser.fromSchema(t);return o.slice?i.parseSlice(Sa(e),o.parseOptions).content:i.parse(Sa(e),o.parseOptions)}return Ea("",t,o)}function GC(e,t,o){let n=e.steps.length-1;if(n<t)return;let r=e.steps[n];if(!(r instanceof ReplaceStep||r instanceof ReplaceAroundStep))return;let i=e.mapping.maps[n],a=0;i.forEach((l,s,u,c)=>{a===0&&(a=c);}),e.setSelection(Selection.near(e.doc.resolve(a),o));}var UC=e=>!("type"in e),HC=(e,t,o)=>({tr:n,dispatch:r,editor:i})=>{var a;if(r){o={parseOptions:{},updateSelection:true,applyInputRules:false,applyPasteRules:false,...o};let l;try{l=Ea(t,i.schema,{parseOptions:{preserveWhitespace:"full",...o.parseOptions},errorOnInvalidContent:(a=o.errorOnInvalidContent)!==null&&a!==void 0?a:i.options.enableContentCheck});}catch(g){return i.emit("contentError",{editor:i,error:g,disableCollaboration:()=>{console.error("[tiptap error]: Unable to disable collaboration at this point in time");}}),false}let{from:s,to:u}=typeof e=="number"?{from:e,to:e}:{from:e.from,to:e.to},c=true,p=true;if((UC(l)?l:[l]).forEach(g=>{g.check(),c=c?g.isText&&g.marks.length===0:false,p=p?g.isBlock:false;}),s===u&&p){let{parent:g}=n.doc.resolve(s);g.isTextblock&&!g.type.spec.code&&!g.childCount&&(s-=1,u+=1);}let f;c?(Array.isArray(t)?f=t.map(g=>g.text||"").join(""):typeof t=="object"&&t&&t.text?f=t.text:f=t,n.insertText(f,s,u)):(f=l,n.replaceWith(s,u,f)),o.updateSelection&&GC(n,n.steps.length-1,-1),o.applyInputRules&&n.setMeta("applyInputRules",{from:s,text:f}),o.applyPasteRules&&n.setMeta("applyPasteRules",{from:s,text:f});}return true},jC=()=>({state:e,dispatch:t})=>joinUp(e,t),WC=()=>({state:e,dispatch:t})=>joinDown(e,t),KC=()=>({state:e,dispatch:t})=>joinBackward(e,t),qC=()=>({state:e,dispatch:t})=>joinForward(e,t),YC=()=>({state:e,dispatch:t,tr:o})=>{try{let n=joinPoint(e.doc,e.selection.$from.pos,-1);return n==null?!1:(o.join(n,2),t&&t(o),!0)}catch{return false}},XC=()=>({state:e,dispatch:t,tr:o})=>{try{let n=joinPoint(e.doc,e.selection.$from.pos,1);return n==null?!1:(o.join(n,2),t&&t(o),!0)}catch{return false}},JC=()=>({state:e,dispatch:t})=>joinTextblockBackward(e,t),QC=()=>({state:e,dispatch:t})=>joinTextblockForward(e,t);function mm(){return typeof navigator<"u"?/Mac/.test(navigator.platform):false}function ZC(e){let t=e.split(/-(?!$)/),o=t[t.length-1];o==="Space"&&(o=" ");let n,r,i,a;for(let l=0;l<t.length-1;l+=1){let s=t[l];if(/^(cmd|meta|m)$/i.test(s))a=true;else if(/^a(lt)?$/i.test(s))n=true;else if(/^(c|ctrl|control)$/i.test(s))r=true;else if(/^s(hift)?$/i.test(s))i=true;else if(/^mod$/i.test(s))Tl()||mm()?a=true:r=true;else throw new Error(`Unrecognized modifier name: ${s}`)}return n&&(o=`Alt-${o}`),r&&(o=`Ctrl-${o}`),a&&(o=`Meta-${o}`),i&&(o=`Shift-${o}`),o}var ek=e=>({editor:t,view:o,tr:n,dispatch:r})=>{let i=ZC(e).split(/-(?!$)/),a=i.find(u=>!["Alt","Ctrl","Meta","Shift"].includes(u)),l=new KeyboardEvent("keydown",{key:a==="Space"?" ":a,altKey:i.includes("Alt"),ctrlKey:i.includes("Ctrl"),metaKey:i.includes("Meta"),shiftKey:i.includes("Shift"),bubbles:true,cancelable:true}),s=t.captureTransaction(()=>{o.someProp("handleKeyDown",u=>u(o,l));});return s?.steps.forEach(u=>{let c=u.map(n.mapping);c&&r&&n.maybeStep(c);}),true};function wl(e,t,o={}){let{from:n,to:r,empty:i}=e.selection,a=t?rt(t,e.schema):null,l=[];e.doc.nodesBetween(n,r,(p,m)=>{if(p.isText)return;let f=Math.max(n,m),g=Math.min(r,m+p.nodeSize);l.push({node:p,from:f,to:g});});let s=r-n,u=l.filter(p=>a?a.name===p.node.type.name:true).filter(p=>wa(p.node.attrs,o,{strict:false}));return i?!!u.length:u.reduce((p,m)=>p+m.to-m.from,0)>=s}var tk=(e,t={})=>({state:o,dispatch:n})=>{let r=rt(e,o.schema);return wl(o,r,t)?lift(o,n):false},ok=()=>({state:e,dispatch:t})=>liftEmptyBlock(e,t),nk=e=>({state:t,dispatch:o})=>{let n=rt(e,t.schema);return liftListItem(n)(t,o)},rk=()=>({state:e,dispatch:t})=>newlineInCode(e,t);function fm(e,t){return t.nodes[e]?"node":t.marks[e]?"mark":null}function nm(e,t){let o=typeof t=="string"?[t]:t;return Object.keys(e).reduce((n,r)=>(o.includes(r)||(n[r]=e[r]),n),{})}var ik=(e,t)=>({tr:o,state:n,dispatch:r})=>{let i=null,a=null,l=fm(typeof e=="string"?e:e.name,n.schema);return l?(l==="node"&&(i=rt(e,n.schema)),l==="mark"&&(a=zo(e,n.schema)),r&&o.selection.ranges.forEach(s=>{n.doc.nodesBetween(s.$from.pos,s.$to.pos,(u,c)=>{i&&i===u.type&&o.setNodeMarkup(c,void 0,nm(u.attrs,t)),a&&u.marks.length&&u.marks.forEach(p=>{a===p.type&&o.addMark(c,c+u.nodeSize,a.create(nm(p.attrs,t)));});});}),true):false},ak=()=>({tr:e,dispatch:t})=>(t&&e.scrollIntoView(),true),sk=()=>({tr:e,commands:t})=>t.setTextSelection({from:0,to:e.doc.content.size}),lk=()=>({state:e,dispatch:t})=>selectNodeBackward(e,t),ck=()=>({state:e,dispatch:t})=>selectNodeForward(e,t),uk=()=>({state:e,dispatch:t})=>selectParentNode(e,t),pk=()=>({state:e,dispatch:t})=>selectTextblockEnd(e,t),dk=()=>({state:e,dispatch:t})=>selectTextblockStart(e,t);function mk(e,t,o={},n={}){return Ea(e,t,{slice:false,parseOptions:o,errorOnInvalidContent:n.errorOnInvalidContent})}var fk=(e,t=false,o={},n={})=>({editor:r,tr:i,dispatch:a,commands:l})=>{var s,u;let{doc:c}=i;if(o.preserveWhitespace!=="full"){let p=mk(e,r.schema,o,{errorOnInvalidContent:(s=n.errorOnInvalidContent)!==null&&s!==void 0?s:r.options.enableContentCheck});return a&&i.replaceWith(0,c.content.size,p).setMeta("preventUpdate",!t),true}return a&&i.setMeta("preventUpdate",!t),l.insertContentAt({from:0,to:c.content.size},e,{parseOptions:o,errorOnInvalidContent:(u=n.errorOnInvalidContent)!==null&&u!==void 0?u:r.options.enableContentCheck})};function gk(e,t){let o=zo(t,e.schema),{from:n,to:r,empty:i}=e.selection,a=[];i?(e.storedMarks&&a.push(...e.storedMarks),a.push(...e.selection.$head.marks())):e.doc.nodesBetween(n,r,s=>{a.push(...s.marks);});let l=a.find(s=>s.type.name===o.name);return l?{...l.attrs}:{}}function hk(e){for(let t=0;t<e.edgeCount;t+=1){let{type:o}=e.edge(t);if(o.isTextblock&&!o.hasRequiredAttrs())return o}return null}function bk(e,t){for(let o=e.depth;o>0;o-=1){let n=e.node(o);if(t(n))return {pos:o>0?e.before(o):0,start:e.start(o),depth:o,node:n}}}function El(e){return t=>bk(t.$from,e)}function gm(e,t,o){let n=[];return e===t?o.resolve(e).marks().forEach(r=>{let i=o.resolve(e),a=kl(i,r.type);a&&n.push({mark:r,...a});}):o.nodesBetween(e,t,(r,i)=>{!r||r?.nodeSize===void 0||n.push(...r.marks.map(a=>({from:i,to:i+r.nodeSize,mark:a})));}),n}function ka(e,t,o){return Object.fromEntries(Object.entries(o).filter(([n])=>{let r=e.find(i=>i.type===t&&i.name===n);return r?r.attribute.keepOnSplit:false}))}function yk(e,t,o={}){let{empty:n,ranges:r}=e.selection,i=t?zo(t,e.schema):null;if(n)return !!(e.storedMarks||e.selection.$from.marks()).filter(p=>i?i.name===p.type.name:true).find(p=>wa(p.attrs,o,{strict:false}));let a=0,l=[];if(r.forEach(({$from:p,$to:m})=>{let f=p.pos,g=m.pos;e.doc.nodesBetween(f,g,(S,v)=>{if(!S.isText&&!S.marks.length)return;let h=Math.max(f,v),b=Math.min(g,v+S.nodeSize),C=b-h;a+=C,l.push(...S.marks.map(d=>({mark:d,from:h,to:b})));});}),a===0)return false;let s=l.filter(p=>i?i.name===p.mark.type.name:true).filter(p=>wa(p.mark.attrs,o,{strict:false})).reduce((p,m)=>p+m.to-m.from,0),u=l.filter(p=>i?p.mark.type!==i&&p.mark.type.excludes(i):true).reduce((p,m)=>p+m.to-m.from,0);return (s>0?s+u:s)>=a}function rm(e,t){let{nodeExtensions:o}=bC(t),n=o.find(a=>a.name===e);if(!n)return false;let r={name:n.name,options:n.options,storage:n.storage},i=nt(dt(n,"group",r));return typeof i!="string"?false:i.split(" ").includes("list")}function hm(e,{checkChildren:t=true,ignoreWhitespace:o=false}={}){var n;if(o){if(e.type.name==="hardBreak")return true;if(e.isText)return /^\s*$/m.test((n=e.text)!==null&&n!==void 0?n:"")}if(e.isText)return !e.text;if(e.isAtom||e.isLeaf)return false;if(e.content.childCount===0)return true;if(t){let r=true;return e.content.forEach(i=>{r!==false&&(hm(i,{ignoreWhitespace:o,checkChildren:t})||(r=false));}),r}return false}function vk(e,t,o){var n;let{selection:r}=t,i=null;if(pm(r)&&(i=r.$cursor),i){let l=(n=e.storedMarks)!==null&&n!==void 0?n:i.marks();return !!o.isInSet(l)||!l.some(s=>s.type.excludes(o))}let{ranges:a}=r;return a.some(({$from:l,$to:s})=>{let u=l.depth===0?e.doc.inlineContent&&e.doc.type.allowsMarkType(o):false;return e.doc.nodesBetween(l.pos,s.pos,(c,p,m)=>{if(u)return false;if(c.isInline){let f=!m||m.type.allowsMarkType(o),g=!!o.isInSet(c.marks)||!c.marks.some(S=>S.type.excludes(o));u=f&&g;}return !u}),u})}var Sk=(e,t={})=>({tr:o,state:n,dispatch:r})=>{let{selection:i}=o,{empty:a,ranges:l}=i,s=zo(e,n.schema);if(r)if(a){let u=gk(n,s);o.addStoredMark(s.create({...u,...t}));}else l.forEach(u=>{let c=u.$from.pos,p=u.$to.pos;n.doc.nodesBetween(c,p,(m,f)=>{let g=Math.max(f,c),S=Math.min(f+m.nodeSize,p);m.marks.find(h=>h.type===s)?m.marks.forEach(h=>{s===h.type&&o.addMark(g,S,s.create({...h.attrs,...t}));}):o.addMark(g,S,s.create(t));});});return vk(n,o,s)},xk=(e,t)=>({tr:o})=>(o.setMeta(e,t),true),Ck=(e,t={})=>({state:o,dispatch:n,chain:r})=>{let i=rt(e,o.schema);return i.isTextblock?r().command(({commands:a})=>setBlockType(i,t)(o)?true:a.clearNodes()).command(({state:a})=>setBlockType(i,t)(a,n)).run():(console.warn('[tiptap warn]: Currently "setNode()" only supports text block nodes.'),false)},kk=e=>({tr:t,dispatch:o})=>{if(o){let{doc:n}=t,r=an(e,0,n.content.size),i=NodeSelection.create(n,r);t.setSelection(i);}return true},Tk=e=>({tr:t,dispatch:o})=>{if(o){let{doc:n}=t,{from:r,to:i}=typeof e=="number"?{from:e,to:e}:e,a=TextSelection.atStart(n).from,l=TextSelection.atEnd(n).to,s=an(r,a,l),u=an(i,a,l),c=TextSelection.create(n,s,u);t.setSelection(c);}return true},wk=e=>({state:t,dispatch:o})=>{let n=rt(e,t.schema);return sinkListItem(n)(t,o)};function im(e,t){let o=e.storedMarks||e.selection.$to.parentOffset&&e.selection.$from.marks();if(o){let n=o.filter(r=>t?.includes(r.type.name));e.tr.ensureMarks(n);}}var Ek=({keepMarks:e=true}={})=>({tr:t,state:o,dispatch:n,editor:r})=>{let{selection:i,doc:a}=t,{$from:l,$to:s}=i,u=r.extensionManager.attributes,c=ka(u,l.node().type.name,l.node().attrs);if(i instanceof NodeSelection&&i.node.isBlock)return !l.parentOffset||!canSplit(a,l.pos)?false:(n&&(e&&im(o,r.extensionManager.splittableMarks),t.split(l.pos).scrollIntoView()),true);if(!l.parent.isBlock)return false;let p=s.parentOffset===s.parent.content.size,m=l.depth===0?void 0:hk(l.node(-1).contentMatchAt(l.indexAfter(-1))),f=p&&m?[{type:m,attrs:c}]:void 0,g=canSplit(t.doc,t.mapping.map(l.pos),1,f);if(!f&&!g&&canSplit(t.doc,t.mapping.map(l.pos),1,m?[{type:m}]:void 0)&&(g=true,f=m?[{type:m,attrs:c}]:void 0),n){if(g&&(i instanceof TextSelection&&t.deleteSelection(),t.split(t.mapping.map(l.pos),1,f),m&&!p&&!l.parentOffset&&l.parent.type!==m)){let S=t.mapping.map(l.before()),v=t.doc.resolve(S);l.node(-1).canReplaceWith(v.index(),v.index()+1,m)&&t.setNodeMarkup(t.mapping.map(l.before()),m);}e&&im(o,r.extensionManager.splittableMarks),t.scrollIntoView();}return g},Ik=(e,t={})=>({tr:o,state:n,dispatch:r,editor:i})=>{var a;let l=rt(e,n.schema),{$from:s,$to:u}=n.selection,c=n.selection.node;if(c&&c.isBlock||s.depth<2||!s.sameParent(u))return false;let p=s.node(-1);if(p.type!==l)return false;let m=i.extensionManager.attributes;if(s.parent.content.size===0&&s.node(-1).childCount===s.indexAfter(-1)){if(s.depth===2||s.node(-3).type!==l||s.index(-2)!==s.node(-2).childCount-1)return false;if(r){let h=Fragment$2.empty,b=s.index(-1)?1:s.index(-2)?2:3;for(let R=s.depth-b;R>=s.depth-3;R-=1)h=Fragment$2.from(s.node(R).copy(h));let C=s.indexAfter(-1)<s.node(-2).childCount?1:s.indexAfter(-2)<s.node(-3).childCount?2:3,d={...ka(m,s.node().type.name,s.node().attrs),...t},y=((a=l.contentMatch.defaultType)===null||a===void 0?void 0:a.createAndFill(d))||void 0;h=h.append(Fragment$2.from(l.createAndFill(null,y)||void 0));let x=s.before(s.depth-(b-1));o.replace(x,s.after(-C),new Slice(h,4-b,0));let k=-1;o.doc.nodesBetween(x,o.doc.content.size,(R,B)=>{if(k>-1)return false;R.isTextblock&&R.content.size===0&&(k=B+1);}),k>-1&&o.setSelection(TextSelection.near(o.doc.resolve(k))),o.scrollIntoView();}return true}let f=u.pos===s.end()?p.contentMatchAt(0).defaultType:null,g={...ka(m,p.type.name,p.attrs),...t},S={...ka(m,s.node().type.name,s.node().attrs),...t};o.delete(s.pos,u.pos);let v=f?[{type:l,attrs:g},{type:f,attrs:S}]:[{type:l,attrs:g}];if(!canSplit(o.doc,s.pos,2))return false;if(r){let{selection:h,storedMarks:b}=n,{splittableMarks:C}=i.extensionManager,d=b||h.$to.parentOffset&&h.$from.marks();if(o.split(s.pos,2,v).scrollIntoView(),!d||!r)return true;let y=d.filter(x=>C.includes(x.type.name));o.ensureMarks(y);}return true},yl=(e,t)=>{let o=El(a=>a.type===t)(e.selection);if(!o)return true;let n=e.doc.resolve(Math.max(0,o.pos-1)).before(o.depth);if(n===void 0)return true;let r=e.doc.nodeAt(n);return o.node.type===r?.type&&canJoin(e.doc,o.pos)&&e.join(o.pos),true},vl=(e,t)=>{let o=El(a=>a.type===t)(e.selection);if(!o)return true;let n=e.doc.resolve(o.start).after(o.depth);if(n===void 0)return true;let r=e.doc.nodeAt(n);return o.node.type===r?.type&&canJoin(e.doc,n)&&e.join(n),true},Ak=(e,t,o,n={})=>({editor:r,tr:i,state:a,dispatch:l,chain:s,commands:u,can:c})=>{let{extensions:p,splittableMarks:m}=r.extensionManager,f=rt(e,a.schema),g=rt(t,a.schema),{selection:S,storedMarks:v}=a,{$from:h,$to:b}=S,C=h.blockRange(b),d=v||S.$to.parentOffset&&S.$from.marks();if(!C)return false;let y=El(x=>rm(x.type.name,p))(S);if(C.depth>=1&&y&&C.depth-y.depth<=1){if(y.node.type===f)return u.liftListItem(g);if(rm(y.node.type.name,p)&&f.validContent(y.node.content)&&l)return s().command(()=>(i.setNodeMarkup(y.pos,f),true)).command(()=>yl(i,f)).command(()=>vl(i,f)).run()}return !o||!d||!l?s().command(()=>c().wrapInList(f,n)?true:u.clearNodes()).wrapInList(f,n).command(()=>yl(i,f)).command(()=>vl(i,f)).run():s().command(()=>{let x=c().wrapInList(f,n),k=d.filter(R=>m.includes(R.type.name));return i.ensureMarks(k),x?true:u.clearNodes()}).wrapInList(f,n).command(()=>yl(i,f)).command(()=>vl(i,f)).run()},Pk=(e,t={},o={})=>({state:n,commands:r})=>{let{extendEmptyMarkRange:i=false}=o,a=zo(e,n.schema);return yk(n,a,t)?r.unsetMark(a,{extendEmptyMarkRange:i}):r.setMark(a,t)},Rk=(e,t,o={})=>({state:n,commands:r})=>{let i=rt(e,n.schema),a=rt(t,n.schema),l=wl(n,i,o),s;return n.selection.$anchor.sameParent(n.selection.$head)&&(s=n.selection.$anchor.parent.attrs),l?r.setNode(a,s):r.setNode(i,{...s,...o})},Ok=(e,t={})=>({state:o,commands:n})=>{let r=rt(e,o.schema);return wl(o,r,t)?n.lift(r):n.wrapIn(r,t)},Mk=()=>({state:e,dispatch:t})=>{let o=e.plugins;for(let n=0;n<o.length;n+=1){let r=o[n],i;if(r.spec.isInputRules&&(i=r.getState(e))){if(t){let a=e.tr,l=i.transform;for(let s=l.steps.length-1;s>=0;s-=1)a.step(l.steps[s].invert(l.docs[s]));if(i.text){let s=a.doc.resolve(i.from).marks();a.replaceWith(i.from,i.to,e.schema.text(i.text,s));}else a.delete(i.from,i.to);}return true}}return false},Dk=()=>({tr:e,dispatch:t})=>{let{selection:o}=e,{empty:n,ranges:r}=o;return n||t&&r.forEach(i=>{e.removeMark(i.$from.pos,i.$to.pos);}),true},Lk=(e,t={})=>({tr:o,state:n,dispatch:r})=>{var i;let{extendEmptyMarkRange:a=false}=t,{selection:l}=o,s=zo(e,n.schema),{$from:u,empty:c,ranges:p}=l;if(!r)return true;if(c&&a){let{from:m,to:f}=l,g=(i=u.marks().find(v=>v.type===s))===null||i===void 0?void 0:i.attrs,S=kl(u,s,g);S&&(m=S.from,f=S.to),o.removeMark(m,f,s);}else p.forEach(m=>{o.removeMark(m.$from.pos,m.$to.pos,s);});return o.removeStoredMark(s),true},Bk=(e,t={})=>({tr:o,state:n,dispatch:r})=>{let i=null,a=null,l=fm(typeof e=="string"?e:e.name,n.schema);return l?(l==="node"&&(i=rt(e,n.schema)),l==="mark"&&(a=zo(e,n.schema)),r&&o.selection.ranges.forEach(s=>{let u=s.$from.pos,c=s.$to.pos;n.doc.nodesBetween(u,c,(p,m)=>{i&&i===p.type&&o.setNodeMarkup(m,void 0,{...p.attrs,...t}),a&&p.marks.length&&p.marks.forEach(f=>{if(a===f.type){let g=Math.max(m,u),S=Math.min(m+p.nodeSize,c);o.addMark(g,S,a.create({...f.attrs,...t}));}});});}),true):false},zk=(e,t={})=>({state:o,dispatch:n})=>{let r=rt(e,o.schema);return wrapIn(r,t)(o,n)},Nk=(e,t={})=>({state:o,dispatch:n})=>{let r=rt(e,o.schema);return wrapInList(r,t)(o,n)},Vk=Object.freeze({__proto__:null,blur:kC,clearContent:TC,clearNodes:wC,command:EC,createParagraphNear:IC,cut:AC,deleteCurrentNode:PC,deleteNode:RC,deleteRange:OC,deleteSelection:MC,enter:DC,exitCode:LC,extendMarkRange:zC,first:NC,focus:FC,forEach:_C,insertContent:$C,insertContentAt:HC,joinBackward:KC,joinDown:WC,joinForward:qC,joinItemBackward:YC,joinItemForward:XC,joinTextblockBackward:JC,joinTextblockForward:QC,joinUp:jC,keyboardShortcut:ek,lift:tk,liftEmptyBlock:ok,liftListItem:nk,newlineInCode:rk,resetAttributes:ik,scrollIntoView:ak,selectAll:sk,selectNodeBackward:lk,selectNodeForward:ck,selectParentNode:uk,selectTextblockEnd:pk,selectTextblockStart:dk,setContent:fk,setMark:Sk,setMeta:xk,setNode:Ck,setNodeSelection:kk,setTextSelection:Tk,sinkListItem:wk,splitBlock:Ek,splitListItem:Ik,toggleList:Ak,toggleMark:Pk,toggleNode:Rk,toggleWrap:Ok,undoInputRule:Mk,unsetAllMarks:Dk,unsetMark:Lk,updateAttributes:Bk,wrapIn:zk,wrapInList:Nk});ao.create({name:"commands",addCommands(){return {...Vk}}});ao.create({name:"editable",addProseMirrorPlugins(){return [new Plugin({key:new PluginKey("editable"),props:{editable:()=>this.editor.options.editable}})]}});ao.create({name:"focusEvents",addProseMirrorPlugins(){let{editor:e}=this;return [new Plugin({key:new PluginKey("focusEvents"),props:{handleDOMEvents:{focus:(t,o)=>{e.isFocused=true;let n=e.state.tr.setMeta("focus",{event:o}).setMeta("addToHistory",false);return t.dispatch(n),false},blur:(t,o)=>{e.isFocused=false;let n=e.state.tr.setMeta("blur",{event:o}).setMeta("addToHistory",false);return t.dispatch(n),false}}}})]}});ao.create({name:"keymap",addKeyboardShortcuts(){let e=()=>this.editor.commands.first(({commands:a})=>[()=>a.undoInputRule(),()=>a.command(({tr:l})=>{let{selection:s,doc:u}=l,{empty:c,$anchor:p}=s,{pos:m,parent:f}=p,g=p.parent.isTextblock&&m>0?l.doc.resolve(m-1):p,S=g.parent.type.spec.isolating,v=p.pos-p.parentOffset,h=S&&g.parent.childCount===1?v===p.pos:Selection.atStart(u).from===m;return !c||!f.type.isTextblock||f.textContent.length||!h||h&&p.parent.type.name==="paragraph"?false:a.clearNodes()}),()=>a.deleteSelection(),()=>a.joinBackward(),()=>a.selectNodeBackward()]),t=()=>this.editor.commands.first(({commands:a})=>[()=>a.deleteSelection(),()=>a.deleteCurrentNode(),()=>a.joinForward(),()=>a.selectNodeForward()]),n={Enter:()=>this.editor.commands.first(({commands:a})=>[()=>a.newlineInCode(),()=>a.createParagraphNear(),()=>a.liftEmptyBlock(),()=>a.splitBlock()]),"Mod-Enter":()=>this.editor.commands.exitCode(),Backspace:e,"Mod-Backspace":e,"Shift-Backspace":e,Delete:t,"Mod-Delete":t,"Mod-a":()=>this.editor.commands.selectAll()},r={...n},i={...n,"Ctrl-h":e,"Alt-Backspace":e,"Ctrl-d":t,"Ctrl-Alt-Backspace":t,"Alt-Delete":t,"Alt-d":t,"Ctrl-a":()=>this.editor.commands.selectTextblockStart(),"Ctrl-e":()=>this.editor.commands.selectTextblockEnd()};return Tl()||mm()?i:r},addProseMirrorPlugins(){return [new Plugin({key:new PluginKey("clearDocument"),appendTransaction:(e,t,o)=>{let n=e.some(S=>S.docChanged)&&!t.doc.eq(o.doc),r=e.some(S=>S.getMeta("preventClearDocument"));if(!n||r)return;let{empty:i,from:a,to:l}=t.selection,s=Selection.atStart(t.doc).from,u=Selection.atEnd(t.doc).to;if(i||!(a===s&&l===u)||!hm(o.doc))return;let m=o.tr,f=cm({state:o,transaction:m}),{commands:g}=new Sl({editor:this.editor,state:f});if(g.clearNodes(),!!m.steps.length)return m}})]}});ao.create({name:"tabindex",addProseMirrorPlugins(){return [new Plugin({key:new PluginKey("tabindex"),props:{attributes:()=>this.editor.isEditable?{tabindex:"0"}:{}}})]}});function Il(e){return new Ta({find:e.find,handler:({state:t,range:o,match:n})=>{let r=nt(e.getAttributes,void 0,n);if(r===false||r===null)return null;let{tr:i}=t,a=n[n.length-1],l=n[0];if(a){let s=l.search(/\S/),u=o.from+l.indexOf(a),c=u+a.length;if(gm(o.from,o.to,t.doc).filter(f=>f.mark.type.excluded.find(S=>S===e.type&&S!==f.mark.type)).filter(f=>f.to>u).length)return null;c<o.to&&i.delete(c,o.to),u>o.from&&i.delete(o.from+s,u);let m=o.from+s+a.length;i.addMark(o.from+s,m,e.type.create(r||{})),i.removeStoredMark(e.type);}}})}function bm(e){return new Ta({find:e.find,handler:({state:t,range:o,match:n})=>{let r=nt(e.getAttributes,void 0,n)||{},{tr:i}=t,a=o.from,l=o.to,s=e.type.create(r);if(n[1]){let u=n[0].lastIndexOf(n[1]),c=a+u;c>l?c=l:l=c+n[1].length;let p=n[0][n[0].length-1];i.insertText(p,a+n[0].length-1),i.replaceWith(c,l,s);}else if(n[0]){let u=e.type.isInline?a:a-1;i.insert(u,e.type.create(r)).delete(i.mapping.map(a),i.mapping.map(l));}i.scrollIntoView();}})}var Ia=class e{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(dt(this,"addOptions",{name:this.name}))),this.storage=nt(dt(this,"addStorage",{name:this.name,options:this.options}))||{};}static create(t={}){return new e(t)}configure(t={}){let o=this.extend({...this.config,addOptions:()=>Pa(this.options,t)});return o.name=this.name,o.parent=this.parent,o}extend(t={}){let o=new e(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(dt(o,"addOptions",{name:o.name})),o.storage=nt(dt(o,"addStorage",{name:o.name,options:o.options})),o}static handleExit({editor:t,mark:o}){let{tr:n}=t.state,r=t.state.selection.$from;if(r.pos===r.end()){let a=r.marks();if(!!!a.find(u=>u?.type.name===o.name))return false;let s=a.find(u=>u?.type.name===o.name);return s&&n.removeStoredMark(s),n.insertText(" ",r.pos),t.view.dispatch(n),true}return false}},Aa=class e{constructor(t={}){this.type="node",this.name="node",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(dt(this,"addOptions",{name:this.name}))),this.storage=nt(dt(this,"addStorage",{name:this.name,options:this.options}))||{};}static create(t={}){return new e(t)}configure(t={}){let o=this.extend({...this.config,addOptions:()=>Pa(this.options,t)});return o.name=this.name,o.parent=this.parent,o}extend(t={}){let o=new e(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(dt(o,"addOptions",{name:o.name})),o.storage=nt(dt(o,"addStorage",{name:o.name,options:o.options})),o}};function Al(e){return new xl({find:e.find,handler:({state:t,range:o,match:n,pasteEvent:r})=>{let i=nt(e.getAttributes,void 0,n,r);if(i===false||i===null)return null;let{tr:a}=t,l=n[n.length-1],s=n[0],u=o.to;if(l){let c=s.search(/\S/),p=o.from+s.indexOf(l),m=p+l.length;if(gm(o.from,o.to,t.doc).filter(g=>g.mark.type.excluded.find(v=>v===e.type&&v!==g.mark.type)).filter(g=>g.to>p).length)return null;m<o.to&&a.delete(m,o.to),p>o.from&&a.delete(o.from+c,p),u=o.from+c+l.length,a.addMark(o.from+c,u,e.type.create(i||{})),a.removeStoredMark(e.type);}}})}var Fk=/(?:^|\s)(\*\*(?!\s+\*\*)((?:[^*]+))\*\*(?!\s+\*\*))$/,_k=/(?:^|\s)(\*\*(?!\s+\*\*)((?:[^*]+))\*\*(?!\s+\*\*))/g,$k=/(?:^|\s)(__(?!\s+__)((?:[^_]+))__(?!\s+__))$/,Gk=/(?:^|\s)(__(?!\s+__)((?:[^_]+))__(?!\s+__))/g,ym=Ia.create({name:"bold",addOptions(){return {HTMLAttributes:{}}},parseHTML(){return [{tag:"strong"},{tag:"b",getAttrs:e=>e.style.fontWeight!=="normal"&&null},{style:"font-weight",getAttrs:e=>/^(bold(er)?|[5-9]\d{2,})$/.test(e)&&null}]},renderHTML({HTMLAttributes:e}){return ["strong",um(this.options.HTMLAttributes,e),0]},addCommands(){return {setBold:()=>({commands:e})=>e.setMark(this.name),toggleBold:()=>({commands:e})=>e.toggleMark(this.name),unsetBold:()=>({commands:e})=>e.unsetMark(this.name)}},addKeyboardShortcuts(){return {"Mod-b":()=>this.editor.commands.toggleBold(),"Mod-B":()=>this.editor.commands.toggleBold()}},addInputRules(){return [Il({find:Fk,type:this.type}),Il({find:$k,type:this.type})]},addPasteRules(){return [Al({find:_k,type:this.type}),Al({find:Gk,type:this.type})]}});var Uk=/(?:^|\s)((?:\{\{)([a-zA-Z0-9]+)(?:\}\}))$/,Hk=Aa.create({name:"variable",group:"inline",content:"text*",marks:"_",atom:false,inline:true,selectable:true,addAttributes(){return {varName:{default:"",parseHTML:e=>e.innerText}}},addInputRules(){return [bm({find:Uk,type:this.type,getAttributes:e=>({varName:e[0]})})]},renderHTML({node:e}){return ["code",{class:"bespoke-var"},e.attrs.varName.trim()]},parseHTML(){return [{tag:'code[class="bespoke-var"]'}]},toDOM(){return ["code",{class:"bespoke-var"},0]}}),vm=Hk;var Sm=ao.create({name:"VariablesStorage",addStorage(){return {suggestions:[]}}});var Ce="top",Be="bottom",Pe="right",Ee="left",Ra="auto",No=[Ce,Be,Pe,Ee],Co="start",sn="end",xm="clippingParents",Oa="viewport",Jn="popper",Cm="reference",Pl=No.reduce(function(e,t){return e.concat([t+"-"+Co,t+"-"+sn])},[]),Ma=[].concat(No,[Ra]).reduce(function(e,t){return e.concat([t,t+"-"+Co,t+"-"+sn])},[]),jk="beforeRead",Wk="read",Kk="afterRead",qk="beforeMain",Yk="main",Xk="afterMain",Jk="beforeWrite",Qk="write",Zk="afterWrite",km=[jk,Wk,Kk,qk,Yk,Xk,Jk,Qk,Zk];function $e(e){return e?(e.nodeName||"").toLowerCase():null}function ve(e){if(e==null)return window;if(e.toString()!=="[object Window]"){var t=e.ownerDocument;return t&&t.defaultView||window}return e}function Vt(e){var t=ve(e).Element;return e instanceof t||e instanceof Element}function ze(e){var t=ve(e).HTMLElement;return e instanceof t||e instanceof HTMLElement}function Qn(e){if(typeof ShadowRoot>"u")return false;var t=ve(e).ShadowRoot;return e instanceof t||e instanceof ShadowRoot}function eT(e){var t=e.state;Object.keys(t.elements).forEach(function(o){var n=t.styles[o]||{},r=t.attributes[o]||{},i=t.elements[o];!ze(i)||!$e(i)||(Object.assign(i.style,n),Object.keys(r).forEach(function(a){var l=r[a];l===false?i.removeAttribute(a):i.setAttribute(a,l===true?"":l);}));});}function tT(e){var t=e.state,o={popper:{position:t.options.strategy,left:"0",top:"0",margin:"0"},arrow:{position:"absolute"},reference:{}};return Object.assign(t.elements.popper.style,o.popper),t.styles=o,t.elements.arrow&&Object.assign(t.elements.arrow.style,o.arrow),function(){Object.keys(t.elements).forEach(function(n){var r=t.elements[n],i=t.attributes[n]||{},a=Object.keys(t.styles.hasOwnProperty(n)?t.styles[n]:o[n]),l=a.reduce(function(s,u){return s[u]="",s},{});!ze(r)||!$e(r)||(Object.assign(r.style,l),Object.keys(i).forEach(function(s){r.removeAttribute(s);}));});}}var Kr={name:"applyStyles",enabled:true,phase:"write",fn:eT,effect:tT,requires:["computeStyles"]};function Ge(e){return e.split("-")[0]}var Jt=Math.max,ln=Math.min,ko=Math.round;function Zn(){var e=navigator.userAgentData;return e!=null&&e.brands&&Array.isArray(e.brands)?e.brands.map(function(t){return t.brand+"/"+t.version}).join(" "):navigator.userAgent}function qr(){return !/^((?!chrome|android).)*safari/i.test(Zn())}function Ft(e,t,o){t===void 0&&(t=false),o===void 0&&(o=false);var n=e.getBoundingClientRect(),r=1,i=1;t&&ze(e)&&(r=e.offsetWidth>0&&ko(n.width)/e.offsetWidth||1,i=e.offsetHeight>0&&ko(n.height)/e.offsetHeight||1);var a=Vt(e)?ve(e):window,l=a.visualViewport,s=!qr()&&o,u=(n.left+(s&&l?l.offsetLeft:0))/r,c=(n.top+(s&&l?l.offsetTop:0))/i,p=n.width/r,m=n.height/i;return {width:p,height:m,top:c,right:u+p,bottom:c+m,left:u,x:u,y:c}}function cn(e){var t=Ft(e),o=e.offsetWidth,n=e.offsetHeight;return Math.abs(t.width-o)<=1&&(o=t.width),Math.abs(t.height-n)<=1&&(n=t.height),{x:e.offsetLeft,y:e.offsetTop,width:o,height:n}}function Yr(e,t){var o=t.getRootNode&&t.getRootNode();if(e.contains(t))return true;if(o&&Qn(o)){var n=t;do{if(n&&e.isSameNode(n))return true;n=n.parentNode||n.host;}while(n)}return false}function mt(e){return ve(e).getComputedStyle(e)}function Rl(e){return ["table","td","th"].indexOf($e(e))>=0}function We(e){return ((Vt(e)?e.ownerDocument:e.document)||window.document).documentElement}function To(e){return $e(e)==="html"?e:e.assignedSlot||e.parentNode||(Qn(e)?e.host:null)||We(e)}function Tm(e){return !ze(e)||mt(e).position==="fixed"?null:e.offsetParent}function oT(e){var t=/firefox/i.test(Zn()),o=/Trident/i.test(Zn());if(o&&ze(e)){var n=mt(e);if(n.position==="fixed")return null}var r=To(e);for(Qn(r)&&(r=r.host);ze(r)&&["html","body"].indexOf($e(r))<0;){var i=mt(r);if(i.transform!=="none"||i.perspective!=="none"||i.contain==="paint"||["transform","perspective"].indexOf(i.willChange)!==-1||t&&i.willChange==="filter"||t&&i.filter&&i.filter!=="none")return r;r=r.parentNode;}return null}function Qt(e){for(var t=ve(e),o=Tm(e);o&&Rl(o)&&mt(o).position==="static";)o=Tm(o);return o&&($e(o)==="html"||$e(o)==="body"&&mt(o).position==="static")?t:o||oT(e)||t}function un(e){return ["top","bottom"].indexOf(e)>=0?"x":"y"}function pn(e,t,o){return Jt(e,ln(t,o))}function wm(e,t,o){var n=pn(e,t,o);return n>o?o:n}function Xr(){return {top:0,right:0,bottom:0,left:0}}function Jr(e){return Object.assign({},Xr(),e)}function Qr(e,t){return t.reduce(function(o,n){return o[n]=e,o},{})}var nT=function(t,o){return t=typeof t=="function"?t(Object.assign({},o.rects,{placement:o.placement})):t,Jr(typeof t!="number"?t:Qr(t,No))};function rT(e){var t,o=e.state,n=e.name,r=e.options,i=o.elements.arrow,a=o.modifiersData.popperOffsets,l=Ge(o.placement),s=un(l),u=[Ee,Pe].indexOf(l)>=0,c=u?"height":"width";if(!(!i||!a)){var p=nT(r.padding,o),m=cn(i),f=s==="y"?Ce:Ee,g=s==="y"?Be:Pe,S=o.rects.reference[c]+o.rects.reference[s]-a[s]-o.rects.popper[c],v=a[s]-o.rects.reference[s],h=Qt(i),b=h?s==="y"?h.clientHeight||0:h.clientWidth||0:0,C=S/2-v/2,d=p[f],y=b-m[c]-p[g],x=b/2-m[c]/2+C,k=pn(d,x,y),R=s;o.modifiersData[n]=(t={},t[R]=k,t.centerOffset=k-x,t);}}function iT(e){var t=e.state,o=e.options,n=o.element,r=n===void 0?"[data-popper-arrow]":n;r!=null&&(typeof r=="string"&&(r=t.elements.popper.querySelector(r),!r)||Yr(t.elements.popper,r)&&(t.elements.arrow=r));}var Em={name:"arrow",enabled:true,phase:"main",fn:rT,effect:iT,requires:["popperOffsets"],requiresIfExists:["preventOverflow"]};function _t(e){return e.split("-")[1]}var aT={top:"auto",right:"auto",bottom:"auto",left:"auto"};function sT(e,t){var o=e.x,n=e.y,r=t.devicePixelRatio||1;return {x:ko(o*r)/r||0,y:ko(n*r)/r||0}}function Im(e){var t,o=e.popper,n=e.popperRect,r=e.placement,i=e.variation,a=e.offsets,l=e.position,s=e.gpuAcceleration,u=e.adaptive,c=e.roundOffsets,p=e.isFixed,m=a.x,f=m===void 0?0:m,g=a.y,S=g===void 0?0:g,v=typeof c=="function"?c({x:f,y:S}):{x:f,y:S};f=v.x,S=v.y;var h=a.hasOwnProperty("x"),b=a.hasOwnProperty("y"),C=Ee,d=Ce,y=window;if(u){var x=Qt(o),k="clientHeight",R="clientWidth";if(x===ve(o)&&(x=We(o),mt(x).position!=="static"&&l==="absolute"&&(k="scrollHeight",R="scrollWidth")),x=x,r===Ce||(r===Ee||r===Pe)&&i===sn){d=Be;var B=p&&x===y&&y.visualViewport?y.visualViewport.height:x[k];S-=B-n.height,S*=s?1:-1;}if(r===Ee||(r===Ce||r===Be)&&i===sn){C=Pe;var N=p&&x===y&&y.visualViewport?y.visualViewport.width:x[R];f-=N-n.width,f*=s?1:-1;}}var $=Object.assign({position:l},u&&aT),K=c===true?sT({x:f,y:S},ve(o)):{x:f,y:S};if(f=K.x,S=K.y,s){var T;return Object.assign({},$,(T={},T[d]=b?"0":"",T[C]=h?"0":"",T.transform=(y.devicePixelRatio||1)<=1?"translate("+f+"px, "+S+"px)":"translate3d("+f+"px, "+S+"px, 0)",T))}return Object.assign({},$,(t={},t[d]=b?S+"px":"",t[C]=h?f+"px":"",t.transform="",t))}function lT(e){var t=e.state,o=e.options,n=o.gpuAcceleration,r=n===void 0?true:n,i=o.adaptive,a=i===void 0?true:i,l=o.roundOffsets,s=l===void 0?true:l,u={placement:Ge(t.placement),variation:_t(t.placement),popper:t.elements.popper,popperRect:t.rects.popper,gpuAcceleration:r,isFixed:t.options.strategy==="fixed"};t.modifiersData.popperOffsets!=null&&(t.styles.popper=Object.assign({},t.styles.popper,Im(Object.assign({},u,{offsets:t.modifiersData.popperOffsets,position:t.options.strategy,adaptive:a,roundOffsets:s})))),t.modifiersData.arrow!=null&&(t.styles.arrow=Object.assign({},t.styles.arrow,Im(Object.assign({},u,{offsets:t.modifiersData.arrow,position:"absolute",adaptive:false,roundOffsets:s})))),t.attributes.popper=Object.assign({},t.attributes.popper,{"data-popper-placement":t.placement});}var Am={name:"computeStyles",enabled:true,phase:"beforeWrite",fn:lT,data:{}};var Da={passive:true};function cT(e){var t=e.state,o=e.instance,n=e.options,r=n.scroll,i=r===void 0?true:r,a=n.resize,l=a===void 0?true:a,s=ve(t.elements.popper),u=[].concat(t.scrollParents.reference,t.scrollParents.popper);return i&&u.forEach(function(c){c.addEventListener("scroll",o.update,Da);}),l&&s.addEventListener("resize",o.update,Da),function(){i&&u.forEach(function(c){c.removeEventListener("scroll",o.update,Da);}),l&&s.removeEventListener("resize",o.update,Da);}}var Pm={name:"eventListeners",enabled:true,phase:"write",fn:function(){},effect:cT,data:{}};var uT={left:"right",right:"left",bottom:"top",top:"bottom"};function er(e){return e.replace(/left|right|bottom|top/g,function(t){return uT[t]})}var pT={start:"end",end:"start"};function La(e){return e.replace(/start|end/g,function(t){return pT[t]})}function dn(e){var t=ve(e),o=t.pageXOffset,n=t.pageYOffset;return {scrollLeft:o,scrollTop:n}}function mn(e){return Ft(We(e)).left+dn(e).scrollLeft}function Ol(e,t){var o=ve(e),n=We(e),r=o.visualViewport,i=n.clientWidth,a=n.clientHeight,l=0,s=0;if(r){i=r.width,a=r.height;var u=qr();(u||!u&&t==="fixed")&&(l=r.offsetLeft,s=r.offsetTop);}return {width:i,height:a,x:l+mn(e),y:s}}function Ml(e){var t,o=We(e),n=dn(e),r=(t=e.ownerDocument)==null?void 0:t.body,i=Jt(o.scrollWidth,o.clientWidth,r?r.scrollWidth:0,r?r.clientWidth:0),a=Jt(o.scrollHeight,o.clientHeight,r?r.scrollHeight:0,r?r.clientHeight:0),l=-n.scrollLeft+mn(e),s=-n.scrollTop;return mt(r||o).direction==="rtl"&&(l+=Jt(o.clientWidth,r?r.clientWidth:0)-i),{width:i,height:a,x:l,y:s}}function fn(e){var t=mt(e),o=t.overflow,n=t.overflowX,r=t.overflowY;return /auto|scroll|overlay|hidden/.test(o+r+n)}function Ba(e){return ["html","body","#document"].indexOf($e(e))>=0?e.ownerDocument.body:ze(e)&&fn(e)?e:Ba(To(e))}function Vo(e,t){var o;t===void 0&&(t=[]);var n=Ba(e),r=n===((o=e.ownerDocument)==null?void 0:o.body),i=ve(n),a=r?[i].concat(i.visualViewport||[],fn(n)?n:[]):n,l=t.concat(a);return r?l:l.concat(Vo(To(a)))}function tr(e){return Object.assign({},e,{left:e.x,top:e.y,right:e.x+e.width,bottom:e.y+e.height})}function dT(e,t){var o=Ft(e,false,t==="fixed");return o.top=o.top+e.clientTop,o.left=o.left+e.clientLeft,o.bottom=o.top+e.clientHeight,o.right=o.left+e.clientWidth,o.width=e.clientWidth,o.height=e.clientHeight,o.x=o.left,o.y=o.top,o}function Rm(e,t,o){return t===Oa?tr(Ol(e,o)):Vt(t)?dT(t,o):tr(Ml(We(e)))}function mT(e){var t=Vo(To(e)),o=["absolute","fixed"].indexOf(mt(e).position)>=0,n=o&&ze(e)?Qt(e):e;return Vt(n)?t.filter(function(r){return Vt(r)&&Yr(r,n)&&$e(r)!=="body"}):[]}function Dl(e,t,o,n){var r=t==="clippingParents"?mT(e):[].concat(t),i=[].concat(r,[o]),a=i[0],l=i.reduce(function(s,u){var c=Rm(e,u,n);return s.top=Jt(c.top,s.top),s.right=ln(c.right,s.right),s.bottom=ln(c.bottom,s.bottom),s.left=Jt(c.left,s.left),s},Rm(e,a,n));return l.width=l.right-l.left,l.height=l.bottom-l.top,l.x=l.left,l.y=l.top,l}function Zr(e){var t=e.reference,o=e.element,n=e.placement,r=n?Ge(n):null,i=n?_t(n):null,a=t.x+t.width/2-o.width/2,l=t.y+t.height/2-o.height/2,s;switch(r){case Ce:s={x:a,y:t.y-o.height};break;case Be:s={x:a,y:t.y+t.height};break;case Pe:s={x:t.x+t.width,y:l};break;case Ee:s={x:t.x-o.width,y:l};break;default:s={x:t.x,y:t.y};}var u=r?un(r):null;if(u!=null){var c=u==="y"?"height":"width";switch(i){case Co:s[u]=s[u]-(t[c]/2-o[c]/2);break;case sn:s[u]=s[u]+(t[c]/2-o[c]/2);break;}}return s}function Zt(e,t){t===void 0&&(t={});var o=t,n=o.placement,r=n===void 0?e.placement:n,i=o.strategy,a=i===void 0?e.strategy:i,l=o.boundary,s=l===void 0?xm:l,u=o.rootBoundary,c=u===void 0?Oa:u,p=o.elementContext,m=p===void 0?Jn:p,f=o.altBoundary,g=f===void 0?false:f,S=o.padding,v=S===void 0?0:S,h=Jr(typeof v!="number"?v:Qr(v,No)),b=m===Jn?Cm:Jn,C=e.rects.popper,d=e.elements[g?b:m],y=Dl(Vt(d)?d:d.contextElement||We(e.elements.popper),s,c,a),x=Ft(e.elements.reference),k=Zr({reference:x,element:C,placement:r}),R=tr(Object.assign({},C,k)),B=m===Jn?R:x,N={top:y.top-B.top+h.top,bottom:B.bottom-y.bottom+h.bottom,left:y.left-B.left+h.left,right:B.right-y.right+h.right},$=e.modifiersData.offset;if(m===Jn&&$){var K=$[r];Object.keys(N).forEach(function(T){var M=[Pe,Be].indexOf(T)>=0?1:-1,I=[Ce,Be].indexOf(T)>=0?"y":"x";N[T]+=K[I]*M;});}return N}function Ll(e,t){t===void 0&&(t={});var o=t,n=o.placement,r=o.boundary,i=o.rootBoundary,a=o.padding,l=o.flipVariations,s=o.allowedAutoPlacements,u=s===void 0?Ma:s,c=_t(n),p=c?l?Pl:Pl.filter(function(g){return _t(g)===c}):No,m=p.filter(function(g){return u.indexOf(g)>=0});m.length===0&&(m=p);var f=m.reduce(function(g,S){return g[S]=Zt(e,{placement:S,boundary:r,rootBoundary:i,padding:a})[Ge(S)],g},{});return Object.keys(f).sort(function(g,S){return f[g]-f[S]})}function fT(e){if(Ge(e)===Ra)return [];var t=er(e);return [La(e),t,La(t)]}function gT(e){var t=e.state,o=e.options,n=e.name;if(!t.modifiersData[n]._skip){for(var r=o.mainAxis,i=r===void 0?true:r,a=o.altAxis,l=a===void 0?true:a,s=o.fallbackPlacements,u=o.padding,c=o.boundary,p=o.rootBoundary,m=o.altBoundary,f=o.flipVariations,g=f===void 0?true:f,S=o.allowedAutoPlacements,v=t.options.placement,h=Ge(v),b=h===v,C=s||(b||!g?[er(v)]:fT(v)),d=[v].concat(C).reduce(function(_,Q){return _.concat(Ge(Q)===Ra?Ll(t,{placement:Q,boundary:c,rootBoundary:p,padding:u,flipVariations:g,allowedAutoPlacements:S}):Q)},[]),y=t.rects.reference,x=t.rects.popper,k=new Map,R=true,B=d[0],N=0;N<d.length;N++){var $=d[N],K=Ge($),T=_t($)===Co,M=[Ce,Be].indexOf(K)>=0,I=M?"width":"height",O=Zt(t,{placement:$,boundary:c,rootBoundary:p,altBoundary:m,padding:u}),G=M?T?Pe:Ee:T?Be:Ce;y[I]>x[I]&&(G=er(G));var W=er(G),F=[];if(i&&F.push(O[K]<=0),l&&F.push(O[G]<=0,O[W]<=0),F.every(function(_){return _})){B=$,R=false;break}k.set($,F);}if(R)for(var L=g?3:1,U=function(Q){var Y=d.find(function(ce){var re=k.get(ce);if(re)return re.slice(0,Q).every(function(ae){return ae})});if(Y)return B=Y,"break"},P=L;P>0;P--){var A=U(P);if(A==="break")break}t.placement!==B&&(t.modifiersData[n]._skip=true,t.placement=B,t.reset=true);}}var Om={name:"flip",enabled:true,phase:"main",fn:gT,requiresIfExists:["offset"],data:{_skip:false}};function Mm(e,t,o){return o===void 0&&(o={x:0,y:0}),{top:e.top-t.height-o.y,right:e.right-t.width+o.x,bottom:e.bottom-t.height+o.y,left:e.left-t.width-o.x}}function Dm(e){return [Ce,Pe,Be,Ee].some(function(t){return e[t]>=0})}function hT(e){var t=e.state,o=e.name,n=t.rects.reference,r=t.rects.popper,i=t.modifiersData.preventOverflow,a=Zt(t,{elementContext:"reference"}),l=Zt(t,{altBoundary:true}),s=Mm(a,n),u=Mm(l,r,i),c=Dm(s),p=Dm(u);t.modifiersData[o]={referenceClippingOffsets:s,popperEscapeOffsets:u,isReferenceHidden:c,hasPopperEscaped:p},t.attributes.popper=Object.assign({},t.attributes.popper,{"data-popper-reference-hidden":c,"data-popper-escaped":p});}var Lm={name:"hide",enabled:true,phase:"main",requiresIfExists:["preventOverflow"],fn:hT};function bT(e,t,o){var n=Ge(e),r=[Ee,Ce].indexOf(n)>=0?-1:1,i=typeof o=="function"?o(Object.assign({},t,{placement:e})):o,a=i[0],l=i[1];return a=a||0,l=(l||0)*r,[Ee,Pe].indexOf(n)>=0?{x:l,y:a}:{x:a,y:l}}function yT(e){var t=e.state,o=e.options,n=e.name,r=o.offset,i=r===void 0?[0,0]:r,a=Ma.reduce(function(c,p){return c[p]=bT(p,t.rects,i),c},{}),l=a[t.placement],s=l.x,u=l.y;t.modifiersData.popperOffsets!=null&&(t.modifiersData.popperOffsets.x+=s,t.modifiersData.popperOffsets.y+=u),t.modifiersData[n]=a;}var Bm={name:"offset",enabled:true,phase:"main",requires:["popperOffsets"],fn:yT};function vT(e){var t=e.state,o=e.name;t.modifiersData[o]=Zr({reference:t.rects.reference,element:t.rects.popper,placement:t.placement});}var zm={name:"popperOffsets",enabled:true,phase:"read",fn:vT,data:{}};function Bl(e){return e==="x"?"y":"x"}function ST(e){var t=e.state,o=e.options,n=e.name,r=o.mainAxis,i=r===void 0?true:r,a=o.altAxis,l=a===void 0?false:a,s=o.boundary,u=o.rootBoundary,c=o.altBoundary,p=o.padding,m=o.tether,f=m===void 0?true:m,g=o.tetherOffset,S=g===void 0?0:g,v=Zt(t,{boundary:s,rootBoundary:u,padding:p,altBoundary:c}),h=Ge(t.placement),b=_t(t.placement),C=!b,d=un(h),y=Bl(d),x=t.modifiersData.popperOffsets,k=t.rects.reference,R=t.rects.popper,B=typeof S=="function"?S(Object.assign({},t.rects,{placement:t.placement})):S,N=typeof B=="number"?{mainAxis:B,altAxis:B}:Object.assign({mainAxis:0,altAxis:0},B),$=t.modifiersData.offset?t.modifiersData.offset[t.placement]:null,K={x:0,y:0};if(x){if(i){var T,M=d==="y"?Ce:Ee,I=d==="y"?Be:Pe,O=d==="y"?"height":"width",G=x[d],W=G+v[M],F=G-v[I],L=f?-R[O]/2:0,U=b===Co?k[O]:R[O],P=b===Co?-R[O]:-k[O],A=t.elements.arrow,_=f&&A?cn(A):{width:0,height:0},Q=t.modifiersData["arrow#persistent"]?t.modifiersData["arrow#persistent"].padding:Xr(),Y=Q[M],ce=Q[I],re=pn(0,k[O],_[O]),ae=C?k[O]/2-L-re-Y-N.mainAxis:U-re-Y-N.mainAxis,fe=C?-k[O]/2+L+re+ce+N.mainAxis:P+re+ce+N.mainAxis,ht=t.elements.arrow&&Qt(t.elements.arrow),Tt=ht?d==="y"?ht.clientTop||0:ht.clientLeft||0:0,Rt=(T=$?.[d])!=null?T:0,z=G+ae-Rt-Tt,X=G+fe-Rt,ie=pn(f?ln(W,z):W,G,f?Jt(F,X):F);x[d]=ie,K[d]=ie-G;}if(l){var Ve,at=d==="x"?Ce:Ee,Ye=d==="x"?Be:Pe,Kt=x[y],Mo=y==="y"?"height":"width",wr=Kt+v[at],Qo=Kt-v[Ye],Er=[Ce,Ee].indexOf(h)!==-1,Ai=(Ve=$?.[y])!=null?Ve:0,Pi=Er?wr:Kt-k[Mo]-R[Mo]-Ai+N.altAxis,Ri=Er?Kt+k[Mo]+R[Mo]-Ai-N.altAxis:Qo,Oi=f&&Er?wm(Pi,Kt,Ri):pn(f?Pi:wr,Kt,f?Ri:Qo);x[y]=Oi,K[y]=Oi-Kt;}t.modifiersData[n]=K;}}var Nm={name:"preventOverflow",enabled:true,phase:"main",fn:ST,requiresIfExists:["offset"]};function zl(e){return {scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}}function Nl(e){return e===ve(e)||!ze(e)?dn(e):zl(e)}function xT(e){var t=e.getBoundingClientRect(),o=ko(t.width)/e.offsetWidth||1,n=ko(t.height)/e.offsetHeight||1;return o!==1||n!==1}function Vl(e,t,o){o===void 0&&(o=false);var n=ze(t),r=ze(t)&&xT(t),i=We(t),a=Ft(e,r,o),l={scrollLeft:0,scrollTop:0},s={x:0,y:0};return (n||!n&&!o)&&(($e(t)!=="body"||fn(i))&&(l=Nl(t)),ze(t)?(s=Ft(t,true),s.x+=t.clientLeft,s.y+=t.clientTop):i&&(s.x=mn(i))),{x:a.left+l.scrollLeft-s.x,y:a.top+l.scrollTop-s.y,width:a.width,height:a.height}}function CT(e){var t=new Map,o=new Set,n=[];e.forEach(function(i){t.set(i.name,i);});function r(i){o.add(i.name);var a=[].concat(i.requires||[],i.requiresIfExists||[]);a.forEach(function(l){if(!o.has(l)){var s=t.get(l);s&&r(s);}}),n.push(i);}return e.forEach(function(i){o.has(i.name)||r(i);}),n}function Fl(e){var t=CT(e);return km.reduce(function(o,n){return o.concat(t.filter(function(r){return r.phase===n}))},[])}function _l(e){var t;return function(){return t||(t=new Promise(function(o){Promise.resolve().then(function(){t=void 0,o(e());});})),t}}function $l(e){var t=e.reduce(function(o,n){var r=o[n.name];return o[n.name]=r?Object.assign({},r,n,{options:Object.assign({},r.options,n.options),data:Object.assign({},r.data,n.data)}):n,o},{});return Object.keys(t).map(function(o){return t[o]})}var Vm={placement:"bottom",modifiers:[],strategy:"absolute"};function Fm(){for(var e=arguments.length,t=new Array(e),o=0;o<e;o++)t[o]=arguments[o];return !t.some(function(n){return !(n&&typeof n.getBoundingClientRect=="function")})}function _m(e){e===void 0&&(e={});var t=e,o=t.defaultModifiers,n=o===void 0?[]:o,r=t.defaultOptions,i=r===void 0?Vm:r;return function(l,s,u){u===void 0&&(u=i);var c={placement:"bottom",orderedModifiers:[],options:Object.assign({},Vm,i),modifiersData:{},elements:{reference:l,popper:s},attributes:{},styles:{}},p=[],m=false,f={state:c,setOptions:function(h){var b=typeof h=="function"?h(c.options):h;S(),c.options=Object.assign({},i,c.options,b),c.scrollParents={reference:Vt(l)?Vo(l):l.contextElement?Vo(l.contextElement):[],popper:Vo(s)};var C=Fl($l([].concat(n,c.options.modifiers)));return c.orderedModifiers=C.filter(function(d){return d.enabled}),g(),f.update()},forceUpdate:function(){if(!m){var h=c.elements,b=h.reference,C=h.popper;if(Fm(b,C)){c.rects={reference:Vl(b,Qt(C),c.options.strategy==="fixed"),popper:cn(C)},c.reset=false,c.placement=c.options.placement,c.orderedModifiers.forEach(function(N){return c.modifiersData[N.name]=Object.assign({},N.data)});for(var d=0;d<c.orderedModifiers.length;d++){if(c.reset===true){c.reset=false,d=-1;continue}var y=c.orderedModifiers[d],x=y.fn,k=y.options,R=k===void 0?{}:k,B=y.name;typeof x=="function"&&(c=x({state:c,options:R,name:B,instance:f})||c);}}}},update:_l(function(){return new Promise(function(v){f.forceUpdate(),v(c);})}),destroy:function(){S(),m=true;}};if(!Fm(l,s))return f;f.setOptions(u).then(function(v){!m&&u.onFirstUpdate&&u.onFirstUpdate(v);});function g(){c.orderedModifiers.forEach(function(v){var h=v.name,b=v.options,C=b===void 0?{}:b,d=v.effect;if(typeof d=="function"){var y=d({state:c,name:h,instance:f,options:C}),x=function(){};p.push(y||x);}});}function S(){p.forEach(function(v){return v()}),p=[];}return f}}var kT=[Pm,zm,Am,Kr,Bm,Om,Nm,Em,Lm],Gl=_m({defaultModifiers:kT});var TT="tippy-box",Jm="tippy-content",wT="tippy-backdrop",Qm="tippy-arrow",Zm="tippy-svg-arrow",gn={passive:true,capture:true},ef=function(){return document.body};function ET(e,t){return {}.hasOwnProperty.call(e,t)}function Ul(e,t,o){if(Array.isArray(e)){var n=e[t];return n??(Array.isArray(o)?o[t]:o)}return e}function Xl(e,t){var o={}.toString.call(e);return o.indexOf("[object")===0&&o.indexOf(t+"]")>-1}function tf(e,t){return typeof e=="function"?e.apply(void 0,t):e}function $m(e,t){if(t===0)return e;var o;return function(n){clearTimeout(o),o=setTimeout(function(){e(n);},t);}}function IT(e,t){var o=Object.assign({},e);return t.forEach(function(n){delete o[n];}),o}function AT(e){return e.split(/\s+/).filter(Boolean)}function nr(e){return [].concat(e)}function Gm(e,t){e.indexOf(t)===-1&&e.push(t);}function PT(e){return e.filter(function(t,o){return e.indexOf(t)===o})}function RT(e){return e.split("-")[0]}function Na(e){return [].slice.call(e)}function Um(e){return Object.keys(e).reduce(function(t,o){return e[o]!==void 0&&(t[o]=e[o]),t},{})}function ei(){return document.createElement("div")}function ti(e){return ["Element","Fragment"].some(function(t){return Xl(e,t)})}function OT(e){return Xl(e,"NodeList")}function MT(e){return Xl(e,"MouseEvent")}function DT(e){return !!(e&&e._tippy&&e._tippy.reference===e)}function LT(e){return ti(e)?[e]:OT(e)?Na(e):Array.isArray(e)?e:Na(document.querySelectorAll(e))}function Hl(e,t){e.forEach(function(o){o&&(o.style.transitionDuration=t+"ms");});}function Hm(e,t){e.forEach(function(o){o&&o.setAttribute("data-state",t);});}function BT(e){var t,o=nr(e),n=o[0];return n!=null&&(t=n.ownerDocument)!=null&&t.body?n.ownerDocument:document}function zT(e,t){var o=t.clientX,n=t.clientY;return e.every(function(r){var i=r.popperRect,a=r.popperState,l=r.props,s=l.interactiveBorder,u=RT(a.placement),c=a.modifiersData.offset;if(!c)return true;var p=u==="bottom"?c.top.y:0,m=u==="top"?c.bottom.y:0,f=u==="right"?c.left.x:0,g=u==="left"?c.right.x:0,S=i.top-n+p>s,v=n-i.bottom-m>s,h=i.left-o+f>s,b=o-i.right-g>s;return S||v||h||b})}function jl(e,t,o){var n=t+"EventListener";["transitionend","webkitTransitionEnd"].forEach(function(r){e[n](r,o);});}function jm(e,t){for(var o=t;o;){var n;if(e.contains(o))return true;o=o.getRootNode==null||(n=o.getRootNode())==null?void 0:n.host;}return false}var so={isTouch:false},Wm=0;function NT(){so.isTouch||(so.isTouch=true,window.performance&&document.addEventListener("mousemove",of));}function of(){var e=performance.now();e-Wm<20&&(so.isTouch=false,document.removeEventListener("mousemove",of)),Wm=e;}function VT(){var e=document.activeElement;if(DT(e)){var t=e._tippy;e.blur&&!t.state.isVisible&&e.blur();}}function FT(){document.addEventListener("touchstart",NT,gn),window.addEventListener("blur",VT);}var _T=typeof window<"u"&&typeof document<"u",$T=_T?!!window.msCrypto:false;function or(e){var t=e==="destroy"?"n already-":" ";return [e+"() was called on a"+t+"destroyed instance. This is a no-op but","indicates a potential memory leak."].join(" ")}function Km(e){var t=/[ \t]{2,}/g,o=/^[ \t]*/gm;return e.replace(t," ").replace(o,"").trim()}function GT(e){return Km(`
12
12
  %ctippy.js
13
13
 
14
- %c`+Kf(e)+`
14
+ %c`+Km(e)+`
15
15
 
16
16
  %c\u{1F477}\u200D This is a development-only message. It will be removed in production.
17
- `)}function nm(e){return [GT(e),"color: #00C584; font-size: 1.3em; font-weight: bold;","line-height: 1.5","color: #a6a095;"]}var oi;process.env.NODE_ENV!=="production"&&UT();function UT(){oi=new Set;}function To(e,t){if(e&&!oi.has(t)){var o;oi.add(t),(o=console).warn.apply(o,nm(t));}}function Kl(e,t){if(e&&!oi.has(t)){var o;oi.add(t),(o=console).error.apply(o,nm(t));}}function HT(e){var t=!e,o=Object.prototype.toString.call(e)==="[object Object]"&&!e.addEventListener;Kl(t,["tippy() was passed","`"+String(e)+"`","as its targets (first) argument. Valid types are: String, Element,","Element[], or NodeList."].join(" ")),Kl(o,["tippy() was passed a plain object which is not supported as an argument","for virtual positioning. Use props.getReferenceClientRect instead."].join(" "));}var rm={animateFill:false,followCursor:false,inlinePositioning:false,sticky:false},jT={allowHTML:false,animation:"fade",arrow:true,content:"",inertia:false,maxWidth:350,role:"tooltip",theme:"",zIndex:9999},Tt=Object.assign({appendTo:em,aria:{content:"auto",expanded:"auto"},delay:0,duration:[300,250],getReferenceClientRect:null,hideOnClick:true,ignoreAttributes:false,interactive:false,interactiveBorder:2,interactiveDebounce:0,moveTransition:"",offset:[0,10],onAfterUpdate:function(){},onBeforeUpdate:function(){},onCreate:function(){},onDestroy:function(){},onHidden:function(){},onHide:function(){},onMount:function(){},onShow:function(){},onShown:function(){},onTrigger:function(){},onUntrigger:function(){},onClickOutside:function(){},placement:"top",plugins:[],popperOptions:{},render:null,showOnCreate:false,touch:true,trigger:"mouseenter focus",triggerTarget:null},rm,jT),WT=Object.keys(Tt),KT=function(t){process.env.NODE_ENV!=="production"&&am(t,[]);var o=Object.keys(t);o.forEach(function(n){Tt[n]=t[n];});};function im(e){var t=e.plugins||[],o=t.reduce(function(n,r){var i=r.name,s=r.defaultValue;if(i){var l;n[i]=e[i]!==void 0?e[i]:(l=Tt[i])!=null?l:s;}return n},{});return Object.assign({},e,o)}function qT(e,t){var o=t?Object.keys(im(Object.assign({},Tt,{plugins:t}))):WT,n=o.reduce(function(r,i){var s=(e.getAttribute("data-tippy-"+i)||"").trim();if(!s)return r;if(i==="content")r[i]=s;else try{r[i]=JSON.parse(s);}catch{r[i]=s;}return r},{});return n}function qf(e,t){var o=Object.assign({},t,{content:tm(t.content,[e])},t.ignoreAttributes?{}:qT(e,t.plugins));return o.aria=Object.assign({},Tt.aria,o.aria),o.aria={expanded:o.aria.expanded==="auto"?t.interactive:o.aria.expanded,content:o.aria.content==="auto"?t.interactive?null:"describedby":o.aria.content},o}function am(e,t){e===void 0&&(e={}),t===void 0&&(t=[]);var o=Object.keys(e);o.forEach(function(n){var r=IT(Tt,Object.keys(rm)),i=!ET(r,n);i&&(i=t.filter(function(s){return s.name===n}).length===0),To(i,["`"+n+"`","is not a valid prop. You may have spelled it incorrectly, or if it's","a plugin, forgot to pass it in an array as props.plugins.",`
17
+ `)}function nf(e){return [GT(e),"color: #00C584; font-size: 1.3em; font-weight: bold;","line-height: 1.5","color: #a6a095;"]}var oi;process.env.NODE_ENV!=="production"&&UT();function UT(){oi=new Set;}function wo(e,t){if(e&&!oi.has(t)){var o;oi.add(t),(o=console).warn.apply(o,nf(t));}}function Kl(e,t){if(e&&!oi.has(t)){var o;oi.add(t),(o=console).error.apply(o,nf(t));}}function HT(e){var t=!e,o=Object.prototype.toString.call(e)==="[object Object]"&&!e.addEventListener;Kl(t,["tippy() was passed","`"+String(e)+"`","as its targets (first) argument. Valid types are: String, Element,","Element[], or NodeList."].join(" ")),Kl(o,["tippy() was passed a plain object which is not supported as an argument","for virtual positioning. Use props.getReferenceClientRect instead."].join(" "));}var rf={animateFill:false,followCursor:false,inlinePositioning:false,sticky:false},jT={allowHTML:false,animation:"fade",arrow:true,content:"",inertia:false,maxWidth:350,role:"tooltip",theme:"",zIndex:9999},wt=Object.assign({appendTo:ef,aria:{content:"auto",expanded:"auto"},delay:0,duration:[300,250],getReferenceClientRect:null,hideOnClick:true,ignoreAttributes:false,interactive:false,interactiveBorder:2,interactiveDebounce:0,moveTransition:"",offset:[0,10],onAfterUpdate:function(){},onBeforeUpdate:function(){},onCreate:function(){},onDestroy:function(){},onHidden:function(){},onHide:function(){},onMount:function(){},onShow:function(){},onShown:function(){},onTrigger:function(){},onUntrigger:function(){},onClickOutside:function(){},placement:"top",plugins:[],popperOptions:{},render:null,showOnCreate:false,touch:true,trigger:"mouseenter focus",triggerTarget:null},rf,jT),WT=Object.keys(wt),KT=function(t){process.env.NODE_ENV!=="production"&&sf(t,[]);var o=Object.keys(t);o.forEach(function(n){wt[n]=t[n];});};function af(e){var t=e.plugins||[],o=t.reduce(function(n,r){var i=r.name,a=r.defaultValue;if(i){var l;n[i]=e[i]!==void 0?e[i]:(l=wt[i])!=null?l:a;}return n},{});return Object.assign({},e,o)}function qT(e,t){var o=t?Object.keys(af(Object.assign({},wt,{plugins:t}))):WT,n=o.reduce(function(r,i){var a=(e.getAttribute("data-tippy-"+i)||"").trim();if(!a)return r;if(i==="content")r[i]=a;else try{r[i]=JSON.parse(a);}catch{r[i]=a;}return r},{});return n}function qm(e,t){var o=Object.assign({},t,{content:tf(t.content,[e])},t.ignoreAttributes?{}:qT(e,t.plugins));return o.aria=Object.assign({},wt.aria,o.aria),o.aria={expanded:o.aria.expanded==="auto"?t.interactive:o.aria.expanded,content:o.aria.content==="auto"?t.interactive?null:"describedby":o.aria.content},o}function sf(e,t){e===void 0&&(e={}),t===void 0&&(t=[]);var o=Object.keys(e);o.forEach(function(n){var r=IT(wt,Object.keys(rf)),i=!ET(r,n);i&&(i=t.filter(function(a){return a.name===n}).length===0),wo(i,["`"+n+"`","is not a valid prop. You may have spelled it incorrectly, or if it's","a plugin, forgot to pass it in an array as props.plugins.",`
18
18
 
19
19
  `,`All props: https://atomiks.github.io/tippyjs/v6/all-props/
20
- `,"Plugins: https://atomiks.github.io/tippyjs/v6/plugins/"].join(" "));});}var YT=function(){return "innerHTML"};function ql(e,t){e[YT()]=t;}function Yf(e){var t=ei();return e===true?t.className=Qf:(t.className=Zf,ti(e)?t.appendChild(e):ql(t,e)),t}function Xf(e,t){ti(t.content)?(ql(e,""),e.appendChild(t.content)):typeof t.content!="function"&&(t.allowHTML?ql(e,t.content):e.textContent=t.content);}function Yl(e){var t=e.firstElementChild,o=Na(t.children);return {box:t,content:o.find(function(n){return n.classList.contains(Jf)}),arrow:o.find(function(n){return n.classList.contains(Qf)||n.classList.contains(Zf)}),backdrop:o.find(function(n){return n.classList.contains(wT)})}}function sm(e){var t=ei(),o=ei();o.className=TT,o.setAttribute("data-state","hidden"),o.setAttribute("tabindex","-1");var n=ei();n.className=Jf,n.setAttribute("data-state","hidden"),Xf(n,e.props),t.appendChild(o),o.appendChild(n),r(e.props,e.props);function r(i,s){var l=Yl(t),a=l.box,u=l.content,c=l.arrow;s.theme?a.setAttribute("data-theme",s.theme):a.removeAttribute("data-theme"),typeof s.animation=="string"?a.setAttribute("data-animation",s.animation):a.removeAttribute("data-animation"),s.inertia?a.setAttribute("data-inertia",""):a.removeAttribute("data-inertia"),a.style.maxWidth=typeof s.maxWidth=="number"?s.maxWidth+"px":s.maxWidth,s.role?a.setAttribute("role",s.role):a.removeAttribute("role"),(i.content!==s.content||i.allowHTML!==s.allowHTML)&&Xf(u,e.props),s.arrow?c?i.arrow!==s.arrow&&(a.removeChild(c),a.appendChild(Yf(s.arrow))):a.appendChild(Yf(s.arrow)):c&&a.removeChild(c);}return {popper:t,onUpdate:r}}sm.$$tippy=true;var XT=1,za=[],Wl=[];function JT(e,t){var o=qf(e,Object.assign({},Tt,im(Uf(t)))),n,r,i,s=false,l=false,a=false,u=false,c,p,f,m=[],g=$f(z,o.interactiveDebounce),S,v=XT++,h=null,b=PT(o.plugins),C={isEnabled:true,isVisible:false,isDestroyed:false,isMounted:false,isShown:false},d={id:v,reference:e,popper:ei(),popperInstance:h,props:o,state:C,plugins:b,clearDelayTimeouts:Pi,setProps:Ri,setContent:Oi,show:Pb,hide:Rb,hideWithInteractivity:Ob,enable:Er,disable:Ai,unmount:Mb,destroy:Db};if(!o.render)return process.env.NODE_ENV!=="production"&&Kl(true,"render() function has not been supplied."),d;var y=o.render(d),x=y.popper,k=y.onUpdate;x.setAttribute("data-tippy-root",""),x.id="tippy-"+d.id,d.popper=x,e._tippy=d,x._tippy=d;var R=b.map(function(D){return D.fn(d)}),B=e.hasAttribute("aria-expanded");return gt(),L(),G(),W("onCreate",[d]),o.showOnCreate&&wr(),x.addEventListener("mouseenter",function(){d.props.interactive&&d.state.isVisible&&d.clearDelayTimeouts();}),x.addEventListener("mouseleave",function(){d.props.interactive&&d.props.trigger.indexOf("mouseenter")>=0&&M().addEventListener("mousemove",g);}),d;function N(){var D=d.props.touch;return Array.isArray(D)?D:[D,0]}function $(){return N()[0]==="hold"}function K(){var D;return !!((D=d.props.render)!=null&&D.$$tippy)}function T(){return S||e}function M(){var D=T().parentNode;return D?BT(D):document}function I(){return Yl(x)}function O(D){return d.state.isMounted&&!d.state.isVisible||so.isTouch||c&&c.type==="focus"?0:Ul(d.props.delay,D?0:1,Tt.delay)}function G(D){D===void 0&&(D=false),x.style.pointerEvents=d.props.interactive&&!D?"":"none",x.style.zIndex=""+d.props.zIndex;}function W(D,Z,oe){if(oe===void 0&&(oe=true),R.forEach(function(pe){pe[D]&&pe[D].apply(pe,Z);}),oe){var ge;(ge=d.props)[D].apply(ge,Z);}}function F(){var D=d.props.aria;if(D.content){var Z="aria-"+D.content,oe=x.id,ge=er(d.props.triggerTarget||e);ge.forEach(function(pe){var st=pe.getAttribute(Z);if(d.state.isVisible)pe.setAttribute(Z,st?st+" "+oe:oe);else {var Ot=st&&st.replace(oe,"").trim();Ot?pe.setAttribute(Z,Ot):pe.removeAttribute(Z);}});}}function L(){if(!(B||!d.props.aria.expanded)){var D=er(d.props.triggerTarget||e);D.forEach(function(Z){d.props.interactive?Z.setAttribute("aria-expanded",d.state.isVisible&&Z===T()?"true":"false"):Z.removeAttribute("aria-expanded");});}}function U(){M().removeEventListener("mousemove",g),za=za.filter(function(D){return D!==g});}function P(D){if(!(so.isTouch&&(a||D.type==="mousedown"))){var Z=D.composedPath&&D.composedPath()[0]||D.target;if(!(d.props.interactive&&jf(x,Z))){if(er(d.props.triggerTarget||e).some(function(oe){return jf(oe,Z)})){if(so.isTouch||d.state.isVisible&&d.props.trigger.indexOf("click")>=0)return}else W("onClickOutside",[d,D]);d.props.hideOnClick===true&&(d.clearDelayTimeouts(),d.hide(),l=true,setTimeout(function(){l=false;}),d.state.isMounted||Y());}}}function A(){a=true;}function _(){a=false;}function Q(){var D=M();D.addEventListener("mousedown",P,true),D.addEventListener("touchend",P,gn),D.addEventListener("touchstart",_,gn),D.addEventListener("touchmove",A,gn);}function Y(){var D=M();D.removeEventListener("mousedown",P,true),D.removeEventListener("touchend",P,gn),D.removeEventListener("touchstart",_,gn),D.removeEventListener("touchmove",A,gn);}function ce(D,Z){ae(D,function(){!d.state.isVisible&&x.parentNode&&x.parentNode.contains(x)&&Z();});}function re(D,Z){ae(D,Z);}function ae(D,Z){var oe=I().box;function ge(pe){pe.target===oe&&(jl(oe,"remove",ge),Z());}if(D===0)return Z();jl(oe,"remove",p),jl(oe,"add",ge),p=ge;}function me(D,Z,oe){oe===void 0&&(oe=false);var ge=er(d.props.triggerTarget||e);ge.forEach(function(pe){pe.addEventListener(D,Z,oe),m.push({node:pe,eventType:D,handler:Z,options:oe});});}function gt(){$()&&(me("touchstart",Rt,{passive:true}),me("touchend",X,{passive:true})),AT(d.props.trigger).forEach(function(D){if(D!=="manual")switch(me(D,Rt),D){case "mouseenter":me("mouseleave",X);break;case "focus":me($T?"focusout":"blur",ie);break;case "focusin":me("focusout",ie);break}});}function kt(){m.forEach(function(D){var Z=D.node,oe=D.eventType,ge=D.handler,pe=D.options;Z.removeEventListener(oe,ge,pe);}),m=[];}function Rt(D){var Z,oe=false;if(!(!d.state.isEnabled||Ve(D)||l)){var ge=((Z=c)==null?void 0:Z.type)==="focus";c=D,S=D.currentTarget,L(),!d.state.isVisible&&MT(D)&&za.forEach(function(pe){return pe(D)}),D.type==="click"&&(d.props.trigger.indexOf("mouseenter")<0||s)&&d.props.hideOnClick!==false&&d.state.isVisible?oe=true:wr(D),D.type==="click"&&(s=!oe),oe&&!ge&&Qo(D);}}function z(D){var Z=D.target,oe=T().contains(Z)||x.contains(Z);if(!(D.type==="mousemove"&&oe)){var ge=Oo().concat(x).map(function(pe){var st,Ot=pe._tippy,kn=(st=Ot.popperInstance)==null?void 0:st.state;return kn?{popperRect:pe.getBoundingClientRect(),popperState:kn,props:o}:null}).filter(Boolean);zT(ge,D)&&(U(),Qo(D));}}function X(D){var Z=Ve(D)||d.props.trigger.indexOf("click")>=0&&s;if(!Z){if(d.props.interactive){d.hideWithInteractivity(D);return}Qo(D);}}function ie(D){d.props.trigger.indexOf("focusin")<0&&D.target!==T()||d.props.interactive&&D.relatedTarget&&x.contains(D.relatedTarget)||Qo(D);}function Ve(D){return so.isTouch?$()!==D.type.indexOf("touch")>=0:false}function at(){Ye();var D=d.props,Z=D.popperOptions,oe=D.placement,ge=D.offset,pe=D.getReferenceClientRect,st=D.moveTransition,Ot=K()?Yl(x).arrow:null,kn=pe?{getBoundingClientRect:pe,contextElement:pe.contextElement||T()}:e,Lu={name:"$$tippy",enabled:true,phase:"beforeWrite",requires:["computeStyles"],fn:function(Mi){var Tn=Mi.state;if(K()){var Lb=I(),Ds=Lb.box;["placement","reference-hidden","escaped"].forEach(function(Di){Di==="placement"?Ds.setAttribute("data-placement",Tn.placement):Tn.attributes.popper["data-popper-"+Di]?Ds.setAttribute("data-"+Di,""):Ds.removeAttribute("data-"+Di);}),Tn.attributes.popper={};}}},Zo=[{name:"offset",options:{offset:ge}},{name:"preventOverflow",options:{padding:{top:2,bottom:2,left:5,right:5}}},{name:"flip",options:{padding:5}},{name:"computeStyles",options:{adaptive:!st}},Lu];K()&&Ot&&Zo.push({name:"arrow",options:{element:Ot,padding:3}}),Zo.push.apply(Zo,Z?.modifiers||[]),d.popperInstance=Gl(kn,x,Object.assign({},Z,{placement:oe,onFirstUpdate:f,modifiers:Zo}));}function Ye(){d.popperInstance&&(d.popperInstance.destroy(),d.popperInstance=null);}function Wt(){var D=d.props.appendTo,Z,oe=T();d.props.interactive&&D===em||D==="parent"?Z=oe.parentNode:Z=tm(D,[oe]),Z.contains(x)||Z.appendChild(x),d.state.isMounted=true,at(),process.env.NODE_ENV!=="production"&&To(d.props.interactive&&D===Tt.appendTo&&oe.nextElementSibling!==x,["Interactive tippy element may not be accessible via keyboard","navigation because it is not directly after the reference element","in the DOM source order.",`
20
+ `,"Plugins: https://atomiks.github.io/tippyjs/v6/plugins/"].join(" "));});}var YT=function(){return "innerHTML"};function ql(e,t){e[YT()]=t;}function Ym(e){var t=ei();return e===true?t.className=Qm:(t.className=Zm,ti(e)?t.appendChild(e):ql(t,e)),t}function Xm(e,t){ti(t.content)?(ql(e,""),e.appendChild(t.content)):typeof t.content!="function"&&(t.allowHTML?ql(e,t.content):e.textContent=t.content);}function Yl(e){var t=e.firstElementChild,o=Na(t.children);return {box:t,content:o.find(function(n){return n.classList.contains(Jm)}),arrow:o.find(function(n){return n.classList.contains(Qm)||n.classList.contains(Zm)}),backdrop:o.find(function(n){return n.classList.contains(wT)})}}function lf(e){var t=ei(),o=ei();o.className=TT,o.setAttribute("data-state","hidden"),o.setAttribute("tabindex","-1");var n=ei();n.className=Jm,n.setAttribute("data-state","hidden"),Xm(n,e.props),t.appendChild(o),o.appendChild(n),r(e.props,e.props);function r(i,a){var l=Yl(t),s=l.box,u=l.content,c=l.arrow;a.theme?s.setAttribute("data-theme",a.theme):s.removeAttribute("data-theme"),typeof a.animation=="string"?s.setAttribute("data-animation",a.animation):s.removeAttribute("data-animation"),a.inertia?s.setAttribute("data-inertia",""):s.removeAttribute("data-inertia"),s.style.maxWidth=typeof a.maxWidth=="number"?a.maxWidth+"px":a.maxWidth,a.role?s.setAttribute("role",a.role):s.removeAttribute("role"),(i.content!==a.content||i.allowHTML!==a.allowHTML)&&Xm(u,e.props),a.arrow?c?i.arrow!==a.arrow&&(s.removeChild(c),s.appendChild(Ym(a.arrow))):s.appendChild(Ym(a.arrow)):c&&s.removeChild(c);}return {popper:t,onUpdate:r}}lf.$$tippy=true;var XT=1,za=[],Wl=[];function JT(e,t){var o=qm(e,Object.assign({},wt,af(Um(t)))),n,r,i,a=false,l=false,s=false,u=false,c,p,m,f=[],g=$m(z,o.interactiveDebounce),S,v=XT++,h=null,b=PT(o.plugins),C={isEnabled:true,isVisible:false,isDestroyed:false,isMounted:false,isShown:false},d={id:v,reference:e,popper:ei(),popperInstance:h,props:o,state:C,plugins:b,clearDelayTimeouts:Pi,setProps:Ri,setContent:Oi,show:Pb,hide:Rb,hideWithInteractivity:Ob,enable:Er,disable:Ai,unmount:Mb,destroy:Db};if(!o.render)return process.env.NODE_ENV!=="production"&&Kl(true,"render() function has not been supplied."),d;var y=o.render(d),x=y.popper,k=y.onUpdate;x.setAttribute("data-tippy-root",""),x.id="tippy-"+d.id,d.popper=x,e._tippy=d,x._tippy=d;var R=b.map(function(D){return D.fn(d)}),B=e.hasAttribute("aria-expanded");return ht(),L(),G(),W("onCreate",[d]),o.showOnCreate&&wr(),x.addEventListener("mouseenter",function(){d.props.interactive&&d.state.isVisible&&d.clearDelayTimeouts();}),x.addEventListener("mouseleave",function(){d.props.interactive&&d.props.trigger.indexOf("mouseenter")>=0&&M().addEventListener("mousemove",g);}),d;function N(){var D=d.props.touch;return Array.isArray(D)?D:[D,0]}function $(){return N()[0]==="hold"}function K(){var D;return !!((D=d.props.render)!=null&&D.$$tippy)}function T(){return S||e}function M(){var D=T().parentNode;return D?BT(D):document}function I(){return Yl(x)}function O(D){return d.state.isMounted&&!d.state.isVisible||so.isTouch||c&&c.type==="focus"?0:Ul(d.props.delay,D?0:1,wt.delay)}function G(D){D===void 0&&(D=false),x.style.pointerEvents=d.props.interactive&&!D?"":"none",x.style.zIndex=""+d.props.zIndex;}function W(D,Z,oe){if(oe===void 0&&(oe=true),R.forEach(function(de){de[D]&&de[D].apply(de,Z);}),oe){var ge;(ge=d.props)[D].apply(ge,Z);}}function F(){var D=d.props.aria;if(D.content){var Z="aria-"+D.content,oe=x.id,ge=nr(d.props.triggerTarget||e);ge.forEach(function(de){var st=de.getAttribute(Z);if(d.state.isVisible)de.setAttribute(Z,st?st+" "+oe:oe);else {var Ot=st&&st.replace(oe,"").trim();Ot?de.setAttribute(Z,Ot):de.removeAttribute(Z);}});}}function L(){if(!(B||!d.props.aria.expanded)){var D=nr(d.props.triggerTarget||e);D.forEach(function(Z){d.props.interactive?Z.setAttribute("aria-expanded",d.state.isVisible&&Z===T()?"true":"false"):Z.removeAttribute("aria-expanded");});}}function U(){M().removeEventListener("mousemove",g),za=za.filter(function(D){return D!==g});}function P(D){if(!(so.isTouch&&(s||D.type==="mousedown"))){var Z=D.composedPath&&D.composedPath()[0]||D.target;if(!(d.props.interactive&&jm(x,Z))){if(nr(d.props.triggerTarget||e).some(function(oe){return jm(oe,Z)})){if(so.isTouch||d.state.isVisible&&d.props.trigger.indexOf("click")>=0)return}else W("onClickOutside",[d,D]);d.props.hideOnClick===true&&(d.clearDelayTimeouts(),d.hide(),l=true,setTimeout(function(){l=false;}),d.state.isMounted||Y());}}}function A(){s=true;}function _(){s=false;}function Q(){var D=M();D.addEventListener("mousedown",P,true),D.addEventListener("touchend",P,gn),D.addEventListener("touchstart",_,gn),D.addEventListener("touchmove",A,gn);}function Y(){var D=M();D.removeEventListener("mousedown",P,true),D.removeEventListener("touchend",P,gn),D.removeEventListener("touchstart",_,gn),D.removeEventListener("touchmove",A,gn);}function ce(D,Z){ae(D,function(){!d.state.isVisible&&x.parentNode&&x.parentNode.contains(x)&&Z();});}function re(D,Z){ae(D,Z);}function ae(D,Z){var oe=I().box;function ge(de){de.target===oe&&(jl(oe,"remove",ge),Z());}if(D===0)return Z();jl(oe,"remove",p),jl(oe,"add",ge),p=ge;}function fe(D,Z,oe){oe===void 0&&(oe=false);var ge=nr(d.props.triggerTarget||e);ge.forEach(function(de){de.addEventListener(D,Z,oe),f.push({node:de,eventType:D,handler:Z,options:oe});});}function ht(){$()&&(fe("touchstart",Rt,{passive:true}),fe("touchend",X,{passive:true})),AT(d.props.trigger).forEach(function(D){if(D!=="manual")switch(fe(D,Rt),D){case "mouseenter":fe("mouseleave",X);break;case "focus":fe($T?"focusout":"blur",ie);break;case "focusin":fe("focusout",ie);break}});}function Tt(){f.forEach(function(D){var Z=D.node,oe=D.eventType,ge=D.handler,de=D.options;Z.removeEventListener(oe,ge,de);}),f=[];}function Rt(D){var Z,oe=false;if(!(!d.state.isEnabled||Ve(D)||l)){var ge=((Z=c)==null?void 0:Z.type)==="focus";c=D,S=D.currentTarget,L(),!d.state.isVisible&&MT(D)&&za.forEach(function(de){return de(D)}),D.type==="click"&&(d.props.trigger.indexOf("mouseenter")<0||a)&&d.props.hideOnClick!==false&&d.state.isVisible?oe=true:wr(D),D.type==="click"&&(a=!oe),oe&&!ge&&Qo(D);}}function z(D){var Z=D.target,oe=T().contains(Z)||x.contains(Z);if(!(D.type==="mousemove"&&oe)){var ge=Mo().concat(x).map(function(de){var st,Ot=de._tippy,En=(st=Ot.popperInstance)==null?void 0:st.state;return En?{popperRect:de.getBoundingClientRect(),popperState:En,props:o}:null}).filter(Boolean);zT(ge,D)&&(U(),Qo(D));}}function X(D){var Z=Ve(D)||d.props.trigger.indexOf("click")>=0&&a;if(!Z){if(d.props.interactive){d.hideWithInteractivity(D);return}Qo(D);}}function ie(D){d.props.trigger.indexOf("focusin")<0&&D.target!==T()||d.props.interactive&&D.relatedTarget&&x.contains(D.relatedTarget)||Qo(D);}function Ve(D){return so.isTouch?$()!==D.type.indexOf("touch")>=0:false}function at(){Ye();var D=d.props,Z=D.popperOptions,oe=D.placement,ge=D.offset,de=D.getReferenceClientRect,st=D.moveTransition,Ot=K()?Yl(x).arrow:null,En=de?{getBoundingClientRect:de,contextElement:de.contextElement||T()}:e,Bu={name:"$$tippy",enabled:true,phase:"beforeWrite",requires:["computeStyles"],fn:function(Mi){var In=Mi.state;if(K()){var Lb=I(),Ds=Lb.box;["placement","reference-hidden","escaped"].forEach(function(Di){Di==="placement"?Ds.setAttribute("data-placement",In.placement):In.attributes.popper["data-popper-"+Di]?Ds.setAttribute("data-"+Di,""):Ds.removeAttribute("data-"+Di);}),In.attributes.popper={};}}},Zo=[{name:"offset",options:{offset:ge}},{name:"preventOverflow",options:{padding:{top:2,bottom:2,left:5,right:5}}},{name:"flip",options:{padding:5}},{name:"computeStyles",options:{adaptive:!st}},Bu];K()&&Ot&&Zo.push({name:"arrow",options:{element:Ot,padding:3}}),Zo.push.apply(Zo,Z?.modifiers||[]),d.popperInstance=Gl(En,x,Object.assign({},Z,{placement:oe,onFirstUpdate:m,modifiers:Zo}));}function Ye(){d.popperInstance&&(d.popperInstance.destroy(),d.popperInstance=null);}function Kt(){var D=d.props.appendTo,Z,oe=T();d.props.interactive&&D===ef||D==="parent"?Z=oe.parentNode:Z=tf(D,[oe]),Z.contains(x)||Z.appendChild(x),d.state.isMounted=true,at(),process.env.NODE_ENV!=="production"&&wo(d.props.interactive&&D===wt.appendTo&&oe.nextElementSibling!==x,["Interactive tippy element may not be accessible via keyboard","navigation because it is not directly after the reference element","in the DOM source order.",`
21
21
 
22
22
  `,"Using a wrapper <div> or <span> tag around the reference element","solves this by creating a new parentNode context.",`
23
23
 
24
24
  `,"Specifying `appendTo: document.body` silences this warning, but it","assumes you are using a focus management solution to handle","keyboard navigation.",`
25
25
 
26
- `,"See: https://atomiks.github.io/tippyjs/v6/accessibility/#interactivity"].join(" "));}function Oo(){return Na(x.querySelectorAll("[data-tippy-root]"))}function wr(D){d.clearDelayTimeouts(),D&&W("onTrigger",[d,D]),Q();var Z=O(true),oe=N(),ge=oe[0],pe=oe[1];so.isTouch&&ge==="hold"&&pe&&(Z=pe),Z?n=setTimeout(function(){d.show();},Z):d.show();}function Qo(D){if(d.clearDelayTimeouts(),W("onUntrigger",[d,D]),!d.state.isVisible){Y();return}if(!(d.props.trigger.indexOf("mouseenter")>=0&&d.props.trigger.indexOf("click")>=0&&["mouseleave","mousemove"].indexOf(D.type)>=0&&s)){var Z=O(false);Z?r=setTimeout(function(){d.state.isVisible&&d.hide();},Z):i=requestAnimationFrame(function(){d.hide();});}}function Er(){d.state.isEnabled=true;}function Ai(){d.hide(),d.state.isEnabled=false;}function Pi(){clearTimeout(n),clearTimeout(r),cancelAnimationFrame(i);}function Ri(D){if(process.env.NODE_ENV!=="production"&&To(d.state.isDestroyed,Zn("setProps")),!d.state.isDestroyed){W("onBeforeUpdate",[d,D]),kt();var Z=d.props,oe=qf(e,Object.assign({},Z,Uf(D),{ignoreAttributes:true}));d.props=oe,gt(),Z.interactiveDebounce!==oe.interactiveDebounce&&(U(),g=$f(z,oe.interactiveDebounce)),Z.triggerTarget&&!oe.triggerTarget?er(Z.triggerTarget).forEach(function(ge){ge.removeAttribute("aria-expanded");}):oe.triggerTarget&&e.removeAttribute("aria-expanded"),L(),G(),k&&k(Z,oe),d.popperInstance&&(at(),Oo().forEach(function(ge){requestAnimationFrame(ge._tippy.popperInstance.forceUpdate);})),W("onAfterUpdate",[d,D]);}}function Oi(D){d.setProps({content:D});}function Pb(){process.env.NODE_ENV!=="production"&&To(d.state.isDestroyed,Zn("show"));var D=d.state.isVisible,Z=d.state.isDestroyed,oe=!d.state.isEnabled,ge=so.isTouch&&!d.props.touch,pe=Ul(d.props.duration,0,Tt.duration);if(!(D||Z||oe||ge)&&!T().hasAttribute("disabled")&&(W("onShow",[d],false),d.props.onShow(d)!==false)){if(d.state.isVisible=true,K()&&(x.style.visibility="visible"),G(),Q(),d.state.isMounted||(x.style.transition="none"),K()){var st=I(),Ot=st.box,kn=st.content;Hl([Ot,kn],0);}f=function(){var Zo;if(!(!d.state.isVisible||u)){if(u=true,x.offsetHeight,x.style.transition=d.props.moveTransition,K()&&d.props.animation){var Ms=I(),Mi=Ms.box,Tn=Ms.content;Hl([Mi,Tn],pe),Hf([Mi,Tn],"visible");}F(),L(),Gf(Wl,d),(Zo=d.popperInstance)==null||Zo.forceUpdate(),W("onMount",[d]),d.props.animation&&K()&&re(pe,function(){d.state.isShown=true,W("onShown",[d]);});}},Wt();}}function Rb(){process.env.NODE_ENV!=="production"&&To(d.state.isDestroyed,Zn("hide"));var D=!d.state.isVisible,Z=d.state.isDestroyed,oe=!d.state.isEnabled,ge=Ul(d.props.duration,1,Tt.duration);if(!(D||Z||oe)&&(W("onHide",[d],false),d.props.onHide(d)!==false)){if(d.state.isVisible=false,d.state.isShown=false,u=false,s=false,K()&&(x.style.visibility="hidden"),U(),Y(),G(true),K()){var pe=I(),st=pe.box,Ot=pe.content;d.props.animation&&(Hl([st,Ot],ge),Hf([st,Ot],"hidden"));}F(),L(),d.props.animation?K()&&ce(ge,d.unmount):d.unmount();}}function Ob(D){process.env.NODE_ENV!=="production"&&To(d.state.isDestroyed,Zn("hideWithInteractivity")),M().addEventListener("mousemove",g),Gf(za,g),g(D);}function Mb(){process.env.NODE_ENV!=="production"&&To(d.state.isDestroyed,Zn("unmount")),d.state.isVisible&&d.hide(),d.state.isMounted&&(Ye(),Oo().forEach(function(D){D._tippy.unmount();}),x.parentNode&&x.parentNode.removeChild(x),Wl=Wl.filter(function(D){return D!==d}),d.state.isMounted=false,W("onHidden",[d]));}function Db(){process.env.NODE_ENV!=="production"&&To(d.state.isDestroyed,Zn("destroy")),!d.state.isDestroyed&&(d.clearDelayTimeouts(),d.unmount(),kt(),delete e._tippy,d.state.isDestroyed=true,W("onDestroy",[d]));}}function ni(e,t){t===void 0&&(t={});var o=Tt.plugins.concat(t.plugins||[]);process.env.NODE_ENV!=="production"&&(HT(e),am(t,o)),FT();var n=Object.assign({},t,{plugins:o}),r=LT(e);if(process.env.NODE_ENV!=="production"){var i=ti(n.content),s=r.length>1;To(i&&s,["tippy() was passed an Element as the `content` prop, but more than","one tippy instance was created by this invocation. This means the","content element will only be appended to the last tippy instance.",`
26
+ `,"See: https://atomiks.github.io/tippyjs/v6/accessibility/#interactivity"].join(" "));}function Mo(){return Na(x.querySelectorAll("[data-tippy-root]"))}function wr(D){d.clearDelayTimeouts(),D&&W("onTrigger",[d,D]),Q();var Z=O(true),oe=N(),ge=oe[0],de=oe[1];so.isTouch&&ge==="hold"&&de&&(Z=de),Z?n=setTimeout(function(){d.show();},Z):d.show();}function Qo(D){if(d.clearDelayTimeouts(),W("onUntrigger",[d,D]),!d.state.isVisible){Y();return}if(!(d.props.trigger.indexOf("mouseenter")>=0&&d.props.trigger.indexOf("click")>=0&&["mouseleave","mousemove"].indexOf(D.type)>=0&&a)){var Z=O(false);Z?r=setTimeout(function(){d.state.isVisible&&d.hide();},Z):i=requestAnimationFrame(function(){d.hide();});}}function Er(){d.state.isEnabled=true;}function Ai(){d.hide(),d.state.isEnabled=false;}function Pi(){clearTimeout(n),clearTimeout(r),cancelAnimationFrame(i);}function Ri(D){if(process.env.NODE_ENV!=="production"&&wo(d.state.isDestroyed,or("setProps")),!d.state.isDestroyed){W("onBeforeUpdate",[d,D]),Tt();var Z=d.props,oe=qm(e,Object.assign({},Z,Um(D),{ignoreAttributes:true}));d.props=oe,ht(),Z.interactiveDebounce!==oe.interactiveDebounce&&(U(),g=$m(z,oe.interactiveDebounce)),Z.triggerTarget&&!oe.triggerTarget?nr(Z.triggerTarget).forEach(function(ge){ge.removeAttribute("aria-expanded");}):oe.triggerTarget&&e.removeAttribute("aria-expanded"),L(),G(),k&&k(Z,oe),d.popperInstance&&(at(),Mo().forEach(function(ge){requestAnimationFrame(ge._tippy.popperInstance.forceUpdate);})),W("onAfterUpdate",[d,D]);}}function Oi(D){d.setProps({content:D});}function Pb(){process.env.NODE_ENV!=="production"&&wo(d.state.isDestroyed,or("show"));var D=d.state.isVisible,Z=d.state.isDestroyed,oe=!d.state.isEnabled,ge=so.isTouch&&!d.props.touch,de=Ul(d.props.duration,0,wt.duration);if(!(D||Z||oe||ge)&&!T().hasAttribute("disabled")&&(W("onShow",[d],false),d.props.onShow(d)!==false)){if(d.state.isVisible=true,K()&&(x.style.visibility="visible"),G(),Q(),d.state.isMounted||(x.style.transition="none"),K()){var st=I(),Ot=st.box,En=st.content;Hl([Ot,En],0);}m=function(){var Zo;if(!(!d.state.isVisible||u)){if(u=true,x.offsetHeight,x.style.transition=d.props.moveTransition,K()&&d.props.animation){var Ms=I(),Mi=Ms.box,In=Ms.content;Hl([Mi,In],de),Hm([Mi,In],"visible");}F(),L(),Gm(Wl,d),(Zo=d.popperInstance)==null||Zo.forceUpdate(),W("onMount",[d]),d.props.animation&&K()&&re(de,function(){d.state.isShown=true,W("onShown",[d]);});}},Kt();}}function Rb(){process.env.NODE_ENV!=="production"&&wo(d.state.isDestroyed,or("hide"));var D=!d.state.isVisible,Z=d.state.isDestroyed,oe=!d.state.isEnabled,ge=Ul(d.props.duration,1,wt.duration);if(!(D||Z||oe)&&(W("onHide",[d],false),d.props.onHide(d)!==false)){if(d.state.isVisible=false,d.state.isShown=false,u=false,a=false,K()&&(x.style.visibility="hidden"),U(),Y(),G(true),K()){var de=I(),st=de.box,Ot=de.content;d.props.animation&&(Hl([st,Ot],ge),Hm([st,Ot],"hidden"));}F(),L(),d.props.animation?K()&&ce(ge,d.unmount):d.unmount();}}function Ob(D){process.env.NODE_ENV!=="production"&&wo(d.state.isDestroyed,or("hideWithInteractivity")),M().addEventListener("mousemove",g),Gm(za,g),g(D);}function Mb(){process.env.NODE_ENV!=="production"&&wo(d.state.isDestroyed,or("unmount")),d.state.isVisible&&d.hide(),d.state.isMounted&&(Ye(),Mo().forEach(function(D){D._tippy.unmount();}),x.parentNode&&x.parentNode.removeChild(x),Wl=Wl.filter(function(D){return D!==d}),d.state.isMounted=false,W("onHidden",[d]));}function Db(){process.env.NODE_ENV!=="production"&&wo(d.state.isDestroyed,or("destroy")),!d.state.isDestroyed&&(d.clearDelayTimeouts(),d.unmount(),Tt(),delete e._tippy,d.state.isDestroyed=true,W("onDestroy",[d]));}}function ni(e,t){t===void 0&&(t={});var o=wt.plugins.concat(t.plugins||[]);process.env.NODE_ENV!=="production"&&(HT(e),sf(t,o)),FT();var n=Object.assign({},t,{plugins:o}),r=LT(e);if(process.env.NODE_ENV!=="production"){var i=ti(n.content),a=r.length>1;wo(i&&a,["tippy() was passed an Element as the `content` prop, but more than","one tippy instance was created by this invocation. This means the","content element will only be appended to the last tippy instance.",`
27
27
 
28
28
  `,"Instead, pass the .innerHTML of the element, or use a function that","returns a cloned version of the element instead.",`
29
29
 
30
30
  `,`1) content: element.innerHTML
31
- `,"2) content: () => element.cloneNode(true)"].join(" "));}var l=r.reduce(function(a,u){var c=u&&JT(u,n);return c&&a.push(c),a},[]);return ti(e)?l[0]:l}ni.defaultProps=Tt;ni.setDefaultProps=KT;ni.currentInput=so;Object.assign({},Kr,{effect:function(t){var o=t.state,n={popper:{position:o.options.strategy,left:"0",top:"0",margin:"0"},arrow:{position:"absolute"},reference:{}};Object.assign(o.elements.popper.style,n.popper),o.styles=n,o.elements.arrow&&Object.assign(o.elements.arrow.style,n.arrow);}});ni.setDefaultProps({render:sm});var lm=ni;var lw=forwardRef(function(t,o){let n=useMantineTheme(),[r,i]=useState(0),s=c=>{let p=t.items[c];p&&t.command({id:p});},l=()=>{i((r+t.items.length-1)%t.items.length);},a=()=>{i((r+1)%t.items.length);},u=()=>{s(r);};return useEffect(()=>i(0),[t.items]),useImperativeHandle(o,()=>({onKeyDown:({event:c})=>c.key==="ArrowUp"?(l(),true):c.key==="ArrowDown"?(a(),true):c.key==="Enter"||c.key==="Tab"?(u(),true):false})),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===r?"is-selected":""}`,sx:f=>({backgroundColor:p===r?f.colors.blue[0]:"none"}),py:2,px:4,fz:12,w:"100%",onClick:()=>s(p),children:jsxs(Group,{spacing:"xs",children:[jsx(Center,{h:"1rem",w:"1rem",sx:{borderRadius:"100%",background:n.colors.blue[6]},children:jsx(IconBraces,{size:"0.8rem",color:"white"})}),jsx(Text,{ff:"monospace",component:"code",color:"gray.7",children:`${c}`})]})})},p)):null})}),um=lw;var pw=()=>({char:"{{",allowedPrefixes:[" "],items:({query:e,editor:t})=>t.storage.VariablesStorage.suggestions.filter(o=>o.toLowerCase().startsWith(e.toLowerCase())).slice(0,5),render:()=>{let e,t;return {onStart:o=>{e=new ReactRenderer(um,{props:o,editor:o.editor}),o.clientRect&&(t=lm("body",{getReferenceClientRect:o.clientRect,appendTo:()=>document.body,content:e.element,showOnCreate:true,interactive:true,trigger:"manual",placement:"bottom-start"}));},onUpdate(o){e.updateProps(o),o.clientRect&&t[0].setProps({getReferenceClientRect:o.clientRect});},onKeyDown(o){return o.event.key==="Escape"?(t[0].hide(),true):e.ref?.onKeyDown(o)},onExit(){t[0].destroy(),e.destroy();}}}}),pm=pw;function Jl(e){return e.replace(/<code[^>]*>([^<>]*)<\/code>/g,"$1")}function Ql(e){return e.replace(/({{.*?}})/g,'<code class="bespoke-var">$1</code>')}var Bw=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"}}})),fm=()=>{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:true,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:true,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:true,children:jsx(IconUnderline,{size:"0.8rem",stroke:e.isActive("underline")?4:2,color:t.colors.gray[7]})})]}):null},zw=()=>{let{editor:e}=useCurrentEditor();return jsx("div",{children:jsx(BubbleMenu,{tippyOptions:{placement:"bottom"},editor:e,children:jsx(fm,{})})})},Nw=()=>{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:true,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:true,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:true,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:true,children:jsx(IconAlignJustified,{size:"0.8rem",stroke:e.isActive({textAlign:"justify"})?4:2,color:t.colors.gray[7]})})]}):null},Vw=()=>{let{editor:e}=useCurrentEditor(),t=useMantineTheme();return e?jsxs(Button.Group,{children:[jsx(Button,{onClick:()=>e.commands.undo(),size:"xs",variant:"default",compact:true,children:jsx(IconArrowBackUp,{size:"0.8rem",color:t.colors.gray[7]})}),jsx(Button,{onClick:()=>e.commands.redo(),size:"xs",variant:"default",compact:true,children:jsx(IconArrowForwardUp,{size:"0.8rem",color:t.colors.gray[7]})})]}):null},Fw=({toolbarActive:e=true,toolbarLeftSection:t=null,toolbarRightSection:o=null,toolbarOptions:n={}})=>{let r=n.history??true,i=n.alignment??false,s=n.format??true;return jsxs(Group,{mb:"0.25rem",position:"apart",children:[t,e&&jsxs(Group,{children:[r&&jsx(Vw,{}),i&&jsx(Nw,{}),s&&jsx(fm,{})]}),o]})};function Fa(e){let{id:t,value:o,onChange:n=()=>{},variables:r,toolbarLeftSection:i,toolbarRightSection:s,toolbarOptions:l={},tipTapExtensions:a=[],bubbleMenu:u=true,disabled:c=false,editorProps:p,placeholder:f="This looks empty! Start writing some content"}=e,[m,g]=useState(false),S=useClickOutside(()=>g(false)),{classes:v}=Bw(),h=JSON.stringify(r||{}),b=useMemo(()=>{let y=JSON.parse(h),x=[yw.configure({heading:false,bold:false,history:{depth:20},code:false,hardBreak:false,codeBlock:false}),yf.extend({spanning:true}),Sw.extend({addKeyboardShortcuts(){return {Enter:()=>this.editor.commands.setHardBreak()}}}),xw.configure({types:["paragraph"]}),bw,vf,Cw.configure({placeholder:f}),Lw,...a];return y&&(x.push(Sf),x.push(vw.configure({HTMLAttributes:{type:null},renderText({node:k}){return `{{${k.attrs.label??k.attrs.id}}}`},renderHTML({node:k}){return ["code",{},`{{${k.attrs.label??k.attrs.id}}}`]},suggestion:pm()}))),x},[h,a,f]),C=({editor:y})=>{let x=Jl(y.getHTML());n(x);},d=({editor:y})=>{let x=JSON.parse(h);y.storage.VariablesStorage.suggestions=Object.keys(x);};return jsx(Box,{ref:S,className:"bespoke-editor",onClickCapture:()=>g(true),children:jsx(EditorProvider,{extensions:b,content:o?Ql(o):void 0,onUpdate:C,onFocus:d,editable:!c,slotBefore:jsx(Fw,{toolbarActive:m,toolbarLeftSection:i,toolbarRightSection:s,toolbarOptions:l}),editorProps:{editable:()=>!c,attributes:{id:t||"",class:`${v.bespokeEditor}${c?" disabled":""}`}},...p,children:u&&jsx(zw,{})})})}var mm=createContext({mode:"simple",changeEditorMode:()=>{},reference:{locale:void 0,content:{},activate:()=>{},deactivate:()=>{},setActive:()=>{},active:false}});function Hw(e){let[t,o]=useState(false),[n,r]=useState({}),i=$a$1();return useEffect(()=>{if(!t){r(void 0);return}Gh.get(`/api/cms/read/block?&id=${e}&include=true`).then(({data:s})=>{r(s.data[0].contentByLocale[i].content.simple);}).catch(()=>r(void 0));},[t,e,i]),{content:n,locale:i,activate:()=>o(true),deactivate:()=>o(false),setActive:o}}function gm({children:e,buttons:t,blockType:o,blockId:n}){let[r,i]=useState(()=>[z.VIZ,z.GENERATOR,z.SECTION_FLAG].includes(o)?"code":"simple"),s=Hw(n),l={mode:r,changeEditorMode:i,reference:s,...t};return jsx(mm.Provider,{value:l,children:e})}function lo(){return useContext(mm)}function i0({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(ym,{content:t})]})}function ym({content:e}){return jsx(CopyButton,{value:e,timeout:2e3,children:({copied:t,copy:o})=>jsx(Tooltip,{label:t?"Copied":"Copy",withArrow:true,position:"right",children:jsx(ActionIcon,{size:"xs",color:t?"teal":"gray",variant:"subtle",onClick:()=>{o();let n=new Blob([e],{type:"text/html"}),r=new ClipboardItem({"text/html":n});navigator.clipboard.write([r]);},children:t?jsx(IconCheck,{style:{width:rem(16)}}):jsx(IconCopy,{style:{width:rem(16)}})})})})}function a0({referenceLocale:e,referenceContent:t}){return jsx(Stack,{spacing:"xs",children:jsx(Fa,{value:t,toolbarLeftSection:jsx(Text,{size:"0.625rem",tt:"uppercase",fw:700,color:"gray",children:"Reference Content"}),toolbarRightSection:jsx(i0,{locale:e,content:t}),toolbarOptions:{history:false,format:false,alignment:false},disabled:true})})}function wt({field:e,handleEditor:t,value:o,referenceContent:n,referenceLocale:r,variables:i,editorConfig:s={}}){return jsxs(Stack,{spacing:0,children:[jsx(Fa,{id:e,onChange:l=>{t(e,p$1(l));},toolbarLeftSection:jsx(Text,{component:"label",htmlFor:e,size:"xs",transform:"uppercase",weight:"bold",color:"gray",mb:"xs",children:titleCase(e)}),toolbarRightSection:jsx(ym,{content:o}),toolbarOptions:{history:true,alignment:e!=="tooltip",format:true},value:o,variables:i,placeholder:`This looks empty. Start adding content for the ${e}! You can add automated {{variables}}`,...s}),n&&jsx(Box,{mt:"xs",children:jsx(a0,{referenceContent:n[e],referenceLocale:r})})]})}function s0({fields:e,locale:t,defaultContent:o,onChange:n,variables:r}){let[i,s]=useState(()=>ya(o)),{reference:l}=lo();useEffect(()=>{n(i,t);},[]);let a=(c,p)=>{s(f=>({...f,[c]:p}));},[u]=useDebouncedValue(i,500);return useEffect(()=>{let c=Object.keys(u).reduce((f,m)=>({...f,[m]:p$1(u[m])}),{}),p=ro(c);n({simple:c,logic:p},t);},[u,t]),jsx(Stack,{spacing:"xl",children:e.map(({field:c,editorConfig:p})=>jsx(wt,{field:c,handleEditor:a,value:i[c]||"",referenceContent:l.content,referenceLocale:l.locale,variables:r,editorConfig:p},c))})}var vm=s0;function f0({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 Ke=f0;var hn={SINGLE:"single",MULTI:"multi"},nc={SEGMENTED_CONTROL:"segmented control",SELECTOR:"selector"},Fo={STATIC:"static",DYNAMIC:"dynamic"},rc=e=>e&&Array.isArray(e)&&e.length>0,$a=e=>rc(e)&&["string"].includes(typeof e[0]),xm=e=>{let{name:t,type:o,optionsType:n,options:r}=e;return [t,o,n,r].every(Boolean)?n===Fo.STATIC?r.static?.length>0&&r.static?.every(i=>i.id):r.dynamic?.isPrimitiveType?true:!!r.dynamic?.idKey:false},Ga=(e,t,o)=>{let n,r;switch(o){case Fo.STATIC:n=e===hn.SINGLE?t.static.find(i=>i.isDefault)?.id:t.static.filter(i=>i.isDefault).map(i=>i.id),r=t.static.map(({id:i,label:s})=>({id:i,label:s||i}));break;case Fo.DYNAMIC:if(t.dynamic){let{optionsVar:i,idKey:s,labelKey:l,imageKey:a,defaultVar:u,isPrimitiveType:c}=t.dynamic;u&&(n=`variables["${u}"]`),r=c?`variables["${i}"]`:`(variables["${i}"] || []).map(d => ({id: String(d["${s}"]), label: String(d["${l||s}"]), imageUrl: String(d["${a||null}"])}))`;}break;}return {logicOptions:r,defaultValue:n}};function S0({option:e,editOption:t,deleteOption:o}){return jsxs("tr",{className:"reports-selector-static-option",children:[jsx("td",{children:jsx(Checkbox,{checked:e.isDefault,onChange:n=>t({isDefault:n.currentTarget.checked})})}),jsx("td",{children:jsx(TextInput,{placeholder:"Option value",value:e.id,onChange:n=>{t({id:n.currentTarget.value});},error:e.id.indexOf(" ")>-1?"Please, avoid the usage of spaces in the ID":false})}),jsx("td",{children:jsx(TextInput,{placeholder:"Option label",value:e.label,onChange:n=>t({label:n.currentTarget.value})})}),jsx("td",{children:jsx(ActionIcon,{onClick:o,children:jsx(IconTrash,{})})})]})}function x0({staticOptions:e,setStaticOptions:t}){let o=useCallback(()=>t([...e,{isDefault:!e.length,id:"",label:""}]),[e,t]),n=useCallback((i,s)=>{if(!s||i>=e.length||i<0)return;let l=[...e];l.splice(i,1,{...e[i],...s}),t(l);},[e,t]),r=useCallback(i=>{let s=[...e];s.splice(i,1),t(s);},[e,t]);return jsxs(Fragment,{children:[jsx(Input.Wrapper,{required:true,label:"Static Selector Options",children:jsxs("table",{children:[jsx("thead",{children:e.length>0&&jsx("tr",{children:["Default","ID","Label",""].map((i,s)=>jsx("td",{className:`${s===0?"selector-option-default-col":""} ${s===1?"required":""}`,children:i},`heading-${s}`))})}),jsx("tbody",{children:e.map((i,s)=>jsx(S0,{option:i,editOption:l=>n(s,l),deleteOption:()=>r(s)},`option-${s}`))})]})}),jsx(ActionIcon,{onClick:o,children:jsx(IconPlus,{})})]})}function C0({id:e,dynamicOptions:t,setDynamicOptions:o}){let{optionsVar:n,idKey:r,labelKey:i,defaultVar:s,imageKey:l,isPrimitiveType:a}=t,u=La$1(e),[c,p]=useState(false),[f,m]=useState({}),[g,S]=useState([]),[v,h]=useState([]);useEffect(()=>{u||(m({}),S([]));let k=Object.entries(u).filter(([,B])=>rc(B)).reduce((B,[N,$])=>(B[N]=$,B),{});m(k);let R=Object.keys(u);S(R),p(true);},[u]);let b=useCallback((k,R)=>{o({...t,[k]:R});},[t]);useEffect(()=>{if(!Object.keys(f).length)return;let k=$a(f[n]);if(k)h([]),b("idKey",null),b("labelKey",null),b("imageKey",null);else {let R=new Set;(f[t.optionsVar]||[]).forEach(N=>Object.keys(typeof N=="object"?N:{}).forEach($=>R.add($)));let B=Array.from(R).sort().map(N=>N);h(B);}b("isPrimitiveType",k);},[f,n]);let C=useCallback(k=>{o({...t,optionsVar:k,idKey:null,labelKey:null,imageKey:null});},[t,o]),d=useMemo(()=>{let k=[];return f&&n&&r&&Array.isArray(f[n])&&(k=f[n].filter(R=>`${R[r]}`.indexOf(" ")>0)),k.length>0?`One or more ID's have spaces on it. (
31
+ `,"2) content: () => element.cloneNode(true)"].join(" "));}var l=r.reduce(function(s,u){var c=u&&JT(u,n);return c&&s.push(c),s},[]);return ti(e)?l[0]:l}ni.defaultProps=wt;ni.setDefaultProps=KT;ni.currentInput=so;Object.assign({},Kr,{effect:function(t){var o=t.state,n={popper:{position:o.options.strategy,left:"0",top:"0",margin:"0"},arrow:{position:"absolute"},reference:{}};Object.assign(o.elements.popper.style,n.popper),o.styles=n,o.elements.arrow&&Object.assign(o.elements.arrow.style,n.arrow);}});ni.setDefaultProps({render:lf});var cf=ni;var lw=forwardRef(function(t,o){let n=useMantineTheme(),[r,i]=useState(0),a=c=>{let p=t.items[c];p&&t.command({id:p});},l=()=>{i((r+t.items.length-1)%t.items.length);},s=()=>{i((r+1)%t.items.length);},u=()=>{a(r);};return useEffect(()=>i(0),[t.items]),useImperativeHandle(o,()=>({onKeyDown:({event:c})=>c.key==="ArrowUp"?(l(),true):c.key==="ArrowDown"?(s(),true):c.key==="Enter"||c.key==="Tab"?(u(),true):false})),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===r?"is-selected":""}`,sx:m=>({backgroundColor:p===r?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:n.colors.blue[6]},children:jsx(IconBraces,{size:"0.8rem",color:"white"})}),jsx(Text,{ff:"monospace",component:"code",color:"gray.7",children:`${c}`})]})})},p)):null})}),pf=lw;var pw=()=>({char:"{{",allowedPrefixes:[" "],items:({query:e,editor:t})=>t.storage.VariablesStorage.suggestions.filter(o=>o.toLowerCase().startsWith(e.toLowerCase())).slice(0,5),render:()=>{let e,t;return {onStart:o=>{e=new ReactRenderer(pf,{props:o,editor:o.editor}),o.clientRect&&(t=cf("body",{getReferenceClientRect:o.clientRect,appendTo:()=>document.body,content:e.element,showOnCreate:true,interactive:true,trigger:"manual",placement:"bottom-start"}));},onUpdate(o){e.updateProps(o),o.clientRect&&t[0].setProps({getReferenceClientRect:o.clientRect});},onKeyDown(o){return o.event.key==="Escape"?(t[0].hide(),true):e.ref?.onKeyDown(o)},onExit(){t[0].destroy(),e.destroy();}}}}),df=pw;function Jl(e){return e.replace(/<code[^>]*>([^<>]*)<\/code>/g,"$1")}function Ql(e){return e.replace(/({{.*?}})/g,'<code class="bespoke-var">$1</code>')}var Bw=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"}}})),ff=()=>{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:true,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:true,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:true,children:jsx(IconUnderline,{size:"0.8rem",stroke:e.isActive("underline")?4:2,color:t.colors.gray[7]})})]}):null},zw=()=>{let{editor:e}=useCurrentEditor();return jsx("div",{children:jsx(BubbleMenu,{tippyOptions:{placement:"bottom"},editor:e,children:jsx(ff,{})})})},Nw=()=>{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:true,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:true,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:true,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:true,children:jsx(IconAlignJustified,{size:"0.8rem",stroke:e.isActive({textAlign:"justify"})?4:2,color:t.colors.gray[7]})})]}):null},Vw=()=>{let{editor:e}=useCurrentEditor(),t=useMantineTheme();return e?jsxs(Button.Group,{children:[jsx(Button,{onClick:()=>e.commands.undo(),size:"xs",variant:"default",compact:true,children:jsx(IconArrowBackUp,{size:"0.8rem",color:t.colors.gray[7]})}),jsx(Button,{onClick:()=>e.commands.redo(),size:"xs",variant:"default",compact:true,children:jsx(IconArrowForwardUp,{size:"0.8rem",color:t.colors.gray[7]})})]}):null},Fw=({toolbarActive:e=true,toolbarLeftSection:t=null,toolbarRightSection:o=null,toolbarOptions:n={}})=>{let r=n.history??true,i=n.alignment??false,a=n.format??true;return jsxs(Group,{mb:"0.25rem",position:"apart",children:[t,e&&jsxs(Group,{children:[r&&jsx(Vw,{}),i&&jsx(Nw,{}),a&&jsx(ff,{})]}),o]})};function Fa(e){let{id:t,value:o,onChange:n=()=>{},variables:r,toolbarLeftSection:i,toolbarRightSection:a,toolbarOptions:l={},tipTapExtensions:s=[],bubbleMenu:u=true,disabled:c=false,editorProps:p,placeholder:m="This looks empty! Start writing some content"}=e,[f,g]=useState(false),S=useClickOutside(()=>g(false)),{classes:v}=Bw(),h=JSON.stringify(r||{}),b=useMemo(()=>{let y=JSON.parse(h),x=[yw.configure({heading:false,bold:false,history:{depth:20},code:false,hardBreak:false,codeBlock:false}),ym.extend({spanning:true}),Sw.extend({addKeyboardShortcuts(){return {Enter:()=>this.editor.commands.setHardBreak()}}}),xw.configure({types:["paragraph"]}),bw,vm,Cw.configure({placeholder:m}),Lw,...s];return y&&(x.push(Sm),x.push(vw.configure({HTMLAttributes:{type:null},renderText({node:k}){return `{{${k.attrs.label??k.attrs.id}}}`},renderHTML({node:k}){return ["code",{},`{{${k.attrs.label??k.attrs.id}}}`]},suggestion:df()}))),x},[h,s,m]),C=({editor:y})=>{let x=Jl(y.getHTML());n(x);},d=({editor:y})=>{let x=JSON.parse(h);y.storage.VariablesStorage.suggestions=Object.keys(x);};return jsx(Box,{ref:S,className:"bespoke-editor",onClickCapture:()=>g(true),children:jsx(EditorProvider,{extensions:b,content:o?Ql(o):void 0,onUpdate:C,onFocus:d,editable:!c,slotBefore:jsx(Fw,{toolbarActive:f,toolbarLeftSection:i,toolbarRightSection:a,toolbarOptions:l}),editorProps:{editable:()=>!c,attributes:{id:t||"",class:`${v.bespokeEditor}${c?" disabled":""}`}},...p,children:u&&jsx(zw,{})})})}var gf=createContext({mode:"simple",changeEditorMode:()=>{},reference:{locale:void 0,content:{},activate:()=>{},deactivate:()=>{},setActive:()=>{},active:false}});function Hw(e){let[t,o]=useState(false),[n,r]=useState({}),i=$a$1();return useEffect(()=>{if(!t){r(void 0);return}Gh.get(`/api/cms/read/block?&id=${e}&include=true`).then(({data:a})=>{r(a.data[0].contentByLocale[i].content.simple);}).catch(()=>r(void 0));},[t,e,i]),{content:n,locale:i,activate:()=>o(true),deactivate:()=>o(false),setActive:o}}function hf({children:e,buttons:t,blockType:o,blockId:n}){let[r,i]=useState(()=>[z.VIZ,z.GENERATOR,z.SECTION_FLAG].includes(o)?"code":"simple"),a=Hw(n),l={mode:r,changeEditorMode:i,reference:a,...t};return jsx(gf.Provider,{value:l,children:e})}function lo(){return useContext(gf)}function i0({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(vf,{content:t})]})}function vf({content:e}){return jsx(CopyButton,{value:e,timeout:2e3,children:({copied:t,copy:o})=>jsx(Tooltip,{label:t?"Copied":"Copy",withArrow:true,position:"right",children:jsx(ActionIcon,{size:"xs",color:t?"teal":"gray",variant:"subtle",onClick:()=>{o();let n=new Blob([e],{type:"text/html"}),r=new ClipboardItem({"text/html":n});navigator.clipboard.write([r]);},children:t?jsx(IconCheck,{style:{width:rem(16)}}):jsx(IconCopy,{style:{width:rem(16)}})})})})}function a0({referenceLocale:e,referenceContent:t}){return jsx(Stack,{spacing:"xs",children:jsx(Fa,{value:t,toolbarLeftSection:jsx(Text,{size:"0.625rem",tt:"uppercase",fw:700,color:"gray",children:"Reference Content"}),toolbarRightSection:jsx(i0,{locale:e,content:t}),toolbarOptions:{history:false,format:false,alignment:false},disabled:true})})}function Et({field:e,handleEditor:t,value:o,referenceContent:n,referenceLocale:r,variables:i,editorConfig:a={}}){return jsxs(Stack,{spacing:0,children:[jsx(Fa,{id:e,onChange:l=>{t(e,p$1(l));},toolbarLeftSection:jsx(Text,{component:"label",htmlFor:e,size:"xs",transform:"uppercase",weight:"bold",color:"gray",mb:"xs",children:titleCase(e)}),toolbarRightSection:jsx(vf,{content:o}),toolbarOptions:{history:true,alignment:e!=="tooltip",format:true},value:o,variables:i,placeholder:`This looks empty. Start adding content for the ${e}! You can add automated {{variables}}`,...a}),n&&jsx(Box,{mt:"xs",children:jsx(a0,{referenceContent:n[e],referenceLocale:r})})]})}function s0({fields:e,locale:t,defaultContent:o,onChange:n,variables:r}){let[i,a]=useState(()=>ya(o)),{reference:l}=lo();useEffect(()=>{n(i,t);},[]);let s=(c,p)=>{a(m=>({...m,[c]:p}));},[u]=useDebouncedValue(i,500);return useEffect(()=>{let c=Object.keys(u).reduce((m,f)=>({...m,[f]:p$1(u[f])}),{}),p=ro(c);n({simple:c,logic:p},t);},[u,t]),jsx(Stack,{spacing:"xl",children:e.map(({field:c,editorConfig:p})=>jsx(Et,{field:c,handleEditor:s,value:i[c]||"",referenceContent:l.content,referenceLocale:l.locale,variables:r,editorConfig:p},c))})}var Sf=s0;function m0({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 Ke=m0;var hn={SINGLE:"single",MULTI:"multi"},nc={SEGMENTED_CONTROL:"segmented control",SELECTOR:"selector"},Fo={STATIC:"static",DYNAMIC:"dynamic"},rc=e=>e&&Array.isArray(e)&&e.length>0,$a=e=>rc(e)&&["string"].includes(typeof e[0]),Cf=e=>{let{name:t,type:o,optionsType:n,options:r}=e;return [t,o,n,r].every(Boolean)?n===Fo.STATIC?r.static?.length>0&&r.static?.every(i=>i.id):r.dynamic?.isPrimitiveType?true:!!r.dynamic?.idKey:false},Ga=(e,t,o)=>{let n,r;switch(o){case Fo.STATIC:n=e===hn.SINGLE?t.static.find(i=>i.isDefault)?.id:t.static.filter(i=>i.isDefault).map(i=>i.id),r=t.static.map(({id:i,label:a})=>({id:i,label:a||i}));break;case Fo.DYNAMIC:if(t.dynamic){let{optionsVar:i,idKey:a,labelKey:l,imageKey:s,defaultVar:u,isPrimitiveType:c}=t.dynamic;u&&(n=`variables["${u}"]`),r=c?`variables["${i}"]`:`(variables["${i}"] || []).map(d => ({id: String(d["${a}"]), label: String(d["${l||a}"]), imageUrl: String(d["${s||null}"])}))`;}break;}return {logicOptions:r,defaultValue:n}};function S0({option:e,editOption:t,deleteOption:o}){return jsxs("tr",{className:"reports-selector-static-option",children:[jsx("td",{children:jsx(Checkbox,{checked:e.isDefault,onChange:n=>t({isDefault:n.currentTarget.checked})})}),jsx("td",{children:jsx(TextInput,{placeholder:"Option value",value:e.id,onChange:n=>{t({id:n.currentTarget.value});},error:e.id.indexOf(" ")>-1?"Please, avoid the usage of spaces in the ID":false})}),jsx("td",{children:jsx(TextInput,{placeholder:"Option label",value:e.label,onChange:n=>t({label:n.currentTarget.value})})}),jsx("td",{children:jsx(ActionIcon,{onClick:o,children:jsx(IconTrash,{})})})]})}function x0({staticOptions:e,setStaticOptions:t}){let o=useCallback(()=>t([...e,{isDefault:!e.length,id:"",label:""}]),[e,t]),n=useCallback((i,a)=>{if(!a||i>=e.length||i<0)return;let l=[...e];l.splice(i,1,{...e[i],...a}),t(l);},[e,t]),r=useCallback(i=>{let a=[...e];a.splice(i,1),t(a);},[e,t]);return jsxs(Fragment,{children:[jsx(Input.Wrapper,{required:true,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(S0,{option:i,editOption:l=>n(a,l),deleteOption:()=>r(a)},`option-${a}`))})]})}),jsx(ActionIcon,{onClick:o,children:jsx(IconPlus,{})})]})}function C0({id:e,dynamicOptions:t,setDynamicOptions:o}){let{optionsVar:n,idKey:r,labelKey:i,defaultVar:a,imageKey:l,isPrimitiveType:s}=t,u=La$1(e),[c,p]=useState(false),[m,f]=useState({}),[g,S]=useState([]),[v,h]=useState([]);useEffect(()=>{u||(f({}),S([]));let k=Object.entries(u).filter(([,B])=>rc(B)).reduce((B,[N,$])=>(B[N]=$,B),{});f(k);let R=Object.keys(u);S(R),p(true);},[u]);let b=useCallback((k,R)=>{o({...t,[k]:R});},[t]);useEffect(()=>{if(!Object.keys(m).length)return;let k=$a(m[n]);if(k)h([]),b("idKey",null),b("labelKey",null),b("imageKey",null);else {let R=new Set;(m[t.optionsVar]||[]).forEach(N=>Object.keys(typeof N=="object"?N:{}).forEach($=>R.add($)));let B=Array.from(R).sort().map(N=>N);h(B);}b("isPrimitiveType",k);},[m,n]);let C=useCallback(k=>{o({...t,optionsVar:k,idKey:null,labelKey:null,imageKey:null});},[t,o]),d=useMemo(()=>{let k=[];return m&&n&&r&&Array.isArray(m[n])&&(k=m[n].filter(R=>`${R[r]}`.indexOf(" ")>0)),k.length>0?`One or more ID's have spaces on it. (
32
32
  ${k.map(R=>`"${R[r]}"`).join(",")}
33
- ) Avoid this, please.`:false},[f,n,r]);if(!c)return null;let y=Object.keys(f),x=k=>k&&Array.isArray(k)&&k.length;return jsxs(Fragment,{children:[jsx(Select,{label:"Options List Variable",placeholder:"Pick a variable",value:x(y)&&n,required:true,onChange:C,data:y}),jsx(Select,{label:"Options ID Key",placeholder:"Pick a property key",value:x(v)&&r,required:!a,disabled:a,onChange:k=>b("idKey",k),data:v,error:d}),jsx(Select,{label:"Options Label Key",placeholder:"Pick a property key",disabled:a,clearable:true,value:x(v)&&i,onChange:k=>b("labelKey",k),data:v}),jsx(Select,{label:"Options Image Key",placeholder:"Pick a property key",disabled:a,clearable:true,value:x(v)&&l,onChange:k=>b("imageKey",k),data:v}),jsx(Select,{label:"Default ID Variable",placeholder:"Pick a variable",clearable:true,value:x(g)&&s,onChange:k=>b("defaultVar",k),data:g})]})}function or(e,t,o){return e&&e[t]||o}function k0(e){let{id:t,executeButton:o,onChange:n,simpleState:r,referenceContent:i,referenceLocale:s,variables:l}=e,[a,u]=useState(()=>{let f=r&&r.options&&Object.prototype.hasOwnProperty.call(r?.options,"dynamic")&&Object.prototype.hasOwnProperty.call(r?.options,"static");return {selectorIdentifier:or(r,"name",""),selectorType:or(r,"type",hn.SINGLE),selectorComponent:or(r,"component",nc.SELECTOR),options:r&&f?r.options:{static:[],dynamic:{}},optionsType:or(r,"optionsType","static"),hideLabel:or(r,"hideLabel","false"),resetSectionVars:or(r,"resetSectionVars","false")}});useEffect(()=>{let{selectorIdentifier:f,selectorType:m,selectorComponent:g,options:S,optionsType:v,hideLabel:h,resetSectionVars:b}=a,C={name:f,hideLabel:h,resetSectionVars:b,component:g,type:m},{logicOptions:d,defaultValue:y}=Ga(m,S,v);y&&(C.defaultValue=y),C.options=d;let x=`return ${Wn(C)};`,k={name:f,type:m,component:g,hideLabel:h,resetSectionVars:b,defaultValue:y,optionsType:v,options:S},R=xm(k);n(k,x,R);},[a]);let c=(f,m)=>u(g=>({...g,[f]:m})),p=B[z.SELECTOR].find(f=>f.field===A.SELECTOR_NAME)?.editorConfig;return jsxs(Fragment,{children:[jsxs(Stack,{children:[jsx(wt,{field:"name",value:a.selectorIdentifier,handleEditor:(f,m)=>c("selectorIdentifier",m),referenceContent:i,referenceLocale:s,variables:l,editorConfig:p}),jsx(Checkbox,{label:jsx(Ke,{label:"Hide Label",py:0}),checked:a.hideLabel==="true",onChange:f=>c("hideLabel",f.currentTarget.checked?"true":"false")})]}),jsx(Select,{label:jsx(Ke,{label:"Selector Type"}),value:a.selectorType,onChange:f=>c("selectorType",f),data:Object.values(hn)}),a.selectorType===hn.SINGLE&&jsx(Select,{label:jsx(Ke,{label:"Selector Component"}),value:a.selectorComponent,onChange:f=>c("selectorComponent",f),data:Object.values(nc)}),jsx(Select,{label:jsx(Ke,{label:"Options Type"}),value:a.optionsType,onChange:f=>c("optionsType",f),data:Object.values(Fo)}),a.optionsType===Fo.STATIC?jsx(x0,{staticOptions:a.options.static,setStaticOptions:f=>c("options",{...a.options,static:f})}):jsx(C0,{dynamicOptions:a.options.dynamic,setDynamicOptions:f=>c("options",{...a.options,dynamic:f}),id:t}),jsx(Checkbox,{my:"md",label:jsx(Ke,{label:"Reset SectionVariables on change",py:0}),checked:a.resetSectionVars==="true",onChange:f=>c("resetSectionVars",f.currentTarget.checked?"true":"false")}),o]})}var Tm=k0;var Em=["xs","sm","md","lg","xl"],z0=["0","1","2","3","4","5"],wo={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"}},N0=forwardRef(({value:e,iconType:t="tabler",...o},n)=>jsx("div",{ref:n,...o,children:jsxs(Group,{noWrap:true,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 bn(e){let[t,o]=useState(e?._iconType??"none"),[n,r]=useState(e?._icon??""),[i,s]=useState([]),[l,a]=useState(""),[u,c]=useState(e?._iconVariant??"transparent"),[p,f]=useState(e?._iconSize??"md"),[m,g]=useState(e?._iconRadius??"md"),[S,v]=useState(e?._iconPadding??"1"),h=[wo.none.value,wo.custom.value].includes(t),b=useRef(null),C=useMemo(()=>({_icon:n,_iconType:t,_defaultIcon:l,_iconVariant:u,_iconSize:p,_iconRadius:m,_iconPadding:S}),[n,t,l,u,p,m,S]),d=x=>{r(""),o(x);};useEffect(()=>{h||Gh.get(`/api/cms/list/icons/${t}`).then(x=>{s(x.data.data.results),a(x.data.data.results[0]);});},[t]);let y=jsx(Accordion,{variant:"separated",children:jsxs(Accordion.Item,{value:"icon",children:[jsx(Accordion.Control,{icon:jsx(IconPhotoFilled,{}),children:jsxs(Text,{children:["Icon configuration: ",wo[t]&&jsx("strong",{children:wo[t].label})]})}),jsx(Accordion.Panel,{children:jsxs(Stack,{children:[jsx(Input.Wrapper,{label:"Title's icon",children:jsx(SegmentedControl,{fullWidth:true,value:t,onChange:d,data:Object.values(wo)})}),!h&&jsx(Select,{label:"Choose an icon from the list",searchable:true,description:jsxs(Fragment,{children:["Powered by"," ",jsx("a",{style:{textDecoration:"underline"},href:wo[t].link,target:"_blank",rel:"noreferrer",children:wo[t].text}),"."]}),defaultValue:l,value:n,required:true,onChange:x=>r(x||""),data:i,limit:10,itemComponent:N0,disabled:!i||i.length===0,icon:jsx(Image,{p:5,src:`/api/cms/read/icons/${t}/icon.svg?name=${n||l}`,alt:"Icon preview"})}),t===wo.custom.value&&jsxs(Flex,{align:"flex-end",children:[jsx(TextInput,{ref:b,placeholder:"e.g '/image{{id1}}.png' or 'http://site/image.png'",label:"Enter an icon path",required:true,defaultValue:n,description:"Add an absolute or a relative path url",onBlur:x=>r(x.currentTarget.value),sx:{flexGrow:1}}),jsx(ActionIcon,{maw:36,size:36,onClick:()=>b.current?r(b.current.value??""):void 0,sx:{flexGrow:0},children:jsx(IconFileUpload,{})})]}),t!==wo.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:true,onChange:x=>c(x||"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:true,value:p,onChange:f,data:Em})}),jsx(Input.Wrapper,{label:"Radius",children:jsx(SegmentedControl,{fullWidth:true,value:m,onChange:g,data:Em})}),jsx(Input.Wrapper,{label:"Padding",children:jsx(SegmentedControl,{fullWidth:true,value:S,onChange:v,data:z0})})]})]})})]})});return {simpleIconState:C,panel:y}}function Uo(e,t){let[o,n]=useState({...t,...e});return {state:o,updateState:(i,s)=>{let l={...o,[i]:s};n(l);}}}var U0={type:"list",title:"",shotTitle:""},H0=[{value:"list",label:"List"},{value:"multilevel",label:"Multilevel"}];function uc({simpleState:e,onChange:t,variables:o,referenceContent:n,referenceLocale:r}){let{state:i,updateState:s}=Uo(e,U0),{simpleIconState:l,panel:a}=bn(e);return useEffect(()=>{let u={...i,...l},c=ro(u);t(u,c);},[i,l]),jsxs(Stack,{children:[jsx(Title,{order:4,children:"Nav UI"}),jsx(Select,{label:"Nav Type",data:H0,value:i.type,defaultValue:"list",onChange:u=>s("type",u)}),B[z.NAV].map(({field:u,editorConfig:c})=>jsx(wt,{field:u,value:i[u],handleEditor:s,referenceContent:n,referenceLocale:r,variables:o,editorConfig:c},u)),a]})}function pc({executeButton:e,onChange:t,simpleState:o}){let[n,r]=useState(o?.compare??"variant"),[i,s]=useState(o?.limit??4);return useEffect(()=>{t({compare:n,limit:i});},[n,i]),jsxs(Stack,{children:[jsx(Radio.Group,{description:"Valid only for single-dimensional profiles",label:"Compare with members of:",onChange:r,value:n,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:l=>s(l),type:"number",value:i}),e]})}function fc({executeButton:e,onChange:t,simpleState:o}){let[n,r]=useState(o?.label??""),[i,s]=useState(o?.showIcon??true),[l,a]=useState(o?.fullWidth??false),[u,c]=useState(o?.showWhenDisabled??false);return useEffect(()=>{t({label:n,showIcon:i,fullWidth:l,showWhenDisabled:u});},[n,i,l,u,t]),jsxs(Stack,{children:[jsx(TextInput,{placeholder:"Label for reset section state button",value:n,onChange:p=>r(p.target.value),label:"Label"}),jsxs(Group,{children:[jsx(Switch,{checked:i,label:"Show icon",onChange:p=>s(p.currentTarget.checked)}),jsx(Switch,{checked:l,label:"Full width",onChange:p=>a(p.currentTarget.checked)}),jsx(Switch,{checked:u,label:"Show when disabled",onChange:p=>c(p.currentTarget.checked)})]}),e]})}var oE={title:"Title",tooltip:"",slug:""};function mc({onChange:e,simpleState:t,variables:o,referenceContent:n,referenceLocale:r}){let{state:i,updateState:s}=Uo(t,oE),{simpleIconState:l,panel:a}=bn(t);return useEffect(()=>{let u={...i,...l},c=ro(u);e(u,c);},[l,i]),jsxs(Stack,{children:[B[z.TITLE].map(({field:u,editorConfig:c})=>jsx(wt,{field:u,value:i[u],handleEditor:s,referenceContent:n,referenceLocale:r,variables:o,editorConfig:c},u)),a]})}var uE=[{value:"left",label:"Left"},{value:"center",label:"Center"},{value:"right",label:"Right"}];function gc({executeButton:e,onChange:t,simpleState:o}){let[n,r]=useState(o?.label??""),[i,s]=useState(o?.removeLabel??""),[l,a]=useState(o?.showIcon??true),[u,c]=useState(o?.position??"center");return useEffect(()=>{t({label:n,removeLabel:i,showIcon:l,position:u});},[n,l,i,u,t]),jsxs(Stack,{children:[jsx(TextInput,{placeholder:"Label for comparison button",value:n,onChange:p=>r(p.target.value),label:"Label"}),jsx(TextInput,{placeholder:"Label for remove comparison button",value:i,onChange:p=>s(p.target.value),label:"Remove Label"}),jsx(Group,{children:jsx(Switch,{checked:l,label:"Show icon",onChange:p=>a(p.currentTarget.checked)})}),jsx(Select,{label:"Button position",data:uE,value:u,onChange:c}),e]})}function hc({simpleState:e,onChange:t,variables:o,referenceContent:n,referenceLocale:r}){let{state:i,updateState:s}=Uo(e,{title:"",value:"",subtitle:"",tooltip:""}),{simpleIconState:l,panel:a}=bn(e);return useEffect(()=>{let u={...i,...l},c=ro(u);t(u,c);},[l,i]),jsxs(Stack,{children:[B[z.STAT].map(({field:u,editorConfig:c})=>jsx(wt,{field:u,value:i[u],handleEditor:s,referenceContent:n,referenceLocale:r,variables:o,editorConfig:c},u)),a]})}var DE={enableBottomToolbar:true,enableColumnActions:true,enableColumnFilters:true,enableColumnResizing:true,enableDensityToggle:true,enableFullScreenToggle:false,enableGlobalFilter:true,enableHiding:true,enablePagination:true,enableSorting:true,enableStickyHeader:true,enableTopToolbar:true},zm={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."}},LE={density:"xs"},Nm=["5","10","15","20","25","30","50","100"],Vm={pageIndex:0,pageSize:10},Fm=e=>e&&Array.isArray(e)&&e.some(t=>typeof t=="object"&&t!==null),BE=forwardRef(function({customLabels:t,customLabelsHandler:o,index:n,isActiveRefenceContent:r=false,option:i,referenceColumns:s=[],selectedColumnsHandler:l,...a},u){let c=t.find(m=>m.key===i.label)?.label||"",f=s.find(m=>m.accessorKey===i.label)?.header||i.label;return jsxs(Group,{grow:true,ref:u,...a,children:[jsxs(Group,{children:[jsx(IconGripVertical,{}),jsx(Checkbox,{checked:i.checked,label:i.label,onChange:m=>l.setItemProp(n,"checked",m.currentTarget.checked)})]}),jsx(Input,{disabled:!i.checked,onChange:m=>o.setItemProp(n,"label",m.currentTarget.value),value:c}),r&&jsx(Input,{disabled:true,value:f})]},`table-group-${i.label}-${n}`)});function Cc(e){let{executeButton:t,id:o,onChange:n,referenceContent:r={},referenceLocale:i,simpleState:s}=e,{columns:l}=r,a=_a(),u=useMemo(()=>a!==i&&r&&Object.keys(r).length>0,[a,r,i]),c=La$1(o),[p,f]=useState([]),[m,g]=useListState([]),[S,v]=useState([]),[h,b]=useState(false),[C,d]=useState({}),[y,x]=useState(Vm),[k,R]=useState({rowsPerPageOptions:Nm}),[B,N]=useListState([]),[$,K]=useState(null),[T,M]=useSetState(DE),[I,O]=useState(LE),[G,W]=useState({}),F=useMemo(()=>B.every(A=>A.checked),[B]),L=useMemo(()=>B.some(A=>A.checked)&&!F,[F,B]);useEffect(()=>{if(!s||!Object.keys(s).length)return;let A=c[s.variable]||[],_=new Set;A.filter(z=>typeof z=="object"&&z!==null).forEach(z=>{Object.keys(z).forEach(X=>_.add(X));});let Q={},Y=[];s.columns&&Object.keys(s.columns)&&s.columns.forEach(z=>{Q[z.accessorKey]=z.header;});let ce=[],re=[];Array.from(_).forEach(z=>{re.push({key:z,label:Q[z]||z}),ce.push({checked:!!Q[z],key:randomId(),label:z}),Y.push(z);}),g.setState(re),N.setState(ce);let{initialState:ae={},state:me={},mantinePaginationProps:gt={},...kt}=s.tableProps||{},Rt=me.columnOrder.filter(z=>Y.includes(z));Rt.push(Y.filter(z=>!me.columnOrder.includes(z))),f(Rt.flat()||[]),R(gt),x(ae.pagination),M({...kt}),W(me),O(ae),K(s.variable||"");},[]),useEffect(()=>{if(!c){d({});return}let A=Object.entries(c).filter(([Q,Y])=>Fm(Y)).reduce((Q,[Y,ce])=>(Q[Y]=ce,Q),{});d(A);let _=Object.keys(A);v(_);},[c]);let U=A=>{if(K(A),!A||!Fm(C[A])){b(false),N.setState([]);return}let _=C[A];if(_.every(ae=>typeof ae=="object"&&ae===null)){b(false),N.setState([]);return}_.every(ae=>typeof ae=="object"&&ae!==null)?b(false):b(true);let Q=new Set;_.filter(ae=>typeof ae=="object"&&ae!==null).forEach(ae=>{Object.keys(ae).forEach(me=>Q.add(me));});let Y=[],ce=[],re=[];Array.from(Q).forEach(ae=>{Y.push({checked:true,key:randomId(),label:ae}),ce.push({key:ae,label:ae}),re.push(ae);}),N.setState(Y),g.setState(ce),f(re);};useEffect(()=>{let A={};m.forEach(me=>{A[me.key]=me.label;});let _=B.filter(me=>me.checked).map(me=>({accessorKey:me.label,header:A[me.label]})),Q={...I,pagination:y},Y={...G,columnOrder:p},ce={columns:_,data:$?`variables["${$}"]`:[],tableProps:{...T,initialState:Q,state:Y,mantinePaginationProps:k},variable:$||""},re=`return ${Wn(ce)};`,ae={columns:_,data:$?`variables["${$}"]`:[],tableProps:{...T,initialState:Q,state:Y,mantinePaginationProps:k},variable:$||""};n(ae,re);},[p,m,k,y,B,$,T,G,I]);let P=useCallback(A=>{if(!A.destination||A.source.index===A.destination.index)return;let _=[...p],[Q]=_.splice(A.source.index,1);_.splice(A.destination.index,0,Q),f(_),W(Y=>{let ce=Y;return ce.columnOrder=_,ce});},[p]);return jsxs(Fragment,{children:[jsxs(Stack,{mb:"sm",children:[jsx(Select,{clearable:true,data:S,description:"Select an array of data available in the block inputs to use as data input for the table.",label:"Data input",onChange:A=>U(A),searchable:true,value:$}),$&&C[$]&&B.length>0&&jsxs(Fragment,{children:[jsx(Input.Wrapper,{description:"Select the columns to display in the table.",error:h&&"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:true,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:F,indeterminate:L,label:"All",onChange:()=>N.setState(A=>A.map(_=>({..._,checked:!F})))}),jsx(ScrollArea.Autosize,{mah:300,children:jsx(DragDropContext,{onDragEnd:P,children:jsx(Droppable,{droppableId:"columns",children:A=>jsx("div",{ref:A.innerRef,...A.droppableProps,children:p.map((_,Q)=>{let Y=B.findIndex(re=>re.label===_),ce=B[Y];return jsx(Draggable,{draggableId:`${ce.label}`,index:Q,isDragDisabled:!ce.checked,children:re=>jsx(BE,{customLabels:m,customLabelsHandler:g,index:Y,isActiveRefenceContent:u,option:ce,ref:re.innerRef,referenceColumns:l,selectedColumnsHandler:N,...re.draggableProps,...re.dragHandleProps})},ce.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(T).map(A=>jsx(Checkbox,{checked:T[A],label:jsx(Tooltip,{label:zm[A]?.desc||A,multiline:true,children:jsx(Text,{children:zm[A]?.label||A})}),onChange:()=>M({[A]:!T[A]})},`table-prop-${A}`))}),T?.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:true,children:[jsx(NumberInput,{label:"Initial page",min:0,onChange:A=>{x(_=>({..._,pageIndex:A}));},value:y.pageIndex}),jsx(Select,{data:k.rowsPerPageOptions||[],getCreateLabel:A=>`+ Create ${A}`,label:"Initial page size",onChange:A=>{x(_=>({..._,pageSize:parseInt(A,10)}));},searchable:true,value:y.pageSize.toString()})]}),jsxs(Group,{align:"flex-end",grow:true,children:[jsx(MultiSelect,{clearable:true,creatable:true,data:k.rowsPerPageOptions||[],getCreateLabel:A=>`+ Create ${A}`,label:"Page size options",onChange:A=>{R(_=>({..._,rowsPerPageOptions:A.sort((Q,Y)=>parseInt(Q,10)-parseInt(Y,10))})),A&&A.length>0&&!A.includes(y.pageSize.toString())&&x(_=>({..._,pageSize:parseInt(A[0],10)}));},onCreate:A=>(R(_=>({..._,rowsPerPageOptions:[..._.rowsPerPageOptions||[],A].sort((Q,Y)=>parseInt(Q,10)-parseInt(Y,10))})),A),searchable:true,value:k.rowsPerPageOptions||[]}),jsx(Button,{color:"yellow",onClick:()=>{R(A=>({...A,rowsPerPageOptions:Nm})),x(Vm);},children:"Reset page sizes values"})]})]})]})]})})})]})})]})]}),t]})}var _m=e=>{let{dataVar:t,levelsVar:o}=e;return !![t,o].every(Boolean)},Qa=e=>{let t,o,{colorKey:n,dataVar:r,iconKey:i,defaultVar:s,isPrimitiveType:l,levelsVar:a,searchIndexKey:u}=e;s&&typeof s=="string"&&(t=`variables["${s}"].value`,o=`variables["${s}"].type`);let c=l?`variables["${r}"]`:`(variables["${r}"] || []).map((d) => ({...d, colorKey: String(d["${n}"]), iconKey: String(d["${i}"]), searchIndexKey: String(d["${u}"])}))`;return {logicLevels:`variables["${a}"]`,logicOptions:c,defaultValue:t,defaultValueType:o}};var Tc=e=>B[z.MULTIHIERARCHY_SELECTOR].find(t=>t.field===e)?.editorConfig,VE=e=>e&&Array.isArray(e)&&e.some(t=>typeof t=="object"&&t!==null),FE=e=>e&&e.type&&e.value,ir=e=>e&&Array.isArray(e)&&e.length;function vt(e,t,o){return e&&e[t]||o}function wc(e){let{executeButton:t,id:o,onChange:n,referenceContent:r,referenceLocale:i,simpleState:s}=e,l=La$1(o),[a,u]=useState(false),[c,p]=useState(()=>({allLabel:vt(s,"allLabel","All"),colorKey:vt(s,"colorKey",""),dataVar:vt(s,"dataVar",""),defaultVar:vt(s,"defaultVar",""),hideLabel:vt(s,"hideLabel","false"),resetSectionVars:vt(s,"resetSectionVars","false"),iconKey:vt(s,"iconKey",""),isPrimitiveType:vt(s,"isPrimiteType",false),levelsVar:vt(s,"levelsVar",""),limit:vt(s,"limit",0),placeholder:vt(s,"placeholder",""),searchIndexKey:vt(s,"searchIndexKey",""),searchIndexSeparator:vt(s,"searchIndexSeparator","|"),selectorIdentifier:vt(s,"label","")})),[f,m]=useState([]),[g,S]=useState([]),[v,h]=useState({}),[b,C]=useState({}),[d,y]=useState([]),x=useCallback((T,M,I=false)=>p(O=>({...O,[T]:!M&&I?"":M})),[]);useEffect(()=>{if(!l){m([]),S([]),h({}),C({});return}let T=Object.entries(l).filter(([G,W])=>VE(W)).reduce((G,[W,F])=>(G[W]=F,G),{}),M=Object.entries(l).filter(([,G])=>FE(G)).reduce((G,[W,F])=>(G[W]=F,G),{});C(T),h(M);let I=Object.keys(T),O=Object.keys(M);m(I),S(O),u(true);},[l]),useEffect(()=>{if(!Object.keys(b).length)return;let T=$a(b[c.dataVar]);if(T)y([]),x("colorKey",""),x("iconKey",""),x("searchIndexKey","");else {let M=new Set;(b[c.dataVar]||[]).forEach(O=>Object.keys(typeof O=="object"?O:{}).forEach(G=>M.add(G)));let I=Array.from(M).sort().map(O=>O);y(I);}x("isPrimitiveType",T);},[b,c.dataVar]),useEffect(()=>{let{allLabel:T,colorKey:M,dataVar:I,defaultVar:O,hideLabel:G,resetSectionVars:W,iconKey:F,levelsVar:L,limit:U,placeholder:P,searchIndexKey:A,searchIndexSeparator:_,selectorIdentifier:Q}=c,Y={allLabel:T,colorKey:M,dataVar:I,defaultVar:O,label:Q,hideLabel:G,resetSectionVars:W,iconKey:F,levelsVar:L,limit:U,placeholder:P,searchIndexKey:A,searchIndexSeparator:_},{logicOptions:ce,logicLevels:re,defaultValue:ae,defaultValueType:me}=Qa(Y);ae&&me&&(Y.defaultValue=ae,Y.defaultValueType=me),Y.data=ce,Y.levels=re;let gt=`return ${Wn(Y)};`,kt=Y,Rt=_m(kt);n(kt,gt,Rt);},[c]);let k=useCallback(T=>{x("dataVar",T),x("defaultVar",{}),x("colorKey",""),x("iconKey",""),x("searchIndexKey","");},[x]);if(!a)return null;let R=Object.keys(b),B=Object.keys(v),N=Tc(A.MULTIHIERARCHY_SELECTOR_ALL_LABEL),$=Tc(A.MULTIHIERARCHY_SELECTOR_NAME),K=Tc(A.MULTIHIERARCHY_SELECTOR_PLACEHOLDER);return jsxs(Fragment,{children:[jsxs(Stack,{mb:"sm",spacing:"xs",children:[jsx(wt,{field:"label",value:c.selectorIdentifier,handleEditor:(T,M)=>{x("selectorIdentifier",M);},referenceContent:r,referenceLocale:i,variables:l,editorConfig:$}),jsx(Checkbox,{label:jsx(Ke,{label:"Hide Label",py:0}),checked:c.hideLabel==="true",onChange:T=>x("hideLabel",T.currentTarget.checked?"true":"false")}),jsx(Select,{data:f,description:"(Required) Select an array of data available in the block inputs to use as data input.",label:jsx(Ke,{label:"Data Input"}),onChange:T=>k(T),value:ir(R)&&c.dataVar}),jsx(Select,{data:f,description:"(Required) Select an array of {label, value} items in the block inputs to use as levels.",label:jsx(Ke,{label:"Levels Input"}),onChange:T=>x("levelsVar",T),value:ir(R)&&c.levelsVar}),jsx(Select,{clearable:true,data:g,description:"(Optional) Select an object with {type, value} keys in the block inputs to use as default value.",label:jsx(Ke,{label:"Default Value"}),onChange:T=>{if(!T){x("defaultVar","");return}x("defaultVar",T);},value:ir(B)&&c.defaultVar}),jsx(NumberInput,{description:"(Optional) Sets a limit for selected values. Set 0 for no limit.",label:jsx(Ke,{label:"Limit"}),min:0,onChange:T=>x("limit",T),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(wt,{field:"allLabel",value:c.allLabel,handleEditor:(T,M)=>x("allLabel",g$1(M)),referenceContent:r,referenceLocale:i,variables:l,editorConfig:N}),jsx(wt,{field:"placeholder",value:c.placeholder,handleEditor:(T,M)=>x("placeholder",g$1(M)),referenceContent:r,referenceLocale:i,variables:l,editorConfig:K}),jsx(Select,{clearable:true,data:d,description:"(Optional) Select a property key to use as item's icon background color. Requires defining an icon key.",disabled:c.isPrimitiveType,label:jsx(Ke,{label:"Color property key"}),onChange:T=>x("colorKey",T,true),value:ir(d)&&c.colorKey}),jsx(Select,{clearable:true,data:d,description:"(Optional) Select a property key to use as item's icon src.",disabled:c.isPrimitiveType,label:jsx(Ke,{label:"Icon property key"}),onChange:T=>x("iconKey",T,true),value:ir(d)&&c.iconKey}),jsx(Select,{clearable:true,data:d,description:"(Optional) Select a property key to extend the search functionality. The selected key MUST only contain text elements.",disabled:c.isPrimitiveType,label:jsx(Ke,{label:"Search index key"}),onChange:T=>x("searchIndexKey",T,true),value:ir(d)&&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(Ke,{label:"Search index separator"}),onChange:T=>x("searchIndexSeparator",T.currentTarget.value),value:c.searchIndexSeparator})]})})]})})]}),jsx(Checkbox,{my:"md",label:jsx(Ke,{label:"Reset SectionVariables on change",py:0}),checked:c.resetSectionVars==="true",onChange:T=>x("resetSectionVars",T.currentTarget.checked?"true":"false")}),t]})}var $E={[z.SELECTOR]:Tm,[z.NAV]:uc,[z.RELATED]:pc,[z.RESET_BUTTON]:fc,[z.COMPARISON_BUTTON]:gc,[z.TITLE]:mc,[z.STAT]:hc,[z.TABLE]:Cc,[z.MULTIHIERARCHY_SELECTOR]:wc},Hm=$E;function GE(e){let{blockType:t,id:o,locale:n,setBlockContent:r,simpleState:i}=e,s=lo(),l=La$1(o),a=Hm[t],u=jsx(vm,{fields:B[t],locale:n,defaultContent:i,variables:l,onChange:r},"text-editor");return a?jsx(a,{id:o,executeButton:s.executeButton,onChange:(c,p,f=true)=>r({simple:c,logic:p},n,true,f),simpleState:i,richTextEditor:u,variables:l,referenceContent:s.reference.content,referenceLocale:s.reference.locale}):u}var Wm=GE;function QE({id:e,variables:t,reserved:o,hasInternalKeys:n}){let[r,i]=useState(false);return jsxs(Fragment,{children:[n&&jsx(Switch,{label:"Show internal variables",size:"xs",checked:r,onChange:s=>i(s.currentTarget.checked)}),jsx(l,{id:e,variables:t,reserved:o,showInternal:r})]})}function ZE({id:e,setInlineId:t}){let o=va$1(u=>u.records.entities.block),n=ua(),r=Ma$1(e),i=Object.keys(r.attributes),s=useContext(db$1),l=Ya(s),a=u=>{n(ta$1.updateEntity("block",{id:e,inputAction:{operation:"delete",input:{input_id:u,block_id:e}}})).then(()=>{l();});};return jsx("div",{style:{display:"flex",flex:"1 1 auto",flexDirection:"column",width:"100%"},children:Object.keys(r).sort(u=>u==="attributes"?-1:1).map(u=>{let c=o[u],p=c&&[z.GENERATOR,z.SECTION_FLAG].includes(c.type),f=c?.type&&c?.id?`${c.type}${c.id}`:"",m=Object.keys(r[u]).some(k(f));return jsxs(Stack,{className:"cr-variable-group",style:{position:"relative"},children:[jsx(Divider,{}),jsxs(Group,{position:"apart",noWrap:true,grow:true,children:[jsx(Title,{order:6,children:c?`${titleCase(c.type)} ${c.id} Variables`:"Dimension Variables"}),c&&jsxs(Group,{position:"right",noWrap:true,children:[p&&jsx(Tooltip,{label:"Edit this generator",children:jsx(ActionIcon,{size:"xs",onClick:()=>t(u),variant:"subtle",color:"gray",children:jsx(IconPencil,{size:15})})}),jsx(Tooltip,{label:"Remove as input",children:jsx(ActionIcon,{size:"xs",onClick:()=>a(u),variant:"light",color:"red",children:jsx(IconLinkOff,{size:15})})})]})]}),jsx(QE,{id:u,variables:r[u],reserved:i,hasInternalKeys:m})]},u)})})}var Xm=ZE;function gI({blockType:e,fullscreen:t,toggle:o,codeEditor:n}){let r=lo(),i=[z.GENERATOR,z.VIZ].includes(e),[s,{open:l,close:a}]=useDisclosure(false);return jsxs(Fragment,{children:[jsxs(Popover,{width:400,position:"bottom",withArrow:true,shadow:"md",opened:s,children:[jsx(Popover.Target,{children:jsx(ActionIcon,{variant:"subtle",color:"blue",size:"sm",onMouseEnter:l,onMouseLeave:a,pos:"absolute",top:3,left:3,style:{zIndex:1},children:jsx(IconHelp,{size:16})})}),jsx(Popover.Dropdown,{children:jsxs(Text,{size:"sm",children:["You can access ",jsx(Code,{children:"variables"}),", ",jsx(Code,{children:"formatters"}),",",jsx(Code,{children:"locale"}),", ",jsx(Code,{children:"libs"}),",",e===z.GENERATOR&&jsxs(Fragment,{children:[jsx(Code,{children:"resp"}),", "]}),e===z.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."]})]})})]}),n,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:true,children:t?"Minimize":"Maximize"}),r.executeButton]})]})}function hI(){let e=lo(),t=_a(),o=$a$1(),n=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:r=>e.changeEditorMode(r.currentTarget.checked?"code":"simple"),onLabel:jsx(IconCode,{size:rem(12)}),offLabel:jsx(IconCode,{size:rem(12)})}),e.mode!=="code"&&n&&jsx(Switch,{checked:e.reference.active,onChange:r=>e.reference.setActive(r.currentTarget.checked),size:"xs",label:"See reference language",labelPosition:"left",onLabel:jsx(IconLanguage,{size:"0.7rem"}),offLabel:jsx(IconLanguage,{size:"0.7rem"})})]})})}function bI({header:e,blockContent:t,blockSettings:o,blockType:n$1,id:r,locale:i,onSave:s,setBlockContent:l,setBlockSettings:a,setInlineId:u,sid:c}){let[p,f]=useState("Content"),[m,g]=useState(false),[S,v]=useState(false),h=Na$1(r),b=lo(),d=va$1(P=>P.status.isRunConsumersRunning).includes(c),y=useMemo(()=>{let P={resp:null,apiFinalUrls:null,apiDataSources:void 0};return h&&h.resp&&h.apiFinalUrls&&h.apiDataSources&&(P.resp=h.resp,P.apiFinalUrls=h.apiFinalUrls,P.apiDataSources=h.apiDataSources),P},[h]),x=La$1(r),{ref:k,toggle:R,fullscreen:B}=useFullscreen(),N=t&&(t.api||t.api==="")?t.api.split("|||"):[],$=(P,A)=>l({logic:P},A),K=(P,A)=>{let _=[...N];_[A]=P,l({api:_.join("|||")},void 0,void 0,void 0,true);},T=()=>{l({api:[...N,""].join("|||")}),g(true);},M=P=>{l({api:N.length===1&&N[0]===""?null:N.filter((A,_)=>_!==P).join("|||")},void 0,void 0,void 0,true);},I=(P,A)=>{a({[P]:A});},O=()=>{g(!m);},G=()=>{v(!S);},W=jsx(rn,{monacoOptions:{onChange:P=>$(P,i),value:t?.logic||"",height:B?"85vh":"61vh",width:"100%"}},"code-editor"),F=t?.simple||{},L=jsx(Wm,{blockType:n$1,id:r,locale:i,simpleState:F,setBlockContent:l,variables:x}),U=jsx(Col,{span:4,sx:P=>({display:"flex",flexDirection:"column",borderLeft:`2px solid ${P.colors.gray[0]}`}),children:jsxs(Stack,{children:[jsx(Text,{inline:true,size:"xs",transform:"uppercase",weight:"bold",color:"gray",children:"Preview"}),jsx(fa,{id:r,active:true,blockStateContent:t,blockStateSettings:o,locale:i,allowed:true,debug:true},"block-preview")]})});return jsxs(Grid,{h:"100%",children:[jsxs(Col,{span:3,sx:{alignSelf:"stretch",display:"flex",flexDirection:"column",height:"100%",position:"relative"},children:[z.SECTION_FLAG!==n$1&&jsx(Qd,{id:r}),jsx("div",{style:{width:"100%",maxHeight:"80vh",overflowY:"auto"},children:jsx(Xm,{id:r,setInlineId:u})})]}),jsxs(Col,{span:9,sx:P=>({alignSelf:"stretch",display:"flex",flexDirection:"column",height:"100%",borderLeft:`2px solid ${P.colors.gray[0]}`}),children:[e,jsxs(Tabs,{value:p,onTabChange:f,keepMounted:false,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:k,pos:"relative",bg:"white",h:"100%",children:jsxs(Grid,{className:"cr-block-output",style:{flex:1,width:"100%",height:B?"100vh":"100%",margin:0},children:[jsxs(Col,{span:8,className:`cr-block-output-editor ${b.mode}`,children:[![z.VIZ,z.GENERATOR,z.SECTION_FLAG].includes(n$1)&&jsx(hI,{}),[z.GENERATOR,z.SECTION_FLAG].includes(n$1)&&jsxs(Stack,{mb:5,spacing:4,children:[d&&jsx(Overlay,{children:jsx(Text,{children:"Running..."})}),jsxs(Group,{spacing:"xs",children:[jsx(Button,{size:"sm",variant:"light",color:"blue",leftIcon:m?jsx(IconChevronDown,{size:16}):jsx(IconChevronRight,{size:16}),onClick:O,sx:{flex:1},children:`${N.length} API Request${N.length!==1?"s":""}`}),jsx(Button,{size:"sm",onClick:T,variant:"light",color:"blue",leftIcon:jsx(IconPlus,{size:15}),children:"Add API"})]}),jsxs(Collapse,{in:m,children:[N.map((P,A)=>jsx($d,{defaultValue:P,pos:A+1,id:r,finalUrl:y.apiFinalUrls&&y.apiFinalUrls[A]?y.apiFinalUrls[A]:null,dataSource:y.apiDataSources&&y.apiDataSources[A]?y.apiDataSources[A]:null,onChangeAPI:_=>K(_,A),onDelete:()=>M(A)},`${r}-${A}-${N.length}`)),y.resp&&jsx(Button,{variant:"light",color:"blue",size:"xs",leftIcon:S?jsx(IconChevronDown,{size:14}):jsx(IconChevronRight,{size:14}),onClick:G,mt:5,children:"Response data preview (resp)"}),y.resp&&jsx(Collapse,{in:S,children:jsx("div",{style:{maxHeight:200,overflowY:"scroll"},children:jsx(j,{value:y.resp,root:true,label:"resp"})})})]})]}),jsxs(Box,{bg:b.mode==="code"?"#272822":"none",p:"xs",pos:"relative",children:[b.mode==="code"&&jsx(gI,{blockType:n$1,fullscreen:B,toggle:R,codeEditor:W}),b.mode!=="code"&&L]})]},"content-col"),U]})})}),jsx(Tabs.Panel,{value:"Style",pt:"xs",children:jsx(Box,{ref:k,pos:"relative",bg:"white",h:"100%",children:jsxs(Grid,{children:[jsxs(Col,{span:8,children:[jsx(Title,{order:4,children:"Style settings"}),jsx(n,{id:r,display:"inline",handleChange:I})]},"content-col"),U]})})}),jsx(Tabs.Panel,{value:"Settings",pt:"xs",children:jsx(Jd,{id:r,setBlockSettings:a})})]})]})]})}var ng=bI;var rg=e=>(!e||!e.contentByLocale||Object.keys(e.contentByLocale).forEach(t=>{let o=e.contentByLocale[t]?.content;o&&Object.keys(o).length===0&&(o.simpleEnabled=true,o.simple={});}),e);var Nc=["_icon","_iconType","_iconVariant","_iconSize","_iconRadius","_iconPadding"],ig={[z.SELECTOR]:["hideLabel","resetSectionVars","component","optionsType","type"],[z.TITLE]:[...Nc],[z.NAV]:[...Nc],[z.STAT]:[...Nc],[z.TABLE]:["data","tableProps","variable"],[z.MULTIHIERARCHY_SELECTOR]:["colorKey","dataVar","defaultVar","hideLabel","resetSectionVars","iconKey","levelsVar","limit","searchIndexKey","searchIndexSeparator"]},AI=(e,t)=>({...e,[t.locale]:{...t,content:t.content}});function PI({block:e,localeDerived:t}){let o=lo(),n=Ea$1(e.section_id).data,r=Da$1(n.report_id).data,i=n?.settings.name||`Section ${n?.id}`,s=`${e.type} ${e.id}`,l=r?.name||`Report ${r.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:i}),jsx(Text,{size:"xs",children:s})]}),jsx(Badge,{size:"sm",radius:"sm",rightSection:jsx(Center,{children:t==="logic"?jsx(IconCode,{size:"0.6rem"}):jsx(IconLanguage,{size:"0.6rem"})}),children:t})]})}),jsxs(Group,{children:[o.cancelButton,o.closeAndSaveButton]})]})}function RI({id:e,modified:t,callbacks:o,inline:n}){let r=ua(),i=useContext(db$1),s=Ya(i),{setOpened:l,setModified:a,maybeCloseWithoutSaving:u,setInlineId:c}=o,p=Fa$1(e).data,f=va$1(O=>O.status.currentLocale),m=va$1(O=>O.status.localeDefault),g=va$1(O=>O.status.locales),S=N$1(p,f).locale,[v,h]=useState(),[b,C]=useState(false),[d,y]=useState(true);if(useEffect(()=>{h(rg(ya(p))),C(true);},[]),!p||!b||!v)return null;let x=O(v,f),k=v.settings,R=(O={},G=m,W=true,F=void 0,L=false)=>{let{locale:U}=N$1(p,G);if(W&&!t&&a(true),F!==void 0&&d!==F&&y(F),!O||Object.keys(O).length<1)return;let P=v.contentByLocale[U]||{id:e,locale:U,content:{}},A={...v,contentByLocale:{...v.contentByLocale,[U]:{...P,content:{...P.content,...O}}}};if(h(A),L){let _=N(A);r(ta$1.updateEntity("block",_)).then(()=>{s(),a(false);});}},B=(O,G)=>{if(S!=="logic"&&Object.keys(ig).includes(p.type)){let W={...O},F=O[G].content;return g.forEach(L=>{if(L===S)return;let P={...O[L].content.simple};Object.keys(F.simple).map(_=>{ig[p.type].includes(_)&&(P[_]=F.simple[_]);});let A={...P};if(p.type===z.SELECTOR){let{selectorType:_=hn.SINGLE,options:Q={static:[]},optionsType:Y=Fo.STATIC}=O[L].content.simple,{logicOptions:ce,defaultValue:re}=Ga(_,Q,Y);re&&(A.defaultValue=re),A.options=ce;}if(p.type===z.MULTIHIERARCHY_SELECTOR){let _=O[L].content.simple,{logicLevels:Q,logicOptions:Y,defaultValue:ce,defaultValueType:re}=Qa(_);ce&&re&&(A.defaultValue=ce,A.defaultValueType=re),A.data=Y,A.levels=Q;}W[L].content={...W[L].content,simple:P,logic:ro(A,false)};}),W}return O},N=(O=null)=>{let G=O||v,{settings:W}=G,F=Object.values(G.contentByLocale).reduce(AI,{}),L=["id","api","shared","type"].reduce((P,A)=>({...P,[A]:G[A]}),{}),U=B(F,f);return {...L,id:G.id,contentByLocale:U,settings:W}},$=async O=>{let G=N();r(ta$1.updateEntity("block",G)).then(()=>{s(),a(false),O||(n?c(null):l(false));});},K=O=>{t||a(true),O.type||O.shared!==void 0?h({...v,...O}):h({...v,settings:{...v.settings,...O}});};return jsx(Fragment,{children:jsx(gm,{buttons:{cancelButton:jsx(Button,{leftIcon:jsx(IconCircleX,{size:"0.8rem"}),size:"xs",variant:"outline",onClick:u,color:"red",children:"Cancel"},"cancel"),closeAndSaveButton:jsx(Button,{leftIcon:jsx(IconDeviceFloppy,{size:"0.8rem"}),size:"xs",disabled:!d,onClick:()=>$(false),children:`Save & ${n?"Return":"Close"}`},"save"),executeButton:jsx(Button,{disabled:!d,onClick:()=>$(true),size:"xs",compact:true,children:"Save & Execute"})},blockType:p.type,blockId:p.id,children:jsx(ng,{header:jsx(PI,{localeDerived:S,block:p}),blockContent:x,blockSettings:k,blockType:p.type,id:e,sid:p.section_id,locale:f,onSave:$,setBlockContent:R,setBlockSettings:K,setInlineId:c},"be")})})}var ag=RI;function jI({id:e,setHoverBlock:t,isInput:o,isConsumer:n$1,active:r,showOutline:i=true}){let[s,l]=useState(false),{newConfirmation:a}=b(),[u$1,c]=useState(false),[p,f]=useState(false),[m,g]=useState(null),S=useContext(db$1),v=Ya(S),h=useMantineTheme(),b$1=La$1(e),C=Na$1(e),d$1=useCallback(()=>{c(false),f(false),g(null);},[]),y=useDispatch(),x=va$1(A=>A.status.currentLocale),{data:k}=Fa$1(e),R=va$1(A=>A.records.entities.block),{isFetching:B}=ab("block",e),{allowed:N,allowedMessage:$}=useMemo(()=>{let A=!C?.hiddenByCascade,_="";return k&&(_=C?.hiddenByCascade===e?`Hidden by ${k.settings.allowed}: ${k.settings.allowed?b$1[k.settings.allowed]:null}`:`Hidden by ${C?.hiddenByCascade}`),{allowed:A,allowedMessage:_}},[b$1,C,k,e]);if(!k)return null;let{blockcol:K,type:T,section_id:M,contentByLocale:I,settings:O,inputs:G$1}=k,W=async()=>{if(p)try{await a({title:"Are you sure?",message:"Close editor without saving?",confirmText:"Yes, abandon changes."}),d$1();}catch{}else d$1();},F={centered:true,withCloseButton:false,opened:u$1,onClose:W,overflow:"inside",padding:h.spacing.sm,size:"95%",styles:{body:{height:"100%"}}},L={onMouseEnter:()=>t(e),onMouseLeave:()=>t(false)},U={setOpened:c,setModified:f,setInlineId:g,maybeCloseWithoutSaving:W},P=()=>{let A=Object.keys(R).filter(Y=>R[Y].section_id===k.section_id&&R[Y].blockcol===k.blockcol).map(Y=>R[Y].blockrow),_=f$2(A),Q={create:{blockrow:d(_),blockcol:K,locales:Object.keys(I).map(Y=>Y),section_id:M,type:T},update:{contentByLocale:I,settings:O,inputs:G$1.map(Y=>R[Y])}};y(ta$1.cloneEntity("block",Q)).then(()=>{[z.GENERATOR,z.SECTION_FLAG].includes(k.type)&&v({sid:M});});};return jsxs(Fragment,{children:[jsxs(Group,{id:`block-${e}`,onMouseOver:()=>l(true),onMouseOut:()=>l(false),className:"cr-section-block",pos:"relative",py:G.block.padding,...L,sx:A=>({border:"1px solid transparent",resize:"horizontal","&:hover":{border:i?`1px solid ${A.colors.blue[2]}`:"1px solid transparent"},...i?{"&:hover::before":{position:"absolute",top:0,left:0,fontSize:8,color:A.colors.blue[5],transform:"translateY(-100%)",content:`"Block ${e}"`,width:"fit-content"}}:{}}),children:[jsx(fa,{style:{color:"red"},id:e,debug:[z.VIZ,z.GENERATOR,z.SECTION_FLAG].includes(k.type),active:r,locale:x,allowed:N,isFetching:B},"bp"),(s||o||n$1)&&jsxs(Group,{spacing:0,className:"cr-block-controls export-hidden",style:{position:"absolute",right:px(h.spacing.xs)/2,top:px(h.spacing.xs)/2,backgroundColor:h.colors.gray[2],borderRadius:h.radius.sm,zIndex:5},children:[o||n$1?jsx(ActionIcon,{children:o?jsx(IconLogout,{size:20,color:h.colors.red[5]}):jsx(IconLogin,{size:20,color:h.colors.green[5]})},"globe"):null,k.shared&&jsx(Tooltip,{withArrow:true,label:"Sharing: Enabled",children:jsx(ActionIcon,{variant:"transparent",children:jsx(IconWorld,{size:20})},"globe")},"tt"),"access"in k.settings&&!["public","guest"].some(A=>!k.settings.access||k.settings.access.includes(A))&&jsx(Tooltip,{withArrow:true,label:"Private Block",children:jsx(ActionIcon,{variant:"transparent",children:jsx(IconLock,{size:20})},"lock")},"tt"),!N&&jsx(Tooltip,{withArrow:true,label:$,children:jsx(ActionIcon,{variant:"transparent",children:jsx(IconEyeOff,{size:20})})},"allowed"),![z.GENERATOR,z.SECTION_FLAG].includes(k.type)&&jsx(n,{id:e,display:"button"},"design"),jsx(ActionIcon,{onClick:()=>c(true),children:jsx(IconPencil,{size:20})},"edit"),![z.SECTION_FLAG].includes(k.type)&&jsx(ActionIcon,{onClick:P,children:jsx(IconCopy,{size:20})},"copy"),jsx(zd,{type:u.BLOCK,id:e},"cog")]},"bc")]},"block"),jsx(Modal,{fullScreen:true,...F,children:jsx(ag,{callbacks:U,id:m||e,inline:m,modified:p},m||e)},"d")]})}var sr=jI;var ug=({id:e,disabled:t=false})=>{let{sectionVariables:o,resetSectionVariables:n}=Va(e);return !Object.keys(o).length?null:jsx(ActionIcon,{disabled:t,onClick:n,variant:"filled",size:"xs",children:jsx(IconRefresh,{size:20})})},QI=({sectionId:e,onActivate:t})=>{let{activeEntity:o}=Ka(),{handlers:n}=Za("settings");return o.type==="section"&&o.id===e?jsx(Button,{size:"xs",radius:"xl",leftIcon:jsx(IconPencil,{size:14}),fw:400,onClick:n.open,compact:true,children:"Edit"}):jsx(ActionIcon,{variant:"transparent",onClick:()=>{t(),n.open();},children:jsx(IconPencil,{size:18})})};function ZI({sectionId:e$1,onActivate:t,position:o}){let n=useDispatch(),r=Ea$1(e$1),i=va$1(f=>f.records.entities.section),{data:s}=r,l=a$2(),a=Number.parseInt(l.params[0]),u=Da$1(a),c=va$1(f=>f.records.entities.block);if(!s||!u.data?.sections)return null;let{sections:p}=u.data;return jsxs(Group,{spacing:2,children:[jsx(QI,{sectionId:e$1,onActivate:t}),jsx(ActionIcon,{variant:"transparent",onClick:()=>{let f={...s,ordering:e(i,p,o+1,true)},m=eA(f,c);n(ta$1.cloneEntity("section",m));},children:jsx(IconCopy,{size:18})}),jsx(Bt,{type:"section",id:e$1})]})}function eA(e,t){let{heading:o,report_id:n,ordering:r,settings:i}=e,s=[];return {create:{ordering:r,report_id:n},update:{settings:i,heading:o,report_id:n,blocks:e?.blocks.map(a=>{let u=t[a],{blockcol:c,blockrow:p,contentByLocale:f,type:m,settings:g,section_id:S,shared:v,inputs:h,consumers:b}=u;return {blockcol:c,blockrow:p,contentByLocale:f,id:a,type:m,settings:g,section_id:S,shared:v,inputs:h.map(C=>{let d=t[C],{id:y,section_id:x,blockcol:k,blockrow:R,contentByLocale:B,settings:N,shared:$,type:K}=d;return {id:y,section_id:x,blockcol:k,blockrow:R,contentByLocale:B,settings:N,shared:$,type:K}}),consumers:b.reduce((C,d)=>{let y=t[d];if(y){let{id:x,section_id:k,blockcol:R,blockrow:B,contentByLocale:N,settings:$,shared:K,type:T}=y;return [...C,{id:x,section_id:k,blockcol:R,blockrow:B,contentByLocale:N,settings:$,shared:K,type:T}]}return C},s)}})}}}var pg=ZI;function mg({active:e,isDragging:t,id:o,dragHandleProps:n,hidden:r="",onActivate:i$1,sectionSettings:s,position:l}){let a=va$1(f=>f.records.entities.section[o]||null);if(!a)return null;let u=useMemo(()=>a&&a.settings?.name?.length?a.settings.name:`section-${a.id}`,[a.settings?.name,a.id]),c=useMemo(()=>i(u),[u]),p=r!=="";return jsxs(Group,{className:`cms-section-header${e||t?" active":""}`,position:"apart",bg:p?"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",...n,w:16,sx:{cursor:"grab"},children:jsx(IconGripHorizontal,{size:16})},"b1"),jsxs(Text,{size:"xs",fw:400,color:"dark.9",children:[u,c!==u&&jsxs(Text,{span:true,size:"xs",c:"dimmed",children:[" #",c]}),p&&` ${r}`]})]})}),jsxs(Group,{children:[jsxs(Flex,{justify:"flex-end",mx:16,align:"center",gap:"xs",children:[jsx(ug,{id:a.id,disabled:!e}),s.optionsMenu&&jsx(C,{sectionId:a.id,disabled:!e})]}),jsx(pg,{sectionId:o,onActivate:i$1,position:l})]})]})}var yA=Object.values(z),xg=({columns:e,columnIndex:t,section:o})=>{let n=ua(),{settings:r}=i$1(o.report_id),[i,s]=useDisclosure(false),l=(u,c=false)=>{let p="!",f="!";typeof c=="string"?(f=c,p=f$2(Object.keys(e[c]),true)):Object.keys(e).length>0&&(f=f$2(Object.keys(e),true));let{locales:m}=N$1({type:u});n(ta$1.createEntity("block",{blockrow:p,blockcol:f,type:u,section_id:o.id,locales:m})).then(g=>{u===z.VIZ&&n(ta$1.updateEntity("block",{id:g.data.id,contentByLocale:{logic:{...g.data.contentByLocale.logic,content:{simpleEnabled:true,simple:{},logic:V}}}}));});},a=yA.filter(u=>![z.GENERATOR,z.SECTION_FLAG,z.FALLBACK].includes(u)&&(r.comparison?true:u!==z.COMPARISON_BUTTON)).map(u=>{let c=O$1(u);return {label:jsx(UnstyledButton,{p:"xs",w:"100%",onClick:()=>{l(u,t),s.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:Q(u)||u})]})}),value:u}});return jsx(Center,{w:"100%",py:"sm",children:jsxs(Popover,{position:"right",withinPortal:true,zIndex:100,opened:i,onClose:s.close,children:[jsx(Popover.Target,{children:jsx(ActionIcon,{size:"lg",radius:"xl",variant:"light",bg:"#E5E5E5 !important",onClick:s.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:a.map(({label:u,value:c})=>jsx(List.Item,{w:"100%",children:u},c))})})]})]})})},vA=({columns:e,section:t,show:o=false})=>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(xg,{columnIndex:false,columns:e,section:t})]})}):null,SA=({active:e=false})=>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:n=>({boxSizing:"border-box",zIndex:99,transition:"right 0.4s",overflow:"hidden",background:o.isDraggingOver?n.colors[n.primaryColor][0]:n.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,{})]})})}),xA=({onActivate:e,section:t,show:o=false})=>{let r=va$1(i=>i.status.isRunConsumersRunning).includes(t.id);return !o&&!r?null:jsxs(Overlay,{className:"cms-section-overlay",onClick:()=>e(t.id),opacity:.6,color:"#E9ECEF",style:{cursor:"pointer",zIndex:3},sx:i=>({transition:"background-color .45s",".bespoke-Section-edit":{opacity:0,transition:"opacity .45s"},"&:hover":{backgroundColor:i.fn.rgba("#E9ECEF",.9),".bespoke-Section-edit":{opacity:1}}}),center:true,children:[!r&&jsxs(Group,{className:"bespoke-Section-edit",align:"center",spacing:"xs",children:[jsx(Text,{fw:700,children:"Click to Edit"}),jsx(IconPencil,{size:"1rem"})]}),r&&jsxs(Stack,{align:"center",spacing:"xs",children:[jsx(Text,{fw:700,children:"Loading dependencies"}),jsx(Loader,{size:"md"})]})]})};function CA({for:e$1,isDragging:t,onActivate:o,dragHandleProps:n,position:r}){let i$1=ua(),{activeEntity:s}=Ka(),[l,a]=useState(false),[u,c]=useState(),p=useRef(null),f=va$1(I=>I.records.entities.block),m$1=va$1(I=>I.status.previews),g=ab("section",e$1.id),{memberImageBg:S,hidden:v,columnSettings:h={}}=e$1.settings,b=s.type==="section"&&s.id===e$1.id,{inputs:C,consumers:d}=useMemo(()=>{if(u){let I=f[u],{inputs:O,consumers:G}=I;return {inputs:O,consumers:G}}return {inputs:[],consumers:[]}},[u]),y=Object.values(f||{}).filter(I=>I.section_id===e$1.id&&![z.GENERATOR,z.SECTION_FLAG].includes(I.type)).reduce((I,O)=>(I[O.blockcol]?I[O.blockcol][O.blockrow]=O:I[O.blockcol]={[O.blockrow]:O},I),{}),x=useMantineTheme(),k=()=>a(true),R=I=>{if(a(false),!I.destination)return;let{source:O,destination:G}=I;if(O.droppableId===G.droppableId&&O.index===G.index)return;let W=G.droppableId==="newColumn",F=Number(I.draggableId),L=O.droppableId,U=W?f$2(Object.keys(y),true):G.droppableId,P={id:F,blockrow:"!",blockcol:"!"},A=L!==U;P.blockcol=A?U:L;let _=Object.values(y[P.blockcol]||{}),Q=_.reduce((re,ae)=>({...re,[ae.id]:ae}),{}),Y=_.sort((re,ae)=>c$1(re,ae,"blockrow")).map(re=>re.id),ce=G.index>O.index;P.blockrow=e(Q,Y,G.index,A,ce,"blockrow"),i$1(ta$1.updateEntity("block",P));},B=useMemo(()=>{let I=Object.values(f||{}).filter(O=>O.section_id===e$1.id&&W(O));return I.length>1&&console.error(`Error, there are more than one Section Flag Generator in section ${e$1.id}`),I.length>0?I[0]:false},[f,b,e$1.id]),N=va$1(I=>B&&I.variables.variables[B.id]&&!I.variables.variables[B.id][T]||false),$=useMemo(()=>{let I="";return N&&B&&(I+=`(Not allowed by Section Flag #${B.id})`),v&&(I+="(Hidden by Section Settings)"),I},[v,N]),K=Object.keys(y).sort((I,O)=>-b$1(I,O)),T$1=Object.keys(y).length,M=useMemo(()=>e$1?.settings?.name?i(e$1?.settings?.name):`section-${e$1.id}`,[e$1.id,e$1?.settings?.name]);return g.isFetching?jsxs(Box,{p:"lg",m:"lg",bg:G.section.backgroundColor,sx:I=>({borderRadius:I.radius.md,border:`1px solid ${I.colors.gray[4]}`}),children:[jsx(Skeleton,{height:50,circle:true,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(mg,{active:b,id:e$1.id,isDragging:t,hidden:$,dragHandleProps:n,onActivate:()=>o(e$1.id),sectionSettings:e$1.settings,position:r}),jsxs(Box,{pos:"relative",sx:I=>({border:b?`1px solid ${I.colors.blue[4]}`:"none",borderRadius:2}),children:[jsx(Paper,{id:M,className:`cms-section${t||b?" active":""}`,bg:e$1.settings.style==="card"?G.section.backgroundColor:"transparent",p:0,mih:100,maw:e$1.settings.width==="center"?x.breakpoints.xl:"none",w:"100%",mx:"auto",pos:"relative",shadow:e$1.settings.style==="card"?G.section.boxShadow:"none",radius:G.section.borderRadius,sx:{overflow:"hidden"},children:jsxs(Box,{pos:"relative",children:[S&&jsx(B$1,{previews:m$1}),jsx(F,{ref:p,containerProps:{mih:!b||!T$1?120:"none",p:e$1.settings.margin||"md",style:{zIndex:2},gap:e$1.settings.columnGutter||"md",wrap:"wrap"},children:jsxs(DragDropContext,{onDragEnd:R,onDragStart:k,children:[K.map(I=>{let O=Object.values(y[I]).sort((G,W)=>c$1(G,W,"blockrow"));return jsx(Droppable,{droppableId:I,children:(G,W)=>jsxs(D,{column:y[I],columnSettings:h[I],ref:G.innerRef,basis:`calc(${100/T$1}% - (10px * ${T$1}))`,sx:{background:W.isDraggingOver?x.colors[x.primaryColor][0]:"inherit",border:"1px solid transparent","& .bespoke-resize-col":{visibility:"hidden"},"&:hover .bespoke-resize-col":{visibility:"visible"},"&:hover":{border:`1px solid ${x.colors.teal[1]}`}},...G.droppableProps,children:[jsx(E,{sectionId:e$1.id,columnIndex:I}),O.map((F,L)=>{if(!f[F.id])return null;let{settings:U,type:P}=f[F.id],A=U.width&&!U.width.stretch&&U.width.unit?m[U.width.unit](U.width.value):U.display==="inline"?"auto":"100%",_={alignSelf:P===z.VIZ?"stretch":"flex-start",flexGrow:0,margin:"0",width:A,minWidth:120};return jsx(Draggable,{draggableId:String(F.id),index:L,children:(Q,Y)=>jsx(Box,{ref:Q.innerRef,...Q.draggableProps,...Q.dragHandleProps,sx:[_,{boxShadow:Y.isDragging?x.shadows.lg:"none",...Q.draggableProps.style}],children:jsx(sr,{id:Number(F.id),active:b,isInput:C.includes(Number(F.id)),isConsumer:d.includes(Number(F.id)),setHoverBlock:c},`block-${F.id}`)})},F.id)}),b&&jsx(xg,{section:e$1,columnIndex:I,columns:y}),G.placeholder]})},I)}),jsx(SA,{active:l&&b})]})}),jsx(vA,{columns:y,section:e$1,show:b&&!T$1})]})}),jsx(xA,{onActivate:o,section:e$1,show:!b})]})]})}var Cg=cb(CA,Ea$1);function LA(e,t){let o=document.getElementById(t),n=90;if(o){let i=o.getBoundingClientRect().top+e.current.scrollTop-n;e.current.scrollTo({top:i,behavior:"smooth"});}}function BA(e,t,o){let n=document.getElementById(`bespoke-${t}-${o}`),r=60;if(n){let s=n.getBoundingClientRect().top+e.current.scrollTop-r;e.current.scrollTo({top:s,behavior:"smooth"});}}function zA({section:e,onEnd:t}){let[o,n]=useState(e.settings?.name||`section-${e.id}`),r=s=>{[13,27].includes(s.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:s=>n(s.target.value),onKeyDown:r})}var NA=forwardRef(function({scrollContainer:t,section:o,isActive:n,...r},i$1){let s=va$1(k=>k?.records.entities.block),{settings:l,updateSettings:a}=h(o.id),u=useMantineTheme(),[c,p]=useState(false),[f,m]=useState(false),g=va$1(k=>{let R=o.blocks.map(B=>k.records.entities.block[B]).filter(B=>W(B));return R.length>0?k.variables.variables[R[0].id]:false}),S=g?u.colors[g[T]===false?"red":"green"][3]:"",v=useCallback(k=>{a("name",k),m(false);},[a]),h$1=useRef(false);useEffect(()=>{p(!!n);},[n]);let b=useMemo(()=>l?.name?i(l?.name):`section-${o.id}`,[o.id,l?.name]),C=useMemo(()=>l?.name||`section-${o.id}`,[o.id,l?.name]),d=k=>{k.detail===1&&(h$1.current=false,setTimeout(()=>{h$1.current||LA(t,b);},200)),k.detail===2&&(h$1.current=true,m(R=>!R));},y=n?u.colors.blue[5]:"black",x=o?.blocks.map(k=>s[k]).filter(k=>![z.GENERATOR,z.SECTION_FLAG].includes(k.type)).map(k=>{let R=N[k.type]||IconDice;return jsx(List.Item,{pl:"lg",sx:{border:"1px solid transparent","&:hover":{border:"1px solid blue",cursor:"default"}},icon:jsx(R,{size:"0.8rem"}),onClick:()=>BA(t,k.type,k.id),children:jsx(Text,{size:"sm",children:`${k.type} ${k.id}`})},k.id)});return jsxs(List.Item,{ref:i$1,w:"100%",...r,children:[jsxs(Group,{position:"apart",noWrap:true,px:"sm",bg:n?u.colors.gray[2]:"transparent",sx:k=>({cursor:"default",border:`1px solid ${n?k.colors.gray[2]:"transparent"}`,".section-icon":{color:y},":hover":{border:`1px solid ${k.colors.blue[5]}`}}),children:[jsxs(Group,{spacing:"xs",miw:0,onClick:d,noWrap:true,children:[jsx(IconBoxMultiple,{className:"section-icon",size:"0.8rem",style:{flexShrink:0}}),f?jsx(zA,{section:o,onEnd:v}):jsxs(Group,{spacing:4,align:"flex-end",children:[jsxs(Text,{size:"sm",fw:500,color:"gray.5",span:true,children:[o.id," -"]}),jsx(Text,{size:"sm",c:y,maw:220,sx:{whiteSpace:"nowrap",textOverflow:"ellipsis",overflow:"hidden"},span:true,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:S,fill:S}),x.length&&jsx(IconChevronDown,{size:"0.8rem",style:{transform:`rotate(${c?-180:0}deg)`,flexShrink:0},onClick:()=>p(k=>!k)})]})]}),c&&x.length?jsx(List,{listStyleType:"none",children:x}):null]})}),wg=NA;function Wc({activeSection:e$1,scrollContainer:t}){let o=va$1(l=>l?.records.entities.section),n=ua(),r=Object.values(o).sort(c$1),i=r.map(l=>l?.id),s=useCallback(l=>{if(!l.destination||l.source.index===l.destination.index)return;let a=Number.parseInt(l.draggableId,10),u=l.destination.index>l.source.index,c=e(o,i,l.destination.index,false,u),p=i.slice(),f=p.splice(l.source.index,1);p.splice(l.destination.index,0,...f),n(ta$1.updateEntity("section",{id:a,ordering:c}));},[n,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:true,children:[jsx(IconIndentIncrease,{size:"1rem"}),jsx(Text,{ml:"xs",span:true,children:"Navigation"})]})}),jsx(DragDropContext,{onDragEnd:s,children:jsx(List,{styles:{itemWrapper:{width:"100%"}},mt:"sm",listStyleType:"none",children:jsx(Droppable,{droppableId:"sections",children:l=>jsx("div",{ref:l.innerRef,...l.droppableProps,children:r.map((a,u)=>jsx(Draggable,{draggableId:`${a?.id}`,index:u,children:c=>jsx(wg,{scrollContainer:t,ref:c.innerRef,section:a,isActive:a.id===e$1,...c.draggableProps,...c.dragHandleProps})},a?.id))})})})})]})}var JA=e=>t=>Object.values(t.records.entities.block||{}).filter(o=>o.section_id===e&&z.GENERATOR===o.type);function Kc({activeSection:e}){let t=va$1(JA(e)),o=ua(),n=()=>{let{locales:r}=N$1({type:z.GENERATOR});o(ta$1.createEntity("block",{blockrow:void 0,blockcol:void 0,type:z.GENERATOR,section_id:e,locales:r})).then(i=>{o(ta$1.updateEntity("block",{id:i.data.id,contentByLocale:{logic:{...i.data.contentByLocale.logic,content:{simpleEnabled:true,simple:{},logic:U}}}}));});};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:n,children:jsx(IconPlus,{})})]}),t.length?t.map(r=>jsx("div",{children:jsx(sr,{id:Number(r.id),active:!!e,isInput:false,isConsumer:false,setHoverBlock:()=>{},showOutline:false})},`block-${r.id}`)):jsx(Text,{align:"center",size:"sm",children:"Click '+' to add a generator"})]})})}function Lg({sectionId:e}){let[t,o]=useState(window.innerWidth-40),[n,r]=useState(window.innerHeight-150);useEffect(()=>{let g=()=>{o(window.innerWidth-40),r(window.innerHeight-120);};return window.addEventListener("resize",g),()=>{window.removeEventListener("resize",g);}},[]);let i=Aa$1(),s=za$1(),[l,a]=useState(`${e}`),u=useMemo(()=>s.isSuccess?s.data.map(S=>({value:`${S.id}`,label:S.settings.name?`${S.settings.name} (${S.id})`:`Section ${S.id}`})):[],[s.isLoading]),c=useMemo(()=>{if(i.isSuccess&&l){let g={id:"root",label:"section",size:40,parentIds:[]},S={id:"wide",label:"report",size:40,parentIds:[]},v=i.data.filter(b=>`${b.section_id}`==`${l}`),h=v.map(b=>b.id);return [g,S,...v.map(b=>{let C=b.consumers.length>0?b.consumers.length*20:40,d=b.inputs.length>0?b.inputs.map(y=>h.includes(y)?`${y}`:`${S.id}`):[`${g.id}`];return {id:`${b.id}`,label:`${b.type}`,size:C>50?50:C,parentIds:[...Array.from(new Set(d))]}})]}else return []},[i.isLoading,l]),p=useRef(null);return useEffect(()=>{let g=ds.dagStratify()(c),S=40,v=ds.sugiyama().nodeSize(M=>{let I=M?M.data:null,O=I?I.size:S;return [(M?3.6:.25)*O,3*O]}),{width:h,height:b}=v(g),C=Ut.select(p.current);C.selectAll("*").remove(),C.attr("viewBox",[0,0,h,b].join(" "));let d=C.append("defs"),y=g.size(),x=Ut.interpolateRainbow,k=new Map;c.forEach((M,I)=>{k.set(M.id,x(I/y));});let R=Ut.line().curve(Ut.curveCatmullRom).x(M=>M.x).y(M=>M.y);C.append("g").selectAll("g").data(g.links()).enter().append("g").append("path").attr("class","curve").attr("d",({points:M})=>R(M)).attr("fill","none").attr("stroke-width",3).attr("stroke",({source:M,target:I})=>{let O=encodeURIComponent(`${M.data.id}--${I.data.id}`),G=d.append("linearGradient").attr("id",O).attr("gradientUnits","userSpaceOnUse").attr("x1",M.x).attr("x2",I.x).attr("y1",M.y).attr("y2",I.y);return G.append("stop").attr("offset","0%").attr("stop-color",k.get(M.data.id)),G.append("stop").attr("offset","100%").attr("stop-color",k.get(I.data.id)),`url(#${O})`}),C.append("g").selectAll("g").data(g.descendants()).enter().append("g").attr("transform",({x:M,y:I})=>`translate(${M}, ${I})`).append("circle").attr("r",M=>M.data.size).attr("fill",M=>k.get(M.data.id));let $=C.append("g").selectAll("g").data(g.links()).enter().append("g"),K=Ut.symbol().type(Ut.symbolTriangle).size(S*1.5);$.append("path").attr("class","arrow").attr("d",K).attr("transform",M=>{let{points:I,target:O}=M,[G,W]=I.reverse(),F=W.x-G.x,L=W.y-G.y,U=O.data.size*1/Math.sqrt(F*F+L*L),P=Math.atan2(-L,-F)*180/Math.PI+90;return `translate(${G.x+F*U}, ${G.y+L*U}) rotate(${P})`}).attr("fill",({target:M})=>k.get(M.data.id)).attr("stroke","white");let T=C.append("g").selectAll("g").data(g.descendants()).enter().append("g").attr("transform",({x:M,y:I})=>`translate(${M}, ${I})`);T.append("text").text(M=>M.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"),T.append("text").text(M=>M.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:l,onChange:a,data:u,width:"80%"}),jsxs(Group,{grow:true,maw:100,children:[jsx(ActionIcon,{onClick:()=>{let g=u.findIndex(S=>S.value===l);g>0&&a(u[g-1].value);},variant:"outline",children:jsx(IconChevronLeft,{size:"1.125rem"})}),jsx(ActionIcon,{onClick:()=>{let g=u.findIndex(S=>S.value===l);g<u.length-1&&a(u[g+1].value);},variant:"outline",children:jsx(IconChevronRight,{size:"1.125rem"})})]})]}),jsx("svg",{ref:p,width:t,height:n})]})}function Bg({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(l,{id:t,variables:o})]})]})}function hP({sectionId:e}){let[t,o]=useDisclosure(false);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:true,children:jsx(Lg,{sectionId:e})})]})}function bP({activeSection:e}){let t=va$1(i=>i.records.entities.block),o=va$1(i=>i.variables.attributes),n=va$1(i=>i.variables.variables),r=Object.values(t).filter(i=>(i.section_id===e||i.shared)&&Object.keys(n[i.id]||{}).length);return jsxs(Box,{px:"sm",w:"100%",children:[jsx(Text,{fw:700,size:"sm",children:jsxs(Center,{inline:true,children:[jsx(IconCodeDots,{size:"1rem"}),jsx(Text,{ml:"xs",span:true,children:"Variables"})]})}),jsx(ScrollArea.Autosize,{mah:"40vh",mx:"sm",w:"240px",children:jsxs(Stack,{mt:"sm",children:[jsx(Bg,{name:"Report Variables",id:"attributes",variables:o}),r.map(i=>jsx(Bg,{id:i.id,name:`${i.type} ${i.id}`,variables:n[i.id]},i.id))]})})]})}function yP(){return jsx(Title,{children:"Formatters"})}var vP={section:[{label:"Navigation",value:"navigation"},{label:"Generators",value:"generators"}]};function Zc({scrollContainer:e}){let{opened:t,handlers:o}=Za("tools"),{toggle:n}=o,[r,i]=useState("navigation"),{activeEntity:s}=Ka(),l=c=>i(c),a=s.type==="section"?s.id:null,u=t&&jsxs(Fragment,{children:[a&&jsx(SegmentedControl,{sx:{flexShrink:0},data:vP.section,value:r,onChange:l}),jsxs(Stack,{sx:{flexGrow:1},spacing:"sm",mt:32,children:[(r==="navigation"||!a)&&jsx(Wc,{activeSection:a,scrollContainer:e}),r==="generators"&&a&&jsx(Kc,{activeSection:a}),r==="variables"&&jsx(bP,{activeSection:a}),r==="formatters"&&jsx(yP,{})]})]});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:[s.type==="section"&&t&&jsx(hP,{sectionId:a}),jsx(UnstyledButton,{onClick:n,sx:{transform:`rotate(${t?0:180}deg)`},children:jsx(IconChevronLeft,{size:24})})]})]})}function wP({activeSection:e}){let{settings:t,updateSettings:o}=h(e),n=t.name||`section-${e}`,[r,i]=useState(n),[s,l]=useState(false);return jsx(TextInput,{label:"Section Name",description:"Section name. Only for organization purposes. Won't be displayed on the final report.",value:s?r:n,onChange:a=>i(a.target.value),onFocusCapture:()=>{i(n),l(true);},onBlurCapture:()=>{o("name",r),l(false);},withAsterisk:true,radius:2})}function EP({activeSection:e}){let{settings:t,updateSettings:o}=h(e),n=t.tags,r=va$1(a=>e&&a.records.entities.section[e]),i=va$1(a=>e&&r?Object.values(a.records.entities.section).filter(u=>u&&u.report_id===r.report_id):[]),s=useMemo(()=>{let a=new Set;return i.forEach(u=>{let c=u?.settings?.tags;c&&(Array.isArray(c)?c.forEach(p=>p&&a.add(p)):typeof c=="string"&&c.split(/\s+/).forEach(p=>p&&a.add(p)));}),Array.from(a).sort()},[i]),l=useMemo(()=>n?Array.isArray(n)?n:typeof n=="string"?n.split(/\s+/).filter(Boolean):[]:[],[n]);return jsx(MultiSelect,{label:"Section Tags",description:"Section tags. They will be appended to the dom element as data attributes.",placeholder:"Select or create tags",data:s,value:l,onChange:a=>o("tags",a),radius:2,searchable:true,creatable:true,getCreateLabel:a=>`+ Create ${a}`})}function eu(){let{activeEntity:e}=Ka(),t=e.id,o=va$1(y=>t&&y.records.entities.section[t]),n=va$1(y=>t&&o&&y.records.entities.report[o.report_id]),r=va$1(y=>{if(t&&o){let x=o.blocks.map(k=>y.records.entities.block[k]).filter(k=>W(k));return x.length>1&&console.error(`Error, there is more than one section flag generator in section ${e.id}`),x.length>0?x[0]:false}return false}),i=ua(),s=useContext(db$1),l=Ya(s),a=f(),u=y=>{y==="always"&&r?c(r.id):y==="section-flag"&&p();},c=y=>{i(ta$1.deleteEntity("block",y)).then(()=>{l(),console.info(`Flag generator with ID ${y} deleted.`);});},p=()=>{let{locales:y}=N$1({type:z.SECTION_FLAG});i(ta$1.createEntity("block",{blockrow:void 0,blockcol:void 0,type:z.SECTION_FLAG,section_id:t,locales:y})).then(x=>{i(ta$1.updateEntity("block",{id:x.data.id,contentByLocale:{logic:{...x.data.contentByLocale.logic,content:{simpleEnabled:true,simple:{},logic:`return {
33
+ ) Avoid this, please.`:false},[m,n,r]);if(!c)return null;let y=Object.keys(m),x=k=>k&&Array.isArray(k)&&k.length;return jsxs(Fragment,{children:[jsx(Select,{label:"Options List Variable",placeholder:"Pick a variable",value:x(y)&&n,required:true,onChange:C,data:y}),jsx(Select,{label:"Options ID Key",placeholder:"Pick a property key",value:x(v)&&r,required:!s,disabled:s,onChange:k=>b("idKey",k),data:v,error:d}),jsx(Select,{label:"Options Label Key",placeholder:"Pick a property key",disabled:s,clearable:true,value:x(v)&&i,onChange:k=>b("labelKey",k),data:v}),jsx(Select,{label:"Options Image Key",placeholder:"Pick a property key",disabled:s,clearable:true,value:x(v)&&l,onChange:k=>b("imageKey",k),data:v}),jsx(Select,{label:"Default ID Variable",placeholder:"Pick a variable",clearable:true,value:x(g)&&a,onChange:k=>b("defaultVar",k),data:g})]})}function ir(e,t,o){return e&&e[t]||o}function k0(e){let{id:t,executeButton:o,onChange:n,simpleState:r,referenceContent:i,referenceLocale:a,variables:l}=e,[s,u]=useState(()=>{let m=r&&r.options&&Object.prototype.hasOwnProperty.call(r?.options,"dynamic")&&Object.prototype.hasOwnProperty.call(r?.options,"static");return {selectorIdentifier:ir(r,"name",""),selectorType:ir(r,"type",hn.SINGLE),selectorComponent:ir(r,"component",nc.SELECTOR),options:r&&m?r.options:{static:[],dynamic:{}},optionsType:ir(r,"optionsType","static"),hideLabel:ir(r,"hideLabel","false"),resetSectionVars:ir(r,"resetSectionVars","false")}});useEffect(()=>{let{selectorIdentifier:m,selectorType:f,selectorComponent:g,options:S,optionsType:v,hideLabel:h,resetSectionVars:b}=s,C={name:m,hideLabel:h,resetSectionVars:b,component:g,type:f},{logicOptions:d,defaultValue:y}=Ga(f,S,v);y&&(C.defaultValue=y),C.options=d;let x=`return ${Yn(C)};`,k={name:m,type:f,component:g,hideLabel:h,resetSectionVars:b,defaultValue:y,optionsType:v,options:S},R=Cf(k);n(k,x,R);},[s]);let c=(m,f)=>u(g=>({...g,[m]:f})),p=B[z.SELECTOR].find(m=>m.field===A.SELECTOR_NAME)?.editorConfig;return jsxs(Fragment,{children:[jsxs(Stack,{children:[jsx(Et,{field:"name",value:s.selectorIdentifier,handleEditor:(m,f)=>c("selectorIdentifier",f),referenceContent:i,referenceLocale:a,variables:l,editorConfig:p}),jsx(Checkbox,{label:jsx(Ke,{label:"Hide Label",py:0}),checked:s.hideLabel==="true",onChange:m=>c("hideLabel",m.currentTarget.checked?"true":"false")})]}),jsx(Select,{label:jsx(Ke,{label:"Selector Type"}),value:s.selectorType,onChange:m=>c("selectorType",m),data:Object.values(hn)}),s.selectorType===hn.SINGLE&&jsx(Select,{label:jsx(Ke,{label:"Selector Component"}),value:s.selectorComponent,onChange:m=>c("selectorComponent",m),data:Object.values(nc)}),jsx(Select,{label:jsx(Ke,{label:"Options Type"}),value:s.optionsType,onChange:m=>c("optionsType",m),data:Object.values(Fo)}),s.optionsType===Fo.STATIC?jsx(x0,{staticOptions:s.options.static,setStaticOptions:m=>c("options",{...s.options,static:m})}):jsx(C0,{dynamicOptions:s.options.dynamic,setDynamicOptions:m=>c("options",{...s.options,dynamic:m}),id:t}),jsx(Checkbox,{my:"md",label:jsx(Ke,{label:"Reset SectionVariables on change",py:0}),checked:s.resetSectionVars==="true",onChange:m=>c("resetSectionVars",m.currentTarget.checked?"true":"false")}),o]})}var wf=k0;var If=["xs","sm","md","lg","xl"],z0=["0","1","2","3","4","5"],Eo={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"}},N0=forwardRef(({value:e,iconType:t="tabler",...o},n)=>jsx("div",{ref:n,...o,children:jsxs(Group,{noWrap:true,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 bn(e){let[t,o]=useState(e?._iconType??"none"),[n,r]=useState(e?._icon??""),[i,a]=useState([]),[l,s]=useState(""),[u,c]=useState(e?._iconVariant??"transparent"),[p,m]=useState(e?._iconSize??"md"),[f,g]=useState(e?._iconRadius??"md"),[S,v]=useState(e?._iconPadding??"1"),h=[Eo.none.value,Eo.custom.value].includes(t),b=useRef(null),C=useMemo(()=>({_icon:n,_iconType:t,_defaultIcon:l,_iconVariant:u,_iconSize:p,_iconRadius:f,_iconPadding:S}),[n,t,l,u,p,f,S]),d=x=>{r(""),o(x);};useEffect(()=>{h||Gh.get(`/api/cms/list/icons/${t}`).then(x=>{a(x.data.data.results),s(x.data.data.results[0]);});},[t]);let y=jsx(Accordion,{variant:"separated",children:jsxs(Accordion.Item,{value:"icon",children:[jsx(Accordion.Control,{icon:jsx(IconPhotoFilled,{}),children:jsxs(Text,{children:["Icon configuration: ",Eo[t]&&jsx("strong",{children:Eo[t].label})]})}),jsx(Accordion.Panel,{children:jsxs(Stack,{children:[jsx(Input.Wrapper,{label:"Title's icon",children:jsx(SegmentedControl,{fullWidth:true,value:t,onChange:d,data:Object.values(Eo)})}),!h&&jsx(Select,{label:"Choose an icon from the list",searchable:true,description:jsxs(Fragment,{children:["Powered by"," ",jsx("a",{style:{textDecoration:"underline"},href:Eo[t].link,target:"_blank",rel:"noreferrer",children:Eo[t].text}),"."]}),defaultValue:l,value:n,required:true,onChange:x=>r(x||""),data:i,limit:10,itemComponent:N0,disabled:!i||i.length===0,icon:jsx(Image,{p:5,src:`/api/cms/read/icons/${t}/icon.svg?name=${n||l}`,alt:"Icon preview"})}),t===Eo.custom.value&&jsxs(Flex,{align:"flex-end",children:[jsx(TextInput,{ref:b,placeholder:"e.g '/image{{id1}}.png' or 'http://site/image.png'",label:"Enter an icon path",required:true,defaultValue:n,description:"Add an absolute or a relative path url",onBlur:x=>r(x.currentTarget.value),sx:{flexGrow:1}}),jsx(ActionIcon,{maw:36,size:36,onClick:()=>b.current?r(b.current.value??""):void 0,sx:{flexGrow:0},children:jsx(IconFileUpload,{})})]}),t!==Eo.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:true,onChange:x=>c(x||"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:true,value:p,onChange:m,data:If})}),jsx(Input.Wrapper,{label:"Radius",children:jsx(SegmentedControl,{fullWidth:true,value:f,onChange:g,data:If})}),jsx(Input.Wrapper,{label:"Padding",children:jsx(SegmentedControl,{fullWidth:true,value:S,onChange:v,data:z0})})]})]})})]})});return {simpleIconState:C,panel:y}}function Uo(e,t){let[o,n]=useState({...t,...e});return {state:o,updateState:(i,a)=>{let l={...o,[i]:a};n(l);}}}var U0={type:"list",title:"",shotTitle:""},H0=[{value:"list",label:"List"},{value:"multilevel",label:"Multilevel"}];function uc({simpleState:e,onChange:t,variables:o,referenceContent:n,referenceLocale:r}){let{state:i,updateState:a}=Uo(e,U0),{simpleIconState:l,panel:s}=bn(e);return useEffect(()=>{let u={...i,...l},c=ro(u);t(u,c);},[i,l]),jsxs(Stack,{children:[jsx(Title,{order:4,children:"Nav UI"}),jsx(Select,{label:"Nav Type",data:H0,value:i.type,defaultValue:"list",onChange:u=>a("type",u)}),B[z.NAV].map(({field:u,editorConfig:c})=>jsx(Et,{field:u,value:i[u],handleEditor:a,referenceContent:n,referenceLocale:r,variables:o,editorConfig:c},u)),s]})}function pc({executeButton:e,onChange:t,simpleState:o}){let[n,r]=useState(o?.compare??"variant"),[i,a]=useState(o?.limit??4);return useEffect(()=>{t({compare:n,limit:i});},[n,i]),jsxs(Stack,{children:[jsx(Radio.Group,{description:"Valid only for single-dimensional profiles",label:"Compare with members of:",onChange:r,value:n,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:l=>a(l),type:"number",value:i}),e]})}function mc({executeButton:e,onChange:t,simpleState:o}){let[n,r]=useState(o?.label??""),[i,a]=useState(o?.showIcon??true),[l,s]=useState(o?.fullWidth??false),[u,c]=useState(o?.showWhenDisabled??false);return useEffect(()=>{t({label:n,showIcon:i,fullWidth:l,showWhenDisabled:u});},[n,i,l,u,t]),jsxs(Stack,{children:[jsx(TextInput,{placeholder:"Label for reset section state button",value:n,onChange:p=>r(p.target.value),label:"Label"}),jsxs(Group,{children:[jsx(Switch,{checked:i,label:"Show icon",onChange:p=>a(p.currentTarget.checked)}),jsx(Switch,{checked:l,label:"Full width",onChange:p=>s(p.currentTarget.checked)}),jsx(Switch,{checked:u,label:"Show when disabled",onChange:p=>c(p.currentTarget.checked)})]}),e]})}var oE={title:"Title",tooltip:"",slug:""};function fc({onChange:e,simpleState:t,variables:o,referenceContent:n,referenceLocale:r}){let{state:i,updateState:a}=Uo(t,oE),{simpleIconState:l,panel:s}=bn(t);return useEffect(()=>{let u={...i,...l},c=ro(u);e(u,c);},[l,i]),jsxs(Stack,{children:[B[z.TITLE].map(({field:u,editorConfig:c})=>jsx(Et,{field:u,value:i[u],handleEditor:a,referenceContent:n,referenceLocale:r,variables:o,editorConfig:c},u)),s]})}var uE=[{value:"left",label:"Left"},{value:"center",label:"Center"},{value:"right",label:"Right"}];function gc({executeButton:e,onChange:t,simpleState:o}){let[n,r]=useState(o?.label??""),[i,a]=useState(o?.removeLabel??""),[l,s]=useState(o?.showIcon??true),[u,c]=useState(o?.position??"center");return useEffect(()=>{t({label:n,removeLabel:i,showIcon:l,position:u});},[n,l,i,u,t]),jsxs(Stack,{children:[jsx(TextInput,{placeholder:"Label for comparison button",value:n,onChange:p=>r(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:l,label:"Show icon",onChange:p=>s(p.currentTarget.checked)})}),jsx(Select,{label:"Button position",data:uE,value:u,onChange:c}),e]})}function hc({simpleState:e,onChange:t,variables:o,referenceContent:n,referenceLocale:r}){let{state:i,updateState:a}=Uo(e,{title:"",value:"",subtitle:"",tooltip:""}),{simpleIconState:l,panel:s}=bn(e);return useEffect(()=>{let u={...i,...l},c=ro(u);t(u,c);},[l,i]),jsxs(Stack,{children:[B[z.STAT].map(({field:u,editorConfig:c})=>jsx(Et,{field:u,value:i[u],handleEditor:a,referenceContent:n,referenceLocale:r,variables:o,editorConfig:c},u)),s]})}var DE={enableBottomToolbar:true,enableColumnActions:true,enableColumnFilters:true,enableColumnResizing:true,enableDensityToggle:true,enableFullScreenToggle:false,enableGlobalFilter:true,enableHiding:true,enablePagination:true,enableSorting:true,enableStickyHeader:true,enableTopToolbar:true},Nf={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."}},LE={density:"xs"},Vf=["5","10","15","20","25","30","50","100"],Ff={pageIndex:0,pageSize:10},_f=e=>e&&Array.isArray(e)&&e.some(t=>typeof t=="object"&&t!==null),BE=forwardRef(function({customLabels:t,customLabelsHandler:o,index:n,isActiveRefenceContent:r=false,option:i,referenceColumns:a=[],selectedColumnsHandler:l,...s},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:true,ref:u,...s,children:[jsxs(Group,{children:[jsx(IconGripVertical,{}),jsx(Checkbox,{checked:i.checked,label:i.label,onChange:f=>l.setItemProp(n,"checked",f.currentTarget.checked)})]}),jsx(Input,{disabled:!i.checked,onChange:f=>o.setItemProp(n,"label",f.currentTarget.value),value:c}),r&&jsx(Input,{disabled:true,value:m})]},`table-group-${i.label}-${n}`)});function Cc(e){let{executeButton:t,id:o,onChange:n,referenceContent:r={},referenceLocale:i,simpleState:a}=e,{columns:l}=r,s=_a(),u=useMemo(()=>s!==i&&r&&Object.keys(r).length>0,[s,r,i]),c=La$1(o),[p,m]=useState([]),[f,g]=useListState([]),[S,v]=useState([]),[h,b]=useState(false),[C,d]=useState({}),[y,x]=useState(Ff),[k,R]=useState({rowsPerPageOptions:Vf}),[B,N]=useListState([]),[$,K]=useState(null),[T,M]=useSetState(DE),[I,O]=useState(LE),[G,W]=useState({}),F=useMemo(()=>B.every(A=>A.checked),[B]),L=useMemo(()=>B.some(A=>A.checked)&&!F,[F,B]);useEffect(()=>{if(!a||!Object.keys(a).length)return;let A=c[a.variable]||[],_=new Set;A.filter(z=>typeof z=="object"&&z!==null).forEach(z=>{Object.keys(z).forEach(X=>_.add(X));});let Q={},Y=[];a.columns&&Object.keys(a.columns)&&a.columns.forEach(z=>{Q[z.accessorKey]=z.header;});let ce=[],re=[];Array.from(_).forEach(z=>{re.push({key:z,label:Q[z]||z}),ce.push({checked:!!Q[z],key:randomId(),label:z}),Y.push(z);}),g.setState(re),N.setState(ce);let{initialState:ae={},state:fe={},mantinePaginationProps:ht={},...Tt}=a.tableProps||{},Rt=fe.columnOrder.filter(z=>Y.includes(z));Rt.push(Y.filter(z=>!fe.columnOrder.includes(z))),m(Rt.flat()||[]),R(ht),x(ae.pagination),M({...Tt}),W(fe),O(ae),K(a.variable||"");},[]),useEffect(()=>{if(!c){d({});return}let A=Object.entries(c).filter(([Q,Y])=>_f(Y)).reduce((Q,[Y,ce])=>(Q[Y]=ce,Q),{});d(A);let _=Object.keys(A);v(_);},[c]);let U=A=>{if(K(A),!A||!_f(C[A])){b(false),N.setState([]);return}let _=C[A];if(_.every(ae=>typeof ae=="object"&&ae===null)){b(false),N.setState([]);return}_.every(ae=>typeof ae=="object"&&ae!==null)?b(false):b(true);let Q=new Set;_.filter(ae=>typeof ae=="object"&&ae!==null).forEach(ae=>{Object.keys(ae).forEach(fe=>Q.add(fe));});let Y=[],ce=[],re=[];Array.from(Q).forEach(ae=>{Y.push({checked:true,key:randomId(),label:ae}),ce.push({key:ae,label:ae}),re.push(ae);}),N.setState(Y),g.setState(ce),m(re);};useEffect(()=>{let A={};f.forEach(fe=>{A[fe.key]=fe.label;});let _=B.filter(fe=>fe.checked).map(fe=>({accessorKey:fe.label,header:A[fe.label]})),Q={...I,pagination:y},Y={...G,columnOrder:p},ce={columns:_,data:$?`variables["${$}"]`:[],tableProps:{...T,initialState:Q,state:Y,mantinePaginationProps:k},variable:$||""},re=`return ${Yn(ce)};`,ae={columns:_,data:$?`variables["${$}"]`:[],tableProps:{...T,initialState:Q,state:Y,mantinePaginationProps:k},variable:$||""};n(ae,re);},[p,f,k,y,B,$,T,G,I]);let P=useCallback(A=>{if(!A.destination||A.source.index===A.destination.index)return;let _=[...p],[Q]=_.splice(A.source.index,1);_.splice(A.destination.index,0,Q),m(_),W(Y=>{let ce=Y;return ce.columnOrder=_,ce});},[p]);return jsxs(Fragment,{children:[jsxs(Stack,{mb:"sm",children:[jsx(Select,{clearable:true,data:S,description:"Select an array of data available in the block inputs to use as data input for the table.",label:"Data input",onChange:A=>U(A),searchable:true,value:$}),$&&C[$]&&B.length>0&&jsxs(Fragment,{children:[jsx(Input.Wrapper,{description:"Select the columns to display in the table.",error:h&&"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:true,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:F,indeterminate:L,label:"All",onChange:()=>N.setState(A=>A.map(_=>({..._,checked:!F})))}),jsx(ScrollArea.Autosize,{mah:300,children:jsx(DragDropContext,{onDragEnd:P,children:jsx(Droppable,{droppableId:"columns",children:A=>jsx("div",{ref:A.innerRef,...A.droppableProps,children:p.map((_,Q)=>{let Y=B.findIndex(re=>re.label===_),ce=B[Y];return jsx(Draggable,{draggableId:`${ce.label}`,index:Q,isDragDisabled:!ce.checked,children:re=>jsx(BE,{customLabels:f,customLabelsHandler:g,index:Y,isActiveRefenceContent:u,option:ce,ref:re.innerRef,referenceColumns:l,selectedColumnsHandler:N,...re.draggableProps,...re.dragHandleProps})},ce.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(T).map(A=>jsx(Checkbox,{checked:T[A],label:jsx(Tooltip,{label:Nf[A]?.desc||A,multiline:true,children:jsx(Text,{children:Nf[A]?.label||A})}),onChange:()=>M({[A]:!T[A]})},`table-prop-${A}`))}),T?.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:true,children:[jsx(NumberInput,{label:"Initial page",min:0,onChange:A=>{x(_=>({..._,pageIndex:A}));},value:y.pageIndex}),jsx(Select,{data:k.rowsPerPageOptions||[],getCreateLabel:A=>`+ Create ${A}`,label:"Initial page size",onChange:A=>{x(_=>({..._,pageSize:parseInt(A,10)}));},searchable:true,value:y.pageSize.toString()})]}),jsxs(Group,{align:"flex-end",grow:true,children:[jsx(MultiSelect,{clearable:true,creatable:true,data:k.rowsPerPageOptions||[],getCreateLabel:A=>`+ Create ${A}`,label:"Page size options",onChange:A=>{R(_=>({..._,rowsPerPageOptions:A.sort((Q,Y)=>parseInt(Q,10)-parseInt(Y,10))})),A&&A.length>0&&!A.includes(y.pageSize.toString())&&x(_=>({..._,pageSize:parseInt(A[0],10)}));},onCreate:A=>(R(_=>({..._,rowsPerPageOptions:[..._.rowsPerPageOptions||[],A].sort((Q,Y)=>parseInt(Q,10)-parseInt(Y,10))})),A),searchable:true,value:k.rowsPerPageOptions||[]}),jsx(Button,{color:"yellow",onClick:()=>{R(A=>({...A,rowsPerPageOptions:Vf})),x(Ff);},children:"Reset page sizes values"})]})]})]})]})})})]})})]})]}),t]})}var $f=e=>{let{dataVar:t,levelsVar:o}=e;return !![t,o].every(Boolean)},Qa=e=>{let t,o,{colorKey:n,dataVar:r,iconKey:i,defaultVar:a,isPrimitiveType:l,levelsVar:s,searchIndexKey:u}=e;a&&typeof a=="string"&&(t=`variables["${a}"].value`,o=`variables["${a}"].type`);let c=l?`variables["${r}"]`:`(variables["${r}"] || []).map((d) => ({...d, colorKey: String(d["${n}"]), iconKey: String(d["${i}"]), searchIndexKey: String(d["${u}"])}))`;return {logicLevels:`variables["${s}"]`,logicOptions:c,defaultValue:t,defaultValueType:o}};var Tc=e=>B[z.MULTIHIERARCHY_SELECTOR].find(t=>t.field===e)?.editorConfig,VE=e=>e&&Array.isArray(e)&&e.some(t=>typeof t=="object"&&t!==null),FE=e=>e&&e.type&&e.value,lr=e=>e&&Array.isArray(e)&&e.length;function St(e,t,o){return e&&e[t]||o}function wc(e){let{executeButton:t,id:o,onChange:n,referenceContent:r,referenceLocale:i,simpleState:a}=e,l=La$1(o),[s,u]=useState(false),[c,p]=useState(()=>({allLabel:St(a,"allLabel","All"),colorKey:St(a,"colorKey",""),dataVar:St(a,"dataVar",""),defaultVar:St(a,"defaultVar",""),hideLabel:St(a,"hideLabel","false"),resetSectionVars:St(a,"resetSectionVars","false"),iconKey:St(a,"iconKey",""),isPrimitiveType:St(a,"isPrimiteType",false),levelsVar:St(a,"levelsVar",""),limit:St(a,"limit",0),placeholder:St(a,"placeholder",""),searchIndexKey:St(a,"searchIndexKey",""),searchIndexSeparator:St(a,"searchIndexSeparator","|"),selectorIdentifier:St(a,"label","")})),[m,f]=useState([]),[g,S]=useState([]),[v,h]=useState({}),[b,C]=useState({}),[d,y]=useState([]),x=useCallback((T,M,I=false)=>p(O=>({...O,[T]:!M&&I?"":M})),[]);useEffect(()=>{if(!l){f([]),S([]),h({}),C({});return}let T=Object.entries(l).filter(([G,W])=>VE(W)).reduce((G,[W,F])=>(G[W]=F,G),{}),M=Object.entries(l).filter(([,G])=>FE(G)).reduce((G,[W,F])=>(G[W]=F,G),{});C(T),h(M);let I=Object.keys(T),O=Object.keys(M);f(I),S(O),u(true);},[l]),useEffect(()=>{if(!Object.keys(b).length)return;let T=$a(b[c.dataVar]);if(T)y([]),x("colorKey",""),x("iconKey",""),x("searchIndexKey","");else {let M=new Set;(b[c.dataVar]||[]).forEach(O=>Object.keys(typeof O=="object"?O:{}).forEach(G=>M.add(G)));let I=Array.from(M).sort().map(O=>O);y(I);}x("isPrimitiveType",T);},[b,c.dataVar]),useEffect(()=>{let{allLabel:T,colorKey:M,dataVar:I,defaultVar:O,hideLabel:G,resetSectionVars:W,iconKey:F,levelsVar:L,limit:U,placeholder:P,searchIndexKey:A,searchIndexSeparator:_,selectorIdentifier:Q}=c,Y={allLabel:T,colorKey:M,dataVar:I,defaultVar:O,label:Q,hideLabel:G,resetSectionVars:W,iconKey:F,levelsVar:L,limit:U,placeholder:P,searchIndexKey:A,searchIndexSeparator:_},{logicOptions:ce,logicLevels:re,defaultValue:ae,defaultValueType:fe}=Qa(Y);ae&&fe&&(Y.defaultValue=ae,Y.defaultValueType=fe),Y.data=ce,Y.levels=re;let ht=`return ${Yn(Y)};`,Tt=Y,Rt=$f(Tt);n(Tt,ht,Rt);},[c]);let k=useCallback(T=>{x("dataVar",T),x("defaultVar",{}),x("colorKey",""),x("iconKey",""),x("searchIndexKey","");},[x]);if(!s)return null;let R=Object.keys(b),B=Object.keys(v),N=Tc(A.MULTIHIERARCHY_SELECTOR_ALL_LABEL),$=Tc(A.MULTIHIERARCHY_SELECTOR_NAME),K=Tc(A.MULTIHIERARCHY_SELECTOR_PLACEHOLDER);return jsxs(Fragment,{children:[jsxs(Stack,{mb:"sm",spacing:"xs",children:[jsx(Et,{field:"label",value:c.selectorIdentifier,handleEditor:(T,M)=>{x("selectorIdentifier",M);},referenceContent:r,referenceLocale:i,variables:l,editorConfig:$}),jsx(Checkbox,{label:jsx(Ke,{label:"Hide Label",py:0}),checked:c.hideLabel==="true",onChange:T=>x("hideLabel",T.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(Ke,{label:"Data Input"}),onChange:T=>k(T),value:lr(R)&&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(Ke,{label:"Levels Input"}),onChange:T=>x("levelsVar",T),value:lr(R)&&c.levelsVar}),jsx(Select,{clearable:true,data:g,description:"(Optional) Select an object with {type, value} keys in the block inputs to use as default value.",label:jsx(Ke,{label:"Default Value"}),onChange:T=>{if(!T){x("defaultVar","");return}x("defaultVar",T);},value:lr(B)&&c.defaultVar}),jsx(NumberInput,{description:"(Optional) Sets a limit for selected values. Set 0 for no limit.",label:jsx(Ke,{label:"Limit"}),min:0,onChange:T=>x("limit",T),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(Et,{field:"allLabel",value:c.allLabel,handleEditor:(T,M)=>x("allLabel",g$1(M)),referenceContent:r,referenceLocale:i,variables:l,editorConfig:N}),jsx(Et,{field:"placeholder",value:c.placeholder,handleEditor:(T,M)=>x("placeholder",g$1(M)),referenceContent:r,referenceLocale:i,variables:l,editorConfig:K}),jsx(Select,{clearable:true,data:d,description:"(Optional) Select a property key to use as item's icon background color. Requires defining an icon key.",disabled:c.isPrimitiveType,label:jsx(Ke,{label:"Color property key"}),onChange:T=>x("colorKey",T,true),value:lr(d)&&c.colorKey}),jsx(Select,{clearable:true,data:d,description:"(Optional) Select a property key to use as item's icon src.",disabled:c.isPrimitiveType,label:jsx(Ke,{label:"Icon property key"}),onChange:T=>x("iconKey",T,true),value:lr(d)&&c.iconKey}),jsx(Select,{clearable:true,data:d,description:"(Optional) Select a property key to extend the search functionality. The selected key MUST only contain text elements.",disabled:c.isPrimitiveType,label:jsx(Ke,{label:"Search index key"}),onChange:T=>x("searchIndexKey",T,true),value:lr(d)&&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(Ke,{label:"Search index separator"}),onChange:T=>x("searchIndexSeparator",T.currentTarget.value),value:c.searchIndexSeparator})]})})]})})]}),jsx(Checkbox,{my:"md",label:jsx(Ke,{label:"Reset SectionVariables on change",py:0}),checked:c.resetSectionVars==="true",onChange:T=>x("resetSectionVars",T.currentTarget.checked?"true":"false")}),t]})}var $E={[z.SELECTOR]:wf,[z.NAV]:uc,[z.RELATED]:pc,[z.RESET_BUTTON]:mc,[z.COMPARISON_BUTTON]:gc,[z.TITLE]:fc,[z.STAT]:hc,[z.TABLE]:Cc,[z.MULTIHIERARCHY_SELECTOR]:wc},jf=$E;function GE(e){let{blockType:t,id:o,locale:n,setBlockContent:r,simpleState:i}=e,a=lo(),l=La$1(o),s=jf[t],u=jsx(Sf,{fields:B[t],locale:n,defaultContent:i,variables:l,onChange:r},"text-editor");return s?jsx(s,{id:o,executeButton:a.executeButton,onChange:(c,p,m=true)=>r({simple:c,logic:p},n,true,m),simpleState:i,richTextEditor:u,variables:l,referenceContent:a.reference.content,referenceLocale:a.reference.locale}):u}var Kf=GE;function QE({id:e,variables:t,reserved:o,hasInternalKeys:n}){let[r,i]=useState(false);return jsxs(Fragment,{children:[n&&jsx(Switch,{label:"Show internal variables",size:"xs",checked:r,onChange:a=>i(a.currentTarget.checked)}),jsx(l,{id:e,variables:t,reserved:o,showInternal:r})]})}function ZE({id:e,setInlineId:t}){let o=va$1(u=>u.records.entities.block),n=ua(),r=Ma$1(e),i=Object.keys(r.attributes),a=useContext(db$1),l=Ya(a),s=u=>{n(ta$1.updateEntity("block",{id:e,inputAction:{operation:"delete",input:{input_id:u,block_id:e}}})).then(()=>{l();});};return jsx("div",{style:{display:"flex",flex:"1 1 auto",flexDirection:"column",width:"100%"},children:Object.keys(r).sort(u=>u==="attributes"?-1:1).map(u=>{let c=o[u],p=c&&[z.GENERATOR,z.SECTION_FLAG].includes(c.type),m=c?.type&&c?.id?`${c.type}${c.id}`:"",f=Object.keys(r[u]).some(k(m));return jsxs(Stack,{className:"cr-variable-group",style:{position:"relative"},children:[jsx(Divider,{}),jsxs(Group,{position:"apart",noWrap:true,grow:true,children:[jsx(Title,{order:6,children:c?`${titleCase(c.type)} ${c.id} Variables`:"Dimension Variables"}),c&&jsxs(Group,{position:"right",noWrap:true,children:[p&&jsx(Tooltip,{label:"Edit this generator",children:jsx(ActionIcon,{size:"xs",onClick:()=>t(u),variant:"subtle",color:"gray",children:jsx(IconPencil,{size:15})})}),jsx(Tooltip,{label:"Remove as input",children:jsx(ActionIcon,{size:"xs",onClick:()=>s(u),variant:"light",color:"red",children:jsx(IconLinkOff,{size:15})})})]})]}),jsx(QE,{id:u,variables:r[u],reserved:i,hasInternalKeys:f})]},u)})})}var Jf=ZE;function gI({blockType:e,fullscreen:t,toggle:o,codeEditor:n}){let r=lo(),i=[z.GENERATOR,z.VIZ].includes(e),[a,{open:l,close:s}]=useDisclosure(false);return jsxs(Fragment,{children:[jsxs(Popover,{width:400,position:"bottom",withArrow:true,shadow:"md",opened:a,children:[jsx(Popover.Target,{children:jsx(ActionIcon,{variant:"subtle",color:"blue",size:"sm",onMouseEnter:l,onMouseLeave:s,pos:"absolute",top:3,left:3,style:{zIndex:1},children:jsx(IconHelp,{size:16})})}),jsx(Popover.Dropdown,{children:jsxs(Text,{size:"sm",children:["You can access ",jsx(Code,{children:"variables"}),", ",jsx(Code,{children:"formatters"}),",",jsx(Code,{children:"locale"}),", ",jsx(Code,{children:"libs"}),",",e===z.GENERATOR&&jsxs(Fragment,{children:[jsx(Code,{children:"resp"}),", "]}),e===z.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."]})]})})]}),n,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:true,children:t?"Minimize":"Maximize"}),r.executeButton]})]})}function hI(){let e=lo(),t=_a(),o=$a$1(),n=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:r=>e.changeEditorMode(r.currentTarget.checked?"code":"simple"),onLabel:jsx(IconCode,{size:rem(12)}),offLabel:jsx(IconCode,{size:rem(12)})}),e.mode!=="code"&&n&&jsx(Switch,{checked:e.reference.active,onChange:r=>e.reference.setActive(r.currentTarget.checked),size:"xs",label:"See reference language",labelPosition:"left",onLabel:jsx(IconLanguage,{size:"0.7rem"}),offLabel:jsx(IconLanguage,{size:"0.7rem"})})]})})}function bI({header:e,blockContent:t,blockSettings:o,blockType:n$1,id:r,locale:i,onSave:a,setBlockContent:l,setBlockSettings:s,setInlineId:u,sid:c}){let[p,m]=useState("Content"),[f,g]=useState(false),[S,v]=useState(false),h=Na$1(r),b=lo(),d=va$1(P=>P.status.isRunConsumersRunning).includes(c),y=useMemo(()=>{let P={resp:null,apiFinalUrls:null,apiDataSources:void 0};return h&&h.resp&&h.apiFinalUrls&&h.apiDataSources&&(P.resp=h.resp,P.apiFinalUrls=h.apiFinalUrls,P.apiDataSources=h.apiDataSources),P},[h]),x=La$1(r),{ref:k,toggle:R,fullscreen:B}=useFullscreen(),N=t&&(t.api||t.api==="")?t.api.split("|||"):[],$=(P,A)=>l({logic:P},A),K=(P,A)=>{let _=[...N];_[A]=P,l({api:_.join("|||")},void 0,void 0,void 0,true);},T=()=>{l({api:[...N,""].join("|||")}),g(true);},M=P=>{l({api:N.length===1&&N[0]===""?null:N.filter((A,_)=>_!==P).join("|||")},void 0,void 0,void 0,true);},I=(P,A)=>{s({[P]:A});},O=()=>{g(!f);},G=()=>{v(!S);},W=jsx(rn,{monacoOptions:{onChange:P=>$(P,i),value:t?.logic||"",height:B?"85vh":"61vh",width:"100%"}},"code-editor"),F=t?.simple||{},L=jsx(Kf,{blockType:n$1,id:r,locale:i,simpleState:F,setBlockContent:l,variables:x}),U=jsx(Col,{span:4,sx:P=>({display:"flex",flexDirection:"column",borderLeft:`2px solid ${P.colors.gray[0]}`}),children:jsxs(Stack,{children:[jsx(Text,{inline:true,size:"xs",transform:"uppercase",weight:"bold",color:"gray",children:"Preview"}),jsx(ma,{id:r,active:true,blockStateContent:t,blockStateSettings:o,locale:i,allowed:true,debug:true},"block-preview")]})});return jsxs(Grid,{h:"100%",children:[jsxs(Col,{span:3,sx:{alignSelf:"stretch",display:"flex",flexDirection:"column",height:"100%",position:"relative"},children:[z.SECTION_FLAG!==n$1&&jsx(Zd,{id:r}),jsx("div",{style:{width:"100%",maxHeight:"80vh",overflowY:"auto"},children:jsx(Jf,{id:r,setInlineId:u})})]}),jsxs(Col,{span:9,sx:P=>({alignSelf:"stretch",display:"flex",flexDirection:"column",height:"100%",borderLeft:`2px solid ${P.colors.gray[0]}`}),children:[e,jsxs(Tabs,{value:p,onTabChange:m,keepMounted:false,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:k,pos:"relative",bg:"white",h:"100%",children:jsxs(Grid,{className:"cr-block-output",style:{flex:1,width:"100%",height:B?"100vh":"100%",margin:0},children:[jsxs(Col,{span:8,className:`cr-block-output-editor ${b.mode}`,children:[![z.VIZ,z.GENERATOR,z.SECTION_FLAG].includes(n$1)&&jsx(hI,{}),[z.GENERATOR,z.SECTION_FLAG].includes(n$1)&&jsxs(Stack,{mb:5,spacing:4,children:[d&&jsx(Overlay,{children:jsx(Text,{children:"Running..."})}),jsxs(Group,{spacing:"xs",children:[jsx(Button,{size:"sm",variant:"light",color:"blue",leftIcon:f?jsx(IconChevronDown,{size:16}):jsx(IconChevronRight,{size:16}),onClick:O,sx:{flex:1},children:`${N.length} API Request${N.length!==1?"s":""}`}),jsx(Button,{size:"sm",onClick:T,variant:"light",color:"blue",leftIcon:jsx(IconPlus,{size:15}),children:"Add API"})]}),jsxs(Collapse,{in:f,children:[N.map((P,A)=>jsx(Gd,{defaultValue:P,pos:A+1,id:r,finalUrl:y.apiFinalUrls&&y.apiFinalUrls[A]?y.apiFinalUrls[A]:null,dataSource:y.apiDataSources&&y.apiDataSources[A]?y.apiDataSources[A]:null,onChangeAPI:_=>K(_,A),onDelete:()=>M(A)},`${r}-${A}-${N.length}`)),y.resp&&jsx(Button,{variant:"light",color:"blue",size:"xs",leftIcon:S?jsx(IconChevronDown,{size:14}):jsx(IconChevronRight,{size:14}),onClick:G,mt:5,children:"Response data preview (resp)"}),y.resp&&jsx(Collapse,{in:S,children:jsx("div",{style:{maxHeight:200,overflowY:"scroll"},children:jsx(j,{value:y.resp,root:true,label:"resp"})})})]})]}),jsxs(Box,{bg:b.mode==="code"?"#272822":"none",p:"xs",pos:"relative",children:[b.mode==="code"&&jsx(gI,{blockType:n$1,fullscreen:B,toggle:R,codeEditor:W}),b.mode!=="code"&&L]})]},"content-col"),U]})})}),jsx(Tabs.Panel,{value:"Style",pt:"xs",children:jsx(Box,{ref:k,pos:"relative",bg:"white",h:"100%",children:jsxs(Grid,{children:[jsxs(Col,{span:8,children:[jsx(Title,{order:4,children:"Style settings"}),jsx(n,{id:r,display:"inline",handleChange:I})]},"content-col"),U]})})}),jsx(Tabs.Panel,{value:"Settings",pt:"xs",children:jsx(Qd,{id:r,setBlockSettings:s})})]})]})]})}var rg=bI;var ig=e=>(!e||!e.contentByLocale||Object.keys(e.contentByLocale).forEach(t=>{let o=e.contentByLocale[t]?.content;o&&Object.keys(o).length===0&&(o.simpleEnabled=true,o.simple={});}),e);var Nc=["_icon","_iconType","_iconVariant","_iconSize","_iconRadius","_iconPadding"],ag={[z.SELECTOR]:["hideLabel","resetSectionVars","component","optionsType","type"],[z.TITLE]:[...Nc],[z.NAV]:[...Nc],[z.STAT]:[...Nc],[z.TABLE]:["data","tableProps","variable"],[z.MULTIHIERARCHY_SELECTOR]:["colorKey","dataVar","defaultVar","hideLabel","resetSectionVars","iconKey","levelsVar","limit","searchIndexKey","searchIndexSeparator"]},AI=(e,t)=>({...e,[t.locale]:{...t,content:t.content}});function PI({block:e,localeDerived:t}){let o=lo(),n=Ea$1(e.section_id).data,r=Da$1(n.report_id).data,i=n?.settings.name||`Section ${n?.id}`,a=`${e.type} ${e.id}`,l=r?.name||`Report ${r.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:i}),jsx(Text,{size:"xs",children:a})]}),jsx(Badge,{size:"sm",radius:"sm",rightSection:jsx(Center,{children:t==="logic"?jsx(IconCode,{size:"0.6rem"}):jsx(IconLanguage,{size:"0.6rem"})}),children:t})]})}),jsxs(Group,{children:[o.cancelButton,o.closeAndSaveButton]})]})}function RI({id:e,modified:t,callbacks:o,inline:n}){let r=ua(),i=useContext(db$1),a=Ya(i),{setOpened:l,setModified:s,maybeCloseWithoutSaving:u,setInlineId:c}=o,p=Fa$1(e).data,m=va$1(O=>O.status.currentLocale),f=va$1(O=>O.status.localeDefault),g=va$1(O=>O.status.locales),S=N$1(p,m).locale,[v,h]=useState(),[b,C]=useState(false),[d,y]=useState(true);if(useEffect(()=>{h(ig(ya(p))),C(true);},[]),!p||!b||!v)return null;let x=O(v,m),k=v.settings,R=(O={},G=f,W=true,F=void 0,L=false)=>{let{locale:U}=N$1(p,G);if(W&&!t&&s(true),F!==void 0&&d!==F&&y(F),!O||Object.keys(O).length<1)return;let P=v.contentByLocale[U]||{id:e,locale:U,content:{}},A={...v,contentByLocale:{...v.contentByLocale,[U]:{...P,content:{...P.content,...O}}}};if(h(A),L){let _=N(A);r(ta$1.updateEntity("block",_)).then(()=>{a(),s(false);});}},B=(O,G)=>{if(S!=="logic"&&Object.keys(ag).includes(p.type)){let W={...O},F=O[G].content;return g.forEach(L=>{if(L===S)return;let P={...O[L].content.simple};Object.keys(F.simple).map(_=>{ag[p.type].includes(_)&&(P[_]=F.simple[_]);});let A={...P};if(p.type===z.SELECTOR){let{selectorType:_=hn.SINGLE,options:Q={static:[]},optionsType:Y=Fo.STATIC}=O[L].content.simple,{logicOptions:ce,defaultValue:re}=Ga(_,Q,Y);re&&(A.defaultValue=re),A.options=ce;}if(p.type===z.MULTIHIERARCHY_SELECTOR){let _=O[L].content.simple,{logicLevels:Q,logicOptions:Y,defaultValue:ce,defaultValueType:re}=Qa(_);ce&&re&&(A.defaultValue=ce,A.defaultValueType=re),A.data=Y,A.levels=Q;}W[L].content={...W[L].content,simple:P,logic:ro(A,false)};}),W}return O},N=(O=null)=>{let G=O||v,{settings:W}=G,F=Object.values(G.contentByLocale).reduce(AI,{}),L=["id","api","shared","type"].reduce((P,A)=>({...P,[A]:G[A]}),{}),U=B(F,m);return {...L,id:G.id,contentByLocale:U,settings:W}},$=async O=>{let G=N();r(ta$1.updateEntity("block",G)).then(()=>{a(),s(false),O||(n?c(null):l(false));});},K=O=>{t||s(true),O.type||O.shared!==void 0?h({...v,...O}):h({...v,settings:{...v.settings,...O}});};return jsx(Fragment,{children:jsx(hf,{buttons:{cancelButton:jsx(Button,{leftIcon:jsx(IconCircleX,{size:"0.8rem"}),size:"xs",variant:"outline",onClick:u,color:"red",children:"Cancel"},"cancel"),closeAndSaveButton:jsx(Button,{leftIcon:jsx(IconDeviceFloppy,{size:"0.8rem"}),size:"xs",disabled:!d,onClick:()=>$(false),children:`Save & ${n?"Return":"Close"}`},"save"),executeButton:jsx(Button,{disabled:!d,onClick:()=>$(true),size:"xs",compact:true,children:"Save & Execute"})},blockType:p.type,blockId:p.id,children:jsx(rg,{header:jsx(PI,{localeDerived:S,block:p}),blockContent:x,blockSettings:k,blockType:p.type,id:e,sid:p.section_id,locale:m,onSave:$,setBlockContent:R,setBlockSettings:K,setInlineId:c},"be")})})}var sg=RI;function jI({id:e,setHoverBlock:t,isInput:o,isConsumer:n$1,active:r,showOutline:i=true}){let[a,l]=useState(false),{newConfirmation:s}=b(),[u$1,c]=useState(false),[p,m]=useState(false),[f,g]=useState(null),S=useContext(db$1),v=Ya(S),h=useMantineTheme(),b$1=La$1(e),C=Na$1(e),d$1=useCallback(()=>{c(false),m(false),g(null);},[]),y=useDispatch(),x=va$1(A=>A.status.currentLocale),{data:k}=Fa$1(e),R=va$1(A=>A.records.entities.block),{isFetching:B}=ab("block",e),{allowed:N,allowedMessage:$}=useMemo(()=>{let A=!C?.hiddenByCascade,_="";return k&&(_=C?.hiddenByCascade===e?`Hidden by ${k.settings.allowed}: ${k.settings.allowed?b$1[k.settings.allowed]:null}`:`Hidden by ${C?.hiddenByCascade}`),{allowed:A,allowedMessage:_}},[b$1,C,k,e]);if(!k)return null;let{blockcol:K,type:T,section_id:M,contentByLocale:I,settings:O,inputs:G$1}=k,W=async()=>{if(p)try{await s({title:"Are you sure?",message:"Close editor without saving?",confirmText:"Yes, abandon changes."}),d$1();}catch{}else d$1();},F={centered:true,withCloseButton:false,opened:u$1,onClose:W,overflow:"inside",padding:h.spacing.sm,size:"95%",styles:{body:{height:"100%"}}},L={onMouseEnter:()=>t(e),onMouseLeave:()=>t(false)},U={setOpened:c,setModified:m,setInlineId:g,maybeCloseWithoutSaving:W},P=()=>{let A=Object.keys(R).filter(Y=>R[Y].section_id===k.section_id&&R[Y].blockcol===k.blockcol).map(Y=>R[Y].blockrow),_=f$2(A),Q={create:{blockrow:d(_),blockcol:K,locales:Object.keys(I).map(Y=>Y),section_id:M,type:T},update:{contentByLocale:I,settings:O,inputs:G$1.map(Y=>R[Y])}};y(ta$1.cloneEntity("block",Q)).then(()=>{[z.GENERATOR,z.SECTION_FLAG].includes(k.type)&&v({sid:M});});};return jsxs(Fragment,{children:[jsxs(Group,{id:`block-${e}`,onMouseOver:()=>l(true),onMouseOut:()=>l(false),className:"cr-section-block",pos:"relative",py:G.block.padding,...L,sx:A=>({border:"1px solid transparent",resize:"horizontal","&:hover":{border:i?`1px solid ${A.colors.blue[2]}`:"1px solid transparent"},...i?{"&:hover::before":{position:"absolute",top:0,left:0,fontSize:8,color:A.colors.blue[5],transform:"translateY(-100%)",content:`"Block ${e}"`,width:"fit-content"}}:{}}),children:[jsx(ma,{style:{color:"red"},id:e,debug:[z.VIZ,z.GENERATOR,z.SECTION_FLAG].includes(k.type),active:r,locale:x,allowed:N,isFetching:B},"bp"),(a||o||n$1)&&jsxs(Group,{spacing:0,className:"cr-block-controls export-hidden",style:{position:"absolute",right:px(h.spacing.xs)/2,top:px(h.spacing.xs)/2,backgroundColor:h.colors.gray[2],borderRadius:h.radius.sm,zIndex:5},children:[o||n$1?jsx(ActionIcon,{children:o?jsx(IconLogout,{size:20,color:h.colors.red[5]}):jsx(IconLogin,{size:20,color:h.colors.green[5]})},"globe"):null,k.shared&&jsx(Tooltip,{withArrow:true,label:"Sharing: Enabled",children:jsx(ActionIcon,{variant:"transparent",children:jsx(IconWorld,{size:20})},"globe")},"tt"),"access"in k.settings&&!["public","guest"].some(A=>!k.settings.access||k.settings.access.includes(A))&&jsx(Tooltip,{withArrow:true,label:"Private Block",children:jsx(ActionIcon,{variant:"transparent",children:jsx(IconLock,{size:20})},"lock")},"tt"),!N&&jsx(Tooltip,{withArrow:true,label:$,children:jsx(ActionIcon,{variant:"transparent",children:jsx(IconEyeOff,{size:20})})},"allowed"),![z.GENERATOR,z.SECTION_FLAG].includes(k.type)&&jsx(n,{id:e,display:"button"},"design"),jsx(ActionIcon,{onClick:()=>c(true),children:jsx(IconPencil,{size:20})},"edit"),![z.SECTION_FLAG].includes(k.type)&&jsx(ActionIcon,{onClick:P,children:jsx(IconCopy,{size:20})},"copy"),jsx(Nd,{type:u.BLOCK,id:e},"cog")]},"bc")]},"block"),jsx(Modal,{fullScreen:true,...F,children:jsx(sg,{callbacks:U,id:f||e,inline:f,modified:p},f||e)},"d")]})}var ur=jI;var pg=({id:e,disabled:t=false})=>{let{sectionVariables:o,resetSectionVariables:n}=Va(e);return !Object.keys(o).length?null:jsx(ActionIcon,{disabled:t,onClick:n,variant:"filled",size:"xs",children:jsx(IconRefresh,{size:20})})},QI=({sectionId:e,onActivate:t})=>{let{activeEntity:o}=Ka(),{handlers:n}=Za("settings");return o.type==="section"&&o.id===e?jsx(Button,{size:"xs",radius:"xl",leftIcon:jsx(IconPencil,{size:14}),fw:400,onClick:n.open,compact:true,children:"Edit"}):jsx(ActionIcon,{variant:"transparent",onClick:()=>{t(),n.open();},children:jsx(IconPencil,{size:18})})};function ZI({sectionId:e$1,onActivate:t,position:o}){let n=useDispatch(),r=Ea$1(e$1),i=va$1(m=>m.records.entities.section),{data:a}=r,l=a$2(),s=Number.parseInt(l.params[0]),u=Da$1(s),c=va$1(m=>m.records.entities.block);if(!a||!u.data?.sections)return null;let{sections:p}=u.data;return jsxs(Group,{spacing:2,children:[jsx(QI,{sectionId:e$1,onActivate:t}),jsx(ActionIcon,{variant:"transparent",onClick:()=>{let m={...a,ordering:e(i,p,o+1,true)},f=eA(m,c);n(ta$1.cloneEntity("section",f));},children:jsx(IconCopy,{size:18})}),jsx(Bt,{type:"section",id:e$1})]})}function eA(e,t){let{heading:o,report_id:n,ordering:r,settings:i}=e,a=[];return {create:{ordering:r,report_id:n},update:{settings:i,heading:o,report_id:n,blocks:e?.blocks.map(s=>{let u=t[s],{blockcol:c,blockrow:p,contentByLocale:m,type:f,settings:g,section_id:S,shared:v,inputs:h,consumers:b}=u;return {blockcol:c,blockrow:p,contentByLocale:m,id:s,type:f,settings:g,section_id:S,shared:v,inputs:h.map(C=>{let d=t[C],{id:y,section_id:x,blockcol:k,blockrow:R,contentByLocale:B,settings:N,shared:$,type:K}=d;return {id:y,section_id:x,blockcol:k,blockrow:R,contentByLocale:B,settings:N,shared:$,type:K}}),consumers:b.reduce((C,d)=>{let y=t[d];if(y){let{id:x,section_id:k,blockcol:R,blockrow:B,contentByLocale:N,settings:$,shared:K,type:T}=y;return [...C,{id:x,section_id:k,blockcol:R,blockrow:B,contentByLocale:N,settings:$,shared:K,type:T}]}return C},a)}})}}}var dg=ZI;function fg({active:e,isDragging:t,id:o,dragHandleProps:n,hidden:r="",onActivate:i$1,sectionSettings:a,position:l}){let s=va$1(m=>m.records.entities.section[o]||null);if(!s)return null;let u=useMemo(()=>s&&s.settings?.name?.length?s.settings.name:`section-${s.id}`,[s.settings?.name,s.id]),c=useMemo(()=>i(u),[u]),p=r!=="";return jsxs(Group,{className:`cms-section-header${e||t?" active":""}`,position:"apart",bg:p?"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",...n,w:16,sx:{cursor:"grab"},children:jsx(IconGripHorizontal,{size:16})},"b1"),jsxs(Text,{size:"xs",fw:400,color:"dark.9",children:[u,c!==u&&jsxs(Text,{span:true,size:"xs",c:"dimmed",children:[" #",c]}),p&&` ${r}`,a.clientSideSection&&jsx(Text,{span:true,size:"xs",c:"orange.7",children:" \u2014 Client Side Section"})]})]})}),jsxs(Group,{children:[jsxs(Flex,{justify:"flex-end",mx:16,align:"center",gap:"xs",children:[jsx(pg,{id:s.id,disabled:!e}),a.optionsMenu&&jsx(C,{sectionId:s.id,disabled:!e})]}),jsx(dg,{sectionId:o,onActivate:i$1,position:l})]})]})}var yA=Object.values(z),xg=({columns:e,columnIndex:t,section:o})=>{let n=ua(),{settings:r}=i$1(o.report_id),[i,a]=useDisclosure(false),l=(u,c=false)=>{let p="!",m="!";typeof c=="string"?(m=c,p=f$2(Object.keys(e[c]),true)):Object.keys(e).length>0&&(m=f$2(Object.keys(e),true));let{locales:f}=N$1({type:u});n(ta$1.createEntity("block",{blockrow:p,blockcol:m,type:u,section_id:o.id,locales:f})).then(g=>{u===z.VIZ&&n(ta$1.updateEntity("block",{id:g.data.id,contentByLocale:{logic:{...g.data.contentByLocale.logic,content:{simpleEnabled:true,simple:{},logic:V}}}}));});},s=yA.filter(u=>![z.GENERATOR,z.SECTION_FLAG,z.FALLBACK,z.SKELETON].includes(u)&&(r.comparison?true:u!==z.COMPARISON_BUTTON)).map(u=>{let c=O$1(u);return {label:jsx(UnstyledButton,{p:"xs",w:"100%",onClick:()=>{l(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:Q(u)||u})]})}),value:u}});return jsx(Center,{w:"100%",py:"sm",children:jsxs(Popover,{position:"right",withinPortal:true,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:s.map(({label:u,value:c})=>jsx(List.Item,{w:"100%",children:u},c))})})]})]})})},vA=({columns:e,section:t,show:o=false})=>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(xg,{columnIndex:false,columns:e,section:t})]})}):null,SA=({active:e=false})=>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:n=>({boxSizing:"border-box",zIndex:99,transition:"right 0.4s",overflow:"hidden",background:o.isDraggingOver?n.colors[n.primaryColor][0]:n.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,{})]})})}),xA=({onActivate:e,section:t,show:o=false})=>{let r=va$1(i=>i.status.isRunConsumersRunning).includes(t.id);return !o&&!r?null:jsxs(Overlay,{className:"cms-section-overlay",onClick:()=>e(t.id),opacity:.6,color:"#E9ECEF",style:{cursor:"pointer",zIndex:3},sx:i=>({transition:"background-color .45s",".bespoke-Section-edit":{opacity:0,transition:"opacity .45s"},"&:hover":{backgroundColor:i.fn.rgba("#E9ECEF",.9),".bespoke-Section-edit":{opacity:1}}}),center:true,children:[!r&&jsxs(Group,{className:"bespoke-Section-edit",align:"center",spacing:"xs",children:[jsx(Text,{fw:700,children:"Click to Edit"}),jsx(IconPencil,{size:"1rem"})]}),r&&jsxs(Stack,{align:"center",spacing:"xs",children:[jsx(Text,{fw:700,children:"Loading dependencies"}),jsx(Loader,{size:"md"})]})]})};function CA({for:e$1,isDragging:t,onActivate:o,dragHandleProps:n,position:r}){let i$1=ua(),{activeEntity:a}=Ka(),[l,s]=useState(false),[u,c]=useState(),p=useRef(null),m$1=va$1(I=>I.records.entities.block),f=va$1(I=>I.status.previews),g=ab("section",e$1.id),{memberImageBg:S,hidden:v,columnSettings:h={}}=e$1.settings,b=a.type==="section"&&a.id===e$1.id,{inputs:C,consumers:d}=useMemo(()=>{if(u){let I=m$1[u],{inputs:O,consumers:G}=I;return {inputs:O,consumers:G}}return {inputs:[],consumers:[]}},[u]),y=Object.values(m$1||{}).filter(I=>I.section_id===e$1.id&&![z.GENERATOR,z.SECTION_FLAG].includes(I.type)).reduce((I,O)=>(I[O.blockcol]?I[O.blockcol][O.blockrow]=O:I[O.blockcol]={[O.blockrow]:O},I),{}),x=useMantineTheme(),k=()=>s(true),R=I=>{if(s(false),!I.destination)return;let{source:O,destination:G}=I;if(O.droppableId===G.droppableId&&O.index===G.index)return;let W=G.droppableId==="newColumn",F=Number(I.draggableId),L=O.droppableId,U=W?f$2(Object.keys(y),true):G.droppableId,P={id:F,blockrow:"!",blockcol:"!"},A=L!==U;P.blockcol=A?U:L;let _=Object.values(y[P.blockcol]||{}),Q=_.reduce((re,ae)=>({...re,[ae.id]:ae}),{}),Y=_.sort((re,ae)=>c$1(re,ae,"blockrow")).map(re=>re.id),ce=G.index>O.index;P.blockrow=e(Q,Y,G.index,A,ce,"blockrow"),i$1(ta$1.updateEntity("block",P));},B=useMemo(()=>{let I=Object.values(m$1||{}).filter(O=>O.section_id===e$1.id&&W(O));return I.length>1&&console.error(`Error, there are more than one Section Flag Generator in section ${e$1.id}`),I.length>0?I[0]:false},[m$1,b,e$1.id]),N=va$1(I=>B&&I.variables.variables[B.id]&&!I.variables.variables[B.id][T]||false),$=useMemo(()=>{let I="";return N&&B&&(I+=`(Not allowed by Section Flag #${B.id})`),v&&(I+="(Hidden by Section Settings)"),I},[v,N]),K=Object.keys(y).sort((I,O)=>-b$1(I,O)),T$1=Object.keys(y).length,M=useMemo(()=>e$1?.settings?.name?i(e$1?.settings?.name):`section-${e$1.id}`,[e$1.id,e$1?.settings?.name]);return g.isFetching?jsxs(Box,{p:"lg",m:"lg",bg:G.section.backgroundColor,sx:I=>({borderRadius:I.radius.md,border:`1px solid ${I.colors.gray[4]}`}),children:[jsx(Skeleton,{height:50,circle:true,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(fg,{active:b,id:e$1.id,isDragging:t,hidden:$,dragHandleProps:n,onActivate:()=>o(e$1.id),sectionSettings:e$1.settings,position:r}),jsxs(Box,{pos:"relative",sx:I=>({border:b?`1px solid ${I.colors.blue[4]}`:"none",borderRadius:2}),children:[jsx(Paper,{id:M,className:`cms-section${t||b?" active":""}`,bg:e$1.settings.style==="card"?G.section.backgroundColor:"transparent",p:0,mih:100,maw:e$1.settings.width==="center"?x.breakpoints.xl:"none",w:"100%",mx:"auto",pos:"relative",shadow:e$1.settings.style==="card"?G.section.boxShadow:"none",radius:G.section.borderRadius,sx:{overflow:"hidden"},children:jsxs(Box,{pos:"relative",children:[S&&jsx(B$1,{previews:f}),jsx(F,{ref:p,containerProps:{mih:!b||!T$1?120:"none",p:e$1.settings.margin||"md",style:{zIndex:2},gap:e$1.settings.columnGutter||"md",wrap:"wrap"},children:jsxs(DragDropContext,{onDragEnd:R,onDragStart:k,children:[K.map(I=>{let O=Object.values(y[I]).sort((G,W)=>c$1(G,W,"blockrow"));return jsx(Droppable,{droppableId:I,children:(G,W)=>jsxs(D,{column:y[I],columnSettings:h[I],ref:G.innerRef,basis:`calc(${100/T$1}% - (10px * ${T$1}))`,sx:{background:W.isDraggingOver?x.colors[x.primaryColor][0]:"inherit",border:"1px solid transparent","& .bespoke-resize-col":{visibility:"hidden"},"&:hover .bespoke-resize-col":{visibility:"visible"},"&:hover":{border:`1px solid ${x.colors.teal[1]}`}},...G.droppableProps,children:[jsx(E,{sectionId:e$1.id,columnIndex:I}),O.map((F,L)=>{if(!m$1[F.id])return null;let{settings:U,type:P}=m$1[F.id],A=U.width&&!U.width.stretch&&U.width.unit?m[U.width.unit](U.width.value):U.display==="inline"?"auto":"100%",_={alignSelf:P===z.VIZ?"stretch":"flex-start",flexGrow:0,margin:"0",width:A,minWidth:120};return jsx(Draggable,{draggableId:String(F.id),index:L,children:(Q,Y)=>jsx(Box,{ref:Q.innerRef,...Q.draggableProps,...Q.dragHandleProps,sx:[_,{boxShadow:Y.isDragging?x.shadows.lg:"none",...Q.draggableProps.style}],children:jsx(ur,{id:Number(F.id),active:b,isInput:C.includes(Number(F.id)),isConsumer:d.includes(Number(F.id)),setHoverBlock:c},`block-${F.id}`)})},F.id)}),b&&jsx(xg,{section:e$1,columnIndex:I,columns:y}),G.placeholder]})},I)}),jsx(SA,{active:l&&b})]})}),jsx(vA,{columns:y,section:e$1,show:b&&!T$1})]})}),jsx(xA,{onActivate:o,section:e$1,show:!b})]})]})}var Cg=cb(CA,Ea$1);function BA(e,t){let o=document.getElementById(t),n=90;if(o){let i=o.getBoundingClientRect().top+e.current.scrollTop-n;e.current.scrollTo({top:i,behavior:"smooth"});}}function zA(e,t,o){let n=document.getElementById(`bespoke-${t}-${o}`),r=60;if(n){let a=n.getBoundingClientRect().top+e.current.scrollTop-r;e.current.scrollTo({top:a,behavior:"smooth"});}}function NA({section:e,onEnd:t}){let[o,n]=useState(e.settings?.name||`section-${e.id}`),r=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=>n(a.target.value),onKeyDown:r})}var VA=forwardRef(function({scrollContainer:t,section:o,isActive:n,...r},i$1){let a=va$1(k=>k?.records.entities.block),{settings:l,updateSettings:s}=h(o.id),u=useMantineTheme(),[c,p]=useState(false),[m,f]=useState(false),g=va$1(k=>{let R=o.blocks.map(B=>k.records.entities.block[B]).filter(B=>W(B));return R.length>0?k.variables.variables[R[0].id]:false}),S=g?u.colors[g[T]===false?"red":"green"][3]:"",v=useCallback(k=>{s("name",k),f(false);},[s]),h$1=useRef(false);useEffect(()=>{p(!!n);},[n]);let b=useMemo(()=>l?.name?i(l?.name):`section-${o.id}`,[o.id,l?.name]),C=useMemo(()=>l?.name||`section-${o.id}`,[o.id,l?.name]),d=k=>{k.detail===1&&(h$1.current=false,setTimeout(()=>{h$1.current||BA(t,b);},200)),k.detail===2&&(h$1.current=true,f(R=>!R));},y=n?u.colors.blue[5]:"black",x=o?.blocks.map(k=>a[k]).filter(k=>![z.GENERATOR,z.SECTION_FLAG].includes(k.type)).map(k=>{let R=N[k.type]||IconDice;return jsx(List.Item,{pl:"lg",sx:{border:"1px solid transparent","&:hover":{border:"1px solid blue",cursor:"default"}},icon:jsx(R,{size:"0.8rem"}),onClick:()=>zA(t,k.type,k.id),children:jsx(Text,{size:"sm",children:`${k.type} ${k.id}`})},k.id)});return jsxs(List.Item,{ref:i$1,w:"100%",...r,children:[jsxs(Group,{position:"apart",noWrap:true,px:"sm",bg:n?u.colors.gray[2]:"transparent",sx:k=>({cursor:"default",border:`1px solid ${n?k.colors.gray[2]:"transparent"}`,".section-icon":{color:y},":hover":{border:`1px solid ${k.colors.blue[5]}`}}),children:[jsxs(Group,{spacing:"xs",miw:0,onClick:d,noWrap:true,children:[jsx(IconBoxMultiple,{className:"section-icon",size:"0.8rem",style:{flexShrink:0}}),m?jsx(NA,{section:o,onEnd:v}):jsxs(Group,{spacing:4,align:"flex-end",children:[jsxs(Text,{size:"sm",fw:500,color:"gray.5",span:true,children:[o.id," -"]}),jsx(Text,{size:"sm",c:y,maw:220,sx:{whiteSpace:"nowrap",textOverflow:"ellipsis",overflow:"hidden"},span:true,children:C})]})]}),jsxs(Group,{spacing:"xs",children:[o.settings.hidden&&jsx(IconEyeOff,{size:"0.8rem",color:u.colors.red[3]}),l?.clientSideSection&&jsx(IconDeviceLaptop,{size:"0.8rem",color:u.colors.orange[5]}),g&&jsx(IconFlag,{size:"0.8rem",color:S,fill:S}),x.length&&jsx(IconChevronDown,{size:"0.8rem",style:{transform:`rotate(${c?-180:0}deg)`,flexShrink:0},onClick:()=>p(k=>!k)})]})]}),c&&x.length?jsx(List,{listStyleType:"none",children:x}):null]})}),wg=VA;function Kc({activeSection:e$1,scrollContainer:t}){let o=va$1(l=>l?.records.entities.section),n=ua(),r=Object.values(o).sort(c$1),i=r.map(l=>l?.id),a=useCallback(l=>{if(!l.destination||l.source.index===l.destination.index)return;let s=Number.parseInt(l.draggableId,10),u=l.destination.index>l.source.index,c=e(o,i,l.destination.index,false,u),p=i.slice(),m=p.splice(l.source.index,1);p.splice(l.destination.index,0,...m),n(ta$1.updateEntity("section",{id:s,ordering:c}));},[n,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:true,children:[jsx(IconIndentIncrease,{size:"1rem"}),jsx(Text,{ml:"xs",span:true,children:"Navigation"})]})}),jsx(DragDropContext,{onDragEnd:a,children:jsx(List,{styles:{itemWrapper:{width:"100%"}},mt:"sm",listStyleType:"none",children:jsx(Droppable,{droppableId:"sections",children:l=>jsx("div",{ref:l.innerRef,...l.droppableProps,children:r.map((s,u)=>jsx(Draggable,{draggableId:`${s?.id}`,index:u,children:c=>jsx(wg,{scrollContainer:t,ref:c.innerRef,section:s,isActive:s.id===e$1,...c.draggableProps,...c.dragHandleProps})},s?.id))})})})})]})}var QA=e=>t=>Object.values(t.records.entities.block||{}).filter(o=>o.section_id===e&&z.GENERATOR===o.type);function qc({activeSection:e}){let t=va$1(QA(e)),o=ua(),n=()=>{let{locales:r}=N$1({type:z.GENERATOR});o(ta$1.createEntity("block",{blockrow:void 0,blockcol:void 0,type:z.GENERATOR,section_id:e,locales:r})).then(i=>{o(ta$1.updateEntity("block",{id:i.data.id,contentByLocale:{logic:{...i.data.contentByLocale.logic,content:{simpleEnabled:true,simple:{},logic:U}}}}));});};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:n,children:jsx(IconPlus,{})})]}),t.length?t.map(r=>jsx("div",{children:jsx(ur,{id:Number(r.id),active:!!e,isInput:false,isConsumer:false,setHoverBlock:()=>{},showOutline:false})},`block-${r.id}`)):jsx(Text,{align:"center",size:"sm",children:"Click '+' to add a generator"})]})})}function Lg({sectionId:e}){let[t,o]=useState(window.innerWidth-40),[n,r]=useState(window.innerHeight-150);useEffect(()=>{let g=()=>{o(window.innerWidth-40),r(window.innerHeight-120);};return window.addEventListener("resize",g),()=>{window.removeEventListener("resize",g);}},[]);let i=Aa$1(),a=za$1(),[l,s]=useState(`${e}`),u=useMemo(()=>a.isSuccess?a.data.map(S=>({value:`${S.id}`,label:S.settings.name?`${S.settings.name} (${S.id})`:`Section ${S.id}`})):[],[a.isLoading]),c=useMemo(()=>{if(i.isSuccess&&l){let g={id:"root",label:"section",size:40,parentIds:[]},S={id:"wide",label:"report",size:40,parentIds:[]},v=i.data.filter(b=>`${b.section_id}`==`${l}`),h=v.map(b=>b.id);return [g,S,...v.map(b=>{let C=b.consumers.length>0?b.consumers.length*20:40,d=b.inputs.length>0?b.inputs.map(y=>h.includes(y)?`${y}`:`${S.id}`):[`${g.id}`];return {id:`${b.id}`,label:`${b.type}`,size:C>50?50:C,parentIds:[...Array.from(new Set(d))]}})]}else return []},[i.isLoading,l]),p=useRef(null);return useEffect(()=>{let g=ds.dagStratify()(c),S=40,v=ds.sugiyama().nodeSize(M=>{let I=M?M.data:null,O=I?I.size:S;return [(M?3.6:.25)*O,3*O]}),{width:h,height:b}=v(g),C=Ht.select(p.current);C.selectAll("*").remove(),C.attr("viewBox",[0,0,h,b].join(" "));let d=C.append("defs"),y=g.size(),x=Ht.interpolateRainbow,k=new Map;c.forEach((M,I)=>{k.set(M.id,x(I/y));});let R=Ht.line().curve(Ht.curveCatmullRom).x(M=>M.x).y(M=>M.y);C.append("g").selectAll("g").data(g.links()).enter().append("g").append("path").attr("class","curve").attr("d",({points:M})=>R(M)).attr("fill","none").attr("stroke-width",3).attr("stroke",({source:M,target:I})=>{let O=encodeURIComponent(`${M.data.id}--${I.data.id}`),G=d.append("linearGradient").attr("id",O).attr("gradientUnits","userSpaceOnUse").attr("x1",M.x).attr("x2",I.x).attr("y1",M.y).attr("y2",I.y);return G.append("stop").attr("offset","0%").attr("stop-color",k.get(M.data.id)),G.append("stop").attr("offset","100%").attr("stop-color",k.get(I.data.id)),`url(#${O})`}),C.append("g").selectAll("g").data(g.descendants()).enter().append("g").attr("transform",({x:M,y:I})=>`translate(${M}, ${I})`).append("circle").attr("r",M=>M.data.size).attr("fill",M=>k.get(M.data.id));let $=C.append("g").selectAll("g").data(g.links()).enter().append("g"),K=Ht.symbol().type(Ht.symbolTriangle).size(S*1.5);$.append("path").attr("class","arrow").attr("d",K).attr("transform",M=>{let{points:I,target:O}=M,[G,W]=I.reverse(),F=W.x-G.x,L=W.y-G.y,U=O.data.size*1/Math.sqrt(F*F+L*L),P=Math.atan2(-L,-F)*180/Math.PI+90;return `translate(${G.x+F*U}, ${G.y+L*U}) rotate(${P})`}).attr("fill",({target:M})=>k.get(M.data.id)).attr("stroke","white");let T=C.append("g").selectAll("g").data(g.descendants()).enter().append("g").attr("transform",({x:M,y:I})=>`translate(${M}, ${I})`);T.append("text").text(M=>M.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"),T.append("text").text(M=>M.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:l,onChange:s,data:u,width:"80%"}),jsxs(Group,{grow:true,maw:100,children:[jsx(ActionIcon,{onClick:()=>{let g=u.findIndex(S=>S.value===l);g>0&&s(u[g-1].value);},variant:"outline",children:jsx(IconChevronLeft,{size:"1.125rem"})}),jsx(ActionIcon,{onClick:()=>{let g=u.findIndex(S=>S.value===l);g<u.length-1&&s(u[g+1].value);},variant:"outline",children:jsx(IconChevronRight,{size:"1.125rem"})})]})]}),jsx("svg",{ref:p,width:t,height:n})]})}function Bg({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(l,{id:t,variables:o})]})]})}function bP({sectionId:e}){let[t,o]=useDisclosure(false);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:true,children:jsx(Lg,{sectionId:e})})]})}function yP({activeSection:e}){let t=va$1(i=>i.records.entities.block),o=va$1(i=>i.variables.attributes),n=va$1(i=>i.variables.variables),r=Object.values(t).filter(i=>(i.section_id===e||i.shared)&&Object.keys(n[i.id]||{}).length);return jsxs(Box,{px:"sm",w:"100%",children:[jsx(Text,{fw:700,size:"sm",children:jsxs(Center,{inline:true,children:[jsx(IconCodeDots,{size:"1rem"}),jsx(Text,{ml:"xs",span:true,children:"Variables"})]})}),jsx(ScrollArea.Autosize,{mah:"40vh",mx:"sm",w:"240px",children:jsxs(Stack,{mt:"sm",children:[jsx(Bg,{name:"Report Variables",id:"attributes",variables:o}),r.map(i=>jsx(Bg,{id:i.id,name:`${i.type} ${i.id}`,variables:n[i.id]},i.id))]})})]})}function vP(){return jsx(Title,{children:"Formatters"})}var SP={section:[{label:"Navigation",value:"navigation"},{label:"Generators",value:"generators"}]};function eu({scrollContainer:e}){let{opened:t,handlers:o}=Za("tools"),{toggle:n}=o,[r,i]=useState("navigation"),{activeEntity:a}=Ka(),l=c=>i(c),s=a.type==="section"?a.id:null,u=t&&jsxs(Fragment,{children:[s&&jsx(SegmentedControl,{sx:{flexShrink:0},data:SP.section,value:r,onChange:l}),jsxs(Stack,{sx:{flexGrow:1},spacing:"sm",mt:32,children:[(r==="navigation"||!s)&&jsx(Kc,{activeSection:s,scrollContainer:e}),r==="generators"&&s&&jsx(qc,{activeSection:s}),r==="variables"&&jsx(yP,{activeSection:s}),r==="formatters"&&jsx(vP,{})]})]});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(bP,{sectionId:s}),jsx(UnstyledButton,{onClick:n,sx:{transform:`rotate(${t?0:180}deg)`},children:jsx(IconChevronLeft,{size:24})})]})]})}function EP({activeSection:e}){let{settings:t,updateSettings:o}=h(e),n=t.name||`section-${e}`,[r,i]=useState(n),[a,l]=useState(false);return jsx(TextInput,{label:"Section Name",description:"Section name. Only for organization purposes. Won't be displayed on the final report.",value:a?r:n,onChange:s=>i(s.target.value),onFocusCapture:()=>{i(n),l(true);},onBlurCapture:()=>{o("name",r),l(false);},withAsterisk:true,radius:2})}function IP({activeSection:e}){let{settings:t,updateSettings:o}=h(e),n=t.tags,r=va$1(s=>e&&s.records.entities.section[e]),i=va$1(s=>e&&r?Object.values(s.records.entities.section).filter(u=>u&&u.report_id===r.report_id):[]),a=useMemo(()=>{let s=new Set;return i.forEach(u=>{let c=u?.settings?.tags;c&&(Array.isArray(c)?c.forEach(p=>p&&s.add(p)):typeof c=="string"&&c.split(/\s+/).forEach(p=>p&&s.add(p)));}),Array.from(s).sort()},[i]),l=useMemo(()=>n?Array.isArray(n)?n:typeof n=="string"?n.split(/\s+/).filter(Boolean):[]:[],[n]);return jsx(MultiSelect,{label:"Section Tags",description:"Section tags. They will be appended to the dom element as data attributes.",placeholder:"Select or create tags",data:a,value:l,onChange:s=>o("tags",s),radius:2,searchable:true,creatable:true,getCreateLabel:s=>`+ Create ${s}`})}function tu(){let{activeEntity:e}=Ka(),t=e.id,o=va$1(y=>t&&y.records.entities.section[t]),n=va$1(y=>t&&o&&y.records.entities.report[o.report_id]),r=va$1(y=>{if(t&&o){let x=o.blocks.map(k=>y.records.entities.block[k]).filter(k=>W(k));return x.length>1&&console.error(`Error, there is more than one section flag generator in section ${e.id}`),x.length>0?x[0]:false}return false}),i=ua(),a=useContext(db$1),l=Ya(a),s=f(),u=y=>{y==="always"&&r?c(r.id):y==="section-flag"&&p();},c=y=>{i(ta$1.deleteEntity("block",y)).then(()=>{l(),console.info(`Flag generator with ID ${y} deleted.`);});},p=()=>{let{locales:y}=N$1({type:z.SECTION_FLAG});i(ta$1.createEntity("block",{blockrow:void 0,blockcol:void 0,type:z.SECTION_FLAG,section_id:t,locales:y})).then(x=>{i(ta$1.updateEntity("block",{id:x.data.id,contentByLocale:{logic:{...x.data.contentByLocale.logic,content:{simpleEnabled:true,simple:{},logic:`return {
34
34
  ${T}: true
35
- }`}}}})).then(()=>{l();});});},f$1=n?.settings||{},{settings:m,updateSettings:g}=h(t),S=useMemo(()=>[{key:"optionData",label:"Download data (csv, xls, json)"},{key:"optionImage",label:"Save Image"},{key:"optionShare",label:"Share link"}],[]),v=useMemo(()=>S.map(y=>jsxs(List.Item,{children:[y.label,"."]},`item-${y.key}`)),[S]);if(e.type!=="section"||!e.id)return null;let h$1=useMemo(()=>[{value:"always",label:"Always"},{value:"section-flag",label:"Use Section Flag"}],[]),b=useMemo(()=>[{value:"always",label:"Always"},{value:"never",label:"Never"},{value:"optional",label:"Optional"}],[]),C=r?"section-flag":"always";if(e.type!=="section"||!e.id)return null;let d=m.showInPdf||"optional";return jsxs("div",{children:[jsx(wP,{activeSection:t}),jsx(EP,{activeSection:t}),jsx(Divider,{my:"sm"}),jsxs(Stack,{mt:"sm",children:[jsxs(Stack,{spacing:"0.4rem",children:[jsx(H$1,{target:jsx(Switch,{radius:"sm",label:"Show export menu.",checked:m.optionsMenu,onChange:y=>g("optionsMenu",y.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:true,size:"sm",children:v})]})}),m.optionsMenu&&jsx(Stack,{spacing:"0.5rem",pl:"md",children:S.map(y=>jsx(Switch,{radius:"sm",label:y.label,checked:typeof m[y.key]>"u"?m.optionsMenu:m[y.key],onChange:x=>g(y.key,x.currentTarget.checked)},y.key))})]}),jsx(H$1,{target:jsx(Switch,{radius:"sm",label:"Show anchor link.",checked:m.showAnchor,onChange:y=>g("showAnchor",y.currentTarget.checked)}),dropdown:jsx(Text,{size:"sm",maw:200,children:"Show `#` link on top left corner of the section"})}),jsx(H$1,{target:jsx(Switch,{radius:"sm",label:"Show section.",checked:!m.hidden,onChange:y=>g("hidden",!y.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(H$1,{target:jsx(Select,{label:"Show in PDF",value:d,data:b,disabled:!a,onChange:y=>g("showInPdf",y)}),dropdown:jsx(Text,{size:"sm",maw:200,children:a?"Hide or show the section in the pdf report.":"PDF API URL is not set."})}),jsx(H$1,{target:jsx(Select,{label:"Allow section",placeholder:"Select an option",description:r?`Controlled by Section Flag #${r.id}`:"Section always visible",value:C,data:h$1,onChange:u}),dropdown:jsx(Text,{size:"sm",maw:200,children:"You can control section visibility (allow) creating a Section Flag Block"})}),r&&jsx(Stack,{spacing:"xs",children:jsx(sr,{id:Number(r.id),active:!!t,isInput:false,isConsumer:false,setHoverBlock:()=>{},showOutline:false})}),f$1.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:m.comparisonHide,onChange:y=>g("comparisonHide",y.currentTarget.checked)}),jsx(Switch,{radius:"sm",label:"Show once in comparison",checked:m.comparisonMerge,onChange:y=>g("comparisonMerge",y.currentTarget.checked)})]})})]})})]})]},`settings-${t}`)}function tu(e){let{label:t,labelProps:o,...n}=e;return jsxs(Stack,{spacing:"md",children:[jsx(Text,{...o,children:t}),jsx(SegmentedControl,{...n})]})}function nu(){let{activeEntity:e}=Ka(),t=e.id,{settings:o,updateSettings:n}=h(t);return e.type!=="section"||!e.id?null:jsxs(Fragment,{children:[jsxs(Stack,{spacing:"md",children:[jsx(Text,{children:"Image"}),jsx(H$1,{target:jsx(Switch,{radius:"sm",label:"Show image background",checked:o.memberImageBg,onChange:r=>n("memberImageBg",r.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(A$1).map(r=>jsx(tu,{label:A$1[r].label,data:A$1[r].options,value:String(o[r]||A$1[r].defaultValue),onChange:i=>n(r,i)},r))]})}var Ug={report:[{label:"Settings",value:"settings",component:jsx(J,{})}],section:[{label:"Style",value:"style",component:jsx(nu,{})},{label:"Settings",value:"settings",component:jsx(eu,{})}],block:[{label:"Content",value:"content",component:null},{label:"Style",value:"style",component:null},{label:"Settings",value:"settings",component:null}]};function ru(){let{opened:e,handlers:t}=Za("settings"),[o,n]=useState("settings"),r=a=>n(a),{activeEntity:i}=Ka();if(!i.type)return null;let s=Ug[i.type].find(a=>a.value===o)?.component||null,l=e&&jsx(Fragment,{children:jsxs("div",{children:[i.type==="report"?jsx(Text,{children:"Report Settings"}):jsx(SegmentedControl,{value:o,data:Ug[i.type],onChange:r,fullWidth:true}),jsx(Stack,{sx:{flexGrow:1},spacing:"sm",mt:32,children:s})]})});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:a=>({overflow:"hidden",borderLeft:`1px solid ${a.colors.gray[2]}`,flexShrink:0,flexGrow:0}),children:[l,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})})})]})}function KP({for:e,setSectionTotals:t}){let o=va$1(b=>b.variables.status),n=va$1(b=>b.variables.variables),r=Aa$1(e.blocks),i=useMemo(()=>{if(r.isSuccess){let b=new Map(e.blocks.map((C,d)=>[C,d]));return r.data.slice().filter(C=>[z.GENERATOR,z.SECTION_FLAG].includes(C.type)).sort((C,d)=>{if(C.type===z.SECTION_FLAG&&d.type!==z.SECTION_FLAG)return -1;if(d.type===z.SECTION_FLAG&&C.type!==z.SECTION_FLAG)return 1;let y=b.get(C.id)??Number.MAX_VALUE,x=b.get(d.id)??Number.MAX_VALUE;return y-x})}else return []},[r.isLoading,r.isSuccess,e.blocks]);if(i.length===0)return null;let{hidden:s}=e.settings,l=useContext(db$1),a=Ya(l),c=va$1(b=>b.status.isRunConsumersRunning).includes(e.id),p=va$1(b=>b.status.previews);useEffect(()=>{a({sid:e.id});},[e.id,p]);let f=useMemo(()=>{let b=i.filter(C=>C.section_id===e.id&&W(C));return b.length>1&&console.error(`Error, there are more than one Section Flag Generator in section ${e.id}`),b.length>0?b[0]:false},[r,e.id]),m=va$1(b=>f&&b.variables.variables[f.id]&&!b.variables.variables[f.id][T]||false),g=useMemo(()=>{let b="";return m&&f&&(b+=`(Not allowed by Section Flag #${f.id})`),s&&(b+="(Hidden by Section Settings)"),b},[s,m]),S=useMemo(()=>[{accessorKey:"status",header:"",Cell:({cell:b})=>m&&b.row.original.type!==z.SECTION_FLAG?jsx(IconCircleX,{size:"1rem"}):jsx(Fragment,{children:b.getValue()?jsx(Loader,{size:"1rem",color:"blue"}):jsx(IconCircleCheckFilled,{color:"green",size:"1rem"})}),enableSorting:false,size:50,minSize:50,maxSize:50},{accessorKey:"order",header:"Order",size:50,minSize:50,maxSize:50},{accessorKey:"id",header:"ID",size:50,minSize:50,maxSize:50},{accessorKey:"type",header:"Type",size:100,minSize:100,maxSize:100,Cell:({cell:b})=>{let C=O$1(b.getValue());return jsxs(Group,{spacing:0,noWrap:true,children:[jsx(C,{size:16}),jsx(Text,{size:"xs",ml:"xs",children:Q(b.getValue())})]})}},{accessorKey:"duration",header:"Duration",size:100,minSize:100,maxSize:100,Cell:({cell:b})=>`${b.getValue().toFixed(3)}s`},{accessorKey:"sizeApi",header:"API Size",size:100,minSize:100,maxSize:100,Cell:({cell:b})=>b.getValue()?`\u2248${b.getValue().toFixed(2)} Kb`:""},{accessorKey:"sizeBlock",header:"Block Size",size:100,minSize:100,maxSize:100,Cell:({cell:b})=>`\u2248${b.getValue().toFixed(2)} Kb`},{accessorKey:"data",header:"",enableSorting:false,Cell:({cell:b})=>{let C=b.getValue();return jsx(pa,{block:C.block,status:C.blockStatus,variables:C.blockVariables})}}],[]),v=useMemo(()=>i.map((b,C)=>{let d=!!b.contentByLocale?.logic?.content?.api,y=o[b.id]||{},x=n[b.id]||{},k=y.duration?y.duration/1e3:0,B=(y.api&&y.api!==""?y.api.split("|||"):[]).map((N,$)=>({original:N,swapped:y.apiFinalUrls[$]}));return {order:C+1,id:b.id,type:b.type,duration:k,status:d&&!Object.keys(x).length&&!y.error,sizeBlock:JSON.stringify(x).length/1024,sizeApi:y.responseSize,requests:B,data:{block:b,blockStatus:y,blockVariables:x}}}),[i,o,n]),h=useMemo(()=>{let b={requests:0,blocks:0,totalDuration:0,maxDuration:0,avgDuration:0,avgSizeBlock:0,totalSizeBlock:0,avgSizeApi:0,totalSizeApi:0},C=v.filter(d=>m?d.type===z.SECTION_FLAG:true);return b.requests=C.reduce((d,y)=>d+y.requests.length,0),b.blocks=C.length,C.forEach(d=>{d.duration>b.maxDuration&&(b.maxDuration=d.duration),b.totalDuration+=d.duration,b.totalSizeBlock+=d.sizeBlock||0,b.totalSizeApi+=d.sizeApi||0;}),v.length>0&&(b.avgDuration=b.requests>0?b.totalDuration/b.requests:0,b.avgSizeBlock=b.blocks>0?b.totalSizeBlock/b.blocks:0,b.avgSizeApi=b.requests>0?b.totalSizeApi/b.requests:0),b},[v]);return useEffect(()=>{c||t(e.id,h);},[c]),jsxs(Stack,{px:"md",mt:"md",spacing:0,children:[jsxs(Group,{children:[c&&jsx(Loader,{size:"xs",color:"blue"}),!c&&jsx(IconCircleCheckFilled,{color:"green",size:"1rem"}),jsxs(Title,{order:4,children:["Section #",e.id," ",e.settings?.name," ",g]})]}),jsxs(Stack,{spacing:0,mb:"xs",ml:"2rem",children:[jsxs(Group,{spacing:"md",children:[jsxs(Text,{size:"sm",children:["Requests: ",h.requests]}),jsxs(Text,{size:"sm",children:["Total Size: ",h.totalSizeApi.toFixed(2)," Kb"]}),jsxs(Text,{size:"sm",children:["Avg Size: ",h.avgSizeApi.toFixed(2)," Kb"]}),jsxs(Text,{size:"sm",children:["Total Duration: ",h.totalDuration.toFixed(3),"s"]}),jsxs(Text,{size:"sm",children:["Max Duration: ",h.maxDuration.toFixed(3),"s"]}),jsxs(Text,{size:"sm",children:["Avg Duration: ",h.avgDuration.toFixed(3),"s"]})]}),jsxs(Group,{spacing:"md",children:[jsxs(Text,{size:"sm",children:["Blocks: ",h.blocks]}),jsxs(Text,{size:"sm",children:["Total Size: ",h.totalSizeBlock.toFixed(2)," Kb"]}),jsxs(Text,{size:"sm",children:["Avg Size: ",h.avgSizeBlock.toFixed(2)," Kb"]})]})]}),jsx(MantineReactTable,{columns:S,data:v,enablePagination:true,mantinePaginationProps:{showRowsPerPage:false,rowsPerPageOptions:["5","10"],disabled:c},enableBottomToolbar:true,enableColumnActions:false,enableColumnResizing:false,enableEditing:false,enableFullScreenToggle:false,enableGlobalFilter:false,enableRowActions:false,enableRowSelection:false,enableStickyHeader:false,enableStickyFooter:false,enableTopToolbar:false,initialState:{sorting:[{id:"order",desc:false}]},renderDetailPanel:({row:b})=>{let C=b.original.requests;return C.length===0?jsx(Text,{size:"xs",children:"No requests."}):jsx(Stack,{spacing:0,children:C.map((d,y)=>jsxs(Group,{spacing:0,noWrap:true,children:[jsxs(Text,{children:[y+1,"."]}),jsx(Text,{size:"xs",children:jsx("a",{href:d.swapped,target:"_blank",rel:"noopener noreferrer",children:d.original})})]},y))})},positionExpandColumn:"last"})]})}var qg=cb(KP,Ea$1);function Xg(e){let{report:t}=e,o=va$1(a=>a.status.isRunConsumersRunning.length>0),n=va$1(a=>a.status.previews),[r,i]=useState({}),s=(a,u)=>{i({...r,[a]:u});},l=useMemo(()=>{let a={requests:0,blocks:0,totalDuration:0,maxDuration:0,avgDuration:0,avgSizeBlock:0,totalSizeBlock:0,avgSizeApi:0,totalSizeApi:0};return Object.values(r).forEach(u=>{a.requests+=u.requests||0,a.blocks+=u.blocks||0,a.totalDuration+=u.totalDuration||0,a.maxDuration=Math.max(a.maxDuration,u.maxDuration||0),a.totalSizeBlock+=u.totalSizeBlock||0,a.totalSizeApi+=u.totalSizeApi||0;}),a.avgDuration=a.requests>0?a.totalDuration/a.requests:0,a.avgSizeBlock=a.blocks>0?a.totalSizeBlock/a.blocks:0,a.avgSizeApi=a.requests>0?a.totalSizeApi/a.requests:0,a},[r]);return jsxs(Box,{children:[jsxs(Stack,{pos:"fixed",bg:o?"#fab005":"#e7f5ff",px:"md",py:"xs",w:"100%",style:{zIndex:20},spacing:0,children:[jsxs(Group,{children:[o&&jsx(Loader,{size:"xs",color:"blue"}),!o&&jsx(IconCircleCheckFilled,{color:"green",size:"1rem"}),jsxs(Title,{order:3,children:[o?"Generating Debug Report. Please wait...":"Debug Report",":"]}),jsx(Title,{order:3,variant:"dimmed",children:n.map(a=>`${a.variant_slug}/${a.slug}`).join("/")})]}),jsxs(Stack,{spacing:0,ml:"2rem",children:[jsxs(Group,{spacing:"md",children:[jsxs(Text,{size:"sm",children:["Requests: ",l.requests]}),jsxs(Text,{size:"sm",children:["Total Size: ",l.totalSizeApi.toFixed(2)," Kb"]}),jsxs(Text,{size:"sm",children:["Avg Size: ",l.avgSizeApi.toFixed(2)," Kb"]}),jsxs(Text,{size:"sm",children:["Total Duration: ",l.totalDuration.toFixed(3),"s"]}),jsxs(Text,{size:"sm",children:["Max Duration: ",l.maxDuration.toFixed(3),"s"]}),jsxs(Text,{size:"sm",children:["Avg Duration: ",l.avgDuration.toFixed(3),"s"]})]}),jsxs(Group,{spacing:"md",children:[jsxs(Text,{size:"sm",children:["Blocks: ",l.blocks]}),jsxs(Text,{size:"sm",children:["Total Size: ",l.totalSizeBlock.toFixed(2)," Kb"]}),jsxs(Text,{size:"sm",children:["Avg Size: ",l.avgSizeBlock.toFixed(2)," Kb"]})]})]})]}),jsx(Stack,{mt:"5.5rem",children:t.sections.map(a=>jsx(qg,{id:a,setSectionTotals:s},a))})]})}function th(e){let{id:t}=e,o=Da$1(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(mR,{report:o.data,locale:e.locale,isLoading:false}),[o.status,o.data?.sections])}function mR(e$1){let{report:t,isLoading:o}=e$1,n=useMantineTheme(),r=ua(),i=useContext(db$1),s=Ya(i),{newConfirmation:l}=b(),a=va$1(k=>k.status.previews),u=va$1(a$5),{activeEntity:c,selectEntity:p}=Ka(),f=Za("tools"),m=Za("settings"),g=Za("debugView"),S=useMemo(()=>t.sections,[t.sections]),v=useRef(null),h=useCallback(k=>{let R=()=>{p({type:"section",id:k}),s({sid:k});};a.length<t.dimensions.length?l({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(R,()=>{}):R();},[t.dimensions,a]),b$1=useCallback(k=>{if(!k.destination||k.source.index===k.destination.index)return;let R=Number.parseInt(k.draggableId,10),B=k.destination.index>k.source.index,N=e(u,S,k.destination.index,false,B),$=S.slice(),K=$.splice(k.source.index,1);$.splice(k.destination.index,0,...K),r(ta$1.updateEntity("section",{id:R,ordering:N})).then(()=>{r(ta$1.readEntity("report",{id:t.id,include:true}));});},[u,S]),C=useCallback(k=>jsxs("div",{ref:k.innerRef,className:"cms-droppable-container",...k.droppableProps,children:[S.map((R,B)=>jsx(Draggable,{draggableId:`${R}`,index:B,children:(N,$)=>jsxs("div",{className:`cms-section-container${$.isDragging?" isDragging":""}`,ref:N.innerRef,...N.draggableProps,style:{...N.draggableProps.style,boxShadow:$.isDragging?n.shadows.sm:void 0},children:[jsx(Cg,{id:R,isDragging:$.isDragging,onActivate:h,dragHandleProps:N.dragHandleProps,position:B}),jsx(Center,{className:"cms-section-controls",m:"md",children:jsx(Qg,{index:B+1,report:t})})]},`section-${R}`)},R)),k.placeholder]}),[S,c.id,h]),y=!!c.id?50:0,x=50+(f.opened?350:50)+(m.opened?350:y);return jsxs(Box,{children:[jsx(Ld,{report:t}),jsxs(Flex,{children:[!g.opened&&jsx(Zc,{scrollContainer:v}),jsx(Box,{sx:{flexGrow:1},pos:"relative",children:jsx(ScrollArea,{w:`calc(100vw - ${x}px)`,viewportRef:v,h:"calc(100vh - 50px)",styles:{scrollbar:{zIndex:9999}},offsetScrollbars:true,children:jsxs(Stack,{styles:{backgroundColor:n.colors.gray[2]},spacing:0,children:[g.opened&&jsx(Xg,{report:t}),!g.opened&&jsxs(Fragment,{children:[jsx(LoadingOverlay,{visible:o}),t.sections.length===0&&jsx(Center,{className:"cms-section-controls",my:"md",children:jsx(Qg,{index:0,report:t})}),jsx(DragDropContext,{onDragEnd:b$1,children:jsx(Droppable,{droppableId:"sections",children:C})})]})]})})}),c.type&&jsx(ru,{})]})]})}function Qg({index:e$1,report:t}){let o=useMantineTheme(),n=ua(),r=va$1(s=>s.records.entities.section),i=useCallback(()=>{n(ta$1.createEntity("section",{report_id:t.id,ordering:e(r,t.sections,e$1,true)}));},[e$1]);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})})}var rh={value:"all",label:"All"},TR=e=>{if(!e)return [];let t=Object.keys(e).map(o=>({value:String(o),label:String(e[o])}));return [rh,...t]};function ih({onChange:e,loading:t,onEditCreation:o}){let n=ua(),[r,i]=useState(""),[s,l]=useState(false),[a]=useDebouncedValue(r,500),u={type:rh.value},[c,p]=useState(u),f=()=>{i(""),p(u);},m=useMemo(()=>({type:TR(E$1)}),[]);useEffect(()=>{e({...c,query:a});},[c.type,a]);let g=()=>{l(true);let v=Math.random().toString(16).substring(2,10);n(ta$1.createEntity("formatter",{name:`formatter_${v}`,content:{type:"formatter",logic:"return n;",inputType:"string",testValue:"123456",description:"New formatter"}})).then(h=>{l(false),f(),h.ok&&o(h.data.id);});},S=useCallback((v,h)=>{let b={...c,[v]:h};p(b);},[c]);return jsxs("div",{children:[jsx(TextInput,{label:"Search by name or description",value:r,onChange:v=>i(v.currentTarget.value),disabled:t}),jsx(Select,{label:"Type",data:m.type,value:c.type,onChange:v=>S("type",v),disabled:t}),jsx(Space,{h:"md"}),jsx(Button,{fullWidth:true,disabled:t,leftIcon:jsx(IconCircleX,{}),onClick:f,children:"Clear filters"}),jsx(Space,{h:"md"}),jsx(Button,{fullWidth:true,disabled:t,leftIcon:jsx(IconPlus,{}),onClick:g,variant:"light",loading:s,children:"New formatter"})]})}var fh=e=>e?Object.keys(e).map(t=>({value:String(t),label:String(e[t])})):[],OR=(e,t)=>{switch(e){case F$1.OBJECT:return JSON.parse(t);default:return `${t}`}};function gh({formatterId:e,onEditEnd:t}){let o=va$1(T=>T.status.localeDefault),n=!!e,[r,i]=useState(),[s,l]=useState(""),[a,u]=useState([]),[c,p]=useState(true),[f,m]=useState(false),[g,S]=useState(true),[v,h]=useState(true),[b]=useState(false),C=ua(),d=Ia$1(e),y=Ba$1(),x=Ta$1(d.data?.name),k=c||f;useEffect(()=>{d.isLoading||i(d.data);},[d.isLoading]),useEffect(()=>{if(!d.isLoading&&!y.isLoading){let T=d.isSuccess?d.data:void 0,M=y.isSuccess?y.data:[];if(T){let I=M.filter(O=>O.id!==T.id).map(O=>O.name);u(I);}$(),p(false);}},[d.isLoading,y.isLoading]);let R=r&&!a.includes(r.name)&&r.name!=="",B=T=>{R&&h(false),r&&i({...r,name:na(T).replace("-","")});},N=(T,M)=>{T!=="description"&&S(true),r&&i({...r,content:{...r.content,[T]:M}});},$=()=>{if(r){let T="";try{let M=i$2({vars:["n"],logic:r.content.logic},{},o,{}),I=OR(r.content.inputType,r.content.testValue);T=M(I),h(!0);}catch(M){T=`ERROR: ${M.message}`,console.error(M),h(false);}S(false),l(`${T}`);}},K=()=>{m(true),v&&R&&C(ta$1.updateEntity("formatter",r)).then(t);};return jsx(Drawer,{opened:n,onClose:()=>t(),title:`Edit formatter ID ${e}`,padding:"lg",closeOnClickOutside:false,closeOnEscape:false,position:"right",size:"50%",lockScroll:true,withCloseButton:false,children:jsx(bt,{content:jsxs(Fragment,{children:[jsx(LoadingOverlay,{visible:c,overlayBlur:2,overlayOpacity:.5}),b&&jsx(Alert,{title:"Formatter Form",color:"red",children:"Error, please try again."}),r&&!b&&jsxs(Stack,{justify:"space-between",children:[jsxs(Group,{grow:true,align:"flex-start",children:[jsx(TextInput,{label:`Name ${R&&x>0?`(Read only, used in ${x} blocks)`:""}`,value:r.name,icon:R?jsx(IconCircleCheck,{}):jsx(IconAlertCircle,{}),readOnly:R&&x>0,disabled:R&&x>0,onChange:T=>B(T.target.value),error:R?false:"Duplicate or empty name, choose a different one."}),jsx(Select,{label:"Type",data:fh(E$1),value:r.content.type,onChange:T=>N("type",T)})]}),jsx(Textarea,{label:"Description",value:r.content.description,onChange:T=>N("description",T.target.value)}),jsx(rn,{monacoOptions:{onChange:T=>N("logic",T),height:"30vh",value:r.content.logic}},"formatter-code-editor"),jsxs(Group,{grow:true,align:"flex-end",children:[jsx(Select,{label:"Input Type",data:fh(G$1),value:r.content.inputType,onChange:T=>N("inputType",T)}),jsx(TextInput,{label:"Test Value",value:r.content.testValue,onChange:T=>N("testValue",T.target.value),error:r.content.testValue===""&&!v})]}),jsx(Textarea,{readOnly:true,icon:v?jsx(IconCircleCheck,{}):jsx(IconAlertCircle,{}),label:"Test Results",value:s,error:s.includes("ERROR")&&!v?"There is a problem in the function, input type or test value. Please check and run again.":false})]})]}),buttons:jsxs(Fragment,{children:[jsx(Button,{variant:"outline",disabled:k,onClick:()=>t(),children:"Cancel"}),jsx(Button,{onClick:$,disabled:!g,color:g?"blue":v?"green":"red",leftIcon:jsx(IconPlayerPlay,{}),children:"Run Test"}),jsx(Button,{onClick:K,loading:k,disabled:k||!v||g||!R,children:"Save"})]}),size:165})})}var $R=(e,t)=>{switch(e){case F$1.OBJECT:return JSON.parse(t);default:return `${t}`}};function yh({filters:e,onClickEdit:t}){let[o,n]=useState([]),r=Ba$1(),i=r.isSuccess?r.data:[],s=Oa$1(),l=Ua(),a=useMemo(()=>i.map(p=>{let f=l[p.name]?l[p.name]:0,m="";try{let g=$R(p.content.inputType,p.content.testValue);m=s[p.name](g);}catch(g){m=`ERROR: ${g.message}`,console.error(`Error in ${p.name}`),console.error(g);}return {...p,result:m,usageCount:f}}),[i]),u=()=>{let p=a.filter(f=>{let m=true,g=true;return e.query&&(m=f.name.toLowerCase().indexOf(e.query.toLowerCase())>-1||f.content.description.indexOf(e.query)>-1),e.type!=="all"&&(g=f.content.type===e.type),m&&g});n(p);};return useEffect(()=>{u();},[e,a]),jsx(MantineReactTable,{columns:[{header:"ID",accessorKey:"id",minSize:55,size:55,maxSize:55},{header:"Name",accessorKey:"name",Cell:({row:p})=>{let f=p.original.content.type===D$1.FORMATTER?jsx(IconVariable,{size:"1.3em"}):jsx(IconMathFunction,{size:"1.3em"});return jsxs(Group,{noWrap:true,align:"center",spacing:2,children:[jsx("span",{children:p.original.name}),jsx(Tooltip,{label:E$1[p.original.content.type],children:jsx("span",{children:f})})]})},minSize:80,size:80},{header:"Description",accessorKey:"content.description",enableSorting:false,mantineTableBodyCellProps:{sx:{textWrap:"wrap"}},minSize:100},{header:"Demo",accessorKey:"content.testValue",Cell:({row:p})=>{let f=p.original.content.testValue;p.original.content.inputType===F$1.STRING&&(f=`"${f}"`);let m=p.original.result;return typeof p.original.result=="string"&&(m=`"${m}"`),jsxs(Group,{spacing:2,children:[jsx(Tooltip,{label:`Input Type: ${G$1[p.original.content.inputType]}`,children:jsx(Code,{color:"blue",children:f})}),jsx(IconArrowRightCircle,{}),jsx(Code,{color:p.original.result&&`${p.original.result}`.includes("ERROR")?"red":"teal",children:m})]})},enableSorting:false,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:true,children:[jsx(ActionIcon,{onClick:()=>t(p.original),children:jsx(IconPencil,{size:20})},"edit"),jsx(Bt,{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:false,minSize:80,size:80,maxSize:80,mantineTableHeadCellProps:{align:"center"},mantineTableBodyCellProps:{align:"center"}}],data:o,enableBottomToolbar:false,enableColumnActions:false,enableColumnResizing:true,enablePagination:false,enableTopToolbar:false,initialState:{density:"xs"},layoutMode:"grid",mantineTableContainerProps:{sx:{minHeight:150}},mantineTableProps:{striped:true}})}function Sh(){let[e,t]=useState(null),[o,n]=useState(true),r=a=>{n(a);},i=a=>{t(a);},s=a=>{a&&t(a.id);},l=()=>{t(null);};return jsxs(Container,{fluid:true,children:[jsxs(Grid,{children:[jsxs(Grid.Col,{span:2,children:[jsx(Text,{ml:"xl",my:"sm",weight:"bold",children:"Formatters"}),jsx(ih,{onChange:r,onEditCreation:i,loading:false})]}),jsxs(Grid.Col,{span:10,style:{height:"100vh"},children:[jsx(Space,{h:"xs"}),jsx(yh,{filters:o,onClickEdit:s})]})]}),e&&jsx(gh,{formatterId:e,onEditEnd:l})]})}function wh({onChange:e,loading:t,onEditCreation:o}){let n=ua(),[r,i]=useState(""),[s,l]=useState(""),[a,u]=useState(false),[c]=useDebouncedValue(r,500),[p]=useDebouncedValue(s,500),f={query:"",name:""},[m,g]=useState(f),S=()=>{i(""),l(""),g(f);},v=()=>{l(""),g(C=>({...C,name:""}));},h=()=>{i(""),g(C=>({...C,query:""}));};return useEffect(()=>{let C={...m,name:p,query:c,matchPattern:d=>{if(!c)return true;try{return new RegExp(d.patternSwapped).test(c)}catch{return false}}};e(C);},[c,p]),jsxs("div",{children:[jsx(TextInput,{label:"Filter by name",value:s,onChange:C=>l(C.currentTarget.value),disabled:t,rightSection:s?jsx(IconCircleX,{size:16,style:{cursor:"pointer"},onClick:v}):null}),jsx(Space,{h:"md"}),jsx(TextInput,{label:"Test a url here",value:r,onChange:C=>i(C.currentTarget.value),disabled:t,rightSection:r?jsx(IconCircleX,{size:16,style:{cursor:"pointer"},onClick:h}):null}),jsx(Space,{h:"md"}),jsx(Button,{fullWidth:true,disabled:t,leftIcon:jsx(IconPlus,{}),onClick:()=>{u(true);let C=Math.random().toString(16).substring(2,10);n(ta$1.createEntity("datasource",{name:`datasource_${C}`,description:"New Data Source",content:{pattern:"",logic:`
35
+ }`}}}})).then(()=>{l();});});},m=n?.settings||{},{settings:f$1,updateSettings:g}=h(t),S=useMemo(()=>[{key:"optionData",label:"Download data (csv, xls, json)"},{key:"optionImage",label:"Save Image"},{key:"optionShare",label:"Share link"}],[]),v=useMemo(()=>S.map(y=>jsxs(List.Item,{children:[y.label,"."]},`item-${y.key}`)),[S]);if(e.type!=="section"||!e.id)return null;let h$1=useMemo(()=>[{value:"always",label:"Always"},{value:"section-flag",label:"Use Section Flag"}],[]),b=useMemo(()=>[{value:"always",label:"Always"},{value:"never",label:"Never"},{value:"optional",label:"Optional"}],[]),C=r?"section-flag":"always";if(e.type!=="section"||!e.id)return null;let d=f$1.showInPdf||"optional";return jsxs("div",{children:[jsx(EP,{activeSection:t}),jsx(IP,{activeSection:t}),jsx(Divider,{my:"sm"}),jsxs(Stack,{mt:"sm",children:[jsx(H$1,{target:jsx(Switch,{radius:"sm",label:"Client-side section",checked:f$1.clientSideSection,onChange:y=>g("clientSideSection",y.currentTarget.checked)}),dropdown:jsx(Text,{size:"sm",maw:200,children:"Resolve section content on the client side, this is helpful for large reports improving performance."})}),jsxs(Stack,{spacing:"0.4rem",children:[jsx(H$1,{target:jsx(Switch,{radius:"sm",label:"Show export menu.",checked:f$1.optionsMenu,onChange:y=>g("optionsMenu",y.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:true,size:"sm",children:v})]})}),f$1.optionsMenu&&jsx(Stack,{spacing:"0.5rem",pl:"md",children:S.map(y=>jsx(Switch,{radius:"sm",label:y.label,checked:typeof f$1[y.key]>"u"?f$1.optionsMenu:f$1[y.key],onChange:x=>g(y.key,x.currentTarget.checked)},y.key))})]}),jsx(H$1,{target:jsx(Switch,{radius:"sm",label:"Show anchor link.",checked:f$1.showAnchor,onChange:y=>g("showAnchor",y.currentTarget.checked)}),dropdown:jsx(Text,{size:"sm",maw:200,children:"Show `#` link on top left corner of the section"})}),jsx(H$1,{target:jsx(Switch,{radius:"sm",label:"Show section.",checked:!f$1.hidden,onChange:y=>g("hidden",!y.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(H$1,{target:jsx(Select,{label:"Show in PDF",value:d,data:b,disabled:!s,onChange:y=>g("showInPdf",y)}),dropdown:jsx(Text,{size:"sm",maw:200,children:s?"Hide or show the section in the pdf report.":"PDF API URL is not set."})}),jsx(H$1,{target:jsx(Select,{label:"Allow section",placeholder:"Select an option",description:r?`Controlled by Section Flag #${r.id}`:"Section always visible",value:C,data:h$1,onChange:u}),dropdown:jsx(Text,{size:"sm",maw:200,children:"You can control section visibility (allow) creating a Section Flag Block"})}),r&&jsx(Stack,{spacing:"xs",children:jsx(ur,{id:Number(r.id),active:!!t,isInput:false,isConsumer:false,setHoverBlock:()=>{},showOutline:false})}),m.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:f$1.comparisonHide,onChange:y=>g("comparisonHide",y.currentTarget.checked)}),jsx(Switch,{radius:"sm",label:"Show once in comparison",checked:f$1.comparisonMerge,onChange:y=>g("comparisonMerge",y.currentTarget.checked)})]})})]})})]})]},`settings-${t}`)}function ou(e){let{label:t,labelProps:o,...n}=e;return jsxs(Stack,{spacing:"md",children:[jsx(Text,{...o,children:t}),jsx(SegmentedControl,{...n})]})}function ru(){let{activeEntity:e}=Ka(),t=e.id,{settings:o,updateSettings:n}=h(t);return e.type!=="section"||!e.id?null:jsxs(Fragment,{children:[jsxs(Stack,{spacing:"md",children:[jsx(Text,{children:"Image"}),jsx(H$1,{target:jsx(Switch,{radius:"sm",label:"Show image background",checked:o.memberImageBg,onChange:r=>n("memberImageBg",r.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(A$1).map(r=>jsx(ou,{label:A$1[r].label,data:A$1[r].options,value:String(o[r]||A$1[r].defaultValue),onChange:i=>n(r,i)},r))]})}var Ug={report:[{label:"Settings",value:"settings",component:jsx(J,{})}],section:[{label:"Style",value:"style",component:jsx(ru,{})},{label:"Settings",value:"settings",component:jsx(tu,{})}],block:[{label:"Content",value:"content",component:null},{label:"Style",value:"style",component:null},{label:"Settings",value:"settings",component:null}]};function iu(){let{opened:e,handlers:t}=Za("settings"),[o,n]=useState("settings"),r=s=>n(s),{activeEntity:i}=Ka();if(!i.type)return null;let a=Ug[i.type].find(s=>s.value===o)?.component||null,l=e&&jsx(Fragment,{children:jsxs("div",{children:[i.type==="report"?jsx(Text,{children:"Report Settings"}):jsx(SegmentedControl,{value:o,data:Ug[i.type],onChange:r,fullWidth:true}),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:s=>({overflow:"hidden",borderLeft:`1px solid ${s.colors.gray[2]}`,flexShrink:0,flexGrow:0}),children:[l,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})})})]})}function qP({for:e,setSectionTotals:t}){let o=va$1(b=>b.variables.status),n=va$1(b=>b.variables.variables),r=Aa$1(e.blocks),i=useMemo(()=>{if(r.isSuccess){let b=new Map(e.blocks.map((C,d)=>[C,d]));return r.data.slice().filter(C=>[z.GENERATOR,z.SECTION_FLAG].includes(C.type)).sort((C,d)=>{if(C.type===z.SECTION_FLAG&&d.type!==z.SECTION_FLAG)return -1;if(d.type===z.SECTION_FLAG&&C.type!==z.SECTION_FLAG)return 1;let y=b.get(C.id)??Number.MAX_VALUE,x=b.get(d.id)??Number.MAX_VALUE;return y-x})}else return []},[r.isLoading,r.isSuccess,e.blocks]);if(i.length===0)return null;let{hidden:a}=e.settings,l=useContext(db$1),s=Ya(l),c=va$1(b=>b.status.isRunConsumersRunning).includes(e.id),p=va$1(b=>b.status.previews);useEffect(()=>{s({sid:e.id});},[e.id,p]);let m=useMemo(()=>{let b=i.filter(C=>C.section_id===e.id&&W(C));return b.length>1&&console.error(`Error, there are more than one Section Flag Generator in section ${e.id}`),b.length>0?b[0]:false},[r,e.id]),f=va$1(b=>m&&b.variables.variables[m.id]&&!b.variables.variables[m.id][T]||false),g=useMemo(()=>{let b="";return f&&m&&(b+=`(Not allowed by Section Flag #${m.id})`),a&&(b+="(Hidden by Section Settings)"),b},[a,f]),S=useMemo(()=>[{accessorKey:"status",header:"",Cell:({cell:b})=>f&&b.row.original.type!==z.SECTION_FLAG?jsx(IconCircleX,{size:"1rem"}):jsx(Fragment,{children:b.getValue()?jsx(Loader,{size:"1rem",color:"blue"}):jsx(IconCircleCheckFilled,{color:"green",size:"1rem"})}),enableSorting:false,size:50,minSize:50,maxSize:50},{accessorKey:"order",header:"Order",size:50,minSize:50,maxSize:50},{accessorKey:"id",header:"ID",size:50,minSize:50,maxSize:50},{accessorKey:"type",header:"Type",size:100,minSize:100,maxSize:100,Cell:({cell:b})=>{let C=O$1(b.getValue());return jsxs(Group,{spacing:0,noWrap:true,children:[jsx(C,{size:16}),jsx(Text,{size:"xs",ml:"xs",children:Q(b.getValue())})]})}},{accessorKey:"duration",header:"Duration",size:100,minSize:100,maxSize:100,Cell:({cell:b})=>`${b.getValue().toFixed(3)}s`},{accessorKey:"sizeApi",header:"API Size",size:100,minSize:100,maxSize:100,Cell:({cell:b})=>b.getValue()?`\u2248${b.getValue().toFixed(2)} Kb`:""},{accessorKey:"sizeBlock",header:"Block Size",size:100,minSize:100,maxSize:100,Cell:({cell:b})=>`\u2248${b.getValue().toFixed(2)} Kb`},{accessorKey:"data",header:"",enableSorting:false,Cell:({cell:b})=>{let C=b.getValue();return jsx(pa,{block:C.block,status:C.blockStatus,variables:C.blockVariables})}}],[]),v=useMemo(()=>i.map((b,C)=>{let d=!!b.contentByLocale?.logic?.content?.api,y=o[b.id]||{},x=n[b.id]||{},k=y.duration?y.duration/1e3:0,B=(y.api&&y.api!==""?y.api.split("|||"):[]).map((N,$)=>({original:N,swapped:y.apiFinalUrls[$]}));return {order:C+1,id:b.id,type:b.type,duration:k,status:d&&!Object.keys(x).length&&!y.error,sizeBlock:JSON.stringify(x).length/1024,sizeApi:y.responseSize,requests:B,data:{block:b,blockStatus:y,blockVariables:x}}}),[i,o,n]),h=useMemo(()=>{let b={requests:0,blocks:0,totalDuration:0,maxDuration:0,avgDuration:0,avgSizeBlock:0,totalSizeBlock:0,avgSizeApi:0,totalSizeApi:0},C=v.filter(d=>f?d.type===z.SECTION_FLAG:true);return b.requests=C.reduce((d,y)=>d+y.requests.length,0),b.blocks=C.length,C.forEach(d=>{d.duration>b.maxDuration&&(b.maxDuration=d.duration),b.totalDuration+=d.duration,b.totalSizeBlock+=d.sizeBlock||0,b.totalSizeApi+=d.sizeApi||0;}),v.length>0&&(b.avgDuration=b.requests>0?b.totalDuration/b.requests:0,b.avgSizeBlock=b.blocks>0?b.totalSizeBlock/b.blocks:0,b.avgSizeApi=b.requests>0?b.totalSizeApi/b.requests:0),b},[v]);return useEffect(()=>{c||t(e.id,h);},[c]),jsxs(Stack,{px:"md",mt:"md",spacing:0,children:[jsxs(Group,{children:[c&&jsx(Loader,{size:"xs",color:"blue"}),!c&&jsx(IconCircleCheckFilled,{color:"green",size:"1rem"}),jsxs(Title,{order:4,children:["Section #",e.id," ",e.settings?.name," ",g,e.settings?.clientSideSection&&jsx(Text,{component:"span",inherit:true,c:"orange.7",children:" \u2014 Client Side Section"})]})]}),jsxs(Stack,{spacing:0,mb:"xs",ml:"2rem",children:[jsxs(Group,{spacing:"md",children:[jsxs(Text,{size:"sm",children:["Requests: ",h.requests]}),jsxs(Text,{size:"sm",children:["Total Size: ",h.totalSizeApi.toFixed(2)," Kb"]}),jsxs(Text,{size:"sm",children:["Avg Size: ",h.avgSizeApi.toFixed(2)," Kb"]}),jsxs(Text,{size:"sm",children:["Total Duration: ",h.totalDuration.toFixed(3),"s"]}),jsxs(Text,{size:"sm",children:["Max Duration: ",h.maxDuration.toFixed(3),"s"]}),jsxs(Text,{size:"sm",children:["Avg Duration: ",h.avgDuration.toFixed(3),"s"]})]}),jsxs(Group,{spacing:"md",children:[jsxs(Text,{size:"sm",children:["Blocks: ",h.blocks]}),jsxs(Text,{size:"sm",children:["Total Size: ",h.totalSizeBlock.toFixed(2)," Kb"]}),jsxs(Text,{size:"sm",children:["Avg Size: ",h.avgSizeBlock.toFixed(2)," Kb"]})]})]}),jsx(MantineReactTable,{columns:S,data:v,enablePagination:true,mantinePaginationProps:{showRowsPerPage:false,rowsPerPageOptions:["5","10"],disabled:c},enableBottomToolbar:true,enableColumnActions:false,enableColumnResizing:false,enableEditing:false,enableFullScreenToggle:false,enableGlobalFilter:false,enableRowActions:false,enableRowSelection:false,enableStickyHeader:false,enableStickyFooter:false,enableTopToolbar:false,initialState:{sorting:[{id:"order",desc:false}]},renderDetailPanel:({row:b})=>{let C=b.original.requests;return C.length===0?jsx(Text,{size:"xs",children:"No requests."}):jsx(Stack,{spacing:0,children:C.map((d,y)=>jsxs(Group,{spacing:0,noWrap:true,children:[jsxs(Text,{children:[y+1,"."]}),jsx(Text,{size:"xs",children:jsx("a",{href:d.swapped,target:"_blank",rel:"noopener noreferrer",children:d.original})})]},y))})},positionExpandColumn:"last"})]})}var qg=cb(qP,Ea$1);function Xg(e){let{report:t}=e,o=va$1(s=>s.status.isRunConsumersRunning.length>0),n=va$1(s=>s.status.previews),[r,i]=useState({}),a=(s,u)=>{i({...r,[s]:u});},l=useMemo(()=>{let s={requests:0,blocks:0,totalDuration:0,maxDuration:0,avgDuration:0,avgSizeBlock:0,totalSizeBlock:0,avgSizeApi:0,totalSizeApi:0};return Object.values(r).forEach(u=>{s.requests+=u.requests||0,s.blocks+=u.blocks||0,s.totalDuration+=u.totalDuration||0,s.maxDuration=Math.max(s.maxDuration,u.maxDuration||0),s.totalSizeBlock+=u.totalSizeBlock||0,s.totalSizeApi+=u.totalSizeApi||0;}),s.avgDuration=s.requests>0?s.totalDuration/s.requests:0,s.avgSizeBlock=s.blocks>0?s.totalSizeBlock/s.blocks:0,s.avgSizeApi=s.requests>0?s.totalSizeApi/s.requests:0,s},[r]);return jsxs(Box,{children:[jsxs(Stack,{pos:"fixed",bg:o?"#fab005":"#e7f5ff",px:"md",py:"xs",w:"100%",style:{zIndex:20},spacing:0,children:[jsxs(Group,{children:[o&&jsx(Loader,{size:"xs",color:"blue"}),!o&&jsx(IconCircleCheckFilled,{color:"green",size:"1rem"}),jsxs(Title,{order:3,children:[o?"Generating Debug Report. Please wait...":"Debug Report",":"]}),jsx(Title,{order:3,variant:"dimmed",children:n.map(s=>`${s.variant_slug}/${s.slug}`).join("/")})]}),jsxs(Stack,{spacing:0,ml:"2rem",children:[jsxs(Group,{spacing:"md",children:[jsxs(Text,{size:"sm",children:["Requests: ",l.requests]}),jsxs(Text,{size:"sm",children:["Total Size: ",l.totalSizeApi.toFixed(2)," Kb"]}),jsxs(Text,{size:"sm",children:["Avg Size: ",l.avgSizeApi.toFixed(2)," Kb"]}),jsxs(Text,{size:"sm",children:["Total Duration: ",l.totalDuration.toFixed(3),"s"]}),jsxs(Text,{size:"sm",children:["Max Duration: ",l.maxDuration.toFixed(3),"s"]}),jsxs(Text,{size:"sm",children:["Avg Duration: ",l.avgDuration.toFixed(3),"s"]})]}),jsxs(Group,{spacing:"md",children:[jsxs(Text,{size:"sm",children:["Blocks: ",l.blocks]}),jsxs(Text,{size:"sm",children:["Total Size: ",l.totalSizeBlock.toFixed(2)," Kb"]}),jsxs(Text,{size:"sm",children:["Avg Size: ",l.avgSizeBlock.toFixed(2)," Kb"]})]})]})]}),jsx(Stack,{mt:"5.5rem",children:t.sections.map(s=>jsx(qg,{id:s,setSectionTotals:a},s))})]})}function th(e){let{id:t}=e,o=Da$1(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(gR,{report:o.data,locale:e.locale,isLoading:false}),[o.status,o.data?.sections])}function gR(e$1){let{report:t,isLoading:o}=e$1,n=useMantineTheme(),r=ua(),i=useContext(db$1),a=Ya(i),{newConfirmation:l}=b(),s=va$1(k=>k.status.previews),u=va$1(a$5),{activeEntity:c,selectEntity:p}=Ka(),m=Za("tools"),f=Za("settings"),g=Za("debugView"),S=useMemo(()=>t.sections,[t.sections]),v=useRef(null),h=useCallback(k=>{let R=()=>{p({type:"section",id:k}),a({sid:k});};s.length<t.dimensions.length?l({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(R,()=>{}):R();},[t.dimensions,s]),b$1=useCallback(k=>{if(!k.destination||k.source.index===k.destination.index)return;let R=Number.parseInt(k.draggableId,10),B=k.destination.index>k.source.index,N=e(u,S,k.destination.index,false,B),$=S.slice(),K=$.splice(k.source.index,1);$.splice(k.destination.index,0,...K),r(ta$1.updateEntity("section",{id:R,ordering:N})).then(()=>{r(ta$1.readEntity("report",{id:t.id,include:true}));});},[u,S]),C=useCallback(k=>jsxs("div",{ref:k.innerRef,className:"cms-droppable-container",...k.droppableProps,children:[S.map((R,B)=>jsx(Draggable,{draggableId:`${R}`,index:B,children:(N,$)=>jsxs("div",{className:`cms-section-container${$.isDragging?" isDragging":""}`,ref:N.innerRef,...N.draggableProps,style:{...N.draggableProps.style,boxShadow:$.isDragging?n.shadows.sm:void 0},children:[jsx(Cg,{id:R,isDragging:$.isDragging,onActivate:h,dragHandleProps:N.dragHandleProps,position:B}),jsx(Center,{className:"cms-section-controls",m:"md",children:jsx(Qg,{index:B+1,report:t})})]},`section-${R}`)},R)),k.placeholder]}),[S,c.id,h]),y=!!c.id?50:0,x=50+(m.opened?350:50)+(f.opened?350:y);return jsxs(Box,{children:[jsx(Bd,{report:t}),jsxs(Flex,{children:[!g.opened&&jsx(eu,{scrollContainer:v}),jsx(Box,{sx:{flexGrow:1},pos:"relative",children:jsx(ScrollArea,{w:`calc(100vw - ${x}px)`,viewportRef:v,h:"calc(100vh - 50px)",styles:{scrollbar:{zIndex:9999}},offsetScrollbars:true,children:jsxs(Stack,{styles:{backgroundColor:n.colors.gray[2]},spacing:0,children:[g.opened&&jsx(Xg,{report:t}),!g.opened&&jsxs(Fragment,{children:[jsx(LoadingOverlay,{visible:o}),t.sections.length===0&&jsx(Center,{className:"cms-section-controls",my:"md",children:jsx(Qg,{index:0,report:t})}),jsx(DragDropContext,{onDragEnd:b$1,children:jsx(Droppable,{droppableId:"sections",children:C})})]})]})})}),c.type&&jsx(iu,{})]})]})}function Qg({index:e$1,report:t}){let o=useMantineTheme(),n=ua(),r=va$1(a=>a.records.entities.section),i=useCallback(()=>{n(ta$1.createEntity("section",{report_id:t.id,ordering:e(r,t.sections,e$1,true)}));},[e$1]);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})})}var rh={value:"all",label:"All"},wR=e=>{if(!e)return [];let t=Object.keys(e).map(o=>({value:String(o),label:String(e[o])}));return [rh,...t]};function ih({onChange:e,loading:t,onEditCreation:o}){let n=ua(),[r,i]=useState(""),[a,l]=useState(false),[s]=useDebouncedValue(r,500),u={type:rh.value},[c,p]=useState(u),m=()=>{i(""),p(u);},f=useMemo(()=>({type:wR(E$1)}),[]);useEffect(()=>{e({...c,query:s});},[c.type,s]);let g=()=>{l(true);let v=Math.random().toString(16).substring(2,10);n(ta$1.createEntity("formatter",{name:`formatter_${v}`,content:{type:"formatter",logic:"return n;",inputType:"string",testValue:"123456",description:"New formatter"}})).then(h=>{l(false),m(),h.ok&&o(h.data.id);});},S=useCallback((v,h)=>{let b={...c,[v]:h};p(b);},[c]);return jsxs("div",{children:[jsx(TextInput,{label:"Search by name or description",value:r,onChange:v=>i(v.currentTarget.value),disabled:t}),jsx(Select,{label:"Type",data:f.type,value:c.type,onChange:v=>S("type",v),disabled:t}),jsx(Space,{h:"md"}),jsx(Button,{fullWidth:true,disabled:t,leftIcon:jsx(IconCircleX,{}),onClick:m,children:"Clear filters"}),jsx(Space,{h:"md"}),jsx(Button,{fullWidth:true,disabled:t,leftIcon:jsx(IconPlus,{}),onClick:g,variant:"light",loading:a,children:"New formatter"})]})}var mh=e=>e?Object.keys(e).map(t=>({value:String(t),label:String(e[t])})):[],MR=(e,t)=>{switch(e){case F$1.OBJECT:return JSON.parse(t);default:return `${t}`}};function gh({formatterId:e,onEditEnd:t}){let o=va$1(T=>T.status.localeDefault),n=!!e,[r,i]=useState(),[a,l]=useState(""),[s,u]=useState([]),[c,p]=useState(true),[m,f]=useState(false),[g,S]=useState(true),[v,h]=useState(true),[b]=useState(false),C=ua(),d=Ia$1(e),y=Ba$1(),x=Ta$1(d.data?.name),k=c||m;useEffect(()=>{d.isLoading||i(d.data);},[d.isLoading]),useEffect(()=>{if(!d.isLoading&&!y.isLoading){let T=d.isSuccess?d.data:void 0,M=y.isSuccess?y.data:[];if(T){let I=M.filter(O=>O.id!==T.id).map(O=>O.name);u(I);}$(),p(false);}},[d.isLoading,y.isLoading]);let R=r&&!s.includes(r.name)&&r.name!=="",B=T=>{R&&h(false),r&&i({...r,name:na(T).replace("-","")});},N=(T,M)=>{T!=="description"&&S(true),r&&i({...r,content:{...r.content,[T]:M}});},$=()=>{if(r){let T="";try{let M=i$2({vars:["n"],logic:r.content.logic},{},o,{}),I=MR(r.content.inputType,r.content.testValue);T=M(I),h(!0);}catch(M){T=`ERROR: ${M.message}`,console.error(M),h(false);}S(false),l(`${T}`);}},K=()=>{f(true),v&&R&&C(ta$1.updateEntity("formatter",r)).then(t);};return jsx(Drawer,{opened:n,onClose:()=>t(),title:`Edit formatter ID ${e}`,padding:"lg",closeOnClickOutside:false,closeOnEscape:false,position:"right",size:"50%",lockScroll:true,withCloseButton:false,children:jsx(yt,{content:jsxs(Fragment,{children:[jsx(LoadingOverlay,{visible:c,overlayBlur:2,overlayOpacity:.5}),b&&jsx(Alert,{title:"Formatter Form",color:"red",children:"Error, please try again."}),r&&!b&&jsxs(Stack,{justify:"space-between",children:[jsxs(Group,{grow:true,align:"flex-start",children:[jsx(TextInput,{label:`Name ${R&&x>0?`(Read only, used in ${x} blocks)`:""}`,value:r.name,icon:R?jsx(IconCircleCheck,{}):jsx(IconAlertCircle,{}),readOnly:R&&x>0,disabled:R&&x>0,onChange:T=>B(T.target.value),error:R?false:"Duplicate or empty name, choose a different one."}),jsx(Select,{label:"Type",data:mh(E$1),value:r.content.type,onChange:T=>N("type",T)})]}),jsx(Textarea,{label:"Description",value:r.content.description,onChange:T=>N("description",T.target.value)}),jsx(rn,{monacoOptions:{onChange:T=>N("logic",T),height:"30vh",value:r.content.logic}},"formatter-code-editor"),jsxs(Group,{grow:true,align:"flex-end",children:[jsx(Select,{label:"Input Type",data:mh(G$1),value:r.content.inputType,onChange:T=>N("inputType",T)}),jsx(TextInput,{label:"Test Value",value:r.content.testValue,onChange:T=>N("testValue",T.target.value),error:r.content.testValue===""&&!v})]}),jsx(Textarea,{readOnly:true,icon:v?jsx(IconCircleCheck,{}):jsx(IconAlertCircle,{}),label:"Test Results",value:a,error:a.includes("ERROR")&&!v?"There is a problem in the function, input type or test value. Please check and run again.":false})]})]}),buttons:jsxs(Fragment,{children:[jsx(Button,{variant:"outline",disabled:k,onClick:()=>t(),children:"Cancel"}),jsx(Button,{onClick:$,disabled:!g,color:g?"blue":v?"green":"red",leftIcon:jsx(IconPlayerPlay,{}),children:"Run Test"}),jsx(Button,{onClick:K,loading:k,disabled:k||!v||g||!R,children:"Save"})]}),size:165})})}var GR=(e,t)=>{switch(e){case F$1.OBJECT:return JSON.parse(t);default:return `${t}`}};function yh({filters:e,onClickEdit:t}){let[o,n]=useState([]),r=Ba$1(),i=r.isSuccess?r.data:[],a=Oa$1(),l=Ua(),s=useMemo(()=>i.map(p=>{let m=l[p.name]?l[p.name]:0,f="";try{let g=GR(p.content.inputType,p.content.testValue);f=a[p.name](g);}catch(g){f=`ERROR: ${g.message}`,console.error(`Error in ${p.name}`),console.error(g);}return {...p,result:f,usageCount:m}}),[i]),u=()=>{let p=s.filter(m=>{let f=true,g=true;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});n(p);};return useEffect(()=>{u();},[e,s]),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===D$1.FORMATTER?jsx(IconVariable,{size:"1.3em"}):jsx(IconMathFunction,{size:"1.3em"});return jsxs(Group,{noWrap:true,align:"center",spacing:2,children:[jsx("span",{children:p.original.name}),jsx(Tooltip,{label:E$1[p.original.content.type],children:jsx("span",{children:m})})]})},minSize:80,size:80},{header:"Description",accessorKey:"content.description",enableSorting:false,mantineTableBodyCellProps:{sx:{textWrap:"wrap"}},minSize:100},{header:"Demo",accessorKey:"content.testValue",Cell:({row:p})=>{let m=p.original.content.testValue;p.original.content.inputType===F$1.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: ${G$1[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:false,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:true,children:[jsx(ActionIcon,{onClick:()=>t(p.original),children:jsx(IconPencil,{size:20})},"edit"),jsx(Bt,{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:false,minSize:80,size:80,maxSize:80,mantineTableHeadCellProps:{align:"center"},mantineTableBodyCellProps:{align:"center"}}],data:o,enableBottomToolbar:false,enableColumnActions:false,enableColumnResizing:true,enablePagination:false,enableTopToolbar:false,initialState:{density:"xs"},layoutMode:"grid",mantineTableContainerProps:{sx:{minHeight:150}},mantineTableProps:{striped:true}})}function Sh(){let[e,t]=useState(null),[o,n]=useState(true),r=s=>{n(s);},i=s=>{t(s);},a=s=>{s&&t(s.id);},l=()=>{t(null);};return jsxs(Container,{fluid:true,children:[jsxs(Grid,{children:[jsxs(Grid.Col,{span:2,children:[jsx(Text,{ml:"xl",my:"sm",weight:"bold",children:"Formatters"}),jsx(ih,{onChange:r,onEditCreation:i,loading:false})]}),jsxs(Grid.Col,{span:10,style:{height:"100vh"},children:[jsx(Space,{h:"xs"}),jsx(yh,{filters:o,onClickEdit:a})]})]}),e&&jsx(gh,{formatterId:e,onEditEnd:l})]})}function wh({onChange:e,loading:t,onEditCreation:o}){let n=ua(),[r,i]=useState(""),[a,l]=useState(""),[s,u]=useState(false),[c]=useDebouncedValue(r,500),[p]=useDebouncedValue(a,500),m={query:"",name:""},[f,g]=useState(m),S=()=>{i(""),l(""),g(m);},v=()=>{l(""),g(C=>({...C,name:""}));},h=()=>{i(""),g(C=>({...C,query:""}));};return useEffect(()=>{let C={...f,name:p,query:c,matchPattern:d=>{if(!c)return true;try{return new RegExp(d.patternSwapped).test(c)}catch{return false}}};e(C);},[c,p]),jsxs("div",{children:[jsx(TextInput,{label:"Filter by name",value:a,onChange:C=>l(C.currentTarget.value),disabled:t,rightSection:a?jsx(IconCircleX,{size:16,style:{cursor:"pointer"},onClick:v}):null}),jsx(Space,{h:"md"}),jsx(TextInput,{label:"Test a url here",value:r,onChange:C=>i(C.currentTarget.value),disabled:t,rightSection:r?jsx(IconCircleX,{size:16,style:{cursor:"pointer"},onClick:h}):null}),jsx(Space,{h:"md"}),jsx(Button,{fullWidth:true,disabled:t,leftIcon:jsx(IconPlus,{}),onClick:()=>{u(true);let C=Math.random().toString(16).substring(2,10);n(ta$1.createEntity("datasource",{name:`datasource_${C}`,description:"New Data Source",content:{pattern:"",logic:`
36
36
  return {
37
37
  axiosConfig: {
38
38
  method: 'get',
@@ -44,6 +44,6 @@ return {
44
44
  method: 'get',
45
45
  url: url,
46
46
  }
47
- };`,testUrl:"",useProxy:true,order:0,access:["public"]}})).then(d=>{u(false),S(),d.ok&&o(d.data.id);});},variant:"light",loading:a,children:"New Data Source"})]})}function Oh({dataSourceId:e,onEditEnd:t}){va$1(P=>P.status.localeDefault);let n=a$1(),r=!!e,[i,s]=useState(),[l,a]=useState(""),[u,c]=useState(""),[p,f]=useState(true),[m,g]=useState(false),[S,v]=useState(true),[h,b]=useState(true),[C]=useState(false),[d,y]=useState(null),[x,k]=useState(null),[R,B]=useState(null),[N,$]=useState({}),K=ua(),T=Ja(e),M=p||m,I$2=X();useEffect(()=>{T.isLoading||(s(T.data),F(),f(false)),K(ta$1.readEnvSecrets()).then(P=>{$(P.secrets);});},[T.isLoading]);let O=P=>{try{return new RegExp(P,"gm"),!0}catch{return false}},G=(P,A)=>{i&&s({...i,[P]:A});},W=(P,A)=>{if(P!=="description"&&v(true),i){if(P==="pattern"){let _=O(A);y(_?null:"Invalid regular expression pattern"),b(_);}P==="order"&&(A=A===""?0:Math.floor(Number(A))),P==="useProxy"&&(A=A==="true"),s({...i,content:{...i.content,[P]:A}});}},F=async()=>{if(i){let P="",A={...I$2};try{let _;if(i.content.pattern.trim())_=I(i.content.pattern,{},{variables:A}),k(_);else throw new Error("Pattern cannot be empty");let Q;if(i.content.testUrl.trim())Q=I(i.content.testUrl,{},{variables:A}),B(Q);else throw new Error("Test URL cannot be empty");if(!O(_))throw new Error("Invalid regular expression pattern");if(!new RegExp(_,"gm").test(Q))throw new Error("Test URL doesn't match the pattern");if(i.content.useProxy)P=`Config will be processed in the server in /api/cms/url/proxy?url=${Q}`;else {let ce={envs:{...I$2},...n&&n.user?{session:n}:{}},ae=j$1({vars:["url","libs","session"],logic:i.content.logic},ce)(Q);P=typeof ae=="object"?JSON.stringify(ae,null,2):String(ae);}c(P);}catch(_){console.error(_),c(`ERROR: ${_.message}`);}}},L=async()=>{let P="";if(i&&u!==""){g(true);try{if(i.content.useProxy)await U(),P=await K(ta$1.urlProxy({url:`${R}`}));else {let A=JSON.parse(u).axiosConfig,_=await Gh(A).catch(Q=>{throw new Error("ERROR fetching "+A.url+": "+Q.message)});if(_.status===200)_.headers["content-type"]==="text/csv"?P=csvParse(_.data):P=_.data;else throw new Error("No valid response for "+A.url)}a(typeof P=="object"?JSON.stringify(P,null,2):String(P)),g(!1),b(!0),v(!1);}catch(A){console.error(A),b(false),g(false),a(`ERROR: ${A.message}`);}}},U=async(P=false)=>{g(true),h&&i&&await K(ta$1.updateEntity("datasource",i)).then(()=>{P&&(g(false),t());});};return jsx(Drawer,{opened:r,onClose:()=>t(),title:`Edit Data Source ID ${e}`,padding:"lg",closeOnClickOutside:false,closeOnEscape:false,position:"right",size:"90%",lockScroll:true,withCloseButton:false,children:jsx(bt,{content:jsxs(Fragment,{children:[jsx(LoadingOverlay,{visible:p,overlayBlur:2,overlayOpacity:.5}),C&&jsx(Alert,{title:"Formatter Form",color:"red",children:"Error, please try again."}),i&&!C&&jsxs(Stack,{justify:"space-between",children:[jsxs(Group,{grow:true,align:"top",children:[jsx(TextInput,{label:"Name",description:"Name of the Data Source",value:i.name,onChange:P=>G("name",P.target.value),style:{flex:2}}),jsx(NumberInput,{label:"Execution Order",description:"Lower numbers match first",min:0,defaultValue:0,value:i.content.order||0,onChange:P=>W("order",P),hideControls:false,style:{flex:1}}),jsx(Textarea,{label:"Description",value:i.description,onChange:P=>G("description",P.target.value)})]}),jsx(Divider,{my:"sm"}),jsxs(Group,{grow:true,align:"top",children:[jsx(Input.Wrapper,{label:"Public ENV VARS",description:"You can use them as templates in pattern, logic and testUrl. (Defined in next.config file.)",children:Object.keys(I$2).map(P=>jsx(j,{label:P,value:I$2[P]},P))}),jsx(Input.Wrapper,{label:"Secret ENV VARS",description:"If this datasource is using proxy you can use non-public secrets in the logic. (Defined as BESPOKE_SECRET_*)",children:i.content.useProxy?Object.keys(N).map(P=>jsx(j,{label:P,value:N[P]},P)):jsx(Text,{m:"xs",size:"sm",align:"center",c:"dimmed",children:"No secrets available if Use Proxy is NO"})})]}),jsxs(Group,{grow:true,align:"top",children:[jsxs(Stack,{children:[jsxs(Stack,{spacing:2,children:[jsx(TextInput,{label:jsxs(Text,{size:"sm",span:true,children:["Regex Pattern ",jsx("a",{href:"https://www.akto.io/tools/javascript-regex-tester",target:"_blank",rel:"noreferrer",children:jsx(IconHelpCircle,{size:"1rem"})})]}),value:i.content.pattern,icon:jsx(IconSlash,{size:"0.8rem"}),rightSection:jsx(Text,{size:"sm",c:"dimmed",span:true,children:"/gm"}),onChange:P=>W("pattern",P.target.value),error:d||i.content.pattern===""&&!h}),x&&jsxs(Text,{size:"xs",children:["Final Regex Pattern: ",`new RegExp(${x}, "gm")`]})]}),jsx(Input.Wrapper,{label:"Use proxy on Client Side",description:"If the datasource has secrets on its logic, set proxy to YES to avoid expose credentials.",children:jsx(SegmentedControl,{fullWidth:true,value:i.content.useProxy?.toString()||"false",onChange:P=>W("useProxy",P),data:[{label:"No",value:"false"},{label:"Yes",value:"true"}]})}),jsx(I$1,{value:i.content.access||["public"],onChange:P=>W("access",P),item:"Data Source"})]}),jsxs(Stack,{spacing:4,children:[jsx(Input.Wrapper,{label:"Client-Side Logic (Variables: url, envs, libs, session)",children:jsx(rn,{monacoOptions:{onChange:P=>W("logic",P),height:"30vh",value:i.content.logic}},"data-source-code-editor")}),jsx(Input.Wrapper,{label:"Server-Side Logic \u2014 SSR/Proxy (Variables: url, envs, libs, session)",description:"Optional. When set, overrides the client-side logic for server-side execution (SSR rendering and proxy requests).",children:jsx(rn,{monacoOptions:{onChange:P=>W("logic_ssr",P),height:"30vh",value:i.content.logic_ssr||""}},"data-source-ssr-code-editor")})]})]}),jsx(Divider,{my:"sm"}),jsxs(Stack,{spacing:2,children:[jsx(TextInput,{label:"Test URL",value:i.content.testUrl,onChange:P=>W("testUrl",P.target.value),error:i.content.testUrl===""&&!h}),R&&jsxs(Text,{size:"xs",children:["Final Test URL: ",R]})]}),jsx(Textarea,{readOnly:true,icon:u.includes("ERROR:")?jsx(IconAlertCircle,{}):jsx(IconCircleCheck,{}),label:"Test Config Results",minRows:7,value:u,error:u.includes("ERROR:")?"There is a problem in the function, pattern or test url. Please check and run again to be able to save it.":false}),jsx(Textarea,{readOnly:true,icon:h?jsx(IconCircleCheck,{}):jsx(IconAlertCircle,{}),label:"Test Response Results",minRows:7,value:l,error:l.includes("ERROR")&&!h?"There is a problem in the request, the server response is not ok. Please check and run again to be able to save it.":false})]})]}),buttons:jsxs(Fragment,{children:[jsx(Button,{variant:"outline",disabled:M,onClick:()=>t(),children:"Cancel"}),jsx(Button,{onClick:F,disabled:!S||M,color:S?"blue":h?"green":"red",leftIcon:jsx(IconPlayerPlay,{}),children:"Run Test Config"}),jsxs(Button,{onClick:L,disabled:!S||u.includes("ERROR:")||u===""||M,color:S?"blue":h?"green":"red",leftIcon:jsx(IconPlayerPlay,{}),loading:M,children:[i?.content.useProxy?"Save & ":"","Run Test Request"]}),jsx(Button,{onClick:()=>U(true),loading:M,disabled:M||!h||S,children:"Save"})]}),size:165})})}function Mh({filters:e,onClickEdit:t}){let[o,n]=useState([]),r=X(),i=Ca(),s=i.isSuccess?i.data.map(c=>{let p={...r};return {...c,patternSwapped:I(c.content.pattern,{},{variables:p})}}):[],l=useMemo(()=>s,[s]),a=()=>{let c=l.filter(p=>{let f=true;if(e.name&&(f=p.name.toLowerCase().indexOf(e.name.toLowerCase())>-1||p.description.indexOf(e.name)>-1),e.query)try{f=new RegExp(p.patternSwapped).test(e.query);}catch{f=false;}return f});n(c);};return useEffect(()=>{a();},[e,l]),jsx(MantineReactTable,{columns:[{header:"ID",accessorKey:"id",minSize:35,size:35,maxSize:35,mantineTableHeadCellProps:{align:"right"},mantineTableBodyCellProps:{align:"right"}},{header:"Name",accessorKey:"name"},{header:"Use Proxy",accessorKey:"content.useProxy",minSize:70,size:70,maxSize:70,Cell:({row:c})=>c.original.content.useProxy?"YES":"NO"},{header:"REGEX Pattern",accessorKey:"content.pattern"},{header:"REGEX Pattern Swapped",accessorKey:"patternSwapped"},{header:"Order",accessorKey:"content.order",minSize:50,size:50,maxSize:50,mantineTableHeadCellProps:{align:"right"},mantineTableBodyCellProps:{align:"right"}},{header:"Actions",accessorKey:"actions",Cell:({row:c})=>jsxs(Group,{position:"center",spacing:"xs",noWrap:true,children:[jsx(ActionIcon,{onClick:()=>t(c.original),children:jsx(IconPencil,{size:20})},"edit"),jsx(Bt,{id:c.original.id,type:"datasource",disabled:c.original.usageCount>0,warning:`Delete Data Source called "${c.original.name}" (id:${c.original.id}) ? It is not used in any block.`})]}),enableSorting:false,minSize:80,size:80,maxSize:80,mantineTableHeadCellProps:{align:"center"},mantineTableBodyCellProps:{align:"center"}}],data:o,enableBottomToolbar:false,enableColumnActions:false,enableColumnResizing:true,enablePagination:false,enableTopToolbar:false,initialState:{density:"xs",sorting:[{id:"content.order",desc:false}]},layoutMode:"grid",mantineTableContainerProps:{sx:{minHeight:150}},mantineTableProps:{striped:true}})}function Lh(){let[e,t]=useState(null),[o,n]=useState(true),r=a=>{n(a);},i=a=>{t(a);},s=a=>{a&&t(a.id);},l=()=>{t(null);};return jsxs(Container,{fluid:true,children:[jsxs(Grid,{children:[jsxs(Grid.Col,{span:2,children:[jsx(Text,{ml:"xl",my:"sm",weight:"bold",children:"Data Sources"}),jsx(wh,{onChange:r,onEditCreation:i,loading:false})]}),jsxs(Grid.Col,{span:10,style:{height:"100vh"},children:[jsx(Space,{h:"xs"}),jsx(Mh,{filters:o,onClickEdit:s})]})]}),e&&jsx(Oh,{dataSourceId:e,onEditEnd:l})]})}function zh(){let{user:e}=a$1();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!"})]})}var At={value:"all",label:"All"},vu=e=>{if(!e)return [];let t=e.map(o=>({value:String(o.id),label:o.name}));return [At,...t]};function Fh({onChange:e,loading:t}){let o=ua(),n=va$1(h=>Object.values(h.records.entities.report).map(b=>({id:b.id,name:b.name,dimensions:b.dimensions.map(C=>{let d=h.records.entities.dimension[C];return {id:d.id,name:d.name,variants:d.variants.map(y=>{let x=h.records.entities.variant[y];return {id:x.id,name:x.name}})}})}))),r=va$1(h=>h.status.localeDefault),[i,s]=useState(""),[l,a]=useState(false),[u]=useDebouncedValue(i,500),c={report:At.value,dimension:At.value,variant:At.value,visible:false,noImage:false,limit:"10",paginationVariants:[]},[p,f]=useState(c),m=useMemo(()=>({report:vu(n),dimension:vu(n.filter(h=>p.report===At.value||p.report===`${h.id}`).reduce((h,b)=>h.concat(b.dimensions),[])),variant:vu(n.filter(h=>p.report===At.value||p.report===`${h.id}`).reduce((h,b)=>(b.dimensions.filter(C=>p.dimension===At.value||p.dimension===`${C.id}`).forEach(C=>{h=h.concat(C.variants);}),h),[])),limit:[10,25,50,100].map(h=>({value:String(h),label:String(h)}))}),[n,p]),g=useCallback((h,b)=>{let C={...p,[h]:b};switch(h){case "report":C.dimension=At.value,C.variant=At.value;break;case "dimension":C.variant=At.value;break;}f(C);},[p]),S=()=>{s(""),f(c);},v=()=>{a(true),o(ta$1.searchRegenerate()).then(()=>{a(false),e(p);});};return useEffect(()=>{let h=[];if(p.variant!==At.value)h=[`${p.variant}`];else if(p.dimension!==At.value)n.forEach(b=>{let C=b.dimensions.find(d=>`${d.id}`===p.dimension);C&&(h=C.variants.map(d=>`${d.id}`));});else if(p.report!==At.value){let b=n.find(C=>`${C.id}`===p.report);b&&b.dimensions.forEach(C=>{h=[...h,...C.variants.map(d=>`${d.id}`)];});}e({...p,paginationVariants:h,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 (${r.toUpperCase()})`,value:i,onChange:h=>s(h.currentTarget.value),disabled:t}),jsx(Select,{label:"Reports",data:m.report,value:p.report,onChange:h=>g("report",h),disabled:t}),jsx(Select,{label:"Dimensions",data:m.dimension,value:p.dimension,onChange:h=>g("dimension",h),disabled:t}),jsx(Select,{label:"Variants",data:m.variant,value:p.variant,onChange:h=>g("variant",h),disabled:t}),jsx(Select,{label:"Rows limit",data:m.limit,value:p.limit,onChange:h=>g("limit",h),disabled:t}),jsx(Space,{h:"md"}),jsx(Checkbox,{label:"Show visible members only",checked:p.visible,onChange:h=>g("visible",h.currentTarget.checked)}),jsx(Space,{h:"md"}),jsx(Checkbox,{label:"Show members with no image",checked:p.noImage,onChange:h=>g("noImage",h.currentTarget.checked)}),jsx(Space,{h:"md"}),jsx(Button,{fullWidth:true,disabled:t,leftIcon:jsx(IconCircleX,{}),onClick:S,children:"Clear filters"}),jsx(Space,{h:"md"}),jsx(Button,{fullWidth:true,disabled:t,leftIcon:jsx(IconRefresh,{}),onClick:v,variant:"light",loading:l,children:"Re-Index Search"})]})}var $O=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 GO({member:e,onEditEnd:t}){let o=e.contentByLocale&&e.contentByLocale[0]?e.contentByLocale[0].name:"",n=useMemo(()=>({upload:{title:"Upload",key:"upload",input:"file",forceSearch:false,pagination:false,getAxiosSearchConfig:()=>({})},local:{title:"Gallery",key:"local",input:"text",forceSearch:true,pagination:false,getAxiosSearchConfig:(T,M,I)=>({url:"/api/cms/images/search/local",method:"get",params:{prompt:T,page:I}})},flickr:{title:"Flickr",key:"flickr",input:"text",forceSearch:true,pagination:true,getAxiosSearchConfig:(T,M,I)=>({url:"/api/cms/images/search/flickr",method:"get",params:{prompt:T,page:I}})},unsplash:{title:"Unsplash",key:"unsplash",input:"text",forceSearch:true,pagination:true,getAxiosSearchConfig:(T,M,I)=>({url:"/api/cms/images/search/unsplash",method:"get",params:{prompt:T,page:I}})},pixabay:{title:"Pixabay",key:"pixabay",input:"text",forceSearch:true,pagination:true,getAxiosSearchConfig:(T,M,I)=>({url:"/api/cms/images/search/pixabay",method:"get",params:{prompt:T,page:I}})}}),[]),r=useMemo(()=>Object.values(n).filter(T=>$O(T.key)).map(T=>({value:T.key,label:T.title})),[]),[i,s]=useState(false),[l,a]=useState(Object.values(n)[0]),[u,c]=useState(500),[p,f]=useState(o),[m,g]=useState(),[S,v]=useState([]),[h,b]=useState(),[C,d]=useState(false),[y,x]=useState(1),k=async(T=void 0)=>{if(T&&T!==y)x(1);else {d(false),s(true);let M=l.getAxiosSearchConfig(p,m,T||y),I=await Gh(M).then(O=>O.data.data&&O.data.data.results?O.data.data.results:[]).catch(O=>{console.error(O),d(true);});v(I),I.length>0&&b(I[0]),s(false);}},R=T=>{b(T);},B=async()=>{s(true);let T=new FormData;T.append("content_id",e.content_id),h&&m&&(T.append("file",m),delete h.file),h&&(T.append("image_id",h.id),T.append("image_source",h.source)),await Gh({method:"post",url:`/api/cms/images/save/${l.key}`,data:T}).then(()=>{t(true);}).catch(M=>{console.error(M),d(true);}),s(false);},N=T=>{d(false),a(n[T]),b(void 0),v([]),x(1);};useEffect(()=>{let{innerHeight:T}=window;c(T-280);},[]),useEffect(()=>{!i&&l.forceSearch&&k();},[y,l]);let $=S&&S.length===0&&!i&&l.key!=="upload",K=S&&S.length===0&&!i&&l.key==="upload";return jsx(Drawer,{opened:true,onClose:t,title:`Image selection for ${o} (${e.id}) `,padding:"lg",closeOnClickOutside:false,closeOnEscape:false,position:"left",size:"50%",lockScroll:true,withCloseButton:false,children:jsx("div",{style:{height:"100%"},children:jsxs(Stack,{spacing:"sm",children:[jsxs(Stack,{spacing:"xs",children:[jsx(SegmentedControl,{disabled:i,value:l.key,onChange:T=>N(T),data:r,fullWidth:true}),jsxs(Group,{position:"apart",grow:true,align:"flex-end",children:[l.input==="text"&&jsx(TextInput,{placeholder:"Search term",label:"Search term",value:p,onChange:T=>f(T.target.value),onKeyDown:getHotkeyHandler([["Enter",()=>k(1)]])}),l.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:m,onChange:T=>{if(b(void 0),T){let I={id:"custom",source:URL.createObjectURL(T),file:T};v([I]),g(T),b(I);}},icon:jsx(IconUpload,{size:14})}),l.forceSearch&&jsx(Button,{fullWidth:true,disabled:i||!p||p==="",onClick:()=>k(1),leftIcon:jsx(IconPlayerPlay,{}),children:"Search"})]})]}),jsx(Group,{mt:"xs",grow:true,children:jsxs(ScrollArea,{offsetScrollbars:true,type:"always",style:{height:u},children:[jsx(LoadingOverlay,{visible:i,overlayBlur:2,overlayOpacity:.5,overlayColor:"#fff"}),C&&jsx(Alert,{title:`${l.title}`,color:"red",children:"Error, please try again."}),$&&jsx(Alert,{title:`${l.title}`,color:"blue",children:"No results, for try another prompt or provider."}),K&&jsx(Alert,{icon:jsx(IconPhoto,{size:"1rem"}),title:"Welcome to image selector!",color:"blue",children:"Upload an image or select a provider."}),S&&S.length>0&&!i&&jsxs(Fragment,{children:[jsx(SimpleGrid,{cols:3,children:S.map(T=>jsx(Image,{alt:`${l.title}-image-${T.id}`,radius:"md",src:T.source,style:{cursor:"pointer",borderRadius:15,border:h&&h.id===T.id?"5px solid black":""},onClick:()=>R(T)},T.id))}),jsx(Space,{h:"md"}),l.pagination&&jsx(Button,{variant:"outline",fullWidth:true,onClick:()=>x(y+1),children:"Load more images"})]})]})}),jsxs(Group,{mt:"xs",grow:true,style:{height:45},children:[jsx(Button,{variant:"outline",disabled:i,onClick:()=>t(false),children:"Cancel"}),jsx(Button,{onClick:B,loading:i,disabled:i||!h,children:"Save"})]})]})})})}var Hh=GO;function Jh({memberId:e,onEditEnd:t$1}){let o=va$1(L=>L.status.localeDefault),n=va$1(L=>L.status.locales),r=n.map(L=>({value:L,label:`${L.toUpperCase()}`})),i=!!e,[s,l]=useState(o),[a,u]=useState(null),[c,p]=useState(true),[f,m]=useState(false),[g,S]=useState(false),[v,h]=useState("member"),[b,C]=useState(false),[d,y]=useState([]),[x,k]=useState({}),R=useForm(),B=n.reduce((L,U)=>(L[U]=useForm({}),L),{}),N=useForm(),$=n.reduce((L,U)=>(L[U]=useForm({}),L),{}),K=ua(),T=async()=>{p(true),S(false);let L=await K(ta$1.readMember({locale:"all",content_ids:[e],all:true,mode:"content_ids",output:"full"})).then(U=>{let P;return U.results&&U.results[0]?(S(false),P=U.results[0]):S(true),P}).catch(U=>{console.error(U),S(true);});L&&(u(L),R.setValues(L),L.contentByLocale.forEach(U=>{B[U.locale].setValues({name:U.name,keywords:U.keywords?U.keywords:[],attributes:U.attributes?Object.keys(U.attributes).map(P=>({key:P,value:U.attributes[P]})):[]});}),L.image&&(N.setValues(L.image),L.image.contentByLocale.forEach(U=>{$[U.locale].setValues({meta:U.meta});}))),p(false);},M=async()=>{if(a&&a.contentByLocale){let L=a.contentByLocale.find(U=>U.locale===s);if(L){C(true);let U=f$1({q:L.name,limit:"10",locale:s,visible:"true",includes:"true",noImage:"false",format:"plain",all:"true"});K(ta$1.searchMember(U)).then(P=>{if(P&&P.results){let A=P.results.filter(_=>_.content_id!==e);y(A);}C(false);}).catch(P=>{console.error(P),C(false);});}}};useEffect(()=>{e?T():u(null);},[e]),useEffect(()=>{a&&M();},[a,s]);let I=async L=>{L&&T(),m(false);},O=()=>{u({...a,image:null,image_id:null});},G=async()=>{p(true);let L={...R.values,contentByLocale:a.contentByLocale.map(A=>{let _=B[A.locale]?{...B[A.locale].values}:{};return _.keywords=_.keywords&&_.keywords.length>0?_.keywords:null,{...A,..._}}),image:a.image?{...N.values,contentByLocale:n.map(A=>{let _=a.image.contentByLocale.find(Y=>Y.locale===A),Q=$[_.locale]?$[_.locale].values:{};return {..._,...Q}})}:null,image_id:a.image_id},U=[Gh.post("/api/cms/update/member",L)],P=Object.keys(x);P.length>0&&P.forEach(A=>{U.push(Gh.post("/api/cms/update/member",{content_id:d[A].content_id,image_id:a.image_id}));}),Promise.all(U).then(()=>{t$1();}).catch(A=>{console.error(A),S(true);});},W=Object.keys(B[s].values).length>0,F={state:{rowSelection:x},onRowSelectionChange:k,enableRowSelection:L=>a.image_id&&L.original.image_id!==a.image_id};return jsxs(Fragment,{children:[jsx(Drawer,{opened:i,onClose:()=>t$1(),title:`Edit member ID ${e}`,padding:"lg",closeOnClickOutside:false,closeOnEscape:false,position:"right",size:"50%",lockScroll:true,withCloseButton:false,children:jsx(bt,{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."}),a&&!g&&jsxs(Tabs,{defaultValue:"member",value:v,onTabChange:h,children:[jsxs(Tabs.List,{grow:true,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:true,children:[jsx(TextInput,{mt:"xs",disabled:true,label:"Original ID",...R.getInputProps("id")}),jsx(TextInput,{mt:"xs",disabled:true,label:"Content ID",...R.getInputProps("content_id")})]}),jsxs(Group,{position:"apart",grow:true,children:[jsx(TextInput,{mt:"xs",icon:"/",disabled:true,label:"Variant Slug",...R.getInputProps("variant_slug")}),jsx(TextInput,{mt:"xs",icon:"/",disabled:true,label:"Member Slug",...R.getInputProps("slug")})]}),jsxs(Group,{position:"apart",grow:true,children:[jsx(TextInput,{mt:"xs",disabled:true,label:"Report",...R.getInputProps("report_name")}),jsx(TextInput,{mt:"xs",disabled:true,label:"Dimension",...R.getInputProps("dimension_name")}),jsx(TextInput,{mt:"xs",disabled:true,label:"Variant",...R.getInputProps("variant_name")})]}),jsxs(Group,{grow:true,children:[jsxs(Box,{onClick:()=>h("image"),style:{cursor:"pointer"},pos:"relative",children:[jsx(Overlay,{opacity:0,center:true,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(Vr,{member:a,forceRefreshTimestamp:true})]}),jsx(Input.Wrapper,{label:"Search relevance",description:`
47
+ };`,testUrl:"",useProxy:true,order:0,access:["public"]}})).then(d=>{u(false),S(),d.ok&&o(d.data.id);});},variant:"light",loading:s,children:"New Data Source"})]})}function Oh({dataSourceId:e,onEditEnd:t}){va$1(P=>P.status.localeDefault);let n=a$1(),r=!!e,[i,a]=useState(),[l,s]=useState(""),[u,c]=useState(""),[p,m]=useState(true),[f,g]=useState(false),[S,v]=useState(true),[h,b]=useState(true),[C]=useState(false),[d,y]=useState(null),[x,k]=useState(null),[R,B]=useState(null),[N,$]=useState({}),K=ua(),T=Ja(e),M=p||f,I$2=X();useEffect(()=>{T.isLoading||(a(T.data),F(),m(false)),K(ta$1.readEnvSecrets()).then(P=>{$(P.secrets);});},[T.isLoading]);let O=P=>{try{return new RegExp(P,"gm"),!0}catch{return false}},G=(P,A)=>{i&&a({...i,[P]:A});},W=(P,A)=>{if(P!=="description"&&v(true),i){if(P==="pattern"){let _=O(A);y(_?null:"Invalid regular expression pattern"),b(_);}P==="order"&&(A=A===""?0:Math.floor(Number(A))),P==="useProxy"&&(A=A==="true"),a({...i,content:{...i.content,[P]:A}});}},F=async()=>{if(i){let P="",A={...I$2};try{let _;if(i.content.pattern.trim())_=I(i.content.pattern,{},{variables:A}),k(_);else throw new Error("Pattern cannot be empty");let Q;if(i.content.testUrl.trim())Q=I(i.content.testUrl,{},{variables:A}),B(Q);else throw new Error("Test URL cannot be empty");if(!O(_))throw new Error("Invalid regular expression pattern");if(!new RegExp(_,"gm").test(Q))throw new Error("Test URL doesn't match the pattern");if(i.content.useProxy)P=`Config will be processed in the server in /api/cms/url/proxy?url=${Q}`;else {let ce={envs:{...I$2},...n&&n.user?{session:n}:{}},ae=j$1({vars:["url","libs","session"],logic:i.content.logic},ce)(Q);P=typeof ae=="object"?JSON.stringify(ae,null,2):String(ae);}c(P);}catch(_){console.error(_),c(`ERROR: ${_.message}`);}}},L=async()=>{let P="";if(i&&u!==""){g(true);try{if(i.content.useProxy)await U(),P=await K(ta$1.urlProxy({url:`${R}`}));else {let A=JSON.parse(u).axiosConfig,_=await Gh(A).catch(Q=>{throw new Error("ERROR fetching "+A.url+": "+Q.message)});if(_.status===200)_.headers["content-type"]==="text/csv"?P=csvParse(_.data):P=_.data;else throw new Error("No valid response for "+A.url)}s(typeof P=="object"?JSON.stringify(P,null,2):String(P)),g(!1),b(!0),v(!1);}catch(A){console.error(A),b(false),g(false),s(`ERROR: ${A.message}`);}}},U=async(P=false)=>{g(true),h&&i&&await K(ta$1.updateEntity("datasource",i)).then(()=>{P&&(g(false),t());});};return jsx(Drawer,{opened:r,onClose:()=>t(),title:`Edit Data Source ID ${e}`,padding:"lg",closeOnClickOutside:false,closeOnEscape:false,position:"right",size:"90%",lockScroll:true,withCloseButton:false,children:jsx(yt,{content:jsxs(Fragment,{children:[jsx(LoadingOverlay,{visible:p,overlayBlur:2,overlayOpacity:.5}),C&&jsx(Alert,{title:"Formatter Form",color:"red",children:"Error, please try again."}),i&&!C&&jsxs(Stack,{justify:"space-between",children:[jsxs(Group,{grow:true,align:"top",children:[jsx(TextInput,{label:"Name",description:"Name of the Data Source",value:i.name,onChange:P=>G("name",P.target.value),style:{flex:2}}),jsx(NumberInput,{label:"Execution Order",description:"Lower numbers match first",min:0,defaultValue:0,value:i.content.order||0,onChange:P=>W("order",P),hideControls:false,style:{flex:1}}),jsx(Textarea,{label:"Description",value:i.description,onChange:P=>G("description",P.target.value)})]}),jsx(Divider,{my:"sm"}),jsxs(Group,{grow:true,align:"top",children:[jsx(Input.Wrapper,{label:"Public ENV VARS",description:"You can use them as templates in pattern, logic and testUrl. (Defined in next.config file.)",children:Object.keys(I$2).map(P=>jsx(j,{label:P,value:I$2[P]},P))}),jsx(Input.Wrapper,{label:"Secret ENV VARS",description:"If this datasource is using proxy you can use non-public secrets in the logic. (Defined as BESPOKE_SECRET_*)",children:i.content.useProxy?Object.keys(N).map(P=>jsx(j,{label:P,value:N[P]},P)):jsx(Text,{m:"xs",size:"sm",align:"center",c:"dimmed",children:"No secrets available if Use Proxy is NO"})})]}),jsxs(Group,{grow:true,align:"top",children:[jsxs(Stack,{children:[jsxs(Stack,{spacing:2,children:[jsx(TextInput,{label:jsxs(Text,{size:"sm",span:true,children:["Regex Pattern ",jsx("a",{href:"https://www.akto.io/tools/javascript-regex-tester",target:"_blank",rel:"noreferrer",children:jsx(IconHelpCircle,{size:"1rem"})})]}),value:i.content.pattern,icon:jsx(IconSlash,{size:"0.8rem"}),rightSection:jsx(Text,{size:"sm",c:"dimmed",span:true,children:"/gm"}),onChange:P=>W("pattern",P.target.value),error:d||i.content.pattern===""&&!h}),x&&jsxs(Text,{size:"xs",children:["Final Regex Pattern: ",`new RegExp(${x}, "gm")`]})]}),jsx(Input.Wrapper,{label:"Use proxy on Client Side",description:"If the datasource has secrets on its logic, set proxy to YES to avoid expose credentials.",children:jsx(SegmentedControl,{fullWidth:true,value:i.content.useProxy?.toString()||"false",onChange:P=>W("useProxy",P),data:[{label:"No",value:"false"},{label:"Yes",value:"true"}]})}),jsx(I$1,{value:i.content.access||["public"],onChange:P=>W("access",P),item:"Data Source"})]}),jsxs(Stack,{spacing:4,children:[jsx(Input.Wrapper,{label:"Client-Side Logic (Variables: url, envs, libs, session)",children:jsx(rn,{monacoOptions:{onChange:P=>W("logic",P),height:"30vh",value:i.content.logic}},"data-source-code-editor")}),jsx(Input.Wrapper,{label:"Server-Side Logic \u2014 SSR/Proxy (Variables: url, envs, libs, session)",description:"Optional. When set, overrides the client-side logic for server-side execution (SSR rendering and proxy requests).",children:jsx(rn,{monacoOptions:{onChange:P=>W("logic_ssr",P),height:"30vh",value:i.content.logic_ssr||""}},"data-source-ssr-code-editor")})]})]}),jsx(Divider,{my:"sm"}),jsxs(Stack,{spacing:2,children:[jsx(TextInput,{label:"Test URL",value:i.content.testUrl,onChange:P=>W("testUrl",P.target.value),error:i.content.testUrl===""&&!h}),R&&jsxs(Text,{size:"xs",children:["Final Test URL: ",R]})]}),jsx(Textarea,{readOnly:true,icon:u.includes("ERROR:")?jsx(IconAlertCircle,{}):jsx(IconCircleCheck,{}),label:"Test Config Results",minRows:7,value:u,error:u.includes("ERROR:")?"There is a problem in the function, pattern or test url. Please check and run again to be able to save it.":false}),jsx(Textarea,{readOnly:true,icon:h?jsx(IconCircleCheck,{}):jsx(IconAlertCircle,{}),label:"Test Response Results",minRows:7,value:l,error:l.includes("ERROR")&&!h?"There is a problem in the request, the server response is not ok. Please check and run again to be able to save it.":false})]})]}),buttons:jsxs(Fragment,{children:[jsx(Button,{variant:"outline",disabled:M,onClick:()=>t(),children:"Cancel"}),jsx(Button,{onClick:F,disabled:!S||M,color:S?"blue":h?"green":"red",leftIcon:jsx(IconPlayerPlay,{}),children:"Run Test Config"}),jsxs(Button,{onClick:L,disabled:!S||u.includes("ERROR:")||u===""||M,color:S?"blue":h?"green":"red",leftIcon:jsx(IconPlayerPlay,{}),loading:M,children:[i?.content.useProxy?"Save & ":"","Run Test Request"]}),jsx(Button,{onClick:()=>U(true),loading:M,disabled:M||!h||S,children:"Save"})]}),size:165})})}function Mh({filters:e,onClickEdit:t}){let[o,n]=useState([]),r=X(),i=Ca(),a=i.isSuccess?i.data.map(c=>{let p={...r};return {...c,patternSwapped:I(c.content.pattern,{},{variables:p})}}):[],l=useMemo(()=>a,[a]),s=()=>{let c=l.filter(p=>{let m=true;if(e.name&&(m=p.name.toLowerCase().indexOf(e.name.toLowerCase())>-1||p.description.indexOf(e.name)>-1),e.query)try{m=new RegExp(p.patternSwapped).test(e.query);}catch{m=false;}return m});n(c);};return useEffect(()=>{s();},[e,l]),jsx(MantineReactTable,{columns:[{header:"ID",accessorKey:"id",minSize:35,size:35,maxSize:35,mantineTableHeadCellProps:{align:"right"},mantineTableBodyCellProps:{align:"right"}},{header:"Name",accessorKey:"name"},{header:"Use Proxy",accessorKey:"content.useProxy",minSize:70,size:70,maxSize:70,Cell:({row:c})=>c.original.content.useProxy?"YES":"NO"},{header:"REGEX Pattern",accessorKey:"content.pattern"},{header:"REGEX Pattern Swapped",accessorKey:"patternSwapped"},{header:"Order",accessorKey:"content.order",minSize:50,size:50,maxSize:50,mantineTableHeadCellProps:{align:"right"},mantineTableBodyCellProps:{align:"right"}},{header:"Actions",accessorKey:"actions",Cell:({row:c})=>jsxs(Group,{position:"center",spacing:"xs",noWrap:true,children:[jsx(ActionIcon,{onClick:()=>t(c.original),children:jsx(IconPencil,{size:20})},"edit"),jsx(Bt,{id:c.original.id,type:"datasource",disabled:c.original.usageCount>0,warning:`Delete Data Source called "${c.original.name}" (id:${c.original.id}) ? It is not used in any block.`})]}),enableSorting:false,minSize:80,size:80,maxSize:80,mantineTableHeadCellProps:{align:"center"},mantineTableBodyCellProps:{align:"center"}}],data:o,enableBottomToolbar:false,enableColumnActions:false,enableColumnResizing:true,enablePagination:false,enableTopToolbar:false,initialState:{density:"xs",sorting:[{id:"content.order",desc:false}]},layoutMode:"grid",mantineTableContainerProps:{sx:{minHeight:150}},mantineTableProps:{striped:true}})}function Lh(){let[e,t]=useState(null),[o,n]=useState(true),r=s=>{n(s);},i=s=>{t(s);},a=s=>{s&&t(s.id);},l=()=>{t(null);};return jsxs(Container,{fluid:true,children:[jsxs(Grid,{children:[jsxs(Grid.Col,{span:2,children:[jsx(Text,{ml:"xl",my:"sm",weight:"bold",children:"Data Sources"}),jsx(wh,{onChange:r,onEditCreation:i,loading:false})]}),jsxs(Grid.Col,{span:10,style:{height:"100vh"},children:[jsx(Space,{h:"xs"}),jsx(Mh,{filters:o,onClickEdit:a})]})]}),e&&jsx(Oh,{dataSourceId:e,onEditEnd:l})]})}function zh(){let{user:e}=a$1();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!"})]})}var At={value:"all",label:"All"},Su=e=>{if(!e)return [];let t=e.map(o=>({value:String(o.id),label:o.name}));return [At,...t]};function Fh({onChange:e,loading:t}){let o=ua(),n=va$1(h=>Object.values(h.records.entities.report).map(b=>({id:b.id,name:b.name,dimensions:b.dimensions.map(C=>{let d=h.records.entities.dimension[C];return {id:d.id,name:d.name,variants:d.variants.map(y=>{let x=h.records.entities.variant[y];return {id:x.id,name:x.name}})}})}))),r=va$1(h=>h.status.localeDefault),[i,a]=useState(""),[l,s]=useState(false),[u]=useDebouncedValue(i,500),c={report:At.value,dimension:At.value,variant:At.value,visible:false,noImage:false,limit:"10",paginationVariants:[]},[p,m]=useState(c),f=useMemo(()=>({report:Su(n),dimension:Su(n.filter(h=>p.report===At.value||p.report===`${h.id}`).reduce((h,b)=>h.concat(b.dimensions),[])),variant:Su(n.filter(h=>p.report===At.value||p.report===`${h.id}`).reduce((h,b)=>(b.dimensions.filter(C=>p.dimension===At.value||p.dimension===`${C.id}`).forEach(C=>{h=h.concat(C.variants);}),h),[])),limit:[10,25,50,100].map(h=>({value:String(h),label:String(h)}))}),[n,p]),g=useCallback((h,b)=>{let C={...p,[h]:b};switch(h){case "report":C.dimension=At.value,C.variant=At.value;break;case "dimension":C.variant=At.value;break;}m(C);},[p]),S=()=>{a(""),m(c);},v=()=>{s(true),o(ta$1.searchRegenerate()).then(()=>{s(false),e(p);});};return useEffect(()=>{let h=[];if(p.variant!==At.value)h=[`${p.variant}`];else if(p.dimension!==At.value)n.forEach(b=>{let C=b.dimensions.find(d=>`${d.id}`===p.dimension);C&&(h=C.variants.map(d=>`${d.id}`));});else if(p.report!==At.value){let b=n.find(C=>`${C.id}`===p.report);b&&b.dimensions.forEach(C=>{h=[...h,...C.variants.map(d=>`${d.id}`)];});}e({...p,paginationVariants:h,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 (${r.toUpperCase()})`,value:i,onChange:h=>a(h.currentTarget.value),disabled:t}),jsx(Select,{label:"Reports",data:f.report,value:p.report,onChange:h=>g("report",h),disabled:t}),jsx(Select,{label:"Dimensions",data:f.dimension,value:p.dimension,onChange:h=>g("dimension",h),disabled:t}),jsx(Select,{label:"Variants",data:f.variant,value:p.variant,onChange:h=>g("variant",h),disabled:t}),jsx(Select,{label:"Rows limit",data:f.limit,value:p.limit,onChange:h=>g("limit",h),disabled:t}),jsx(Space,{h:"md"}),jsx(Checkbox,{label:"Show visible members only",checked:p.visible,onChange:h=>g("visible",h.currentTarget.checked)}),jsx(Space,{h:"md"}),jsx(Checkbox,{label:"Show members with no image",checked:p.noImage,onChange:h=>g("noImage",h.currentTarget.checked)}),jsx(Space,{h:"md"}),jsx(Button,{fullWidth:true,disabled:t,leftIcon:jsx(IconCircleX,{}),onClick:S,children:"Clear filters"}),jsx(Space,{h:"md"}),jsx(Button,{fullWidth:true,disabled:t,leftIcon:jsx(IconRefresh,{}),onClick:v,variant:"light",loading:l,children:"Re-Index Search"})]})}var GO=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 UO({member:e,onEditEnd:t}){let o=e.contentByLocale&&e.contentByLocale[0]?e.contentByLocale[0].name:"",n=useMemo(()=>({upload:{title:"Upload",key:"upload",input:"file",forceSearch:false,pagination:false,getAxiosSearchConfig:()=>({})},local:{title:"Gallery",key:"local",input:"text",forceSearch:true,pagination:false,getAxiosSearchConfig:(T,M,I)=>({url:"/api/cms/images/search/local",method:"get",params:{prompt:T,page:I}})},flickr:{title:"Flickr",key:"flickr",input:"text",forceSearch:true,pagination:true,getAxiosSearchConfig:(T,M,I)=>({url:"/api/cms/images/search/flickr",method:"get",params:{prompt:T,page:I}})},unsplash:{title:"Unsplash",key:"unsplash",input:"text",forceSearch:true,pagination:true,getAxiosSearchConfig:(T,M,I)=>({url:"/api/cms/images/search/unsplash",method:"get",params:{prompt:T,page:I}})},pixabay:{title:"Pixabay",key:"pixabay",input:"text",forceSearch:true,pagination:true,getAxiosSearchConfig:(T,M,I)=>({url:"/api/cms/images/search/pixabay",method:"get",params:{prompt:T,page:I}})}}),[]),r=useMemo(()=>Object.values(n).filter(T=>GO(T.key)).map(T=>({value:T.key,label:T.title})),[]),[i,a]=useState(false),[l,s]=useState(Object.values(n)[0]),[u,c]=useState(500),[p,m]=useState(o),[f,g]=useState(),[S,v]=useState([]),[h,b]=useState(),[C,d]=useState(false),[y,x]=useState(1),k=async(T=void 0)=>{if(T&&T!==y)x(1);else {d(false),a(true);let M=l.getAxiosSearchConfig(p,f,T||y),I=await Gh(M).then(O=>O.data.data&&O.data.data.results?O.data.data.results:[]).catch(O=>{console.error(O),d(true);});v(I),I.length>0&&b(I[0]),a(false);}},R=T=>{b(T);},B=async()=>{a(true);let T=new FormData;T.append("content_id",e.content_id),h&&f&&(T.append("file",f),delete h.file),h&&(T.append("image_id",h.id),T.append("image_source",h.source)),await Gh({method:"post",url:`/api/cms/images/save/${l.key}`,data:T}).then(()=>{t(true);}).catch(M=>{console.error(M),d(true);}),a(false);},N=T=>{d(false),s(n[T]),b(void 0),v([]),x(1);};useEffect(()=>{let{innerHeight:T}=window;c(T-280);},[]),useEffect(()=>{!i&&l.forceSearch&&k();},[y,l]);let $=S&&S.length===0&&!i&&l.key!=="upload",K=S&&S.length===0&&!i&&l.key==="upload";return jsx(Drawer,{opened:true,onClose:t,title:`Image selection for ${o} (${e.id}) `,padding:"lg",closeOnClickOutside:false,closeOnEscape:false,position:"left",size:"50%",lockScroll:true,withCloseButton:false,children:jsx("div",{style:{height:"100%"},children:jsxs(Stack,{spacing:"sm",children:[jsxs(Stack,{spacing:"xs",children:[jsx(SegmentedControl,{disabled:i,value:l.key,onChange:T=>N(T),data:r,fullWidth:true}),jsxs(Group,{position:"apart",grow:true,align:"flex-end",children:[l.input==="text"&&jsx(TextInput,{placeholder:"Search term",label:"Search term",value:p,onChange:T=>m(T.target.value),onKeyDown:getHotkeyHandler([["Enter",()=>k(1)]])}),l.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:T=>{if(b(void 0),T){let I={id:"custom",source:URL.createObjectURL(T),file:T};v([I]),g(T),b(I);}},icon:jsx(IconUpload,{size:14})}),l.forceSearch&&jsx(Button,{fullWidth:true,disabled:i||!p||p==="",onClick:()=>k(1),leftIcon:jsx(IconPlayerPlay,{}),children:"Search"})]})]}),jsx(Group,{mt:"xs",grow:true,children:jsxs(ScrollArea,{offsetScrollbars:true,type:"always",style:{height:u},children:[jsx(LoadingOverlay,{visible:i,overlayBlur:2,overlayOpacity:.5,overlayColor:"#fff"}),C&&jsx(Alert,{title:`${l.title}`,color:"red",children:"Error, please try again."}),$&&jsx(Alert,{title:`${l.title}`,color:"blue",children:"No results, for try another prompt or provider."}),K&&jsx(Alert,{icon:jsx(IconPhoto,{size:"1rem"}),title:"Welcome to image selector!",color:"blue",children:"Upload an image or select a provider."}),S&&S.length>0&&!i&&jsxs(Fragment,{children:[jsx(SimpleGrid,{cols:3,children:S.map(T=>jsx(Image,{alt:`${l.title}-image-${T.id}`,radius:"md",src:T.source,style:{cursor:"pointer",borderRadius:15,border:h&&h.id===T.id?"5px solid black":""},onClick:()=>R(T)},T.id))}),jsx(Space,{h:"md"}),l.pagination&&jsx(Button,{variant:"outline",fullWidth:true,onClick:()=>x(y+1),children:"Load more images"})]})]})}),jsxs(Group,{mt:"xs",grow:true,style:{height:45},children:[jsx(Button,{variant:"outline",disabled:i,onClick:()=>t(false),children:"Cancel"}),jsx(Button,{onClick:B,loading:i,disabled:i||!h,children:"Save"})]})]})})})}var Hh=UO;function Jh({memberId:e,onEditEnd:t$1}){let o=va$1(L=>L.status.localeDefault),n=va$1(L=>L.status.locales),r=n.map(L=>({value:L,label:`${L.toUpperCase()}`})),i=!!e,[a,l]=useState(o),[s,u]=useState(null),[c,p]=useState(true),[m,f]=useState(false),[g,S]=useState(false),[v,h]=useState("member"),[b,C]=useState(false),[d,y]=useState([]),[x,k]=useState({}),R=useForm(),B=n.reduce((L,U)=>(L[U]=useForm({}),L),{}),N=useForm(),$=n.reduce((L,U)=>(L[U]=useForm({}),L),{}),K=ua(),T=async()=>{p(true),S(false);let L=await K(ta$1.readMember({locale:"all",content_ids:[e],all:true,mode:"content_ids",output:"full"})).then(U=>{let P;return U.results&&U.results[0]?(S(false),P=U.results[0]):S(true),P}).catch(U=>{console.error(U),S(true);});L&&(u(L),R.setValues(L),L.contentByLocale.forEach(U=>{B[U.locale].setValues({name:U.name,keywords:U.keywords?U.keywords:[],attributes:U.attributes?Object.keys(U.attributes).map(P=>({key:P,value:U.attributes[P]})):[]});}),L.image&&(N.setValues(L.image),L.image.contentByLocale.forEach(U=>{$[U.locale].setValues({meta:U.meta});}))),p(false);},M=async()=>{if(s&&s.contentByLocale){let L=s.contentByLocale.find(U=>U.locale===a);if(L){C(true);let U=f$1({q:L.name,limit:"10",locale:a,visible:"true",includes:"true",noImage:"false",format:"plain",all:"true"});K(ta$1.searchMember(U)).then(P=>{if(P&&P.results){let A=P.results.filter(_=>_.content_id!==e);y(A);}C(false);}).catch(P=>{console.error(P),C(false);});}}};useEffect(()=>{e?T():u(null);},[e]),useEffect(()=>{s&&M();},[s,a]);let I=async L=>{L&&T(),f(false);},O=()=>{u({...s,image:null,image_id:null});},G=async()=>{p(true);let L={...R.values,contentByLocale:s.contentByLocale.map(A=>{let _=B[A.locale]?{...B[A.locale].values}:{};return _.keywords=_.keywords&&_.keywords.length>0?_.keywords:null,{...A,..._}}),image:s.image?{...N.values,contentByLocale:n.map(A=>{let _=s.image.contentByLocale.find(Y=>Y.locale===A),Q=$[_.locale]?$[_.locale].values:{};return {..._,...Q}})}:null,image_id:s.image_id},U=[Gh.post("/api/cms/update/member",L)],P=Object.keys(x);P.length>0&&P.forEach(A=>{U.push(Gh.post("/api/cms/update/member",{content_id:d[A].content_id,image_id:s.image_id}));}),Promise.all(U).then(()=>{t$1();}).catch(A=>{console.error(A),S(true);});},W=Object.keys(B[a].values).length>0,F={state:{rowSelection:x},onRowSelectionChange:k,enableRowSelection:L=>s.image_id&&L.original.image_id!==s.image_id};return jsxs(Fragment,{children:[jsx(Drawer,{opened:i,onClose:()=>t$1(),title:`Edit member ID ${e}`,padding:"lg",closeOnClickOutside:false,closeOnEscape:false,position:"right",size:"50%",lockScroll:true,withCloseButton:false,children:jsx(yt,{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."}),s&&!g&&jsxs(Tabs,{defaultValue:"member",value:v,onTabChange:h,children:[jsxs(Tabs.List,{grow:true,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:true,children:[jsx(TextInput,{mt:"xs",disabled:true,label:"Original ID",...R.getInputProps("id")}),jsx(TextInput,{mt:"xs",disabled:true,label:"Content ID",...R.getInputProps("content_id")})]}),jsxs(Group,{position:"apart",grow:true,children:[jsx(TextInput,{mt:"xs",icon:"/",disabled:true,label:"Variant Slug",...R.getInputProps("variant_slug")}),jsx(TextInput,{mt:"xs",icon:"/",disabled:true,label:"Member Slug",...R.getInputProps("slug")})]}),jsxs(Group,{position:"apart",grow:true,children:[jsx(TextInput,{mt:"xs",disabled:true,label:"Report",...R.getInputProps("report_name")}),jsx(TextInput,{mt:"xs",disabled:true,label:"Dimension",...R.getInputProps("dimension_name")}),jsx(TextInput,{mt:"xs",disabled:true,label:"Variant",...R.getInputProps("variant_name")})]}),jsxs(Group,{grow:true,children:[jsxs(Box,{onClick:()=>h("image"),style:{cursor:"pointer"},pos:"relative",children:[jsx(Overlay,{opacity:0,center:true,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(Vr,{member:s,forceRefreshTimestamp:true})]}),jsx(Input.Wrapper,{label:"Search relevance",description:`
48
48
  Relevance index to be used with search. Values from 0 (less relevant) to 1 (more relevant)
49
- `,children:jsx(NumberInput,{disabled:!R.values.visible,type:"number",precision:4,step:1e-4,removeTrailingZeros:true,min:0,max:1,decimalSeparator:".",...R.getInputProps("zvalue")})}),jsx(Checkbox,{mt:"2.3rem",label:"Visible in search",...R.getInputProps("visible",{type:"checkbox"})})]}),jsx(Group,{mt:"xs",position:"apart",grow:true,children:jsx(SegmentedControl,{value:s,onChange:l,data:r})}),!W&&jsx(Alert,{title:"Unavailable locale",color:"blue",children:"This language was not ingested for the current member. Go to variant editor and provide the members there."}),W&&jsxs(Fragment,{children:[jsx(Group,{mt:"xs",position:"apart",grow:true,children:jsx(TextInput,{label:"Name",...B[s].getInputProps("name")})}),jsx(Group,{mt:"xs",position:"apart",align:"top",grow:true,children:jsx(MultiSelect,{label:"Keywords",data:B[s].values.keywords,placeholder:"Enter keywords",searchable:true,creatable:true,valueComponent:({label:L})=>jsxs(Badge,{onClick:()=>{let U=B[s].values.keywords;B[s].setFieldValue("keywords",U.filter(P=>P!==L));},children:[L," ","x"]}),getCreateLabel:L=>`+ Create ${L}`,value:B[s].values.keywords,onCreate:L=>{let U=B[s].values.keywords;return B[s].setFieldValue("keywords",[...U,L]),L}})}),jsx(Input.Wrapper,{label:"Attributes",children:jsx(t,{data:B[s].values.attributes})})]})]})}),jsx(Tabs.Panel,{value:"image",py:"md",children:jsxs(Stack,{justify:"space-between",children:[jsxs(Group,{position:"apart",grow:true,children:[jsxs(Stack,{children:[jsx(Vr,{member:a,forceRefreshTimestamp:true}),jsx(Button,{variant:"outline",disabled:c,leftIcon:jsx(IconPolaroid,{}),onClick:()=>m(true),children:"Change image"}),a&&a.image&&jsx(Button,{variant:"outline",disabled:c,leftIcon:jsx(IconCircleMinus,{}),onClick:()=>O(),children:"Remove image"}),jsx(Space,{h:"md"})]}),jsxs(Stack,{justify:"flex-start",children:[jsx(TextInput,{disabled:!a||!a.image,label:"Source",...N.getInputProps("url")}),jsx(TextInput,{disabled:!a||!a.image,label:"Author",...N.getInputProps("author")}),jsx(TextInput,{disabled:!a||!a.image,label:"License",...N.getInputProps("license")}),jsx(SegmentedControl,{disabled:!a||!a.image,value:s,onChange:l,data:r}),jsx(TextInput,{disabled:!a||!a.image,label:"Alternative image text",...$[s].getInputProps("meta")})]})]}),b&&jsx(Loader,{}),!b&&d.length>0&&jsxs(Fragment,{children:[jsx(Text,{children:"Select the members you want to update with the same image."}),jsx(Vn,{members:d,colsToRender:["id","report","name","slug","image"],dataTableProps:F})]})]})})]})]}),buttons:jsxs(Fragment,{children:[jsx(Button,{variant:"outline",disabled:c,onClick:()=>t$1(),children:"Cancel"}),jsx(Button,{onClick:G,loading:c,disabled:c,children:"Save Member"})]}),size:165})}),f&&jsx(Hh,{member:a,onEditEnd:I})]})}function Qh(){let[e,t]=useState(null),[o,n]=useState([]),[r,i]=useState(true),[s,l]=useState(true),[a,u]=useState(),[c,p]=useState(1),[f,m]=useState(0),g=C=>{l(C),p(1);},S=C=>{C&&C.length&&u(C[0]);},v=C=>{t(C.content_id);},h=()=>{t(null),b();},b=async()=>{i(true);let C=Object.keys({...s}).reduce((y,x)=>(s[x]!=="all"&&(y[x]=s[x]),y),{}),d=await Gh.get("/api/cms/search/members",{params:{...C,offset:(c-1)*parseInt(C.limit||"10",10),locale:"all",includes:true,sort:a?a.id:"zvalue",direction:a?a.desc?"desc":"asc":"desc",origin:"flexsearch"}}).then(y=>{let x=y.data&&y.data.data&&y.data.data.meta?Object.keys(y.data.data.meta.variantCount).reduce((k,R)=>{let B=y.data.data.meta.variantCount[R];return s.paginationVariants&&s.paginationVariants.length>0&&(s.paginationVariants.includes(R)||(B=0)),k+B},0):0;return m(x),y.data&&y.data.data&&y.data.data.results?y.data.data.results:[]});n(d),i(false);};return useEffect(()=>{s.limit&&b();},[s,a,c]),jsxs(Container,{fluid:true,children:[jsxs(Grid,{children:[jsxs(Grid.Col,{span:2,children:[jsx(Text,{ml:"xl",my:"sm",weight:"bold",children:"Metadata"}),jsx(Fh,{onChange:g,loading:r})]}),jsxs(Grid.Col,{span:10,style:{height:"95vh",position:"relative"},children:[jsx(LoadingOverlay,{visible:r,overlayBlur:2,overlayOpacity:.5}),jsx(Space,{h:"xs"}),jsx(Vn,{members:o,onClickEdit:v,onSort:S}),jsx(Group,{position:"center",children:jsx(Pagination,{value:c,onChange:p,total:Math.ceil(f/(s.limit||10)),size:"sm",py:"xs"})})]})]}),e&&jsx(Jh,{memberId:e,onEditEnd:h})]})}function tb(){let{user:e}=a$1(),t={color:"#000"};return jsxs(Flex,{mih:"100vh",gap:"md",justify:"center",align:"center",direction:"column",wrap:"wrap",style:{background:"white"},children:[jsx(Title,{style:t,children:"Not found."}),jsxs(Title,{order:2,style:t,children:["Sorry, ",e?.name,"!"]}),jsx(Text,{style:t,children:"The page you are looking for is not here."}),jsx(Button,{component:"a",href:"/",children:"Back to homepage"})]})}function Tu(e){let{for:t,enabled:o}=e,n=useMantineTheme(),r=a$2(),i=n.colorScheme==="dark"?n.colors.dark[1]:n.colors.gray[7];return jsxs(Card,{shadow:"xs",p:"sm",w:"100%",children:[jsxs(Group,{position:"apart",children:[jsxs(Center,{mah:24,children:[jsx(IconFileAnalytics,{size:22}),jsx(Text,{mx:"xs",weight:"bold",children:t.name}),t.type==="report"&&t.settings?.hide&&jsx(Tooltip,{label:"Hidden in explore/search",position:"top",children:jsx(IconEyeOff,{size:16,style:{marginLeft:4,color:i}})})]}),jsx(Badge,{variant:"light",children:t.type})]}),jsxs(Text,{size:"sm",style:{color:i,lineHeight:2},children:["Order in explore/search: ",(t.type==="report"?t.settings?.order:void 0)??0]}),jsx(Space,{w:"xs"}),jsxs(Group,{position:"apart",children:[jsx(Vb,{href:r.href("reports",t.id),passHref:true,children:jsx(Button,{leftIcon:jsx(IconPencil,{}),compact:true,children:"Edit"})}),jsx(Bt,{type:"report",id:t.id,disabled:!o})]})]})}cb(Tu,Da$1);var rb=e=>(e&&e.bespoke_app_metadata&&e.bespoke_app_metadata.reports&&Array.isArray(e.bespoke_app_metadata.reports)?e.bespoke_app_metadata.reports:[]).map(o=>o.reportId);function lb(){let e=ua(),[t,o]=useState(false),{user:n}=a$1(),r=rb(n),i=wa$1(),s=useCallback(a=>{o(true),e(ta$1.createEntity("report",a)).then(u=>{u.ok&&r.length>0||o(false);});},[]),l=useMemo(()=>i.isUninitialized||i.isFetching?jsx(LoadingOverlay,{visible:true,overlayBlur:2}):i.isError?jsx(Alert,{icon:jsx(IconFileAnalytics,{size:22}),title:"Server Error",children:i.error.message}):i.data.length===0?jsx(Alert,{icon:jsx(IconFileAnalytics,{size:22}),title:"No Saved Reports",children:"Please use the button below to create your first report."}):jsx(Stack,{children:i.data.sort((a,u)=>{let c=(a.type==="report"?a.settings?.order:void 0)??0,p=(u.type==="report"?u.settings?.order:void 0)??0;return c-p}).map(a=>jsx(Tu,{for:a,enabled:!!(r.length===0||r.includes(a.id))},a.id))}),[i.data,i.error,i.status,r]);return jsxs(Container,{size:"xl",children:[jsx("h1",{children:"Reports"}),jsx(LoadingOverlay,{visible:t,overlayBlur:2,overlayOpacity:.5}),l,jsx(Space,{h:"xl",w:"xl"}),jsx(zn,{fields:[{type:"text",name:"name",label:"Report Name",initialValue:""}],onSubmit:s,target:jsx(ActionIcon,{size:"xl",radius:"xl",children:jsx(IconPlus,{size:30})})})]})}function pb(){let{user:e}=a$1(),t={color:"#000"};return jsxs(Flex,{mih:"100vh",gap:"md",justify:"center",align:"center",direction:"column",wrap:"wrap",style:{background:"white"},children:[jsx(Title,{style:t,children:"Unauthorize or forbidden access."}),jsxs(Title,{style:t,order:2,children:["Sorry, ",e?.name,"!"]}),jsx(Text,{style:t,children:"Your session or your user's roles doesn't satisfy the needs of the requested view. Please, ask your administrator to allow you."}),jsxs(Group,{children:[jsx(Button,{component:"a",href:"/",leftIcon:jsx(IconHome,{size:14}),variant:"outline",color:"dark",children:"Back to homepage"}),jsx(Button,{onClick:()=>signOut({callbackUrl:process.env.NEXT_PUBLIC_REPORTS_BASE_URL||"/"}),leftIcon:jsx(IconLogout,{size:14}),variant:"outline",color:"dark",children:"Disconnect"})]})]})}var db={value:"all",label:"All"},JM=e=>{if(!e)return [];let t=e.map(o=>({value:String(o.id),label:`${o.name} (${o.type})`}));return [db,...t]};function fb({onChange:e,loading:t,roles:o}){let n={role_id:db.value,query:"",page:0},[r,i]=useState(n),[s]=useDebouncedValue(r.query,500),l=useMemo(()=>({roles:JM(o)}),[o]),a=useCallback((c,p)=>{let f={...r,[c]:p};i(f);},[r]),u=()=>{i(n);};return useEffect(()=>{e({...r,query:s});},[r.role_id,r.page,s]),jsxs("div",{children:[jsx(Select,{label:"Roles",data:l.roles,value:r.role_id,onChange:c=>a("role_id",c),disabled:t}),jsx(TextInput,{label:"Search by name or email",value:r.role_id!=="all"?"":r.query,onChange:c=>a("query",c.currentTarget.value),disabled:t||r.role_id!=="all"}),jsx(Space,{h:"md"}),jsx(Button,{fullWidth:true,disabled:t,leftIcon:jsx(IconCircleX,{}),onClick:u,children:"Clear filters"})]})}function mb({reportId:e,onSelectFavorites:t,onClickDelete:o}){let n=Da$1(e),r=g$2(e),{data:i}=xa(),s=i?.reduce((f,m)=>(m.report_id===e&&(f[m.id]=m),f),{})||{},l=va$1(f=>f.status.localeDefault),a=n.data,[u,c]=useState(a?a.dimensions.map(()=>{}):[void 0]),p=(f,m)=>{let g=[...u];g[f]=m?{variantId:parseInt(m.variant_id,10),contentId:parseInt(m.content_id,10)}:void 0,c(g),g.some(S=>typeof S>"u")||t(e,g);};return useEffect(()=>{n.isError&&o(e);},[n.isError]),jsx(Stack,{children:a&&jsxs(Fragment,{children:[jsxs(Group,{spacing:"xl",align:"center",children:[jsxs(Text,{children:["Report: ",a.name]}),jsx(ActionIcon,{size:"md",color:"red",onClick:()=>o(e),children:jsx(IconTrash,{})})]}),a.dimensions.length===0&&jsx(Group,{children:jsxs(Text,{c:"dimmed",fz:"sm",children:["No dimensions created in report ",a.name," yet."]})}),a.dimensions.map((f,m)=>jsxs(Group,{children:[jsxs(Text,{tt:"uppercase",fz:"0.6rem",fw:700,color:"gray.6",children:[s[f].name,":"]}),jsx(ta,{dimensionId:f,value:r?{variantId:r[m].variantId,memberId:r[m].contentId}:void 0,onSelect:g=>p(m,g),locale:l},f)]},f))]})})}function gb({selectedReportId:e="",onChangeReport:t,exclude:o=[]}){let n=wa$1(),r=l=>{t(l);},s=useMemo(()=>n.isSuccess?n.data.map(l=>({value:`${l.id}`,label:l.name})):[],[n.status]).filter(l=>!o.includes(l.value));return jsx(Select,{style:{width:100},size:"xs",placeholder:"Choose a report",data:s,value:String(e),onChange:r,disabled:s.length===0})}var hD=e=>e?e.map(t=>({value:String(t.id),label:t.name,group:t.type})):[];function Sb({userId:e,onEditEnd:t,roles:o}){let n=ua(),{user:r,update:i}=a$1(),[s,l]=useState(null),[a$2,u]=useState(true),[c,p]=useState(false),[f]=useState(""),[m,g]=useState(true),[S,v]=useState(""),h=useForm(),b=useMemo(()=>!!(r&&r.id===e),[r]),C=!!e,d=useMemo(()=>({roles:hD(o)}),[o]),y=s&&s.app_metadata&&s.app_metadata.reports?s.app_metadata.reports:[],x=y.map(I=>String(I.reportId)),k=async()=>{u(true),p(false);let I=await n(ta$1.readUser(e)).then(G=>G);l(I),h.setValues(I);let O=I&&I.app_metadata&&I.app_metadata.reports?I.app_metadata.reports:[];g(O.length===0),u(false);};useEffect(()=>{e?k():l(null);},[e]);let R=async()=>{if(u(true),s){let I={roles:s.roles,app_metadata:s.app_metadata};await n(ta$1.updateUser({user:{user_id:s.user_id,...I}})).then(()=>{b?(console.info("its YOU! Refreshing page to grab new change on session",I),i()):(u(false),t());});}},B=I=>{let O=I.map(L=>o.find(U=>U.id===L)).filter(L=>L),G=O.find(L=>L.name===a.EDITOR);O.find(L=>L.name===a.ADMIN);let F=s?s.app_metadata:{};G||(F={...F,reports:[]},g(true)),l({...s,roles:O,app_metadata:F});},N=I=>{v(I);},$=()=>{if(s&&S){let I=s.app_metadata&&s.app_metadata.reports?s.app_metadata.reports:[];I.push({reportId:parseInt(S,10),favorites:[]}),l({...s,app_metadata:{...s.app_metadata,reports:I}}),v("");}},K=I=>{if(s&&I){let O=s.app_metadata&&s.app_metadata.reports?s.app_metadata.reports:[];l({...s,app_metadata:{...s.app_metadata,reports:O.filter(G=>parseInt(`${G.reportId}`,10)!==parseInt(I,10))}});}},T=I=>{g(I.currentTarget.checked),s&&l({...s,app_metadata:{...s.app_metadata,reports:[]}});},M=(I,O)=>{if(s){let W=(s.app_metadata&&s.app_metadata.reports?[...s.app_metadata.reports]:[]).map(F=>(F.reportId===I&&(F.favorites=O),F));l({...s,app_metadata:{...s.app_metadata,reports:W}});}};return jsx(Fragment,{children:jsx(Drawer,{opened:C,onClose:()=>t(),title:jsxs(Fragment,{children:["Edit user ID ",e," ",b?jsx(Badge,{children:"YOU"}):""]}),padding:"lg",closeOnClickOutside:false,closeOnEscape:false,position:"right",size:"50%",lockScroll:true,withCloseButton:false,children:jsx(bt,{content:jsxs(Fragment,{children:[jsx(LoadingOverlay,{visible:a$2,overlayBlur:2,overlayOpacity:.5}),c&&jsx(Alert,{title:"Member Form",color:"red",children:"Error, please try again."}),r&&!c&&jsxs(Stack,{justify:"space-between",children:[jsxs(Group,{position:"apart",grow:true,children:[jsx(TextInput,{mt:"xs",disabled:true,label:"Name",...h.getInputProps("name")}),jsx(TextInput,{mt:"xs",disabled:true,label:"email",...h.getInputProps("email")})]}),jsxs(Stack,{children:[jsx(Title,{order:2,children:"Roles:"}),jsx(MultiSelect,{data:d.roles,onChange:B,value:(s?.roles||[]).map(I=>I.id),error:f})]}),s&&(s.roles||[]).map(I=>I.name).includes(a.EDITOR)&&jsxs(Stack,{children:[jsx(Title,{order:4,children:"Editor settings:"}),jsxs(Group,{children:[jsx(Text,{children:"Edit selected reports only"}),jsx(Switch,{label:"",checked:m,onChange:T}),jsx(Text,{children:"Edit all reports"})]}),!m&&jsxs(Fragment,{children:[jsxs(Group,{grow:true,children:[jsx(gb,{selectedReportId:S,onChangeReport:N,exclude:x}),jsx(Button,{variant:"outline",disabled:a$2||!S&&S==="",onClick:$,children:"Add Report"})]}),y.map(I=>jsx(Stack,{children:jsx(mb,{reportId:I.reportId,initialFavorites:I.favorites,onSelectFavorites:M,onClickDelete:K})},I.reportId))]})]})]})]}),buttons:jsxs(Fragment,{children:[jsx(Button,{variant:"outline",disabled:a$2,onClick:()=>t(),children:"Cancel"}),jsx(Button,{onClick:R,loading:a$2,disabled:a$2,children:"Save User"})]}),size:165})})})}function xb({response:e,onClickEdit:t,onPageChange:o}){let[n,r]=useState([]),[i,s]=useState({pageIndex:0,pageSize:10}),[l,a]=useState(0);return useEffect(()=>{o(i.pageIndex+1);},[i.pageIndex]),useEffect(()=>{e&&(r(e.users),a(e.total));},[e]),useEffect(()=>{r(e);},[]),jsx(MantineReactTable,{columns:[{header:"",accessorKey:"image",Cell:({row:c})=>jsx(Avatar,{src:c.original.picture,alt:`${c.original.name}`,radius:20}),size:50,mantineTableBodyCellProps:{align:"center"}},{header:"Name",accessorKey:"name"},{header:"Email",accessorKey:"email"},{header:"Actions",accessorKey:"actions",Cell:({row:c})=>jsx(ActionIcon,{onClick:()=>t(c.original),children:jsx(IconPencil,{size:20})},"edit"),size:100,mantineTableHeadCellProps:{align:"center"},mantineTableBodyCellProps:{align:"center"}}],data:n,enableColumnActions:false,enablePagination:true,enableSorting:false,enableTopToolbar:false,initialState:{density:"xs"},layoutMode:"grid",mantineTableContainerProps:{sx:{minHeight:150}},manualPagination:true,onPaginationChange:s,paginationDisplayMode:"pages",rowCount:l,state:{pagination:{pageIndex:i.pageIndex,pageSize:i.pageSize}}})}function kb(){let[e,t]=useState(null),[o,n]=useState([]),[r,i]=useState([]),[s,l]=useState(true),[a,u]=useState({query:""}),c=ua(),p=v=>{u(v);},f=v=>{u({...a,page:v});},m=v=>{t(v.user_id);},g=()=>{t(null),S();},S=async()=>{l(true);let v={query:a.query};a.role_id&&a.role_id!=="all"&&(v.role_id=a.role_id),v.page=a.page?a.page-1:0,c(ta$1.searchUser(v)).then(h=>{n(h),l(false);});};return useEffect(()=>{l(true),c(ta$1.searchRole()).then(v=>{i(v.roles),l(false);});},[c]),useEffect(()=>{S();},[a]),jsxs(Container,{fluid:true,children:[jsxs(Grid,{children:[jsxs(Grid.Col,{span:2,children:[jsx(Text,{ml:"xl",my:"sm",weight:"bold",children:"Users Management"}),jsx(fb,{onChange:p,loading:s,roles:r})]}),jsxs(Grid.Col,{span:10,style:{height:"100vh",position:"relative"},children:[jsx(LoadingOverlay,{visible:s,overlayBlur:2,overlayOpacity:.5}),jsx(Space,{h:"xs"}),jsx(xb,{response:o,onClickEdit:m,onPageChange:f})]})]}),e&&jsx(Sb,{userId:e,onEditEnd:g,roles:r})]})}function KD(e){let{title:t="Bespoke CMS",pathSegment:o="bespoke",locale:n=ea,profilePrefix:r="/profilePathManager",previewPrefix:i=null}=e,s={position:"bottom-center",...e.notifications};return l;function l(a){let{bespokeVersion:u}=a;return jsxs(eb,{pathSegment:o,profilePrefix:r,previewPrefix:i,children:[jsx(_D,{children:jsx("title",{children:t})}),jsxs(MantineProvider,{inherit:false,children:[jsx(Notifications,{...s}),jsx(a$3,{children:jsx(a$4,{fallback:jsx("p",{children:"Client side error in Bespoke. Check the console for details."}),children:jsx(YD,{locale:n,version:u})})})]})]})}}var Eb=[{icon:jsx(IconBallpen,{size:24}),color:"blue",label:"Reports Builder",href:"reports",roleRequired:a.EDITOR},{icon:jsx(IconDatabase,{size:24}),color:"teal",label:"Metadata Editor",href:"metadata",roleRequired:a.EDITOR},{icon:jsx(IconMathFunction,{size:24}),color:"violet",label:"Formatters List",href:"formatters",roleRequired:a.EDITOR},{icon:jsx(IconNetwork,{size:24}),color:"violet",label:"Data Sources",href:"datasources",roleRequired:a.EDITOR},{icon:jsx(IconUsers,{size:24}),color:"pink",label:"Users Management",href:"users",roleRequired:a.ADMIN}];function qD(){let e=ua(),{user:t,isLoading:o}=d$1(),n=t.bespoke_user_metadata.preferredLocale,[r,i]=useState("idle"),{update:s}=a$1();return o?null:jsx(Lr,{onChange:a=>{let u={user_metadata:{preferredLocale:a}};i("loading"),e(ta$1.updateMyData(u)).then(c=>{c.ok&&(e(ta$1.setPreferredLocale(a)),s(),i("idle"));});},defaultValue:n,loading:r==="loading",selectProps:{size:"xs",label:"User Locale",styles:{root:{display:"flex",flexDirection:"row",alignItems:"center",justifyContent:"space-between"}}}})}function YD(e){let{locale:t,version:o}=e,n=useRef(null),[r,{open:i,close:s}]=useDisclosure(false),{user:l,isLoading:a}=d$1(),u=a$2(),c=useCallback(g=>{let S=[];return Eb.forEach(v=>{S.push(jsx(XD,{item:v,disabled:g&&Array.isArray(g.bespoke_roles)?!g.bespoke_roles.includes(v.roleRequired):false},v.label));}),S},[]),p=useMemo(()=>{let g=c(l),S=u.page==="welcome"||r;return jsx(Fragment,{children:jsx(Box,{w:S?240:50,sx:{zIndex:99,overflow:"hidden",transition:"width .3s",boxShadow:"0px 4px 15px 5px rgba(0, 0, 0, 0.05)"},h:"100%",top:0,bottom:0,left:0,pos:"fixed",bg:"#F6F6F6",p:0,children:jsxs(Navbar,{p:0,w:240,hiddenBreakpoint:1e5,pos:"relative",pt:40,top:0,pb:30,h:"100vh",width:{base:240},onMouseEnter:()=>{n.current="open",setTimeout(()=>{n.current==="open"&&i();},200);},onMouseLeave:()=>{n.current="close",setTimeout(()=>{n.current==="close"&&s();},350);},withBorder:false,children:[jsx(Navbar.Section,{style:{position:"relative"},children:jsx(Fp,{href:u.href(""),onlyIcon:!S,version:o})}),jsx(Navbar.Section,{grow:true,component:ScrollArea,children:jsx(Stack,{spacing:0,children:g})}),jsx(Navbar.Section,{children:l&&!a&&jsx(Fragment,{children:jsxs(Stack,{px:13,children:[jsxs(Group,{align:"flex-start",children:[jsx("div",{children:jsx(Avatar,{src:l.picture,radius:"xl",size:"sm"})}),S&&jsxs(Stack,{sx:{flex:1},spacing:"xs",children:[jsxs(Box,{children:[jsx(Text,{size:"sm",weight:500,lh:1,sx:{flexGrow:1},children:l.name}),jsx(Text,{color:"dimmed",size:"xs",children:l.email})]}),jsx(qD,{})]})]}),S&&jsx(Stack,{children:jsx(Button,{px:13,onClick:()=>signOut({callbackUrl:process.env.NEXT_PUBLIC_REPORTS_BASE_URL||"/"}),compact:true,size:"xs",variant:"outline",leftIcon:jsx(IconLogout,{size:14}),children:"Disconnect"})})]})})})]})})})},[u,r,l]),f=useMemo(()=>{let g=Eb.find(S=>S.href.includes(u.page));if(u.page==="welcome")return jsx(zh,{});if(l&&Array.isArray(l.bespoke_roles)&&l.bespoke_roles.includes(g?.roleRequired)){if(u.page==="metadata")return jsx(Qh,{});if(u.page==="formatters")return jsx(Sh,{});if(u.page==="datasources")return jsx(Lh,{});if(u.page==="reports"){if(u.params.length>0){let S=Number.parseInt(u.params[0]);return jsx(th,{id:S,locale:t})}return jsx(lb,{})}if(u.page==="users")return jsx(kb,{})}else return jsx(pb,{});return jsx(tb,{})},[u,l]),m=ua();return useEffect(()=>{m(fa$1.setStatus({isCMS:true}));},[]),jsx(AppShell,{styles:{main:{background:"#f8f9fa",paddingLeft:50,paddingTop:0}},fixed:true,padding:0,navbar:p,children:f})}function XD({item:e,disabled:t}){let{page:o}=a$2(),n=o&&o.includes(e.href);return jsx(Vb,{href:e.href,passHref:true,children:jsx(UnstyledButton,{disabled:t,py:"sm",px:13,bg:n?"blue.1":"transparent",w:"100%",display:"block",sx:{display:"block",width:"100%","&:hover":{backgroundColor:"#f9f9f9"}},children:jsxs(Group,{spacing:24,children:[jsx(ThemeIcon,{size:24,color:n?"blue.5":"gray.6",bg:"transparent",variant:"light",sx:{flexShrink:0},children:e.icon}),jsx(Text,{size:"sm",fw:n?700:500,color:n?"blue.5":"gray.6",children:e.label})]})})},e.label)}export{KD as BespokeManager};
49
+ `,children:jsx(NumberInput,{disabled:!R.values.visible,type:"number",precision:4,step:1e-4,removeTrailingZeros:true,min:0,max:1,decimalSeparator:".",...R.getInputProps("zvalue")})}),jsx(Checkbox,{mt:"2.3rem",label:"Visible in search",...R.getInputProps("visible",{type:"checkbox"})})]}),jsx(Group,{mt:"xs",position:"apart",grow:true,children:jsx(SegmentedControl,{value:a,onChange:l,data:r})}),!W&&jsx(Alert,{title:"Unavailable locale",color:"blue",children:"This language was not ingested for the current member. Go to variant editor and provide the members there."}),W&&jsxs(Fragment,{children:[jsx(Group,{mt:"xs",position:"apart",grow:true,children:jsx(TextInput,{label:"Name",...B[a].getInputProps("name")})}),jsx(Group,{mt:"xs",position:"apart",align:"top",grow:true,children:jsx(MultiSelect,{label:"Keywords",data:B[a].values.keywords,placeholder:"Enter keywords",searchable:true,creatable:true,valueComponent:({label:L})=>jsxs(Badge,{onClick:()=>{let U=B[a].values.keywords;B[a].setFieldValue("keywords",U.filter(P=>P!==L));},children:[L," ","x"]}),getCreateLabel:L=>`+ Create ${L}`,value:B[a].values.keywords,onCreate:L=>{let U=B[a].values.keywords;return B[a].setFieldValue("keywords",[...U,L]),L}})}),jsx(Input.Wrapper,{label:"Attributes",children:jsx(t,{data:B[a].values.attributes})})]})]})}),jsx(Tabs.Panel,{value:"image",py:"md",children:jsxs(Stack,{justify:"space-between",children:[jsxs(Group,{position:"apart",grow:true,children:[jsxs(Stack,{children:[jsx(Vr,{member:s,forceRefreshTimestamp:true}),jsx(Button,{variant:"outline",disabled:c,leftIcon:jsx(IconPolaroid,{}),onClick:()=>f(true),children:"Change image"}),s&&s.image&&jsx(Button,{variant:"outline",disabled:c,leftIcon:jsx(IconCircleMinus,{}),onClick:()=>O(),children:"Remove image"}),jsx(Space,{h:"md"})]}),jsxs(Stack,{justify:"flex-start",children:[jsx(TextInput,{disabled:!s||!s.image,label:"Source",...N.getInputProps("url")}),jsx(TextInput,{disabled:!s||!s.image,label:"Author",...N.getInputProps("author")}),jsx(TextInput,{disabled:!s||!s.image,label:"License",...N.getInputProps("license")}),jsx(SegmentedControl,{disabled:!s||!s.image,value:a,onChange:l,data:r}),jsx(TextInput,{disabled:!s||!s.image,label:"Alternative image text",...$[a].getInputProps("meta")})]})]}),b&&jsx(Loader,{}),!b&&d.length>0&&jsxs(Fragment,{children:[jsx(Text,{children:"Select the members you want to update with the same image."}),jsx($n,{members:d,colsToRender:["id","report","name","slug","image"],dataTableProps:F})]})]})})]})]}),buttons:jsxs(Fragment,{children:[jsx(Button,{variant:"outline",disabled:c,onClick:()=>t$1(),children:"Cancel"}),jsx(Button,{onClick:G,loading:c,disabled:c,children:"Save Member"})]}),size:165})}),m&&jsx(Hh,{member:s,onEditEnd:I})]})}function Qh(){let[e,t]=useState(null),[o,n]=useState([]),[r,i]=useState(true),[a,l]=useState(true),[s,u]=useState(),[c,p]=useState(1),[m,f]=useState(0),g=C=>{l(C),p(1);},S=C=>{C&&C.length&&u(C[0]);},v=C=>{t(C.content_id);},h=()=>{t(null),b();},b=async()=>{i(true);let C=Object.keys({...a}).reduce((y,x)=>(a[x]!=="all"&&(y[x]=a[x]),y),{}),d=await Gh.get("/api/cms/search/members",{params:{...C,offset:(c-1)*parseInt(C.limit||"10",10),locale:"all",includes:true,sort:s?s.id:"zvalue",direction:s?s.desc?"desc":"asc":"desc",origin:"flexsearch"}}).then(y=>{let x=y.data&&y.data.data&&y.data.data.meta?Object.keys(y.data.data.meta.variantCount).reduce((k,R)=>{let B=y.data.data.meta.variantCount[R];return a.paginationVariants&&a.paginationVariants.length>0&&(a.paginationVariants.includes(R)||(B=0)),k+B},0):0;return f(x),y.data&&y.data.data&&y.data.data.results?y.data.data.results:[]});n(d),i(false);};return useEffect(()=>{a.limit&&b();},[a,s,c]),jsxs(Container,{fluid:true,children:[jsxs(Grid,{children:[jsxs(Grid.Col,{span:2,children:[jsx(Text,{ml:"xl",my:"sm",weight:"bold",children:"Metadata"}),jsx(Fh,{onChange:g,loading:r})]}),jsxs(Grid.Col,{span:10,style:{height:"95vh",position:"relative"},children:[jsx(LoadingOverlay,{visible:r,overlayBlur:2,overlayOpacity:.5}),jsx(Space,{h:"xs"}),jsx($n,{members:o,onClickEdit:v,onSort:S}),jsx(Group,{position:"center",children:jsx(Pagination,{value:c,onChange:p,total:Math.ceil(m/(a.limit||10)),size:"sm",py:"xs"})})]})]}),e&&jsx(Jh,{memberId:e,onEditEnd:h})]})}function tb(){let{user:e}=a$1(),t={color:"#000"};return jsxs(Flex,{mih:"100vh",gap:"md",justify:"center",align:"center",direction:"column",wrap:"wrap",style:{background:"white"},children:[jsx(Title,{style:t,children:"Not found."}),jsxs(Title,{order:2,style:t,children:["Sorry, ",e?.name,"!"]}),jsx(Text,{style:t,children:"The page you are looking for is not here."}),jsx(Button,{component:"a",href:"/",children:"Back to homepage"})]})}function wu(e){let{for:t,enabled:o}=e,n=useMantineTheme(),r=a$2(),i=n.colorScheme==="dark"?n.colors.dark[1]:n.colors.gray[7];return jsxs(Card,{shadow:"xs",p:"sm",w:"100%",children:[jsxs(Group,{position:"apart",children:[jsxs(Center,{mah:24,children:[jsx(IconFileAnalytics,{size:22}),jsx(Text,{mx:"xs",weight:"bold",children:t.name}),t.type==="report"&&t.settings?.hide&&jsx(Tooltip,{label:"Hidden in explore/search",position:"top",children:jsx(IconEyeOff,{size:16,style:{marginLeft:4,color:i}})})]}),jsx(Badge,{variant:"light",children:t.type})]}),jsxs(Text,{size:"sm",style:{color:i,lineHeight:2},children:["Order in explore/search: ",(t.type==="report"?t.settings?.order:void 0)??0]}),jsx(Space,{w:"xs"}),jsxs(Group,{position:"apart",children:[jsx(Vb,{href:r.href("reports",t.id),passHref:true,children:jsx(Button,{leftIcon:jsx(IconPencil,{}),compact:true,children:"Edit"})}),jsx(Bt,{type:"report",id:t.id,disabled:!o})]})]})}cb(wu,Da$1);var rb=e=>(e&&e.bespoke_app_metadata&&e.bespoke_app_metadata.reports&&Array.isArray(e.bespoke_app_metadata.reports)?e.bespoke_app_metadata.reports:[]).map(o=>o.reportId);function lb(){let e=ua(),[t,o]=useState(false),{user:n}=a$1(),r=rb(n),i=wa$1(),a=useCallback(s=>{o(true),e(ta$1.createEntity("report",s)).then(u=>{u.ok&&r.length>0||o(false);});},[]),l=useMemo(()=>i.isUninitialized||i.isFetching?jsx(LoadingOverlay,{visible:true,overlayBlur:2}):i.isError?jsx(Alert,{icon:jsx(IconFileAnalytics,{size:22}),title:"Server Error",children:i.error.message}):i.data.length===0?jsx(Alert,{icon:jsx(IconFileAnalytics,{size:22}),title:"No Saved Reports",children:"Please use the button below to create your first report."}):jsx(Stack,{children:i.data.sort((s,u)=>{let c=(s.type==="report"?s.settings?.order:void 0)??0,p=(u.type==="report"?u.settings?.order:void 0)??0;return c-p}).map(s=>jsx(wu,{for:s,enabled:!!(r.length===0||r.includes(s.id))},s.id))}),[i.data,i.error,i.status,r]);return jsxs(Container,{size:"xl",children:[jsx("h1",{children:"Reports"}),jsx(LoadingOverlay,{visible:t,overlayBlur:2,overlayOpacity:.5}),l,jsx(Space,{h:"xl",w:"xl"}),jsx(Fn,{fields:[{type:"text",name:"name",label:"Report Name",initialValue:""}],onSubmit:a,target:jsx(ActionIcon,{size:"xl",radius:"xl",children:jsx(IconPlus,{size:30})})})]})}function pb(){let{user:e}=a$1(),t={color:"#000"};return jsxs(Flex,{mih:"100vh",gap:"md",justify:"center",align:"center",direction:"column",wrap:"wrap",style:{background:"white"},children:[jsx(Title,{style:t,children:"Unauthorize or forbidden access."}),jsxs(Title,{style:t,order:2,children:["Sorry, ",e?.name,"!"]}),jsx(Text,{style:t,children:"Your session or your user's roles doesn't satisfy the needs of the requested view. Please, ask your administrator to allow you."}),jsxs(Group,{children:[jsx(Button,{component:"a",href:"/",leftIcon:jsx(IconHome,{size:14}),variant:"outline",color:"dark",children:"Back to homepage"}),jsx(Button,{onClick:()=>signOut({callbackUrl:process.env.NEXT_PUBLIC_REPORTS_BASE_URL||"/"}),leftIcon:jsx(IconLogout,{size:14}),variant:"outline",color:"dark",children:"Disconnect"})]})]})}var db={value:"all",label:"All"},QM=e=>{if(!e)return [];let t=e.map(o=>({value:String(o.id),label:`${o.name} (${o.type})`}));return [db,...t]};function mb({onChange:e,loading:t,roles:o}){let n={role_id:db.value,query:"",page:0},[r,i]=useState(n),[a]=useDebouncedValue(r.query,500),l=useMemo(()=>({roles:QM(o)}),[o]),s=useCallback((c,p)=>{let m={...r,[c]:p};i(m);},[r]),u=()=>{i(n);};return useEffect(()=>{e({...r,query:a});},[r.role_id,r.page,a]),jsxs("div",{children:[jsx(Select,{label:"Roles",data:l.roles,value:r.role_id,onChange:c=>s("role_id",c),disabled:t}),jsx(TextInput,{label:"Search by name or email",value:r.role_id!=="all"?"":r.query,onChange:c=>s("query",c.currentTarget.value),disabled:t||r.role_id!=="all"}),jsx(Space,{h:"md"}),jsx(Button,{fullWidth:true,disabled:t,leftIcon:jsx(IconCircleX,{}),onClick:u,children:"Clear filters"})]})}function fb({reportId:e,onSelectFavorites:t,onClickDelete:o}){let n=Da$1(e),r=g$2(e),{data:i}=xa(),a=i?.reduce((m,f)=>(f.report_id===e&&(m[f.id]=f),m),{})||{},l=va$1(m=>m.status.localeDefault),s=n.data,[u,c]=useState(s?s.dimensions.map(()=>{}):[void 0]),p=(m,f)=>{let g=[...u];g[m]=f?{variantId:parseInt(f.variant_id,10),contentId:parseInt(f.content_id,10)}:void 0,c(g),g.some(S=>typeof S>"u")||t(e,g);};return useEffect(()=>{n.isError&&o(e);},[n.isError]),jsx(Stack,{children:s&&jsxs(Fragment,{children:[jsxs(Group,{spacing:"xl",align:"center",children:[jsxs(Text,{children:["Report: ",s.name]}),jsx(ActionIcon,{size:"md",color:"red",onClick:()=>o(e),children:jsx(IconTrash,{})})]}),s.dimensions.length===0&&jsx(Group,{children:jsxs(Text,{c:"dimmed",fz:"sm",children:["No dimensions created in report ",s.name," yet."]})}),s.dimensions.map((m,f)=>jsxs(Group,{children:[jsxs(Text,{tt:"uppercase",fz:"0.6rem",fw:700,color:"gray.6",children:[a[m].name,":"]}),jsx(ta,{dimensionId:m,value:r?{variantId:r[f].variantId,memberId:r[f].contentId}:void 0,onSelect:g=>p(f,g),locale:l},m)]},m))]})})}function gb({selectedReportId:e="",onChangeReport:t,exclude:o=[]}){let n=wa$1(),r=l=>{t(l);},a=useMemo(()=>n.isSuccess?n.data.map(l=>({value:`${l.id}`,label:l.name})):[],[n.status]).filter(l=>!o.includes(l.value));return jsx(Select,{style:{width:100},size:"xs",placeholder:"Choose a report",data:a,value:String(e),onChange:r,disabled:a.length===0})}var bD=e=>e?e.map(t=>({value:String(t.id),label:t.name,group:t.type})):[];function Sb({userId:e,onEditEnd:t,roles:o}){let n=ua(),{user:r,update:i}=a$1(),[a$2,l]=useState(null),[s,u]=useState(true),[c,p]=useState(false),[m]=useState(""),[f,g]=useState(true),[S,v]=useState(""),h=useForm(),b=useMemo(()=>!!(r&&r.id===e),[r]),C=!!e,d=useMemo(()=>({roles:bD(o)}),[o]),y=a$2&&a$2.app_metadata&&a$2.app_metadata.reports?a$2.app_metadata.reports:[],x=y.map(I=>String(I.reportId)),k=async()=>{u(true),p(false);let I=await n(ta$1.readUser(e)).then(G=>G);l(I),h.setValues(I);let O=I&&I.app_metadata&&I.app_metadata.reports?I.app_metadata.reports:[];g(O.length===0),u(false);};useEffect(()=>{e?k():l(null);},[e]);let R=async()=>{if(u(true),a$2){let I={roles:a$2.roles,app_metadata:a$2.app_metadata};await n(ta$1.updateUser({user:{user_id:a$2.user_id,...I}})).then(()=>{b?(console.info("its YOU! Refreshing page to grab new change on session",I),i()):(u(false),t());});}},B=I=>{let O=I.map(L=>o.find(U=>U.id===L)).filter(L=>L),G=O.find(L=>L.name===a.EDITOR);O.find(L=>L.name===a.ADMIN);let F=a$2?a$2.app_metadata:{};G||(F={...F,reports:[]},g(true)),l({...a$2,roles:O,app_metadata:F});},N=I=>{v(I);},$=()=>{if(a$2&&S){let I=a$2.app_metadata&&a$2.app_metadata.reports?a$2.app_metadata.reports:[];I.push({reportId:parseInt(S,10),favorites:[]}),l({...a$2,app_metadata:{...a$2.app_metadata,reports:I}}),v("");}},K=I=>{if(a$2&&I){let O=a$2.app_metadata&&a$2.app_metadata.reports?a$2.app_metadata.reports:[];l({...a$2,app_metadata:{...a$2.app_metadata,reports:O.filter(G=>parseInt(`${G.reportId}`,10)!==parseInt(I,10))}});}},T=I=>{g(I.currentTarget.checked),a$2&&l({...a$2,app_metadata:{...a$2.app_metadata,reports:[]}});},M=(I,O)=>{if(a$2){let W=(a$2.app_metadata&&a$2.app_metadata.reports?[...a$2.app_metadata.reports]:[]).map(F=>(F.reportId===I&&(F.favorites=O),F));l({...a$2,app_metadata:{...a$2.app_metadata,reports:W}});}};return jsx(Fragment,{children:jsx(Drawer,{opened:C,onClose:()=>t(),title:jsxs(Fragment,{children:["Edit user ID ",e," ",b?jsx(Badge,{children:"YOU"}):""]}),padding:"lg",closeOnClickOutside:false,closeOnEscape:false,position:"right",size:"50%",lockScroll:true,withCloseButton:false,children:jsx(yt,{content:jsxs(Fragment,{children:[jsx(LoadingOverlay,{visible:s,overlayBlur:2,overlayOpacity:.5}),c&&jsx(Alert,{title:"Member Form",color:"red",children:"Error, please try again."}),r&&!c&&jsxs(Stack,{justify:"space-between",children:[jsxs(Group,{position:"apart",grow:true,children:[jsx(TextInput,{mt:"xs",disabled:true,label:"Name",...h.getInputProps("name")}),jsx(TextInput,{mt:"xs",disabled:true,label:"email",...h.getInputProps("email")})]}),jsxs(Stack,{children:[jsx(Title,{order:2,children:"Roles:"}),jsx(MultiSelect,{data:d.roles,onChange:B,value:(a$2?.roles||[]).map(I=>I.id),error:m})]}),a$2&&(a$2.roles||[]).map(I=>I.name).includes(a.EDITOR)&&jsxs(Stack,{children:[jsx(Title,{order:4,children:"Editor settings:"}),jsxs(Group,{children:[jsx(Text,{children:"Edit selected reports only"}),jsx(Switch,{label:"",checked:f,onChange:T}),jsx(Text,{children:"Edit all reports"})]}),!f&&jsxs(Fragment,{children:[jsxs(Group,{grow:true,children:[jsx(gb,{selectedReportId:S,onChangeReport:N,exclude:x}),jsx(Button,{variant:"outline",disabled:s||!S&&S==="",onClick:$,children:"Add Report"})]}),y.map(I=>jsx(Stack,{children:jsx(fb,{reportId:I.reportId,initialFavorites:I.favorites,onSelectFavorites:M,onClickDelete:K})},I.reportId))]})]})]})]}),buttons:jsxs(Fragment,{children:[jsx(Button,{variant:"outline",disabled:s,onClick:()=>t(),children:"Cancel"}),jsx(Button,{onClick:R,loading:s,disabled:s,children:"Save User"})]}),size:165})})})}function xb({response:e,onClickEdit:t,onPageChange:o}){let[n,r]=useState([]),[i,a]=useState({pageIndex:0,pageSize:10}),[l,s]=useState(0);return useEffect(()=>{o(i.pageIndex+1);},[i.pageIndex]),useEffect(()=>{e&&(r(e.users),s(e.total));},[e]),useEffect(()=>{r(e);},[]),jsx(MantineReactTable,{columns:[{header:"",accessorKey:"image",Cell:({row:c})=>jsx(Avatar,{src:c.original.picture,alt:`${c.original.name}`,radius:20}),size:50,mantineTableBodyCellProps:{align:"center"}},{header:"Name",accessorKey:"name"},{header:"Email",accessorKey:"email"},{header:"Actions",accessorKey:"actions",Cell:({row:c})=>jsx(ActionIcon,{onClick:()=>t(c.original),children:jsx(IconPencil,{size:20})},"edit"),size:100,mantineTableHeadCellProps:{align:"center"},mantineTableBodyCellProps:{align:"center"}}],data:n,enableColumnActions:false,enablePagination:true,enableSorting:false,enableTopToolbar:false,initialState:{density:"xs"},layoutMode:"grid",mantineTableContainerProps:{sx:{minHeight:150}},manualPagination:true,onPaginationChange:a,paginationDisplayMode:"pages",rowCount:l,state:{pagination:{pageIndex:i.pageIndex,pageSize:i.pageSize}}})}function kb(){let[e,t]=useState(null),[o,n]=useState([]),[r,i]=useState([]),[a,l]=useState(true),[s,u]=useState({query:""}),c=ua(),p=v=>{u(v);},m=v=>{u({...s,page:v});},f=v=>{t(v.user_id);},g=()=>{t(null),S();},S=async()=>{l(true);let v={query:s.query};s.role_id&&s.role_id!=="all"&&(v.role_id=s.role_id),v.page=s.page?s.page-1:0,c(ta$1.searchUser(v)).then(h=>{n(h),l(false);});};return useEffect(()=>{l(true),c(ta$1.searchRole()).then(v=>{i(v.roles),l(false);});},[c]),useEffect(()=>{S();},[s]),jsxs(Container,{fluid:true,children:[jsxs(Grid,{children:[jsxs(Grid.Col,{span:2,children:[jsx(Text,{ml:"xl",my:"sm",weight:"bold",children:"Users Management"}),jsx(mb,{onChange:p,loading:a,roles:r})]}),jsxs(Grid.Col,{span:10,style:{height:"100vh",position:"relative"},children:[jsx(LoadingOverlay,{visible:a,overlayBlur:2,overlayOpacity:.5}),jsx(Space,{h:"xs"}),jsx(xb,{response:o,onClickEdit:f,onPageChange:m})]})]}),e&&jsx(Sb,{userId:e,onEditEnd:g,roles:r})]})}function qD(e){let{title:t="Bespoke CMS",pathSegment:o="bespoke",locale:n=ea,profilePrefix:r="/profilePathManager",previewPrefix:i=null}=e,a={position:"bottom-center",...e.notifications};return l;function l(s){let{bespokeVersion:u}=s;return jsxs(eb,{pathSegment:o,profilePrefix:r,previewPrefix:i,children:[jsx($D,{children:jsx("title",{children:t})}),jsxs(MantineProvider,{inherit:false,children:[jsx(Notifications,{...a}),jsx(a$3,{children:jsx(a$4,{fallback:jsx("p",{children:"Client side error in Bespoke. Check the console for details."}),children:jsx(XD,{locale:n,version:u})})})]})]})}}var Eb=[{icon:jsx(IconBallpen,{size:24}),color:"blue",label:"Reports Builder",href:"reports",roleRequired:a.EDITOR},{icon:jsx(IconDatabase,{size:24}),color:"teal",label:"Metadata Editor",href:"metadata",roleRequired:a.EDITOR},{icon:jsx(IconMathFunction,{size:24}),color:"violet",label:"Formatters List",href:"formatters",roleRequired:a.EDITOR},{icon:jsx(IconNetwork,{size:24}),color:"violet",label:"Data Sources",href:"datasources",roleRequired:a.EDITOR},{icon:jsx(IconUsers,{size:24}),color:"pink",label:"Users Management",href:"users",roleRequired:a.ADMIN}];function YD(){let e=ua(),{user:t,isLoading:o}=d$1(),n=t.bespoke_user_metadata.preferredLocale,[r,i]=useState("idle"),{update:a}=a$1();return o?null:jsx(Lr,{onChange:s=>{let u={user_metadata:{preferredLocale:s}};i("loading"),e(ta$1.updateMyData(u)).then(c=>{c.ok&&(e(ta$1.setPreferredLocale(s)),a(),i("idle"));});},defaultValue:n,loading:r==="loading",selectProps:{size:"xs",label:"User Locale",styles:{root:{display:"flex",flexDirection:"row",alignItems:"center",justifyContent:"space-between"}}}})}function XD(e){let{locale:t,version:o}=e,n=useRef(null),[r,{open:i,close:a}]=useDisclosure(false),{user:l,isLoading:s}=d$1(),u=a$2(),c=useCallback(g=>{let S=[];return Eb.forEach(v=>{S.push(jsx(JD,{item:v,disabled:g&&Array.isArray(g.bespoke_roles)?!g.bespoke_roles.includes(v.roleRequired):false},v.label));}),S},[]),p=useMemo(()=>{let g=c(l),S=u.page==="welcome"||r;return jsx(Fragment,{children:jsx(Box,{w:S?240:50,sx:{zIndex:99,overflow:"hidden",transition:"width .3s",boxShadow:"0px 4px 15px 5px rgba(0, 0, 0, 0.05)"},h:"100%",top:0,bottom:0,left:0,pos:"fixed",bg:"#F6F6F6",p:0,children:jsxs(Navbar,{p:0,w:240,hiddenBreakpoint:1e5,pos:"relative",pt:40,top:0,pb:30,h:"100vh",width:{base:240},onMouseEnter:()=>{n.current="open",setTimeout(()=>{n.current==="open"&&i();},200);},onMouseLeave:()=>{n.current="close",setTimeout(()=>{n.current==="close"&&a();},350);},withBorder:false,children:[jsx(Navbar.Section,{style:{position:"relative"},children:jsx(_p,{href:u.href(""),onlyIcon:!S,version:o})}),jsx(Navbar.Section,{grow:true,component:ScrollArea,children:jsx(Stack,{spacing:0,children:g})}),jsx(Navbar.Section,{children:l&&!s&&jsx(Fragment,{children:jsxs(Stack,{px:13,children:[jsxs(Group,{align:"flex-start",children:[jsx("div",{children:jsx(Avatar,{src:l.picture,radius:"xl",size:"sm"})}),S&&jsxs(Stack,{sx:{flex:1},spacing:"xs",children:[jsxs(Box,{children:[jsx(Text,{size:"sm",weight:500,lh:1,sx:{flexGrow:1},children:l.name}),jsx(Text,{color:"dimmed",size:"xs",children:l.email})]}),jsx(YD,{})]})]}),S&&jsx(Stack,{children:jsx(Button,{px:13,onClick:()=>signOut({callbackUrl:process.env.NEXT_PUBLIC_REPORTS_BASE_URL||"/"}),compact:true,size:"xs",variant:"outline",leftIcon:jsx(IconLogout,{size:14}),children:"Disconnect"})})]})})})]})})})},[u,r,l]),m=useMemo(()=>{let g=Eb.find(S=>S.href.includes(u.page));if(u.page==="welcome")return jsx(zh,{});if(l&&Array.isArray(l.bespoke_roles)&&l.bespoke_roles.includes(g?.roleRequired)){if(u.page==="metadata")return jsx(Qh,{});if(u.page==="formatters")return jsx(Sh,{});if(u.page==="datasources")return jsx(Lh,{});if(u.page==="reports"){if(u.params.length>0){let S=Number.parseInt(u.params[0]);return jsx(th,{id:S,locale:t})}return jsx(lb,{})}if(u.page==="users")return jsx(kb,{})}else return jsx(pb,{});return jsx(tb,{})},[u,l]),f=ua();return useEffect(()=>{f(fa.setStatus({isCMS:true}));},[]),jsx(AppShell,{styles:{main:{background:"#f8f9fa",paddingLeft:50,paddingTop:0}},fixed:true,padding:0,navbar:p,children:m})}function JD({item:e,disabled:t}){let{page:o}=a$2(),n=o&&o.includes(e.href);return jsx(Vb,{href:e.href,passHref:true,children:jsx(UnstyledButton,{disabled:t,py:"sm",px:13,bg:n?"blue.1":"transparent",w:"100%",display:"block",sx:{display:"block",width:"100%","&:hover":{backgroundColor:"#f9f9f9"}},children:jsxs(Group,{spacing:24,children:[jsx(ThemeIcon,{size:24,color:n?"blue.5":"gray.6",bg:"transparent",variant:"light",sx:{flexShrink:0},children:e.icon}),jsx(Text,{size:"sm",fw:n?700:500,color:n?"blue.5":"gray.6",children:e.label})]})})},e.label)}export{qD as BespokeManager};