@chaibuilder/sdk 4.0.0-beta.30 → 4.0.0-beta.32

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 (184) hide show
  1. package/dist/{2SSKDMRQ-Dub3pRV1.cjs → 2SSKDMRQ-DfXKDvXk.cjs} +1 -1
  2. package/dist/{2SSKDMRQ-B5Tzwoh4.js → 2SSKDMRQ-pPung-JB.js} +2 -2
  3. package/dist/{AP7HFJJL-CfmdXP9M.js → AP7HFJJL-CEJuc_Ox.js} +1 -1
  4. package/dist/{AP7HFJJL-Dt6MglIr.cjs → AP7HFJJL-PvPBwV6T.cjs} +1 -1
  5. package/dist/{IconPicker-DLqOB-ri.cjs → IconPicker-BJHUCDn4.cjs} +1 -1
  6. package/dist/{IconPicker-Cn8Z42-Z.js → IconPicker-D_GRfhwS.js} +1 -1
  7. package/dist/{WDYDFRGG-BOpmZGHS.js → WDYDFRGG-B3FrCE_j.js} +2 -2
  8. package/dist/{WDYDFRGG-Dfj1ikzw.cjs → WDYDFRGG-BPHlcLi5.cjs} +1 -1
  9. package/dist/{active-in-another-tab-CEWvA8SG.js → active-in-another-tab-C_Ma7oFU.js} +2 -2
  10. package/dist/{active-in-another-tab-DV83cJ_v.cjs → active-in-another-tab-WVYf-z5w.cjs} +1 -1
  11. package/dist/{add-new-language-page-C3Uu92KN.cjs → add-new-language-page-CxW2Vuyr.cjs} +1 -1
  12. package/dist/{add-new-language-page-B3wK94-S.js → add-new-language-page-DtsBO739.js} +3 -3
  13. package/dist/{add-new-page-BOE-xwBc.cjs → add-new-page-BfKt72NF.cjs} +1 -1
  14. package/dist/{add-new-page-DsvGVrR8.js → add-new-page-DG38rI6S.js} +2 -2
  15. package/dist/{ai-panel-content-DBlnfRRi.cjs → ai-panel-content-Dfo4jOVB.cjs} +1 -1
  16. package/dist/{ai-panel-content-BBSzHZG6.js → ai-panel-content-dktE9CIO.js} +3 -3
  17. package/dist/{ai-panel-default-lang-BVBuwnyU.js → ai-panel-default-lang-BbUTXMbm.js} +9 -9
  18. package/dist/{ai-panel-default-lang-DJJWAtN0.cjs → ai-panel-default-lang-GQCtwlPs.cjs} +2 -2
  19. package/dist/{ai-panel-other-lang-fIEZkmRy.js → ai-panel-other-lang-DIDS-mTi.js} +13 -13
  20. package/dist/{ai-panel-other-lang-v8Yd5ggR.cjs → ai-panel-other-lang-nCUxwpLX.cjs} +1 -1
  21. package/dist/{ai-prompt-input-CmSfGxTN.js → ai-prompt-input-B2q30bhR.js} +16 -16
  22. package/dist/{ai-prompt-input-C7ha_0Cn.cjs → ai-prompt-input-Dws5BHhQ.cjs} +1 -1
  23. package/dist/{ai-translation-prompt-BzTGAS3W.cjs → ai-translation-prompt-CJVcuWrs.cjs} +1 -1
  24. package/dist/{ai-translation-prompt-CtBmvsRy.js → ai-translation-prompt-D87qk3C1.js} +1 -1
  25. package/dist/{change-password-modal-CdOwtCWN.cjs → change-password-modal-CVUa60pC.cjs} +1 -1
  26. package/dist/{change-password-modal-DxkhBI5d.js → change-password-modal-PahNYs8x.js} +2 -2
  27. package/dist/{code-editor-Bpn8z2fo.js → code-editor-CWOmKcUc.js} +1 -1
  28. package/dist/{code-editor-fL3s6Hk7.cjs → code-editor-Cim6jQVF.cjs} +1 -1
  29. package/dist/{continue-editing-in-this-client-DDB816CQ.js → continue-editing-in-this-client-BYFOU3hH.js} +2 -2
  30. package/dist/{continue-editing-in-this-client-DjxpjsA8.cjs → continue-editing-in-this-client-CW0f2LRk.cjs} +1 -1
  31. package/dist/core.cjs +1 -1
  32. package/dist/core.d.ts +3 -0
  33. package/dist/core.js +37 -37
  34. package/dist/{css-import-modal-CL8SIC3K.js → css-import-modal-6bMTRlCg.js} +1 -1
  35. package/dist/{css-import-modal-CRC7bK1c.cjs → css-import-modal-CXulmaB4.cjs} +1 -1
  36. package/dist/{delete-page-41tvYcEw.js → delete-page-BDViv7Xm.js} +2 -2
  37. package/dist/{delete-page-BHPlx8ec.cjs → delete-page-CdByrw3j.cjs} +1 -1
  38. package/dist/{design-token-usage-DtdjTCn3.cjs → design-token-usage-D-hrcKz1.cjs} +1 -1
  39. package/dist/{design-token-usage-CyOY4Pni.js → design-token-usage-lf7N_uOk.js} +28 -28
  40. package/dist/digital-asset-manager-CxxhsToc.cjs +1 -0
  41. package/dist/{digital-asset-manager-C_ru4Zes.js → digital-asset-manager-PcYficIX.js} +5 -5
  42. package/dist/{duplicate-page-BvggF83O.cjs → duplicate-page-D2f3HvWX.cjs} +1 -1
  43. package/dist/{duplicate-page-DMmDdmfS.js → duplicate-page-DfEA148D.js} +3 -3
  44. package/dist/{dynamic-page-selector-D2z51nLi.js → dynamic-page-selector-DB__KD2y.js} +2 -2
  45. package/dist/{dynamic-page-selector-C5agz2Ze.cjs → dynamic-page-selector-Dz7D1Wdr.cjs} +1 -1
  46. package/dist/{get-chai-builder-tailwind-config-DNp8Vhme.cjs → get-chai-builder-tailwind-config-7CxFxEYL.cjs} +1 -1
  47. package/dist/{get-chai-builder-tailwind-config-k8l5sdcw.js → get-chai-builder-tailwind-config-DC4sDOYK.js} +3 -3
  48. package/dist/{get-chai-builder-theme-BSUcPs5t.js → get-chai-builder-theme-BpuwSLeS.js} +1 -1
  49. package/dist/{image-compression-DsZ1oqpb.js → image-compression-DPFITwOL.js} +2 -2
  50. package/dist/image-compression-UaU7Bwqe.cjs +1 -0
  51. package/dist/{image-editor-DFmlG348.cjs → image-editor-BdW476J8.cjs} +1 -1
  52. package/dist/{image-editor-sKvOFo-S.js → image-editor-CilPMtAC.js} +1 -1
  53. package/dist/index-Bzyv7mAh.cjs +5 -0
  54. package/dist/{index-BFnMzGe6.js → index-DsQXiNA_.js} +4997 -4877
  55. package/dist/{index-CA1OwKJX.js → index-IQefjAA0.js} +1696 -1640
  56. package/dist/index-mPCp0j2h.cjs +160 -0
  57. package/dist/{json-diff-viewer-DRQSNhaS.cjs → json-diff-viewer-BPqY25PU.cjs} +1 -1
  58. package/dist/{json-diff-viewer-B5wAR5GY.js → json-diff-viewer-Ci2IbgDn.js} +34 -34
  59. package/dist/{lang-panel-q04hEq5o.js → lang-panel-DlAQr-y9.js} +3 -3
  60. package/dist/{lang-panel-BZsICcBR.cjs → lang-panel-jebYHYGD.cjs} +1 -1
  61. package/dist/library-blocks/bento/agency-showcase/agency-showcase.html +175 -0
  62. package/dist/library-blocks/bento/agency-showcase/agency-showcase.webp +0 -0
  63. package/dist/library-blocks/bento/creative-portfolio/creative-portfolio.html +116 -0
  64. package/dist/library-blocks/bento/creative-portfolio/creative-portfolio.webp +0 -0
  65. package/dist/library-blocks/bento/product-features/product-features.html +159 -0
  66. package/dist/library-blocks/bento/product-features/product-features.webp +0 -0
  67. package/dist/library-blocks/bento/saas-dashboard/saas-dashboard.html +182 -0
  68. package/dist/library-blocks/bento/saas-dashboard/saas-dashboard.webp +0 -0
  69. package/dist/library-blocks/bento/startup-metrics/startup-metrics.html +170 -0
  70. package/dist/library-blocks/bento/startup-metrics/startup-metrics.webp +0 -0
  71. package/dist/library-blocks/blocks-list.json +145 -12
  72. package/dist/library-blocks/feature/agency-services/agency-services.html +194 -0
  73. package/dist/library-blocks/feature/agency-services/agency-services.webp +0 -0
  74. package/dist/library-blocks/feature/consulting-firm/consulting-firm.html +219 -0
  75. package/dist/library-blocks/feature/consulting-firm/consulting-firm.webp +0 -0
  76. package/dist/library-blocks/feature/design-studio/design-studio.html +190 -0
  77. package/dist/library-blocks/feature/design-studio/design-studio.webp +0 -0
  78. package/dist/library-blocks/feature/freelancer-toolkit/freelancer-toolkit.html +195 -0
  79. package/dist/library-blocks/feature/freelancer-toolkit/freelancer-toolkit.webp +0 -0
  80. package/dist/library-blocks/feature/marketing-agency/marketing-agency.html +212 -0
  81. package/dist/library-blocks/feature/marketing-agency/marketing-agency.webp +0 -0
  82. package/dist/library-blocks/footer/creative-agency/creative-agency.html +64 -0
  83. package/dist/library-blocks/footer/creative-agency/creative-agency.webp +0 -0
  84. package/dist/library-blocks/footer/minimal-portfolio/minimal-portfolio.html +106 -0
  85. package/dist/library-blocks/footer/minimal-portfolio/minimal-portfolio.webp +0 -0
  86. package/dist/library-blocks/footer/saas-startup/saas-startup.html +117 -0
  87. package/dist/library-blocks/footer/saas-startup/saas-startup.webp +0 -0
  88. package/dist/library-blocks/hero/creative-agency/creative-agency.html +117 -0
  89. package/dist/library-blocks/hero/creative-agency/creative-agency.webp +0 -0
  90. package/dist/library-blocks/hero/developer-focused/developer-focused.html +124 -0
  91. package/dist/library-blocks/hero/developer-focused/developer-focused.webp +0 -0
  92. package/dist/library-blocks/hero/minimal-saas/minimal-saas.html +98 -0
  93. package/dist/library-blocks/hero/minimal-saas/minimal-saas.webp +0 -0
  94. package/dist/library-blocks/hero/portfolio-showcase/portfolio-showcase.html +148 -0
  95. package/dist/library-blocks/hero/portfolio-showcase/portfolio-showcase.webp +0 -0
  96. package/dist/library-blocks/hero/startup-landing/startup-landing.html +130 -0
  97. package/dist/library-blocks/hero/startup-landing/startup-landing.webp +0 -0
  98. package/dist/library-blocks/navbar/creative-agency/creative-agency.html +139 -0
  99. package/dist/library-blocks/navbar/creative-agency/creative-agency.webp +0 -0
  100. package/dist/library-blocks/navbar/minimal-portfolio/minimal-portfolio.html +164 -0
  101. package/dist/library-blocks/navbar/minimal-portfolio/minimal-portfolio.webp +0 -0
  102. package/dist/library-blocks/navbar/saas-startup/saas-startup.html +129 -0
  103. package/dist/library-blocks/navbar/saas-startup/saas-startup.webp +0 -0
  104. package/dist/manage-design-tokens-BknGNAKE.cjs +1 -0
  105. package/dist/manage-design-tokens-Co5677WS.js +428 -0
  106. package/dist/manage-design-tokens-modal-9qpcb-EC.js +161 -0
  107. package/dist/manage-design-tokens-modal-BcgdwEXE.cjs +1 -0
  108. package/dist/{mark-as-template-raTtKmQ9.js → mark-as-template-DOZL3umP.js} +2 -2
  109. package/dist/{mark-as-template-CT-hLGIW.cjs → mark-as-template-DS-tMllK.cjs} +1 -1
  110. package/dist/{nested-path-selector-content-CzQ2Lorl.js → nested-path-selector-content-Be-pbnVl.js} +1 -1
  111. package/dist/{nested-path-selector-content-CSUHTj9G.cjs → nested-path-selector-content-CWmPgU-L.cjs} +1 -1
  112. package/dist/{no-language-page-content-Bg6VjMVY.js → no-language-page-content-C8W0M_Fj.js} +4 -4
  113. package/dist/{no-language-page-content-Bkj8JpEY.cjs → no-language-page-content-DWtEo657.cjs} +1 -1
  114. package/dist/{no-language-page-dialog-TffLjvJn.cjs → no-language-page-dialog-FVXkSnfT.cjs} +1 -1
  115. package/dist/{no-language-page-dialog-CRPMr9YT.js → no-language-page-dialog-cpCZ9vES.js} +2 -2
  116. package/dist/{page-creator-CQhE1tgn.js → page-creator-CFtxeW_t.js} +172 -172
  117. package/dist/{page-creator-RrUhy8uH.cjs → page-creator-o6yRzsVf.cjs} +1 -1
  118. package/dist/{page-lock-D9h5pgxn.cjs → page-lock-BS_ErOIW.cjs} +1 -1
  119. package/dist/{page-lock-Dye1JZBB.js → page-lock-Cthbk6Pg.js} +2 -2
  120. package/dist/{page-locked-dialog-b2_f-A7a.cjs → page-locked-dialog-BWXifuQ8.cjs} +1 -1
  121. package/dist/{page-locked-dialog-BMjPVyHF.js → page-locked-dialog-D5hmaWqw.js} +16 -16
  122. package/dist/page-manager-new-Dl5YwsMm.js +418 -0
  123. package/dist/page-manager-new-DpSqBzeh.cjs +1 -0
  124. package/dist/{page-manager-search-and-filter-DCcYyoPO.js → page-manager-search-and-filter-iFsFJhn4.js} +27 -26
  125. package/dist/{page-manager-search-and-filter-D0ZXojiu.cjs → page-manager-search-and-filter-jDoLrCB7.cjs} +1 -1
  126. package/dist/{page-revisions-content-mDwvH6J-.js → page-revisions-content-C1IGUurW.js} +13 -13
  127. package/dist/{page-revisions-content-BX8ZWebc.cjs → page-revisions-content-CeBepZEw.cjs} +1 -1
  128. package/dist/pages.cjs +1 -1
  129. package/dist/pages.d.ts +3 -0
  130. package/dist/pages.js +1 -1
  131. package/dist/{plugin-Dkmjb2_e.js → plugin-BSjgGgwo.js} +10 -10
  132. package/dist/{publish-pages-content-M_Kb8b-F.js → publish-pages-content-BpEoA1T6.js} +3 -3
  133. package/dist/{publish-pages-content-CR4e9inX.cjs → publish-pages-content-PNsiaGI-.cjs} +1 -1
  134. package/dist/render.cjs +1 -1
  135. package/dist/render.d.ts +1 -0
  136. package/dist/render.js +32 -32
  137. package/dist/{rte-widget-modal-BRSm1Lnp.cjs → rte-widget-modal-CC1KcrAT.cjs} +1 -1
  138. package/dist/{rte-widget-modal-CVZDktXI.js → rte-widget-modal-c3T09VeO.js} +1 -1
  139. package/dist/runtime.d.ts +1 -0
  140. package/dist/{save-to-lib-B1ccNhR2.js → save-to-lib-BERYhyxq.js} +27 -27
  141. package/dist/{save-to-lib-CYEAWxL9.cjs → save-to-lib-Bk59qO1r.cjs} +1 -1
  142. package/dist/sdk.css +1 -1
  143. package/dist/{selected-block-display-aGR7p5JC.js → selected-block-display-C6NxfC0N.js} +11 -11
  144. package/dist/{selected-block-display-MyU0rS4q.cjs → selected-block-display-vFSCOnw8.cjs} +1 -1
  145. package/dist/{seo-panel-B5mDwpaT.cjs → seo-panel-0vlr_dBq.cjs} +1 -1
  146. package/dist/{seo-panel-P9uixkoZ.js → seo-panel-COrEJZLA.js} +138 -138
  147. package/dist/{shared-json-ld-DhQJh_mT.cjs → shared-json-ld-C46hURIr.cjs} +1 -1
  148. package/dist/{shared-json-ld-Ba9GcvLr.js → shared-json-ld-DnTuCBc3.js} +70 -70
  149. package/dist/{slug-input-CAfGHqMW.js → slug-input-CAqkFZBq.js} +1 -1
  150. package/dist/{slug-input-BdMnlYKT.cjs → slug-input-Curnt2n3.cjs} +1 -1
  151. package/dist/supabase-actions.cjs +1 -1
  152. package/dist/supabase-actions.js +193 -195
  153. package/dist/{take-over-request-BeHTL28z.cjs → take-over-request-6fliSr8w.cjs} +1 -1
  154. package/dist/{take-over-request-CXjaDliJ.js → take-over-request-DvmM5qTu.js} +10 -10
  155. package/dist/{theme-panel-footer-D_gxD0j4.cjs → theme-panel-footer-3ixmq107.cjs} +1 -1
  156. package/dist/{theme-panel-footer-BkwhuXM7.js → theme-panel-footer-BlsXRcEY.js} +2 -2
  157. package/dist/{translation-warning-modal-D_vt37fW.cjs → translation-warning-modal-B876S5yp.cjs} +1 -1
  158. package/dist/{translation-warning-modal-CTfArsb1.js → translation-warning-modal-kRcfrPgo.js} +1 -1
  159. package/dist/types.d.ts +3 -0
  160. package/dist/{unmark-as-template-vFgMIdxN.js → unmark-as-template-Dn3klZKq.js} +2 -2
  161. package/dist/{unmark-as-template-D2bvjGKt.cjs → unmark-as-template-q1GblG-u.cjs} +1 -1
  162. package/dist/{unpublish-page-CxkjTzBB.js → unpublish-page-BbFZw0so.js} +2 -2
  163. package/dist/{unpublish-page-CPjHmtSM.cjs → unpublish-page-DMbcHmUV.cjs} +1 -1
  164. package/dist/unpublished-partials-modal-CEFXp1D1.cjs +1 -0
  165. package/dist/unpublished-partials-modal-Ts5ZhAK9.js +41 -0
  166. package/dist/utils.cjs +1 -1
  167. package/dist/utils.js +2 -2
  168. package/dist/{web-preview--by73Vvr.js → web-preview-B2YGL26D.js} +1 -1
  169. package/dist/{web-preview-C3AMe_BB.cjs → web-preview-C6SLwtqv.cjs} +1 -1
  170. package/package.json +2 -7
  171. package/dist/delete-design-token-B0md8qUi.js +0 -40
  172. package/dist/delete-design-token-C94IgWdi.cjs +0 -1
  173. package/dist/digital-asset-manager-DSLQz8qk.cjs +0 -1
  174. package/dist/image-compression-DZ9WMmyn.cjs +0 -1
  175. package/dist/index-Bzn_gpaK.cjs +0 -5
  176. package/dist/index-D30xvFa5.cjs +0 -160
  177. package/dist/library-blocks/hero-1/hero-1.html +0 -74
  178. package/dist/library-blocks/hero-1/hero-1.webp +0 -0
  179. package/dist/library-blocks/hero-2/hero-2.html +0 -95
  180. package/dist/library-blocks/hero-2/hero-2.webp +0 -0
  181. package/dist/manage-design-tokens-Cene3KEu.js +0 -241
  182. package/dist/manage-design-tokens-Di5C6nTj.cjs +0 -1
  183. package/dist/page-manager-new-2mDjnSqc.cjs +0 -1
  184. package/dist/page-manager-new-DP1b_dXt.js +0 -411
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),s=require("./index-D30xvFa5.cjs"),m=require("./register-chai-top-bar-DyW9GPzV.cjs"),c=require("./index-Bzn_gpaK.cjs"),q=require("@tanstack/react-query"),I=require("lodash-es"),N=require("lucide-react"),x=require("react"),F=require("sonner"),z=()=>{const t=c.useApiUrl(),d=c.useFetch();return q.useQuery({queryKey:[c.ACTIONS.GET_GLOBAL_JSONLD_ITEMS],queryFn:async()=>d(t,{action:c.ACTIONS.GET_GLOBAL_JSONLD_ITEMS})})},U=({show:t,onClose:d,initialData:n})=>e.jsx(s.Dialog,{open:t,onOpenChange:()=>d(),children:t&&e.jsx(_,{show:t,onClose:d,initialData:n})}),_=({show:t,onClose:d,initialData:n})=>{const[r,j]=x.useState({name:"",content:"",description:"",enabledByDefaultForNewPages:!1}),[b,C]=x.useState(!1),{data:p}=c.useChaiCurrentPage(),{mutateAsync:S,isPending:f}=c.useAddGlobalSchema(),{mutateAsync:u}=c.useTogglePageGlobalSchema(),w=q.useQueryClient();x.useEffect(()=>{j(n?{name:n.name,description:n.description,content:JSON.stringify(n.jsonld,null,2),enabledByDefaultForNewPages:!1}:{name:"",description:"",content:"",enabledByDefaultForNewPages:!1}),C(!1)},[t,n]);const i=async()=>{if(!r.name||!r.content){F.toast.error("Please enter a name and content");return}const l=c.parseJSONWithPlaceholders(r.content);if(!l.isValid){F.toast.error("Invalid JSON-LD content");return}const y={name:r.name,jsonld:l.parsed,addToExistingPages:b,addToNewPages:r.enabledByDefaultForNewPages,description:r.description};n!=null&&n.primaryPageId&&(y.primaryPage=n.primaryPageId);const A=await S(y);p!=null&&p.id&&(A!=null&&A.id)&&!(n!=null&&n.primaryPageId)&&(await u({schemaId:A.id,pageId:p.id,enabled:!0}),w.invalidateQueries({queryKey:[c.ACTIONS.GET_LANGUAGE_PAGES,p.id]})),d()};return e.jsxs(s.DialogContent,{className:"flex max-w-xl flex-col overflow-y-auto",children:[e.jsx(s.DialogHeader,{children:e.jsx(s.DialogTitle,{children:"Add New Shared JSON-LD Schema"})}),e.jsxs("div",{className:"flex max-h-[75vh] flex-col space-y-2 overflow-y-auto",children:[(n==null?void 0:n.languageCode)&&e.jsxs(m.Alert,{className:"border-blue-200 bg-blue-50",children:[e.jsx(N.Info,{className:"h-4 w-4 text-blue-600"}),e.jsxs(m.AlertDescription,{className:"text-sm text-blue-800",children:["You are creating a ",e.jsx("span",{className:"font-semibold",children:n.languageCode})," language version of this schema. This will be linked to the default language schema."]})]}),e.jsxs("div",{children:[e.jsx(s.Label,{htmlFor:"new-name",children:"Schema Name"}),e.jsx(m.Input,{id:"new-name",value:r.name,onChange:l=>j({...r,name:l.target.value}),placeholder:"e.g., Product Schema",className:"text-xs"})]}),e.jsxs("div",{children:[e.jsx(s.Label,{htmlFor:"new-description",children:"Description"}),e.jsx(m.Input,{id:"new-description",value:r.description||"",onChange:l=>j({...r,description:l.target.value}),placeholder:"Brief description of this schema"})]}),e.jsxs("div",{children:[e.jsx(s.Label,{htmlFor:"new-content",children:"JSON-LD Content"}),e.jsx(c.SmartJsonInput,{id:"new-content",value:r.content||"{}",onChange:l=>j({...r,content:l}),placeholder:"Enter JSON-LD markup...",rows:10})]}),!(n!=null&&n.primaryPageId)&&e.jsxs("div",{className:"flex flex-col gap-3 pt-2",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("input",{type:"checkbox",id:"add-to-all-existing",checked:b,onChange:l=>C(l.target.checked),className:"h-5 w-5 cursor-pointer rounded focus:outline-none focus:ring-2 focus:ring-primary focus:ring-offset-1"}),e.jsxs(s.Label,{htmlFor:"add-to-all-existing",children:[e.jsx("div",{children:"Add to all existing pages"}),e.jsx("div",{className:"text-xs font-light text-muted-foreground",children:"This schema will be added to all existing pages on your site"})]})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("input",{type:"checkbox",id:"new-enabled",checked:r.enabledByDefaultForNewPages,onChange:l=>j({...r,enabledByDefaultForNewPages:l.target.checked}),className:"h-5 w-5 cursor-pointer rounded focus:outline-none focus:ring-2 focus:ring-primary focus:ring-offset-1"}),e.jsxs(s.Label,{htmlFor:"new-enabled",children:[e.jsx("div",{children:"Enabled by default for new pages"}),e.jsx("div",{className:"text-xs font-light text-muted-foreground",children:"New pages will automatically include this schema"})]})]})]}),e.jsx("div",{className:"border-t pt-3",children:e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx(m.Button,{disabled:f,variant:"outline",type:"button",size:"sm",onClick:()=>d(),children:"Cancel"}),e.jsx(m.Button,{disabled:f,type:"button",size:"sm",onClick:i,children:f?e.jsxs(e.Fragment,{children:[e.jsx(N.Loader,{className:"h-4 w-4 animate-spin"})," Adding"]}):e.jsxs(e.Fragment,{children:["Add Schema",(n==null?void 0:n.languageCode)&&` (${n.languageCode})`]})})]})})]})]})},H=({id:t,onClose:d})=>e.jsx(s.Dialog,{open:!!t,onOpenChange:()=>d(),children:t&&e.jsx(Q,{id:t,onClose:d})}),Q=({id:t,onClose:d})=>{const[n,r]=x.useState({name:"",content:"",description:"",enabledByDefaultForNewPages:!1}),[j,b]=x.useState(!1),[C,p]=x.useState(!1),[S,f]=x.useState(!1),{data:u}=z(),{mutateAsync:w,isPending:i}=c.useUpdateGlobalSchema(),{mutateAsync:l}=c.useApplySchemaToAllPages(),{mutateAsync:y}=c.useRemoveSchemaFromAllPages();x.useEffect(()=>{var h,D;if(t&&u){const v=u.find(L=>L.id===t);v&&(r({name:v.name,description:((h=v.metadata)==null?void 0:h.description)||"",content:JSON.stringify(v.jsonld,null,2),enabledByDefaultForNewPages:((D=v.metadata)==null?void 0:D.addToNewPages)||!1}),f(!!v.primaryPage))}},[t,u]);const A=async()=>{if(!n.name||!n.content){F.toast.error("Please enter a name and content");return}const h=c.parseJSONWithPlaceholders(n.content);if(!h.isValid){F.toast.error("Invalid JSON-LD content");return}const D={id:t,name:n.name,jsonld:h.parsed,addToNewPages:n.enabledByDefaultForNewPages,description:n.description};await w(D),d()},O=async()=>{try{await l(t)}finally{b(!1)}},T=async()=>{try{await y(t)}finally{p(!1)}};return e.jsxs(s.DialogContent,{className:"flex max-w-xl flex-col overflow-y-auto",children:[e.jsx(s.DialogHeader,{children:e.jsx(s.DialogTitle,{children:"Edit Shared JSON-LD Schema"})}),e.jsxs("div",{className:"flex max-h-[75vh] flex-col space-y-2 overflow-y-auto",children:[!S&&e.jsxs("div",{className:"flex items-center justify-between rounded-lg border border-blue-300 bg-blue-500/10 p-2",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium text-blue-900",children:"Manage Existing Pages"}),e.jsx("div",{className:"text-xs text-blue-700",children:"Add or remove this schema from all existing pages on your site"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(m.Button,{size:"sm",className:"text-xs",variant:"outline",onClick:()=>b(!0),children:"Add to all existing"}),e.jsx(m.Button,{size:"sm",variant:"ghost",className:"text-xs",onClick:()=>p(!0),children:"Remove from all"})]})]}),e.jsxs("div",{children:[e.jsx(s.Label,{htmlFor:"edit-name",children:"Schema Name"}),e.jsx(m.Input,{id:"edit-name",value:n.name,onChange:h=>r({...n,name:h.target.value}),placeholder:"e.g., Product Schema",className:"text-xs"})]}),e.jsxs("div",{children:[e.jsx(s.Label,{htmlFor:"edit-description",children:"Description"}),e.jsx(m.Input,{id:"edit-description",value:n.description||"",onChange:h=>r({...n,description:h.target.value}),placeholder:"Brief description of this schema"})]}),e.jsxs("div",{children:[e.jsx(s.Label,{htmlFor:"edit-content",children:"JSON-LD Content"}),e.jsx(c.SmartJsonInput,{id:"edit-content",value:n.content||"{}",onChange:h=>r({...n,content:h}),placeholder:"Enter JSON-LD markup...",rows:10})]}),!S&&e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("input",{type:"checkbox",id:"edit-enabled",checked:n.enabledByDefaultForNewPages,onChange:h=>r({...n,enabledByDefaultForNewPages:h.target.checked}),className:"h-5 w-5 cursor-pointer rounded focus:outline-none focus:ring-2 focus:ring-primary focus:ring-offset-1"}),e.jsxs(s.Label,{htmlFor:"edit-enabled",children:[e.jsx("div",{children:"Enabled by default for new pages"}),e.jsx("div",{className:"text-xs font-light text-muted-foreground",children:"New pages will automatically include this schema"})]})]}),e.jsx("div",{className:"border-t pt-3",children:e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx(m.Button,{disabled:i,variant:"outline",type:"button",size:"sm",onClick:()=>d(),children:"Cancel"}),e.jsx(m.Button,{disabled:i,type:"button",size:"sm",onClick:A,children:i?e.jsxs(e.Fragment,{children:[e.jsx(N.Loader,{className:"h-4 w-4 animate-spin"})," Updating"]}):"Update Schema"})]})})]}),e.jsx(s.AlertDialog,{open:j,onOpenChange:b,children:e.jsxs(s.AlertDialogContent,{children:[e.jsxs(s.AlertDialogHeader,{children:[e.jsx(s.AlertDialogTitle,{children:"Add to All Existing Pages?"}),e.jsxs(s.AlertDialogDescription,{children:["This will add the schema ",e.jsx("span",{className:"font-medium",children:n.name})," to all existing pages on your site. This action cannot be undone automatically."]})]}),e.jsxs(s.AlertDialogFooter,{children:[e.jsx(s.AlertDialogCancel,{children:"Cancel"}),e.jsx(s.AlertDialogAction,{onClick:O,children:"Add to All"})]})]})}),e.jsx(s.AlertDialog,{open:C,onOpenChange:p,children:e.jsxs(s.AlertDialogContent,{children:[e.jsxs(s.AlertDialogHeader,{children:[e.jsx(s.AlertDialogTitle,{children:"Remove from All Pages?"}),e.jsxs(s.AlertDialogDescription,{children:["This will remove the schema ",e.jsx("span",{className:"font-medium",children:n.name})," from all existing pages on your site. This action cannot be undone automatically."]})]}),e.jsxs(s.AlertDialogFooter,{children:[e.jsx(s.AlertDialogCancel,{children:"Cancel"}),e.jsx(s.AlertDialogAction,{onClick:T,className:"bg-red-500 hover:bg-red-600",children:"Remove from All"})]})]})})]})};function V(){const[t,d]=x.useState(!1),[n,r]=x.useState(void 0),[j,b]=x.useState(null),[C,p]=x.useState(null),[S,f]=x.useState(null),{data:u,isLoading:w}=z(),{selectedLang:i}=s.useLanguages(),{data:l}=c.useChaiCurrentPage(),{data:y}=c.useLanguagePages(),{mutateAsync:A}=c.useDeleteGlobalSchema(),{mutateAsync:O}=c.useTogglePageGlobalSchema(),T=x.useMemo(()=>y==null?void 0:y.find(a=>!a.primaryPage&&a.lang===""),[y]),h=x.useMemo(()=>(T==null?void 0:T.globalJsonLds)||[],[T]),D=x.useMemo(()=>u?I.filter(u,o=>o.primaryPage===null&&o.lang==="").map(o=>{const g=i?I.find(u,P=>P.primaryPage===o.id&&P.lang===i):null;return{defaultSchema:o,languageVersion:g,displayItem:g||o,hasLanguageVersion:!!g}}):[],[u,i]),[v,L]=x.useState([]),E=v.length>0?v:(l==null?void 0:l.globalJsonLds)||[];x.useEffect(()=>{l!=null&&l.globalJsonLds&&L(l.globalJsonLds)},[l==null?void 0:l.globalJsonLds]);const R=async a=>{if(!(l!=null&&l.id))return;f(a);const o=E.includes(a),g=o?E.filter(P=>P!==a):[...E,a];L(g);try{await O({schemaId:a,pageId:l.id,enabled:!o})}catch{L(l.globalJsonLds)}finally{f(null)}},M=async a=>{f(a);try{await A(a)}finally{f(null)}};return e.jsxs("div",{className:"rounded border bg-muted p-2",children:[e.jsxs("div",{className:"flex items-center justify-between pb-2",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-xs font-medium",children:"Shared JSON-LD Templates"}),e.jsx("div",{className:"w-full text-xs text-gray-500",children:"Manage reusable JSON-LD schemas that can be applied across multiple pages"})]}),!i&&e.jsxs(s.Tooltip,{delayDuration:0,children:[e.jsx(s.TooltipTrigger,{type:"button",disabled:w,className:"rounded-full bg-primary p-1 text-primary-foreground hover:bg-primary/80",onClick:a=>{a.stopPropagation(),d(!0)},children:w?e.jsx(N.Loader,{className:"h-4 w-4 animate-spin"}):e.jsx(N.Plus,{className:"h-4 w-4"})}),e.jsx(s.TooltipContent,{children:"Add new schema"})]})]}),e.jsxs(s.ScrollArea,{className:"max-h-96 overflow-y-auto",children:[e.jsxs("div",{className:"space-y-2",children:[(!u||(u==null?void 0:u.length)===0)&&!w&&e.jsx("div",{className:"flex items-center justify-center px-2 py-4 text-xs",children:"No shared JSON-LD found"}),D.map(({defaultSchema:a,displayItem:o,hasLanguageVersion:g})=>{var B,G;const P=E.includes(o.id),J=h.includes(a.id),k=g&&i?J:P;return e.jsxs(s.Card,{className:`relative border-gray-300 p-0 shadow-none transition-all ${S===o.id?"pointer-events-none":""}`,children:[S===o.id&&e.jsx("div",{className:"absolute bottom-0 left-0 right-0 top-0 z-50 flex items-center justify-center rounded-xl bg-white/80",children:e.jsx(N.Loader,{className:"h-5 w-5 animate-spin text-primary"})}),e.jsx(s.CardHeader,{className:"p-2",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[(g||!i)&&e.jsxs(s.Tooltip,{delayDuration:0,children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx("input",{type:"checkbox",checked:k,onChange:()=>R(a.id),disabled:!!(g&&i),className:"h-5 w-5 cursor-pointer rounded focus:outline-none focus:ring-2 focus:ring-primary focus:ring-offset-1"})}),g&&i&&e.jsx(s.TooltipContent,{children:"Using the default language state"})]}),e.jsxs("div",{children:[e.jsxs(s.CardTitle,{className:"flex items-center gap-2 text-sm leading-none",children:[o.name,g&&i&&e.jsxs("span",{className:"text-xs font-normal text-muted-foreground",children:["(",i,")"]}),k&&e.jsx("span",{className:"sr-only text-xs font-normal text-muted-foreground",children:"Enabled"})]}),((B=o==null?void 0:o.metadata)==null?void 0:B.description)&&e.jsx("p",{className:"mt-1 text-xs leading-none text-muted-foreground",children:(G=o==null?void 0:o.metadata)==null?void 0:G.description})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"mx-2 h-6 w-px bg-border"}),e.jsxs(s.Tooltip,{delayDuration:0,children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx(m.Button,{type:"button",variant:"ghost",size:"icon",className:"h-5 w-5 p-0",onClick:()=>p(o.id),children:e.jsx(N.Eye,{className:"h-4 w-4"})})}),e.jsx(s.TooltipContent,{children:"View schema"})]}),(g||!i)&&e.jsxs(e.Fragment,{children:[e.jsxs(s.Tooltip,{delayDuration:0,children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx(m.Button,{type:"button",variant:"ghost",size:"icon",className:"h-5 w-5 p-0",onClick:()=>b(o.id),children:e.jsx(N.Edit,{className:"h-4 w-4"})})}),e.jsx(s.TooltipContent,{children:"Edit schema"})]}),e.jsxs(s.AlertDialog,{children:[e.jsxs(s.Tooltip,{delayDuration:0,children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx(s.AlertDialogTrigger,{className:"flex h-5 w-5 items-center justify-center rounded-md text-red-500 hover:bg-red-100 hover:text-red-800",children:e.jsx(N.Trash,{className:"h-4 w-4"})})}),e.jsx(s.TooltipContent,{children:"Delete schema"})]}),e.jsxs(s.AlertDialogContent,{children:[e.jsxs(s.AlertDialogHeader,{children:[e.jsx(s.AlertDialogTitle,{children:"Delete Schema"}),e.jsxs(s.AlertDialogDescription,{children:["Are you sure you want to delete"," ",e.jsx("span",{className:"font-medium",children:o.name}),"? This action cannot be undone."]})]}),e.jsxs(s.AlertDialogFooter,{children:[e.jsx(s.AlertDialogCancel,{type:"button",children:"Cancel"}),e.jsx(s.AlertDialogAction,{type:"button",onClick:()=>M(o.id),className:"bg-red-500 text-white hover:bg-red-600",children:"Delete"})]})]})]})]})]})]})}),!g&&i&&e.jsx(s.CardContent,{className:"px-2 pb-2",children:e.jsxs("div",{className:"flex w-full flex-col items-center justify-center rounded-lg border bg-gray-100 py-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"max-w-xl text-center text-xs text-gray-500",children:["Not available in '",i,"' language. Default language JSONLD will be used."]}),J&&e.jsx("span",{className:"rounded-full bg-green-100 px-2 py-0.5 text-xs font-medium text-green-700",children:"Enabled in default"})]}),e.jsx(m.Button,{type:"button",size:"sm",variant:"outline",className:"mt-2",onClick:()=>{r({name:a.name,description:a.description||"",jsonld:a.jsonld,languageCode:i,primaryPageId:a.id}),d(!0)},children:"Copy & Edit from default language"})]})})]},a.id)})]}),w&&e.jsx("div",{className:"flex items-center justify-center p-4",children:e.jsx(N.Loader,{className:"h-5 w-5 animate-spin"})})]}),e.jsx(U,{show:t,onClose:()=>{d(!1),r(void 0)},initialData:n}),e.jsx(H,{id:j,onClose:()=>b(null)}),e.jsx(K,{schema:u==null?void 0:u.find(a=>a.id===C),onClose:()=>p(null)})]})}const K=({schema:t,onClose:d})=>e.jsx(s.Dialog,{open:!!t,onOpenChange:d,children:e.jsxs(s.DialogContent,{className:"max-w-2xl",children:[e.jsx(s.DialogHeader,{children:e.jsxs(s.DialogTitle,{className:"flex items-center gap-2",children:[t==null?void 0:t.name,(t==null?void 0:t.lang)&&e.jsxs("span",{className:"text-sm font-normal text-muted-foreground",children:["(",t.lang,")"]})]})}),e.jsxs("div",{className:"space-y-3",children:[(t==null?void 0:t.description)&&e.jsxs("div",{children:[e.jsx("div",{className:"text-xs font-medium text-muted-foreground",children:"Description"}),e.jsx("div",{className:"text-sm",children:t.description})]}),e.jsxs("div",{children:[e.jsx("div",{className:"mb-2 text-xs font-medium text-muted-foreground",children:"JSON-LD Schema"}),e.jsx(s.Textarea,{value:JSON.stringify(t==null?void 0:t.jsonld,null,2),readOnly:!0,className:"font-mono text-xs",rows:15})]})]})]})});exports.default=V;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),s=require("./index-mPCp0j2h.cjs"),m=require("./register-chai-top-bar-DyW9GPzV.cjs"),c=require("./index-Bzyv7mAh.cjs"),q=require("@tanstack/react-query"),I=require("lodash-es"),N=require("lucide-react"),x=require("react"),F=require("sonner"),z=()=>{const t=c.useApiUrl(),d=c.useFetch();return q.useQuery({queryKey:[c.ACTIONS.GET_GLOBAL_JSONLD_ITEMS],queryFn:async()=>d(t,{action:c.ACTIONS.GET_GLOBAL_JSONLD_ITEMS})})},U=({show:t,onClose:d,initialData:n})=>e.jsx(s.Dialog,{open:t,onOpenChange:()=>d(),children:t&&e.jsx(_,{show:t,onClose:d,initialData:n})}),_=({show:t,onClose:d,initialData:n})=>{const[r,j]=x.useState({name:"",content:"",description:"",enabledByDefaultForNewPages:!1}),[b,C]=x.useState(!1),{data:p}=c.useChaiCurrentPage(),{mutateAsync:S,isPending:f}=c.useAddGlobalSchema(),{mutateAsync:u}=c.useTogglePageGlobalSchema(),w=q.useQueryClient();x.useEffect(()=>{j(n?{name:n.name,description:n.description,content:JSON.stringify(n.jsonld,null,2),enabledByDefaultForNewPages:!1}:{name:"",description:"",content:"",enabledByDefaultForNewPages:!1}),C(!1)},[t,n]);const i=async()=>{if(!r.name||!r.content){F.toast.error("Please enter a name and content");return}const l=c.parseJSONWithPlaceholders(r.content);if(!l.isValid){F.toast.error("Invalid JSON-LD content");return}const y={name:r.name,jsonld:l.parsed,addToExistingPages:b,addToNewPages:r.enabledByDefaultForNewPages,description:r.description};n!=null&&n.primaryPageId&&(y.primaryPage=n.primaryPageId);const A=await S(y);p!=null&&p.id&&(A!=null&&A.id)&&!(n!=null&&n.primaryPageId)&&(await u({schemaId:A.id,pageId:p.id,enabled:!0}),w.invalidateQueries({queryKey:[c.ACTIONS.GET_LANGUAGE_PAGES,p.id]})),d()};return e.jsxs(s.DialogContent,{className:"flex max-w-xl flex-col overflow-y-auto",children:[e.jsx(s.DialogHeader,{children:e.jsx(s.DialogTitle,{children:"Add New Shared JSON-LD Schema"})}),e.jsxs("div",{className:"flex max-h-[75vh] flex-col space-y-2 overflow-y-auto",children:[(n==null?void 0:n.languageCode)&&e.jsxs(m.Alert,{className:"border-blue-200 bg-blue-50",children:[e.jsx(N.Info,{className:"h-4 w-4 text-blue-600"}),e.jsxs(m.AlertDescription,{className:"text-sm text-blue-800",children:["You are creating a ",e.jsx("span",{className:"font-semibold",children:n.languageCode})," language version of this schema. This will be linked to the default language schema."]})]}),e.jsxs("div",{children:[e.jsx(s.Label,{htmlFor:"new-name",children:"Schema Name"}),e.jsx(m.Input,{id:"new-name",value:r.name,onChange:l=>j({...r,name:l.target.value}),placeholder:"e.g., Product Schema",className:"text-xs"})]}),e.jsxs("div",{children:[e.jsx(s.Label,{htmlFor:"new-description",children:"Description"}),e.jsx(m.Input,{id:"new-description",value:r.description||"",onChange:l=>j({...r,description:l.target.value}),placeholder:"Brief description of this schema"})]}),e.jsxs("div",{children:[e.jsx(s.Label,{htmlFor:"new-content",children:"JSON-LD Content"}),e.jsx(c.SmartJsonInput,{id:"new-content",value:r.content||"{}",onChange:l=>j({...r,content:l}),placeholder:"Enter JSON-LD markup...",rows:10})]}),!(n!=null&&n.primaryPageId)&&e.jsxs("div",{className:"flex flex-col gap-3 pt-2",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("input",{type:"checkbox",id:"add-to-all-existing",checked:b,onChange:l=>C(l.target.checked),className:"h-5 w-5 cursor-pointer rounded focus:outline-none focus:ring-2 focus:ring-primary focus:ring-offset-1"}),e.jsxs(s.Label,{htmlFor:"add-to-all-existing",children:[e.jsx("div",{children:"Add to all existing pages"}),e.jsx("div",{className:"text-xs font-light text-muted-foreground",children:"This schema will be added to all existing pages on your site"})]})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("input",{type:"checkbox",id:"new-enabled",checked:r.enabledByDefaultForNewPages,onChange:l=>j({...r,enabledByDefaultForNewPages:l.target.checked}),className:"h-5 w-5 cursor-pointer rounded focus:outline-none focus:ring-2 focus:ring-primary focus:ring-offset-1"}),e.jsxs(s.Label,{htmlFor:"new-enabled",children:[e.jsx("div",{children:"Enabled by default for new pages"}),e.jsx("div",{className:"text-xs font-light text-muted-foreground",children:"New pages will automatically include this schema"})]})]})]}),e.jsx("div",{className:"border-t pt-3",children:e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx(m.Button,{disabled:f,variant:"outline",type:"button",size:"sm",onClick:()=>d(),children:"Cancel"}),e.jsx(m.Button,{disabled:f,type:"button",size:"sm",onClick:i,children:f?e.jsxs(e.Fragment,{children:[e.jsx(N.Loader,{className:"h-4 w-4 animate-spin"})," Adding"]}):e.jsxs(e.Fragment,{children:["Add Schema",(n==null?void 0:n.languageCode)&&` (${n.languageCode})`]})})]})})]})]})},H=({id:t,onClose:d})=>e.jsx(s.Dialog,{open:!!t,onOpenChange:()=>d(),children:t&&e.jsx(Q,{id:t,onClose:d})}),Q=({id:t,onClose:d})=>{const[n,r]=x.useState({name:"",content:"",description:"",enabledByDefaultForNewPages:!1}),[j,b]=x.useState(!1),[C,p]=x.useState(!1),[S,f]=x.useState(!1),{data:u}=z(),{mutateAsync:w,isPending:i}=c.useUpdateGlobalSchema(),{mutateAsync:l}=c.useApplySchemaToAllPages(),{mutateAsync:y}=c.useRemoveSchemaFromAllPages();x.useEffect(()=>{var h,D;if(t&&u){const v=u.find(L=>L.id===t);v&&(r({name:v.name,description:((h=v.metadata)==null?void 0:h.description)||"",content:JSON.stringify(v.jsonld,null,2),enabledByDefaultForNewPages:((D=v.metadata)==null?void 0:D.addToNewPages)||!1}),f(!!v.primaryPage))}},[t,u]);const A=async()=>{if(!n.name||!n.content){F.toast.error("Please enter a name and content");return}const h=c.parseJSONWithPlaceholders(n.content);if(!h.isValid){F.toast.error("Invalid JSON-LD content");return}const D={id:t,name:n.name,jsonld:h.parsed,addToNewPages:n.enabledByDefaultForNewPages,description:n.description};await w(D),d()},O=async()=>{try{await l(t)}finally{b(!1)}},T=async()=>{try{await y(t)}finally{p(!1)}};return e.jsxs(s.DialogContent,{className:"flex max-w-xl flex-col overflow-y-auto",children:[e.jsx(s.DialogHeader,{children:e.jsx(s.DialogTitle,{children:"Edit Shared JSON-LD Schema"})}),e.jsxs("div",{className:"flex max-h-[75vh] flex-col space-y-2 overflow-y-auto",children:[!S&&e.jsxs("div",{className:"flex items-center justify-between rounded-lg border border-blue-300 bg-blue-500/10 p-2",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium text-blue-900",children:"Manage Existing Pages"}),e.jsx("div",{className:"text-xs text-blue-700",children:"Add or remove this schema from all existing pages on your site"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(m.Button,{size:"sm",className:"text-xs",variant:"outline",onClick:()=>b(!0),children:"Add to all existing"}),e.jsx(m.Button,{size:"sm",variant:"ghost",className:"text-xs",onClick:()=>p(!0),children:"Remove from all"})]})]}),e.jsxs("div",{children:[e.jsx(s.Label,{htmlFor:"edit-name",children:"Schema Name"}),e.jsx(m.Input,{id:"edit-name",value:n.name,onChange:h=>r({...n,name:h.target.value}),placeholder:"e.g., Product Schema",className:"text-xs"})]}),e.jsxs("div",{children:[e.jsx(s.Label,{htmlFor:"edit-description",children:"Description"}),e.jsx(m.Input,{id:"edit-description",value:n.description||"",onChange:h=>r({...n,description:h.target.value}),placeholder:"Brief description of this schema"})]}),e.jsxs("div",{children:[e.jsx(s.Label,{htmlFor:"edit-content",children:"JSON-LD Content"}),e.jsx(c.SmartJsonInput,{id:"edit-content",value:n.content||"{}",onChange:h=>r({...n,content:h}),placeholder:"Enter JSON-LD markup...",rows:10})]}),!S&&e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("input",{type:"checkbox",id:"edit-enabled",checked:n.enabledByDefaultForNewPages,onChange:h=>r({...n,enabledByDefaultForNewPages:h.target.checked}),className:"h-5 w-5 cursor-pointer rounded focus:outline-none focus:ring-2 focus:ring-primary focus:ring-offset-1"}),e.jsxs(s.Label,{htmlFor:"edit-enabled",children:[e.jsx("div",{children:"Enabled by default for new pages"}),e.jsx("div",{className:"text-xs font-light text-muted-foreground",children:"New pages will automatically include this schema"})]})]}),e.jsx("div",{className:"border-t pt-3",children:e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx(m.Button,{disabled:i,variant:"outline",type:"button",size:"sm",onClick:()=>d(),children:"Cancel"}),e.jsx(m.Button,{disabled:i,type:"button",size:"sm",onClick:A,children:i?e.jsxs(e.Fragment,{children:[e.jsx(N.Loader,{className:"h-4 w-4 animate-spin"})," Updating"]}):"Update Schema"})]})})]}),e.jsx(s.AlertDialog,{open:j,onOpenChange:b,children:e.jsxs(s.AlertDialogContent,{children:[e.jsxs(s.AlertDialogHeader,{children:[e.jsx(s.AlertDialogTitle,{children:"Add to All Existing Pages?"}),e.jsxs(s.AlertDialogDescription,{children:["This will add the schema ",e.jsx("span",{className:"font-medium",children:n.name})," to all existing pages on your site. This action cannot be undone automatically."]})]}),e.jsxs(s.AlertDialogFooter,{children:[e.jsx(s.AlertDialogCancel,{children:"Cancel"}),e.jsx(s.AlertDialogAction,{onClick:O,children:"Add to All"})]})]})}),e.jsx(s.AlertDialog,{open:C,onOpenChange:p,children:e.jsxs(s.AlertDialogContent,{children:[e.jsxs(s.AlertDialogHeader,{children:[e.jsx(s.AlertDialogTitle,{children:"Remove from All Pages?"}),e.jsxs(s.AlertDialogDescription,{children:["This will remove the schema ",e.jsx("span",{className:"font-medium",children:n.name})," from all existing pages on your site. This action cannot be undone automatically."]})]}),e.jsxs(s.AlertDialogFooter,{children:[e.jsx(s.AlertDialogCancel,{children:"Cancel"}),e.jsx(s.AlertDialogAction,{onClick:T,className:"bg-red-500 hover:bg-red-600",children:"Remove from All"})]})]})})]})};function V(){const[t,d]=x.useState(!1),[n,r]=x.useState(void 0),[j,b]=x.useState(null),[C,p]=x.useState(null),[S,f]=x.useState(null),{data:u,isLoading:w}=z(),{selectedLang:i}=s.useLanguages(),{data:l}=c.useChaiCurrentPage(),{data:y}=c.useLanguagePages(),{mutateAsync:A}=c.useDeleteGlobalSchema(),{mutateAsync:O}=c.useTogglePageGlobalSchema(),T=x.useMemo(()=>y==null?void 0:y.find(a=>!a.primaryPage&&a.lang===""),[y]),h=x.useMemo(()=>(T==null?void 0:T.globalJsonLds)||[],[T]),D=x.useMemo(()=>u?I.filter(u,o=>o.primaryPage===null&&o.lang==="").map(o=>{const g=i?I.find(u,P=>P.primaryPage===o.id&&P.lang===i):null;return{defaultSchema:o,languageVersion:g,displayItem:g||o,hasLanguageVersion:!!g}}):[],[u,i]),[v,L]=x.useState([]),E=v.length>0?v:(l==null?void 0:l.globalJsonLds)||[];x.useEffect(()=>{l!=null&&l.globalJsonLds&&L(l.globalJsonLds)},[l==null?void 0:l.globalJsonLds]);const R=async a=>{if(!(l!=null&&l.id))return;f(a);const o=E.includes(a),g=o?E.filter(P=>P!==a):[...E,a];L(g);try{await O({schemaId:a,pageId:l.id,enabled:!o})}catch{L(l.globalJsonLds)}finally{f(null)}},M=async a=>{f(a);try{await A(a)}finally{f(null)}};return e.jsxs("div",{className:"rounded border bg-muted p-2",children:[e.jsxs("div",{className:"flex items-center justify-between pb-2",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-xs font-medium",children:"Shared JSON-LD Templates"}),e.jsx("div",{className:"w-full text-xs text-gray-500",children:"Manage reusable JSON-LD schemas that can be applied across multiple pages"})]}),!i&&e.jsxs(s.Tooltip,{delayDuration:0,children:[e.jsx(s.TooltipTrigger,{type:"button",disabled:w,className:"rounded-full bg-primary p-1 text-primary-foreground hover:bg-primary/80",onClick:a=>{a.stopPropagation(),d(!0)},children:w?e.jsx(N.Loader,{className:"h-4 w-4 animate-spin"}):e.jsx(N.Plus,{className:"h-4 w-4"})}),e.jsx(s.TooltipContent,{children:"Add new schema"})]})]}),e.jsxs(s.ScrollArea,{className:"max-h-96 overflow-y-auto",children:[e.jsxs("div",{className:"space-y-2",children:[(!u||(u==null?void 0:u.length)===0)&&!w&&e.jsx("div",{className:"flex items-center justify-center px-2 py-4 text-xs",children:"No shared JSON-LD found"}),D.map(({defaultSchema:a,displayItem:o,hasLanguageVersion:g})=>{var B,G;const P=E.includes(o.id),J=h.includes(a.id),k=g&&i?J:P;return e.jsxs(s.Card,{className:`relative border-gray-300 p-0 shadow-none transition-all ${S===o.id?"pointer-events-none":""}`,children:[S===o.id&&e.jsx("div",{className:"absolute bottom-0 left-0 right-0 top-0 z-50 flex items-center justify-center rounded-xl bg-white/80",children:e.jsx(N.Loader,{className:"h-5 w-5 animate-spin text-primary"})}),e.jsx(s.CardHeader,{className:"p-2",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[(g||!i)&&e.jsxs(s.Tooltip,{delayDuration:0,children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx("input",{type:"checkbox",checked:k,onChange:()=>R(a.id),disabled:!!(g&&i),className:"h-5 w-5 cursor-pointer rounded focus:outline-none focus:ring-2 focus:ring-primary focus:ring-offset-1"})}),g&&i&&e.jsx(s.TooltipContent,{children:"Using the default language state"})]}),e.jsxs("div",{children:[e.jsxs(s.CardTitle,{className:"flex items-center gap-2 text-sm leading-none",children:[o.name,g&&i&&e.jsxs("span",{className:"text-xs font-normal text-muted-foreground",children:["(",i,")"]}),k&&e.jsx("span",{className:"sr-only text-xs font-normal text-muted-foreground",children:"Enabled"})]}),((B=o==null?void 0:o.metadata)==null?void 0:B.description)&&e.jsx("p",{className:"mt-1 text-xs leading-none text-muted-foreground",children:(G=o==null?void 0:o.metadata)==null?void 0:G.description})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"mx-2 h-6 w-px bg-border"}),e.jsxs(s.Tooltip,{delayDuration:0,children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx(m.Button,{type:"button",variant:"ghost",size:"icon",className:"h-5 w-5 p-0",onClick:()=>p(o.id),children:e.jsx(N.Eye,{className:"h-4 w-4"})})}),e.jsx(s.TooltipContent,{children:"View schema"})]}),(g||!i)&&e.jsxs(e.Fragment,{children:[e.jsxs(s.Tooltip,{delayDuration:0,children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx(m.Button,{type:"button",variant:"ghost",size:"icon",className:"h-5 w-5 p-0",onClick:()=>b(o.id),children:e.jsx(N.Edit,{className:"h-4 w-4"})})}),e.jsx(s.TooltipContent,{children:"Edit schema"})]}),e.jsxs(s.AlertDialog,{children:[e.jsxs(s.Tooltip,{delayDuration:0,children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx(s.AlertDialogTrigger,{className:"flex h-5 w-5 items-center justify-center rounded-md text-red-500 hover:bg-red-100 hover:text-red-800",children:e.jsx(N.Trash,{className:"h-4 w-4"})})}),e.jsx(s.TooltipContent,{children:"Delete schema"})]}),e.jsxs(s.AlertDialogContent,{children:[e.jsxs(s.AlertDialogHeader,{children:[e.jsx(s.AlertDialogTitle,{children:"Delete Schema"}),e.jsxs(s.AlertDialogDescription,{children:["Are you sure you want to delete"," ",e.jsx("span",{className:"font-medium",children:o.name}),"? This action cannot be undone."]})]}),e.jsxs(s.AlertDialogFooter,{children:[e.jsx(s.AlertDialogCancel,{type:"button",children:"Cancel"}),e.jsx(s.AlertDialogAction,{type:"button",onClick:()=>M(o.id),className:"bg-red-500 text-white hover:bg-red-600",children:"Delete"})]})]})]})]})]})]})}),!g&&i&&e.jsx(s.CardContent,{className:"px-2 pb-2",children:e.jsxs("div",{className:"flex w-full flex-col items-center justify-center rounded-lg border bg-gray-100 py-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"max-w-xl text-center text-xs text-gray-500",children:["Not available in '",i,"' language. Default language JSONLD will be used."]}),J&&e.jsx("span",{className:"rounded-full bg-green-100 px-2 py-0.5 text-xs font-medium text-green-700",children:"Enabled in default"})]}),e.jsx(m.Button,{type:"button",size:"sm",variant:"outline",className:"mt-2",onClick:()=>{r({name:a.name,description:a.description||"",jsonld:a.jsonld,languageCode:i,primaryPageId:a.id}),d(!0)},children:"Copy & Edit from default language"})]})})]},a.id)})]}),w&&e.jsx("div",{className:"flex items-center justify-center p-4",children:e.jsx(N.Loader,{className:"h-5 w-5 animate-spin"})})]}),e.jsx(U,{show:t,onClose:()=>{d(!1),r(void 0)},initialData:n}),e.jsx(H,{id:j,onClose:()=>b(null)}),e.jsx(K,{schema:u==null?void 0:u.find(a=>a.id===C),onClose:()=>p(null)})]})}const K=({schema:t,onClose:d})=>e.jsx(s.Dialog,{open:!!t,onOpenChange:d,children:e.jsxs(s.DialogContent,{className:"max-w-2xl",children:[e.jsx(s.DialogHeader,{children:e.jsxs(s.DialogTitle,{className:"flex items-center gap-2",children:[t==null?void 0:t.name,(t==null?void 0:t.lang)&&e.jsxs("span",{className:"text-sm font-normal text-muted-foreground",children:["(",t.lang,")"]})]})}),e.jsxs("div",{className:"space-y-3",children:[(t==null?void 0:t.description)&&e.jsxs("div",{children:[e.jsx("div",{className:"text-xs font-medium text-muted-foreground",children:"Description"}),e.jsx("div",{className:"text-sm",children:t.description})]}),e.jsxs("div",{children:[e.jsx("div",{className:"mb-2 text-xs font-medium text-muted-foreground",children:"JSON-LD Schema"}),e.jsx(s.Textarea,{value:JSON.stringify(t==null?void 0:t.jsonld,null,2),readOnly:!0,className:"font-mono text-xs",rows:15})]})]})]})});exports.default=V;
@@ -1,24 +1,24 @@
1
1
  import { jsx as e, jsxs as n, Fragment as G } from "react/jsx-runtime";
2
- import { D as W, e as $, f as X, g as Y, q as y, F as U, H as _, I as R, J as M, K as q, M as H, O as K, Q, d as me, x as L, y as F, z as J, a6 as he, U as ue, V as ge, W as fe, G as pe, X as xe, T as Ne } from "./index-BFnMzGe6.js";
2
+ import { D as $, e as W, f as Y, g as X, q as y, a0 as U, a1 as _, as as R, a2 as q, a3 as H, at as M, a4 as K, a5 as Q, d as me, x as L, y as J, z as F, a6 as he, G as ue, H as ge, I as fe, au as pe, J as xe, T as Ne } from "./index-DsQXiNA_.js";
3
3
  import { D as be, F as ye, z as j, B as v } from "./register-chai-top-bar-D6GjnauV.js";
4
- import { ar as ve, as as we, A as V, aw as te, aD as Ae, aE as se, aF as re, aG as de, aH as Ce, aI as Se, aJ as Pe, l as Te, aK as De } from "./index-CA1OwKJX.js";
4
+ import { ar as ve, as as we, A as V, aw as le, aD as Ae, aE as se, aF as re, aG as de, aH as Ce, aI as Se, aJ as Pe, l as Te, aK as De } from "./index-IQefjAA0.js";
5
5
  import { useQuery as Ee, useQueryClient as Le } from "@tanstack/react-query";
6
- import { filter as Fe, find as Je } from "lodash-es";
6
+ import { filter as Je, find as Fe } from "lodash-es";
7
7
  import { Info as Oe, Loader as O, Plus as ke, Eye as Ge, Edit as je, Trash as Be } from "lucide-react";
8
8
  import { useState as g, useEffect as Z, useMemo as z } from "react";
9
9
  import { toast as B } from "sonner";
10
10
  const oe = () => {
11
- const l = ve(), i = we();
11
+ const t = ve(), i = we();
12
12
  return Ee({
13
13
  queryKey: [V.GET_GLOBAL_JSONLD_ITEMS],
14
- queryFn: async () => i(l, { action: V.GET_GLOBAL_JSONLD_ITEMS })
14
+ queryFn: async () => i(t, { action: V.GET_GLOBAL_JSONLD_ITEMS })
15
15
  });
16
16
  }, Ie = ({
17
- show: l,
17
+ show: t,
18
18
  onClose: i,
19
19
  initialData: a
20
- }) => /* @__PURE__ */ e(W, { open: l, onOpenChange: () => i(), children: l && /* @__PURE__ */ e(ze, { show: l, onClose: i, initialData: a }) }), ze = ({
21
- show: l,
20
+ }) => /* @__PURE__ */ e($, { open: t, onOpenChange: () => i(), children: t && /* @__PURE__ */ e(ze, { show: t, onClose: i, initialData: a }) }), ze = ({
21
+ show: t,
22
22
  onClose: i,
23
23
  initialData: a
24
24
  }) => {
@@ -27,7 +27,7 @@ const oe = () => {
27
27
  content: "",
28
28
  description: "",
29
29
  enabledByDefaultForNewPages: !1
30
- }), [x, S] = g(!1), { data: u } = te(), { mutateAsync: C, isPending: p } = Ae(), { mutateAsync: c } = se(), w = Le();
30
+ }), [x, S] = g(!1), { data: u } = le(), { mutateAsync: C, isPending: p } = Ae(), { mutateAsync: c } = se(), w = Le();
31
31
  Z(() => {
32
32
  f(a ? {
33
33
  name: a.name,
@@ -35,20 +35,20 @@ const oe = () => {
35
35
  content: JSON.stringify(a.jsonld, null, 2),
36
36
  enabledByDefaultForNewPages: !1
37
37
  } : { name: "", description: "", content: "", enabledByDefaultForNewPages: !1 }), S(!1);
38
- }, [l, a]);
38
+ }, [t, a]);
39
39
  const o = async () => {
40
40
  if (!d.name || !d.content) {
41
41
  B.error("Please enter a name and content");
42
42
  return;
43
43
  }
44
- const t = de(d.content);
45
- if (!t.isValid) {
44
+ const l = de(d.content);
45
+ if (!l.isValid) {
46
46
  B.error("Invalid JSON-LD content");
47
47
  return;
48
48
  }
49
49
  const N = {
50
50
  name: d.name,
51
- jsonld: t.parsed,
51
+ jsonld: l.parsed,
52
52
  addToExistingPages: x,
53
53
  addToNewPages: d.enabledByDefaultForNewPages,
54
54
  description: d.description
@@ -63,8 +63,8 @@ const oe = () => {
63
63
  queryKey: [V.GET_LANGUAGE_PAGES, u.id]
64
64
  })), i();
65
65
  };
66
- return /* @__PURE__ */ n($, { className: "flex max-w-xl flex-col overflow-y-auto", children: [
67
- /* @__PURE__ */ e(X, { children: /* @__PURE__ */ e(Y, { children: "Add New Shared JSON-LD Schema" }) }),
66
+ return /* @__PURE__ */ n(W, { className: "flex max-w-xl flex-col overflow-y-auto", children: [
67
+ /* @__PURE__ */ e(Y, { children: /* @__PURE__ */ e(X, { children: "Add New Shared JSON-LD Schema" }) }),
68
68
  /* @__PURE__ */ n("div", { className: "flex max-h-[75vh] flex-col space-y-2 overflow-y-auto", children: [
69
69
  (a == null ? void 0 : a.languageCode) && /* @__PURE__ */ n(be, { className: "border-blue-200 bg-blue-50", children: [
70
70
  /* @__PURE__ */ e(Oe, { className: "h-4 w-4 text-blue-600" }),
@@ -81,7 +81,7 @@ const oe = () => {
81
81
  {
82
82
  id: "new-name",
83
83
  value: d.name,
84
- onChange: (t) => f({ ...d, name: t.target.value }),
84
+ onChange: (l) => f({ ...d, name: l.target.value }),
85
85
  placeholder: "e.g., Product Schema",
86
86
  className: "text-xs"
87
87
  }
@@ -94,7 +94,7 @@ const oe = () => {
94
94
  {
95
95
  id: "new-description",
96
96
  value: d.description || "",
97
- onChange: (t) => f({ ...d, description: t.target.value }),
97
+ onChange: (l) => f({ ...d, description: l.target.value }),
98
98
  placeholder: "Brief description of this schema"
99
99
  }
100
100
  )
@@ -106,7 +106,7 @@ const oe = () => {
106
106
  {
107
107
  id: "new-content",
108
108
  value: d.content || "{}",
109
- onChange: (t) => f({ ...d, content: t }),
109
+ onChange: (l) => f({ ...d, content: l }),
110
110
  placeholder: "Enter JSON-LD markup...",
111
111
  rows: 10
112
112
  }
@@ -120,7 +120,7 @@ const oe = () => {
120
120
  type: "checkbox",
121
121
  id: "add-to-all-existing",
122
122
  checked: x,
123
- onChange: (t) => S(t.target.checked),
123
+ onChange: (l) => S(l.target.checked),
124
124
  className: "h-5 w-5 cursor-pointer rounded focus:outline-none focus:ring-2 focus:ring-primary focus:ring-offset-1"
125
125
  }
126
126
  ),
@@ -136,7 +136,7 @@ const oe = () => {
136
136
  type: "checkbox",
137
137
  id: "new-enabled",
138
138
  checked: d.enabledByDefaultForNewPages,
139
- onChange: (t) => f({ ...d, enabledByDefaultForNewPages: t.target.checked }),
139
+ onChange: (l) => f({ ...d, enabledByDefaultForNewPages: l.target.checked }),
140
140
  className: "h-5 w-5 cursor-pointer rounded focus:outline-none focus:ring-2 focus:ring-primary focus:ring-offset-1"
141
141
  }
142
142
  ),
@@ -158,17 +158,17 @@ const oe = () => {
158
158
  ] }) })
159
159
  ] })
160
160
  ] });
161
- }, Ue = ({ id: l, onClose: i }) => /* @__PURE__ */ e(W, { open: !!l, onOpenChange: () => i(), children: l && /* @__PURE__ */ e(_e, { id: l, onClose: i }) }), _e = ({ id: l, onClose: i }) => {
161
+ }, Ue = ({ id: t, onClose: i }) => /* @__PURE__ */ e($, { open: !!t, onOpenChange: () => i(), children: t && /* @__PURE__ */ e(_e, { id: t, onClose: i }) }), _e = ({ id: t, onClose: i }) => {
162
162
  const [a, d] = g({
163
163
  name: "",
164
164
  content: "",
165
165
  description: "",
166
166
  enabledByDefaultForNewPages: !1
167
- }), [f, x] = g(!1), [S, u] = g(!1), [C, p] = g(!1), { data: c } = oe(), { mutateAsync: w, isPending: o } = Ce(), { mutateAsync: t } = Se(), { mutateAsync: N } = Pe();
167
+ }), [f, x] = g(!1), [S, u] = g(!1), [C, p] = g(!1), { data: c } = oe(), { mutateAsync: w, isPending: o } = Ce(), { mutateAsync: l } = Se(), { mutateAsync: N } = Pe();
168
168
  Z(() => {
169
169
  var m, T;
170
- if (l && c) {
171
- const b = c.find((E) => E.id === l);
170
+ if (t && c) {
171
+ const b = c.find((E) => E.id === t);
172
172
  b && (d({
173
173
  name: b.name,
174
174
  description: ((m = b.metadata) == null ? void 0 : m.description) || "",
@@ -176,7 +176,7 @@ const oe = () => {
176
176
  enabledByDefaultForNewPages: ((T = b.metadata) == null ? void 0 : T.addToNewPages) || !1
177
177
  }), p(!!b.primaryPage));
178
178
  }
179
- }, [l, c]);
179
+ }, [t, c]);
180
180
  const A = async () => {
181
181
  if (!a.name || !a.content) {
182
182
  B.error("Please enter a name and content");
@@ -188,7 +188,7 @@ const oe = () => {
188
188
  return;
189
189
  }
190
190
  const T = {
191
- id: l,
191
+ id: t,
192
192
  name: a.name,
193
193
  jsonld: m.parsed,
194
194
  addToNewPages: a.enabledByDefaultForNewPages,
@@ -197,19 +197,19 @@ const oe = () => {
197
197
  await w(T), i();
198
198
  }, I = async () => {
199
199
  try {
200
- await t(l);
200
+ await l(t);
201
201
  } finally {
202
202
  x(!1);
203
203
  }
204
204
  }, P = async () => {
205
205
  try {
206
- await N(l);
206
+ await N(t);
207
207
  } finally {
208
208
  u(!1);
209
209
  }
210
210
  };
211
- return /* @__PURE__ */ n($, { className: "flex max-w-xl flex-col overflow-y-auto", children: [
212
- /* @__PURE__ */ e(X, { children: /* @__PURE__ */ e(Y, { children: "Edit Shared JSON-LD Schema" }) }),
211
+ return /* @__PURE__ */ n(W, { className: "flex max-w-xl flex-col overflow-y-auto", children: [
212
+ /* @__PURE__ */ e(Y, { children: /* @__PURE__ */ e(X, { children: "Edit Shared JSON-LD Schema" }) }),
213
213
  /* @__PURE__ */ n("div", { className: "flex max-h-[75vh] flex-col space-y-2 overflow-y-auto", children: [
214
214
  !C && /* @__PURE__ */ n("div", { className: "flex items-center justify-between rounded-lg border border-blue-300 bg-blue-500/10 p-2", children: [
215
215
  /* @__PURE__ */ n("div", { children: [
@@ -285,37 +285,37 @@ const oe = () => {
285
285
  ] }),
286
286
  /* @__PURE__ */ e(U, { open: f, onOpenChange: x, children: /* @__PURE__ */ n(_, { children: [
287
287
  /* @__PURE__ */ n(R, { children: [
288
- /* @__PURE__ */ e(M, { children: "Add to All Existing Pages?" }),
289
- /* @__PURE__ */ n(q, { children: [
288
+ /* @__PURE__ */ e(q, { children: "Add to All Existing Pages?" }),
289
+ /* @__PURE__ */ n(H, { children: [
290
290
  "This will add the schema ",
291
291
  /* @__PURE__ */ e("span", { className: "font-medium", children: a.name }),
292
292
  " to all existing pages on your site. This action cannot be undone automatically."
293
293
  ] })
294
294
  ] }),
295
- /* @__PURE__ */ n(H, { children: [
295
+ /* @__PURE__ */ n(M, { children: [
296
296
  /* @__PURE__ */ e(K, { children: "Cancel" }),
297
297
  /* @__PURE__ */ e(Q, { onClick: I, children: "Add to All" })
298
298
  ] })
299
299
  ] }) }),
300
300
  /* @__PURE__ */ e(U, { open: S, onOpenChange: u, children: /* @__PURE__ */ n(_, { children: [
301
301
  /* @__PURE__ */ n(R, { children: [
302
- /* @__PURE__ */ e(M, { children: "Remove from All Pages?" }),
303
- /* @__PURE__ */ n(q, { children: [
302
+ /* @__PURE__ */ e(q, { children: "Remove from All Pages?" }),
303
+ /* @__PURE__ */ n(H, { children: [
304
304
  "This will remove the schema ",
305
305
  /* @__PURE__ */ e("span", { className: "font-medium", children: a.name }),
306
306
  " from all existing pages on your site. This action cannot be undone automatically."
307
307
  ] })
308
308
  ] }),
309
- /* @__PURE__ */ n(H, { children: [
309
+ /* @__PURE__ */ n(M, { children: [
310
310
  /* @__PURE__ */ e(K, { children: "Cancel" }),
311
311
  /* @__PURE__ */ e(Q, { onClick: P, className: "bg-red-500 hover:bg-red-600", children: "Remove from All" })
312
312
  ] })
313
313
  ] }) })
314
314
  ] });
315
315
  };
316
- function Ye() {
317
- const [l, i] = g(!1), [a, d] = g(void 0), [f, x] = g(null), [S, u] = g(null), [C, p] = g(null), { data: c, isLoading: w } = oe(), { selectedLang: o } = me(), { data: t } = te(), { data: N } = Te(), { mutateAsync: A } = De(), { mutateAsync: I } = se(), P = z(() => N == null ? void 0 : N.find((s) => !s.primaryPage && s.lang === ""), [N]), m = z(() => (P == null ? void 0 : P.globalJsonLds) || [], [P]), T = z(() => c ? Fe(c, (r) => r.primaryPage === null && r.lang === "").map((r) => {
318
- const h = o ? Je(c, (D) => D.primaryPage === r.id && D.lang === o) : null;
316
+ function Xe() {
317
+ const [t, i] = g(!1), [a, d] = g(void 0), [f, x] = g(null), [S, u] = g(null), [C, p] = g(null), { data: c, isLoading: w } = oe(), { selectedLang: o } = me(), { data: l } = le(), { data: N } = Te(), { mutateAsync: A } = De(), { mutateAsync: I } = se(), P = z(() => N == null ? void 0 : N.find((s) => !s.primaryPage && s.lang === ""), [N]), m = z(() => (P == null ? void 0 : P.globalJsonLds) || [], [P]), T = z(() => c ? Je(c, (r) => r.primaryPage === null && r.lang === "").map((r) => {
318
+ const h = o ? Fe(c, (D) => D.primaryPage === r.id && D.lang === o) : null;
319
319
  return {
320
320
  defaultSchema: r,
321
321
  languageVersion: h,
@@ -323,23 +323,23 @@ function Ye() {
323
323
  displayItem: h || r,
324
324
  hasLanguageVersion: !!h
325
325
  };
326
- }) : [], [c, o]), [b, E] = g([]), k = b.length > 0 ? b : (t == null ? void 0 : t.globalJsonLds) || [];
326
+ }) : [], [c, o]), [b, E] = g([]), k = b.length > 0 ? b : (l == null ? void 0 : l.globalJsonLds) || [];
327
327
  Z(() => {
328
- t != null && t.globalJsonLds && E(t.globalJsonLds);
329
- }, [t == null ? void 0 : t.globalJsonLds]);
328
+ l != null && l.globalJsonLds && E(l.globalJsonLds);
329
+ }, [l == null ? void 0 : l.globalJsonLds]);
330
330
  const ie = async (s) => {
331
- if (!(t != null && t.id)) return;
331
+ if (!(l != null && l.id)) return;
332
332
  p(s);
333
333
  const r = k.includes(s), h = r ? k.filter((D) => D !== s) : [...k, s];
334
334
  E(h);
335
335
  try {
336
336
  await I({
337
337
  schemaId: s,
338
- pageId: t.id,
338
+ pageId: l.id,
339
339
  enabled: !r
340
340
  });
341
341
  } catch {
342
- E(t.globalJsonLds);
342
+ E(l.globalJsonLds);
343
343
  } finally {
344
344
  p(null);
345
345
  }
@@ -359,7 +359,7 @@ function Ye() {
359
359
  ] }),
360
360
  !o && /* @__PURE__ */ n(L, { delayDuration: 0, children: [
361
361
  /* @__PURE__ */ e(
362
- F,
362
+ J,
363
363
  {
364
364
  type: "button",
365
365
  disabled: w,
@@ -370,14 +370,14 @@ function Ye() {
370
370
  children: w ? /* @__PURE__ */ e(O, { className: "h-4 w-4 animate-spin" }) : /* @__PURE__ */ e(ke, { className: "h-4 w-4" })
371
371
  }
372
372
  ),
373
- /* @__PURE__ */ e(J, { children: "Add new schema" })
373
+ /* @__PURE__ */ e(F, { children: "Add new schema" })
374
374
  ] })
375
375
  ] }),
376
376
  /* @__PURE__ */ n(he, { className: "max-h-96 overflow-y-auto", children: [
377
377
  /* @__PURE__ */ n("div", { className: "space-y-2", children: [
378
378
  (!c || (c == null ? void 0 : c.length) === 0) && !w && /* @__PURE__ */ e("div", { className: "flex items-center justify-center px-2 py-4 text-xs", children: "No shared JSON-LD found" }),
379
379
  T.map(({ defaultSchema: s, displayItem: r, hasLanguageVersion: h }) => {
380
- var ae, le;
380
+ var ae, te;
381
381
  const D = k.includes(r.id), ee = m.includes(s.id), ne = h && o ? ee : D;
382
382
  return /* @__PURE__ */ n(
383
383
  ue,
@@ -388,7 +388,7 @@ function Ye() {
388
388
  /* @__PURE__ */ e(ge, { className: "p-2", children: /* @__PURE__ */ n("div", { className: "flex items-center justify-between", children: [
389
389
  /* @__PURE__ */ n("div", { className: "flex items-center gap-3", children: [
390
390
  (h || !o) && /* @__PURE__ */ n(L, { delayDuration: 0, children: [
391
- /* @__PURE__ */ e(F, { asChild: !0, children: /* @__PURE__ */ e(
391
+ /* @__PURE__ */ e(J, { asChild: !0, children: /* @__PURE__ */ e(
392
392
  "input",
393
393
  {
394
394
  type: "checkbox",
@@ -398,7 +398,7 @@ function Ye() {
398
398
  className: "h-5 w-5 cursor-pointer rounded focus:outline-none focus:ring-2 focus:ring-primary focus:ring-offset-1"
399
399
  }
400
400
  ) }),
401
- h && o && /* @__PURE__ */ e(J, { children: "Using the default language state" })
401
+ h && o && /* @__PURE__ */ e(F, { children: "Using the default language state" })
402
402
  ] }),
403
403
  /* @__PURE__ */ n("div", { children: [
404
404
  /* @__PURE__ */ n(fe, { className: "flex items-center gap-2 text-sm leading-none", children: [
@@ -410,13 +410,13 @@ function Ye() {
410
410
  ] }),
411
411
  ne && /* @__PURE__ */ e("span", { className: "sr-only text-xs font-normal text-muted-foreground", children: "Enabled" })
412
412
  ] }),
413
- ((ae = r == null ? void 0 : r.metadata) == null ? void 0 : ae.description) && /* @__PURE__ */ e("p", { className: "mt-1 text-xs leading-none text-muted-foreground", children: (le = r == null ? void 0 : r.metadata) == null ? void 0 : le.description })
413
+ ((ae = r == null ? void 0 : r.metadata) == null ? void 0 : ae.description) && /* @__PURE__ */ e("p", { className: "mt-1 text-xs leading-none text-muted-foreground", children: (te = r == null ? void 0 : r.metadata) == null ? void 0 : te.description })
414
414
  ] })
415
415
  ] }),
416
416
  /* @__PURE__ */ n("div", { className: "flex items-center gap-2", children: [
417
417
  /* @__PURE__ */ e("div", { className: "mx-2 h-6 w-px bg-border" }),
418
418
  /* @__PURE__ */ n(L, { delayDuration: 0, children: [
419
- /* @__PURE__ */ e(F, { asChild: !0, children: /* @__PURE__ */ e(
419
+ /* @__PURE__ */ e(J, { asChild: !0, children: /* @__PURE__ */ e(
420
420
  v,
421
421
  {
422
422
  type: "button",
@@ -427,11 +427,11 @@ function Ye() {
427
427
  children: /* @__PURE__ */ e(Ge, { className: "h-4 w-4" })
428
428
  }
429
429
  ) }),
430
- /* @__PURE__ */ e(J, { children: "View schema" })
430
+ /* @__PURE__ */ e(F, { children: "View schema" })
431
431
  ] }),
432
432
  (h || !o) && /* @__PURE__ */ n(G, { children: [
433
433
  /* @__PURE__ */ n(L, { delayDuration: 0, children: [
434
- /* @__PURE__ */ e(F, { asChild: !0, children: /* @__PURE__ */ e(
434
+ /* @__PURE__ */ e(J, { asChild: !0, children: /* @__PURE__ */ e(
435
435
  v,
436
436
  {
437
437
  type: "button",
@@ -442,24 +442,24 @@ function Ye() {
442
442
  children: /* @__PURE__ */ e(je, { className: "h-4 w-4" })
443
443
  }
444
444
  ) }),
445
- /* @__PURE__ */ e(J, { children: "Edit schema" })
445
+ /* @__PURE__ */ e(F, { children: "Edit schema" })
446
446
  ] }),
447
447
  /* @__PURE__ */ n(U, { children: [
448
448
  /* @__PURE__ */ n(L, { delayDuration: 0, children: [
449
- /* @__PURE__ */ e(F, { asChild: !0, children: /* @__PURE__ */ e(pe, { className: "flex h-5 w-5 items-center justify-center rounded-md text-red-500 hover:bg-red-100 hover:text-red-800", children: /* @__PURE__ */ e(Be, { className: "h-4 w-4" }) }) }),
450
- /* @__PURE__ */ e(J, { children: "Delete schema" })
449
+ /* @__PURE__ */ e(J, { asChild: !0, children: /* @__PURE__ */ e(pe, { className: "flex h-5 w-5 items-center justify-center rounded-md text-red-500 hover:bg-red-100 hover:text-red-800", children: /* @__PURE__ */ e(Be, { className: "h-4 w-4" }) }) }),
450
+ /* @__PURE__ */ e(F, { children: "Delete schema" })
451
451
  ] }),
452
452
  /* @__PURE__ */ n(_, { children: [
453
453
  /* @__PURE__ */ n(R, { children: [
454
- /* @__PURE__ */ e(M, { children: "Delete Schema" }),
455
- /* @__PURE__ */ n(q, { children: [
454
+ /* @__PURE__ */ e(q, { children: "Delete Schema" }),
455
+ /* @__PURE__ */ n(H, { children: [
456
456
  "Are you sure you want to delete",
457
457
  " ",
458
458
  /* @__PURE__ */ e("span", { className: "font-medium", children: r.name }),
459
459
  "? This action cannot be undone."
460
460
  ] })
461
461
  ] }),
462
- /* @__PURE__ */ n(H, { children: [
462
+ /* @__PURE__ */ n(M, { children: [
463
463
  /* @__PURE__ */ e(K, { type: "button", children: "Cancel" }),
464
464
  /* @__PURE__ */ e(
465
465
  Q,
@@ -516,7 +516,7 @@ function Ye() {
516
516
  /* @__PURE__ */ e(
517
517
  Ie,
518
518
  {
519
- show: l,
519
+ show: t,
520
520
  onClose: () => {
521
521
  i(!1), d(void 0);
522
522
  },
@@ -533,26 +533,26 @@ function Ye() {
533
533
  )
534
534
  ] });
535
535
  }
536
- const Re = ({ schema: l, onClose: i }) => /* @__PURE__ */ e(W, { open: !!l, onOpenChange: i, children: /* @__PURE__ */ n($, { className: "max-w-2xl", children: [
537
- /* @__PURE__ */ e(X, { children: /* @__PURE__ */ n(Y, { className: "flex items-center gap-2", children: [
538
- l == null ? void 0 : l.name,
539
- (l == null ? void 0 : l.lang) && /* @__PURE__ */ n("span", { className: "text-sm font-normal text-muted-foreground", children: [
536
+ const Re = ({ schema: t, onClose: i }) => /* @__PURE__ */ e($, { open: !!t, onOpenChange: i, children: /* @__PURE__ */ n(W, { className: "max-w-2xl", children: [
537
+ /* @__PURE__ */ e(Y, { children: /* @__PURE__ */ n(X, { className: "flex items-center gap-2", children: [
538
+ t == null ? void 0 : t.name,
539
+ (t == null ? void 0 : t.lang) && /* @__PURE__ */ n("span", { className: "text-sm font-normal text-muted-foreground", children: [
540
540
  "(",
541
- l.lang,
541
+ t.lang,
542
542
  ")"
543
543
  ] })
544
544
  ] }) }),
545
545
  /* @__PURE__ */ n("div", { className: "space-y-3", children: [
546
- (l == null ? void 0 : l.description) && /* @__PURE__ */ n("div", { children: [
546
+ (t == null ? void 0 : t.description) && /* @__PURE__ */ n("div", { children: [
547
547
  /* @__PURE__ */ e("div", { className: "text-xs font-medium text-muted-foreground", children: "Description" }),
548
- /* @__PURE__ */ e("div", { className: "text-sm", children: l.description })
548
+ /* @__PURE__ */ e("div", { className: "text-sm", children: t.description })
549
549
  ] }),
550
550
  /* @__PURE__ */ n("div", { children: [
551
551
  /* @__PURE__ */ e("div", { className: "mb-2 text-xs font-medium text-muted-foreground", children: "JSON-LD Schema" }),
552
552
  /* @__PURE__ */ e(
553
553
  Ne,
554
554
  {
555
- value: JSON.stringify(l == null ? void 0 : l.jsonld, null, 2),
555
+ value: JSON.stringify(t == null ? void 0 : t.jsonld, null, 2),
556
556
  readOnly: !0,
557
557
  className: "font-mono text-xs",
558
558
  rows: 15
@@ -562,5 +562,5 @@ const Re = ({ schema: l, onClose: i }) => /* @__PURE__ */ e(W, { open: !!l, onOp
562
562
  ] })
563
563
  ] }) });
564
564
  export {
565
- Ye as default
565
+ Xe as default
566
566
  };
@@ -1,6 +1,6 @@
1
1
  import { jsxs as i, jsx as o } from "react/jsx-runtime";
2
2
  import { z as v } from "./register-chai-top-bar-D6GjnauV.js";
3
- import { L as d } from "./index-BFnMzGe6.js";
3
+ import { L as d } from "./index-DsQXiNA_.js";
4
4
  import { useState as x, useEffect as C } from "react";
5
5
  const y = (e) => {
6
6
  if (!e) return { base: e, extension: null };
@@ -1 +1 @@
1
- "use strict";const s=require("react/jsx-runtime"),b=require("./register-chai-top-bar-DyW9GPzV.cjs"),u=require("./index-D30xvFa5.cjs"),d=require("react"),j=e=>{if(!e)return{base:e,extension:null};const n=e.lastIndexOf(".");if(n<=0)return{base:e,extension:null};const t=e.substring(n);return{base:e.substring(0,n),extension:t}},x=e=>{if(!e)return e;const{base:n}=j(e);return n};function E(e,n){const t=(e||"").split("/").filter(Boolean);let r="",a=!0;if(n.slug==="/"){const i=t.pop()||"";if(u.LANGUAGES[i])a=!0;else{r=i;const o=t.pop()||"";a=!!u.LANGUAGES[o]}}else if(n.parent)t.length&&(r=t.pop()||"");else if(t.length){r=t.pop()||"";const i=t.pop()||"";a=!!u.LANGUAGES[i]}return{initSlug:r,prefix:a}}const v=e=>e&&x(e),C=(e,n)=>{const t=x(e||"");return!t||t==="/"?`/${n}`:`${t}/${n}`};function A({value:e,onChange:n,placeholder:t,parentSlug:r,onValidationChange:a,disabled:i=!1,fullSlug:o}){const[g,p]=d.useState(e),[l,f]=d.useState(null);d.useEffect(()=>{p(e)},[e]);const h=S=>{const c=S.target.value.replace(/\//g,"").replace(/\s+/g,"-").replace(/[^a-zA-Z0-9-_.]/g,"-").replace(/-+/g,"-").replace(/^-+/,"").toLowerCase(),m=(c.match(/\./g)||[]).length,N=m<=1;m>1?f("Invalid slug. Only one dot (.) is allowed in the slug"):f(null),a&&a(N),p(c),n(c)};return s.jsxs("div",{children:[r&&s.jsx("div",{className:"mb-1 flex items-center",children:s.jsxs("span",{className:"text-xs text-gray-500",children:["Parent: ",s.jsx("span",{className:"font-mono text-gray-900",children:v(r)})]})}),s.jsxs("div",{className:"relative",children:[s.jsx(b.Input,{disabled:i,value:g,onChange:h,placeholder:t,className:l?"border-red-500":""}),l&&s.jsx("div",{className:"mt-1 text-xs text-red-500",children:l})]}),o&&o!=="undefined"&&s.jsx("div",{className:"mt-1 flex items-center",children:s.jsxs("span",{className:"text-xs text-gray-500",children:["Complete Slug: ",s.jsx("span",{className:"font-mono text-gray-900",children:o})]})})]})}exports.SlugInput=A;exports.combineParentChildSlugs=C;exports.parseSlugForEdit=E;exports.removeSlugExtension=x;
1
+ "use strict";const s=require("react/jsx-runtime"),b=require("./register-chai-top-bar-DyW9GPzV.cjs"),u=require("./index-mPCp0j2h.cjs"),d=require("react"),j=e=>{if(!e)return{base:e,extension:null};const n=e.lastIndexOf(".");if(n<=0)return{base:e,extension:null};const t=e.substring(n);return{base:e.substring(0,n),extension:t}},x=e=>{if(!e)return e;const{base:n}=j(e);return n};function E(e,n){const t=(e||"").split("/").filter(Boolean);let r="",a=!0;if(n.slug==="/"){const i=t.pop()||"";if(u.LANGUAGES[i])a=!0;else{r=i;const o=t.pop()||"";a=!!u.LANGUAGES[o]}}else if(n.parent)t.length&&(r=t.pop()||"");else if(t.length){r=t.pop()||"";const i=t.pop()||"";a=!!u.LANGUAGES[i]}return{initSlug:r,prefix:a}}const v=e=>e&&x(e),C=(e,n)=>{const t=x(e||"");return!t||t==="/"?`/${n}`:`${t}/${n}`};function A({value:e,onChange:n,placeholder:t,parentSlug:r,onValidationChange:a,disabled:i=!1,fullSlug:o}){const[g,p]=d.useState(e),[l,f]=d.useState(null);d.useEffect(()=>{p(e)},[e]);const h=S=>{const c=S.target.value.replace(/\//g,"").replace(/\s+/g,"-").replace(/[^a-zA-Z0-9-_.]/g,"-").replace(/-+/g,"-").replace(/^-+/,"").toLowerCase(),m=(c.match(/\./g)||[]).length,N=m<=1;m>1?f("Invalid slug. Only one dot (.) is allowed in the slug"):f(null),a&&a(N),p(c),n(c)};return s.jsxs("div",{children:[r&&s.jsx("div",{className:"mb-1 flex items-center",children:s.jsxs("span",{className:"text-xs text-gray-500",children:["Parent: ",s.jsx("span",{className:"font-mono text-gray-900",children:v(r)})]})}),s.jsxs("div",{className:"relative",children:[s.jsx(b.Input,{disabled:i,value:g,onChange:h,placeholder:t,className:l?"border-red-500":""}),l&&s.jsx("div",{className:"mt-1 text-xs text-red-500",children:l})]}),o&&o!=="undefined"&&s.jsx("div",{className:"mt-1 flex items-center",children:s.jsxs("span",{className:"text-xs text-gray-500",children:["Complete Slug: ",s.jsx("span",{className:"font-mono text-gray-900",children:o})]})})]})}exports.SlugInput=A;exports.combineParentChildSlugs=C;exports.parseSlugForEdit=E;exports.removeSlugExtension=x;
@@ -1 +1 @@
1
- "use strict";var D=Object.defineProperty;var O=(u,t,e)=>t in u?D(u,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):u[t]=e;var y=(u,t,e)=>O(u,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=require("./actions-registery-Cy1lqUVI.cjs"),w=require("lodash-es"),b=require("sharp"),i=require("zod");class A{constructor(t,e,r){this.appId=t,this.userId=e,this.supabase=r}appendUpdatedAtToUrl(t,e){if(w.isEmpty(t))return"";const r=new URL(t),o=new Date(e).getTime();return r.searchParams.set("t",o.toString()),`${r.origin}${r.pathname}${r.search}${r.hash}`}getBufferFromBase64(t){try{const e=t.split(",")[1]||t;return Buffer.from(e,"base64")}catch{throw new Error("Invalid base64 string format")}}async uploadImageFile(t,e,r,o){try{const s=this.getBufferFromBase64(t),n=await b(s).metadata(),c=["jpeg","jpg","png","webp","gif","svg","tiff"];if(!n.format||!c.includes(n.format.toLowerCase()))throw new Error(`Invalid image format: ${n.format||"unknown"}`);const d=o?await b(s).webp({quality:100}).resize({width:Math.min(n.width||2e3,2e3)}).toBuffer():await b(s).webp({quality:100}).toBuffer();let a=d;if(o&&d.length>120*1024){const _=Math.floor(90*(122880/d.length));a=await b(s).webp({quality:_}).resize({width:Math.min(n.width||2e3,2e3)}).toBuffer()}const l=await b(a).metadata(),g=await b(s).webp({quality:70}).resize({width:300}).toBuffer(),p=r.split("."),m=p.length>1?p.slice(0,-1).join("."):r,f=`${w.kebabCase(m)}.webp`,k=`${f}_thumbnail.webp`,T=this.appId,I=e?`${T}/${e}`:T,S=h.getChaiAction("UPLOAD_TO_STORAGE");if(!S)throw new Error("UPLOAD_TO_STORAGE action not found");S.setContext({appId:this.appId,userId:this.userId});const U=await S.execute({file:a.toString("base64"),fileName:f,contentType:"image/webp",folder:I});if(U.error)throw new Error(U.error);const E=await S.execute({file:g.toString("base64"),fileName:k,contentType:"image/webp",folder:I});if(E.error)throw new Error(E.error);return{url:U.data.url,thumbnailUrl:E.data.url,size:l.size||a.length,width:l.width||0,height:l.height||0,mimeType:"image/webp"}}catch(s){return console.error("Upload image error:",s),{error:s instanceof Error?s.message:"Unknown error"}}}async uploadSvgFile(t,e,r){try{const o=this.getBufferFromBase64(t);let s,n;try{const f=await b(o).metadata();s=f.width,n=f.height}catch{}const c=r.split("."),d=c.length>1?c.slice(0,-1).join("."):r,a=`${w.kebabCase(d)}.svg`,l=this.appId,g=e?`${l}/${e}`:l,p=h.getChaiAction("UPLOAD_TO_STORAGE");if(!p)throw new Error("UPLOAD_TO_STORAGE action not found");p.setContext({appId:this.appId,userId:this.userId});const m=await p.execute({file:o.toString("base64"),fileName:a,contentType:"image/svg+xml",folder:g});if(m.error)throw new Error(m.error);return{url:m.data.url,thumbnailUrl:m.data.url,size:o.length,width:s,height:n,mimeType:"image/svg+xml"}}catch(o){return console.error("SVG upload error:",o),{error:o instanceof Error?o.message:"Unknown error"}}}async upload({file:t,folderId:e,name:r,optimize:o=!0}){var s;try{const c=r.toLowerCase().endsWith(".svg")||t.includes("data:image/svg+xml")?await this.uploadSvgFile(t,e,r):await this.uploadImageFile(t,e,r,o??!0);if("error"in c)return c;const d={name:r,app:this.appId,url:c.url,thumbnailUrl:c.thumbnailUrl,size:(s=c.size)==null?void 0:s.toString(),width:c.width,height:c.height,format:c.mimeType.split("/")[1],folderId:e,type:c.mimeType.startsWith("image/")?"image":"file",createdBy:this.userId,updatedAt:new Date().toISOString()},{data:a,error:l}=await this.supabase.from("app_assets").insert(d).select("*").single();if(l)throw new Error(`Failed to store asset in database: ${l.message}`);return{id:a.id,name:a.name,type:a.type,url:this.appendUpdatedAtToUrl(a.url,a.updatedAt),size:a.size,thumbnailUrl:this.appendUpdatedAtToUrl(a.thumbnailUrl||"",a.updatedAt),width:a.width,height:a.height,format:a.format,folderId:a.folderId,createdBy:a.createdBy||"",createdAt:a.createdAt,updatedAt:a.updatedAt}}catch(n){return{error:n instanceof Error?n.message:"Unknown error occurred"}}}async getAsset({id:t}){try{const{data:e,error:r}=await this.supabase.from("app_assets").select("*").eq("id",t).eq("app",this.appId).single();if(r)throw new Error(`Failed to fetch asset: ${r.message}`);return w.set(e,"url",this.appendUpdatedAtToUrl(e.url,e.updatedAt)),w.set(e,"thumbnailUrl",this.appendUpdatedAtToUrl(e.thumbnailUrl||"",e.updatedAt)),e}catch(e){return{error:e instanceof Error?e.message:"Unknown error occurred"}}}async getAssets({search:t="",page:e=1,limit:r=20}={}){try{const o=(e-1)*r;let s=this.supabase.from("app_assets").select("*",{count:"exact"}).eq("app",this.appId).order("updatedAt",{ascending:!1});t&&(s=s.or(`name.ilike.%${t}%,description.ilike.%${t}%`));const{data:n,error:c,count:d}=await s.range(o,o+r-1);if(c)throw new Error(c.message);return{assets:n.map(l=>(w.set(l,"url",this.appendUpdatedAtToUrl(l.url,l.updatedAt)),w.set(l,"thsupabaseumbnailUrl",this.appendUpdatedAtToUrl(l.thumbnailUrl||"",l.updatedAt)),l)),total:d||0,page:e,pageSize:r}}catch(o){throw console.error("Error fetching assets:",o),o}}async deleteAsset({id:t}){try{const{data:e,error:r}=await this.supabase.from("app_assets").select("*").eq("id",t).eq("app",this.appId).single();if(r)throw new Error(`Failed to fetch asset: ${r.message}`);if(e.url)try{const n=new URL(e.url).pathname.split("/"),c=n.indexOf("dam-assets");if(c!==-1){const d=n.slice(c+1).join("/"),a=h.getChaiAction("DELETE_FROM_STORAGE");if(a&&(a.setContext({appId:this.appId,userId:this.userId}),await a.execute({key:d})),e.thumbnailUrl&&e.thumbnailUrl!==e.url){const g=new URL(e.thumbnailUrl).pathname.split("/"),p=g.indexOf("dam-assets");if(p!==-1){const m=g.slice(p+1).join("/");a&&await a.execute({key:m})}}}}catch(s){console.warn("Failed to delete from storage, continuing with database deletion:",s)}const{error:o}=await this.supabase.from("app_assets").delete().eq("id",t);if(o)throw new Error(`Failed to delete asset: ${o.message}`);return{success:!0}}catch(e){return{error:e instanceof Error?e.message:"Unknown error occurred"}}}async updateAsset({id:t,file:e,description:r}){var o,s;try{const{data:n,error:c}=await this.supabase.from("app_assets").select("*").eq("id",t).single();if(c)throw new Error(`Failed to fetch asset: ${c.message}`);const d={};if(r!==void 0&&(d.description=r,d.updatedAt=new Date().toISOString()),e){const p=((o=n.format)==null?void 0:o.toLowerCase())==="svg"||e.includes("data:image/svg+xml")?await this.uploadSvgFile(e,n.folderId,n.name):await this.uploadImageFile(e,n.folderId,n.name,!0);if("error"in p)return p;d.url=p.url,d.thumbnailUrl=p.thumbnailUrl,d.size=(s=p.size)==null?void 0:s.toString(),d.width=p.width,d.height=p.height,d.format=p.mimeType.split("/")[1],d.updatedAt=new Date().toISOString()}const{data:a,error:l}=await this.supabase.from("app_assets").update(d).eq("id",t).select().single();if(l)throw new Error(`Failed to update asset: ${l.message}`);return w.set(a,"url",this.appendUpdatedAtToUrl(a.url,a.updatedAt)),w.set(a,"thumbnailUrl",this.appendUpdatedAtToUrl(a.thumbnailUrl||"",a.updatedAt)),a}catch(n){return{error:n instanceof Error?n.message:"Unknown error occurred"}}}}const C=i.z.object({name:i.z.string(),file:i.z.string(),folderId:i.z.string().optional().nullable(),optimize:i.z.boolean().optional()});class P extends h.ChaiBaseAction{constructor(t){super(),this.supabase=t}getValidationSchema(){return C}async execute(t){try{if(!this.context)return{error:"Context not set",status:400};const{appId:e,userId:r}=this.context;if(!r)return{error:"User ID is required",status:401};const s=await new A(e,r,this.supabase).upload(t);return"error"in s?{error:s.error,status:400}:s}catch(e){return console.error("UPLOAD_ASSET error:",e),{error:e instanceof Error?e.message:"Unknown error",status:500}}}}const F=i.z.object({id:i.z.string()});class B extends h.ChaiBaseAction{constructor(t){super(),this.supabase=t}getValidationSchema(){return F}async execute(t){try{if(!this.context)return{error:"Context not set",status:400};const{appId:e,userId:r}=this.context;if(!r)return{error:"User ID is required",status:401};const s=await new A(e,r,this.supabase).getAsset(t);return"error"in s?{error:s.error,status:400}:s}catch(e){return console.error("GET_ASSET error:",e),{error:e instanceof Error?e.message:"Unknown error",status:500}}}}const v=i.z.object({search:i.z.string().optional(),page:i.z.number().optional(),limit:i.z.number().optional()});class $ extends h.ChaiBaseAction{constructor(t){super(),this.supabase=t}getValidationSchema(){return v}async execute(t){try{if(!this.context)return{error:"Context not set",status:400};const{appId:e,userId:r}=this.context;if(!r)return{error:"User ID is required",status:401};const s=await new A(e,r,this.supabase).getAssets(t);return"error"in s?{error:s.error,status:400}:s}catch(e){return console.error("GET_ASSETS error:",e),{error:e instanceof Error?e.message:"Unknown error",status:500}}}}const q=i.z.object({id:i.z.string()});class G extends h.ChaiBaseAction{constructor(t){super(),this.supabase=t}getValidationSchema(){return q}async execute(t){try{if(!this.context)return{error:"Context not set",status:400};const{appId:e,userId:r}=this.context;if(!r)return{error:"User ID is required",status:401};const s=await new A(e,r,this.supabase).deleteAsset(t);return"error"in s?{error:s.error,status:400}:s}catch(e){return console.error("DELETE_ASSET error:",e),{error:e instanceof Error?e.message:"Unknown error",status:500}}}}const L=i.z.object({id:i.z.string(),file:i.z.string().optional(),description:i.z.string().optional()});class j extends h.ChaiBaseAction{constructor(t){super(),this.supabase=t}getValidationSchema(){return L}async execute(t){try{if(!this.context)return{error:"Context not set",status:400};const{appId:e,userId:r}=this.context;if(!r)return{error:"User ID is required",status:401};const s=await new A(e,r,this.supabase).updateAsset(t);return"error"in s?{error:s.error,status:400}:s}catch(e){return console.error("UPDATE_ASSET error:",e),{error:e instanceof Error?e.message:"Unknown error",status:500}}}}const R=i.z.object({userId:i.z.string()});class N extends h.ChaiBaseAction{constructor(t){super(),this.supabase=t}getValidationSchema(){return R}async execute(t){var e,r,o,s,n,c;try{const{userId:d}=t,{data:a,error:l}=await this.supabase.auth.admin.getUserById(d);return l?{data:{id:"unknown",email:"unknown@chaibuilder.com",name:"Unknown",avatar:""},status:200}:{data:{id:((e=a.user)==null?void 0:e.id)||"unknown",email:((r=a.user)==null?void 0:r.email)||"unknown@chaibuilder.com",name:((s=(o=a.user)==null?void 0:o.user_metadata)==null?void 0:s.name)||"Unknown",avatar:((c=(n=a.user)==null?void 0:n.user_metadata)==null?void 0:c.avatar_url)||""},status:200}}catch{return{data:{id:"unknown",email:"unknown@chaibuilder.com",name:"Unknown",avatar:""},status:200}}}}const M=i.z.object({email:i.z.string().email(),oldPassword:i.z.string().min(1,"Old password is required"),newPassword:i.z.string().min(8,"New password must be at least 8 characters"),confirmPassword:i.z.string().min(1,"Confirm password is required")}).refine(u=>u.newPassword===u.confirmPassword,{message:"Confirm password does not match",path:["confirmPassword"]});class V extends h.ChaiBaseAction{constructor(t){super(),this.supabase=t}getValidationSchema(){return M}async execute(t){try{const{email:e,oldPassword:r,newPassword:o}=t,{error:s}=await this.supabase.auth.signInWithPassword({email:e,password:r});if(s)throw new h.ActionError("Current password is incorrect","INVALID_PASSWORD",400);const{error:n}=await this.supabase.auth.updateUser({password:o});if(n)throw new h.ActionError(n.message||"Failed to update password","UPDATE_FAILED",400);return{data:{message:"Password changed successfully"},status:200}}catch(e){throw e}}}const W=i.z.object({key:i.z.string()});class x extends h.ChaiBaseAction{constructor(e){super();y(this,"bucketName","dam-assets");this.supabase=e}getValidationSchema(){return W}async execute(e){try{const{key:r}=e,{error:o}=await this.supabase.storage.from(this.bucketName).remove([r]);return o?{error:`Failed to delete from Supabase Storage: ${o.message}`,status:500}:{data:{success:!0},status:200}}catch(r){return console.error("DELETE_FROM_STORAGE error:",r),{error:r instanceof Error?r.message:"Unknown error",status:500}}}}const H=i.z.object({file:i.z.string(),fileName:i.z.string(),contentType:i.z.string().optional(),folder:i.z.string().optional(),metadata:i.z.record(i.z.string(),i.z.any()).optional()});class z extends h.ChaiBaseAction{constructor(e){super();y(this,"bucketName","dam-assets");this.supabase=e}getValidationSchema(){return H}async execute(e){try{if(!this.context)return{error:"Context not set",status:400};const{appId:r}=this.context,{file:o,fileName:s,contentType:n,folder:c,metadata:d}=e;let a;if(typeof o=="string"){const f=o.split(",")[1]||o;a=Buffer.from(f,"base64")}else a=o;const l=c?`${c}/${s}`:`${r}/${s}`,{data:g,error:p}=await this.supabase.storage.from(this.bucketName).upload(l,a,{contentType:n||"application/octet-stream",upsert:!0,...d&&{metadata:d}});if(p)return{error:`Failed to upload to Supabase Storage: ${p.message}`,status:500};const{data:{publicUrl:m}}=this.supabase.storage.from(this.bucketName).getPublicUrl(l);return{data:{url:m,key:g.path,size:a.length,metadata:d},status:200}}catch(r){return console.error("UPLOAD_TO_STORAGE error:",r),{error:r instanceof Error?r.message:"Unknown error",status:500}}}}const K=u=>({GET_CHAI_USER:new N(u),CHANGE_PASSWORD:new V(u)}),Q=u=>({UPLOAD_ASSET:new P(u),GET_ASSET:new B(u),GET_ASSETS:new $(u),DELETE_ASSET:new G(u),UPDATE_ASSET:new j(u),UPLOAD_TO_STORAGE:new z(u),DELETE_FROM_STORAGE:new x(u)});exports.DeleteFromStorageAction=x;exports.SupabaseAuthActions=K;exports.SupabaseStorageActions=Q;exports.UploadToStorageAction=z;
1
+ "use strict";var T=Object.defineProperty;var I=(d,t,e)=>t in d?T(d,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):d[t]=e;var S=(d,t,e)=>I(d,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=require("./actions-registery-Cy1lqUVI.cjs"),f=require("lodash-es"),n=require("zod");class b{constructor(t,e,r){this.appId=t,this.userId=e,this.supabase=r}appendUpdatedAtToUrl(t,e){if(f.isEmpty(t))return"";const r=new URL(t),a=new Date(e).getTime();return r.searchParams.set("t",a.toString()),`${r.origin}${r.pathname}${r.search}${r.hash}`}getBufferFromBase64(t){try{const e=t.split(",")[1]||t;return Buffer.from(e,"base64")}catch{throw new Error("Invalid base64 string format")}}getMimeType(t){var a;const e=((a=t.split(".").pop())==null?void 0:a.toLowerCase())||"";return{jpg:"image/jpeg",jpeg:"image/jpeg",png:"image/png",webp:"image/webp",gif:"image/gif",tiff:"image/tiff",svg:"image/svg+xml"}[e]||"application/octet-stream"}async uploadImageFile(t,e,r,a){try{const s=this.getBufferFromBase64(t),i=this.getMimeType(r);if(!["image/jpeg","image/png","image/webp","image/gif","image/tiff"].includes(i))throw new Error(`Invalid image format: ${i}`);const u=r.split("."),o=u.length>1?u.slice(0,-1).join("."):r,l=u.length>1?u[u.length-1].toLowerCase():"png",g=`${f.kebabCase(o)}.${l}`,p=this.appId,m=e?`${p}/${e}`:p,w=h.getChaiAction("UPLOAD_TO_STORAGE");if(!w)throw new Error("UPLOAD_TO_STORAGE action not found");w.setContext({appId:this.appId,userId:this.userId});const A=await w.execute({file:s.toString("base64"),fileName:g,contentType:i,folder:m});if(A.error)throw new Error(A.error);return{url:A.data.url,thumbnailUrl:A.data.url,size:s.length,width:0,height:0,mimeType:i}}catch(s){return console.error("Upload image error:",s),{error:s instanceof Error?s.message:"Unknown error"}}}async uploadSvgFile(t,e,r){try{const a=this.getBufferFromBase64(t);let s,i;try{const w=a.toString("utf-8"),A=w.match(/\bwidth=["'](\d+)/),U=w.match(/\bheight=["'](\d+)/);A&&(s=parseInt(A[1],10)),U&&(i=parseInt(U[1],10))}catch{}const c=r.split("."),u=c.length>1?c.slice(0,-1).join("."):r,o=`${f.kebabCase(u)}.svg`,l=this.appId,g=e?`${l}/${e}`:l,p=h.getChaiAction("UPLOAD_TO_STORAGE");if(!p)throw new Error("UPLOAD_TO_STORAGE action not found");p.setContext({appId:this.appId,userId:this.userId});const m=await p.execute({file:a.toString("base64"),fileName:o,contentType:"image/svg+xml",folder:g});if(m.error)throw new Error(m.error);return{url:m.data.url,thumbnailUrl:m.data.url,size:a.length,width:s,height:i,mimeType:"image/svg+xml"}}catch(a){return console.error("SVG upload error:",a),{error:a instanceof Error?a.message:"Unknown error"}}}async upload({file:t,folderId:e,name:r,optimize:a=!0}){var s;try{const c=r.toLowerCase().endsWith(".svg")||t.includes("data:image/svg+xml")?await this.uploadSvgFile(t,e,r):await this.uploadImageFile(t,e,r,a??!0);if("error"in c)return c;const u={name:r,app:this.appId,url:c.url,thumbnailUrl:c.thumbnailUrl,size:(s=c.size)==null?void 0:s.toString(),width:c.width,height:c.height,format:c.mimeType.split("/")[1],folderId:e,type:c.mimeType.startsWith("image/")?"image":"file",createdBy:this.userId,updatedAt:new Date().toISOString()},{data:o,error:l}=await this.supabase.from("app_assets").insert(u).select("*").single();if(l)throw new Error(`Failed to store asset in database: ${l.message}`);return{id:o.id,name:o.name,type:o.type,url:this.appendUpdatedAtToUrl(o.url,o.updatedAt),size:o.size,thumbnailUrl:this.appendUpdatedAtToUrl(o.thumbnailUrl||"",o.updatedAt),width:o.width,height:o.height,format:o.format,folderId:o.folderId,createdBy:o.createdBy||"",createdAt:o.createdAt,updatedAt:o.updatedAt}}catch(i){return{error:i instanceof Error?i.message:"Unknown error occurred"}}}async getAsset({id:t}){try{const{data:e,error:r}=await this.supabase.from("app_assets").select("*").eq("id",t).eq("app",this.appId).single();if(r)throw new Error(`Failed to fetch asset: ${r.message}`);return f.set(e,"url",this.appendUpdatedAtToUrl(e.url,e.updatedAt)),f.set(e,"thumbnailUrl",this.appendUpdatedAtToUrl(e.thumbnailUrl||"",e.updatedAt)),e}catch(e){return{error:e instanceof Error?e.message:"Unknown error occurred"}}}async getAssets({search:t="",page:e=1,limit:r=20}={}){try{const a=(e-1)*r;let s=this.supabase.from("app_assets").select("*",{count:"exact"}).eq("app",this.appId).order("updatedAt",{ascending:!1});t&&(s=s.or(`name.ilike.%${t}%,description.ilike.%${t}%`));const{data:i,error:c,count:u}=await s.range(a,a+r-1);if(c)throw new Error(c.message);return{assets:i.map(l=>(f.set(l,"url",this.appendUpdatedAtToUrl(l.url,l.updatedAt)),f.set(l,"thsupabaseumbnailUrl",this.appendUpdatedAtToUrl(l.thumbnailUrl||"",l.updatedAt)),l)),total:u||0,page:e,pageSize:r}}catch(a){throw console.error("Error fetching assets:",a),a}}async deleteAsset({id:t}){try{const{data:e,error:r}=await this.supabase.from("app_assets").select("*").eq("id",t).eq("app",this.appId).single();if(r)throw new Error(`Failed to fetch asset: ${r.message}`);if(e.url)try{const i=new URL(e.url).pathname.split("/"),c=i.indexOf("dam-assets");if(c!==-1){const u=i.slice(c+1).join("/"),o=h.getChaiAction("DELETE_FROM_STORAGE");if(o&&(o.setContext({appId:this.appId,userId:this.userId}),await o.execute({key:u})),e.thumbnailUrl&&e.thumbnailUrl!==e.url){const g=new URL(e.thumbnailUrl).pathname.split("/"),p=g.indexOf("dam-assets");if(p!==-1){const m=g.slice(p+1).join("/");o&&await o.execute({key:m})}}}}catch(s){console.warn("Failed to delete from storage, continuing with database deletion:",s)}const{error:a}=await this.supabase.from("app_assets").delete().eq("id",t);if(a)throw new Error(`Failed to delete asset: ${a.message}`);return{success:!0}}catch(e){return{error:e instanceof Error?e.message:"Unknown error occurred"}}}async updateAsset({id:t,file:e,description:r}){var a,s;try{const{data:i,error:c}=await this.supabase.from("app_assets").select("*").eq("id",t).single();if(c)throw new Error(`Failed to fetch asset: ${c.message}`);const u={};if(r!==void 0&&(u.description=r,u.updatedAt=new Date().toISOString()),e){const p=((a=i.format)==null?void 0:a.toLowerCase())==="svg"||e.includes("data:image/svg+xml")?await this.uploadSvgFile(e,i.folderId,i.name):await this.uploadImageFile(e,i.folderId,i.name,!0);if("error"in p)return p;u.url=p.url,u.thumbnailUrl=p.thumbnailUrl,u.size=(s=p.size)==null?void 0:s.toString(),u.width=p.width,u.height=p.height,u.format=p.mimeType.split("/")[1],u.updatedAt=new Date().toISOString()}const{data:o,error:l}=await this.supabase.from("app_assets").update(u).eq("id",t).select().single();if(l)throw new Error(`Failed to update asset: ${l.message}`);return f.set(o,"url",this.appendUpdatedAtToUrl(o.url,o.updatedAt)),f.set(o,"thumbnailUrl",this.appendUpdatedAtToUrl(o.thumbnailUrl||"",o.updatedAt)),o}catch(i){return{error:i instanceof Error?i.message:"Unknown error occurred"}}}}const x=n.z.object({name:n.z.string(),file:n.z.string(),folderId:n.z.string().optional().nullable(),optimize:n.z.boolean().optional()});class k extends h.ChaiBaseAction{constructor(t){super(),this.supabase=t}getValidationSchema(){return x}async execute(t){try{if(!this.context)return{error:"Context not set",status:400};const{appId:e,userId:r}=this.context;if(!r)return{error:"User ID is required",status:401};const s=await new b(e,r,this.supabase).upload(t);return"error"in s?{error:s.error,status:400}:s}catch(e){return console.error("UPLOAD_ASSET error:",e),{error:e instanceof Error?e.message:"Unknown error",status:500}}}}const z=n.z.object({id:n.z.string()});class _ extends h.ChaiBaseAction{constructor(t){super(),this.supabase=t}getValidationSchema(){return z}async execute(t){try{if(!this.context)return{error:"Context not set",status:400};const{appId:e,userId:r}=this.context;if(!r)return{error:"User ID is required",status:401};const s=await new b(e,r,this.supabase).getAsset(t);return"error"in s?{error:s.error,status:400}:s}catch(e){return console.error("GET_ASSET error:",e),{error:e instanceof Error?e.message:"Unknown error",status:500}}}}const D=n.z.object({search:n.z.string().optional(),page:n.z.number().optional(),limit:n.z.number().optional()});class O extends h.ChaiBaseAction{constructor(t){super(),this.supabase=t}getValidationSchema(){return D}async execute(t){try{if(!this.context)return{error:"Context not set",status:400};const{appId:e,userId:r}=this.context;if(!r)return{error:"User ID is required",status:401};const s=await new b(e,r,this.supabase).getAssets(t);return"error"in s?{error:s.error,status:400}:s}catch(e){return console.error("GET_ASSETS error:",e),{error:e instanceof Error?e.message:"Unknown error",status:500}}}}const C=n.z.object({id:n.z.string()});class P extends h.ChaiBaseAction{constructor(t){super(),this.supabase=t}getValidationSchema(){return C}async execute(t){try{if(!this.context)return{error:"Context not set",status:400};const{appId:e,userId:r}=this.context;if(!r)return{error:"User ID is required",status:401};const s=await new b(e,r,this.supabase).deleteAsset(t);return"error"in s?{error:s.error,status:400}:s}catch(e){return console.error("DELETE_ASSET error:",e),{error:e instanceof Error?e.message:"Unknown error",status:500}}}}const F=n.z.object({id:n.z.string(),file:n.z.string().optional(),description:n.z.string().optional()});class v extends h.ChaiBaseAction{constructor(t){super(),this.supabase=t}getValidationSchema(){return F}async execute(t){try{if(!this.context)return{error:"Context not set",status:400};const{appId:e,userId:r}=this.context;if(!r)return{error:"User ID is required",status:401};const s=await new b(e,r,this.supabase).updateAsset(t);return"error"in s?{error:s.error,status:400}:s}catch(e){return console.error("UPDATE_ASSET error:",e),{error:e instanceof Error?e.message:"Unknown error",status:500}}}}const $=n.z.object({userId:n.z.string()});class j extends h.ChaiBaseAction{constructor(t){super(),this.supabase=t}getValidationSchema(){return $}async execute(t){var e,r,a,s,i,c;try{const{userId:u}=t,{data:o,error:l}=await this.supabase.auth.admin.getUserById(u);return l?{data:{id:"unknown",email:"unknown@chaibuilder.com",name:"Unknown",avatar:""},status:200}:{data:{id:((e=o.user)==null?void 0:e.id)||"unknown",email:((r=o.user)==null?void 0:r.email)||"unknown@chaibuilder.com",name:((s=(a=o.user)==null?void 0:a.user_metadata)==null?void 0:s.name)||"Unknown",avatar:((c=(i=o.user)==null?void 0:i.user_metadata)==null?void 0:c.avatar_url)||""},status:200}}catch{return{data:{id:"unknown",email:"unknown@chaibuilder.com",name:"Unknown",avatar:""},status:200}}}}const B=n.z.object({email:n.z.string().email(),oldPassword:n.z.string().min(1,"Old password is required"),newPassword:n.z.string().min(8,"New password must be at least 8 characters"),confirmPassword:n.z.string().min(1,"Confirm password is required")}).refine(d=>d.newPassword===d.confirmPassword,{message:"Confirm password does not match",path:["confirmPassword"]});class G extends h.ChaiBaseAction{constructor(t){super(),this.supabase=t}getValidationSchema(){return B}async execute(t){try{const{email:e,oldPassword:r,newPassword:a}=t,{error:s}=await this.supabase.auth.signInWithPassword({email:e,password:r});if(s)throw new h.ActionError("Current password is incorrect","INVALID_PASSWORD",400);const{error:i}=await this.supabase.auth.updateUser({password:a});if(i)throw new h.ActionError(i.message||"Failed to update password","UPDATE_FAILED",400);return{data:{message:"Password changed successfully"},status:200}}catch(e){throw e}}}const L=n.z.object({key:n.z.string()});class E extends h.ChaiBaseAction{constructor(e){super();S(this,"bucketName","dam-assets");this.supabase=e}getValidationSchema(){return L}async execute(e){try{const{key:r}=e,{error:a}=await this.supabase.storage.from(this.bucketName).remove([r]);return a?{error:`Failed to delete from Supabase Storage: ${a.message}`,status:500}:{data:{success:!0},status:200}}catch(r){return console.error("DELETE_FROM_STORAGE error:",r),{error:r instanceof Error?r.message:"Unknown error",status:500}}}}const R=n.z.object({file:n.z.string(),fileName:n.z.string(),contentType:n.z.string().optional(),folder:n.z.string().optional(),metadata:n.z.record(n.z.string(),n.z.any()).optional()});class y extends h.ChaiBaseAction{constructor(e){super();S(this,"bucketName","dam-assets");this.supabase=e}getValidationSchema(){return R}async execute(e){try{if(!this.context)return{error:"Context not set",status:400};const{appId:r}=this.context,{file:a,fileName:s,contentType:i,folder:c,metadata:u}=e;let o;if(typeof a=="string"){const w=a.split(",")[1]||a;o=Buffer.from(w,"base64")}else o=a;const l=c?`${c}/${s}`:`${r}/${s}`,{data:g,error:p}=await this.supabase.storage.from(this.bucketName).upload(l,o,{contentType:i||"application/octet-stream",upsert:!0,...u&&{metadata:u}});if(p)return{error:`Failed to upload to Supabase Storage: ${p.message}`,status:500};const{data:{publicUrl:m}}=this.supabase.storage.from(this.bucketName).getPublicUrl(l);return{data:{url:m,key:g.path,size:o.length,metadata:u},status:200}}catch(r){return console.error("UPLOAD_TO_STORAGE error:",r),{error:r instanceof Error?r.message:"Unknown error",status:500}}}}const q=d=>({GET_CHAI_USER:new j(d),CHANGE_PASSWORD:new G(d)}),M=d=>({UPLOAD_ASSET:new k(d),GET_ASSET:new _(d),GET_ASSETS:new O(d),DELETE_ASSET:new P(d),UPDATE_ASSET:new v(d),UPLOAD_TO_STORAGE:new y(d),DELETE_FROM_STORAGE:new E(d)});exports.DeleteFromStorageAction=E;exports.SupabaseAuthActions=q;exports.SupabaseStorageActions=M;exports.UploadToStorageAction=y;