@chaibuilder/sdk 4.0.0-beta.43 → 4.0.0-beta.45

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.
Files changed (125) hide show
  1. package/dist/{2SSKDMRQ-hQZti_AG.js → 2SSKDMRQ-CqsUj10r.js} +2 -2
  2. package/dist/{2SSKDMRQ-BZmyXysb.cjs → 2SSKDMRQ-D12irKaV.cjs} +1 -1
  3. package/dist/{AP7HFJJL-DhBHON6w.js → AP7HFJJL-CEMjieq8.js} +1 -1
  4. package/dist/{AP7HFJJL-DZJbtGey.cjs → AP7HFJJL-CQ1kBXlH.cjs} +1 -1
  5. package/dist/{IconPicker-y7ijQESM.js → IconPicker-CGtjTiWr.js} +1 -1
  6. package/dist/{IconPicker-BTC6tZZE.cjs → IconPicker-CeAu6O-X.cjs} +1 -1
  7. package/dist/{WDYDFRGG-BQXNJif4.cjs → WDYDFRGG-BGBMGOXn.cjs} +1 -1
  8. package/dist/{WDYDFRGG-DT73rUAi.js → WDYDFRGG-Djk7UWh1.js} +2 -2
  9. package/dist/{actions-registery-CqhNZFV3.cjs → actions-registery-B6tt904t.cjs} +18 -18
  10. package/dist/{actions-registery-CMKfEXxX.js → actions-registery-D1v8fvDh.js} +712 -709
  11. package/dist/actions.cjs +1 -1
  12. package/dist/actions.d.ts +135 -0
  13. package/dist/actions.js +7 -6
  14. package/dist/{active-in-another-tab-B_b2Wl-l.cjs → active-in-another-tab-BWn6jTeo.cjs} +1 -1
  15. package/dist/{active-in-another-tab-D5Wsc7po.js → active-in-another-tab-b3dtgwXA.js} +4 -4
  16. package/dist/{add-new-language-page-B37NvHcc.cjs → add-new-language-page-CJgeCgQ_.cjs} +1 -1
  17. package/dist/{add-new-language-page-DgYUSlvF.js → add-new-language-page-DLSJWwTI.js} +3 -3
  18. package/dist/{add-new-page-BLPSZY8N.js → add-new-page-CS8dEOhg.js} +2 -2
  19. package/dist/{add-new-page-CMkPeRMc.cjs → add-new-page-IRS1Ft0d.cjs} +1 -1
  20. package/dist/{ai-panel-default-lang-BJPZtqTZ.cjs → ai-panel-default-lang-BTjr4pC6.cjs} +2 -2
  21. package/dist/{ai-panel-default-lang-q7ibfHDa.js → ai-panel-default-lang-NdhYzpxN.js} +11 -11
  22. package/dist/{ai-panel-other-lang-DO2Pq3eM.js → ai-panel-other-lang-Bj2wYIfM.js} +14 -14
  23. package/dist/{ai-panel-other-lang-CqThrEnR.cjs → ai-panel-other-lang-BpjPfSPX.cjs} +1 -1
  24. package/dist/ai-prompt-input-B8SFfk6N.cjs +1 -0
  25. package/dist/ai-prompt-input-bleYNRnH.js +650 -0
  26. package/dist/{ai-translation-prompt-Ch54mM08.cjs → ai-translation-prompt-D1rNu8P-.cjs} +1 -1
  27. package/dist/{ai-translation-prompt-TUVm5MgK.js → ai-translation-prompt-DHfe6Wzy.js} +1 -1
  28. package/dist/apply-binding-CBSjMYSk.cjs +41 -0
  29. package/dist/{apply-binding-RQRSIe56.js → apply-binding-vAuN-TGV.js} +3 -2
  30. package/dist/{change-password-modal-Cet5GebC.js → change-password-modal-OPNVgWPf.js} +4 -4
  31. package/dist/{change-password-modal-xBIyXsLV.cjs → change-password-modal-pr1urpGi.cjs} +1 -1
  32. package/dist/{code-editor-C8oMJmY_.cjs → code-editor-BVmpIZOt.cjs} +1 -1
  33. package/dist/{code-editor-DvxiAjP6.js → code-editor-BfGHceIq.js} +1 -1
  34. package/dist/{continue-editing-in-this-client-B19gkD98.cjs → continue-editing-in-this-client-B0fhkHm9.cjs} +1 -1
  35. package/dist/{continue-editing-in-this-client-CGd_nIXe.js → continue-editing-in-this-client-BM6Ru46L.js} +2 -2
  36. package/dist/core.cjs +1 -1
  37. package/dist/core.js +18 -18
  38. package/dist/{css-import-modal-JsnFEHuT.cjs → css-import-modal-C9G5pbFd.cjs} +1 -1
  39. package/dist/{css-import-modal-DLLriSUJ.js → css-import-modal-CEQccCmc.js} +1 -1
  40. package/dist/{delete-page-Cc5Z537o.cjs → delete-page-CXRD2fUG.cjs} +1 -1
  41. package/dist/{delete-page-CjdSwdRR.js → delete-page-YGXD04Z1.js} +2 -2
  42. package/dist/{design-token-usage-DCEQ0nFH.cjs → design-token-usage-C5WfKLj-.cjs} +1 -1
  43. package/dist/{design-token-usage-hGL4vi4W.js → design-token-usage-CVPBTF21.js} +8 -8
  44. package/dist/{digital-asset-manager-l1HTU_vW.cjs → digital-asset-manager-BLnvpLiu.cjs} +1 -1
  45. package/dist/{digital-asset-manager-Bb7ESXoQ.js → digital-asset-manager-CC02mA_u.js} +3 -3
  46. package/dist/{duplicate-page-oxFQeRmn.js → duplicate-page-Df3_zMuR.js} +12 -12
  47. package/dist/{duplicate-page-cFYp-bAb.cjs → duplicate-page-N6d80CFF.cjs} +1 -1
  48. package/dist/{dynamic-page-selector-CEHpm0rg.cjs → dynamic-page-selector-CehQLxyZ.cjs} +1 -1
  49. package/dist/{dynamic-page-selector-Brj1zNHl.js → dynamic-page-selector-DDUtutYp.js} +12 -12
  50. package/dist/{image-editor-DhgFpSAR.js → image-editor-CzxSXo-u.js} +1 -1
  51. package/dist/{image-editor-D0A_xctQ.cjs → image-editor-DQ8mQonU.cjs} +1 -1
  52. package/dist/index-DAJ9bufO.cjs +5 -0
  53. package/dist/{index-ZaKz5cWo.cjs → index-DrzR7vXl.cjs} +2 -2
  54. package/dist/{index-CGZjCAyz.js → index-RwAuF_BE.js} +40 -40
  55. package/dist/{index-D2xHSM7d.js → index-nVkLHaAS.js} +1344 -1289
  56. package/dist/{json-diff-viewer-C-H_IWJx.js → json-diff-viewer-CgWyab6R.js} +6 -6
  57. package/dist/{json-diff-viewer-LIr31DRU.cjs → json-diff-viewer-DgcLmglp.cjs} +1 -1
  58. package/dist/{lang-panel-CAcPc81E.js → lang-panel-B95Qvr7o.js} +22 -22
  59. package/dist/{lang-panel-xrs5AMiU.cjs → lang-panel-D1usAgp_.cjs} +1 -1
  60. package/dist/{manage-design-tokens-CT5v3zQJ.js → manage-design-tokens-D2Oz-jVp.js} +2 -2
  61. package/dist/{manage-design-tokens-modal-Rh86m84s.cjs → manage-design-tokens-modal-Gufu9nHL.cjs} +1 -1
  62. package/dist/{manage-design-tokens-modal-C6ZCrth8.js → manage-design-tokens-modal-ZR8PuhWC.js} +2 -2
  63. package/dist/{manage-design-tokens-D2zeiRpA.cjs → manage-design-tokens-sDi2Pdec.cjs} +1 -1
  64. package/dist/{mark-as-template-RDZ4zAWY.cjs → mark-as-template-BN3Ao9n8.cjs} +1 -1
  65. package/dist/{mark-as-template-4VtOICqJ.js → mark-as-template-CzBJQ_nj.js} +2 -2
  66. package/dist/{models-D95ZYr_x.js → models-BCu-p_QK.js} +4 -4
  67. package/dist/{models-5gOsRC56.cjs → models-D0RH2u4C.cjs} +1 -1
  68. package/dist/{nested-path-selector-content-uXvLlVet.js → nested-path-selector-content-Ct80kFX-.js} +1 -1
  69. package/dist/{nested-path-selector-content-CvV4iQ6y.cjs → nested-path-selector-content-DhNCvKp3.cjs} +1 -1
  70. package/dist/{no-language-page-content-SqCm12wz.js → no-language-page-content-CGyfOtV3.js} +4 -4
  71. package/dist/{no-language-page-content-DX7R8GnY.cjs → no-language-page-content-DMxN5AZK.cjs} +1 -1
  72. package/dist/{no-language-page-dialog-BqVCx1Ow.cjs → no-language-page-dialog-5I_REfoR.cjs} +1 -1
  73. package/dist/{no-language-page-dialog-s43OupLf.js → no-language-page-dialog-DJXWLTYK.js} +2 -2
  74. package/dist/{page-creator-6A0cANfE.cjs → page-creator-CGOumc-z.cjs} +1 -1
  75. package/dist/{page-creator-hKMxWP7u.js → page-creator-IQs478pG.js} +3 -3
  76. package/dist/{page-lock-CDP4IhJN.cjs → page-lock-CLZ_Oj1q.cjs} +1 -1
  77. package/dist/{page-lock-CSRmpKr0.js → page-lock-Dx3unkMc.js} +2 -2
  78. package/dist/{page-locked-dialog-Js9XDigU.js → page-locked-dialog-C_JgymA0.js} +15 -15
  79. package/dist/{page-locked-dialog-BOAalIT3.cjs → page-locked-dialog-fTJsy11q.cjs} +1 -1
  80. package/dist/{page-manager-new-BvVol7j6.js → page-manager-new-Cdt2NoSS.js} +29 -29
  81. package/dist/{page-manager-new-DhK74o43.cjs → page-manager-new-yyjdahAJ.cjs} +1 -1
  82. package/dist/{page-manager-search-and-filter-CGZnfZIg.cjs → page-manager-search-and-filter-BQ6yd7_7.cjs} +1 -1
  83. package/dist/{page-manager-search-and-filter-D7aoAp1N.js → page-manager-search-and-filter-kF_V1Kw5.js} +26 -26
  84. package/dist/{page-revisions-content-zatAssu9.js → page-revisions-content-Cf1Cn0wo.js} +24 -24
  85. package/dist/{page-revisions-content-BP1wghI_.cjs → page-revisions-content-DfDZS2ME.cjs} +1 -1
  86. package/dist/pages.cjs +1 -1
  87. package/dist/pages.d.ts +2 -0
  88. package/dist/pages.js +24 -23
  89. package/dist/{publish-pages-content-BvWEkJis.js → publish-pages-content-BLXYr2sJ.js} +23 -23
  90. package/dist/{publish-pages-content-BCkzDZSc.cjs → publish-pages-content-BYPD6vxL.cjs} +1 -1
  91. package/dist/render.cjs +1 -1
  92. package/dist/render.js +2 -2
  93. package/dist/{rte-widget-modal-CQazv0bz.cjs → rte-widget-modal-BwE5wIZa.cjs} +1 -1
  94. package/dist/{rte-widget-modal-D0YHscUT.js → rte-widget-modal-Tj_pS3ql.js} +1 -1
  95. package/dist/{save-to-lib-BBvjMM3Z.cjs → save-to-lib-BZvVC0bb.cjs} +1 -1
  96. package/dist/{save-to-lib-CnKWpb9U.js → save-to-lib-DGONzxBC.js} +62 -62
  97. package/dist/{selected-block-display-BdWPYwVr.js → selected-block-display-CoWqh7BT.js} +11 -11
  98. package/dist/{selected-block-display-D9bDLuNV.cjs → selected-block-display-D1p8khWb.cjs} +1 -1
  99. package/dist/{seo-panel-C2NUYfBh.js → seo-panel-C5_war2g.js} +25 -25
  100. package/dist/{seo-panel-BxN785dG.cjs → seo-panel-DTxo0HRg.cjs} +1 -1
  101. package/dist/{shared-json-ld-DUBQa4Td.js → shared-json-ld-CDQKtky3.js} +46 -46
  102. package/dist/{shared-json-ld-Wgwndrv1.cjs → shared-json-ld-CgF2Si7b.cjs} +1 -1
  103. package/dist/{slug-input-BwWsAZWy.cjs → slug-input-BvIplRdd.cjs} +1 -1
  104. package/dist/{slug-input-Dpgn_HRd.js → slug-input-P-CLfUrw.js} +1 -1
  105. package/dist/supabase-actions.cjs +1 -1
  106. package/dist/supabase-actions.js +1 -1
  107. package/dist/{take-over-request-477jyIub.cjs → take-over-request-BDHFsfIR.cjs} +1 -1
  108. package/dist/{take-over-request-Cla8KuMu.js → take-over-request-mIiTaYST.js} +5 -5
  109. package/dist/{translation-warning-modal-CiXMjMs-.cjs → translation-warning-modal-Bc2i-0YG.cjs} +1 -1
  110. package/dist/{translation-warning-modal-Blylw0Uc.js → translation-warning-modal-BdkToZwn.js} +1 -1
  111. package/dist/{unmark-as-template-Co-3oGGQ.cjs → unmark-as-template-Bf9f4L0-.cjs} +1 -1
  112. package/dist/{unmark-as-template-TjtqlqKG.js → unmark-as-template-D1o7Vm_F.js} +2 -2
  113. package/dist/{unpublish-page-VTYcfZO9.js → unpublish-page-BWnyAdo3.js} +2 -2
  114. package/dist/{unpublish-page-C4v2-E5K.cjs → unpublish-page-YPMIqjta.cjs} +1 -1
  115. package/dist/{unpublished-partials-modal-D1HuPwGr.cjs → unpublished-partials-modal-i1oOnrgA.cjs} +1 -1
  116. package/dist/{unpublished-partials-modal-D6rkb_MK.js → unpublished-partials-modal-p_0N6V23.js} +1 -1
  117. package/dist/{web-preview-DjkWh678.js → web-preview-DN7QMzca.js} +1 -1
  118. package/dist/{web-preview-DNCFZBu2.cjs → web-preview-gmOwlKZr.cjs} +1 -1
  119. package/package.json +1 -1
  120. package/dist/ai-panel-content-C39F2hj1.cjs +0 -1
  121. package/dist/ai-panel-content-tDE696c-.js +0 -62
  122. package/dist/ai-prompt-input-Dcekb4u6.js +0 -652
  123. package/dist/ai-prompt-input-V0noWeHd.cjs +0 -1
  124. package/dist/apply-binding-BuwI_Uf5.cjs +0 -41
  125. package/dist/index-tI1JCogc.cjs +0 -5
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),g=require("./register-chai-top-bar-DyW9GPzV.cjs"),N=require("./index-ZaKz5cWo.cjs"),W=require("class-variance-authority"),y=require("lucide-react"),te=require("nanoid"),c=require("react"),se=require("react-i18next"),R=require("./models-5gOsRC56.cjs");function ne({className:t,...s}){return e.jsx("div",{"data-slot":"input-group",role:"group",className:g.cn("group/input-group shadow-xs relative flex w-full items-center rounded-md border border-input outline-none transition-[color,box-shadow] dark:bg-input/30","h-9 has-[>textarea]:h-auto","has-[>[data-align=inline-start]]:[&>input]:pl-2","has-[>[data-align=inline-end]]:[&>input]:pr-2","has-[>[data-align=block-start]]:h-auto has-[>[data-align=block-start]]:flex-col has-[>[data-align=block-start]]:[&>input]:pb-3","has-[>[data-align=block-end]]:h-auto has-[>[data-align=block-end]]:flex-col has-[>[data-align=block-end]]:[&>input]:pt-3","has-[[data-slot=input-group-control]:focus-visible]:ring-1 has-[[data-slot=input-group-control]:focus-visible]:ring-ring","has-[[data-slot][aria-invalid=true]]:border-destructive has-[[data-slot][aria-invalid=true]]:ring-destructive/20 dark:has-[[data-slot][aria-invalid=true]]:ring-destructive/40",t),...s})}const re=W.cva("text-muted-foreground flex h-auto cursor-text select-none items-center justify-center gap-2 py-1.5 text-sm font-medium group-data-[disabled=true]/input-group:opacity-50 [&>kbd]:rounded-[calc(var(--radius)-5px)] [&>svg:not([class*='size-'])]:size-4",{variants:{align:{"inline-start":"order-first pl-3 has-[>button]:ml-[-0.45rem] has-[>kbd]:ml-[-0.35rem]","inline-end":"order-last pr-3 has-[>button]:mr-[-0.4rem] has-[>kbd]:mr-[-0.35rem]","block-start":"[.border-b]:pb-3 order-first w-full justify-start px-3 pt-3 group-has-[>input]/input-group:pt-2.5","block-end":"[.border-t]:pt-3 order-last w-full justify-start px-3 pb-3 group-has-[>input]/input-group:pb-2.5"}},defaultVariants:{align:"inline-start"}});function H({className:t,align:s="inline-start",...o}){return e.jsx("div",{role:"group","data-slot":"input-group-addon","data-align":s,className:g.cn(re({align:s}),t),onClick:l=>{var i,m;l.target.closest("button")||(m=(i=l.currentTarget.parentElement)==null?void 0:i.querySelector("input"))==null||m.focus()},...o})}const ae=W.cva("flex items-center gap-2 text-sm shadow-none",{variants:{size:{xs:"h-6 gap-1 rounded-[calc(var(--radius)-5px)] px-2 has-[>svg]:px-2 [&>svg:not([class*='size-'])]:size-3.5",sm:"h-8 gap-1.5 rounded-md px-2.5 has-[>svg]:px-2.5","icon-xs":"size-6 rounded-[calc(var(--radius)-5px)] p-0 has-[>svg]:p-0","icon-sm":"size-8 p-0 has-[>svg]:p-0"}},defaultVariants:{size:"xs"}});function K({className:t,type:s="button",variant:o="ghost",size:l="xs",...i}){return e.jsx(g.Button,{type:s,"data-size":l,variant:o,className:g.cn(ae({size:l}),t),...i})}function oe({className:t,...s}){return e.jsx(N.Textarea,{"data-slot":"input-group-control",className:g.cn("flex-1 resize-none rounded-none border-0 bg-transparent py-3 shadow-none focus-visible:ring-0 dark:bg-transparent",t),...s})}const ie=c.createContext(null),ce=c.createContext(null),X=()=>c.useContext(ie),le=()=>c.useContext(ce),$=c.createContext(null),q=()=>{const t=le(),s=c.useContext($),o=t??s;if(!o)throw new Error("usePromptInputAttachments must be used within a PromptInput or PromptInputProvider");return o};function ue({data:t,className:s,...o}){var h;const l=q(),i=t.filename||"",d=((h=t.mediaType)!=null&&h.startsWith("image/")&&t.url?"image":"file")==="image",v=i||(d?"Image":"Attachment");return e.jsxs(Ie,{children:[e.jsx(N.HoverCardTrigger,{asChild:!0,children:e.jsxs("div",{className:g.cn("group relative flex h-8 cursor-default select-none items-center gap-1.5 rounded-md border border-border px-1.5 text-sm font-medium transition-all hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50",s),...o,children:[e.jsxs("div",{className:"relative size-5 shrink-0",children:[e.jsx("div",{className:"absolute inset-0 flex size-5 items-center justify-center overflow-hidden rounded bg-background transition-opacity group-hover:opacity-0",children:d?e.jsx("img",{alt:i||"attachment",className:"size-5 object-cover",height:20,src:t.url,width:20}):e.jsx("div",{className:"flex size-5 items-center justify-center text-muted-foreground",children:e.jsx(y.PaperclipIcon,{className:"size-3"})})}),e.jsxs(g.Button,{"aria-label":"Remove attachment",className:"absolute inset-0 size-5 cursor-pointer rounded p-0 opacity-0 transition-opacity group-hover:pointer-events-auto group-hover:opacity-100 [&>svg]:size-2.5",onClick:S=>{S.stopPropagation(),l.remove(t.id)},type:"button",variant:"ghost",children:[e.jsx(y.XIcon,{}),e.jsx("span",{className:"sr-only",children:"Remove"})]})]}),e.jsx("span",{className:"flex-1 truncate",children:v})]},t.id)}),e.jsx(ye,{className:"w-auto p-2",children:e.jsxs("div",{className:"w-auto space-y-3",children:[d&&e.jsx("div",{className:"flex max-h-96 w-96 items-center justify-center overflow-hidden rounded-md border",children:e.jsx("img",{alt:i||"attachment preview",className:"max-h-full max-w-full object-contain",height:384,src:t.url,width:448})}),e.jsx("div",{className:"flex items-center gap-2.5",children:e.jsxs("div",{className:"min-w-0 flex-1 space-y-1 px-0.5",children:[e.jsx("h4",{className:"truncate text-sm font-semibold leading-none",children:i||(d?"Image":"Attachment")}),t.mediaType&&e.jsx("p",{className:"truncate font-mono text-xs text-muted-foreground",children:t.mediaType})]})})]})})]})}function de({children:t,className:s,...o}){const l=q();return l.files.length?e.jsx("div",{className:g.cn("flex flex-wrap items-center gap-2 p-3",s),...o,children:l.files.map(i=>e.jsx(c.Fragment,{children:t(i)},i.id))}):null}const pe=({label:t="Add photos or files",...s})=>{const o=q();return e.jsxs(N.DropdownMenuItem,{...s,onSelect:l=>{l.preventDefault(),o.openFileDialog()},children:[e.jsx(y.ImageIcon,{className:"mr-2 size-4"})," ",t]})},me=({className:t,accept:s,multiple:o,globalDrop:l,syncHiddenInput:i,maxFiles:m,maxFileSize:d,onError:v,onSubmit:h,children:S,...P})=>{const n=X(),a=!!n,p=c.useRef(null),D=c.useRef(null),I=c.useRef(null);c.useEffect(()=>{var j;const r=(j=D.current)==null?void 0:j.closest("form");r instanceof HTMLFormElement&&(I.current=r)},[]);const[k,z]=c.useState([]),x=a?n.attachments.files:k,C=c.useCallback(()=>{var r;(r=p.current)==null||r.click()},[]),M=c.useCallback(r=>!s||s.trim()===""?!0:s.includes("image/*")?r.type.startsWith("image/"):!0,[s]),U=c.useCallback(r=>{const j=Array.from(r),f=j.filter(w=>M(w));if(j.length&&f.length===0){v==null||v({code:"accept",message:"No files match the accepted types."});return}const u=w=>d?w.size<=d:!0,b=f.filter(u);if(f.length>0&&b.length===0){v==null||v({code:"max_file_size",message:"All files exceed the maximum size."});return}z(w=>{const A=typeof m=="number"?Math.max(0,m-w.length):void 0,ee=typeof A=="number"?b.slice(0,A):b;typeof A=="number"&&b.length>A&&(v==null||v({code:"max_files",message:"Too many files. Some were not added."}));const V=[];for(const E of ee)V.push({id:te.nanoid(),type:"file",url:URL.createObjectURL(E),mediaType:E.type,filename:E.name});return w.concat(V)})},[M,m,d,v]),T=a?r=>n.attachments.add(r):U,L=a?r=>n.attachments.remove(r):r=>z(j=>{const f=j.find(u=>u.id===r);return f!=null&&f.url&&URL.revokeObjectURL(f.url),j.filter(u=>u.id!==r)}),O=a?()=>n.attachments.clear():()=>z(r=>{for(const j of r)j.url&&URL.revokeObjectURL(j.url);return[]}),B=a?()=>n.attachments.openFileDialog():C;c.useEffect(()=>{a&&n.__registerFileInput(p,()=>{var r;return(r=p.current)==null?void 0:r.click()})},[a,n]),c.useEffect(()=>{i&&p.current&&x.length===0&&(p.current.value="")},[x,i]),c.useEffect(()=>{const r=I.current;if(!r)return;const j=u=>{var b,w;(w=(b=u.dataTransfer)==null?void 0:b.types)!=null&&w.includes("Files")&&u.preventDefault()},f=u=>{var b,w,A;(w=(b=u.dataTransfer)==null?void 0:b.types)!=null&&w.includes("Files")&&u.preventDefault(),(A=u.dataTransfer)!=null&&A.files&&u.dataTransfer.files.length>0&&T(u.dataTransfer.files)};return r.addEventListener("dragover",j),r.addEventListener("drop",f),()=>{r.removeEventListener("dragover",j),r.removeEventListener("drop",f)}},[T]),c.useEffect(()=>{if(!l)return;const r=f=>{var u,b;(b=(u=f.dataTransfer)==null?void 0:u.types)!=null&&b.includes("Files")&&f.preventDefault()},j=f=>{var u,b,w;(b=(u=f.dataTransfer)==null?void 0:u.types)!=null&&b.includes("Files")&&f.preventDefault(),(w=f.dataTransfer)!=null&&w.files&&f.dataTransfer.files.length>0&&T(f.dataTransfer.files)};return document.addEventListener("dragover",r),document.addEventListener("drop",j),()=>{document.removeEventListener("dragover",r),document.removeEventListener("drop",j)}},[T,l]),c.useEffect(()=>()=>{if(!a)for(const r of x)r.url&&URL.revokeObjectURL(r.url)},[a,x]);const Y=r=>{r.currentTarget.files&&T(r.currentTarget.files)},J=async r=>{const f=await(await fetch(r)).blob();return new Promise((u,b)=>{const w=new FileReader;w.onloadend=()=>u(w.result),w.onerror=b,w.readAsDataURL(f)})},Q=c.useMemo(()=>({files:x.map(r=>({...r,id:r.id})),add:T,remove:L,clear:O,openFileDialog:B,fileInputRef:p}),[x,T,L,O,B]),Z=r=>{r.preventDefault();const j=r.currentTarget,f=a?n.textInput.value:new FormData(j).get("message")||"";a||j.reset(),Promise.all(x.map(async({...u})=>u.url&&u.url.startsWith("blob:")?{...u,url:await J(u.url)}:u)).then(u=>{try{const b=h({text:f,files:u},r);b instanceof Promise?b.then(()=>{O(),a&&n.textInput.clear()}).catch(()=>{}):(O(),a&&n.textInput.clear())}catch{}})},G=e.jsxs(e.Fragment,{children:[e.jsx("span",{"aria-hidden":"true",className:"hidden",ref:D}),e.jsx("input",{accept:s,"aria-label":"Upload files",className:"hidden",multiple:o,onChange:Y,ref:p,title:"Upload files",type:"file"}),e.jsx("form",{className:g.cn("w-full",t),onSubmit:Z,...P,children:e.jsx(ne,{className:"overflow-hidden",children:S})})]});return a?G:e.jsx($.Provider,{value:Q,children:G})},fe=({onChange:t,className:s,placeholder:o="What would you like to know?",...l})=>{const i=X(),m=q(),[d,v]=c.useState(!1),h=n=>{if(n.key==="Enter"){if(d||n.nativeEvent.isComposing||n.shiftKey)return;n.preventDefault();const a=n.currentTarget.form,p=a==null?void 0:a.querySelector('button[type="submit"]');if(p!=null&&p.disabled)return;a==null||a.requestSubmit()}if(n.key==="Backspace"&&n.currentTarget.value===""&&m.files.length>0){n.preventDefault();const a=m.files.at(-1);a&&m.remove(a.id)}},S=n=>{var D;const a=(D=n.clipboardData)==null?void 0:D.items;if(!a)return;const p=[];for(const I of a)if(I.kind==="file"){const k=I.getAsFile();k&&p.push(k)}p.length>0&&(n.preventDefault(),m.add(p))},P=i?{value:i.textInput.value,onChange:n=>{i.textInput.setInput(n.currentTarget.value),t==null||t(n)}}:{onChange:t};return e.jsx(oe,{className:g.cn("field-sizing-content max-h-48 min-h-16",s),name:"message",onCompositionEnd:()=>v(!1),onCompositionStart:()=>v(!0),onKeyDown:h,onPaste:S,placeholder:o,...l,...P})},he=({className:t,...s})=>e.jsx(H,{align:"block-end",className:g.cn("order-first flex-wrap gap-1",t),...s}),xe=({className:t,...s})=>e.jsx(H,{align:"block-end",className:g.cn("justify-between gap-1",t),...s}),ge=({className:t,...s})=>e.jsx("div",{className:g.cn("flex items-center gap-1",t),...s}),F=({variant:t="ghost",className:s,size:o,...l})=>{const i=o??(c.Children.count(l.children)>1?"sm":"icon-sm");return e.jsx(K,{className:g.cn(s),size:i,type:"button",variant:t,...l})},ve=t=>e.jsx(N.DropdownMenu,{...t}),je=({className:t,children:s,...o})=>e.jsx(N.DropdownMenuTrigger,{asChild:!0,children:e.jsx(F,{className:t,...o,children:s??e.jsx(y.PlusIcon,{className:"size-4"})})}),be=({className:t,...s})=>e.jsx(N.DropdownMenuContent,{align:"start",className:g.cn(t),...s}),we=({className:t,variant:s="default",size:o="icon-sm",status:l,children:i,...m})=>{let d=e.jsx(y.CornerDownLeftIcon,{className:"size-4"});return l==="submitted"?d=e.jsx(y.Loader2Icon,{className:"size-4 animate-spin"}):l==="streaming"?d=e.jsx(y.SquareIcon,{className:"size-4"}):l==="error"&&(d=e.jsx(y.XIcon,{className:"size-4"})),e.jsx(K,{"aria-label":"Submit",className:g.cn(t),size:o,type:"submit",variant:s,...m,children:i??d})},Ne=({className:t,textareaRef:s,onTranscriptionChange:o,...l})=>{const[i,m]=c.useState(!1),[d,v]=c.useState(null),h=c.useRef(null);c.useEffect(()=>{if(typeof window<"u"&&("SpeechRecognition"in window||"webkitSpeechRecognition"in window)){const P=window.SpeechRecognition||window.webkitSpeechRecognition,n=new P;n.continuous=!0,n.interimResults=!0,n.lang="en-US",n.onstart=()=>{m(!0)},n.onend=()=>{m(!1)},n.onresult=a=>{var D;let p="";for(let I=a.resultIndex;I<a.results.length;I++){const k=a.results[I];k.isFinal&&(p+=((D=k[0])==null?void 0:D.transcript)??"")}if(p&&(s!=null&&s.current)){const I=s.current,k=I.value,z=k+(k?" ":"")+p;I.value=z,I.dispatchEvent(new Event("input",{bubbles:!0})),o==null||o(z)}},n.onerror=a=>{console.error("Speech recognition error:",a.error),m(!1)},h.current=n,c.startTransition(()=>v(n))}return()=>{h.current&&h.current.stop()}},[s,o]);const S=c.useCallback(()=>{d&&(i?d.stop():d.start())},[d,i]);return e.jsx(F,{className:g.cn("relative transition-all duration-200",i&&"animate-pulse bg-accent text-accent-foreground",t),disabled:!d,onClick:S,...l,children:e.jsx(y.MicIcon,{className:"size-4"})})},Ie=({openDelay:t=0,closeDelay:s=0,...o})=>e.jsx(N.HoverCard,{closeDelay:s,openDelay:t,...o}),ye=({align:t="start",...s})=>e.jsx(N.HoverCardContent,{align:t,...s}),Se=t=>e.jsx(N.Dialog,{...t}),ke=t=>e.jsx(N.DialogTrigger,{...t}),De=({className:t,children:s,title:o="Model Selector",...l})=>e.jsxs(N.DialogContent,{className:g.cn("p-0",t),...l,children:[e.jsx(N.DialogTitle,{className:"sr-only",children:o}),e.jsx(N.Command,{className:"**:data-[slot=command-input-wrapper]:h-auto",children:s})]}),Pe=({className:t,...s})=>e.jsx(N.CommandInput,{className:g.cn("h-auto py-3.5",t),...s}),Te=t=>e.jsx(N.CommandList,{...t}),ze=t=>e.jsx(N.CommandGroup,{...t}),Ce=t=>e.jsx(N.CommandItem,{...t}),Ae=({provider:t,className:s,...o})=>e.jsx("img",{...o,alt:`${t} logo`,className:g.cn("size-3 dark:invert",s),height:12,src:`https://models.dev/logos/${t}.svg`,width:12}),Le=({className:t,...s})=>e.jsx("span",{className:g.cn("flex-1 truncate text-left",t),...s}),Re=({selectedModel:t,onModelChange:s,disabled:o=!1})=>{const[l,i]=c.useState(!1),[m,d]=c.useState(""),v=R.getModelById(t)||R.getDefaultModel(),S=R.AI_MODELS.filter(n=>n.name.toLowerCase().includes(m.toLowerCase())||n.provider.toLowerCase().includes(m.toLowerCase())).reduce((n,a)=>(n[a.provider]||(n[a.provider]=[]),n[a.provider].push(a),n),{}),P=n=>{s(n),i(!1),d("")};return e.jsxs(Se,{open:l,onOpenChange:i,children:[e.jsx(ke,{asChild:!0,children:e.jsxs(g.Button,{variant:"outline",size:"sm",disabled:o,className:"h-8 gap-1 px-2 text-xs",children:[e.jsx(y.Cpu,{size:14}),e.jsx("span",{className:"max-w-20 truncate",children:v.name})]})}),e.jsxs(De,{className:"w-96 p-0",children:[e.jsx(Pe,{placeholder:"Search models...",value:m,onValueChange:d}),e.jsx(Te,{children:Object.entries(S).map(([n,a])=>e.jsx(ze,{heading:n.charAt(0).toUpperCase()+n.slice(1),children:a.map(p=>e.jsxs(Ce,{value:p.id,onSelect:()=>P(p.id),className:"flex cursor-pointer items-center gap-2 p-2",children:[e.jsx(Ae,{provider:p.provider}),e.jsxs("div",{className:"flex flex-1 flex-col",children:[e.jsx(Le,{children:p.name}),e.jsx("span",{className:"text-xs text-muted-foreground",children:p.description})]}),t===p.id&&e.jsx("div",{className:"h-2 w-2 rounded-full bg-blue-500"})]},p.id))},n))})]})]})},_="chai-ai-selected-model",Me=({input:t,setInput:s,onSend:o,onStop:l,isLoading:i,disabled:m,selectedLang:d,selectedModel:v=R.getDefaultModel().id,onModelChange:h})=>{const{t:S}=se.useTranslation(),[P,n]=c.useState(v),[a,p]=c.useState(null),D=c.useRef(null),[I,k]=c.useState(!1);c.useEffect(()=>{if(!d){const x=localStorage.getItem(_);if(x)n(x),h==null||h(x);else{const C=R.getDefaultModel().id;n(C),h==null||h(C)}}},[d,h]);const z=x=>{var U;const C=x.files.find(T=>{var L;return(L=T.mediaType)==null?void 0:L.startsWith("image/")}),M=(C==null?void 0:C.url)||a;o((U=x.text)==null?void 0:U.trim(),void 0,M,P),p(null)};return e.jsx("div",{className:"relative",children:e.jsx("div",{className:"border-gray-20 rounded-lg border",children:e.jsxs(me,{onSubmit:z,accept:"image/*",className:"flex h-auto w-full flex-col",children:[e.jsx(he,{className:"p-0",children:e.jsx(de,{className:"pb-0",children:x=>e.jsx(ue,{className:"text-xs",data:x})})}),e.jsx(fe,{ref:D,value:t,onChange:x=>s(x.target.value),placeholder:S(d?"Ask to update content":"Ask me anything..."),disabled:i,className:"max-h-[200px] min-h-[60px] w-full",rows:3}),e.jsxs(xe,{children:[d?e.jsx("div",{}):e.jsxs(ge,{children:[e.jsxs(ve,{children:[e.jsx(je,{disabled:i,children:e.jsx(y.Paperclip,{size:16})}),e.jsx(be,{children:e.jsx(pe,{})})]}),e.jsx(Ne,{textareaRef:D,onTranscriptionChange:s,disabled:i}),e.jsx(Re,{selectedModel:P,onModelChange:x=>{n(x),h==null||h(x),localStorage.setItem(_,x)},disabled:i}),e.jsxs(F,{className:"hidden",size:"sm",onClick:()=>k(!I),variant:I?"default":"ghost",children:[e.jsx(y.GlobeIcon,{size:16}),e.jsx("span",{children:"Search"})]})]}),i?e.jsx("button",{onClick:l,className:"z-50 flex items-center gap-x-1 rounded-md bg-red-500 p-1.5 text-white transition-colors hover:bg-red-600",title:S("Stop generation"),children:e.jsx(y.Square,{size:16})}):e.jsx(we,{disabled:!t.trim()||m,children:e.jsx(y.Send,{size:16})})]})]})})})};exports.default=Me;
@@ -1,41 +0,0 @@
1
- "use strict";var ut=Object.defineProperty;var pt=(t,s,e)=>s in t?ut(t,s,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[s]=e;var _=(t,s,e)=>pt(t,typeof s!="symbol"?s+"":s,e);const k=require("./STRINGS-FNnfjF5H.cjs"),N=require("./common-functions-B3a4xKt_.cjs"),a=require("lodash-es"),$=require("himalaya"),z=require("./core-czmLeR0h.cjs"),dt=require("tailwind-merge"),X=t=>{if(t=t.replace(k.STYLES_KEY,""),!t)return{baseClasses:"",classes:""};const s=t.split(/,(?![^\[]*\])/);if(s.length===1)return{baseClasses:"",classes:s[0].trim()};const[e,...n]=s;return{baseClasses:e.trim(),classes:n.join(",").trim().replace(/ +(?= )/g,"")}};function ht(t,s,e){const n=a.get(e,"i18nProps",[]);if(a.isEmpty(s)||a.isEmpty(n))return t;const i=a.cloneDeep(t);return a.forEach(a.keys(i),r=>{if(a.includes(n,r)&&!a.isEmpty(s)){const o=a.get(i,r),l=a.get(i,`${r}-${s}`,"");a.isString(o)?i[r]=a.isString(l)&&!a.isEmpty(l.trim())&&l.trimStart()||o:i[r]=a.isEmpty(l)?o:l}}),i}const Z=(t,s)=>{const{baseClasses:e,classes:n}=X(t),r=n.split(" ").filter(l=>l.startsWith(k.DESIGN_TOKEN_PREFIX)).map(l=>{var p;return(p=s[l])==null?void 0:p.value}),o=n.split(" ").filter(l=>!l.startsWith(k.DESIGN_TOKEN_PREFIX)).join(" ");return dt.twMerge.apply(null,[e,...r,o])};function gt(t,s){return a.get(t,`${s}_attrs`,{})}function yt(t,s=!0,e={}){const n={};return Object.keys(t).forEach(i=>{if(a.isString(t[i])&&t[i].startsWith(k.STYLES_KEY)){const r=Z(t[i],e),o=gt(t,i);n[i]={...!a.isEmpty(r)&&{className:r},...o,...s?{"data-style-prop":i,"data-block-parent":t._id,"data-style-id":`${i}-${t._id}`}:{}}}}),n}const ft=a.memoize(t=>{const s=z.getRegisteredChaiBlock(t),e=a.get(s,"schema.properties",{});return Object.fromEntries(Object.entries(e).filter(([,n])=>a.get(n,"runtime",!1)))}),mt=(t,s)=>{if(!a.isArray(t))return t;let e=t,n;return typeof s.limit=="number"&&s.limit>0&&(n=s.limit),n!==void 0&&(e=e.slice(0,n)),e},_t=(t,s)=>{const e=a.cloneDeep(t);return a.forEach(a.keys(e),n=>{if(a.isString(e[n])&&!a.startsWith(n,"_")){let i=e[n];n==="repeaterItems"&&(e.repeaterItemsBinding=i);const r=/\{\{(.*?)\}\}/g,o=i.match(r);o&&o.forEach(l=>{let p=l.slice(2,-2);const c=a.get(s,p,l);i=a.isArray(c)?c:i.replace(l,c)}),e[n]=i}}),e},xt=t=>{const s=/(?:https?:\/\/)?(?:www\.)?(?:youtube\.com\/(?:[^\/\n\s]+\/\S+\/|(?:v|e(?:mbed)?)\/|\S*?[?&]v=)|youtu\.be\/)([a-zA-Z0-9_-]{11})/,e=/(?:https?:\/\/)?(?:www\.)?(player)?.vimeo\.com/;return s.test(t)||e.test(t)},bt=t=>{if(a.isEmpty(t))return t;const s=/<video[^>]+src=['"]([^'">]+)['"]/,e=/<iframe[^>]+src=['"]([^'">]+)['"]/,n=t.match(s),i=t.match(e),r=n?n[1]:i?i[1]:null,o=/(?:https?:\/\/)?(?:www\.)?(?:youtube\.com\/(?:[^\/\n\s]+\/\S+\/|(?:v|e(?:mbed)?)\/|\S*?[?&]v=)|youtu\.be\/)([a-zA-Z0-9_-]{11})/,l=/(?:https?:\/\/)?(?:www\.)?player.vimeo\.com/;return r&&(o.test(r)||l.test(r))?r:t},J=["chai-name","data-chai-name"],kt={img:{alt:"alt",width:"width",height:"height",src:"image"},video:{src:"url",autoplay:"controls.autoPlay",muted:"controls.muted",loop:"controls.loop",controls:"controls.widgets"},a:{href:"link.href",target:"link.target",type:""},input:{placeholder:"placeholder",required:"required",type:"inputType",name:"fieldName"},textarea:{placeholder:"placeholder",required:"required",type:"inputType",name:"fieldName"},select:{placeholder:"placeholder",required:"required",multiple:"multiple",name:"fieldName"},form:{action:"action"}},Tt=(t,s)=>{var e;return((e=t.children)==null?void 0:e.length)===1&&a.includes(["Heading","Paragraph","Span","ListItem","Button","Label","TableCell","Link","RichText"],s._type)},A=t=>t.map(s=>s.type==="text"?a.get(s,"content",""):a.isEmpty(s.children)?"":A(s.children||[])).join(""),D=t=>t===null?"":t,Q=t=>{const s=a.compact(a.map(t.split(/\s+/),a.trim)),e=a.find(s,l=>/^w-/.test(l)),n=a.find(s,l=>/^h-/.test(l));if(!n||!e)return{height:"",width:""};const i=l=>{if(!l)return;const p=l.match(/^[wh]-(?:\[(.*?)\]|(.+))$/);if(!p)return;if(p[1])return p[1];const c=p[2];return/^\d+(\.\d+)?$/.test(c)?`${Number(c)*4}px`:c==="auto"||a.includes(c,"%")?c:"16px"},r=i(e),o=i(n);return{width:a.includes(r,"px")?r:"16px",height:a.includes(o,"px")?o:"16px"}},G=t=>{if(t.tagName==="svg")return{};const s={},e=kt[t.tagName||""]||{},n=t.attributes||[];return a.forEach(n,({key:i,value:r})=>{var o;if(!a.includes(J,i))if(i==="bid"&&(s._bid=D(r)),e[i]){if(t.tagName==="img"&&i==="src"&&!r.startsWith("http")){const l=a.find(t.attributes,{key:"width"}),p=a.find(t.attributes,{key:"height"});l&&p?r=`https://picsum.photos/${l==null?void 0:l.value}x${p==null?void 0:p.value}`:r="https://picsum.photos/150x150"}else if(t.tagName==="a"){const l=a.find(t.attributes,{key:"href"});l&&typeof(l==null?void 0:l.value)=="string"&&((o=l==null?void 0:l.value)!=null&&o.startsWith("pageType:"))&&a.set(s,"link.type","pageType")}a.set(s,e[i],D(r))}else a.includes(["style","class","srcset","bid"],i)||(s.styles_attrs=s.styles_attrs||{},a.startsWith(i,"@")&&(i=i.replace("@","x-on:")),s.styles_attrs[`${i}`]=D(r))}),delete s.class,s},St=(t,s="styles")=>{if(!t.attributes)return{[s]:`${k.STYLES_KEY},`};const e=a.find(t.attributes,{key:"class"});if(e){const n=e.value;return{[s]:`${k.STYLES_KEY},${n}`}}return{[s]:`${k.STYLES_KEY},`}},vt=t=>{const s=a.get(t,"attributes",[]),e=s.find(c=>c.key==="data-chai-richtext"||c.key==="chai-richtext"),n=s.find(c=>c.key==="data-chai-lightbox"||c.key==="chai-lightbox"),i=s.find(c=>c.key==="data-chai-dropdown"||c.key==="chai-dropdown"),r=s.find(c=>c.key==="data-chai-dropdown-button"||c.key==="chai-dropdown-button"),o=s.find(c=>c.key==="data-chai-dropdown-content"||c.key==="chai-dropdown-content"),l=s.find(c=>c.key==="class"),p=l&&l.value.split(/\s+/).includes("rte");if(i)return{_type:"Dropdown"};if(r)return{_type:"DropdownButton"};if(o)return{_type:"DropdownContent"};if(e||p)return{_type:"Paragraph"};if(n)return{_type:"LightBoxLink"};switch(t.tagName){case"img":return{_type:"Image"};case"input":return{_type:"Input",showLabel:!1};case"hr":return{_type:"Divider"};case"br":return{_type:"LineBreak"};case"textarea":return{_type:"TextArea",showLabel:!1};case"audio":return{_type:"Audio"};case"canvas":return{_type:"Canvas"};case"video":case"iframe":return{_type:"CustomHTML"};case"svg":return{_type:"Icon"};case"select":return{_type:"Select",options:[]};case"option":return{_type:"Option"};case"ul":case"ol":case"dl":return{_type:"List",tag:t.tagName,_listType:t.tagName==="ol"?"list-decimal":"list-none"};case"li":case"dt":return{_type:"ListItem",tag:t.tagName};case"span":case"figcaption":case"legend":return{_type:"Span",tag:t.tagName};case"p":return{_type:"Paragraph",content:""};case"a":return{_type:"Link"};case"form":return{_type:"Form"};case"label":return{_type:"Label"};case"button":return{_type:"Button"};case"code":return{_type:"Box",_name:"Code"};case"h1":case"h2":case"h3":case"h4":case"h5":case"h6":return{_type:"Heading",tag:t.tagName};case"table":return{_type:"Table"};case"tr":return{_type:"TableRow"};case"td":case"th":return{_type:"TableCell",tag:t.tagName};case"thead":return{_type:"TableHead"};case"tbody":return{_type:"TableBody"};case"tfoot":return{_type:"TableFooter"};default:{const c=a.get(t,"children",[]).length>0?"Box":"EmptyBox";return{_type:c,tag:t.tagName,_name:c=="EmptyBox"||t.tagName==="div"?c:a.capitalize(t.tagName)}}}},P=(t,s=null)=>a.flatMapDeep(t,e=>{var v,x,S,T,w,Y,M,q,H,O;if(e.type==="comment")return[];let n={_id:N.generateUUID()};if(s&&(n._parent=s.block._id),e.type==="text")return a.isEmpty(a.get(e,"content",""))?[]:s&&Tt(s.node,s.block)?(a.set(s,"block.content",a.get(e,"content","")),[]):{...n,_type:"Text",content:a.get(e,"content","")};if(a.startsWith(e.tagName,"chai-")){const u=e.attributes||[],d=a.find(u,{key:"chai-type"}),g=(d==null?void 0:d.value)||a.startCase(a.camelCase(e.tagName||"")).replace(/ /g,"").replace(/\s+/g,"");n._type=g,a.forEach(u,({key:b,value:V})=>{if(b==="about-this-component"||b==="chai-type"||b==="can-move"||b==="can-delete")return;if(b==="id"){n._id=V;return}const ct=a.startsWith(b,"_")?b:a.camelCase(b);let B=D(V);typeof B=="string"&&a.startsWith(B,"#styles:")&&(B=B.replace("#styles:","#styles:,")),n[ct]=B});const m=P(e.children||[],{block:n,node:e});return[n,...m]}const i=a.get(e,"attributes",[]),r=e.tagName==="p"||i.find(u=>u.key==="data-chai-richtext"||u.key==="chai-richtext"),o=i.find(u=>u.key==="class"),l=o&&o.value.split(/\s+/).includes("rte"),p=i.find(u=>u.key==="data-chai-lightbox"||u.key==="chai-lightbox"),c=i.find(u=>u.key==="data-chai-dropdown"||u.key==="chai-dropdown"),f=i.find(u=>u.key==="data-chai-dropdown-button"||u.key==="chai-dropdown-button"),h=i.find(u=>u.key==="data-chai-dropdown-content"||u.key==="chai-dropdown-content");if(n={...n,...vt(e),...G(e),...St(e)},e.attributes){const u=e.attributes.find(d=>a.includes(J,d.key));u&&(n._name=u.value)}if(r||l)return n.content=`<p>${$.stringify(e.children||[])}</p>`,a.has(n,"styles_attrs.data-chai-richtext")&&delete n.styles_attrs["data-chai-richtext"],a.has(n,"styles_attrs.chai-richtext")&&delete n.styles_attrs["chai-richtext"],[n];if(p){const u=["data-chai-lightbox","chai-lightbox","data-vbtype","data-autoplay","data-maxwidth","data-overlay","data-gall","href"];n={...n,href:((v=i.find(d=>d.key==="href"))==null?void 0:v.value)||"",hrefType:((x=i.find(d=>d.key==="data-vbtype"))==null?void 0:x.value)||"video",autoplay:((S=i.find(d=>d.key==="data-autoplay"))==null?void 0:S.value)==="true"?"true":"false",maxWidth:((w=(T=i.find(d=>d.key==="data-maxwidth"))==null?void 0:T.value)==null?void 0:w.replace("px",""))||"",backdropColor:((Y=i.find(d=>d.key==="data-overlay"))==null?void 0:Y.value)||"",galleryName:((M=i.find(d=>d.key==="data-gall"))==null?void 0:M.value)||""},a.forEach(u,d=>{a.has(n,`styles_attrs.${d}`)&&delete n.styles_attrs[d]})}if(c&&(delete n.styles_attrs,n.showDropdown=!1),h&&delete n.styles_attrs,f){delete n.styles_attrs;const u=a.filter(e.children||[],g=>(g==null?void 0:g.tagName)!=="span");n.content=A(u);const d=a.find(e.children||[],g=>(g==null?void 0:g.tagName)==="span"&&a.some(g.children||[],m=>(m==null?void 0:m.tagName)==="svg"));if(d){const g=a.find(d.children||[],m=>(m==null?void 0:m.tagName)==="svg");if(g){n.icon=$.stringify([g]);const{height:m,width:b}=wt(g,"16px","16px");n.iconHeight=m,n.iconWidth=b}}return[n]}if(n._type==="Input"){const u=n.inputType||"text";u==="checkbox"?a.set(n,"_type","Checkbox"):u==="radio"&&a.set(n,"_type","Radio")}else if(e.tagName==="video"||e.tagName==="iframe"){const u=$.stringify([e]);return xt(u)&&(a.set(n,"_type","Video"),a.set(n,"url",bt(u)),a.set(n,"styles",`${k.STYLES_KEY},`),a.set(n,"controls",{autoPlay:!1,muted:!0,loop:!1,controls:!1})),n.content=u,[n]}else if(e.tagName==="svg"){const u=a.get(a.find(e.attributes,{key:"class"}),"value",""),{height:d,width:g}=Q(u);if(d&&g)n.styles=`${k.STYLES_KEY}, ${N.cn(`w-${g} h-${d}`,u)}`.trim(),n.height=d==null?void 0:d.replace("px",""),n.width=g==null?void 0:g.replace("px","");else{const m=(q=a.find(e.attributes,{key:"height"}))==null?void 0:q.value,b=(H=a.find(e.attributes,{key:"width"}))==null?void 0:H.value;m&&b?(n.styles=`${k.STYLES_KEY}, ${N.cn(`w-[${b}px] h-[${m}px]`,u)}`.trim(),n.height=m,n.width=b):n.styles=`${k.STYLES_KEY}, ${N.cn("w-full h-full",u)}`.trim()}return e.attributes=a.filter(e.attributes,m=>!a.includes(["style","width","height","class"],m.key)),n.icon=$.stringify([e]),[n]}else if(e.tagName=="option"&&s&&((O=s.block)==null?void 0:O._type)==="Select")return s.block.options.push({label:A(e.children||[]),...G(e)}),[];const y=P(e.children||[],{block:n,node:e});return[n,...y]}),wt=(t,s,e)=>{var p,c;const n=a.get(t,"attributes",[]),{height:i,width:r}=Q(a.get(a.find(n,{key:"class"}),"value",""));if(i&&r)return{height:`[${i}px]`,width:`[${r}px]`};const o=(p=a.find(n,{key:"height"}))==null?void 0:p.value,l=(c=a.find(n,{key:"width"}))==null?void 0:c.value;return{height:o?`[${o}px]`:e,width:l?`[${l}px]`:s}},Bt=t=>{t=t.replace(/(\w+)=\\?"(.*?)\\?"/g,(n,i,r)=>{let o=r.replace(/\\"/g,'"');return o=o.replace(/{([^}]+)}/g,l=>l.replace(/"/g,'\\"')),`${i}="${o.replace(/\\"/g,'"')}"`}),t=t.replace(/\\n/g," ").replace(/\\\\/g,"").replace(/\\([/<>])/g,"$1").replace(/\\./g,"").replace(/[\n\r\t\f\v]/g," "),t=t.replace(/\$name="[^"]*"/g,"");const s=t.match(/<body[^>]*>[\s\S]*?<\/body>/);return(s&&s.length>0?s[0].replace(/<body/,"<div").replace(/<\/body>/,"</div>"):t).replace(/\s+/g," ").replaceAll("> <","><").replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,"").trim()},Et=(t,s)=>a.find(t,{_id:s}),$t=(t,s)=>a.isEmpty(s)?t.map(e=>(a.unset(e,"_bid"),e)):a.map(t,e=>{const n=a.isEmpty(e._bid)?void 0:Et(s,e._bid);if(n){n._type==="Icon"&&a.get(e,"icon","").match(/chai-default-svg/)&&delete e.icon;const i={...n,...e};return a.unset(i,"_bid"),i}return a.unset(e,"_bid"),e}),Nt=t=>{const s=$.parse(Bt(t));if(a.isEmpty(t))return[];const e=a.flatten(P(s));return z.syncBlocksWithDefaultProps(e)},It=(t,s)=>t.map(e=>{const n=a.keys(e).filter(i=>a.isString(e[i])&&e[i].startsWith(k.STYLES_KEY));return a.each(n,i=>{e[i]=`${k.STYLES_KEY},${Z(e[i],s)}`}),e}),Ct=t=>{const s=a.last(t);return t.map(e=>{const n=Object.keys(e);for(let i=0;i<n.length;i++)if(a.isString(e[n[i]])&&a.startsWith(n[i],"content")){const r=e===s?"":" ";e[n[i]]=`${e[n[i]].trim()}${r}`}return e})};var j=class extends Error{constructor(t){super(t),this.name="Eta Error"}},tt=class extends j{constructor(t){super(t),this.name="EtaParser Error"}},Lt=class extends j{constructor(t){super(t),this.name="EtaRuntime Error"}},Wt=class extends j{constructor(t){super(t),this.name="EtaNameResolution Error"}};function E(t,s,e){let n=s.slice(0,e).split(/\n/),i=n.length,r=n[i-1].length+1;throw t+=" at line "+i+" col "+r+`:
2
-
3
- `+s.split(/\n/)[i-1]+`
4
- `+Array(r).join(" ")+"^",new tt(t)}function Dt(t,s,e,n){let i=s.split(`
5
- `),r=Math.max(e-3,0),o=Math.min(i.length,e+3),l=n,p=i.slice(r,o).map((f,h)=>{let y=h+r+1;return(y===e?" >> ":" ")+y+"| "+f}).join(`
6
- `),c=new Lt((l?l+":"+e+`
7
- `:"line "+e+`
8
- `)+p+`
9
-
10
- `+t.message);throw c.name=t.name,c.cause=t,c}const At=(async()=>{}).constructor;function Pt(t,s){let e=this.config,n=s!=null&&s.async?At:Function;try{return new n(e.varName,"options",this.compileToString.call(this,t,s))}catch(i){throw i instanceof SyntaxError?new tt(`Bad template syntax
11
-
12
- `+i.message+`
13
- `+Array(i.message.length+1).join("=")+`
14
- `+this.compileToString.call(this,t,s)+`
15
- `):i}}function Ft(t,s){let e=this.config,n=s==null?void 0:s.async,i=this.compileBody,r=this.parse.call(this,t),o=`${e.functionHeader}
16
- let include = (__eta_t, __eta_d) => this.render(__eta_t, {...${e.varName}, ...(__eta_d ?? {})}, options);
17
- let includeAsync = (__eta_t, __eta_d) => this.renderAsync(__eta_t, {...${e.varName}, ...(__eta_d ?? {})}, options);
18
-
19
- let __eta = {res: "", e: this.config.escapeFunction, f: this.config.filterFunction${e.debug?', line: 1, templateStr: "'+t.replace(/\\|"/g,"\\$&").replace(/\r\n|\n|\r/g,"\\n")+'"':""}};
20
-
21
- function layout(path, data) {
22
- __eta.layout = path;
23
- __eta.layoutData = data;
24
- }${e.debug?"try {":""}${e.useWith?"with("+e.varName+"||{}){":""}
25
-
26
- function ${e.outputFunctionName}(s){__eta.res+=s;}
27
-
28
- ${i.call(this,r)}
29
- if (__eta.layout) {
30
- __eta.res = ${n?"await includeAsync":"include"} (__eta.layout, {...${e.varName}, body: __eta.res, ...__eta.layoutData});
31
- }
32
- ${e.useWith?"}":""}${e.debug?"} catch (e) { this.RuntimeErr(e, __eta.templateStr, __eta.line, options.filepath) }":""}
33
- return __eta.res;
34
- `;if(e.plugins)for(let l=0;l<e.plugins.length;l++){let p=e.plugins[l];p.processFnString&&(o=p.processFnString(o,e))}return o}function Rt(t){let s=this.config,e=0,n=t.length,i="";for(;e<n;e++){let r=t[e];if(typeof r=="string")i+="__eta.res+='"+r+`';
35
- `;else{let o=r.t,l=r.val||"";s.debug&&(i+="__eta.line="+r.lineNo+`
36
- `),o==="r"?(s.autoFilter&&(l="__eta.f("+l+")"),i+="__eta.res+="+l+`;
37
- `):o==="i"?(s.autoFilter&&(l="__eta.f("+l+")"),s.autoEscape&&(l="__eta.e("+l+")"),i+="__eta.res+="+l+`;
38
- `):o==="e"&&(i+=l+`
39
- `)}}return i}function jt(t,s,e,n){let i,r;return Array.isArray(s.autoTrim)?(i=s.autoTrim[1],r=s.autoTrim[0]):i=r=s.autoTrim,(e||e===!1)&&(i=e),(n||n===!1)&&(r=n),!r&&!i?t:i==="slurp"&&r==="slurp"?t.trim():(i==="_"||i==="slurp"?t=t.trimStart():(i==="-"||i==="nl")&&(t=t.replace(/^(?:\r\n|\n|\r)/,"")),r==="_"||r==="slurp"?t=t.trimEnd():(r==="-"||r==="nl")&&(t=t.replace(/(?:\r\n|\n|\r)$/,"")),t)}const Yt={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"};function Mt(t){return Yt[t]}function qt(t){let s=String(t);return/[&<>"']/.test(s)?s.replace(/[&<>"']/g,Mt):s}const K={autoEscape:!0,autoFilter:!1,autoTrim:[!1,"nl"],cache:!1,cacheFilepaths:!0,debug:!1,escapeFunction:qt,filterFunction:t=>String(t),outputFunctionName:"output",functionHeader:"",parse:{exec:"",interpolate:"=",raw:"~"},plugins:[],rmWhitespace:!1,tags:["<%","%>"],useWith:!1,varName:"it",defaultExtension:".eta"},I=/`(?:\\[\s\S]|\${(?:[^{}]|{(?:[^{}]|{[^}]*})*})*}|(?!\${)[^\\`])*`/g,C=/'(?:\\[\s\w"'\\`]|[^\n\r'\\])*?'/g,L=/"(?:\\[\s\w"'\\`]|[^\n\r"\\])*?"/g;function W(t){return t.replace(/[.*+\-?^${}()|[\]\\]/g,"\\$&")}function Ht(t,s){return t.slice(0,s).split(`
40
- `).length}function Ot(t){let s=this.config,e=[],n=!1,i=0,r=s.parse;if(s.plugins)for(let h=0;h<s.plugins.length;h++){let y=s.plugins[h];y.processTemplate&&(t=y.processTemplate(t,s))}s.rmWhitespace&&(t=t.replace(/[\r\n]+/g,`
41
- `).replace(/^\s+|\s+$/gm,"")),I.lastIndex=0,C.lastIndex=0,L.lastIndex=0;function o(h,y){h&&(h=jt(h,s,n,y),h&&(h=h.replace(/\\|'/g,"\\$&").replace(/\r\n|\n|\r/g,"\\n"),e.push(h)))}let l=[r.exec,r.interpolate,r.raw].reduce((h,y)=>h&&y?h+"|"+W(y):y?W(y):h,""),p=RegExp(W(s.tags[0])+"(-|_)?\\s*("+l+")?\\s*","g"),c=RegExp("'|\"|`|\\/\\*|(\\s*(-|_)?"+W(s.tags[1])+")","g"),f;for(;f=p.exec(t);){let h=t.slice(i,f.index);i=f[0].length+f.index;let y=f[1],v=f[2]||"";o(h,y),c.lastIndex=i;let x,S=!1;for(;x=c.exec(t);)if(x[1]){let T=t.slice(i,x.index);p.lastIndex=i=c.lastIndex,n=x[2],S={t:v===r.exec?"e":v===r.raw?"r":v===r.interpolate?"i":"",val:T};break}else{let T=x[0];if(T==="/*"){let w=t.indexOf("*/",c.lastIndex);w===-1&&E("unclosed comment",t,x.index),c.lastIndex=w}else T==="'"?(C.lastIndex=x.index,C.exec(t)?c.lastIndex=C.lastIndex:E("unclosed string",t,x.index)):T==='"'?(L.lastIndex=x.index,L.exec(t)?c.lastIndex=L.lastIndex:E("unclosed string",t,x.index)):T==="`"&&(I.lastIndex=x.index,I.exec(t)?c.lastIndex=I.lastIndex:E("unclosed string",t,x.index))}S?(s.debug&&(S.lineNo=Ht(t,f.index)),e.push(S)):E("unclosed tag",t,f.index)}if(o(t.slice(i,t.length),!1),s.plugins)for(let h=0;h<s.plugins.length;h++){let y=s.plugins[h];y.processAST&&(e=y.processAST(e,s))}return e}function et(t,s){let e=s!=null&&s.async?this.templatesAsync:this.templatesSync;if(this.resolvePath&&this.readFile&&!t.startsWith("@")){let n=s.filepath,i=e.get(n);if(this.config.cache&&i)return i;{let r=this.readFile(n),o=this.compile(r,s);return this.config.cache&&e.define(n,o),o}}else{let n=e.get(t);if(n)return n;throw new Wt(`Failed to get template '${t}'`)}}function st(t,s,e){let n,i={...e,async:!1};return typeof t=="string"?(this.resolvePath&&this.readFile&&!t.startsWith("@")&&(i.filepath=this.resolvePath(t,i)),n=et.call(this,t,i)):n=t,n.call(this,s,i)}function nt(t,s,e){let n,i={...e,async:!0};typeof t=="string"?(this.resolvePath&&this.readFile&&!t.startsWith("@")&&(i.filepath=this.resolvePath(t,i)),n=et.call(this,t,i)):n=t;let r=n.call(this,s,i);return Promise.resolve(r)}function Vt(t,s){let e=this.compile(t,{async:!1});return st.call(this,e,s)}function Gt(t,s){let e=this.compile(t,{async:!0});return nt.call(this,e,s)}var U=class{constructor(t){this.cache=t}define(t,s){this.cache[t]=s}get(t){return this.cache[t]}remove(t){delete this.cache[t]}reset(){this.cache={}}load(t){this.cache={...this.cache,...t}}},Kt=class{constructor(t){_(this,"config");_(this,"RuntimeErr",Dt);_(this,"compile",Pt);_(this,"compileToString",Ft);_(this,"compileBody",Rt);_(this,"parse",Ot);_(this,"render",st);_(this,"renderAsync",nt);_(this,"renderString",Vt);_(this,"renderStringAsync",Gt);_(this,"filepathCache",{});_(this,"templatesSync",new U({}));_(this,"templatesAsync",new U({}));_(this,"resolvePath",null);_(this,"readFile",null);t?this.config={...K,...t}:this.config={...K}}configure(t){this.config={...this.config,...t}}withConfig(t){return{...this,config:{...this.config,...t}}}loadTemplate(t,s,e){if(typeof s=="string")(e!=null&&e.async?this.templatesAsync:this.templatesSync).define(t,this.compile(s,e));else{let n=this.templatesSync;(s.constructor.name==="AsyncFunction"||e!=null&&e.async)&&(n=this.templatesAsync),n.define(t,s)}}},at=class extends Kt{};const F=/\{\{(.*?)\}\}/g,rt=/^[\w$][\w$.]*$/,Ut=new at({tags:["{{","}}"],autoEscape:!0,autoTrim:!1,useWith:!0,parse:{interpolate:"",exec:"~",raw:"~"},functionHeader:'const safeGet = (obj, path) => { const parts = path.split("."); let val = obj; for (const p of parts) { if (val == null) return undefined; val = val[p]; } return val; };'}),lt=(t,s,e)=>{const n=e.slice(2,-2).trim();return s!==-1&&a.startsWith(t,"$index.")?`${n}.${s}.${t.slice(7)}`:s!==-1&&a.startsWith(t,"$index")?`${n}.${s}`:t},zt=(t,s,e)=>{if(s===-1||!e)return t;const n=e.slice(2,-2).trim();return t.replace(/\$index\./g,`safeGet(it, "${n}.${s}").`).replace(/\$index/g,`safeGet(it, "${n}.${s}")`)},Xt=(t,s,e)=>t.replace(F,(n,i)=>{const r=i.trim();return r?rt.test(r)?`{{safeGet(it, "${lt(r,s,e)}") ?? ""}}`:`{{${zt(r,s,e)}}}`:'{{""}}'}),Zt=(t,s,e,n)=>{try{return Ut.renderString(Xt(t,e,n),s)}catch{return""}},ot=(t,s,e,n,i)=>{F.lastIndex=0;const r=t.match(F);if(!r)return t;const o=i==="image"||i==="mobileImage";for(const l of r){const p=l.slice(2,-2).trim();if(!rt.test(p))continue;const c=lt(p,e,n),f=a.get(s,c);if(a.isArray(f)||o&&f!==void 0)return f}return Zt(t,s,e,n)},Jt=(t,s)=>ot(t,s,-1,""),R=(t,s,{index:e,key:n},i)=>{if(a.isString(t))return ot(t,s,e,n,i);if(a.isArray(t))return t.map(r=>R(r,s,{index:e,key:n},i));if(t&&typeof t=="object"){const r={};return a.forEach(a.keys(t),o=>{!a.startsWith(o,"_")&&o!=="$repeaterItemsKey"?r[o]=R(t[o],s,{index:e,key:n},o):r[o]=t[o]}),r}return t},Qt=(t,s,{index:e,key:n})=>{let i=a.cloneDeep(t);return i.repeaterItems&&(i.$repeaterItemsKey=i.repeaterItems,a.startsWith(i.repeaterItems,`{{${k.COLLECTION_PREFIX}`)&&(i.$repeaterItemsKey=i.repeaterItems=`${i.repeaterItems.replace("}}",`/${i._id}}}`)}`),!a.isEmpty(i.repeaterItems)&&i.pagination&&(i.repeaterTotalItems=`${i.repeaterItems.replace("}}",`/${i._id}/totalItems}}`)}`)),R(i,s,{index:e,key:n})};exports.adjustSpacingInContentBlocks=Ct;exports.applyBindingToBlockProps=Qt;exports.applyChaiDataBinding=_t;exports.applyDesignTokens=It;exports.applyLanguage=ht;exports.applyLimit=mt;exports.getBlockRuntimeProps=ft;exports.getBlockTagAttributes=yt;exports.getBlocksFromHTML=Nt;exports.getSplitChaiClasses=X;exports.k=at;exports.mergeBlocksWithExisting=$t;exports.resolveBinding=Jt;
@@ -1,5 +0,0 @@
1
- "use strict";var mr=Object.create;var is=Object.defineProperty;var Er=Object.getOwnPropertyDescriptor;var pr=Object.getOwnPropertyNames;var yr=Object.getPrototypeOf,Ar=Object.prototype.hasOwnProperty;var Os=e=>{throw TypeError(e)};var Tr=(e,t,s)=>t in e?is(e,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[t]=s;var Sr=(e,t,s,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of pr(t))!Ar.call(e,r)&&r!==s&&is(e,r,{get:()=>t[r],enumerable:!(n=Er(t,r))||n.enumerable});return e};var Pr=(e,t,s)=>(s=e!=null?mr(yr(e)):{},Sr(t||!e||!e.__esModule?is(s,"default",{value:e,enumerable:!0}):s,e));var os=(e,t,s)=>Tr(e,typeof t!="symbol"?t+"":t,s),Rs=(e,t,s)=>t.has(e)||Os("Cannot "+s);var w=(e,t,s)=>(Rs(e,t,"read from private field"),s?s.call(e):t.get(e)),O=(e,t,s)=>t.has(e)?Os("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,s),k=(e,t,s,n)=>(Rs(e,t,"write to private field"),n?n.call(e,s):t.set(e,s),s);const o=require("react/jsx-runtime"),v=require("./register-chai-top-bar-DyW9GPzV.cjs"),g=require("./index-ZaKz5cWo.cjs"),tn=require("@radix-ui/react-icons"),p=require("lodash-es"),V=require("jotai"),_=require("lucide-react"),oe=require("react-i18next"),f=require("react"),x=require("@tanstack/react-query"),xr=require("./plugin-DHpuZZXz.cjs"),R=require("sonner"),Ht=require("./common-functions-B3a4xKt_.cjs"),_r=require("react-error-boundary"),wr=require("./core-czmLeR0h.cjs"),br=require("./web-blocks.cjs"),Cr=require("./apply-binding-BuwI_Uf5.cjs");function vr(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const s in e)if(s!=="default"){const n=Object.getOwnPropertyDescriptor(e,s);Object.defineProperty(t,s,n.get?n:{enumerable:!0,get:()=>e[s]})}}return t.default=e,Object.freeze(t)}const W=vr(f),Ir=()=>{const[e]=g.useCanvasZoom();return o.jsxs("div",{className:"flex w-12 cursor-not-allowed items-center justify-center gap-x-1 space-x-0 font-medium text-gray-400",children:[o.jsx(tn.ZoomInIcon,{className:"h-3.5 w-3.5 flex-shrink-0"})," ",o.jsxs("div",{className:"text-xs leading-3",children:[p.round(e,0),"%"]})]})},Nr=()=>{const e=g.useBuilderProp("flags.darkMode",!1),t=g.useBuilderProp("flags.dataBinding",!0),[s,n]=V.useAtom(g.dataBindingActiveAtom),{t:r}=oe.useTranslation(),a=e,i=t;return o.jsxs("div",{className:"flex h-10 items-center justify-between px-2",children:[o.jsx("div",{className:"flex h-full space-x-2",children:a?o.jsx(g.DarkMode,{}):null}),o.jsxs("div",{className:"flex h-full items-center space-x-2",children:[o.jsx(g.Breakpoints,{canvas:!0,openDelay:400,activeButtonClass:"bg-gray-200"}),o.jsx(Ir,{}),o.jsx(g.UndoRedo,{})]}),o.jsxs("div",{className:"flex h-full items-center",children:[o.jsx(g.ClearCanvas,{}),i?o.jsxs(g.DropdownMenu,{children:[o.jsx(g.DropdownMenuTrigger,{asChild:!0,children:o.jsx(v.Button,{size:"sm",variant:"ghost",className:"size-2 h-7 w-7 rounded-md p-1",children:o.jsx(_.MoreVertical,{className:"h-2 w-2"})})}),o.jsx(g.DropdownMenuContent,{className:"w-56 border-border text-xs",children:o.jsxs(g.DropdownMenuItem,{className:"flex items-center gap-2",onSelect:l=>l.preventDefault(),children:[o.jsx(tn.LightningBoltIcon,{className:"h-4 w-4 text-gray-500"}),o.jsx("span",{className:"flex-1",children:r("Data Binding")}),o.jsx(g.Switch,{checked:s,onCheckedChange:()=>n(!s)})]})})]}):null]})]})},dt=V.atom(null),Lr=V.atom({}),It=()=>V.useAtom(Lr),re=(e,t)=>{const[s]=It();return f.useMemo(()=>p.get(s,e,t),[s,e,t])},j=()=>re("apiUrl","/chai/api"),Ps=()=>re("realtimeAdapter",null);function Ee(){const[e,t]=f.useState(new URLSearchParams(window.location.search));return f.useEffect(()=>{const s=()=>{t(new URLSearchParams(window.location.search))};return window.addEventListener("popstate",s),()=>{window.removeEventListener("popstate",s)}},[]),[e,t]}const y={GET_GLOBAL_JSONLD_ITEMS:"GET_GLOBAL_JSONLD_ITEMS",GENERATE_SEO_FIELD:"GENERATE_SEO_FIELD",UPDATE_PAGE_METADATA:"UPDATE_PAGE_METADATA",GET_BLOCK_ASYNC_PROPS:"GET_BLOCK_ASYNC_PROPS",ASK_AI:"ASK_AI",GET_DRAFT_PAGE:"GET_DRAFT_PAGE",CREATE_PAGE:"CREATE_PAGE",UPDATE_PAGE:"UPDATE_PAGE",DELETE_PAGE:"DELETE_PAGE",DUPLICATE_PAGE:"DUPLICATE_PAGE",CHANGE_SLUG:"CHANGE_SLUG",TAKE_OFFLINE:"TAKE_OFFLINE",PUBLISH_PAGE:"PUBLISH_PAGE",PUBLISH_CHANGES:"PUBLISH_CHANGES",ADD_NEW_LANGUAGE:"ADD_NEW_LANGUAGE",EDIT_LANGUAGE:"EDIT_LANGUAGE",DELETE_LANGUAGE:"DELETE_LANGUAGE",GET_CHANGES:"GET_CHANGES",GET_SERVER_BLOCK:"GET_SERVER_BLOCK",GET_LANGUAGE_PAGES:"GET_LANGUAGE_PAGES",GET_PROJECT_PAGES:"GET_PROJECT_PAGES",GET_WEBSITE_PAGES:"GET_WEBSITE_PAGES",UPDATE_WEBSITE_FIELDS:"UPDATE_WEBSITE_FIELDS",GET_COLLECTIONS:"GET_COLLECTIONS",GET_PAGE_TYPES:"GET_PAGE_TYPES",SEARCH_PAGES:"SEARCH_PAGES",GET_WEBSITE_DRAFT_SETTINGS:"GET_WEBSITE_DRAFT_SETTINGS",AI_CONTEXT:"AI_CONTEXT",GET_WEBSITE_DATA:"GET_WEBSITE_DATA",GET_CHAI_USER:"GET_CHAI_USER",CHANGE_PASSWORD:"CHANGE_PASSWORD",GET_SEO_FIELDS:"GET_SEO_FIELDS",GET_BUILDER_PAGE_DATA:"GET_BUILDER_PAGE_DATA",GET_PAGE_ALL_DATA:"GET_PAGE_ALL_DATA",GET_PAGE_REVISIONS:"GET_PAGE_REVISIONS",DELETE_PAGE_REVISION:"DELETE_PAGE_REVISION",RESTORE_PAGE_REVISION:"RESTORE_PAGE_REVISION",GET_REVISION_DATA:"GET_REVISION_DATA",GET_PAGE_DATA:"GET_PAGE_DATA",GET_COMPARE_DATA:"GET_COMPARE_DATA",UPSERT_LIBRARY_ITEM:"UPSERT_LIBRARY_ITEM",GET_LIBRARIES:"GET_LIBRARIES",GET_LIBRARY_ITEM:"GET_LIBRARY_ITEM",GET_LIBRARY_ITEMS:"GET_LIBRARY_ITEMS",DELETE_LIBRARY_ITEM:"DELETE_LIBRARY_ITEM",MARK_AS_TEMPLATE:"MARK_AS_TEMPLATE",UNMARK_AS_TEMPLATE:"UNMARK_AS_TEMPLATE",GET_TEMPLATES_BY_TYPE:"GET_TEMPLATES_BY_TYPE",GET_DYNAMIC_PAGES:"GET_DYNAMIC_PAGES",GET_APP_SHARED_JSONLD:"GET_APP_SHARED_JSONLD",UPDATE_APP_SHARED_JSONLD:"UPDATE_APP_SHARED_JSONLD",ADD_GLOBAL_SCHEMA:"ADD_GLOBAL_SCHEMA",UPDATE_GLOBAL_SCHEMA:"UPDATE_GLOBAL_SCHEMA",DELETE_GLOBAL_SCHEMA:"DELETE_GLOBAL_SCHEMA",TOGGLE_PAGE_GLOBAL_SCHEMA:"TOGGLE_PAGE_GLOBAL_SCHEMA",APPLY_SCHEMA_TO_ALL_PAGES:"APPLY_SCHEMA_TO_ALL_PAGES",UI_LIBRARIES:"UI_LIBRARIES",REMOVE_SCHEMA_FROM_ALL_PAGES:"REMOVE_SCHEMA_FROM_ALL_PAGES",UPLOAD_ASSET:"UPLOAD_ASSET",DELETE_ASSET:"DELETE_ASSET",UPDATE_ASSET:"UPDATE_ASSET",GET_ASSETS:"GET_ASSETS",GET_ASSET:"GET_ASSET"},sn=async(e,t,s={})=>await fetch(e,{method:"POST",headers:{"Content-Type":"application/json",...s},body:JSON.stringify(t)}),jr=()=>{const e=G(),t=j();return f.useCallback(async({body:s,headers:n={},url:r=t,streamResponse:a=!1})=>e(r,s,n,a),[e])},G=()=>{const e=re("onLogout",p.noop),t=re("getAccessToken"),s=j();return f.useCallback(async(n=s,r,a={},i=!1)=>{const l=await t();try{const c=p.get(r,"action","").toLowerCase(),d=await sn(n+(c?`?action=${c}`:""),r,{...a,Authorization:`Bearer ${l}`});if(i)return d;if(d.status===401)return console.log("401 Response",d),await e("SESSION_EXPIRED"),null;if(!d.ok){const h=await d.json();throw console.error(`API Error (${d.status}):`,h),{status:d.status,statusText:d.statusText,...h,message:h.error||h.message||`Server error: ${d.status}`}}return await d.json()}catch(c){throw console.error("API request failed:",r,c),c}},[e,t])},kr=V.atom(null),nn=()=>V.useAtom(kr),xs=()=>{const[e]=nn();return(e==null?void 0:e.slug)||""};function Dr(e,t){const[s,n]=f.useState(e);return f.useEffect(()=>{const r=setTimeout(()=>n(e),t);return()=>clearTimeout(r)},[e,t]),s}const Gr=({query:e,uuid:t})=>{const{selectedLang:s,fallbackLang:n}=g.useLanguages(),{data:r}=se(),a=r==null?void 0:r.pageType,i=j(),l=G(),{data:c,isFetching:d}=x.useQuery({queryKey:[y.GET_DYNAMIC_PAGES,e,a,t],staleTime:3600*1e3,placeholderData:[],queryFn:async()=>await l(i,{action:y.GET_DYNAMIC_PAGES,data:{query:e,pageType:a,uuid:t}})||[],enabled:!!a}),h=f.useMemo(()=>s===""?c.filter(u=>u.lang===""||u.lang===n):c.filter(u=>u.lang===s),[s,n,c]);return{allLangPages:c,data:h,isFetching:d}},rn=()=>{const{selectedLang:e,fallbackLang:t}=g.useLanguages(),[s,n]=nn(),[r,a]=f.useState(""),i=Dr(r,500),{allLangPages:l,data:c,isFetching:d}=Gr({query:i}),h=f.useCallback(m=>n(m),[n]),u=f.useCallback(m=>a(m),[a]),E=f.useCallback(()=>{if(!s)return;const m=!(s!=null&&s.primaryPage),A=e.length===0,b=m?s==null?void 0:s.id:s==null?void 0:s.primaryPage,T=l.filter(S=>(S==null?void 0:S.primaryPage)===b||S.id===b).find(S=>A?S.lang===e||S.lang===t:S.lang===e);n(T||s)},[s,e,l,n,t]);return{isFetching:d,dynamicPage:s,searchQuery:r,selectedLang:e,dynamicPages:c,allLangPages:l,updateDynamicPage:h,updateSearchQuery:u,onChangeLanguage:E}},_e=()=>{const e=j(),t=G();return x.useQuery({queryKey:[y.GET_WEBSITE_DRAFT_SETTINGS],staleTime:300*1e3,placeholderData:{languages:[],theme:xr.defaultThemeValues,appKey:"",fallbackLang:"",settings:{},designTokens:{}},queryFn:async()=>t(e,{action:y.GET_WEBSITE_DRAFT_SETTINGS,data:{draft:!0}})})},Yt=()=>{const{data:e}=_e();return f.useMemo(()=>(e==null?void 0:e.fallbackLang)||"en",[e])},we=()=>{const e=G(),t=j();return x.useQuery({queryKey:[y.GET_WEBSITE_PAGES],staleTime:1e3*60*5,queryFn:async()=>e(t,{action:y.GET_WEBSITE_PAGES})||[],placeholderData:s=>s||[]})},an=e=>{const t=G(),s=j(),n=Yt();return x.useQuery({queryKey:[y.GET_WEBSITE_PAGES,e,n],staleTime:1e3*60*5,enabled:!!e,queryFn:async()=>{if(n===e)return{};const r=await t(s,{action:y.GET_WEBSITE_PAGES,data:{lang:e}})||[];return p.keyBy(p.map(r,a=>({...a,lang:e})),"primaryPage")},placeholderData:r=>r||{}})},Or=V.atom({lastSaved:void 0}),on=()=>V.useAtom(Or),se=()=>{const[e]=Ee(),t=e.get("page"),{data:s,isFetching:n}=we();return{data:f.useMemo(()=>({...p.find(s,{id:t})||{}}),[s,t]),isFetching:n}},pe=()=>{const[e]=Ee(),t=e.get("lang")??"",s=e.get("page"),{data:n,isFetching:r}=an(t),{data:a}=we();return{data:f.useMemo(()=>p.find([...p.values(n),...a],t==""?{id:s}:{lang:t,primaryPage:s})||{},[n,a,t,s]),isFetching:r}};V.atom({});const Rr=()=>{const{data:e}=pe(),t=xs(),s=re("getLiveUrl",p.noop),n=e==null?void 0:e.slug,r=s(n||"/");return t?r+t:r},Nt=e=>{const t=j(),[s]=Ee(),n=e??s.get("page"),r=G(),{languages:a}=g.useLanguages();return x.useQuery({queryKey:[y.GET_LANGUAGE_PAGES,n],staleTime:1/0,gcTime:0,placeholderData:[],queryFn:async()=>{if(!n)return null;const i=await r(t,{action:y.GET_LANGUAGE_PAGES,data:{id:n}});return p.reverse(p.sortBy(i,"primaryPage"))},enabled:!!n&&!!(a!=null&&a.length)})},ue={...g.PERMISSIONS,ADD_PAGE:"add_page",EDIT_PAGE:"edit_page",DELETE_PAGE:"delete_page",CHANGE_PAGE_TYPE:"change_page_type",PUBLISH_PAGE:"publish_page",UNPUBLISH_PAGE:"unpublish_page",EDIT_SEO:"edit_seo",RESTORE_REVISION:"restore_revision",DELETE_REVISION:"delete_revision",DELETE_LIBRARY_BLOCK:"delete_library_block"},be=()=>{const e=j(),t=G();return x.useQuery({queryKey:[y.GET_PAGE_TYPES],staleTime:1/0,placeholderData:[],queryFn:async()=>t(e,{action:y.GET_PAGE_TYPES})})},ln=e=>{const{data:t}=be();return f.useMemo(()=>t==null?void 0:t.find(s=>s.key===e),[t,e])},Mr=()=>{const{data:e}=we();return{searchPages:f.useCallback(async(s,n)=>{if(!e||!n)return[];if(Array.isArray(n))return e.filter(a=>n.includes(a.id));const r=n.toLowerCase();return e.filter(a=>a.slug&&!a.dynamic&&(a.id===n||(a.name||"").toLowerCase().includes(r)||(a.slug||"").toLowerCase().includes(r)))},[e])}},cn=({page:e,setDuplicatePage:t,setAddEditPage:s,setUnpublishPage:n,setDeletePage:r,children:a,isLanguagePage:i})=>{const{t:l}=oe.useTranslation(),{hasPermission:c}=g.usePermissions(),{data:d}=be(),h=f.useMemo(()=>p.find(d,{key:e.pageType}),[d,e.pageType]);return!c(ue.EDIT_PAGE)&&!c(ue.DELETE_PAGE)&&!c(ue.UNPUBLISH_PAGE)||!e?null:o.jsxs(g.DropdownMenu,{children:[o.jsx(g.DropdownMenuTrigger,{asChild:!0,onClick:E=>E.stopPropagation(),children:a}),o.jsxs(g.DropdownMenuContent,{align:"center",className:"text-sm",children:[c(ue.ADD_PAGE)&&!i&&o.jsxs(g.DropdownMenuItem,{className:"flex cursor-pointer items-center gap-2",onClick:E=>{E.stopPropagation(),t(e)},children:[o.jsx(_.CopyPlusIcon,{className:"size-3"}),"Duplicate page"]}),c(ue.EDIT_PAGE)&&o.jsxs(g.DropdownMenuItem,{className:"flex cursor-pointer items-center gap-2",onClick:E=>{E.stopPropagation(),s({...e,global:!(h!=null&&h.hasSlug)})},children:[o.jsx(_.Pencil,{className:"size-3"}),"Edit"]}),(e==null?void 0:e.online)&&c(ue.UNPUBLISH_PAGE)&&o.jsxs(g.DropdownMenuItem,{className:"flex cursor-pointer items-center gap-2",onClick:E=>{E.stopPropagation(),n(e)},children:[o.jsx(_.Power,{className:"size-3"}),l("Unpublish")]}),c(ue.DELETE_PAGE)&&o.jsxs(g.DropdownMenuItem,{className:"flex cursor-pointer items-center gap-2",onClick:E=>{E.stopPropagation(),r(e)},children:[o.jsx(_.Trash,{className:"size-3"}),l("Delete")]})]})]})},Ur=(e,t,s)=>((e.includes("THEME")||(t==null?void 0:t.theme)!==void 0)&&(e.push("THEME"),s&&(t!=null&&t.theme)&&s(t.theme)),e),Br=(e,t,s)=>((e.includes("DESIGN_TOKENS")||(t==null?void 0:t.designTokens)!==void 0)&&(e.push("DESIGN_TOKENS"),s&&t.designTokens&&s(t.designTokens)),e),Fr=(e,t,s,n)=>{let r=(e==null?void 0:e.appChanges)||[];return r=Ur(r,t,s),r=Br(r,t,n),e?{...e,...t,appChanges:r}:t},Hr=({queryClient:e,queryKey:t,data:s,setTheme:n,setDesignTokens:r})=>{e.setQueryData(t,a=>Fr(a,s,n,r))},qr=(e,t,s,n,r)=>e.id===t?{...e,designTokens:s,links:n,partialBlocks:r,changes:[{type:"Page"}]}:e,Vr=({queryClient:e,pageId:t,designTokens:s,linkPageIds:n,partialIds:r})=>{e.setQueryData([y.GET_WEBSITE_PAGES],a=>{if(!a||!Array.isArray(a))return a;const i=n.join(" | "),l=r.join(" | ");return a.map(c=>qr(c,t,s,i,l))})},Kr=(e,t,s,n,r,a,i)=>{t.settings&&(Hr({queryClient:e,queryKey:[y.GET_WEBSITE_DRAFT_SETTINGS],data:t.settings,setTheme:a,setDesignTokens:i}),!s&&n&&(t.settings.theme!==void 0&&R.toast.success(r("Theme Updated"),{description:r("{{userName}} updated the theme",{userName:n}),position:"bottom-left"}),t.settings.designTokens!==void 0&&R.toast.success(r("Design Tokens Updated"),{description:r("{{userName}} updated the design tokens",{userName:n}),position:"bottom-left"})))},Qr=(e,t)=>{t.pageId&&t.designTokens&&t.linkPageIds&&t.partialIds&&Vr({queryClient:e,pageId:t.pageId,designTokens:t.designTokens,linkPageIds:t.linkPageIds,partialIds:t.partialIds})},Ms=(e,t)=>t.includes(e.id)?{...e,changes:[],online:!0}:e,zr=(e,t)=>{if(!e)return e;const n=(e.appChanges||[]).filter(r=>!t.includes(r));return{...e,appChanges:n}},$r=({queryClient:e,ids:t})=>{e.setQueryData([y.GET_WEBSITE_PAGES],s=>!s||!Array.isArray(s)?s:s.map(n=>Ms(n,t))),e.setQueryData([y.GET_LANGUAGE_PAGES],s=>!s||!Array.isArray(s)?s:s.map(n=>Ms(n,t))),(t.includes("THEME")||t.includes("DESIGN_TOKENS"))&&e.setQueryData([y.GET_WEBSITE_DRAFT_SETTINGS],s=>zr(s,t))},Us=(e,t)=>e.id===t?{...e,online:!1}:e,Wr=({queryClient:e,pageId:t,primaryPage:s})=>{s?e.setQueryData([y.GET_LANGUAGE_PAGES,s],n=>!n||!Array.isArray(n)?n:n.map(r=>Us(r,t))):e.setQueryData([y.GET_WEBSITE_PAGES],n=>!n||!Array.isArray(n)?n:n.map(r=>Us(r,t)))},Jr=(e,t,s,n)=>{e&&t(s,{data:n})},Yr=(e,t,s,n,r)=>{const{type:a,data:i,sync:l=!1,userName:c}=e;switch(a){case"UPDATE_WEBSITE_DATA":Kr(t,i,l,c,r,s,n);break;case"UPDATE_PAGE_DATA":Qr(t,i);break;case"PUBLISH_CHANGES":i.ids&&$r({queryClient:t,ids:i.ids});break;case"UNPUBLISH_PAGE":i.pageId&&Wr({queryClient:t,pageId:i.pageId,primaryPage:i.primaryPage});break;default:console.log(r("Unknown sync type"),a)}return l},Lt=()=>{const e=x.useQueryClient(),t=Cs(),[s,n]=V.useAtom(g.chaiThemeValuesAtom),[,r]=V.useAtom(g.chaiDesignTokensAtom),{t:a}=oe.useTranslation(),i=f.useCallback(c=>{r(c)},[r]);return{handleQuerySync:f.useCallback(c=>{const d=Yr(c,e,n,i,a);Jr(d,t,c.type,c.data)},[e,t,n,i,a])}},Zt=()=>{const e=re("currentUser"),t=re("onLogout");return{isLoggedIn:!!e,user:e,logout:t}},X={LOCKED:"LOCKED",EDITING:"EDITING",CHECKING:"CHECKING",TAKE_OVER_REQUESTED:"TAKE_OVER_REQUESTED",ACTIVE_IN_ANOTHER_TAB:"ACTIVE_IN_ANOTHER_TAB",FORCE_TAKE_OVER:"FORCE_TAKE_OVER",CONNECTION_LOST:"CONNECTION_LOST"},$={FORCE_TAKE_OVER:"FORCE_TAKE_OVER",TAKE_OVER_REQUEST:"TAKE_OVER_REQUEST",TAKE_OVER_APPROVED:"TAKE_OVER_APPROVED",TAKE_OVER_REJECTED:"TAKE_OVER_REJECTED",FORCE_TAKE_OVER_REQUEST:"FORCE_TAKE_OVER_REQUEST",CONTINUE_EDITING_IN_THIS_CLIENT:"CONTINUE_EDITING_IN_THIS_CLIENT",CONTINUE_EDITING_IN_THIS_TAB_REQUEST:"CONTINUE_EDITING_IN_THIS_TAB_REQUEST",UPDATE_WEBSITE_DATA:"UPDATE_WEBSITE_DATA",UPDATE_PAGE_DATA:"UPDATE_PAGE_DATA",PUBLISH_CHANGES:"PUBLISH_CHANGES",UNPUBLISH_PAGE:"UNPUBLISH_PAGE"},Zr=["sync","join","leave"],Xr=[$.FORCE_TAKE_OVER,$.TAKE_OVER_REQUEST,$.TAKE_OVER_APPROVED,$.TAKE_OVER_REJECTED,$.FORCE_TAKE_OVER_REQUEST,$.CONTINUE_EDITING_IN_THIS_CLIENT,$.CONTINUE_EDITING_IN_THIS_TAB_REQUEST,$.UPDATE_WEBSITE_DATA,$.UPDATE_PAGE_DATA,$.PUBLISH_CHANGES,$.UNPUBLISH_PAGE],ea=V.atom({}),un=V.atom(null),ta=V.atom(X.CHECKING),sa=V.atom({}),na=e=>{const t={},s=p.groupBy(p.values(e).map(p.first).filter(Boolean),"pageId");return Object.entries(s).forEach(([n,r])=>t[n]=p.minBy(r,"onlineAt")),t},ra=e=>{const t=p.minBy(p.values(e).map(p.first).filter(Boolean),"onlineAt"),s=t==null?void 0:t.onlineAt;return s?s-100:+new Date-1e3*60*60*4},jt=()=>{const{user:e}=Zt();return e==null?void 0:e.id},aa=()=>{const{data:e}=_e();return`WEBSITE:${e==null?void 0:e.appKey}`},kt=()=>{const{data:e}=se();return e==null?void 0:e.id},Te=crypto.randomUUID();let ls=null;const nt=10,ia=1e3,oa=2,la=16e3,_s=()=>{const[e,t]=V.useAtom(ea);return{pageToUser:e,setPageToUser:t}},de=()=>{const[e,t]=V.useAtom(ta),s=[X.LOCKED,X.ACTIVE_IN_ANOTHER_TAB].includes(e),n=[X.EDITING].includes(e);return{pageStatus:e,setPageStatus:t,isLocked:s,isEditing:n}},ws=()=>{const[e,t]=V.useAtom(sa);return{pageLockMeta:e,setPageLockMeta:t}},dn=()=>{const e=kt(),{pageToUser:t}=_s();return f.useMemo(()=>t[e],[t,e])},bs=()=>{const e=Ps(),{setPageStatus:t}=de(),[s]=V.useAtom(un);return f.useEffect(()=>{if(clearTimeout(ls),!e)return ls=setTimeout(()=>{e||t(X.EDITING)},500),()=>clearTimeout(ls)},[e,t]),s},ca=()=>{const e=kt(),t=jt(),s=bs(),{setPageToUser:n}=_s(),{setPageStatus:r,pageStatus:a}=de(),i=f.useRef(e);return f.useEffect(()=>{i.current=e},[e]),f.useCallback(l=>{const c=l||s;if(!c)return[];const d=c==null?void 0:c.presenceState(),h=na(d);n(h);const u=h[i.current];if(!u)r(X.CHECKING);else if(!t)r(X.CHECKING);else if(u.userId===t&&u.clientId===Te){if(a===X.TAKE_OVER_REQUESTED)return;r(X.EDITING)}else u.userId===t&&u.clientId!==Te?r(X.ACTIVE_IN_ANOTHER_TAB):r(X.LOCKED)},[s,n,r,t,a])},Cs=()=>{const e=jt(),t=kt(),s=bs(),n=dn(),{setPageLockMeta:r}=ws(),{user:a}=Zt(),i=f.useRef(t);return f.useEffect(()=>{i.current=t},[t]),f.useCallback(async(l,c)=>{if(!s)return;const d=c||{};d.userId=e,d.userName=(a==null?void 0:a.name)||(a==null?void 0:a.email)||"Unknown user",d.pageId=i.current,d.senderClientId=Te,d.receiverClientId=(c==null?void 0:c.requestingClientId)||(n==null?void 0:n.clientId),await s.send(l,d),r({})},[s,e,n,r,a])},ua=()=>{const e=jt(),t=kt(),s=bs(),{setPageStatus:n}=de(),{setPageLockMeta:r}=ws(),a=Cs(),i=f.useRef(t),{savePageAsync:l}=g.useSavePage(),{handleQuerySync:c}=Lt();return f.useEffect(()=>{i.current=t},[t]),f.useCallback(d=>async({payload:h})=>{const u=h||{};if(d===$.UPDATE_WEBSITE_DATA||d===$.UPDATE_PAGE_DATA||d===$.PUBLISH_CHANGES||d===$.UNPUBLISH_PAGE){c({type:d,data:u==null?void 0:u.data,sync:!1,userName:u==null?void 0:u.userName});return}if(!(!(u!=null&&u.pageId)||(u==null?void 0:u.pageId)!==i.current||(u==null?void 0:u.receiverClientId)!==Te))switch(r({}),d){case $.FORCE_TAKE_OVER_REQUEST:case $.CONTINUE_EDITING_IN_THIS_TAB_REQUEST:{try{await l(!0)}catch(E){console.error("Failed to save page before releasing lock:",E)}await a($.CONTINUE_EDITING_IN_THIS_CLIENT,{requestingClientId:u==null?void 0:u.senderClientId}),setTimeout(()=>r({type:d}),0);break}case $.TAKE_OVER_REQUEST:{r({requestingUserId:u==null?void 0:u.userId,requestingClientId:u==null?void 0:u.senderClientId}),n(X.TAKE_OVER_REQUESTED);break}case $.CONTINUE_EDITING_IN_THIS_CLIENT:{const E=ra(s==null?void 0:s.presenceState());n(X.CHECKING),await(s==null?void 0:s.track({onlineAt:E,pageId:i.current,userId:e,clientId:Te}));break}case $.TAKE_OVER_REJECTED:{r({type:$.TAKE_OVER_REJECTED});break}}},[a,r,n,s,e,l,c])},da=()=>{const e=Ps(),t=jt(),s=kt(),n=aa(),[r,a]=V.useAtom(un),i=ua(),l=ca(),c=f.useRef(i),d=f.useRef(l),h=f.useRef(null),u=f.useRef(!1),E=f.useRef(0),m=f.useRef(r),A=f.useRef(()=>{});f.useEffect(()=>{c.current=i,d.current=l,m.current=r},[i,l,r]);const b=f.useCallback(T=>{Xr.forEach(S=>{T.onBroadcast(S,N=>{c.current(S)(N)})}),Zr.forEach(S=>{T.onPresence(S,()=>{d.current(T)})})},[]),L=f.useCallback(()=>{if(u.current||!e||!t||!n)return;if(E.current>=nt){console.error(`Maximum reconnection attempts (${nt}) reached. Stopping reconnection attempts.`);return}u.current=!0,E.current+=1,console.log(`Attempting to reconnect realtime channel (attempt ${E.current}/${nt})`),h.current&&(clearTimeout(h.current),h.current=null),m.current&&(m.current.unsubscribe(),a(null),m.current=null);const T=Math.min(ia*Math.pow(oa,E.current-1),la);h.current=setTimeout(()=>{const S=e.channel(n,{config:{presence:{key:Te}}});b(S),S.subscribe(async N=>{N==="SUBSCRIBED"?(console.log("Realtime connection established successfully"),a(S),m.current=S,E.current=0,u.current=!1):N==="CHANNEL_ERROR"||N==="TIMED_OUT"?(console.log(`Realtime connection failed: ${N}. Attempt ${E.current}/${nt}`),E.current<nt?setTimeout(()=>{u.current=!1,A.current()},500):(console.error("Maximum reconnection attempts reached"),u.current=!1)):N==="CLOSED"&&(console.log("Realtime connection closed"),u.current=!1)})},T)},[e,t,n,a,b]);f.useEffect(()=>{A.current=L},[L]),f.useEffect(()=>{if(!e||!t||!n||r&&r.topic===n)return;E.current=0,u.current=!1;const T=e.channel(n,{config:{presence:{key:Te}}});return b(T),T.subscribe(async S=>{S==="SUBSCRIBED"?(console.log("Realtime connection established successfully"),a(T),m.current=T,E.current=0):S==="CHANNEL_ERROR"||S==="TIMED_OUT"?(console.log(`Realtime connection failed: ${S}. Will attempt to reconnect...`),u.current||L()):S==="CLOSED"&&console.log("Realtime connection closed")}),()=>{h.current&&(clearTimeout(h.current),h.current=null),u.current=!1,E.current=0,m.current===T&&(m.current=null),a(null),T.unsubscribe()}},[e,t,n,a,L,b]),f.useEffect(()=>{const T=()=>{if(document.visibilityState==="visible"){if(console.log("Tab became visible, checking realtime connection..."),!e||!t||!n){console.log("Required dependencies not available, skipping reconnection");return}if(u.current){console.log("Reconnection already in progress, skipping visibility change reconnect");return}m.current?m.current.getState()!=="JOINED"&&(console.log("Channel is not active, reconnecting..."),L()):(console.log("No active channel found, reconnecting..."),L())}};return document.addEventListener("visibilitychange",T),()=>{document.removeEventListener("visibilitychange",T)}},[e,t,n,L]),f.useEffect(()=>(r&&s&&t&&r.track({pageId:s,userId:t,clientId:Te,onlineAt:+new Date}),()=>{r&&s&&r.untrack()}),[r,s,t])},fa=f.lazy(()=>Promise.resolve().then(()=>require("./add-new-page-CMkPeRMc.cjs"))),ha=f.lazy(()=>Promise.resolve().then(()=>require("./delete-page-Cc5Z537o.cjs"))),ga=f.lazy(()=>Promise.resolve().then(()=>require("./duplicate-page-cFYp-bAb.cjs"))),ma=f.lazy(()=>Promise.resolve().then(()=>require("./mark-as-template-RDZ4zAWY.cjs"))),Ea=f.lazy(()=>Promise.resolve().then(()=>require("./unmark-as-template-Co-3oGGQ.cjs"))),pa=f.lazy(()=>Promise.resolve().then(()=>require("./unpublish-page-C4v2-E5K.cjs"))),ya=()=>{const[e,t]=f.useState(null),[s,n]=f.useState(null),[r,a]=f.useState(null),[i,l]=f.useState(null),[c,d]=f.useState(null),[h,u]=f.useState(null),{data:E,isFetching:m}=pe(),{selectedLang:A,fallbackLang:b}=g.useLanguages(),{data:L}=Nt(),T=L==null?void 0:L.find(F=>F.lang===A),{isLocked:S}=de(),N=!(E!=null&&E.slug),Q=V.useSetAtom(dt);if(!E)return null;const K=F=>{A.length>0&&A!==b?Q({edit:!0,id:F==null?void 0:F.id,primaryPage:F==null?void 0:F.primaryPage}):u(F)};return o.jsxs(o.Fragment,{children:[o.jsxs("div",{className:"flex items-center justify-between rounded px-[2px] transition-colors duration-200",children:[o.jsx("p",{className:"flex h-7 max-w-[200px] items-center truncate rounded px-1 text-xs font-medium",children:m?o.jsx(_.Loader,{className:"h-4 w-4 animate-spin text-slate-400"}):o.jsxs("span",{className:"flex items-end overflow-hidden text-ellipsis whitespace-nowrap rounded-sm text-xs font-medium",children:[N?o.jsx(_.Hash,{className:"mr-1 h-4 w-4"}):o.jsx(_.File,{className:"mr-1 h-4 w-4"}),p.get(T||E,"name")??""]})}),S?o.jsx(v.Button,{variant:"ghost",size:"icon",className:"h-7 w-7 cursor-not-allowed rounded opacity-50 hover:bg-transparent",children:o.jsx(_.MoreHorizontal,{className:"h-4 w-4"})}):o.jsx(cn,{page:E,setDuplicatePage:F=>d(F),setAddEditPage:F=>K(F),setUnpublishPage:F=>n(F),setDeletePage:F=>t(F),isLanguagePage:A.length>0&&A!==b,children:o.jsx(v.Button,{variant:"ghost",size:"icon",className:"h-7 w-7 rounded",children:o.jsx(_.MoreVertical,{className:"h-4 w-4"})})})]}),h&&o.jsx(f.Suspense,{children:o.jsx(fa,{closePanel:()=>u(null),editPage:()=>{},addEditPage:h,setAddEditPage:u})}),e&&o.jsx(f.Suspense,{children:o.jsx(ha,{page:e,onClose:()=>t(null)})}),s&&o.jsx(f.Suspense,{children:o.jsx(pa,{page:s,onClose:()=>n(null)})}),r&&o.jsx(f.Suspense,{children:o.jsx(ma,{page:r,onClose:()=>a(null)})}),i&&o.jsx(f.Suspense,{children:o.jsx(Ea,{page:i,onClose:()=>l(null)})}),c&&o.jsx(f.Suspense,{children:o.jsx(ga,{page:c,onClose:()=>d(null),closePanel:()=>u(null)})})]})},Ye=({children:e,className:t=""})=>o.jsx("div",{className:Ht.cn("fixed bottom-0 left-0 right-0 top-[50px] z-[20] flex w-screen flex-col items-center justify-center bg-black/40 transition-all",t),children:e}),Aa=({hasDynamicPage:e})=>o.jsx(Ye,{children:o.jsxs("div",{className:"flex min-w-[300px] max-w-[400px] flex-col items-center justify-center rounded-lg border bg-white p-4 shadow-lg",children:[o.jsx("h1",{className:"text-lg font-medium",children:e?"Select a page":"No pages found"}),o.jsx("p",{className:"pt-2 text-center text-sm font-light text-gray-600",children:e?"Please select a page from the list in the top header. This will enable you to edit the page.":"Please add a new page"})]})}),rt={ab:"Abkhazian",aa:"Afar",af:"Afrikaans",ak:"Akan",sq:"Albanian",am:"Amharic",ar:"Arabic",an:"Aragonese",hy:"Armenian",as:"Assamese",av:"Avaric",ae:"Avestan",ay:"Aymara",az:"Azerbaijani",bm:"Bambara",ba:"Bashkir",eu:"Basque",be:"Belarusian",bn:"Bengali",bh:"Bihari",bi:"Bislama",bs:"Bosnian",br:"Breton",bg:"Bulgarian",my:"Burmese",ca:"Catalan",ch:"Chamorro",ce:"Chechen",ny:"Chichewa",zh:"Chinese","zh-Hans":"Chinese (Simplified)","zh-Hant":"Chinese (Traditional)",cv:"Chuvash",kw:"Cornish",co:"Corsican",cr:"Cree",hr:"Croatian",cs:"Czech",da:"Danish",dv:"Maldivian",nl:"Dutch",dz:"Dzongkha",en:"English",eo:"Esperanto",et:"Estonian",ee:"Ewe",fo:"Faroese",fj:"Fijian",fi:"Finnish",fr:"French",ff:"Fula, Pular",gl:"Galician",gd:"Gaelic (Scottish)",gv:"Manx",ka:"Georgian",de:"German",el:"Greek",kl:"Kalaallisut",gn:"Guarani",gu:"Gujarati",ht:"Haitian Creole",ha:"Hausa",he:"Hebrew",hz:"Herero",hi:"Hindi",ho:"Hiri Motu",hu:"Hungarian",is:"Icelandic",io:"Ido",ig:"Igbo",id:"Indonesian",ia:"Interlingua",ie:"Interlingue",iu:"Inuktitut",ik:"Inupiak",ga:"Irish",it:"Italian",ja:"Japanese",jv:"Javanese",kn:"Kannada",kr:"Kanuri",ks:"Kashmiri",kk:"Kazakh",km:"Khmer",ki:"Kikuyu",rw:"Kinyarwanda",rn:"Kirundi",ky:"Kyrgyz",kv:"Komi",kg:"Kongo",ko:"Korean",ku:"Kurdish",kj:"Kwanyama",lo:"Lao",la:"Latin",lv:"Latvian",li:"Limburgish",ln:"Lingala",lt:"Lithuanian",lu:"Luga-Katanga",lg:"Luganda, Ganda",lb:"Luxembourgish",mk:"Macedonian",mg:"Malagasy",ms:"Malay",ml:"Malayalam",mt:"Maltese",mi:"Maori",mr:"Marathi",mh:"Marshallese",mo:"Moldavian",mn:"Mongolian",na:"Nauru",nv:"Navajo",ng:"Ndonga",nd:"Northern Ndebele",ne:"Nepali",no:"Norwegian",nb:"Norwegian bokmål",nn:"Norwegian nynorsk",ii:"Sichuan Yi",oc:"Occitan",oj:"Ojibwe",cu:"Old Church Slavonic",or:"Oriya",om:"Oromo",os:"Ossetian",pi:"Pāli",ps:"Pashto, Pushto",fa:"Persian (Farsi)",pl:"Polish",pt:"Portuguese",pa:"Punjabi (Eastern)",qu:"Quechua",rm:"Romansh",ro:"Romanian",ru:"Russian",se:"Sami",sm:"Samoan",sg:"Sango",sa:"Sanskrit",sr:"Serbian",sh:"Serbo-Croatian",st:"Sesotho",tn:"Setswana",sn:"Shona",sd:"Sindhi",si:"Sinhalese",ss:"Swati",sk:"Slovak",sl:"Slovenian",so:"Somali",nr:"Southern Ndebele",es:"Spanish",su:"Sundanese",sw:"Swahili (Kiswahili)",sv:"Swedish",tl:"Tagalog",ty:"Tahitian",tg:"Tajik",ta:"Tamil",tt:"Tatar",te:"Telugu",th:"Thai",bo:"Tibetan",ti:"Tigrinya",to:"Tonga",ts:"Tsonga",tr:"Turkish",tk:"Turkmen",tw:"Twi",ug:"Uyghur",uk:"Ukrainian",ur:"Urdu",uz:"Uzbek",ve:"Venda",vi:"Vietnamese",vo:"Volapük",wa:"Wallon",cy:"Welsh",wo:"Wolof",fy:"Western Frisian",xh:"Xhosa",yi:"Yiddish",yo:"Yoruba",za:"Zhuang, Chuang",zu:"Zulu"};function fn(e,t,s=!1){const n=e.toString()?`?${e.toString()}`:"/";s?window.history.replaceState(null,"",n):window.history.pushState({},"",n),t(e),window.dispatchEvent(new PopStateEvent("popstate"))}const Ta=f.lazy(()=>Promise.resolve().then(()=>require("./add-new-language-page-B37NvHcc.cjs"))),Sa=()=>{const e=re("topLeftCorner",null);return e?o.jsx("div",{className:"max-h-9 w-full overflow-hidden pr-2",children:f.createElement(e,{})}):null},hn=({showAdd:e=!0,goToDefaultLang:t=!1})=>{const{fallbackLang:s,languages:n,selectedLang:r,setSelectedLang:a}=g.useLanguages(),i=p.isEmpty(r)?s:r,[,l]=Ee(),{isLocked:c}=de(),{t:d}=oe.useTranslation();f.useEffect(()=>{const T=new URLSearchParams(window.location.search),S=T.get("lang");S&&(n.includes(S)?a(S):(T.delete("lang"),l(T),a("")))},[n,l,a]);const h=V.useSetAtom(dt),{data:u}=se(),{data:E}=_e(),{data:m}=Nt(),A=f.useMemo(()=>{const T=p.compact(p.map(p.get(E,"languages"),S=>{const N=p.find(m,{lang:S});return{key:S,value:p.get(rt,S,S),isLangPageAdded:!!N}})).filter(Boolean);return[{key:s,value:p.get(rt,s),isLangPageAdded:!0},...T]},[s,m,E]),b=T=>{if(document.querySelector('[data-panel-id="seo"]')){const N=new CustomEvent("seo-language-switch-check",{detail:{fromLang:i,toLang:T,switchHandler:()=>L(T)}});window.dispatchEvent(N);return}L(T)},L=T=>{a(T);const S=new URLSearchParams(window.location.search);T===s?S.delete("lang"):S.set("lang",T),fn(S,l)};return p.isEmpty(n)?null:c?o.jsxs(v.Button,{variant:"ghost",size:"sm",className:"ml-px h-max cursor-not-allowed gap-2 py-1.5 opacity-50",children:[o.jsx(_.Languages,{className:"h-4 w-4"}),p.get(rt,i,i),o.jsx(_.ChevronDown,{className:"h-4 w-4"})]}):t?o.jsx(v.Button,{onClick:()=>L(s),variant:"link",size:"sm",children:d("Switch to default language")}):o.jsx(o.Fragment,{children:o.jsxs(g.DropdownMenu,{children:[o.jsx(g.DropdownMenuTrigger,{asChild:!0,className:"focus:outline-none",children:o.jsxs(v.Button,{disabled:!!c,variant:"outline",size:"sm",className:"ml-px h-max gap-2 py-1.5",children:[o.jsx(_.Languages,{className:"h-4 w-4"}),p.get(rt,i,i),o.jsx(_.ChevronDown,{className:"h-4 w-4"})]})}),o.jsxs(g.DropdownMenuContent,{className:"space-y-1 border-border",children:[p.map(A.filter(T=>T.isLangPageAdded),T=>o.jsxs(g.DropdownMenuItem,{className:Ht.cn("flex cursor-pointer items-center justify-between text-xs font-medium text-gray-800",T.key===i&&"!bg-gray-200 text-gray-700"),onClick:()=>b(T.key),children:[o.jsx("div",{className:"text-slate-600",children:T.value}),T.key===s&&o.jsxs("small",{className:"flex items-center gap-x-1 text-[9px] leading-none text-orange-500",children:[o.jsx(_.Star,{fill:"orange",className:"h-2 w-2"}),"Primary"]})]},T.value)),e&&!p.isEmpty(A.filter(T=>!T.isLangPageAdded))&&o.jsxs(o.Fragment,{children:[o.jsx(g.Separator,{}),o.jsxs(v.Button,{size:"sm",variant:"ghost",onClick:()=>{u&&h({edit:!1,primaryPage:u.id})},className:"text-xs font-normal duration-200 hover:bg-slate-300 hover:text-slate-800",children:[o.jsx(_.Plus,{className:"mr-1 h-3 w-3"})," Add Language"]})]})]})]})})};function Pa(){const e=V.useAtomValue(dt),t=V.useSetAtom(dt);return o.jsxs("div",{className:"relative z-10 flex items-center justify-end gap-1",children:[o.jsx(Sa,{}),e&&o.jsx(f.Suspense,{children:o.jsx(Ta,{isOpen:!0,id:e==null?void 0:e.id,edit:!!(e!=null&&e.id),primaryPage:e==null?void 0:e.primaryPage,preselectedLang:e==null?void 0:e.preselectedLang,onClose:()=>t(null)})})]})}function xa(){return o.jsx("div",{className:"mt-2 space-y-2",children:Array.from({length:5}).map((e,t)=>o.jsxs("div",{className:"flex items-start gap-3 rounded-md border p-2",children:[o.jsxs("div",{className:"flex-1 space-y-1",children:[o.jsx(g.Skeleton,{className:"h-4 w-3/4"}),o.jsx(g.Skeleton,{className:"h-3 w-1/2"}),o.jsx(g.Skeleton,{className:"mt-1 h-5 w-20"})]}),o.jsx(g.Skeleton,{className:"h-8 w-8 rounded-full"})]},t))})}const _a=W.lazy(()=>Promise.resolve().then(()=>require("./page-revisions-content-BP1wghI_.cjs")));function wa(){const[e,t]=W.useState(!1);return o.jsx(g.TooltipProvider,{children:o.jsxs(g.Tooltip,{delayDuration:0,children:[o.jsxs(g.Sheet,{open:e,onOpenChange:t,children:[o.jsx(g.SheetTrigger,{asChild:!0,children:o.jsx(g.TooltipTrigger,{asChild:!0,children:o.jsxs("span",{className:"flex items-center gap-2",children:[o.jsxs(v.Button,{variant:"ghost",size:"icon",className:"h-8 w-8",children:[o.jsx(_.History,{className:"h-4 w-4"}),o.jsx("span",{className:"sr-only",children:"View revision history"})]}),o.jsx("div",{className:"h-4 w-px bg-gray-200 dark:bg-gray-700"})]})})}),o.jsx(g.SheetContent,{className:"flex h-[100vh] flex-col",children:e&&o.jsx(f.Suspense,{fallback:o.jsx(xa,{}),children:o.jsx(_a,{isOpen:e})})})]}),o.jsx(g.TooltipContent,{side:"bottom",children:o.jsx("p",{children:"Revision history"})})]})})}const Ut=({permission:e,permissions:t,children:s,fallback:n=null})=>{const{hasPermission:r}=g.usePermissions();return e&&!r(e)||t&&!t.some(a=>r(a))?n:s},ba={SLUG_ALREADY_USED:"This slug is already in use. Please choose a different one."},gn=()=>{var t;const[e]=It();return((t=e==null?void 0:e.flags)==null?void 0:t.revisions)??!1},Ca=()=>{const e=j(),t=x.useQueryClient(),s=G(),{data:n}=be();return x.useMutation({mutationFn:async r=>await s(e,{action:y.CREATE_PAGE,data:r}),onSuccess:(r,a)=>{var l;a&&(a!=null&&a.primaryPage)?(t.invalidateQueries({queryKey:[y.GET_LANGUAGE_PAGES,a==null?void 0:a.primaryPage]}),t.invalidateQueries({queryKey:[y.GET_WEBSITE_PAGES,a==null?void 0:a.lang]})):t.invalidateQueries({queryKey:[y.GET_WEBSITE_PAGES]});const i=a.template?`Page created from "${a.template.name}" template`:a.hasSlug===!1?"New "+((l=p.find(n,{key:a.pageType}))==null?void 0:l.name)+" added successfully":"New page added successfully";R.toast.success(i)},onError:(r,a)=>{const i=p.find(n,{key:a.pageType});R.toast.error(`Failed to add new ${i!=null&&i.hasSlug?"page":i.name}.`,{description:p.get(ba,r.message,r.message)})}})},va=()=>{const e=j(),t=x.useQueryClient(),s=G(),{data:n}=pe(),{data:r}=be();return x.useMutation({mutationFn:async a=>await s(e,{action:y.UPDATE_PAGE,data:a}),onSuccess:(a,i)=>{(n==null?void 0:n.id)===(i==null?void 0:i.id)&&t.invalidateQueries({queryKey:[y.GET_LANGUAGE_PAGES]}),i&&(i!=null&&i.primaryPage||i!=null&&i.seo)?(t.invalidateQueries({queryKey:[y.GET_LANGUAGE_PAGES,i==null?void 0:i.primaryPage]}),t.invalidateQueries({queryKey:[y.GET_WEBSITE_PAGES]})):t.invalidateQueries({queryKey:[y.GET_WEBSITE_PAGES]})},onError:(a,i)=>{const l=p.find(r,{key:i.pageType});R.toast.error(`Failed to update ${l!=null&&l.hasSlug?"page":l.name}.`,{description:a.message})}})},Ia=()=>{const e=j(),t=x.useQueryClient(),s=G(),{data:n}=be();return x.useMutation({mutationFn:async r=>s(e,{action:y.DELETE_PAGE,data:{id:r==null?void 0:r.id}}),onSuccess:(r,a)=>{if(r.code==="PAGE_LOCKED"){R.toast.error("Delete not allowed",{description:"Page is currently being edited by another user."});return}a&&(a!=null&&a.primaryPage)?(t.invalidateQueries({queryKey:[y.GET_LANGUAGE_PAGES,a==null?void 0:a.primaryPage]}),t.invalidateQueries({queryKey:[y.GET_WEBSITE_PAGES]})):t.invalidateQueries({queryKey:[y.GET_WEBSITE_PAGES]})},onError:(r,a)=>{const i=p.find(n,{key:a.pageType});R.toast.error(`Failed to delete ${i!=null&&i.hasSlug?"page":i.name}.`,{description:r.message})}})},Na=()=>{const e=j(),t=G(),{data:s}=be(),{handleQuerySync:n}=Lt();return x.useMutation({mutationFn:async r=>t(e,{action:y.TAKE_OFFLINE,data:{id:r==null?void 0:r.id}}),onSuccess:(r,a)=>{n({type:"UNPUBLISH_PAGE",data:{pageId:a==null?void 0:a.id,primaryPage:a==null?void 0:a.primaryPage},sync:!0});const i=p.find(s,{key:a.pageType});R.toast.success(i!=null&&i.hasSlug?"Page unpublished successfully.":"New "+i.name+" added successfully.")},onError:(r,a)=>{const i=p.find(s,{key:a.pageType});R.toast.error(`Failed to take offline ${i!=null&&i.hasSlug?"page":i.name}.`,{description:r.message})}})},mn=()=>{const e=j(),t=G(),{savePageAsync:s}=g.useSavePage(),n=gn(),{handleQuerySync:r}=Lt();return x.useMutation({mutationFn:async({ids:a})=>(await s(),t(e,{action:y.PUBLISH_CHANGES,data:{ids:a,revisions:n}})),onSuccess:(a,{ids:i})=>{r({type:"PUBLISH_CHANGES",data:{ids:i},sync:!0})},onError:a=>{console.log("##",a),R.toast.error("Failed to publish pages.")}})},La=()=>{const e=j(),t=G(),s=x.useQueryClient();return x.useMutation({mutationFn:async n=>{var r;return t(e,{action:y.MARK_AS_TEMPLATE,data:{id:(r=n.page)==null?void 0:r.id,name:n.name,description:n.description,pageType:n.pageType,previewImage:n.previewImage}})},onSuccess:()=>{s.invalidateQueries({queryKey:[y.GET_WEBSITE_PAGES]}),R.toast.success("Page marked as template successfully.")},onError:()=>{R.toast.error("Failed to mark page as template.")}})},ja=()=>{const e=j(),t=G(),s=x.useQueryClient();return x.useMutation({mutationFn:async n=>t(e,{action:y.UNMARK_AS_TEMPLATE,data:{id:n==null?void 0:n.id}}),onSuccess:()=>{s.invalidateQueries({queryKey:[y.GET_WEBSITE_PAGES]}),R.toast.success("Page unmarked as template successfully.")},onError:()=>{R.toast.error("Failed to unmark page as template.")}})},ka=()=>{const e=j(),t=G(),s=x.useQueryClient();return x.useMutation({mutationFn:async({id:n,slug:r})=>t(e,{action:y.CHANGE_SLUG,data:{id:n,slug:r}}),onSuccess:(n,{primaryPage:r})=>{R.toast.success("Slug changed successfully."),r?s.invalidateQueries({queryKey:[y.GET_LANGUAGE_PAGES,r]}):s.invalidateQueries({queryKey:[y.GET_WEBSITE_PAGES]})},onError:()=>{R.toast.error("Failed to change slug")}})},Da=f.lazy(()=>Promise.resolve().then(()=>require("./publish-pages-content-BCkzDZSc.cjs")));function Ga({showModal:e=!1,onClose:t=()=>console.log("Cancelled")}){const{mutate:s,isPending:n}=mn();return o.jsx(g.Dialog,{open:e,onOpenChange:n?()=>{}:t,children:e&&o.jsx(f.Suspense,{fallback:o.jsx("div",{className:"h-96 w-96 animate-pulse bg-gray-100"}),children:o.jsx(Da,{onClose:t,isPending:n,publishPage:s})})})}const Oa=()=>{const[e]=g.useBlocksStore(),{data:t}=we();return f.useCallback(()=>{if(!t)return{ids:[],names:[],partialBlocksInfo:[]};const n=p.filter(e,c=>c._type==="PartialBlock"),r=p.uniq(p.compact(n.map(c=>p.get(c,"partialBlockId","")))),a=p.compact(r.map(c=>{const d=p.find(t,{id:c});if(!d)return null;if(d.online){if(!p.isEmpty(d.changes))return{id:d.id,name:d.name||d.slug||d.id,status:"unpublished_changes"}}else return{id:d.id,name:d.name||d.slug||d.id,status:"unpublished"};return null})),i=a.map(c=>c.id),l=a.map(c=>c.name);return{ids:i,names:l,partialBlocksInfo:a}},[e,t])},En=e=>{const{fallbackLang:t}=g.useLanguages(),{data:s}=_e(),{data:n,isFetching:r}=Nt(),a=f.useMemo(()=>{const i={[t]:!0};return p.each(p.get(s,"languages"),l=>{const c=p.find(n,{lang:l});i[l]=!!c}),i},[t,n,s]);return r||p.isEmpty(e)||e&&a[e]},Ra=()=>{const{data:e,isLoading:t}=_e(),s=e==null?void 0:e.appChanges,n=s==null?void 0:s.includes("THEME"),r=s==null?void 0:s.includes("DESIGN_TOKENS");return{hasUnpublishedSettings:n||r,hasUnpublishedTheme:n,hasUnpublishedDesignToken:r,isLoading:t}},Ma={particleCount:350,spread:120,origin:{y:.6},angle:90},Ua={TOP_RIGHT:{angle:225,origin:{x:.9,y:0}},BOTTOM_RIGHT:{angle:100,origin:{x:.9,y:.9}}},Ba=async()=>{const{default:e}=await import("canvas-confetti");return e},at=e=>{let t=Ua[e];t||(t={});const s={...Ma,...t};Ba().then(n=>n(s))};function et({children:e,content:t,side:s="bottom",delayDuration:n=700,showTooltip:r=!0}){return r?o.jsx(g.TooltipProvider,{children:o.jsxs(g.Tooltip,{delayDuration:n,children:[o.jsx(g.TooltipTrigger,{asChild:!0,children:e}),o.jsx(g.TooltipContent,{side:s,sideOffset:10,children:o.jsx("p",{children:t})})]})}):e}const Fa=f.lazy(()=>Promise.resolve().then(()=>require("./unpublish-page-C4v2-E5K.cjs"))),Ha=f.lazy(()=>Promise.resolve().then(()=>require("./translation-warning-modal-CiXMjMs-.cjs"))),qa=f.lazy(()=>Promise.resolve().then(()=>require("./unpublished-partials-modal-D1HuPwGr.cjs"))),Bs=f.lazy(()=>Promise.resolve().then(()=>require("./json-diff-viewer-LIr31DRU.cjs"))),Va=()=>{const{t:e}=oe.useTranslation(),{selectedLang:t,fallbackLang:s}=g.useLanguages(),n=re("getPreviewUrl",async E=>E),[r,a]=f.useState(""),{data:i}=se(),{data:l}=Nt(),{data:c}=be(),d=f.useMemo(()=>{var E;return(E=l==null?void 0:l.find(m=>(m==null?void 0:m.lang)===t))==null?void 0:E.slug},[t,l]),h=f.useCallback(E=>{var m;return(m=p.find(c,{key:E}))==null?void 0:m.hasSlug},[c]),u=t===s?"":t;return f.useEffect(()=>{(async()=>{if(typeof n=="function"){const E=!h(i==null?void 0:i.pageType),m=await n(E?`/_partial/${u!==""?u+"/":""}${i==null?void 0:i.id}`:d||"");a(m)}else a("")})()},[n,d,i==null?void 0:i.pageType,h,i==null?void 0:i.id,u]),o.jsxs(o.Fragment,{children:[o.jsx(et,{content:e("Open preview in new tab"),delayDuration:0,children:o.jsx("a",{href:r,target:"_blank",rel:"noopener noreferrer",children:o.jsx(v.Button,{variant:"ghost",size:"sm",className:"gap-2",children:o.jsx(_.Play,{className:"h-4 w-4"})})})}),o.jsx("div",{className:"h-4 w-px bg-gray-200"})]})},Ka=()=>{const{t:e}=oe.useTranslation(),[t,s]=g.useRightPanel();return o.jsxs(o.Fragment,{children:[o.jsx(et,{content:e("Theme"),delayDuration:0,children:o.jsx(v.Button,{variant:t==="theme"?"outline":"ghost",size:"icon",className:"gap-2",onClick:()=>s(t==="theme"?"block":"theme"),children:o.jsx(_.Palette,{className:"h-4 w-4"})})}),o.jsx("div",{className:"h-4 w-px bg-gray-200"})]})},Qa=()=>{const{t:e}=oe.useTranslation(),[t,s]=f.useState(!1),{isLocked:n}=de(),{savePageAsync:r,saveState:a}=g.useSavePage();f.useEffect(()=>{const h=u=>{a==="UNSAVED"&&(u.preventDefault(),u.returnValue=!1)};return a==="UNSAVED"&&window.addEventListener("beforeunload",h),()=>{window.removeEventListener("beforeunload",h)}},[a]);const i=f.useCallback(async()=>{t||(s(!0),await r(),s(!1))},[r,t]),{buttonIcon:l,buttonClass:c,tooltipContent:d}=f.useMemo(()=>{switch(a){case"UNSAVED":return{tooltipContent:e("Save draft"),buttonIcon:o.jsx(_.Save,{className:"h-4 w-4"}),buttonClass:"gap-x-1"};case"SAVING":return{tooltipContent:e("Saving"),buttonIcon:o.jsx(_.Loader,{className:"h-4 w-4 animate-spin text-sky-700"}),buttonClass:"gap-x-1"};case"SAVED":return{tooltipContent:e("Saved"),buttonIcon:o.jsx(_.CheckCircle,{className:"h-4 w-4"}),buttonClass:"text-green-500 gap-x-1"}}},[a,e]);return n?null:o.jsx(et,{content:d,children:o.jsx(v.Button,{size:"sm",variant:"ghost",onClick:i,className:`${c}`,children:l})})},za=()=>{const{t:e}=oe.useTranslation(),{selectedLang:t}=g.useLanguages(),{data:s}=pe(),n=Oa(),[r,a]=f.useState(!1),[i,l]=f.useState(!1),[c,d]=f.useState(null),[h,u]=f.useState(!1),{savePageAsync:E}=g.useSavePage(),[m,A]=f.useState(!1),{hasUnpublishedSettings:b,hasUnpublishedTheme:L,hasUnpublishedDesignToken:T}=Ra(),[S,N]=f.useState(!1),[Q,K]=f.useState([]),[F,le]=f.useState([]),[ne,H]=f.useState(null),{data:P}=se(),{mutate:I,isPending:M}=mn(),{needTranslations:z}=g.useSavePage(),ae=z(),{buttonText:st,buttonClassName:fe,isPublished:ce,hasUnpublishedChanges:he}=f.useMemo(()=>{const te=P&&(P==null?void 0:P.online),ie=!p.isEmpty(P==null?void 0:P.changes);let Gt=te?"hover:bg-green-600 bg-green-500":"",Gs=e(te?"Published":"Publish");return te&&ie&&(Gt="hover:bg-blue-600 bg-blue-500",Gs=e("Publish")),{buttonClassName:Gt,isPublished:te,hasUnpublishedChanges:ie,buttonText:Gs}},[P,e]),ss=async()=>{if(ae){A(!0);return}Ne([s==null?void 0:s.id,s==null?void 0:s.primaryPage])},ns=te=>{const ie=[s==null?void 0:s.id,s==null?void 0:s.primaryPage,...Array.isArray(te)?te:[]];I({ids:p.compact(ie)},{onSuccess:()=>at("TOP_RIGHT")})},Ne=f.useCallback(te=>{const{ids:ie,partialBlocksInfo:Gt}=n();ie.length>0?(K(ie),le(Gt),N(!0)):I({ids:p.compact(te)},{onSuccess:()=>at("TOP_RIGHT")})},[n,I]),Dt=()=>{N(!1),ns(Q),K([]),le([])},Z=()=>{N(!1),K([]),le([])},Le=f.useCallback((te,ie)=>{H({id:te,name:ie})},[]),rs=()=>{A(!1),Ne([s==null?void 0:s.id,s==null?void 0:s.primaryPage])},as=async()=>{A(!1),await E()};return o.jsxs(o.Fragment,{children:[o.jsxs("div",{className:"flex",children:[o.jsxs(v.Button,{size:"sm",onClick:ss,disabled:M||!(P!=null&&P.id),className:`relative flex items-center gap-1 overflow-hidden rounded-r-none text-white transition-all duration-300 ease-in-out ${fe}`,onMouseEnter:()=>l(!0),onMouseLeave:()=>l(!1),children:[o.jsx("span",{className:`flex items-center transition-transform duration-300 ease-in-out ${i?"-translate-y-10":""}`,children:ce?he?o.jsx(_.Pencil,{className:"h-4 w-4"}):o.jsx(_.Send,{className:"h-4 w-4"}):o.jsx(_.Rocket,{className:"h-4 w-4"})}),o.jsx("span",{className:`absolute inset-0 left-3 flex items-center transition-transform duration-300 ease-in-out ${i?"":"translate-y-10"}`,children:ce?o.jsx(_.Rocket,{className:"h-4 w-4"}):o.jsx(_.Send,{className:"h-4 w-4"})}),o.jsx("span",{children:st}),t?`(${p.upperCase(t)})`:""]}),o.jsxs(g.DropdownMenu,{children:[o.jsx(g.DropdownMenuTrigger,{asChild:!0,children:o.jsxs(v.Button,{size:"sm",disabled:M||!(P!=null&&P.id),className:`relative rounded-l-none border-l border-white/50 px-2 text-white ${b?"bg-gray-500 hover:bg-gray-600":fe}`,children:[o.jsx(_.ChevronDown,{className:"h-4 w-4"}),b&&o.jsxs(o.Fragment,{children:[o.jsx("span",{className:"absolute -right-0.5 -top-0.5 h-2 w-2 rounded-full bg-orange-500"}),o.jsx("span",{className:"absolute -right-0.5 -top-0.5 h-2 w-2 animate-ping rounded-full bg-orange-500"})]})]})}),o.jsxs(g.DropdownMenuContent,{align:"end",className:"w-60",children:[o.jsx(g.DropdownMenuLabel,{className:"-mt-1 text-xs font-light text-gray-600",children:e("Page")}),ce&&he&&o.jsxs(g.DropdownMenuItem,{onClick:()=>u(!0),className:"cursor-pointer text-xs",children:[o.jsx(_.Eye,{className:"mr-0.5 h-3 w-3"}),e("View Unpublished changes")]}),!ce&&o.jsxs(g.DropdownMenuItem,{disabled:M,className:"cursor-pointer text-xs",onClick:()=>Ne([P==null?void 0:P.id]),children:[e("Publish")," page"]}),ce&&o.jsxs(g.DropdownMenuItem,{onClick:()=>d(s),className:"cursor-pointer text-xs",children:[o.jsx(_.TriangleAlert,{className:"mr-0.5 h-3 w-3"}),e("Unpublish")," page ",t?`(${p.upperCase(t)})`:""]}),b&&o.jsxs(o.Fragment,{children:[o.jsx(g.DropdownMenuSeparator,{className:"bg-gray-200"}),o.jsx(g.DropdownMenuLabel,{className:"-mt-1 text-xs font-light text-gray-600",children:e("Unpublished website settings")})]}),L&&o.jsx(g.DropdownMenuItem,{disabled:M,className:"cursor-pointer text-xs",onClick:()=>I({ids:["THEME"]},{onSuccess:()=>at("TOP_RIGHT")}),children:o.jsxs("span",{className:"flex h-full w-full items-center gap-2",children:[o.jsx("span",{className:"mt-0.5 h-1 w-1 animate-pulse rounded-full bg-orange-500"}),e("Publish")," theme"]})}),T&&o.jsx(g.DropdownMenuItem,{disabled:M,className:"cursor-pointer text-xs",onClick:()=>I({ids:["DESIGN_TOKENS"]},{onSuccess:()=>at("TOP_RIGHT")}),children:o.jsxs("span",{className:"flex h-full w-full items-center gap-2",children:[o.jsx("span",{className:"mt-0.5 h-1 w-1 animate-pulse rounded-full bg-orange-500"}),e("Publish")," design token"]})})]})]})]}),o.jsx(Ga,{showModal:r,onClose:()=>a(!1)}),c&&o.jsx(f.Suspense,{children:o.jsx(Fa,{page:c,onClose:()=>d(null)})}),h&&o.jsx(f.Suspense,{children:o.jsx(Bs,{open:h,onOpenChange:u,compare:[{label:"live",uid:`live:${P==null?void 0:P.id}`,item:{}},{label:"draft",uid:`draft:${P==null?void 0:P.id}`,item:P}]})}),m&&o.jsx(f.Suspense,{children:o.jsx(Ha,{isOpen:m,onClose:as,onContinue:rs,isPending:M})}),S&&o.jsx(f.Suspense,{children:o.jsx(qa,{isOpen:S,onClose:Z,onContinue:Dt,onViewChanges:Le,isPending:M,partialBlocksInfo:F})}),ne&&o.jsx(f.Suspense,{children:o.jsx(Bs,{open:!!ne,onOpenChange:te=>{te||(H(null),N(!0))},compare:[{label:"live",uid:`live:${ne.id}`,item:{}},{label:"draft",uid:`draft:${ne.id}`,item:{}}]})})]})},$a=()=>{const{t:e}=oe.useTranslation(),{data:t}=se(),s=Rr();return(t==null?void 0:t.online)?o.jsx(et,{content:e("Open live page"),delayDuration:0,children:o.jsx("a",{href:s,target:"_blank",rel:"noopener noreferrer",children:o.jsx(v.Button,{variant:"ghost",size:"icon",className:"ml-1 h-8 w-8",children:o.jsx(_.ExternalLink,{className:"h-4 w-4"})})})}):null};function Wa(){const{isLocked:e}=de(),[t]=Ee(),s=t.get("lang"),n=En(s),r=gn();return e||!n?o.jsx("div",{}):o.jsxs("div",{className:"flex items-center justify-end gap-1",children:[r&&o.jsx(wa,{}),o.jsx(Ut,{permission:ue.EDIT_THEME,children:o.jsx(Ka,{})}),o.jsx(Va,{}),o.jsx(Ut,{permission:ue.SAVE_PAGE,children:o.jsx(Qa,{})}),o.jsx(Ut,{permission:ue.PUBLISH_PAGE,children:o.jsx(za,{})}),o.jsx($a,{})]})}const Ja=f.lazy(()=>Promise.resolve().then(()=>require("./page-manager-new-DhK74o43.cjs"))),Ya=({children:e})=>{const{t}=oe.useTranslation(),[s]=Ee(),n=s.get("page"),{data:r,isFetching:a}=se(),{data:i,isFetching:l}=we(),[c,d]=f.useState(!1),[h,u]=f.useState(!0),{savePage:E}=g.useSavePage(),m=!!n&&!p.isEmpty(r),{isLocked:A}=de();f.useEffect(()=>{!l&&i&&u(!1)},[l,i]);const b=!h&&!n,L=!h&&!a&&p.isEmpty(r),T=c||b||L;return o.jsxs(o.Fragment,{children:[o.jsxs(g.Tooltip,{children:[o.jsx(g.TooltipTrigger,{asChild:!0,onClick:()=>{A||E(),d(!0)},children:e||o.jsxs(v.Button,{variant:"ghost",className:"flex w-full items-center justify-center rounded-md p-2 pl-0",children:[o.jsx(_.Folder,{className:"ml-2 h-10 w-10 fill-primary text-primary"}),o.jsx("div",{className:"flex flex-col items-start",children:o.jsx("span",{className:"text-sm font-semibold",children:t("Pages")})})]},"template-viewer")}),o.jsx(g.TooltipContent,{side:"right",children:o.jsx("p",{children:t("Open pages manager")})})]}),o.jsx(g.Sheet,{open:T,onOpenChange:S=>!S&&m&&d(!1),children:o.jsxs(g.SheetContent,{side:"left","aria-describedby":"pages-manager-description",className:`z-50 !min-w-[50vh] !max-w-[800px] border-border p-0 ${m?"":"sheet-hide-close-btn"}`,children:[o.jsxs(g.SheetHeader,{className:"mb-3 px-4 pt-4",children:[o.jsxs(g.SheetTitle,{className:"flex items-center gap-2 text-sm font-semibold",children:[o.jsx("div",{className:"flex h-9 w-9 items-center justify-center rounded-lg bg-primary text-primary-foreground",children:o.jsx(_.Folder,{className:"h-4 w-4"})}),o.jsxs("div",{className:"flex flex-col",children:[o.jsx("span",{className:"text-sm font-semibold",children:t("Pages")}),o.jsx("span",{id:"pages-manager-description",className:"text-xs font-normal text-muted-foreground",children:t("Manage your site structure")})]})]}),o.jsx(g.SheetDescription,{className:"sr-only",children:t("Manage your site structure")})]}),o.jsx("div",{className:"h-[calc(100vh-80px)] overflow-y-auto",children:T&&o.jsx(f.Suspense,{children:o.jsx(Ja,{close:()=>d(!1)})})})]})})]})},Za=f.lazy(()=>Promise.resolve().then(()=>require("./dynamic-page-selector-CEHpm0rg.cjs"))),Xa=()=>{const{dynamicPage:e,allLangPages:t,isFetching:s}=rn(),n=t.length>0;return s?null:o.jsxs("div",{className:"relative",children:[!e&&o.jsx(Aa,{hasDynamicPage:n}),o.jsx(f.Suspense,{children:o.jsx(Za,{})})]})},ei=()=>{const{isFetching:e}=pe(),{data:t,isFetching:s}=se(),n=p.get(t,"dynamic",!1),r=v.useChaiFeatureFlag("dynamic-page-selector"),a=e||s;return o.jsxs("div",{className:"relative flex items-center",children:[o.jsxs("div",{className:"flex items-center",children:[o.jsx("div",{className:Ht.cn("flex h-8 items-center",a&&"max-w-0 overflow-hidden opacity-0"),children:o.jsx(Ya,{})}),o.jsx(_.ChevronRight,{className:"mx-1 h-3 w-3 flex-shrink-0 text-gray-400"}),o.jsx("div",{className:Ht.cn("flex h-8 items-center",a&&"max-w-0 overflow-hidden opacity-0"),children:o.jsx(ya,{})})]}),n&&r&&o.jsx(Xa,{})]})},ti=()=>o.jsxs("div",{className:"grid h-full w-full grid-cols-3 items-center px-2",children:[o.jsxs("div",{className:"flex justify-start",children:[o.jsx(Pa,{}),o.jsx(ei,{})]}),o.jsx("div",{className:"flex justify-center",children:o.jsx(Nr,{})}),o.jsxs("div",{className:"flex items-center justify-end",children:[o.jsx(hn,{}),o.jsx(Wa,{})]})]}),si=()=>{const e=x.useQueryClient(),{data:t}=x.useQuery({queryKey:[y.AI_CONTEXT],initialData:"",queryFn:()=>"",staleTime:0});return{setAiContext:f.useCallback(n=>{e.setQueryData([y.AI_CONTEXT],n)},[e]),aiContext:t}},ni=()=>{const e=j(),{aiContext:t}=si(),s=G();return f.useCallback(async(n,r,a,i)=>s(e,{action:y.ASK_AI,data:{type:n,prompt:r,blocks:a,context:t,lang:i}}),[e,t,s])},ri=e=>f.useMemo(()=>{if(!e||p.isEmpty(e))return{blocks:[]};const t=p.filter(e,s=>!p.includes(s==null?void 0:s._type,"@chai/"));return{blocks:wr.syncBlocksWithDefaultProps(t)}},[e]),pn=()=>{const[e]=Ee(),t=e.get("page"),s=j(),n=G(),r=x.useQueryClient(),{data:a}=se(),{data:i}=pe(),l=Yt(),c=xs();return x.useQuery({queryKey:[y.GET_PAGE_ALL_DATA,t,i==null?void 0:i.id,c],staleTime:1/0,gcTime:0,queryFn:async()=>{const d=await n(s,{action:y.GET_PAGE_ALL_DATA,data:{id:t,lang:(i==null?void 0:i.lang)||l,pageType:a==null?void 0:a.pageType,pageProps:{slug:(i==null?void 0:i.slug)+c,searchParams:{},pageType:i==null?void 0:i.pageType,fallbackLang:l,lastSaved:i==null?void 0:i.lastSaved,pageId:a==null?void 0:a.id,primaryPageId:(i==null?void 0:i.primaryPage)||(a==null?void 0:a.id),pageBaseSlug:i==null?void 0:i.slug,dynamic:a==null?void 0:a.dynamic,languagePageId:i==null?void 0:i.id,metadata:(a==null?void 0:a.metadata)||{}}}});return r.setQueryData([y.GET_BUILDER_PAGE_DATA,i==null?void 0:i.id,c],d.builderPageData),r.setQueryData([y.GET_LANGUAGE_PAGES,t],d.languagePages),d},enabled:!!t&&!!(a!=null&&a.pageType)&&!!(i!=null&&i.id)})},ai=()=>{const e=j(),t=G(),{handleQuerySync:s}=Lt();return x.useMutation({mutationFn:async n=>t(e,{action:y.UPDATE_WEBSITE_FIELDS,data:n}),onSuccess:(n,r)=>{s({type:"UPDATE_WEBSITE_DATA",data:r,sync:!0})},onError:n=>{R.toast.error("Failed to update website settings",{description:n.message})}})},ii=()=>{const e=j(),t=x.useQueryClient(),s=G(),{selectedLang:n}=g.useLanguages();return x.useMutation({mutationFn:async r=>s(e,{action:y.ADD_GLOBAL_SCHEMA,data:{...r,lang:n}}),onSuccess:()=>{t.invalidateQueries({queryKey:[y.GET_GLOBAL_JSONLD_ITEMS]}),R.toast.success("Schema added successfully.")},onError:r=>{R.toast.error("Failed to add schema",{description:r.message})}})},oi=()=>{const e=j(),t=x.useQueryClient(),s=G(),{selectedLang:n}=g.useLanguages();return x.useMutation({mutationFn:async r=>s(e,{action:y.UPDATE_GLOBAL_SCHEMA,data:{...r,lang:n}}),onSuccess:()=>{t.invalidateQueries({queryKey:[y.GET_GLOBAL_JSONLD_ITEMS]}),R.toast.success("Schema updated successfully.")},onError:r=>{R.toast.error("Failed to update schema",{description:r.message})}})},li=()=>{const e=j(),t=x.useQueryClient(),s=G();return x.useMutation({mutationFn:async n=>s(e,{action:y.DELETE_GLOBAL_SCHEMA,data:{id:n}}),onSuccess:()=>{t.invalidateQueries({queryKey:[y.GET_GLOBAL_JSONLD_ITEMS]}),R.toast.success("Schema deleted successfully.")},onError:n=>{R.toast.error("Failed to delete schema",{description:n.message})}})},ci=()=>{const e=j(),t=G();return x.useMutation({mutationFn:async s=>t(e,{action:y.TOGGLE_PAGE_GLOBAL_SCHEMA,data:s}),onError:s=>{R.toast.error("Failed to toggle schema",{description:s.message})}})},ui=()=>{const e=j(),t=G();return x.useMutation({mutationFn:async s=>t(e,{action:y.APPLY_SCHEMA_TO_ALL_PAGES,data:{schemaId:s}}),onSuccess:s=>{R.toast.success(`Schema applied to ${s.count} page(s)`)},onError:s=>{R.toast.error("Failed to apply schema to all pages",{description:s.message})}})},di=()=>{const e=j(),t=G();return x.useMutation({mutationFn:async s=>t(e,{action:y.REMOVE_SCHEMA_FROM_ALL_PAGES,data:{schemaId:s}}),onSuccess:s=>{R.toast.success(`Schema removed from ${s.count} page(s)`)},onError:s=>{R.toast.error("Failed to remove schema from all pages",{description:s.message})}})},vs=(e=300)=>{const t=re("onLogout",p.noop),s=re("getAccessToken"),n=j();return x.useQuery({queryKey:["check-user-access"],queryFn:async()=>{const r=await s(),i=await sn(n+"?action=check_user_access",{action:"CHECK_USER_ACCESS"},{Authorization:`Bearer ${r}`});if(i.status===401)throw console.log("401 Response",i),R.toast.error("You do not have access to edit this website. Please contact administrator"),await t("UNAUTHORIZED"),new Error("Unauthorized");return await i.json()},refetchInterval:e*1e3,refetchIntervalInBackground:!0,retry:!1})},fi=()=>{const e=j(),t=G(),[,s]=on(),n=x.useQueryClient(),{handleQuerySync:r}=Lt();return{onSave:async({page:i,blocks:l,needTranslations:c,partialIds:d,linkPageIds:h,designTokens:u})=>{try{const E=await t(e,{action:"UPDATE_PAGE",data:{id:i,blocks:l,needTranslations:c}});return E.code==="PAGE_LOCKED"?!0:(s(m=>({...m,lastSaved:new Date().toISOString()})),n.setQueryData([y.GET_LANGUAGE_PAGES,i],m=>m&&(m==null?void 0:m.map(A=>(A==null?void 0:A.id)===i?{...A,changes:["Page"]}:A))),r({type:"UPDATE_PAGE_DATA",data:{pageId:i,partialIds:d,linkPageIds:h,designTokens:u},sync:!0}),E)}catch(E){return console.error(E),new Error("Failed to save blocks")}}}},hi=()=>{const{data:e}=we(),t=j(),s=G();return{getPartialBlocks:f.useCallback(async()=>{const n={};for(const r of e??[])p.isEmpty(r==null?void 0:r.slug)&&(n[r.id]={type:r.pageType,name:p.startCase(r.name??r.slug),description:""});return n},[e]),getPartialBlockBlocks:f.useCallback(async n=>{if(!n)return[];try{const r=await s(t,{action:"GET_DRAFT_PAGE",data:{id:n,draft:!0,editor:!1,mergePartials:!0}});return p.filter(r.blocks,a=>p.has(a,"_id"))}catch(r){return console.error(r),[]}},[s,t])}},gi=f.lazy(()=>Promise.resolve().then(()=>require("./ai-panel-content-C39F2hj1.cjs"))),yn="chai-chat-panel",mi=({className:e="h-full w-full"})=>o.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 512 512",version:"1.1",className:e,children:[o.jsx("title",{children:"ai"}),o.jsx("g",{id:"Page-1",stroke:"none",strokeWidth:"1",fill:"none",fillRule:"evenodd",children:o.jsx("g",{id:"icon",fill:"currentColor",transform:"translate(64.000000, 64.000000)",children:o.jsx("path",{d:"M320,64 L320,320 L64,320 L64,64 L320,64 Z M171.749388,128 L146.817842,128 L99.4840387,256 L121.976629,256 L130.913039,230.977 L187.575039,230.977 L196.319607,256 L220.167172,256 L171.749388,128 Z M260.093778,128 L237.691519,128 L237.691519,256 L260.093778,256 L260.093778,128 Z M159.094727,149.47526 L181.409039,213.333 L137.135039,213.333 L159.094727,149.47526 Z M341.333333,256 L384,256 L384,298.666667 L341.333333,298.666667 L341.333333,256 Z M85.3333333,341.333333 L128,341.333333 L128,384 L85.3333333,384 L85.3333333,341.333333 Z M170.666667,341.333333 L213.333333,341.333333 L213.333333,384 L170.666667,384 L170.666667,341.333333 Z M85.3333333,0 L128,0 L128,42.6666667 L85.3333333,42.6666667 L85.3333333,0 Z M256,341.333333 L298.666667,341.333333 L298.666667,384 L256,384 L256,341.333333 Z M170.666667,0 L213.333333,0 L213.333333,42.6666667 L170.666667,42.6666667 L170.666667,0 Z M256,0 L298.666667,0 L298.666667,42.6666667 L256,42.6666667 L256,0 Z M341.333333,170.666667 L384,170.666667 L384,213.333333 L341.333333,213.333333 L341.333333,170.666667 Z M0,256 L42.6666667,256 L42.6666667,298.666667 L0,298.666667 L0,256 Z M341.333333,85.3333333 L384,85.3333333 L384,128 L341.333333,128 L341.333333,85.3333333 Z M0,170.666667 L42.6666667,170.666667 L42.6666667,213.333333 L0,213.333333 L0,170.666667 Z M0,85.3333333 L42.6666667,85.3333333 L42.6666667,128 L0,128 L0,85.3333333 Z",id:"Combined-Shape"})})})]}),Ei=({isActive:e,show:t})=>g.useBuilderProp("flags.ai",!1)?o.jsx(v.Button,{size:"icon",className:"p-0 [&_svg]:size-6",onClick:t,variant:e?"default":"ghost",children:o.jsx(mi,{className:e?"h-5 w-5 text-white":"h-5 w-5 text-primary"})}):null,pi={id:yn,label:"AI Assistant",button:Ei,panel:gi,position:"top"},yi=f.lazy(()=>Promise.resolve().then(()=>require("./lang-panel-xrs5AMiU.cjs"))),Ai=({isActive:e,show:t})=>{const{data:s}=_e();return!p.has(s,"languages")||!p.get(s,"languages",[]).length?null:o.jsx(v.Button,{size:"sm",onClick:t,variant:e?"default":"ghost",children:o.jsx(_.LanguagesIcon,{className:"h-4 w-4"})})},An="lang",Ti={id:An,label:"Languages",position:"top",panel:yi,button:Ai,view:"modal",width:400},Si=f.lazy(()=>Promise.resolve().then(()=>require("./seo-panel-BxN785dG.cjs"))),Tn="seo",Pi=({isActive:e,show:t})=>{const{data:s}=se(),n=ln(s==null?void 0:s.pageType);return!p.has(n,"hasSlug")||!n.hasSlug?null:o.jsx(v.Button,{size:"icon",className:"my-1 p-0",onClick:t,variant:e?"default":"ghost",children:o.jsxs("svg",{stroke:"currentColor",fill:"none",style:{height:"20px",width:"20px"},strokeWidth:"2",viewBox:"0 0 24 24",strokeLinecap:"round",strokeLinejoin:"round",children:[o.jsx("path",{d:"M7 8h-3a1 1 0 0 0 -1 1v2a1 1 0 0 0 1 1h2a1 1 0 0 1 1 1v2a1 1 0 0 1 -1 1h-3"}),o.jsx("path",{d:"M14 16h-4v-8h4"}),o.jsx("path",{d:"M11 12h2"}),o.jsx("path",{d:"M17 8m0 1a1 1 0 0 1 1 -1h2a1 1 0 0 1 1 1v6a1 1 0 0 1 -1 1h-2a1 1 0 0 1 -1 -1z"})]})})},xi={id:Tn,label:"SEO",panel:Si,button:Pi,position:"top",width:600,view:"modal"},_i=f.lazy(()=>Promise.resolve().then(()=>require("./change-password-modal-xBIyXsLV.cjs")).then(e=>({default:e.ChangePasswordModal}))),Sn="user-info",wi=()=>{const{t:e}=oe.useTranslation(),{user:t,logout:s}=Zt(),n=re("onLogout",p.noop),[r,a]=f.useState(!1);return t?o.jsxs(g.HoverCard,{children:[o.jsx(g.HoverCardTrigger,{asChild:!0,children:o.jsx(v.Button,{variant:"ghost",className:"text-sm font-medium",children:o.jsx(_.User,{className:"h-4 w-4"})})}),o.jsxs(g.HoverCardContent,{className:"w-auto space-y-2 p-4",children:[o.jsx("div",{className:"text-sm font-medium",children:t.name??t.email}),o.jsx("div",{className:"text-xs text-muted-foreground",children:t.email}),o.jsx(v.Button,{variant:"outline",size:"sm",className:"w-full",onClick:()=>a(!0),children:e("Change Password")}),r&&o.jsx(f.Suspense,{fallback:o.jsx(g.Dialog,{open:r,onOpenChange:a,children:o.jsx(g.DialogContent,{className:"sm:max-w-[425px]",children:o.jsx("div",{className:"flex h-[340px] items-center justify-center",children:o.jsx(_.Loader,{className:"h-8 w-8 animate-spin text-muted-foreground"})})})}),children:o.jsx(_i,{open:r,onOpenChange:a})}),o.jsxs(g.AlertDialog,{children:[o.jsx(g.AlertDialogTrigger,{asChild:!0,children:o.jsx(v.Button,{variant:"outline",size:"sm",className:"w-full",children:e("Logout")})}),o.jsxs(g.AlertDialogContent,{children:[o.jsxs(g.AlertDialogHeader,{children:[o.jsx(g.AlertDialogTitle,{children:e("Are you sure you want to logout?")}),o.jsx(g.AlertDialogDescription,{children:e("You will be redirected to the login page.")})]}),o.jsxs(g.AlertDialogFooter,{children:[o.jsx(g.AlertDialogCancel,{children:e("Cancel")}),o.jsx(g.AlertDialogAction,{onClick:()=>{s(),p.isFunction(n)&&n()},children:e("Logout")})]})]})]})]})]}):null},bi={id:Sn,label:"User Info",button:wi,position:"bottom"},Ci=()=>{v.registerChaiSidebarPanel(Tn,xi),v.registerChaiSidebarPanel(An,Ti),v.registerChaiSidebarPanel(Sn,bi),v.registerChaiSidebarPanel(yn,pi)};var C={context:void 0,registry:void 0,effects:void 0,done:!1,getContextId(){return Fs(this.context.count)},getNextContextId(){return Fs(this.context.count++)}};function Fs(e){const t=String(e),s=t.length-1;return C.context.id+(s?String.fromCharCode(96+s):"")+t}function it(e){C.context=e}var Pn=!1,vi=(e,t)=>e===t,qt=Symbol("solid-proxy"),xn=typeof Proxy=="function",Is=Symbol("solid-track"),Vt={equals:vi},_n=jn,Ae=1,Kt=2,wn={owned:null,cleanups:null,context:null,owner:null},cs={},D=null,us=null,Ii=null,U=null,ee=null,ye=null,Xt=0;function Se(e,t){const s=U,n=D,r=e.length===0,a=t===void 0?n:t,i=r?wn:{owned:null,cleanups:null,context:a?a.context:null,owner:a},l=r?e:()=>e(()=>Y(()=>ft(i)));D=i,U=null;try{return me(l,!0)}finally{U=s,D=n}}function q(e,t){t=t?Object.assign({},Vt,t):Vt;const s={value:e,observers:null,observerSlots:null,comparator:t.equals||void 0},n=r=>(typeof r=="function"&&(r=r(s.value)),Ln(s,r));return[Nn.bind(s),n]}function bn(e,t,s){const n=es(e,t,!0,Ae);tt(n)}function Pe(e,t,s){const n=es(e,t,!1,Ae);tt(n)}function Ns(e,t,s){_n=Hi;const n=es(e,t,!1,Ae);(!s||!s.render)&&(n.user=!0),ye?ye.push(n):tt(n)}function J(e,t,s){s=s?Object.assign({},Vt,s):Vt;const n=es(e,t,!0,0);return n.observers=null,n.observerSlots=null,n.comparator=s.equals||void 0,tt(n),Nn.bind(n)}function Ni(e){return e&&typeof e=="object"&&"then"in e}function Li(e,t,s){let n,r,a;n=!0,r=e,a={};let i=null,l=cs,c=null,d=!1,h="initialValue"in a,u=typeof n=="function"&&J(n);const E=new Set,[m,A]=(a.storage||q)(a.initialValue),[b,L]=q(void 0),[T,S]=q(void 0,{equals:!1}),[N,Q]=q(h?"ready":"unresolved");C.context&&(c=C.getNextContextId(),a.ssrLoadFrom==="initial"?l=a.initialValue:C.load&&C.has(c)&&(l=C.load(c)));function K(P,I,M,z){return i===P&&(i=null,z!==void 0&&(h=!0),(P===l||I===l)&&a.onHydrated&&queueMicrotask(()=>a.onHydrated(z,{value:I})),l=cs,F(I,M)),I}function F(P,I){me(()=>{I===void 0&&A(()=>P),Q(I!==void 0?"errored":h?"ready":"unresolved"),L(I);for(const M of E.keys())M.decrement();E.clear()},!1)}function le(){const P=Ui,I=m(),M=b();if(M!==void 0&&!i)throw M;return U&&U.user,I}function ne(P=!0){if(P!==!1&&d)return;d=!1;const I=u?u():n;if(I==null||I===!1){K(i,Y(m));return}let M;const z=l!==cs?l:Y(()=>{try{return r(I,{value:m(),refetching:P})}catch(ae){M=ae}});if(M!==void 0){K(i,void 0,Bt(M),I);return}else if(!Ni(z))return K(i,z,void 0,I),z;return i=z,"v"in z?(z.s===1?K(i,z.v,void 0,I):K(i,void 0,Bt(z.v),I),z):(d=!0,queueMicrotask(()=>d=!1),me(()=>{Q(h?"refreshing":"pending"),S()},!1),z.then(ae=>K(z,ae,void 0,I),ae=>K(z,void 0,Bt(ae),I)))}Object.defineProperties(le,{state:{get:()=>N()},error:{get:()=>b()},loading:{get(){const P=N();return P==="pending"||P==="refreshing"}},latest:{get(){if(!h)return le();const P=b();if(P&&!i)throw P;return m()}}});let H=D;return u?bn(()=>(H=D,ne(!1))):ne(!1),[le,{refetch:P=>vn(H,()=>ne(P)),mutate:A}]}function ji(e){return me(e,!1)}function Y(e){if(U===null)return e();const t=U;U=null;try{return e()}finally{U=t}}function ki(e,t,s){const n=Array.isArray(e);let r,a=s&&s.defer;return i=>{let l;if(n){l=Array(e.length);for(let d=0;d<e.length;d++)l[d]=e[d]()}else l=e();if(a)return a=!1,i;const c=Y(()=>t(l,r,i));return r=l,c}}function Cn(e){Ns(()=>Y(e))}function Ze(e){return D===null||(D.cleanups===null?D.cleanups=[e]:D.cleanups.push(e)),e}function Hs(){return D}function vn(e,t){const s=D,n=U;D=e,U=null;try{return me(t,!0)}catch(r){Ls(r)}finally{D=s,U=n}}function Di(e){const t=U,s=D;return Promise.resolve().then(()=>{U=t,D=s;let n;return me(e,!1),U=D=null,n?n.done:void 0})}var[Gi,Wl]=q(!1);function Oi(){return[Gi,Di]}function Ri(e,t){const s=Symbol("context");return{id:s,Provider:qi(s),defaultValue:e}}function Mi(e){let t;return D&&D.context&&(t=D.context[e.id])!==void 0?t:e.defaultValue}function In(e){const t=J(e),s=J(()=>hs(t()));return s.toArray=()=>{const n=s();return Array.isArray(n)?n:n!=null?[n]:[]},s}var Ui;function Nn(){if(this.sources&&this.state)if(this.state===Ae)tt(this);else{const e=ee;ee=null,me(()=>zt(this),!1),ee=e}if(U){const e=this.observers?this.observers.length:0;U.sources?(U.sources.push(this),U.sourceSlots.push(e)):(U.sources=[this],U.sourceSlots=[e]),this.observers?(this.observers.push(U),this.observerSlots.push(U.sources.length-1)):(this.observers=[U],this.observerSlots=[U.sources.length-1])}return this.value}function Ln(e,t,s){let n=e.value;return(!e.comparator||!e.comparator(n,t))&&(e.value=t,e.observers&&e.observers.length&&me(()=>{for(let r=0;r<e.observers.length;r+=1){const a=e.observers[r],i=us&&us.running;i&&us.disposed.has(a),(i?!a.tState:!a.state)&&(a.pure?ee.push(a):ye.push(a),a.observers&&kn(a)),i||(a.state=Ae)}if(ee.length>1e6)throw ee=[],new Error},!1)),t}function tt(e){if(!e.fn)return;ft(e);const t=Xt;Bi(e,e.value,t)}function Bi(e,t,s){let n;const r=D,a=U;U=D=e;try{n=e.fn(t)}catch(i){return e.pure&&(e.state=Ae,e.owned&&e.owned.forEach(ft),e.owned=null),e.updatedAt=s+1,Ls(i)}finally{U=a,D=r}(!e.updatedAt||e.updatedAt<=s)&&(e.updatedAt!=null&&"observers"in e?Ln(e,n):e.value=n,e.updatedAt=s)}function es(e,t,s,n=Ae,r){const a={fn:e,state:n,updatedAt:null,owned:null,sources:null,sourceSlots:null,cleanups:null,value:t,owner:D,context:D?D.context:null,pure:s};return D===null||D!==wn&&(D.owned?D.owned.push(a):D.owned=[a]),a}function Qt(e){if(e.state===0)return;if(e.state===Kt)return zt(e);if(e.suspense&&Y(e.suspense.inFallback))return e.suspense.effects.push(e);const t=[e];for(;(e=e.owner)&&(!e.updatedAt||e.updatedAt<Xt);)e.state&&t.push(e);for(let s=t.length-1;s>=0;s--)if(e=t[s],e.state===Ae)tt(e);else if(e.state===Kt){const n=ee;ee=null,me(()=>zt(e,t[0]),!1),ee=n}}function me(e,t){if(ee)return e();let s=!1;t||(ee=[]),ye?s=!0:ye=[],Xt++;try{const n=e();return Fi(s),n}catch(n){s||(ye=null),ee=null,Ls(n)}}function Fi(e){if(ee&&(jn(ee),ee=null),e)return;const t=ye;ye=null,t.length&&me(()=>_n(t),!1)}function jn(e){for(let t=0;t<e.length;t++)Qt(e[t])}function Hi(e){let t,s=0;for(t=0;t<e.length;t++){const n=e[t];n.user?e[s++]=n:Qt(n)}if(C.context){if(C.count){C.effects||(C.effects=[]),C.effects.push(...e.slice(0,s));return}it()}for(C.effects&&(C.done||!C.count)&&(e=[...C.effects,...e],s+=C.effects.length,delete C.effects),t=0;t<s;t++)Qt(e[t])}function zt(e,t){e.state=0;for(let s=0;s<e.sources.length;s+=1){const n=e.sources[s];if(n.sources){const r=n.state;r===Ae?n!==t&&(!n.updatedAt||n.updatedAt<Xt)&&Qt(n):r===Kt&&zt(n,t)}}}function kn(e){for(let t=0;t<e.observers.length;t+=1){const s=e.observers[t];s.state||(s.state=Kt,s.pure?ee.push(s):ye.push(s),s.observers&&kn(s))}}function ft(e){let t;if(e.sources)for(;e.sources.length;){const s=e.sources.pop(),n=e.sourceSlots.pop(),r=s.observers;if(r&&r.length){const a=r.pop(),i=s.observerSlots.pop();n<r.length&&(a.sourceSlots[i]=n,r[n]=a,s.observerSlots[n]=i)}}if(e.tOwned){for(t=e.tOwned.length-1;t>=0;t--)ft(e.tOwned[t]);delete e.tOwned}if(e.owned){for(t=e.owned.length-1;t>=0;t--)ft(e.owned[t]);e.owned=null}if(e.cleanups){for(t=e.cleanups.length-1;t>=0;t--)e.cleanups[t]();e.cleanups=null}e.state=0}function Bt(e){return e instanceof Error?e:new Error(typeof e=="string"?e:"Unknown error",{cause:e})}function Ls(e,t=D){throw Bt(e)}function hs(e){if(typeof e=="function"&&!e.length)return hs(e());if(Array.isArray(e)){const t=[];for(let s=0;s<e.length;s++){const n=hs(e[s]);Array.isArray(n)?t.push.apply(t,n):t.push(n)}return t}return e}function qi(e,t){return function(n){let r;return Pe(()=>r=Y(()=>(D.context={...D.context,[e]:n.value},In(()=>n.children))),void 0),r}}var gs=Symbol("fallback");function $t(e){for(let t=0;t<e.length;t++)e[t]()}function Vi(e,t,s={}){let n=[],r=[],a=[],i=0,l=t.length>1?[]:null;return Ze(()=>$t(a)),()=>{let c=e()||[],d=c.length,h,u;return c[Is],Y(()=>{let m,A,b,L,T,S,N,Q,K;if(d===0)i!==0&&($t(a),a=[],n=[],r=[],i=0,l&&(l=[])),s.fallback&&(n=[gs],r[0]=Se(F=>(a[0]=F,s.fallback())),i=1);else if(i===0){for(r=new Array(d),u=0;u<d;u++)n[u]=c[u],r[u]=Se(E);i=d}else{for(b=new Array(d),L=new Array(d),l&&(T=new Array(d)),S=0,N=Math.min(i,d);S<N&&n[S]===c[S];S++);for(N=i-1,Q=d-1;N>=S&&Q>=S&&n[N]===c[Q];N--,Q--)b[Q]=r[N],L[Q]=a[N],l&&(T[Q]=l[N]);for(m=new Map,A=new Array(Q+1),u=Q;u>=S;u--)K=c[u],h=m.get(K),A[u]=h===void 0?-1:h,m.set(K,u);for(h=S;h<=N;h++)K=n[h],u=m.get(K),u!==void 0&&u!==-1?(b[u]=r[h],L[u]=a[h],l&&(T[u]=l[h]),u=A[u],m.set(K,u)):a[h]();for(u=S;u<d;u++)u in b?(r[u]=b[u],a[u]=L[u],l&&(l[u]=T[u],l[u](u))):r[u]=Se(E);r=r.slice(0,i=d),n=c.slice(0)}return r});function E(m){if(a[u]=m,l){const[A,b]=q(u);return l[u]=b,t(c[u],A)}return t(c[u])}}}function Ki(e,t,s={}){let n=[],r=[],a=[],i=[],l=0,c;return Ze(()=>$t(a)),()=>{const d=e()||[],h=d.length;return d[Is],Y(()=>{if(h===0)return l!==0&&($t(a),a=[],n=[],r=[],l=0,i=[]),s.fallback&&(n=[gs],r[0]=Se(E=>(a[0]=E,s.fallback())),l=1),r;for(n[0]===gs&&(a[0](),a=[],n=[],r=[],l=0),c=0;c<h;c++)c<n.length&&n[c]!==d[c]?i[c](()=>d[c]):c>=n.length&&(r[c]=Se(u));for(;c<n.length;c++)a[c]();return l=i.length=a.length=h,n=d.slice(0),r=r.slice(0,l)});function u(E){a[c]=E;const[m,A]=q(d[c]);return i[c]=A,t(m,c)}}}function js(e,t){return Y(()=>e(t||{}))}function Ot(){return!0}var ms={get(e,t,s){return t===qt?s:e.get(t)},has(e,t){return t===qt?!0:e.has(t)},set:Ot,deleteProperty:Ot,getOwnPropertyDescriptor(e,t){return{configurable:!0,enumerable:!0,get(){return e.get(t)},set:Ot,deleteProperty:Ot}},ownKeys(e){return e.keys()}};function ds(e){return(e=typeof e=="function"?e():e)?e:{}}function Qi(){for(let e=0,t=this.length;e<t;++e){const s=this[e]();if(s!==void 0)return s}}function ks(...e){let t=!1;for(let i=0;i<e.length;i++){const l=e[i];t=t||!!l&&qt in l,e[i]=typeof l=="function"?(t=!0,J(l)):l}if(xn&&t)return new Proxy({get(i){for(let l=e.length-1;l>=0;l--){const c=ds(e[l])[i];if(c!==void 0)return c}},has(i){for(let l=e.length-1;l>=0;l--)if(i in ds(e[l]))return!0;return!1},keys(){const i=[];for(let l=0;l<e.length;l++)i.push(...Object.keys(ds(e[l])));return[...new Set(i)]}},ms);const s={},n=Object.create(null);for(let i=e.length-1;i>=0;i--){const l=e[i];if(!l)continue;const c=Object.getOwnPropertyNames(l);for(let d=c.length-1;d>=0;d--){const h=c[d];if(h==="__proto__"||h==="constructor")continue;const u=Object.getOwnPropertyDescriptor(l,h);if(!n[h])n[h]=u.get?{enumerable:!0,configurable:!0,get:Qi.bind(s[h]=[u.get.bind(l)])}:u.value!==void 0?u:void 0;else{const E=s[h];E&&(u.get?E.push(u.get.bind(l)):u.value!==void 0&&E.push(()=>u.value))}}}const r={},a=Object.keys(n);for(let i=a.length-1;i>=0;i--){const l=a[i],c=n[l];c&&c.get?Object.defineProperty(r,l,c):r[l]=c?c.value:void 0}return r}function Dn(e,...t){if(xn&&qt in e){const r=new Set(t.length>1?t.flat():t[0]),a=t.map(i=>new Proxy({get(l){return i.includes(l)?e[l]:void 0},has(l){return i.includes(l)&&l in e},keys(){return i.filter(l=>l in e)}},ms));return a.push(new Proxy({get(i){return r.has(i)?void 0:e[i]},has(i){return r.has(i)?!1:i in e},keys(){return Object.keys(e).filter(i=>!r.has(i))}},ms)),a}const s={},n=t.map(()=>({}));for(const r of Object.getOwnPropertyNames(e)){const a=Object.getOwnPropertyDescriptor(e,r),i=!a.get&&!a.set&&a.enumerable&&a.writable&&a.configurable;let l=!1,c=0;for(const d of t)d.includes(r)&&(l=!0,i?n[c][r]=a.value:Object.defineProperty(n[c],r,a)),++c;l||(i?s[r]=a.value:Object.defineProperty(s,r,a))}return[...n,s]}function Gn(e){let t,s;const n=r=>{const a=C.context;if(a){const[l,c]=q();C.count||(C.count=0),C.count++,(s||(s=e())).then(d=>{!C.done&&it(a),C.count--,c(()=>d.default),it()}),t=l}else if(!t){const[l]=Li(()=>(s||(s=e())).then(c=>c.default));t=l}let i;return J(()=>(i=t())?Y(()=>{if(!a||C.done)return i(r);const l=C.context;it(a);const c=i(r);return it(l),c}):"")};return n.preload=()=>s||((s=e()).then(r=>t=()=>r.default),s),n}var zi=0;function $i(){return C.context?C.getNextContextId():`cl-${zi++}`}var On=e=>`Stale read from <${e}>.`;function Wi(e){const t="fallback"in e&&{fallback:()=>e.fallback};return J(Vi(()=>e.each,e.children,t||void 0))}function Ji(e){const t="fallback"in e&&{fallback:()=>e.fallback};return J(Ki(()=>e.each,e.children,t||void 0))}function Yi(e){const t=e.keyed,s=J(()=>e.when,void 0,void 0),n=t?s:J(s,void 0,{equals:(r,a)=>!r==!a});return J(()=>{const r=n();if(r){const a=e.children;return typeof a=="function"&&a.length>0?Y(()=>a(t?r:()=>{if(!Y(n))throw On("Show");return s()})):a}return e.fallback},void 0,void 0)}function Zi(e){const t=In(()=>e.children),s=J(()=>{const n=t(),r=Array.isArray(n)?n:[n];let a=()=>{};for(let i=0;i<r.length;i++){const l=i,c=r[i],d=a,h=J(()=>d()?void 0:c.when,void 0,void 0),u=c.keyed?h:J(h,void 0,{equals:(E,m)=>!E==!m});a=()=>d()||(u()?[l,h,c]:void 0)}return a});return J(()=>{const n=s()();if(!n)return e.fallback;const[r,a,i]=n,l=i.children;return typeof l=="function"&&l.length>0?Y(()=>l(i.keyed?a():()=>{var d;if(((d=Y(s)())==null?void 0:d[0])!==r)throw On("Match");return a()})):l},void 0,void 0)}function Xi(e){return e}var eo=["allowfullscreen","async","autofocus","autoplay","checked","controls","default","disabled","formnovalidate","hidden","indeterminate","inert","ismap","loop","multiple","muted","nomodule","novalidate","open","playsinline","readonly","required","reversed","seamless","selected"],to=new Set(["className","value","readOnly","noValidate","formNoValidate","isMap","noModule","playsInline",...eo]),so=new Set(["innerHTML","textContent","innerText","children"]),no=Object.assign(Object.create(null),{className:"class",htmlFor:"for"}),ro=Object.assign(Object.create(null),{class:"className",novalidate:{$:"noValidate",FORM:1},formnovalidate:{$:"formNoValidate",BUTTON:1,INPUT:1},ismap:{$:"isMap",IMG:1},nomodule:{$:"noModule",SCRIPT:1},playsinline:{$:"playsInline",VIDEO:1},readonly:{$:"readOnly",INPUT:1,TEXTAREA:1}});function ao(e,t){const s=ro[e];return typeof s=="object"?s[t]?s.$:void 0:s}var io=new Set(["beforeinput","click","dblclick","contextmenu","focusin","focusout","input","keydown","keyup","mousedown","mousemove","mouseout","mouseover","mouseup","pointerdown","pointermove","pointerout","pointerover","pointerup","touchend","touchmove","touchstart"]),oo=new Set(["altGlyph","altGlyphDef","altGlyphItem","animate","animateColor","animateMotion","animateTransform","circle","clipPath","color-profile","cursor","defs","desc","ellipse","feBlend","feColorMatrix","feComponentTransfer","feComposite","feConvolveMatrix","feDiffuseLighting","feDisplacementMap","feDistantLight","feDropShadow","feFlood","feFuncA","feFuncB","feFuncG","feFuncR","feGaussianBlur","feImage","feMerge","feMergeNode","feMorphology","feOffset","fePointLight","feSpecularLighting","feSpotLight","feTile","feTurbulence","filter","font","font-face","font-face-format","font-face-name","font-face-src","font-face-uri","foreignObject","g","glyph","glyphRef","hkern","image","line","linearGradient","marker","mask","metadata","missing-glyph","mpath","path","pattern","polygon","polyline","radialGradient","rect","set","stop","svg","switch","symbol","text","textPath","tref","tspan","use","view","vkern"]),lo={xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace"},co=e=>J(()=>e());function uo(e,t,s){let n=s.length,r=t.length,a=n,i=0,l=0,c=t[r-1].nextSibling,d=null;for(;i<r||l<a;){if(t[i]===s[l]){i++,l++;continue}for(;t[r-1]===s[a-1];)r--,a--;if(r===i){const h=a<n?l?s[l-1].nextSibling:s[a-l]:c;for(;l<a;)e.insertBefore(s[l++],h)}else if(a===l)for(;i<r;)(!d||!d.has(t[i]))&&t[i].remove(),i++;else if(t[i]===s[a-1]&&s[l]===t[r-1]){const h=t[--r].nextSibling;e.insertBefore(s[l++],t[i++].nextSibling),e.insertBefore(s[--a],h),t[r]=s[a]}else{if(!d){d=new Map;let u=l;for(;u<a;)d.set(s[u],u++)}const h=d.get(t[i]);if(h!=null)if(l<h&&h<a){let u=i,E=1,m;for(;++u<r&&u<a&&!((m=d.get(t[u]))==null||m!==h+E);)E++;if(E>h-l){const A=t[i];for(;l<h;)e.insertBefore(s[l++],A)}else e.replaceChild(s[l++],t[i++])}else i++;else t[i++].remove()}}}var ct="_$DX_DELEGATE";function Rn(e,t,s,n={}){let r;return Se(a=>{r=a,t===document?e():Jt(t,e(),t.firstChild?null:void 0,s)},n.owner),()=>{r(),t.textContent=""}}function fo(e,t,s,n){let r;const a=()=>{const l=document.createElement("template");return l.innerHTML=e,l.content.firstChild},i=()=>(r||(r=a())).cloneNode(!0);return i.cloneNode=i,i}function Mn(e,t=window.document){const s=t[ct]||(t[ct]=new Set);for(let n=0,r=e.length;n<r;n++){const a=e[n];s.has(a)||(s.add(a),t.addEventListener(a,qn))}}function ho(e=window.document){if(e[ct]){for(let t of e[ct].keys())e.removeEventListener(t,qn);delete e[ct]}}function Wt(e,t,s){Ie(e)||(s==null?e.removeAttribute(t):e.setAttribute(t,s))}function go(e,t,s,n){Ie(e)||(n==null?e.removeAttributeNS(t,s):e.setAttributeNS(t,s,n))}function mo(e,t,s){Ie(e)||(s?e.setAttribute(t,""):e.removeAttribute(t))}function Un(e,t){Ie(e)||(t==null?e.removeAttribute("class"):e.className=t)}function Bn(e,t,s,n){if(n)Array.isArray(s)?(e[`$$${t}`]=s[0],e[`$$${t}Data`]=s[1]):e[`$$${t}`]=s;else if(Array.isArray(s)){const r=s[0];e.addEventListener(t,s[0]=a=>r.call(e,s[1],a))}else e.addEventListener(t,s,typeof s!="function"&&s)}function Eo(e,t,s={}){const n=Object.keys(t||{}),r=Object.keys(s);let a,i;for(a=0,i=r.length;a<i;a++){const l=r[a];!l||l==="undefined"||t[l]||(qs(e,l,!1),delete s[l])}for(a=0,i=n.length;a<i;a++){const l=n[a],c=!!t[l];!l||l==="undefined"||s[l]===c||!c||(qs(e,l,!0),s[l]=c)}return s}function po(e,t,s){if(!t)return s?Wt(e,"style"):t;const n=e.style;if(typeof t=="string")return n.cssText=t;typeof s=="string"&&(n.cssText=s=void 0),s||(s={}),t||(t={});let r,a;for(a in s)t[a]==null&&n.removeProperty(a),delete s[a];for(a in t)r=t[a],r!==s[a]&&(n.setProperty(a,r),s[a]=r);return s}function Fn(e,t={},s,n){const r={};return n||Pe(()=>r.children=ht(e,t.children,r.children)),Pe(()=>typeof t.ref=="function"&&Hn(t.ref,e)),Pe(()=>yo(e,t,s,!0,r,!0)),r}function Hn(e,t,s){return Y(()=>e(t,s))}function Jt(e,t,s,n){if(s!==void 0&&!n&&(n=[]),typeof t!="function")return ht(e,t,n,s);Pe(r=>ht(e,t(),r,s),n)}function yo(e,t,s,n,r={},a=!1){t||(t={});for(const i in r)if(!(i in t)){if(i==="children")continue;r[i]=Vs(e,i,null,r[i],s,a,t)}for(const i in t){if(i==="children")continue;const l=t[i];r[i]=Vs(e,i,l,r[i],s,a,t)}}function Ao(e){let t,s;return!Ie()||!(t=C.registry.get(s=So()))?e():(C.completed&&C.completed.add(t),C.registry.delete(s),t)}function Ie(e){return!!C.context&&!C.done&&(!e||e.isConnected)}function To(e){return e.toLowerCase().replace(/-([a-z])/g,(t,s)=>s.toUpperCase())}function qs(e,t,s){const n=t.trim().split(/\s+/);for(let r=0,a=n.length;r<a;r++)e.classList.toggle(n[r],s)}function Vs(e,t,s,n,r,a,i){let l,c,d,h,u;if(t==="style")return po(e,s,n);if(t==="classList")return Eo(e,s,n);if(s===n)return n;if(t==="ref")a||s(e);else if(t.slice(0,3)==="on:"){const E=t.slice(3);n&&e.removeEventListener(E,n,typeof n!="function"&&n),s&&e.addEventListener(E,s,typeof s!="function"&&s)}else if(t.slice(0,10)==="oncapture:"){const E=t.slice(10);n&&e.removeEventListener(E,n,!0),s&&e.addEventListener(E,s,!0)}else if(t.slice(0,2)==="on"){const E=t.slice(2).toLowerCase(),m=io.has(E);if(!m&&n){const A=Array.isArray(n)?n[0]:n;e.removeEventListener(E,A)}(m||s)&&(Bn(e,E,s,m),m&&Mn([E]))}else if(t.slice(0,5)==="attr:")Wt(e,t.slice(5),s);else if(t.slice(0,5)==="bool:")mo(e,t.slice(5),s);else if((u=t.slice(0,5)==="prop:")||(d=so.has(t))||!r&&((h=ao(t,e.tagName))||(c=to.has(t)))||(l=e.nodeName.includes("-")||"is"in i)){if(u)t=t.slice(5),c=!0;else if(Ie(e))return s;t==="class"||t==="className"?Un(e,s):l&&!c&&!d?e[To(t)]=s:e[h||t]=s}else{const E=r&&t.indexOf(":")>-1&&lo[t.split(":")[0]];E?go(e,E,t,s):Wt(e,no[t]||t,s)}return s}function qn(e){if(C.registry&&C.events&&C.events.find(([c,d])=>d===e))return;let t=e.target;const s=`$$${e.type}`,n=e.target,r=e.currentTarget,a=c=>Object.defineProperty(e,"target",{configurable:!0,value:c}),i=()=>{const c=t[s];if(c&&!t.disabled){const d=t[`${s}Data`];if(d!==void 0?c.call(t,d,e):c.call(t,e),e.cancelBubble)return}return t.host&&typeof t.host!="string"&&!t.host._$host&&t.contains(e.target)&&a(t.host),!0},l=()=>{for(;i()&&(t=t._$host||t.parentNode||t.host););};if(Object.defineProperty(e,"currentTarget",{configurable:!0,get(){return t||document}}),C.registry&&!C.done&&(C.done=_$HY.done=!0),e.composedPath){const c=e.composedPath();a(c[0]);for(let d=0;d<c.length-2&&(t=c[d],!!i());d++){if(t._$host){t=t._$host,l();break}if(t.parentNode===r)break}}else l();a(n)}function ht(e,t,s,n,r){const a=Ie(e);if(a){!s&&(s=[...e.childNodes]);let c=[];for(let d=0;d<s.length;d++){const h=s[d];h.nodeType===8&&h.data.slice(0,2)==="!$"?h.remove():c.push(h)}s=c}for(;typeof s=="function";)s=s();if(t===s)return s;const i=typeof t,l=n!==void 0;if(e=l&&s[0]&&s[0].parentNode||e,i==="string"||i==="number"){if(a||i==="number"&&(t=t.toString(),t===s))return s;if(l){let c=s[0];c&&c.nodeType===3?c.data!==t&&(c.data=t):c=document.createTextNode(t),s=je(e,s,n,c)}else s!==""&&typeof s=="string"?s=e.firstChild.data=t:s=e.textContent=t}else if(t==null||i==="boolean"){if(a)return s;s=je(e,s,n)}else{if(i==="function")return Pe(()=>{let c=t();for(;typeof c=="function";)c=c();s=ht(e,c,s,n)}),()=>s;if(Array.isArray(t)){const c=[],d=s&&Array.isArray(s);if(Es(c,t,s,r))return Pe(()=>s=ht(e,c,s,n,!0)),()=>s;if(a){if(!c.length)return s;if(n===void 0)return s=[...e.childNodes];let h=c[0];if(h.parentNode!==e)return s;const u=[h];for(;(h=h.nextSibling)!==n;)u.push(h);return s=u}if(c.length===0){if(s=je(e,s,n),l)return s}else d?s.length===0?Ks(e,c,n):uo(e,s,c):(s&&je(e),Ks(e,c));s=c}else if(t.nodeType){if(a&&t.parentNode)return s=l?[t]:t;if(Array.isArray(s)){if(l)return s=je(e,s,n,t);je(e,s,null,t)}else s==null||s===""||!e.firstChild?e.appendChild(t):e.replaceChild(t,e.firstChild);s=t}}return s}function Es(e,t,s,n){let r=!1;for(let a=0,i=t.length;a<i;a++){let l=t[a],c=s&&s[e.length],d;if(!(l==null||l===!0||l===!1))if((d=typeof l)=="object"&&l.nodeType)e.push(l);else if(Array.isArray(l))r=Es(e,l,c)||r;else if(d==="function")if(n){for(;typeof l=="function";)l=l();r=Es(e,Array.isArray(l)?l:[l],Array.isArray(c)?c:[c])||r}else e.push(l),r=!0;else{const h=String(l);c&&c.nodeType===3&&c.data===h?e.push(c):e.push(document.createTextNode(h))}}return r}function Ks(e,t,s=null){for(let n=0,r=t.length;n<r;n++)e.insertBefore(t[n],s)}function je(e,t,s,n){if(s===void 0)return e.textContent="";const r=n||document.createTextNode("");if(t.length){let a=!1;for(let i=t.length-1;i>=0;i--){const l=t[i];if(r!==l){const c=l.parentNode===e;!a&&!i?c?e.replaceChild(r,l):e.insertBefore(r,s):c&&l.remove()}else a=!0}}else e.insertBefore(r,s);return[r]}function So(){return C.getNextContextId()}var Po="http://www.w3.org/2000/svg";function Vn(e,t=!1){return t?document.createElementNS(Po,e):document.createElement(e)}function xo(e){const{useShadow:t}=e,s=document.createTextNode(""),n=()=>e.mount||document.body,r=Hs();let a,i=!!C.context;return Ns(()=>{i&&(Hs().user=i=!1),a||(a=vn(r,()=>J(()=>e.children)));const l=n();if(l instanceof HTMLHeadElement){const[c,d]=q(!1),h=()=>d(!0);Se(u=>Jt(l,()=>c()?u():a(),null)),Ze(h)}else{const c=Vn(e.isSVG?"g":"div",e.isSVG),d=t&&c.attachShadow?c.attachShadow({mode:"open"}):c;Object.defineProperty(c,"_$host",{get(){return s.parentNode},configurable:!0}),Jt(d,a),l.appendChild(c),e.ref&&e.ref(c),Ze(()=>l.removeChild(c))}},void 0,{render:!i}),s}function _o(e,t){const s=J(e);return J(()=>{const n=s();switch(typeof n){case"function":return Y(()=>n(t));case"string":const r=oo.has(n),a=C.context?Ao():Vn(n,r);return Fn(a,t,r),a}})}function wo(e){const[,t]=Dn(e,["component"]);return _o(()=>e.component,t)}var bo=class{constructor(){this.keyToValue=new Map,this.valueToKey=new Map}set(e,t){this.keyToValue.set(e,t),this.valueToKey.set(t,e)}getByKey(e){return this.keyToValue.get(e)}getByValue(e){return this.valueToKey.get(e)}clear(){this.keyToValue.clear(),this.valueToKey.clear()}},Kn=class{constructor(e){this.generateIdentifier=e,this.kv=new bo}register(e,t){this.kv.getByValue(e)||(t||(t=this.generateIdentifier(e)),this.kv.set(t,e))}clear(){this.kv.clear()}getIdentifier(e){return this.kv.getByValue(e)}getValue(e){return this.kv.getByKey(e)}},Co=class extends Kn{constructor(){super(e=>e.name),this.classToAllowedProps=new Map}register(e,t){typeof t=="object"?(t.allowProps&&this.classToAllowedProps.set(e,t.allowProps),super.register(e,t.identifier)):super.register(e,t)}getAllowedProps(e){return this.classToAllowedProps.get(e)}};function vo(e){if("values"in Object)return Object.values(e);const t=[];for(const s in e)e.hasOwnProperty(s)&&t.push(e[s]);return t}function Io(e,t){const s=vo(e);if("find"in s)return s.find(t);const n=s;for(let r=0;r<n.length;r++){const a=n[r];if(t(a))return a}}function Xe(e,t){Object.entries(e).forEach(([s,n])=>t(n,s))}function Ft(e,t){return e.indexOf(t)!==-1}function Qs(e,t){for(let s=0;s<e.length;s++){const n=e[s];if(t(n))return n}}var No=class{constructor(){this.transfomers={}}register(e){this.transfomers[e.name]=e}findApplicable(e){return Io(this.transfomers,t=>t.isApplicable(e))}findByName(e){return this.transfomers[e]}},Lo=e=>Object.prototype.toString.call(e).slice(8,-1),Qn=e=>typeof e>"u",jo=e=>e===null,gt=e=>typeof e!="object"||e===null||e===Object.prototype?!1:Object.getPrototypeOf(e)===null?!0:Object.getPrototypeOf(e)===Object.prototype,ps=e=>gt(e)&&Object.keys(e).length===0,xe=e=>Array.isArray(e),ko=e=>typeof e=="string",Do=e=>typeof e=="number"&&!isNaN(e),Go=e=>typeof e=="boolean",Oo=e=>e instanceof RegExp,mt=e=>e instanceof Map,Et=e=>e instanceof Set,zn=e=>Lo(e)==="Symbol",Ro=e=>e instanceof Date&&!isNaN(e.valueOf()),Mo=e=>e instanceof Error,zs=e=>typeof e=="number"&&isNaN(e),Uo=e=>Go(e)||jo(e)||Qn(e)||Do(e)||ko(e)||zn(e),Bo=e=>typeof e=="bigint",Fo=e=>e===1/0||e===-1/0,Ho=e=>ArrayBuffer.isView(e)&&!(e instanceof DataView),qo=e=>e instanceof URL,$n=e=>e.replace(/\./g,"\\."),fs=e=>e.map(String).map($n).join("."),ut=e=>{const t=[];let s="";for(let r=0;r<e.length;r++){let a=e.charAt(r);if(a==="\\"&&e.charAt(r+1)==="."){s+=".",r++;continue}if(a==="."){t.push(s),s="";continue}s+=a}const n=s;return t.push(n),t};function ge(e,t,s,n){return{isApplicable:e,annotation:t,transform:s,untransform:n}}var Wn=[ge(Qn,"undefined",()=>null,()=>{}),ge(Bo,"bigint",e=>e.toString(),e=>typeof BigInt<"u"?BigInt(e):e),ge(Ro,"Date",e=>e.toISOString(),e=>new Date(e)),ge(Mo,"Error",(e,t)=>{const s={name:e.name,message:e.message};return t.allowedErrorProps.forEach(n=>{s[n]=e[n]}),s},(e,t)=>{const s=new Error(e.message);return s.name=e.name,s.stack=e.stack,t.allowedErrorProps.forEach(n=>{s[n]=e[n]}),s}),ge(Oo,"regexp",e=>""+e,e=>{const t=e.slice(1,e.lastIndexOf("/")),s=e.slice(e.lastIndexOf("/")+1);return new RegExp(t,s)}),ge(Et,"set",e=>[...e.values()],e=>new Set(e)),ge(mt,"map",e=>[...e.entries()],e=>new Map(e)),ge(e=>zs(e)||Fo(e),"number",e=>zs(e)?"NaN":e>0?"Infinity":"-Infinity",Number),ge(e=>e===0&&1/e===-1/0,"number",()=>"-0",Number),ge(qo,"URL",e=>e.toString(),e=>new URL(e))];function ts(e,t,s,n){return{isApplicable:e,annotation:t,transform:s,untransform:n}}var Jn=ts((e,t)=>zn(e)?!!t.symbolRegistry.getIdentifier(e):!1,(e,t)=>["symbol",t.symbolRegistry.getIdentifier(e)],e=>e.description,(e,t,s)=>{const n=s.symbolRegistry.getValue(t[1]);if(!n)throw new Error("Trying to deserialize unknown symbol");return n}),Vo=[Int8Array,Uint8Array,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array,Uint8ClampedArray].reduce((e,t)=>(e[t.name]=t,e),{}),Yn=ts(Ho,e=>["typed-array",e.constructor.name],e=>[...e],(e,t)=>{const s=Vo[t[1]];if(!s)throw new Error("Trying to deserialize unknown typed array");return new s(e)});function Zn(e,t){return e!=null&&e.constructor?!!t.classRegistry.getIdentifier(e.constructor):!1}var Xn=ts(Zn,(e,t)=>["class",t.classRegistry.getIdentifier(e.constructor)],(e,t)=>{const s=t.classRegistry.getAllowedProps(e.constructor);if(!s)return{...e};const n={};return s.forEach(r=>{n[r]=e[r]}),n},(e,t,s)=>{const n=s.classRegistry.getValue(t[1]);if(!n)throw new Error(`Trying to deserialize unknown class '${t[1]}' - check https://github.com/blitz-js/superjson/issues/116#issuecomment-773996564`);return Object.assign(Object.create(n.prototype),e)}),er=ts((e,t)=>!!t.customTransformerRegistry.findApplicable(e),(e,t)=>["custom",t.customTransformerRegistry.findApplicable(e).name],(e,t)=>t.customTransformerRegistry.findApplicable(e).serialize(e),(e,t,s)=>{const n=s.customTransformerRegistry.findByName(t[1]);if(!n)throw new Error("Trying to deserialize unknown custom value");return n.deserialize(e)}),Ko=[Xn,Jn,er,Yn],$s=(e,t)=>{const s=Qs(Ko,r=>r.isApplicable(e,t));if(s)return{value:s.transform(e,t),type:s.annotation(e,t)};const n=Qs(Wn,r=>r.isApplicable(e,t));if(n)return{value:n.transform(e,t),type:n.annotation}},tr={};Wn.forEach(e=>{tr[e.annotation]=e});var Qo=(e,t,s)=>{if(xe(t))switch(t[0]){case"symbol":return Jn.untransform(e,t,s);case"class":return Xn.untransform(e,t,s);case"custom":return er.untransform(e,t,s);case"typed-array":return Yn.untransform(e,t,s);default:throw new Error("Unknown transformation: "+t)}else{const n=tr[t];if(!n)throw new Error("Unknown transformation: "+t);return n.untransform(e,s)}},ke=(e,t)=>{if(t>e.size)throw new Error("index out of bounds");const s=e.keys();for(;t>0;)s.next(),t--;return s.next().value};function sr(e){if(Ft(e,"__proto__"))throw new Error("__proto__ is not allowed as a property");if(Ft(e,"prototype"))throw new Error("prototype is not allowed as a property");if(Ft(e,"constructor"))throw new Error("constructor is not allowed as a property")}var zo=(e,t)=>{sr(t);for(let s=0;s<t.length;s++){const n=t[s];if(Et(e))e=ke(e,+n);else if(mt(e)){const r=+n,a=+t[++s]==0?"key":"value",i=ke(e,r);switch(a){case"key":e=i;break;case"value":e=e.get(i);break}}else e=e[n]}return e},ys=(e,t,s)=>{if(sr(t),t.length===0)return s(e);let n=e;for(let a=0;a<t.length-1;a++){const i=t[a];if(xe(n)){const l=+i;n=n[l]}else if(gt(n))n=n[i];else if(Et(n)){const l=+i;n=ke(n,l)}else if(mt(n)){if(a===t.length-2)break;const c=+i,d=+t[++a]==0?"key":"value",h=ke(n,c);switch(d){case"key":n=h;break;case"value":n=n.get(h);break}}}const r=t[t.length-1];if(xe(n)?n[+r]=s(n[+r]):gt(n)&&(n[r]=s(n[r])),Et(n)){const a=ke(n,+r),i=s(a);a!==i&&(n.delete(a),n.add(i))}if(mt(n)){const a=+t[t.length-2],i=ke(n,a);switch(+r==0?"key":"value"){case"key":{const c=s(i);n.set(c,n.get(i)),c!==i&&n.delete(i);break}case"value":{n.set(i,s(n.get(i)));break}}}return e};function As(e,t,s=[]){if(!e)return;if(!xe(e)){Xe(e,(a,i)=>As(a,t,[...s,...ut(i)]));return}const[n,r]=e;r&&Xe(r,(a,i)=>{As(a,t,[...s,...ut(i)])}),t(n,s)}function $o(e,t,s){return As(t,(n,r)=>{e=ys(e,r,a=>Qo(a,n,s))}),e}function Wo(e,t){function s(n,r){const a=zo(e,ut(r));n.map(ut).forEach(i=>{e=ys(e,i,()=>a)})}if(xe(t)){const[n,r]=t;n.forEach(a=>{e=ys(e,ut(a),()=>e)}),r&&Xe(r,s)}else Xe(t,s);return e}var Jo=(e,t)=>gt(e)||xe(e)||mt(e)||Et(e)||Zn(e,t);function Yo(e,t,s){const n=s.get(e);n?n.push(t):s.set(e,[t])}function Zo(e,t){const s={};let n;return e.forEach(r=>{if(r.length<=1)return;t||(r=r.map(l=>l.map(String)).sort((l,c)=>l.length-c.length));const[a,...i]=r;a.length===0?n=i.map(fs):s[fs(a)]=i.map(fs)}),n?ps(s)?[n]:[n,s]:ps(s)?void 0:s}var nr=(e,t,s,n,r=[],a=[],i=new Map)=>{const l=Uo(e);if(!l){Yo(e,r,t);const m=i.get(e);if(m)return n?{transformedValue:null}:m}if(!Jo(e,s)){const m=$s(e,s),A=m?{transformedValue:m.value,annotations:[m.type]}:{transformedValue:e};return l||i.set(e,A),A}if(Ft(a,e))return{transformedValue:null};const c=$s(e,s),d=(c==null?void 0:c.value)??e,h=xe(d)?[]:{},u={};Xe(d,(m,A)=>{if(A==="__proto__"||A==="constructor"||A==="prototype")throw new Error(`Detected property ${A}. This is a prototype pollution risk, please remove it from your object.`);const b=nr(m,t,s,n,[...r,A],[...a,e],i);h[A]=b.transformedValue,xe(b.annotations)?u[A]=b.annotations:gt(b.annotations)&&Xe(b.annotations,(L,T)=>{u[$n(A)+"."+T]=L})});const E=ps(u)?{transformedValue:h,annotations:c?[c.type]:void 0}:{transformedValue:h,annotations:c?[c.type,u]:u};return l||i.set(e,E),E};function rr(e){return Object.prototype.toString.call(e).slice(8,-1)}function Ws(e){return rr(e)==="Array"}function Xo(e){if(rr(e)!=="Object")return!1;const t=Object.getPrototypeOf(e);return!!t&&t.constructor===Object&&t===Object.prototype}function el(e,t,s,n,r){const a={}.propertyIsEnumerable.call(n,t)?"enumerable":"nonenumerable";a==="enumerable"&&(e[t]=s),r&&a==="nonenumerable"&&Object.defineProperty(e,t,{value:s,enumerable:!1,writable:!0,configurable:!0})}function Ts(e,t={}){if(Ws(e))return e.map(r=>Ts(r,t));if(!Xo(e))return e;const s=Object.getOwnPropertyNames(e),n=Object.getOwnPropertySymbols(e);return[...s,...n].reduce((r,a)=>{if(Ws(t.props)&&!t.props.includes(a))return r;const i=e[a],l=Ts(i,t);return el(r,a,l,e,t.nonenumerable),r},{})}var B=class{constructor({dedupe:e=!1}={}){this.classRegistry=new Co,this.symbolRegistry=new Kn(t=>t.description??""),this.customTransformerRegistry=new No,this.allowedErrorProps=[],this.dedupe=e}serialize(e){const t=new Map,s=nr(e,t,this,this.dedupe),n={json:s.transformedValue};s.annotations&&(n.meta={...n.meta,values:s.annotations});const r=Zo(t,this.dedupe);return r&&(n.meta={...n.meta,referentialEqualities:r}),n}deserialize(e){const{json:t,meta:s}=e;let n=Ts(t);return s!=null&&s.values&&(n=$o(n,s.values,this)),s!=null&&s.referentialEqualities&&(n=Wo(n,s.referentialEqualities)),n}stringify(e){return JSON.stringify(this.serialize(e))}parse(e){return this.deserialize(JSON.parse(e))}registerClass(e,t){this.classRegistry.register(e,t)}registerSymbol(e,t){this.symbolRegistry.register(e,t)}registerCustom(e,t){this.customTransformerRegistry.register({name:t,...e})}allowErrorProps(...e){this.allowedErrorProps.push(...e)}};B.defaultInstance=new B;B.serialize=B.defaultInstance.serialize.bind(B.defaultInstance);B.deserialize=B.defaultInstance.deserialize.bind(B.defaultInstance);B.stringify=B.defaultInstance.stringify.bind(B.defaultInstance);B.parse=B.defaultInstance.parse.bind(B.defaultInstance);B.registerClass=B.defaultInstance.registerClass.bind(B.defaultInstance);B.registerSymbol=B.defaultInstance.registerSymbol.bind(B.defaultInstance);B.registerCustom=B.defaultInstance.registerCustom.bind(B.defaultInstance);B.allowErrorProps=B.defaultInstance.allowErrorProps.bind(B.defaultInstance);var ar=B.serialize,tl=B.stringify;function sl(e){return e.state.fetchStatus==="fetching"?"fetching":e.getObserversCount()?e.state.fetchStatus==="paused"?"paused":e.isStale()?"stale":"fresh":"inactive"}function nl(e,t){return`${e}${t.charAt(0).toUpperCase()+t.slice(1)}`}function rl({queryState:e,observerCount:t,isStale:s}){return e.fetchStatus==="fetching"?"blue":t?e.fetchStatus==="paused"?"purple":s?"yellow":"green":"gray"}function al({status:e,isPaused:t}){return t?"purple":e==="error"?"red":e==="pending"?"yellow":e==="success"?"green":"gray"}function il(e){return e==="fresh"?"green":e==="stale"?"yellow":e==="paused"?"purple":e==="inactive"?"gray":"blue"}var ol=(e,t=!1)=>{const{json:s}=ar(e);return JSON.stringify(s,null,t?2:void 0)},Rt=e=>e.state.fetchStatus!=="idle"?0:e.getObserversCount()?e.isStale()?2:1:3,ll=(e,t)=>e.queryHash.localeCompare(t.queryHash),ir=(e,t)=>e.state.dataUpdatedAt<t.state.dataUpdatedAt?1:-1,cl=(e,t)=>Rt(e)===Rt(t)?ir(e,t):Rt(e)>Rt(t)?1:-1,ul={status:cl,"query hash":ll,"last updated":ir},Mt=e=>e.state.isPaused?0:e.state.status==="error"?2:e.state.status==="pending"?1:3,or=(e,t)=>e.state.submittedAt<t.state.submittedAt?1:-1,dl=(e,t)=>Mt(e)===Mt(t)?or(e,t):Mt(e)>Mt(t)?1:-1,fl={status:dl,"last updated":or},hl=e=>e*parseFloat(getComputedStyle(document.documentElement).fontSize),gl=()=>{const[e,t]=q("dark");return Cn(()=>{const s=window.matchMedia("(prefers-color-scheme: dark)");t(s.matches?"dark":"light");const n=r=>{t(r.matches?"dark":"light")};s.addEventListener("change",n),Ze(()=>s.removeEventListener("change",n))}),e},ot=(e,t,s)=>{if(t.length===0)return s;if(e instanceof Map){const n=new Map(e);if(t.length===1)return n.set(t[0],s),n;const[r,...a]=t;return n.set(r,ot(n.get(r),a,s)),n}if(e instanceof Set){const n=ot(Array.from(e),t,s);return new Set(n)}if(Array.isArray(e)){const n=[...e];if(t.length===1)return n[t[0]]=s,n;const[r,...a]=t;return n[r]=ot(n[r],a,s),n}if(e instanceof Object){const n={...e};if(t.length===1)return n[t[0]]=s,n;const[r,...a]=t;return n[r]=ot(n[r],a,s),n}return e},lt=(e,t)=>{if(e instanceof Map){const s=new Map(e);if(t.length===1)return s.delete(t[0]),s;const[n,...r]=t;return s.set(n,lt(s.get(n),r)),s}if(e instanceof Set){const s=lt(Array.from(e),t);return new Set(s)}if(Array.isArray(e)){const s=[...e];if(t.length===1)return s.filter((a,i)=>i.toString()!==t[0]);const[n,...r]=t;return s[n]=lt(s[n],r),s}if(e instanceof Object){const s={...e};if(t.length===1)return delete s[t[0]],s;const[n,...r]=t;return s[n]=lt(s[n],r),s}return e},lr=(e,t)=>{if(!e||document.querySelector("#_goober")||(t==null?void 0:t.querySelector("#_goober")))return;const n=document.createElement("style"),r=document.createTextNode("");n.appendChild(r),n.id="_goober",n.setAttribute("nonce",e),t?t.appendChild(n):document.head.appendChild(n)},De,pt,yt,At,Ce,Tt,Ge,Oe,Re,Me,Ue,St,Be,Fe,Pt,Xs,ml=(Xs=class{constructor(e){O(this,De);O(this,pt);O(this,yt);O(this,At);O(this,Ce,!1);O(this,Tt);O(this,Ge);O(this,Oe);O(this,Re);O(this,Me);O(this,Ue);O(this,St);O(this,Be);O(this,Fe);O(this,Pt);const{client:t,queryFlavor:s,version:n,onlineManager:r,buttonPosition:a,position:i,initialIsOpen:l,errorTypes:c,styleNonce:d,shadowDOMTarget:h,hideDisabledQueries:u,theme:E}=e;k(this,De,q(t)),k(this,yt,s),k(this,At,n),k(this,pt,r),k(this,Tt,d),k(this,Ge,h),k(this,Oe,q(a)),k(this,Re,q(i)),k(this,Me,q(l)),k(this,Ue,q(c)),k(this,St,q(u)),k(this,Fe,q(E))}setButtonPosition(e){w(this,Oe)[1](e)}setPosition(e){w(this,Re)[1](e)}setInitialIsOpen(e){w(this,Me)[1](e)}setErrorTypes(e){w(this,Ue)[1](e)}setClient(e){w(this,De)[1](e)}setTheme(e){w(this,Fe)[1](e)}mount(e){if(w(this,Ce))throw new Error("Devtools is already mounted");const t=Rn(()=>{const s=this,[n]=w(this,Oe),[r]=w(this,Re),[a]=w(this,Me),[i]=w(this,Ue),[l]=w(this,St),[c]=w(this,De),[d]=w(this,Fe);let h;return w(this,Be)?h=w(this,Be):(h=Gn(()=>Promise.resolve().then(()=>require("./WDYDFRGG-BQXNJif4.cjs"))),k(this,Be,h)),lr(w(this,Tt),w(this,Ge)),js(h,ks({get queryFlavor(){return w(s,yt)},get version(){return w(s,At)},get onlineManager(){return w(s,pt)},get shadowDOMTarget(){return w(s,Ge)}},{get client(){return c()},get buttonPosition(){return n()},get position(){return r()},get initialIsOpen(){return a()},get errorTypes(){return i()},get hideDisabledQueries(){return l()},get theme(){return d()}}))},e);k(this,Ce,!0),k(this,Pt,t)}unmount(){var e;if(!w(this,Ce))throw new Error("Devtools is not mounted");(e=w(this,Pt))==null||e.call(this),k(this,Ce,!1)}},De=new WeakMap,pt=new WeakMap,yt=new WeakMap,At=new WeakMap,Ce=new WeakMap,Tt=new WeakMap,Ge=new WeakMap,Oe=new WeakMap,Re=new WeakMap,Me=new WeakMap,Ue=new WeakMap,St=new WeakMap,Be=new WeakMap,Fe=new WeakMap,Pt=new WeakMap,Xs),He,xt,_t,wt,ve,bt,qe,Ve,Ke,Qe,ze,Ct,$e,We,Je,vt,en,El=(en=class{constructor(e){O(this,He);O(this,xt);O(this,_t);O(this,wt);O(this,ve,!1);O(this,bt);O(this,qe);O(this,Ve);O(this,Ke);O(this,Qe);O(this,ze);O(this,Ct);O(this,$e);O(this,We);O(this,Je);O(this,vt);const{client:t,queryFlavor:s,version:n,onlineManager:r,buttonPosition:a,position:i,initialIsOpen:l,errorTypes:c,styleNonce:d,shadowDOMTarget:h,onClose:u,hideDisabledQueries:E,theme:m}=e;k(this,He,q(t)),k(this,_t,s),k(this,wt,n),k(this,xt,r),k(this,bt,d),k(this,qe,h),k(this,Ve,q(a)),k(this,Ke,q(i)),k(this,Qe,q(l)),k(this,ze,q(c)),k(this,Ct,q(E)),k(this,$e,q(u)),k(this,Je,q(m))}setButtonPosition(e){w(this,Ve)[1](e)}setPosition(e){w(this,Ke)[1](e)}setInitialIsOpen(e){w(this,Qe)[1](e)}setErrorTypes(e){w(this,ze)[1](e)}setClient(e){w(this,He)[1](e)}setOnClose(e){w(this,$e)[1](()=>e)}setTheme(e){w(this,Je)[1](e)}mount(e){if(w(this,ve))throw new Error("Devtools is already mounted");const t=Rn(()=>{const s=this,[n]=w(this,Ve),[r]=w(this,Ke),[a]=w(this,Qe),[i]=w(this,ze),[l]=w(this,Ct),[c]=w(this,He),[d]=w(this,$e),[h]=w(this,Je);let u;return w(this,We)?u=w(this,We):(u=Gn(()=>Promise.resolve().then(()=>require("./2SSKDMRQ-BZmyXysb.cjs"))),k(this,We,u)),lr(w(this,bt),w(this,qe)),js(u,ks({get queryFlavor(){return w(s,_t)},get version(){return w(s,wt)},get onlineManager(){return w(s,xt)},get shadowDOMTarget(){return w(s,qe)}},{get client(){return c()},get buttonPosition(){return n()},get position(){return r()},get initialIsOpen(){return a()},get errorTypes(){return i()},get hideDisabledQueries(){return l()},get onClose(){return d()},get theme(){return h()}}))},e);k(this,ve,!0),k(this,vt,t)}unmount(){var e;if(!w(this,ve))throw new Error("Devtools is not mounted");(e=w(this,vt))==null||e.call(this),k(this,ve,!1)}},He=new WeakMap,xt=new WeakMap,_t=new WeakMap,wt=new WeakMap,ve=new WeakMap,bt=new WeakMap,qe=new WeakMap,Ve=new WeakMap,Ke=new WeakMap,Qe=new WeakMap,ze=new WeakMap,Ct=new WeakMap,$e=new WeakMap,We=new WeakMap,Je=new WeakMap,vt=new WeakMap,en);function pl(e){const t=x.useQueryClient(e.client),s=W.useRef(null),{buttonPosition:n,position:r,initialIsOpen:a,errorTypes:i,styleNonce:l,shadowDOMTarget:c,hideDisabledQueries:d,theme:h}=e,[u]=W.useState(new ml({client:t,queryFlavor:"React Query",version:"5",onlineManager:x.onlineManager,buttonPosition:n,position:r,initialIsOpen:a,errorTypes:i,styleNonce:l,shadowDOMTarget:c,hideDisabledQueries:d,theme:h}));return W.useEffect(()=>{u.setClient(t)},[t,u]),W.useEffect(()=>{n&&u.setButtonPosition(n)},[n,u]),W.useEffect(()=>{r&&u.setPosition(r)},[r,u]),W.useEffect(()=>{u.setInitialIsOpen(a||!1)},[a,u]),W.useEffect(()=>{u.setErrorTypes(i||[])},[i,u]),W.useEffect(()=>{u.setTheme(h)},[h,u]),W.useEffect(()=>(s.current&&u.mount(s.current),()=>{u.unmount()}),[u]),o.jsx("div",{dir:"ltr",className:"tsqd-parent-container",ref:s})}function yl(e){const t=x.useQueryClient(e.client),s=W.useRef(null),{errorTypes:n,styleNonce:r,shadowDOMTarget:a,hideDisabledQueries:i,theme:l}=e,[c]=W.useState(new El({client:t,queryFlavor:"React Query",version:"5",onlineManager:x.onlineManager,buttonPosition:"bottom-left",position:"bottom",initialIsOpen:!0,errorTypes:n,styleNonce:r,shadowDOMTarget:a,onClose:e.onClose,hideDisabledQueries:i,theme:l}));return W.useEffect(()=>{c.setClient(t)},[t,c]),W.useEffect(()=>{c.setOnClose(e.onClose??(()=>{}))},[e.onClose,c]),W.useEffect(()=>{c.setErrorTypes(n||[])},[n,c]),W.useEffect(()=>{c.setTheme(l)},[l,c]),W.useEffect(()=>(s.current&&c.mount(s.current),()=>{c.unmount()}),[c]),o.jsx("div",{style:{height:"500px",...e.style},className:"tsqd-parent-container",ref:s})}var Js=process.env.NODE_ENV!=="development"?function(){return null}:pl;process.env.NODE_ENV;const cr=V.atom(""),Al=()=>{v.registerChaiFeatureFlag("dynamic-page-selector",{description:"Dynamic page selector"}),v.registerChaiFeatureFlag("enable-add-page-dropdown",{description:"Enable add page dropdown"})},Tl=()=>{const{data:e}=se(),{data:t}=pe(),{data:s}=_e(),n=j(),r=G(),a=f.useMemo(()=>(s==null?void 0:s.fallbackLang)||"en",[s==null?void 0:s.fallbackLang]),i=f.useRef(new Map);return x.useMutation({mutationFn:async({block:l})=>{const c=l._id,d=(t==null?void 0:t.lang)||a,h=`${c}:${d}`;if(i.current.has(h))return i.current.get(h);const u=r(n,{action:y.GET_BLOCK_ASYNC_PROPS,data:{block:l,lang:d,pageProps:{slug:t==null?void 0:t.slug,searchParams:{},pageType:t==null?void 0:t.pageType,fallbackLang:a,lastSaved:t.lastSaved,pageId:e.id,primaryPageId:t.primaryPage||e.id,pageBaseSlug:t==null?void 0:t.slug,dynamic:e==null?void 0:e.dynamic,languagePageId:t.id}}});return i.current.set(h,u),u.finally(()=>{i.current.delete(h)}),u}})},ur=()=>{const[,e]=Ee();return f.useCallback((t,s)=>{const r=new URLSearchParams(window.location.search).get("lang"),a=new URLSearchParams({page:t});r&&a.set("lang",r),window.history.pushState({},"",`?${a.toString()}`),e(a),window.dispatchEvent(new PopStateEvent("popstate")),s==null||s()},[e])},dr=()=>{const e=ur();return f.useCallback(({pageId:t})=>{e(t)},[e])},Ds=()=>{const e=G(),t=j(),s=x.useQueryClient();return x.useQuery({queryKey:[y.GET_WEBSITE_DATA],staleTime:300*1e3,queryFn:async()=>{const n=await e(t,{action:y.GET_WEBSITE_DATA});return s.setQueryData([y.GET_WEBSITE_DRAFT_SETTINGS],n.websiteSettings),s.setQueryData([y.GET_WEBSITE_PAGES],n.websitePages),s.setQueryData([y.GET_PAGE_TYPES],n.pageTypes),s.setQueryData([y.GET_LIBRARIES],n.libraries),s.setQueryData([y.GET_COLLECTIONS],n.collections),n}})};function Sl(e){const t={};for(const s of e)t[s.id]={name:s.name,isPartial:p.isEmpty(s.slug),partialBlocks:s.partialBlocks?s.partialBlocks.split("|").filter(Boolean):[],links:s.links?s.links.split("|").filter(Boolean):[],designTokens:s.designTokens??{}};return t}const fr=()=>{const{data:e}=we();return{data:f.useMemo(()=>Sl(e??[]),[e])}},Ys={async getUILibraryBlock(e,t,s){const n=await t(s,{action:"GET_LIBRARY_ITEM",data:{id:e.id}}),r=p.get(n,"html",""),a=p.get(n,"blocks",[]);return p.isArray(a)?a:Cr.getBlocksFromHTML(r)},async getUILibraryBlocks(e,t,s){return(await t(s,{action:"GET_LIBRARY_ITEMS",data:{id:e.id}})).map(r=>({...r}))}},Pl=()=>{const e=G(),t=j(),{data:s}=Ds(),n=s==null?void 0:s.libraries;return x.useQuery({queryKey:[y.UI_LIBRARIES],staleTime:"static",queryFn:async()=>{const r=n.map(a=>({...a}));return r.forEach(a=>{v.registerChaiLibrary(a.id,{name:a.isSiteLibrary?a.name+" (Current Site) ":a.name,description:a.description,getBlocksList:i=>Ys.getUILibraryBlocks(i,e,t),getBlock:({block:i})=>Ys.getUILibraryBlock(i,e,t)})}),r}})},xl=f.lazy(()=>Promise.resolve().then(()=>require("./page-lock-CDP4IhJN.cjs"))),_l=f.lazy(()=>Promise.resolve().then(()=>require("./no-language-page-dialog-BqVCx1Ow.cjs"))),wl=f.lazy(()=>Promise.resolve().then(()=>require("./digital-asset-manager-l1HTU_vW.cjs"))),bl=f.lazy(()=>Promise.resolve().then(()=>require("./save-to-lib-BBvjMM3Z.cjs"))),Cl=f.lazy(()=>Promise.resolve().then(()=>require("./web-preview-DNCFZBu2.cjs")));Al();br.loadWebBlocks();v.registerChaiTopBar(ti);Ci();v.registerChaiMediaManager(wl);v.registerChaiSaveToLibrary(bl);const vl={role:"admin",permissions:null},Zs=e=>{const{isLoading:t}=vs();return t?o.jsx(Ye,{className:"fixed inset-0 bg-white",children:o.jsx(_.Loader,{className:"h-6 w-6 animate-spin text-primary"})}):o.jsx(Il,{...e})},Il=e=>{const{data:t,isFetching:s,isError:n}=Ds();return!t||s?o.jsx(Ye,{className:"fixed inset-0 bg-white",children:o.jsx(_.Loader,{className:"h-6 w-6 animate-spin text-primary"})}):n?o.jsxs(Ye,{className:"fixed inset-0 bg-white",children:[o.jsx("p",{children:"Failed to load website data"}),o.jsx(v.Button,{onClick:()=>window.location.reload(),children:"Retry"})]}):o.jsx(Nl,{...e})},Nl=({...e})=>{var Dt;const{data:t}=Ds(),{data:s}=fr(),{data:n}=Pl(),{collections:r,pageTypes:a,websiteSettings:i}=t,l=f.useMemo(()=>(i==null?void 0:i.fallbackLang)||"en",[i]),{data:c,isFetching:d}=vs(),h=c||vl,[u]=Ee(),E=u.get("page"),{data:m}=se(),{data:A,isFetching:b}=pn(),{blocks:L}=ri(((Dt=A==null?void 0:A.draftPage)==null?void 0:Dt.blocks)??[]),{pageStatus:T}=de(),S=ni(),{onSave:N}=fi(),{mutateAsync:Q}=Tl(),{getPartialBlocks:K,getPartialBlockBlocks:F}=hi(),{searchPages:le}=Mr(),{mutateAsync:ne}=ai(),H=dr(),[P,I]=f.useState(!1),M=f.useRef([]),z=f.useMemo(()=>p.get(i,"theme",{})||{},[i]),ae=f.useMemo(()=>p.get(i,"languages",[])||[],[i]),st=f.useMemo(()=>p.get(i,"designTokens",{})||{},[i]),fe=T===X.EDITING,ce=T===X.CHECKING,he=b||ce;f.useEffect(()=>{M.current=L},[L]);const[ss]=V.useAtom(cr);f.useEffect(()=>{const Z=()=>{document.hidden?I(!0):I(!1)};return window.addEventListener("visibilitychange",Z),()=>window.removeEventListener("visibilitychange",Z)},[]);const ns=f.useMemo(()=>{const Z={};return h&&(Z.permissions=p.get(h,"permissions",null),Z.role=p.get(h,"role","user")),Z.pageExternalData=(A==null?void 0:A.builderPageData)??{},Z},[h,A]),Ne=f.useMemo(()=>n==null?void 0:n.some(Z=>Z.isSiteLibrary),[n]);return o.jsxs(o.Fragment,{children:[b&&o.jsx(Ye,{className:d?"fixed inset-0 bg-white":"bg-white/75",children:o.jsx(_.Loader,{className:`animate-spin text-primary ${d?"h-6 w-6":"h-5 w-5"}`})}),ss&&o.jsx(f.Suspense,{fallback:o.jsx("div",{className:"absolute inset-0 z-[999999] flex min-h-screen w-screen items-center justify-center bg-gray-100",children:o.jsx(_.Loader,{className:"h-6 w-6 animate-spin text-primary"})}),children:o.jsx(Cl,{})}),o.jsx(g.ChaiBuilderEditor,{siteWideUsage:s??{},flags:e.flags?{...e.flags,librarySite:Ne}:{librarySite:Ne},gotoPage:H,collections:r??[],getBlockAsyncProps:Q,themePresets:e.themePresets??[],pageId:m==null?void 0:m.id,loading:he,fallbackLang:l,languages:ae,brandingOptions:z,designTokens:st,translations:e.translations||{},locale:e.locale||"en",htmlDir:e.htmlDir||"ltr",autoSave:!P&&fe&&(e.autoSave??!0),autoSaveActionsCount:e.autoSaveActionsCount??10,onError:e.onError||console.error,getPartialBlockBlocks:F,getPartialBlocks:K,blocks:b?[]:L,theme:p.cloneDeep(z),pageTypes:a,searchPageTypeItems:le,askAiCallBack:S,onSave:async({blocks:Z,needTranslations:Le,partialIds:rs,linkPageIds:as,designTokens:te})=>{if(!E)return!0;M.current=Z;const ie=[...Z];return await N({page:E,blocks:ie,needTranslations:Le,partialIds:rs,linkPageIds:as,designTokens:te}),M.current=ie,!0},onSaveWebsiteData:async({type:Z,data:Le})=>(Z==="THEME"?await ne({settings:{theme:Le}}):Z==="DESIGN_TOKENS"&&await ne({settings:{designTokens:Le}}),!0),...ns,children:o.jsx(xl,{isFetchingPageData:b})}),o.jsx("div",{children:o.jsx(_l,{})})]})},Ll=new x.QueryClient({defaultOptions:{queries:{refetchOnWindowFocus:!1,refetchOnReconnect:!1,refetchOnMount:!1}}}),jl=e=>{const[,t]=It(),[s,n]=f.useState(!1);return f.useEffect(()=>(t(p.pick(e,["apiUrl","usersApiUrl","assetsApiUrl","getPreviewUrl","getLiveUrl","topLeftCorner","onLogout","getAccessToken","websocket","realtimeAdapter","getLoggedInUser","flags","currentUser"])),setTimeout(()=>{n(!0)},200),()=>{n(!1),t({})}),[e,t]),s?p.get(e,"hasReactQueryProvider",!1)===!0?o.jsxs(o.Fragment,{children:[o.jsx(Zs,{...e}),o.jsx(Js,{})]}):o.jsxs(x.QueryClientProvider,{client:Ll,children:[o.jsx(Zs,{...e}),o.jsx(Js,{})]}):o.jsx("div",{})},kl=W.lazy(()=>Promise.resolve().then(()=>require("./nested-path-selector-content-CvV4iQ6y.cjs")));function hr({data:e,onSelect:t,dataType:s="value",disabled:n=!1}){const[r,a]=W.useState(!1);return o.jsxs(g.Popover,{open:r,onOpenChange:a,children:[o.jsxs(g.Tooltip,{children:[o.jsx(g.TooltipTrigger,{asChild:!0,children:o.jsx(g.PopoverTrigger,{asChild:!0,children:o.jsx(v.Button,{size:"sm",variant:"outline",className:"h-6 w-6 px-1 py-0 text-[9px] text-muted-foreground",role:"combobox","aria-expanded":r,disabled:n,children:o.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24px",height:"24px",viewBox:"0 0 24 24",fill:"none",children:o.jsx("path",{d:"M9.5 5H9C7.89543 5 7 5.89543 7 7V9C7 10 6.4 12 4 12C5 12 7 12.6 7 15V17.0002C7 18.1048 7.89543 19 9 19H9.5M14.5 5H15C16.1046 5 17 5.89543 17 7V9C17 10 17.6 12 20 12C19 12 17 12.6 17 15V17.0002C17 18.1048 16.1046 19 15 19H14.5",stroke:"#000000",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2"})})})})}),o.jsx(g.TooltipContent,{children:"Add field"})]}),r&&o.jsx(W.Suspense,{children:o.jsx(kl,{data:e,onSelect:t,dataType:s,open:r,setOpen:a})})]})}const Dl=()=>{const{data:e}=se(),{data:t}=pe(),s=j(),n=G(),r=Yt(),a=xs();return x.useQuery({queryKey:[y.GET_BUILDER_PAGE_DATA,t==null?void 0:t.id,a],staleTime:1/0,gcTime:0,queryFn:async()=>n(s,{action:y.GET_BUILDER_PAGE_DATA,data:{pageType:e==null?void 0:e.pageType,lang:(t==null?void 0:t.lang)||r,dynamic:e==null?void 0:e.dynamic,pageProps:{slug:(t==null?void 0:t.slug)+a,searchParams:{},pageType:t==null?void 0:t.pageType,fallbackLang:r,lastSaved:t.lastSaved,pageId:e.id,primaryPageId:t.primaryPage||e.id,pageBaseSlug:t==null?void 0:t.slug,dynamic:e==null?void 0:e.dynamic,languagePageId:t.id,metadata:e.metadata||{}}}}),enabled:!!(e!=null&&e.pageType)&&!!t.id})},Gl=()=>{const{savePageAsync:e}=g.useSavePage(),t=x.useQueryClient(),{isLocked:s}=de();return f.useCallback(async()=>{s||await e(),t.invalidateQueries({queryKey:[y.GET_DRAFT_PAGE]}),t.invalidateQueries({queryKey:[y.GET_BUILDER_PAGE_DATA]})},[e,t,s])},Ol=()=>{const e=x.useQueryClient();return f.useCallback(()=>{e.clear()},[e])},Rl=()=>{const e=j(),t=G(),{data:s}=pe(),n=x.useQueryClient();return x.useMutation({mutationFn:async r=>{if(!(s!=null&&s.id))throw new Error("No active page found");return await t(`${e}`,{action:y.UPDATE_PAGE_METADATA,data:{id:s.id,metadata:r}})},onSuccess:()=>{n.invalidateQueries({queryKey:[y.GET_BUILDER_PAGE_DATA]}),n.invalidateQueries({queryKey:[y.GET_LANGUAGE_PAGES]})},onError:()=>{console.error("Failed to update metadata")}})},Ml=f.lazy(()=>Promise.resolve().then(()=>require("./digital-asset-manager-l1HTU_vW.cjs"))),Ul=({assetId:e,assetUrl:t,onChange:s,className:n="",placeholder:r="Select an image",disabled:a=!1})=>{const{t:i}=oe.useTranslation(),[l,c]=f.useState(!1),d=()=>{a||c(!0)},h=()=>{c(!1)},u=A=>{const b=Array.isArray(A)?A[0]:A;b!=null&&b.url&&s(p.pick(b,["url","id"])),c(!1)},E=()=>{s({url:"",id:""})},m=(t==null?void 0:t.startsWith("{{"))&&(t==null?void 0:t.endsWith("}}"));return o.jsxs("div",{className:`w-full ${n}`,children:[t?o.jsxs("div",{className:"relative overflow-hidden rounded-md border",children:[m?o.jsx("div",{className:"flex h-12 items-center bg-gray-100 px-4",children:o.jsx("p",{className:"text-xs text-gray-500",children:t})}):o.jsx("img",{onClick:d,src:t,alt:i("Selected image"),className:"h-auto max-h-[100px] w-full bg-gray-100 object-contain"}),o.jsxs("div",{className:"absolute right-2 top-2 flex gap-2",children:[o.jsx(v.Button,{type:"button",variant:"outline",size:"icon",className:"h-8 w-8 rounded-full bg-white text-red-500",onClick:E,disabled:a,children:m?o.jsx(_.X,{className:"h-4 w-4"}):o.jsx(_.Trash2,{className:"h-4 w-4"})}),!m&&o.jsx(v.Button,{type:"button",variant:"outline",size:"icon",className:"h-8 w-8 rounded-full bg-white/80 hover:bg-white/90",onClick:d,disabled:a,children:o.jsx(_.ImageIcon,{className:"h-4 w-4"})})]})]}):o.jsx("div",{className:`flex cursor-pointer items-center justify-center rounded-md border border-dashed p-6 ${a?"cursor-not-allowed opacity-50":"hover:border-gray-400"}`,onClick:d,children:o.jsxs("div",{className:"flex flex-col items-center gap-2",children:[o.jsx(_.ImageIcon,{className:"h-10 w-10 text-gray-400"}),o.jsx("p",{className:"text-sm text-gray-500",children:r})]})}),o.jsx(g.Dialog,{open:l,onOpenChange:c,children:o.jsxs(g.DialogContent,{className:"h-fit w-full max-w-7xl overflow-hidden p-0",children:[o.jsxs(g.DialogHeader,{className:"hidden border-b px-4 py-2",children:[o.jsx(g.DialogTitle,{children:i("Select Image")}),o.jsx(v.Button,{type:"button",variant:"ghost",size:"icon",className:"absolute right-4 top-2",onClick:h,children:o.jsx(_.X,{className:"h-4 w-4"})})]}),o.jsx("div",{className:"h-full flex-1 p-4",children:o.jsx(f.Suspense,{children:o.jsx(Ml,{close:h,onSelect:u,mode:"image",assetId:e})})})]})})]})},Bl=e=>e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),Ss=e=>{if(!e.trim())return{isValid:!1,parsed:null,placeholders:[],error:{message:"JSON is empty"}};try{return{isValid:!0,parsed:JSON.parse(e),error:null,placeholders:[]}}catch{}const t=/{{([^{}]+)}}/g,s=[];let n=e,r;for(;(r=t.exec(e))!==null;){const a=r[0],i=r.index,l=`"__placeholder_${s.length}__"`;s.push({original:a,replaced:l,position:i}),n=n.replace(a,l)}try{return{isValid:!0,parsed:JSON.parse(n),error:null,placeholders:s}}catch(a){const i=a,l=i.message.match(/position (\d+)/),c=l?parseInt(l[1]):void 0;let d,h;if(c!==void 0){const u=n.substring(0,c).split(`
2
- `);d=u.length,h=u[u.length-1].length+1}return{isValid:!1,parsed:null,placeholders:s,error:{message:i.message,line:d,column:h,position:c}}}},Fl=(e,t)=>{let n=JSON.stringify(e,null,2);return t.forEach(({original:r},a)=>{const i=`"__placeholder_${a}__"`,l=new RegExp(Bl(i),"g");n=n.replace(l,r)}),n},Hl=(e,t)=>{if(!e)return"";let s=JSON.stringify(e,null,2);const n=/{{([^{}]+)}}/g;let r;for(;(r=n.exec(s))!==null;){const a=r[1],i=p.get(t,a,null);s=s.replace(r[0],i)}return s},ql=f.lazy(()=>Promise.resolve().then(()=>require("./shared-json-ld-Wgwndrv1.cjs"))),Vl=({value:e,onChange:t,disabled:s=!1,readOnly:n=!1,placeholder:r="Enter JSON",rows:a=6,id:i="json-input",pageData:l={},handleFieldInsert:c,hasJsonLdForSelectedLang:d,copyJsonLDFromDefaultPage:h})=>{const[u,E]=f.useState("edit"),[m,A]=f.useState(null),[b,L]=f.useState(""),T=f.useRef(null),[S]=It(),N=i==="jsonLD"&&p.get(S,"flags.sharedJsonLD",!1),Q=i==="jsonLD"&&!d&&!!h;f.useEffect(()=>{e.trim()===""&&t("{}")},[e,t]);const K=H=>{if(n)return;const P=H.target.value;t(P)},F=H=>{if(H.key==="Tab"){H.preventDefault();const P=H.currentTarget,I=P.selectionStart,M=P.selectionEnd;if(I!==M){const ae=e.substring(I,M).split(`
3
- `);if(H.shiftKey){const fe=ae.map(he=>he.startsWith(" ")?he.substring(2):he).join(`
4
- `),ce=e.substring(0,I)+fe+e.substring(M);t(ce),setTimeout(()=>{P.selectionStart=I,P.selectionEnd=I+fe.length},0)}else{const fe=ae.map(he=>` ${he}`).join(`
5
- `),ce=e.substring(0,I)+fe+e.substring(M);t(ce),setTimeout(()=>{P.selectionStart=I,P.selectionEnd=I+fe.length},0)}}else{const z=e.substring(0,I)+" "+e.substring(M);t(z),setTimeout(()=>{P.selectionStart=P.selectionEnd=I+2},0)}}};f.useEffect(()=>{const H=Ss(e);H.isValid?f.startTransition(()=>{if(A(null),H.parsed){const P=Hl(H.parsed,l);L(P)}else L("")}):f.startTransition(()=>{A(H.error),L("")})},[e,l]);const le=()=>{const H=Ss(e);if(H.isValid&&H.parsed){const P=Fl(H.parsed,H.placeholders);t(P)}},ne=()=>{m!=null&&m.position&&T.current&&(T.current.focus(),T.current.setSelectionRange(m.position,m.position+1))};return o.jsx(_r.ErrorBoundary,{fallback:o.jsx("div",{children:"Some error"}),children:o.jsx("div",{className:"space-y-2",children:o.jsxs(g.Tabs,{value:u,onValueChange:E,className:"w-full",children:[o.jsxs("div",{className:"mb-2 flex items-center justify-between",children:[o.jsxs(g.TabsList,{className:"w-max",children:[o.jsxs(g.TabsTrigger,{value:"edit",className:"flex items-center gap-1",children:[o.jsx(_.Code,{className:"h-4 w-4"}),o.jsx("span",{children:"Edit"})]}),o.jsxs(g.TabsTrigger,{value:"preview",className:"flex items-center gap-1",disabled:!e.trim()||m!==null||Q,children:[o.jsx(_.Eye,{className:"h-4 w-4"}),o.jsx("span",{children:"Preview"})]}),N&&o.jsxs(g.TabsTrigger,{value:"shared",className:"flex items-center gap-1",disabled:!e.trim()||m!==null,children:[o.jsx(_.Share2,{className:"h-4 w-4"}),o.jsx("span",{children:"Shared"})]})]}),Q?null:u==="edit"&&!n&&o.jsx("div",{className:"flex items-center gap-2",children:o.jsx(hr,{dataType:"value",data:l??{},onSelect:H=>c&&c(H,i)})})]}),o.jsxs(g.TabsContent,{value:"edit",className:"relative mt-0",children:[!Q&&u==="edit"&&o.jsx(et,{content:"Format JSON",side:"right",showTooltip:!s&&!m,children:o.jsx(v.Button,{type:"button",variant:"outline",size:"icon",onClick:le,className:"absolute right-1 top-1 h-6 w-6 p-1",disabled:!e.trim()||s||m!==null,children:o.jsx(_.FileCode2,{})})}),Q?o.jsx("div",{className:"flex h-40 items-center justify-center rounded-md bg-black/20",children:o.jsxs("div",{className:"flex max-w-[400px] flex-col items-center gap-2 rounded-md bg-white p-4 shadow-lg",children:[o.jsx("div",{className:"max-w-xl text-center text-xs text-gray-500",children:"JSON-LD for is not added for selected language. JSON LD will be used from default language."}),o.jsxs(v.Button,{type:"button",variant:"default",size:"sm",onClick:h,children:[o.jsx(_.Plus,{}),"Copy & Edit from default language"]})]})}):o.jsx(g.Textarea,{ref:T,id:i,name:i,className:`rounded-md border border-input text-xs ${m?"border-red-500":""}`,onChange:K,onKeyDown:F,value:e,placeholder:r,rows:a,disabled:s,readOnly:n}),m&&o.jsxs(v.Alert,{variant:"destructive",className:"mt-2",children:[o.jsx(_.AlertTriangle,{className:"h-4 w-4"}),o.jsxs(v.AlertDescription,{className:"flex flex-col",children:[o.jsx("span",{className:"font-medium",children:"Invalid JSON"}),o.jsx("span",{className:"text-sm",children:m.message}),m.line&&m.column&&o.jsxs("span",{className:"text-sm",children:["Error at line ",m.line,", column ",m.column]}),o.jsx(v.Button,{type:"button",variant:"link",size:"sm",className:"mt-1 h-auto self-start p-0 text-sm",onClick:ne,children:"Show position"})]})]})]}),o.jsxs(g.TabsContent,{value:"preview",className:"mt-0",children:[o.jsx(g.Textarea,{rows:a,value:b,readOnly:!0,className:"cursor-default bg-muted font-mono text-sm"}),o.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:"This is how the JSON will look after placeholder substitution."})]}),N&&o.jsx(g.TabsContent,{value:"shared",className:"mt-0",children:o.jsx(f.Suspense,{children:o.jsx(ql,{})})})]})})})},Kl=e=>{const t=j(),s=G();return x.useQuery({queryKey:[y.GET_CHAI_USER,e],queryFn:async()=>{const n=await s(t,{action:y.GET_CHAI_USER,data:{userId:e}}),r=(n==null?void 0:n.data)||{};return{...r,name:r.name||r.email}},enabled:!p.isEmpty(e),staleTime:"static"})};class Ql{constructor(t){os(this,"channel");this.channel=t}get topic(){return this.channel.topic}getState(){const t=this.channel.state;return{closed:"CLOSED",errored:"ERROR",joined:"JOINED",joining:"JOINING",leaving:"LEAVING"}[t]||"CLOSED"}async subscribe(t){this.channel.subscribe(s=>{t(s)})}unsubscribe(){this.channel.unsubscribe()}onBroadcast(t,s){this.channel.on("broadcast",{event:t},s)}onPresence(t,s){this.channel.on("presence",{event:t},s)}async send(t,s){await this.channel.send({event:t,payload:s,type:"broadcast"})}async track(t){await this.channel.track(t)}untrack(){this.channel.untrack()}presenceState(){return this.channel.presenceState()}}class gr{constructor(t){os(this,"client");this.client=t}channel(t,s){const n=this.client.channel(t,s);return new Ql(n)}}function zl(e){return new gr(e)}if(typeof window>"u")throw new Error("@chaibuilder/pages is not available on the server");exports.$TRACK=Is;exports.ACTIONS=y;exports.BlurContainer=Ye;exports.ChaiWebsiteBuilder=jl;exports.Dynamic=wo;exports.EVENT=$;exports.For=Wi;exports.ImagePicker=Ul;exports.Index=Ji;exports.LANGUAGES=rt;exports.LanguageSwitcher=hn;exports.Match=Xi;exports.NestedPathSelector=hr;exports.PAGES_PERMISSIONS=ue;exports.PAGE_STATUS=X;exports.PageActionsDropdown=cn;exports.PermissionChecker=Ut;exports.Portal=xo;exports.Show=Yi;exports.SmartJsonInput=Vl;exports.SupabaseRealtimeAdapter=gr;exports.Switch=Zi;exports.Tooltip=et;exports.addEventListener=Bn;exports.addNewLangAtom=dt;exports.batch=ji;exports.className=Un;exports.clearDelegatedEvents=ho;exports.convertRemToPixels=hl;exports.createComponent=js;exports.createComputed=bn;exports.createContext=Ri;exports.createEffect=Ns;exports.createMemo=J;exports.createRealtimeAdapter=zl;exports.createRenderEffect=Pe;exports.createRoot=Se;exports.createSignal=q;exports.createUniqueId=$i;exports.delegateEvents=Mn;exports.deleteNestedDataByPath=lt;exports.displayValue=ol;exports.getMutationStatusColor=al;exports.getPreferredColorScheme=gl;exports.getQueryStatusColor=rl;exports.getQueryStatusColorByLabel=il;exports.getQueryStatusLabel=sl;exports.getSidedProp=nl;exports.insert=Jt;exports.memo=co;exports.mergeProps=ks;exports.mutationSortFns=fl;exports.navigateToPage=fn;exports.on=ki;exports.onCleanup=Ze;exports.onMount=Cn;exports.parseJSONWithPlaceholders=Ss;exports.previewUrlAtom=cr;exports.serialize=ar;exports.setAttribute=Wt;exports.sortFns=ul;exports.splitProps=Dn;exports.spread=Fn;exports.stringify=tl;exports.template=fo;exports.throwConfetti=at;exports.untrack=Y;exports.updateNestedDataByPath=ot;exports.use=Hn;exports.useAddGlobalSchema=ii;exports.useApiUrl=j;exports.useApplySchemaToAllPages=ui;exports.useBuilderFetch=jr;exports.useBuilderPageData=Dl;exports.useChaiAuth=Zt;exports.useChaiUserInfo=Kl;exports.useChaibuilderRealtime=da;exports.useChangePage=ur;exports.useChangeSlug=ka;exports.useCheckUserAccess=vs;exports.useClearAll=Ol;exports.useContext=Mi;exports.useCreatePage=Ca;exports.useCurrentActivePage=pe;exports.useCurrentPageOwner=dn;exports.useDeleteGlobalSchema=li;exports.useDeletePage=Ia;exports.useDynamicPageSelector=rn;exports.useFallbackLang=Yt;exports.useFetch=G;exports.useGotoPage=dr;exports.useIsLanguagePageCreated=En;exports.useLanguagePages=Nt;exports.useMarkAsTemplate=La;exports.usePageAllData=pn;exports.usePageEditInfo=on;exports.usePageLockMeta=ws;exports.usePageLockStatus=de;exports.usePageToUser=_s;exports.usePageType=ln;exports.usePageTypes=be;exports.usePagesProp=re;exports.usePagesProps=It;exports.usePrimaryPage=se;exports.useRealtimeAdapter=Ps;exports.useReloadPage=Gl;exports.useRemoveSchemaFromAllPages=di;exports.useSearchParams=Ee;exports.useSendRealtimeEvent=Cs;exports.useSiteWideUsage=fr;exports.useTogglePageGlobalSchema=ci;exports.useTransition=Oi;exports.useUnmarkAsTemplate=ja;exports.useUnpublishPage=Na;exports.useUpdateActivePageMetadata=Rl;exports.useUpdateGlobalSchema=oi;exports.useUpdatePage=va;exports.useUserId=jt;exports.useWebsiteLanguagePages=an;exports.useWebsitePrimaryPages=we;exports.useWebsiteSetting=_e;