@chaibuilder/pages 0.16.4 → 0.16.5

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 (76) hide show
  1. package/dist/{2AITGKQY-DI5Po2Nc.js → 2AITGKQY-BXiVm60u.js} +2 -2
  2. package/dist/{2AITGKQY-8xBkB8Pv.cjs → 2AITGKQY-BkyIOFBN.cjs} +1 -1
  3. package/dist/{NCMVHL6D-kHUQxG8D.js → NCMVHL6D-C0JGE8Qr.js} +2 -2
  4. package/dist/{NCMVHL6D-B4xqJIpr.cjs → NCMVHL6D-CnBMv9bF.cjs} +1 -1
  5. package/dist/{ZDWCUMSJ-DRgY2Er1.js → ZDWCUMSJ-Cs-CWvpw.js} +1 -1
  6. package/dist/{ZDWCUMSJ-CjlhoCfQ.cjs → ZDWCUMSJ-jR6OAwVS.cjs} +1 -1
  7. package/dist/{add-new-language-page-DSB8ohdj.js → add-new-language-page-CKwMwrAg.js} +2 -2
  8. package/dist/{add-new-language-page-noBKABVx.cjs → add-new-language-page-UatKeIR2.cjs} +1 -1
  9. package/dist/{add-new-page-CByS9KqS.cjs → add-new-page-BZ2av8fu.cjs} +1 -1
  10. package/dist/{add-new-page-BYkFbQvH.js → add-new-page-BzBMJ3Cn.js} +1 -1
  11. package/dist/{ai-panel-content-DET3HjIR.js → ai-panel-content-B7VWN9Hp.js} +2 -2
  12. package/dist/{ai-panel-content-BBnzp4fO.cjs → ai-panel-content-DvNWlTtZ.cjs} +1 -1
  13. package/dist/{ai-panel-default-lang-BYfcAA8u.js → ai-panel-default-lang-DRkJegQm.js} +2 -2
  14. package/dist/{ai-panel-default-lang-D-RS6z5I.cjs → ai-panel-default-lang-Dnfg53l_.cjs} +1 -1
  15. package/dist/{ai-panel-other-lang-BoD4FsoG.cjs → ai-panel-other-lang-0_g52R_I.cjs} +1 -1
  16. package/dist/{ai-panel-other-lang-TVjNYPRK.js → ai-panel-other-lang-CQVkWTd3.js} +3 -3
  17. package/dist/{ai-panel-quick-prompts-BPrA9nvg.js → ai-panel-quick-prompts-BfMsNuRu.js} +1 -1
  18. package/dist/{ai-panel-quick-prompts-BGBdrdP7.cjs → ai-panel-quick-prompts-CGKAAn9A.cjs} +1 -1
  19. package/dist/{ai-prompt-input-qegCvwnu.js → ai-prompt-input-C3TnCYfz.js} +1 -1
  20. package/dist/{ai-prompt-input-DB1FpA_q.cjs → ai-prompt-input-CffQQOKA.cjs} +1 -1
  21. package/dist/{ai-translation-prompt--HB1UAhC.js → ai-translation-prompt-B8VdHfLY.js} +1 -1
  22. package/dist/{ai-translation-prompt-Bj-AM4xK.cjs → ai-translation-prompt-DH7gwfqx.cjs} +1 -1
  23. package/dist/{delete-page-C7xfkDN5.js → delete-page-Ck7tD4Hf.js} +1 -1
  24. package/dist/{delete-page-DJLNpUxo.cjs → delete-page-Crpwn0Wk.cjs} +1 -1
  25. package/dist/{digital-asset-manager-BblMbig0.cjs → digital-asset-manager-BVrv1-r1.cjs} +1 -1
  26. package/dist/{digital-asset-manager-INrgGoC0.js → digital-asset-manager-DgLKRrYj.js} +1 -1
  27. package/dist/{duplicate-page-B8k4yZxa.js → duplicate-page-C7d1f7Ii.js} +2 -2
  28. package/dist/{duplicate-page-C9XewuHN.cjs → duplicate-page-CXUueWfr.cjs} +1 -1
  29. package/dist/{dynamic-page-selector-C7Vos5-l.js → dynamic-page-selector-D544FjmW.js} +1 -1
  30. package/dist/{dynamic-page-selector-CYYnEngT.cjs → dynamic-page-selector-DcWDnam4.cjs} +1 -1
  31. package/dist/{index-CyHmr87X.cjs → index-B1OACNv-.cjs} +3 -3
  32. package/dist/{index-DRQI9rlW.js → index-DdQbaicX.js} +235 -235
  33. package/dist/index.cjs +1 -1
  34. package/dist/index.d.ts +1 -1
  35. package/dist/index.js +1 -1
  36. package/dist/{json-diff-viewer-8vUwU0Sk.js → json-diff-viewer-BhWTP1YY.js} +1 -1
  37. package/dist/{json-diff-viewer-DVskWjAL.cjs → json-diff-viewer-KCkYwJMA.cjs} +1 -1
  38. package/dist/{lang-panel-B8SeKnwN.js → lang-panel-by1VOWvc.js} +2 -2
  39. package/dist/{lang-panel-BeyCHr4u.cjs → lang-panel-tOddhH70.cjs} +1 -1
  40. package/dist/{mark-as-template-DTEF_hyN.cjs → mark-as-template-BUCysjr2.cjs} +1 -1
  41. package/dist/{mark-as-template-CpNHtyfB.js → mark-as-template-ngqCvlhA.js} +1 -1
  42. package/dist/{no-language-page-content-DnAP2ICP.cjs → no-language-page-content-CzTbZ07M.cjs} +1 -1
  43. package/dist/{no-language-page-content-BPiFDGJr.js → no-language-page-content-Dz3GSvnO.js} +1 -1
  44. package/dist/{page-creator-BawPgFIv.cjs → page-creator-BICVMC59.cjs} +1 -1
  45. package/dist/{page-creator-BiDN-rLc.js → page-creator-D2iEu92e.js} +2 -2
  46. package/dist/{page-lock-request-BVYclE6H.js → page-lock-request-DjfV2kmK.js} +1 -1
  47. package/dist/{page-lock-request-wIw-W5qT.cjs → page-lock-request-hlvjC2uX.cjs} +1 -1
  48. package/dist/{page-locked-by-dialog-jZDY0omZ.cjs → page-locked-by-dialog-NpUOJvWZ.cjs} +1 -1
  49. package/dist/{page-locked-by-dialog-CuHvd48D.js → page-locked-by-dialog-m6K_uaE8.js} +1 -1
  50. package/dist/{page-manager-new-BmZlPcpL.cjs → page-manager-new-C2jmBaFF.cjs} +1 -1
  51. package/dist/{page-manager-new-kMwd9hkH.js → page-manager-new-DshyH-mV.js} +2 -2
  52. package/dist/{page-manager-search-and-filter-BU-1wFbM.js → page-manager-search-and-filter-DCg7Fqi_.js} +1 -1
  53. package/dist/{page-manager-search-and-filter-DMauRN5Y.cjs → page-manager-search-and-filter-D_g51CM8.cjs} +1 -1
  54. package/dist/{page-revisions-content-c32By7XR.js → page-revisions-content-DZzxttKH.js} +2 -2
  55. package/dist/{page-revisions-content-BH0Xy_k9.cjs → page-revisions-content-N_qdjfDX.cjs} +1 -1
  56. package/dist/{prompt-helper-Bh7WyDYo.js → prompt-helper-D0QRFyFX.js} +1 -1
  57. package/dist/{prompt-helper-BLBZjr5q.cjs → prompt-helper-DIy7u3rt.cjs} +1 -1
  58. package/dist/{publish-pages-content-BB6l92oG.js → publish-pages-content-CRvy9fwt.js} +2 -2
  59. package/dist/{publish-pages-content-B5UqPZy0.cjs → publish-pages-content-Dtu7807d.cjs} +1 -1
  60. package/dist/{save-to-lib-NvQZll63.js → save-to-lib-BE0-MXVv.js} +1 -1
  61. package/dist/{save-to-lib-DM1MzZTb.cjs → save-to-lib-XnTNVHzy.cjs} +1 -1
  62. package/dist/{seo-panel-C20m5SFc.cjs → seo-panel-Ce3uf7XT.cjs} +1 -1
  63. package/dist/{seo-panel-BsMBb5Ep.js → seo-panel-dIE8Wi40.js} +1 -1
  64. package/dist/{shared-json-ld-CfWO90c0.cjs → shared-json-ld-DiVirR4t.cjs} +1 -1
  65. package/dist/{shared-json-ld-BVqIgANo.js → shared-json-ld-UCI8GeFi.js} +1 -1
  66. package/dist/{slug-input-BewLv-d8.cjs → slug-input-BbkCbVMY.cjs} +1 -1
  67. package/dist/{slug-input-RCGUFL2T.js → slug-input-DTA7c8c6.js} +1 -1
  68. package/dist/{theme-panel-footer-BJB36k8A.js → theme-panel-footer-BjRPU7lq.js} +1 -1
  69. package/dist/{theme-panel-footer-8oSQtfZ5.cjs → theme-panel-footer-uGKDjNbs.cjs} +1 -1
  70. package/dist/{unmark-as-template-CGZ0CCI2.js → unmark-as-template-BWviVI2t.js} +1 -1
  71. package/dist/{unmark-as-template-DLNmyum3.cjs → unmark-as-template-Dbhko_72.cjs} +1 -1
  72. package/dist/{unpublish-page-CEtpcrvc.js → unpublish-page-BzI9EFF9.js} +1 -1
  73. package/dist/{unpublish-page-B_xQPGsZ.cjs → unpublish-page-D0EmMryc.cjs} +1 -1
  74. package/dist/{web-preview-Cifi0bwK.cjs → web-preview-CSV-DXpI.cjs} +1 -1
  75. package/dist/{web-preview-CCGkTRU3.js → web-preview-SIUM1SWa.js} +1 -1
  76. package/package.json +1 -1
@@ -1,6 +1,6 @@
1
1
  import { jsx as t, jsxs as g, Fragment as hn } from "react/jsx-runtime";
2
- import { p as fn, r as gn, S as mn } from "./slug-input-RCGUFL2T.js";
3
- import { b as xn, c as vn, d as Sn, e as pn, f as Nn, g as Z, h as Fn, i as wn, L as A } from "./index-DRQI9rlW.js";
2
+ import { p as fn, r as gn, S as mn } from "./slug-input-DTA7c8c6.js";
3
+ import { b as xn, c as vn, d as Sn, e as pn, f as Nn, g as Z, h as Fn, i as wn, L as A } from "./index-DdQbaicX.js";
4
4
  import { useLanguages as An, useTranslation as T, useSidebarActivePanel as Cn } from "@chaibuilder/sdk";
5
5
  import { Dialog as En, DialogContent as $n, DialogHeader as Dn, DialogTitle as Ln, DialogDescription as Tn, Label as I, Input as Un, Alert as H, DialogFooter as kn, Button as Rn } from "@chaibuilder/sdk/ui";
6
6
  import { filter as Wn, find as Bn, startsWith as In } from "lodash-es";
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),V=require("./slug-input-BewLv-d8.cjs"),f=require("./index-CyHmr87X.cjs"),w=require("@chaibuilder/sdk"),S=require("@chaibuilder/sdk/ui"),Y=require("lodash-es"),is=require("lucide-react"),N=require("react"),X=({edit:c,lang:h,languages:a,name:u,setLang:t,setName:i,primaryPageObject:o})=>{const{t:s}=w.useTranslation();return e.jsxs("div",{className:"space-y-1",children:[e.jsx(S.Label,{htmlFor:"lang",children:s("Language")}),e.jsxs("select",{value:c?"":h,disabled:c||!a.length,onChange:l=>{const x=l.target.value;t(x),!c&&(Y.startsWith(u,o==null?void 0:o.name)||u.length===0)&&i(`${o==null?void 0:o.name} - ${f.LANGUAGES[x]}`)},className:"col-span-3 flex h-9 w-full rounded-md border border-border bg-background px-3 py-1 text-sm shadow-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50",children:[e.jsx("option",{value:"",disabled:!0,children:c?f.LANGUAGES[h]||h:a.length?s("Choose language"):s("All available language page is created.")}),a.map(l=>e.jsx("option",{value:l,children:f.LANGUAGES[l]||l},l))]})]})},Z=({lang:c,name:h,setName:a,parentHasSelectedLanguagePage:u})=>{const{t}=w.useTranslation();return e.jsxs("div",{className:"space-y-1",children:[e.jsx(S.Label,{htmlFor:"name",children:t("Page Name")}),e.jsx(S.Input,{id:"name",value:c?h:"",onChange:i=>a(i.target.value),required:!0,placeholder:t(c?"Enter page name":"Choose language to add slug"),disabled:!u||!c})]})},ds=({dynamic:c,isNonSlugPageType:h,isRootPage:a,lang:u,useLanguagePrefix:t,setUseLanguagePrefix:i,isHomePage:o,parentSlug:s,parentHasSelectedLanguagePage:l,slug:x,setSlug:d,setIsSlugValid:m,getSlug:g})=>{const{t:r}=w.useTranslation();return h?null:e.jsxs("div",{className:"space-y-1",children:[a&&u&&e.jsxs("div",{className:"flex items-center space-x-2 pb-1",children:[e.jsx("input",{type:"checkbox",id:"useLanguagePrefix",checked:t,onChange:A=>i(A.target.checked),className:"rounded border-gray-300"}),e.jsxs(S.Label,{htmlFor:"useLanguagePrefix",className:"text-sm font-normal leading-tight",children:["Add language code (",e.jsxs("span",{className:"font-mono text-gray-900",children:["/",u]}),") as slug prefix"]})]}),e.jsx(S.Label,{htmlFor:"slug",children:r("Slug")}),c?e.jsx(S.Alert,{variant:"default",className:"p-2 text-xs font-medium italic text-muted-foreground",children:r("This page will use dynamic slug as defined in primary page")}):e.jsx(V.SlugInput,{disabled:!u||!l,value:x,onChange:d,placeholder:r(u?o&&t?"Leave empty for home page":"Enter page slug":"Choose language to add slug"),parentSlug:s,onValidationChange:m,fullSlug:g()})]})},_=({parentHasSelectedLanguagePage:c,name:h,lang:a,slug:u,edit:t,id:i,primaryPageObject:o,pages:s,isNonSlugPageType:l,isHomePage:x,useLanguagePrefix:d,isSlugValid:m,isPending:g})=>{const{t:r}=w.useTranslation(),A=g||!h||!a||s.some(v=>(t?v.id!==i:!0)&&v.parent===(o==null?void 0:o.id)&&v.lang===a)||!l&&!(x&&d)&&(!m||!u);return e.jsx(S.DialogFooter,{children:c?e.jsxs(e.Fragment,{children:[e.jsx(S.Button,{type:"submit",disabled:A&&!o.dynamic,children:g?e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"loader mr-2"}),r(t?"Updating...":"Adding...")]}):r(t?"Update":"Add new language page")}),s.some(v=>(t?v.id!==i:!0)&&v.parent===(o==null?void 0:o.id)&&v.lang===a)&&e.jsx("p",{className:"mt-2 text-xs text-red-500",children:r("A page for this language already exists.")})]}):a&&e.jsx(S.Alert,{variant:"destructive",children:e.jsxs("p",{className:"mx-auto w-5/6 text-center",children:[r("You need to create the")," ",e.jsx("span",{className:"font-medium",children:f.LANGUAGES[a]})," ",r("page in the parent to add here.")]})})})},cs=({onSubmit:c,edit:h,lang:a,languages:u,name:t,setLang:i,setName:o,primaryPageObject:s,parentHasSelectedLanguagePage:l,id:x,pages:d,isNonSlugPageType:m,isHomePage:g,useLanguagePrefix:r,slug:A,isSlugValid:v,isPending:E})=>e.jsxs("form",{onSubmit:c,children:[e.jsxs("div",{className:"grid gap-4 py-4",children:[e.jsx(X,{edit:h,lang:a,languages:u,name:t,setLang:i,setName:o,primaryPageObject:s}),e.jsx(Z,{lang:a,name:t,setName:o,parentHasSelectedLanguagePage:l})]}),e.jsx(_,{parentHasSelectedLanguagePage:l,name:t,lang:a,slug:A,edit:h,id:x,primaryPageObject:s,pages:d,isNonSlugPageType:m,isHomePage:g,useLanguagePrefix:r,isSlugValid:v,isPending:E})]}),rs=({loading:c,onSubmit:h,edit:a,lang:u,languages:t,name:i,setLang:o,setName:s,primaryPageObject:l,parentHasSelectedLanguagePage:x,isNonSlugPageType:d,isRootPage:m,useLanguagePrefix:g,setUseLanguagePrefix:r,isHomePage:A,parentSlug:v,slug:E,setSlug:C,isSlugValid:T,setIsSlugValid:R,getSlug:M,isPending:$,id:D,pages:L})=>c?e.jsx("div",{className:"flex h-80 items-center justify-center",children:e.jsx(is.Loader,{className:"animate-spin"})}):d?e.jsx(cs,{onSubmit:h,edit:a,lang:u,languages:t,name:i,setLang:o,setName:s,primaryPageObject:l,parentHasSelectedLanguagePage:x,id:D,pages:L,isNonSlugPageType:d,isHomePage:A,useLanguagePrefix:g,slug:E,isSlugValid:T,isPending:$}):e.jsxs("form",{onSubmit:h,children:[e.jsxs("div",{className:"grid gap-4 py-4",children:[e.jsx(X,{edit:a,lang:u,languages:t,name:i,setLang:o,setName:s,primaryPageObject:l}),e.jsx(Z,{lang:u,name:i,setName:s,parentHasSelectedLanguagePage:x}),e.jsx(ds,{dynamic:l==null?void 0:l.dynamic,isNonSlugPageType:d,isRootPage:m,lang:u,useLanguagePrefix:g,setUseLanguagePrefix:r,isHomePage:A,parentSlug:v,parentHasSelectedLanguagePage:x,slug:E,setSlug:C,isSlugValid:T,setIsSlugValid:R,getSlug:M})]}),e.jsx(_,{parentHasSelectedLanguagePage:x,name:i,lang:u,slug:E,edit:a,id:D,primaryPageObject:l,pages:L,isNonSlugPageType:d,isHomePage:A,useLanguagePrefix:g,isSlugValid:T,isPending:$})]}),hs=({id:c,isOpen:h,onClose:a,primaryPage:u,edit:t=!1,preselectedLang:i})=>{const{data:o=[]}=f.useWebsitePages(),s=N.useMemo(()=>o.find(n=>n.id===u),[o,u]),[l,x]=N.useState(""),[d,m]=N.useState(""),[g,r]=N.useState(""),[A,v]=N.useState(!0),[E,C]=N.useState(!0),{mutate:T,isPending:R}=f.useCreatePage(),{mutate:M,isPending:$}=f.useUpdatePage(),D=R||$,{data:L,isFetching:H}=f.useWebsiteSetting(),j=f.useFallbackLang(),{data:G,isFetching:b}=f.useLanguagePages(u),{data:F=[],isFetching:y}=f.useLanguagePages(s==null?void 0:s.parent),{data:z=[],isFetching:P}=f.usePageTypes(),{setSelectedLang:O}=w.useLanguages(),{t:I}=w.useTranslation(),[,ss]=f.useSearchParams(),[,es]=w.useSidebarActivePanel(),ns=H||b||y||P,U=N.useMemo(()=>Y.filter(L==null?void 0:L.languages,n=>!Y.find(G,{lang:n})),[L,G]),W=N.useMemo(()=>z.find(n=>n.key===(s==null?void 0:s.pageType)),[z,s==null?void 0:s.pageType]),J=!(W!=null&&W.hasSlug),B=(s==null?void 0:s.slug)==="/";N.useEffect(()=>{if(!t&&s&&i&&(m(i),x(`${s.name} - ${f.LANGUAGES[i]}`)),!t||!s)return;const n=G==null?void 0:G.find(us=>us.id===c);if(!n)return;x(n.name),m(n.lang);const p=n.slug||"",{initSlug:k,prefix:as}=V.parseSlugForEdit(p,s);r(k),C(as)},[t,c,G,s,i]),N.useEffect(()=>{if(i)m(i);else if((U==null?void 0:U.length)===1&&!t){const n=U[0];if(!n||!f.LANGUAGES[n])return;m(n),(!l||l===(s==null?void 0:s.name))&&x(`${s==null?void 0:s.name} - ${f.LANGUAGES[n]}`)}},[i,U,t,l,s]);const{parentSlug:K,isRootPage:q}=N.useMemo(()=>{if(B||!d)return{parentSlug:void 0,isRootPage:!(s!=null&&s.parent)};if(!(s!=null&&s.parent))return{parentSlug:E?`/${d}`:void 0,isRootPage:!0};const n=F==null?void 0:F.find(p=>p.lang===d);return{parentSlug:n==null?void 0:n.slug,isRootPage:!1}},[s==null?void 0:s.parent,F,E,d,B]),ts=N.useMemo(()=>q?!0:!!(F!=null&&F.some(n=>(n==null?void 0:n.lang)===d)),[d,F,q]),Q=()=>{let n="";return q?n=`/${E?[d,g].filter(Boolean).join("/"):g}`:n=`${V.removeSlugExtension(K)}/${g}`,n.replace(/\/{2,}/g,"/").replace(/\/$/,"")},os=n=>{const p=new URLSearchParams(window.location.search);j&&n===j?p.delete("lang"):p.set("lang",n),ss(p),window.dispatchEvent(new PopStateEvent("popstate"))},ls=n=>{n.preventDefault();const p={name:l,lang:d,primaryPage:s==null?void 0:s.id,slug:J?"":Q(),pageType:s==null?void 0:s.pageType,...t&&{id:c}},k=()=>{!t&&d&&(O(d),os(d)),es("outline"),a()};t?M(p,{onSuccess:k}):T(p,{onSuccess:k})};return e.jsx(S.Dialog,{open:h,onOpenChange:a,children:h&&e.jsxs(S.DialogContent,{className:"text-slate-600 sm:max-w-[425px]",children:[e.jsxs(S.DialogHeader,{children:[e.jsx(S.DialogTitle,{children:I(t?"Edit language":"Add new language page")}),e.jsx(S.DialogDescription,{className:"font-light",children:I("Enter the details for the language")})]}),e.jsx(rs,{id:c,pages:o,loading:ns,onSubmit:ls,edit:t,lang:d,languages:U,name:l,setLang:m,setName:x,primaryPageObject:s,parentHasSelectedLanguagePage:ts,isNonSlugPageType:J,isRootPage:q,useLanguagePrefix:E,setUseLanguagePrefix:C,isHomePage:B,parentSlug:K,slug:g,setSlug:r,isSlugValid:A,setIsSlugValid:v,getSlug:Q,isPending:D})]})})};exports.default=hs;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),V=require("./slug-input-BbkCbVMY.cjs"),f=require("./index-B1OACNv-.cjs"),w=require("@chaibuilder/sdk"),S=require("@chaibuilder/sdk/ui"),Y=require("lodash-es"),is=require("lucide-react"),N=require("react"),X=({edit:c,lang:h,languages:a,name:u,setLang:t,setName:i,primaryPageObject:o})=>{const{t:s}=w.useTranslation();return e.jsxs("div",{className:"space-y-1",children:[e.jsx(S.Label,{htmlFor:"lang",children:s("Language")}),e.jsxs("select",{value:c?"":h,disabled:c||!a.length,onChange:l=>{const x=l.target.value;t(x),!c&&(Y.startsWith(u,o==null?void 0:o.name)||u.length===0)&&i(`${o==null?void 0:o.name} - ${f.LANGUAGES[x]}`)},className:"col-span-3 flex h-9 w-full rounded-md border border-border bg-background px-3 py-1 text-sm shadow-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50",children:[e.jsx("option",{value:"",disabled:!0,children:c?f.LANGUAGES[h]||h:a.length?s("Choose language"):s("All available language page is created.")}),a.map(l=>e.jsx("option",{value:l,children:f.LANGUAGES[l]||l},l))]})]})},Z=({lang:c,name:h,setName:a,parentHasSelectedLanguagePage:u})=>{const{t}=w.useTranslation();return e.jsxs("div",{className:"space-y-1",children:[e.jsx(S.Label,{htmlFor:"name",children:t("Page Name")}),e.jsx(S.Input,{id:"name",value:c?h:"",onChange:i=>a(i.target.value),required:!0,placeholder:t(c?"Enter page name":"Choose language to add slug"),disabled:!u||!c})]})},ds=({dynamic:c,isNonSlugPageType:h,isRootPage:a,lang:u,useLanguagePrefix:t,setUseLanguagePrefix:i,isHomePage:o,parentSlug:s,parentHasSelectedLanguagePage:l,slug:x,setSlug:d,setIsSlugValid:m,getSlug:g})=>{const{t:r}=w.useTranslation();return h?null:e.jsxs("div",{className:"space-y-1",children:[a&&u&&e.jsxs("div",{className:"flex items-center space-x-2 pb-1",children:[e.jsx("input",{type:"checkbox",id:"useLanguagePrefix",checked:t,onChange:A=>i(A.target.checked),className:"rounded border-gray-300"}),e.jsxs(S.Label,{htmlFor:"useLanguagePrefix",className:"text-sm font-normal leading-tight",children:["Add language code (",e.jsxs("span",{className:"font-mono text-gray-900",children:["/",u]}),") as slug prefix"]})]}),e.jsx(S.Label,{htmlFor:"slug",children:r("Slug")}),c?e.jsx(S.Alert,{variant:"default",className:"p-2 text-xs font-medium italic text-muted-foreground",children:r("This page will use dynamic slug as defined in primary page")}):e.jsx(V.SlugInput,{disabled:!u||!l,value:x,onChange:d,placeholder:r(u?o&&t?"Leave empty for home page":"Enter page slug":"Choose language to add slug"),parentSlug:s,onValidationChange:m,fullSlug:g()})]})},_=({parentHasSelectedLanguagePage:c,name:h,lang:a,slug:u,edit:t,id:i,primaryPageObject:o,pages:s,isNonSlugPageType:l,isHomePage:x,useLanguagePrefix:d,isSlugValid:m,isPending:g})=>{const{t:r}=w.useTranslation(),A=g||!h||!a||s.some(v=>(t?v.id!==i:!0)&&v.parent===(o==null?void 0:o.id)&&v.lang===a)||!l&&!(x&&d)&&(!m||!u);return e.jsx(S.DialogFooter,{children:c?e.jsxs(e.Fragment,{children:[e.jsx(S.Button,{type:"submit",disabled:A&&!o.dynamic,children:g?e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"loader mr-2"}),r(t?"Updating...":"Adding...")]}):r(t?"Update":"Add new language page")}),s.some(v=>(t?v.id!==i:!0)&&v.parent===(o==null?void 0:o.id)&&v.lang===a)&&e.jsx("p",{className:"mt-2 text-xs text-red-500",children:r("A page for this language already exists.")})]}):a&&e.jsx(S.Alert,{variant:"destructive",children:e.jsxs("p",{className:"mx-auto w-5/6 text-center",children:[r("You need to create the")," ",e.jsx("span",{className:"font-medium",children:f.LANGUAGES[a]})," ",r("page in the parent to add here.")]})})})},cs=({onSubmit:c,edit:h,lang:a,languages:u,name:t,setLang:i,setName:o,primaryPageObject:s,parentHasSelectedLanguagePage:l,id:x,pages:d,isNonSlugPageType:m,isHomePage:g,useLanguagePrefix:r,slug:A,isSlugValid:v,isPending:E})=>e.jsxs("form",{onSubmit:c,children:[e.jsxs("div",{className:"grid gap-4 py-4",children:[e.jsx(X,{edit:h,lang:a,languages:u,name:t,setLang:i,setName:o,primaryPageObject:s}),e.jsx(Z,{lang:a,name:t,setName:o,parentHasSelectedLanguagePage:l})]}),e.jsx(_,{parentHasSelectedLanguagePage:l,name:t,lang:a,slug:A,edit:h,id:x,primaryPageObject:s,pages:d,isNonSlugPageType:m,isHomePage:g,useLanguagePrefix:r,isSlugValid:v,isPending:E})]}),rs=({loading:c,onSubmit:h,edit:a,lang:u,languages:t,name:i,setLang:o,setName:s,primaryPageObject:l,parentHasSelectedLanguagePage:x,isNonSlugPageType:d,isRootPage:m,useLanguagePrefix:g,setUseLanguagePrefix:r,isHomePage:A,parentSlug:v,slug:E,setSlug:C,isSlugValid:T,setIsSlugValid:R,getSlug:M,isPending:$,id:D,pages:L})=>c?e.jsx("div",{className:"flex h-80 items-center justify-center",children:e.jsx(is.Loader,{className:"animate-spin"})}):d?e.jsx(cs,{onSubmit:h,edit:a,lang:u,languages:t,name:i,setLang:o,setName:s,primaryPageObject:l,parentHasSelectedLanguagePage:x,id:D,pages:L,isNonSlugPageType:d,isHomePage:A,useLanguagePrefix:g,slug:E,isSlugValid:T,isPending:$}):e.jsxs("form",{onSubmit:h,children:[e.jsxs("div",{className:"grid gap-4 py-4",children:[e.jsx(X,{edit:a,lang:u,languages:t,name:i,setLang:o,setName:s,primaryPageObject:l}),e.jsx(Z,{lang:u,name:i,setName:s,parentHasSelectedLanguagePage:x}),e.jsx(ds,{dynamic:l==null?void 0:l.dynamic,isNonSlugPageType:d,isRootPage:m,lang:u,useLanguagePrefix:g,setUseLanguagePrefix:r,isHomePage:A,parentSlug:v,parentHasSelectedLanguagePage:x,slug:E,setSlug:C,isSlugValid:T,setIsSlugValid:R,getSlug:M})]}),e.jsx(_,{parentHasSelectedLanguagePage:x,name:i,lang:u,slug:E,edit:a,id:D,primaryPageObject:l,pages:L,isNonSlugPageType:d,isHomePage:A,useLanguagePrefix:g,isSlugValid:T,isPending:$})]}),hs=({id:c,isOpen:h,onClose:a,primaryPage:u,edit:t=!1,preselectedLang:i})=>{const{data:o=[]}=f.useWebsitePages(),s=N.useMemo(()=>o.find(n=>n.id===u),[o,u]),[l,x]=N.useState(""),[d,m]=N.useState(""),[g,r]=N.useState(""),[A,v]=N.useState(!0),[E,C]=N.useState(!0),{mutate:T,isPending:R}=f.useCreatePage(),{mutate:M,isPending:$}=f.useUpdatePage(),D=R||$,{data:L,isFetching:H}=f.useWebsiteSetting(),j=f.useFallbackLang(),{data:G,isFetching:b}=f.useLanguagePages(u),{data:F=[],isFetching:y}=f.useLanguagePages(s==null?void 0:s.parent),{data:z=[],isFetching:P}=f.usePageTypes(),{setSelectedLang:O}=w.useLanguages(),{t:I}=w.useTranslation(),[,ss]=f.useSearchParams(),[,es]=w.useSidebarActivePanel(),ns=H||b||y||P,U=N.useMemo(()=>Y.filter(L==null?void 0:L.languages,n=>!Y.find(G,{lang:n})),[L,G]),W=N.useMemo(()=>z.find(n=>n.key===(s==null?void 0:s.pageType)),[z,s==null?void 0:s.pageType]),J=!(W!=null&&W.hasSlug),B=(s==null?void 0:s.slug)==="/";N.useEffect(()=>{if(!t&&s&&i&&(m(i),x(`${s.name} - ${f.LANGUAGES[i]}`)),!t||!s)return;const n=G==null?void 0:G.find(us=>us.id===c);if(!n)return;x(n.name),m(n.lang);const p=n.slug||"",{initSlug:k,prefix:as}=V.parseSlugForEdit(p,s);r(k),C(as)},[t,c,G,s,i]),N.useEffect(()=>{if(i)m(i);else if((U==null?void 0:U.length)===1&&!t){const n=U[0];if(!n||!f.LANGUAGES[n])return;m(n),(!l||l===(s==null?void 0:s.name))&&x(`${s==null?void 0:s.name} - ${f.LANGUAGES[n]}`)}},[i,U,t,l,s]);const{parentSlug:K,isRootPage:q}=N.useMemo(()=>{if(B||!d)return{parentSlug:void 0,isRootPage:!(s!=null&&s.parent)};if(!(s!=null&&s.parent))return{parentSlug:E?`/${d}`:void 0,isRootPage:!0};const n=F==null?void 0:F.find(p=>p.lang===d);return{parentSlug:n==null?void 0:n.slug,isRootPage:!1}},[s==null?void 0:s.parent,F,E,d,B]),ts=N.useMemo(()=>q?!0:!!(F!=null&&F.some(n=>(n==null?void 0:n.lang)===d)),[d,F,q]),Q=()=>{let n="";return q?n=`/${E?[d,g].filter(Boolean).join("/"):g}`:n=`${V.removeSlugExtension(K)}/${g}`,n.replace(/\/{2,}/g,"/").replace(/\/$/,"")},os=n=>{const p=new URLSearchParams(window.location.search);j&&n===j?p.delete("lang"):p.set("lang",n),ss(p),window.dispatchEvent(new PopStateEvent("popstate"))},ls=n=>{n.preventDefault();const p={name:l,lang:d,primaryPage:s==null?void 0:s.id,slug:J?"":Q(),pageType:s==null?void 0:s.pageType,...t&&{id:c}},k=()=>{!t&&d&&(O(d),os(d)),es("outline"),a()};t?M(p,{onSuccess:k}):T(p,{onSuccess:k})};return e.jsx(S.Dialog,{open:h,onOpenChange:a,children:h&&e.jsxs(S.DialogContent,{className:"text-slate-600 sm:max-w-[425px]",children:[e.jsxs(S.DialogHeader,{children:[e.jsx(S.DialogTitle,{children:I(t?"Edit language":"Add new language page")}),e.jsx(S.DialogDescription,{className:"font-light",children:I("Enter the details for the language")})]}),e.jsx(rs,{id:c,pages:o,loading:ns,onSubmit:ls,edit:t,lang:d,languages:U,name:l,setLang:m,setName:x,primaryPageObject:s,parentHasSelectedLanguagePage:ts,isNonSlugPageType:J,isRootPage:q,useLanguagePrefix:E,setUseLanguagePrefix:C,isHomePage:B,parentSlug:K,slug:g,setSlug:r,isSlugValid:A,setIsSlugValid:v,getSlug:Q,isPending:D})]})})};exports.default=hs;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),a=require("@chaibuilder/sdk"),n=require("@chaibuilder/sdk/ui"),t=require("react"),u=t.lazy(()=>Promise.resolve().then(()=>require("./page-creator-BawPgFIv.cjs"))),x=({addEditPage:s,setAddEditPage:r,closePanel:c})=>{const{t:o}=a.useTranslation(),i=!!(s!=null&&s.id),l=!!s;return e.jsx(n.Dialog,{open:l,onOpenChange:()=>r(void 0),children:l&&e.jsxs(n.DialogContent,{className:"sm:max-w-[425px]",children:[e.jsxs(n.DialogHeader,{children:[e.jsxs(n.DialogTitle,{children:[o(i?"Edit":"Add New")," "]}),e.jsx(n.DialogDescription,{children:o(i?"Update your page name":"Enter details to create a new page")})]}),e.jsx(t.Suspense,{fallback:e.jsx("div",{className:"min-h-40"}),children:e.jsx(u,{closePanel:c,addEditPage:s,close:()=>r(void 0)})})]})})};exports.default=x;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),a=require("@chaibuilder/sdk"),n=require("@chaibuilder/sdk/ui"),t=require("react"),u=t.lazy(()=>Promise.resolve().then(()=>require("./page-creator-BICVMC59.cjs"))),x=({addEditPage:s,setAddEditPage:r,closePanel:c})=>{const{t:o}=a.useTranslation(),i=!!(s!=null&&s.id),l=!!s;return e.jsx(n.Dialog,{open:l,onOpenChange:()=>r(void 0),children:l&&e.jsxs(n.DialogContent,{className:"sm:max-w-[425px]",children:[e.jsxs(n.DialogHeader,{children:[e.jsxs(n.DialogTitle,{children:[o(i?"Edit":"Add New")," "]}),e.jsx(n.DialogDescription,{children:o(i?"Update your page name":"Enter details to create a new page")})]}),e.jsx(t.Suspense,{fallback:e.jsx("div",{className:"min-h-40"}),children:e.jsx(u,{closePanel:c,addEditPage:s,close:()=>r(void 0)})})]})})};exports.default=x;
@@ -2,7 +2,7 @@ import { jsx as e, jsxs as r } from "react/jsx-runtime";
2
2
  import { useTranslation as a } from "@chaibuilder/sdk";
3
3
  import { Dialog as c, DialogContent as m, DialogHeader as p, DialogTitle as h, DialogDescription as f } from "@chaibuilder/sdk/ui";
4
4
  import { lazy as D, Suspense as u } from "react";
5
- const x = D(() => import("./page-creator-BiDN-rLc.js")), C = ({
5
+ const x = D(() => import("./page-creator-D2iEu92e.js")), C = ({
6
6
  addEditPage: o,
7
7
  setAddEditPage: i,
8
8
  closePanel: t
@@ -1,11 +1,11 @@
1
1
  import { jsxs as m, Fragment as M, jsx as n } from "react/jsx-runtime";
2
- import { q as j, i as y } from "./index-DRQI9rlW.js";
2
+ import { q as j, i as y } from "./index-DdQbaicX.js";
3
3
  import { useTranslation as B, useLanguages as F } from "@chaibuilder/sdk";
4
4
  import { Button as z } from "@chaibuilder/sdk/ui";
5
5
  import { Plus as I } from "lucide-react";
6
6
  import { lazy as x, useState as l, useEffect as q, Suspense as D } from "react";
7
7
  import { toast as E } from "sonner";
8
- const G = x(() => import("./ai-panel-default-lang-BYfcAA8u.js")), O = x(() => import("./ai-panel-other-lang-TVjNYPRK.js")), V = () => {
8
+ const G = x(() => import("./ai-panel-default-lang-DRkJegQm.js")), O = x(() => import("./ai-panel-other-lang-CQVkWTd3.js")), V = () => {
9
9
  const { t: s } = B(), [b, r] = l(""), [e, o] = l([]), [a, c] = l(!1), [i, f] = l(null), [w, u] = l(null), [C, L] = l("google/gemini-2.5-flash"), { selectedLang: d, fallbackLang: P } = F(), N = j(), [v] = y(), S = v.get("page"), k = (e == null ? void 0 : e.filter((t) => t.role === "user").length) >= 4, A = (e == null ? void 0 : e.filter((t) => t.role === "user").length) >= 10;
10
10
  q(() => {
11
11
  o([]);
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),j=require("./index-CyHmr87X.cjs"),m=require("@chaibuilder/sdk"),N=require("@chaibuilder/sdk/ui"),k=require("lucide-react"),n=require("react"),M=require("sonner"),A=n.lazy(()=>Promise.resolve().then(()=>require("./ai-panel-default-lang-D-RS6z5I.cjs"))),z=n.lazy(()=>Promise.resolve().then(()=>require("./ai-panel-other-lang-BoD4FsoG.cjs"))),B=()=>{const{t:o}=m.useTranslation(),[S,r]=n.useState(""),[t,l]=n.useState([]),[a,c]=n.useState(!1),[i,u]=n.useState(null),[b,d]=n.useState(null),[p,P]=n.useState("google/gemini-2.5-flash"),{selectedLang:f,fallbackLang:q}=m.useLanguages(),v=j.useBuilderFetch(),[w]=j.useSearchParams(),C=w.get("page"),L=(t==null?void 0:t.filter(s=>s.role==="user").length)>=4,y=(t==null?void 0:t.filter(s=>s.role==="user").length)>=10;n.useEffect(()=>{l([])},[f,C]);const g=()=>{l([]),r(""),d(null),u(null),c(!1)},x={t:o,fetch:v,input:S,messages:t,setInput:r,isLoading:a,handleStop:()=>{i&&(i.abort(),u(null)),c(!1),r(""),d(null),l(s=>{const h=s[s.length-1];return h&&h.role==="assistant"&&!h.content.trim()?s.slice(0,-1):s}),M.toast.info(o("Generation stopped"))},handleReset:g,setMessages:l,setIsLoading:c,currentBlock:b,fallbackLang:q,abortController:i,setCurrentBlock:d,setAbortController:u,forceNewConversation:y,suggestNewConversation:L,selectedModel:p,onModelChange:P};return e.jsxs(e.Fragment,{children:[a&&e.jsx("div",{className:"fixed inset-0 left-0 top-0 z-40 flex h-screen w-screen flex-col items-center justify-center bg-transparent"}),e.jsxs("div",{className:"flex h-full w-full flex-col bg-white",children:[e.jsxs("div",{className:"flex w-full items-center justify-between",children:[e.jsx("p",{className:"text-xs text-gray-500",children:o("Your conversation will not be saved")}),(t==null?void 0:t.length)>0&&e.jsx(N.Button,{variant:"outline",size:"icon",onClick:g,className:"h-6 w-6",disabled:a,children:e.jsx(k.Plus,{})})]}),e.jsx(n.Suspense,{fallback:e.jsx("div",{children:"Loading AI Panel..."}),children:f?e.jsx(z,{...x,selectedLang:f}):e.jsx(A,{...x})})]})]})};exports.default=B;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),j=require("./index-B1OACNv-.cjs"),m=require("@chaibuilder/sdk"),N=require("@chaibuilder/sdk/ui"),k=require("lucide-react"),n=require("react"),M=require("sonner"),A=n.lazy(()=>Promise.resolve().then(()=>require("./ai-panel-default-lang-Dnfg53l_.cjs"))),z=n.lazy(()=>Promise.resolve().then(()=>require("./ai-panel-other-lang-0_g52R_I.cjs"))),B=()=>{const{t:o}=m.useTranslation(),[S,r]=n.useState(""),[t,l]=n.useState([]),[a,c]=n.useState(!1),[i,u]=n.useState(null),[b,d]=n.useState(null),[p,P]=n.useState("google/gemini-2.5-flash"),{selectedLang:f,fallbackLang:q}=m.useLanguages(),v=j.useBuilderFetch(),[w]=j.useSearchParams(),C=w.get("page"),L=(t==null?void 0:t.filter(s=>s.role==="user").length)>=4,y=(t==null?void 0:t.filter(s=>s.role==="user").length)>=10;n.useEffect(()=>{l([])},[f,C]);const g=()=>{l([]),r(""),d(null),u(null),c(!1)},x={t:o,fetch:v,input:S,messages:t,setInput:r,isLoading:a,handleStop:()=>{i&&(i.abort(),u(null)),c(!1),r(""),d(null),l(s=>{const h=s[s.length-1];return h&&h.role==="assistant"&&!h.content.trim()?s.slice(0,-1):s}),M.toast.info(o("Generation stopped"))},handleReset:g,setMessages:l,setIsLoading:c,currentBlock:b,fallbackLang:q,abortController:i,setCurrentBlock:d,setAbortController:u,forceNewConversation:y,suggestNewConversation:L,selectedModel:p,onModelChange:P};return e.jsxs(e.Fragment,{children:[a&&e.jsx("div",{className:"fixed inset-0 left-0 top-0 z-40 flex h-screen w-screen flex-col items-center justify-center bg-transparent"}),e.jsxs("div",{className:"flex h-full w-full flex-col bg-white",children:[e.jsxs("div",{className:"flex w-full items-center justify-between",children:[e.jsx("p",{className:"text-xs text-gray-500",children:o("Your conversation will not be saved")}),(t==null?void 0:t.length)>0&&e.jsx(N.Button,{variant:"outline",size:"icon",onClick:g,className:"h-6 w-6",disabled:a,children:e.jsx(k.Plus,{})})]}),e.jsx(n.Suspense,{fallback:e.jsx("div",{children:"Loading AI Panel..."}),children:f?e.jsx(z,{...x,selectedLang:f}):e.jsx(A,{...x})})]})]})};exports.default=B;
@@ -3,7 +3,7 @@ import { useAddBlock as te, useReplaceBlock as ne, useSelectedBlock as re, useBl
3
3
  import { Bot as se, Plus as ae } from "lucide-react";
4
4
  import { lazy as D, useRef as ce, useEffect as ie, Suspense as _ } from "react";
5
5
  import { toast as de } from "sonner";
6
- import { a as ue } from "./prompt-helper-Bh7WyDYo.js";
6
+ import { a as ue } from "./prompt-helper-D0QRFyFX.js";
7
7
  function me(t) {
8
8
  if (!t) return "";
9
9
  let e = t.trim();
@@ -26,7 +26,7 @@ const he = (t) => {
26
26
  return c.style.height = "100vh", l.appendChild(c), c;
27
27
  }
28
28
  return l;
29
- }, pe = D(() => import("./ai-panel-message-bubble-DPAaAMAZ.js")), be = D(() => import("./ai-prompt-input-qegCvwnu.js")), Ee = ({
29
+ }, pe = D(() => import("./ai-panel-message-bubble-DPAaAMAZ.js")), be = D(() => import("./ai-prompt-input-C3TnCYfz.js")), Ee = ({
30
30
  t,
31
31
  fetch: e,
32
32
  input: s,
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react/jsx-runtime"),h=require("@chaibuilder/sdk"),T=require("lucide-react"),d=require("react"),ee=require("sonner"),te=require("./prompt-helper-BLBZjr5q.cjs");function ne(n){if(!n)return"";let e=n.trim();return e=e.replace(/^```html\n?/i,""),e=e.replace(/^```\n?/,""),e=e.replace(/\n?```$/,""),e=e.trim(),e}function re(n){if(!n)return"";const e=ne(n);return e.length===0||!e.includes("<")||!e.includes(">")?"":e}const oe=n=>{const e=document.getElementById("canvas-iframe");if(!e)return null;const l=e==null?void 0:e.contentDocument;if(!l)return null;const s=l.querySelector(`[data-block-id="${n}"]`);if(!s)return null;if(n==="canvas"){const a=l.createElement("div");return a.style.height="100vh",s.appendChild(a),a}return s},se=d.lazy(()=>Promise.resolve().then(()=>require("./ai-panel-message-bubble-Bl-aUeU4.cjs"))),le=d.lazy(()=>Promise.resolve().then(()=>require("./ai-prompt-input-DB1FpA_q.cjs"))),ce=({t:n,fetch:e,input:l,messages:s,setInput:a,isLoading:m,setMessages:v,handleReset:_,handleStop:D,setIsLoading:k,currentBlock:z,fallbackLang:M,setCurrentBlock:R,setAbortController:E,forceNewConversation:j,suggestNewConversation:V,selectedModel:q="google/gemini-2.5-flash",onModelChange:O})=>{const A=d.useRef(null),{addPredefinedBlock:U}=h.useAddBlock(),W=h.useReplaceBlock(),f=h.useSelectedBlock(),$=h.useBlocksHtmlForAi(),C=h.useHtmlToBlocks(),K=()=>{var o;(o=A.current)==null||o.scrollIntoView({behavior:"smooth"})};d.useEffect(()=>{K()},[s,m]);const L=async(o,x,H,G)=>{var I;if(!o||m)return;const r=f;R(f);const N=$();if(f&&!N){ee.toast.error(n("Something went wrong. Please try again."));return}const P={id:Date.now().toString(),role:"user",content:te.getUserPrompt({language:M,userInput:x||o,currentHtml:f?N:""}),userMessage:o},B={id:Date.now().toString(),role:"assistant",content:""};v(i=>[...i,P,B]),k(!0);const J=new AbortController;E(J);try{const i={messages:[...s,P].map(g=>({role:g.role,content:g.content})),model:G||q};H&&(i.image=H);const b=await e({body:{action:"ASK_AI",data:i},streamResponse:!0});if(!b.ok)throw new Error(n("Failed to get AI response"));const p=(I=b.body)==null?void 0:I.getReader(),Q=new TextDecoder;let y="";if(!p)throw new Error(n("Response body is not readable"));const u=oe(r?r==null?void 0:r._id:"canvas");for(;;){const{done:g,value:Y}=await p.read();if(g){u&&!r&&u.remove();break}const Z=Q.decode(Y,{stream:!0});if(y+=Z,u){u.innerHTML=y;const w=u.getBoundingClientRect(),c=document.getElementById("canvas-iframe"),F=c==null?void 0:c.contentWindow;F&&(w.top>=0&&w.bottom<=F.innerHeight||u.scrollIntoView({behavior:"smooth",block:"nearest"}))}v(w=>w.map(c=>c.id===B.id?{...c,content:y}:c))}const X=re(y),S=C(X);r!=null&&r._id?(console.log("Editing block",r==null?void 0:r._id,S),W(r==null?void 0:r._id,S)):U([...S],r==null?void 0:r._parent,-1)}catch(i){if(i.name!=="AbortError"){const b={id:(Date.now()+1).toString(),role:"assistant",content:n("Sorry, I encountered an error. Please try again.")};v(p=>[...p,b])}}finally{a(""),k(!1),R(null),E(null)}};return t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"flex-1 space-y-3 overflow-y-auto py-4",children:[s.length===0&&t.jsx("div",{className:"flex-1 space-y-3 overflow-y-auto py-4",children:t.jsxs("div",{className:"mx-auto mt-8 text-center text-gray-500",children:[t.jsx(T.Bot,{size:48,className:"mx-auto mb-4 text-gray-300"}),t.jsx("p",{className:"mx-auto max-w-[75%] text-sm",children:n("Start a conversation with the AI assistant to generate and update your sections")})]})}),s.map((o,x)=>o.role!=="system"&&t.jsx(d.Suspense,{fallback:t.jsx("div",{children:"Loading..."}),children:t.jsx(se,{message:o,isUser:o.role==="user",isLoading:o.role==="assistant"&&m&&x===s.length-1})},x)),V&&!m&&t.jsx("button",{onClick:_,className:"flex w-full items-center justify-center gap-2 rounded-lg border border-blue-200 bg-blue-50 p-1.5 text-left transition-colors hover:bg-blue-100",children:t.jsx("div",{className:"flex flex-col",children:t.jsxs("span",{className:"flex items-center gap-1 text-xs font-medium text-blue-700",children:[t.jsx(T.Plus,{className:"h-4 w-4 capitalize text-blue-600"}),n(j?"Start":"New")," ",n("Conversation")," ",!j&&t.jsx("span",{className:"text-[10px] font-extralight text-blue-600",children:n("For best results")})]})})}),t.jsx("div",{ref:A})]}),!j&&t.jsx("div",{className:"border-gray-200 pb-2",children:t.jsx(d.Suspense,{fallback:t.jsx("div",{children:"Loading..."}),children:t.jsx(le,{input:l,setInput:a,onSend:L,onStop:D,isLoading:m,selectedLang:"",currentBlock:f||z,disabled:(l==null?void 0:l.length)===0,selectedModel:q,onModelChange:O})})})]})};exports.default=ce;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react/jsx-runtime"),h=require("@chaibuilder/sdk"),T=require("lucide-react"),d=require("react"),ee=require("sonner"),te=require("./prompt-helper-DIy7u3rt.cjs");function ne(n){if(!n)return"";let e=n.trim();return e=e.replace(/^```html\n?/i,""),e=e.replace(/^```\n?/,""),e=e.replace(/\n?```$/,""),e=e.trim(),e}function re(n){if(!n)return"";const e=ne(n);return e.length===0||!e.includes("<")||!e.includes(">")?"":e}const oe=n=>{const e=document.getElementById("canvas-iframe");if(!e)return null;const l=e==null?void 0:e.contentDocument;if(!l)return null;const s=l.querySelector(`[data-block-id="${n}"]`);if(!s)return null;if(n==="canvas"){const a=l.createElement("div");return a.style.height="100vh",s.appendChild(a),a}return s},se=d.lazy(()=>Promise.resolve().then(()=>require("./ai-panel-message-bubble-Bl-aUeU4.cjs"))),le=d.lazy(()=>Promise.resolve().then(()=>require("./ai-prompt-input-CffQQOKA.cjs"))),ce=({t:n,fetch:e,input:l,messages:s,setInput:a,isLoading:m,setMessages:v,handleReset:_,handleStop:D,setIsLoading:k,currentBlock:z,fallbackLang:M,setCurrentBlock:R,setAbortController:E,forceNewConversation:j,suggestNewConversation:V,selectedModel:q="google/gemini-2.5-flash",onModelChange:O})=>{const A=d.useRef(null),{addPredefinedBlock:U}=h.useAddBlock(),W=h.useReplaceBlock(),f=h.useSelectedBlock(),$=h.useBlocksHtmlForAi(),C=h.useHtmlToBlocks(),K=()=>{var o;(o=A.current)==null||o.scrollIntoView({behavior:"smooth"})};d.useEffect(()=>{K()},[s,m]);const L=async(o,x,H,G)=>{var I;if(!o||m)return;const r=f;R(f);const N=$();if(f&&!N){ee.toast.error(n("Something went wrong. Please try again."));return}const P={id:Date.now().toString(),role:"user",content:te.getUserPrompt({language:M,userInput:x||o,currentHtml:f?N:""}),userMessage:o},B={id:Date.now().toString(),role:"assistant",content:""};v(i=>[...i,P,B]),k(!0);const J=new AbortController;E(J);try{const i={messages:[...s,P].map(g=>({role:g.role,content:g.content})),model:G||q};H&&(i.image=H);const b=await e({body:{action:"ASK_AI",data:i},streamResponse:!0});if(!b.ok)throw new Error(n("Failed to get AI response"));const p=(I=b.body)==null?void 0:I.getReader(),Q=new TextDecoder;let y="";if(!p)throw new Error(n("Response body is not readable"));const u=oe(r?r==null?void 0:r._id:"canvas");for(;;){const{done:g,value:Y}=await p.read();if(g){u&&!r&&u.remove();break}const Z=Q.decode(Y,{stream:!0});if(y+=Z,u){u.innerHTML=y;const w=u.getBoundingClientRect(),c=document.getElementById("canvas-iframe"),F=c==null?void 0:c.contentWindow;F&&(w.top>=0&&w.bottom<=F.innerHeight||u.scrollIntoView({behavior:"smooth",block:"nearest"}))}v(w=>w.map(c=>c.id===B.id?{...c,content:y}:c))}const X=re(y),S=C(X);r!=null&&r._id?(console.log("Editing block",r==null?void 0:r._id,S),W(r==null?void 0:r._id,S)):U([...S],r==null?void 0:r._parent,-1)}catch(i){if(i.name!=="AbortError"){const b={id:(Date.now()+1).toString(),role:"assistant",content:n("Sorry, I encountered an error. Please try again.")};v(p=>[...p,b])}}finally{a(""),k(!1),R(null),E(null)}};return t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"flex-1 space-y-3 overflow-y-auto py-4",children:[s.length===0&&t.jsx("div",{className:"flex-1 space-y-3 overflow-y-auto py-4",children:t.jsxs("div",{className:"mx-auto mt-8 text-center text-gray-500",children:[t.jsx(T.Bot,{size:48,className:"mx-auto mb-4 text-gray-300"}),t.jsx("p",{className:"mx-auto max-w-[75%] text-sm",children:n("Start a conversation with the AI assistant to generate and update your sections")})]})}),s.map((o,x)=>o.role!=="system"&&t.jsx(d.Suspense,{fallback:t.jsx("div",{children:"Loading..."}),children:t.jsx(se,{message:o,isUser:o.role==="user",isLoading:o.role==="assistant"&&m&&x===s.length-1})},x)),V&&!m&&t.jsx("button",{onClick:_,className:"flex w-full items-center justify-center gap-2 rounded-lg border border-blue-200 bg-blue-50 p-1.5 text-left transition-colors hover:bg-blue-100",children:t.jsx("div",{className:"flex flex-col",children:t.jsxs("span",{className:"flex items-center gap-1 text-xs font-medium text-blue-700",children:[t.jsx(T.Plus,{className:"h-4 w-4 capitalize text-blue-600"}),n(j?"Start":"New")," ",n("Conversation")," ",!j&&t.jsx("span",{className:"text-[10px] font-extralight text-blue-600",children:n("For best results")})]})})}),t.jsx("div",{ref:A})]}),!j&&t.jsx("div",{className:"border-gray-200 pb-2",children:t.jsx(d.Suspense,{fallback:t.jsx("div",{children:"Loading..."}),children:t.jsx(le,{input:l,setInput:a,onSend:L,onStop:D,isLoading:m,selectedLang:"",currentBlock:f||z,disabled:(l==null?void 0:l.length)===0,selectedModel:q,onModelChange:O})})})]})};exports.default=ce;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),G=require("./index-CyHmr87X.cjs"),d=require("@chaibuilder/sdk"),j=require("lucide-react"),r=require("react"),L=require("./prompt-helper-BLBZjr5q.cjs"),Q=r.lazy(()=>Promise.resolve().then(()=>require("./ai-panel-message-bubble-Bl-aUeU4.cjs"))),X=r.lazy(()=>Promise.resolve().then(()=>require("./ai-translation-prompt-Bj-AM4xK.cjs"))),Y=r.lazy(()=>Promise.resolve().then(()=>require("./ai-prompt-input-DB1FpA_q.cjs"))),Z=({fetch:q,input:o,messages:c,setInput:f,isLoading:n,handleStop:A,handleReset:R,setMessages:b,setIsLoading:u,selectedLang:i,currentBlock:E,fallbackLang:O,abortController:x,setAbortController:I,forceNewConversation:h,suggestNewConversation:z,selectedModel:g="google/gemini-2.5-flash",onModelChange:D})=>{const{t}=d.useTranslation(),y=r.useRef(null),p=d.useSelectedBlock(),v=d.useI18nBlocks(),F=d.useStreamMultipleBlocksProps(),M=()=>{var s;(s=y.current)==null||s.scrollIntoView({behavior:"smooth"})};r.useEffect(()=>{M()},[c,n]);const w=async(s,a,U)=>{var S;const N=(s==null?void 0:s.toLowerCase())==="translate",k={id:Date.now().toString(),role:"user",content:L.getTranslationUserPrompt({fallbackLang:O,userInput:a||s,language:i,blocks:N?v():v(i)}),userMessage:a||s||t("Translate the content")};u(!0);const _=new AbortController;I(_);const C={id:Date.now().toString(),role:"assistant",content:""};b(T=>[...T,k,C]),u(!0);try{const B=await q({body:{action:"ASK_AI",data:{messages:[k],initiator:N?"TRANSLATE_CONTENT":"UPDATE_CONTENT",model:U||g}},streamResponse:!0});if(!B.ok)throw new Error(t("Failed to get AI response"));const P=(S=B.body)==null?void 0:S.getReader(),H=new TextDecoder;let l="";if(!P)throw new Error(t("Response body is not readable"));for(;;){const{done:K,value:V}=await P.read();if(K)break;const W=H.decode(V,{stream:!0});l+=W,b(m=>(m[m.length-1].content=l,[...m]))}const J=JSON.parse(l==null?void 0:l.replace("```json","").replace("```",""));F(J)}catch{x==null||x.abort()}finally{u(!1),f("")}};return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"py-2",children:e.jsx(r.Suspense,{fallback:e.jsx("div",{children:t("Loading...")}),children:e.jsx(X,{isLoading:n,selectedBlock:p,selectedLang:i,onClick:w})})}),e.jsxs("div",{className:"flex-1 space-y-3 overflow-y-auto py-4",children:[c.length===0&&e.jsxs("div",{className:"flex-1 space-y-3 overflow-y-auto py-4",children:[e.jsxs("div",{className:"mx-auto mt-8 text-center text-gray-500",children:[e.jsx(j.Bot,{size:48,className:"mx-auto mb-4 text-gray-300"}),e.jsx("p",{className:"mx-auto max-w-[75%] text-sm",children:t("Start a conversation with the AI assistant to translate/edit your content")})]}),e.jsxs("div",{className:"relative rounded-lg border px-3 py-2 text-sm text-muted-foreground",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(j.InfoIcon,{className:"h-3 w-3"}),e.jsx("span",{className:"text-xs",children:t("Only content can be edited in secondary languages. To edit layout, styles and more, switch to the default language.")})]}),e.jsx("div",{className:"mt-1",children:e.jsx(G.LanguageSwitcher,{showAdd:!1,variant:"outline",goToDefaultLang:!0})})]})]}),c.map((s,a)=>s.role!=="system"&&e.jsx(r.Suspense,{fallback:e.jsx("div",{children:t("Loading...")}),children:e.jsx(Q,{message:s,isUser:s.role==="user",isLoading:s.role==="assistant"&&n&&a===c.length-1})},a)),z&&!n&&e.jsx("button",{onClick:R,className:"flex w-full items-center justify-center gap-2 rounded-lg border border-blue-200 bg-blue-50 p-1.5 text-left transition-colors hover:bg-blue-100",children:e.jsx("div",{className:"flex flex-col",children:e.jsxs("span",{className:"flex items-center gap-1 text-xs font-medium text-blue-700",children:[e.jsx(j.Plus,{className:"h-4 w-4 capitalize text-blue-600"}),h?t("Start "):""," ",t("New Conversation")," ",!h&&e.jsx("span",{className:"text-[10px] font-extralight text-blue-600",children:t("For best results")})]})})}),e.jsx("div",{ref:y})]}),!h&&e.jsx("div",{className:"border-gray-200 pb-2",children:e.jsx(r.Suspense,{fallback:e.jsx("div",{children:t("Loading...")}),children:e.jsx(Y,{input:o,setInput:f,onSend:w,onStop:A,isLoading:n,selectedLang:i,currentBlock:p||E,disabled:(o==null?void 0:o.length)===0,selectedModel:g,onModelChange:D})})})]})};exports.default=Z;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),G=require("./index-B1OACNv-.cjs"),d=require("@chaibuilder/sdk"),j=require("lucide-react"),r=require("react"),L=require("./prompt-helper-DIy7u3rt.cjs"),Q=r.lazy(()=>Promise.resolve().then(()=>require("./ai-panel-message-bubble-Bl-aUeU4.cjs"))),X=r.lazy(()=>Promise.resolve().then(()=>require("./ai-translation-prompt-DH7gwfqx.cjs"))),Y=r.lazy(()=>Promise.resolve().then(()=>require("./ai-prompt-input-CffQQOKA.cjs"))),Z=({fetch:q,input:o,messages:c,setInput:f,isLoading:n,handleStop:A,handleReset:R,setMessages:b,setIsLoading:u,selectedLang:i,currentBlock:E,fallbackLang:O,abortController:x,setAbortController:I,forceNewConversation:h,suggestNewConversation:z,selectedModel:g="google/gemini-2.5-flash",onModelChange:D})=>{const{t}=d.useTranslation(),y=r.useRef(null),p=d.useSelectedBlock(),v=d.useI18nBlocks(),F=d.useStreamMultipleBlocksProps(),M=()=>{var s;(s=y.current)==null||s.scrollIntoView({behavior:"smooth"})};r.useEffect(()=>{M()},[c,n]);const w=async(s,a,U)=>{var S;const N=(s==null?void 0:s.toLowerCase())==="translate",k={id:Date.now().toString(),role:"user",content:L.getTranslationUserPrompt({fallbackLang:O,userInput:a||s,language:i,blocks:N?v():v(i)}),userMessage:a||s||t("Translate the content")};u(!0);const _=new AbortController;I(_);const C={id:Date.now().toString(),role:"assistant",content:""};b(T=>[...T,k,C]),u(!0);try{const B=await q({body:{action:"ASK_AI",data:{messages:[k],initiator:N?"TRANSLATE_CONTENT":"UPDATE_CONTENT",model:U||g}},streamResponse:!0});if(!B.ok)throw new Error(t("Failed to get AI response"));const P=(S=B.body)==null?void 0:S.getReader(),H=new TextDecoder;let l="";if(!P)throw new Error(t("Response body is not readable"));for(;;){const{done:K,value:V}=await P.read();if(K)break;const W=H.decode(V,{stream:!0});l+=W,b(m=>(m[m.length-1].content=l,[...m]))}const J=JSON.parse(l==null?void 0:l.replace("```json","").replace("```",""));F(J)}catch{x==null||x.abort()}finally{u(!1),f("")}};return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"py-2",children:e.jsx(r.Suspense,{fallback:e.jsx("div",{children:t("Loading...")}),children:e.jsx(X,{isLoading:n,selectedBlock:p,selectedLang:i,onClick:w})})}),e.jsxs("div",{className:"flex-1 space-y-3 overflow-y-auto py-4",children:[c.length===0&&e.jsxs("div",{className:"flex-1 space-y-3 overflow-y-auto py-4",children:[e.jsxs("div",{className:"mx-auto mt-8 text-center text-gray-500",children:[e.jsx(j.Bot,{size:48,className:"mx-auto mb-4 text-gray-300"}),e.jsx("p",{className:"mx-auto max-w-[75%] text-sm",children:t("Start a conversation with the AI assistant to translate/edit your content")})]}),e.jsxs("div",{className:"relative rounded-lg border px-3 py-2 text-sm text-muted-foreground",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(j.InfoIcon,{className:"h-3 w-3"}),e.jsx("span",{className:"text-xs",children:t("Only content can be edited in secondary languages. To edit layout, styles and more, switch to the default language.")})]}),e.jsx("div",{className:"mt-1",children:e.jsx(G.LanguageSwitcher,{showAdd:!1,variant:"outline",goToDefaultLang:!0})})]})]}),c.map((s,a)=>s.role!=="system"&&e.jsx(r.Suspense,{fallback:e.jsx("div",{children:t("Loading...")}),children:e.jsx(Q,{message:s,isUser:s.role==="user",isLoading:s.role==="assistant"&&n&&a===c.length-1})},a)),z&&!n&&e.jsx("button",{onClick:R,className:"flex w-full items-center justify-center gap-2 rounded-lg border border-blue-200 bg-blue-50 p-1.5 text-left transition-colors hover:bg-blue-100",children:e.jsx("div",{className:"flex flex-col",children:e.jsxs("span",{className:"flex items-center gap-1 text-xs font-medium text-blue-700",children:[e.jsx(j.Plus,{className:"h-4 w-4 capitalize text-blue-600"}),h?t("Start "):""," ",t("New Conversation")," ",!h&&e.jsx("span",{className:"text-[10px] font-extralight text-blue-600",children:t("For best results")})]})})}),e.jsx("div",{ref:y})]}),!h&&e.jsx("div",{className:"border-gray-200 pb-2",children:e.jsx(r.Suspense,{fallback:e.jsx("div",{children:t("Loading...")}),children:e.jsx(Y,{input:o,setInput:f,onSend:w,onStop:A,isLoading:n,selectedLang:i,currentBlock:p||E,disabled:(o==null?void 0:o.length)===0,selectedModel:g,onModelChange:D})})})]})};exports.default=Z;
@@ -1,10 +1,10 @@
1
1
  import { jsxs as a, Fragment as H, jsx as e } from "react/jsx-runtime";
2
- import { aj as L } from "./index-DRQI9rlW.js";
2
+ import { aj as L } from "./index-DdQbaicX.js";
3
3
  import { useTranslation as Q, useSelectedBlock as X, useI18nBlocks as Y, useStreamMultipleBlocksProps as Z } from "@chaibuilder/sdk";
4
4
  import { Bot as $, InfoIcon as ee, Plus as te } from "lucide-react";
5
5
  import { lazy as g, useRef as se, useEffect as ae, Suspense as f } from "react";
6
- import { g as oe } from "./prompt-helper-Bh7WyDYo.js";
7
- const re = g(() => import("./ai-panel-message-bubble-DPAaAMAZ.js")), ne = g(() => import("./ai-translation-prompt--HB1UAhC.js")), le = g(() => import("./ai-prompt-input-qegCvwnu.js")), fe = ({
6
+ import { g as oe } from "./prompt-helper-D0QRFyFX.js";
7
+ const re = g(() => import("./ai-panel-message-bubble-DPAaAMAZ.js")), ne = g(() => import("./ai-translation-prompt-B8VdHfLY.js")), le = g(() => import("./ai-prompt-input-C3TnCYfz.js")), fe = ({
8
8
  fetch: P,
9
9
  input: l,
10
10
  messages: c,
@@ -2,7 +2,7 @@ import { jsxs as s, Fragment as d, jsx as a } from "react/jsx-runtime";
2
2
  import { useTranslation as h, mergeClasses as c } from "@chaibuilder/sdk";
3
3
  import { ChevronsUpDown as f } from "lucide-react";
4
4
  import { useState as x } from "react";
5
- import { L as N, U as w, A as g } from "./prompt-helper-Bh7WyDYo.js";
5
+ import { L as N, U as w, A as g } from "./prompt-helper-D0QRFyFX.js";
6
6
  const E = ({ onSelect: p, currentBlock: e, selectedLang: r }) => {
7
7
  const { t } = h(), [o, i] = x(!1), l = r ? N : e ? w : g;
8
8
  return /* @__PURE__ */ s(d, { children: [
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),l=require("@chaibuilder/sdk"),m=require("lucide-react"),x=require("react"),r=require("./prompt-helper-BLBZjr5q.cjs"),u=({onSelect:p,currentBlock:s,selectedLang:a})=>{const{t}=l.useTranslation(),[i,o]=x.useState(!1),c=a?r.LANGUAGE_CONTENT_ACTIONS:s?r.UPDATE_ACTIONS:r.ADD_NEW_SECTIONS;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{onClick:()=>o(!i),className:l.mergeClasses("flex h-6 w-full cursor-pointer items-center justify-between gap-2 px-2",s?"bg-green-50/80 text-green-500 hover:bg-green-50":"bg-primary/5 text-primary hover:bg-primary/10"),children:[e.jsx("span",{className:"truncate whitespace-nowrap text-xs font-medium leading-none",children:s?e.jsxs("span",{children:[e.jsx("span",{className:"font-extralight",children:t(a?"Edit Content:":"Edit:")})," ",s._name||s._type]}):t("Quick Prompts")}),e.jsx(m.ChevronsUpDown,{className:"h-3 w-3"})]}),i&&e.jsx("div",{className:"max-h-60 w-full overflow-y-auto bg-white px-1 pb-1",children:c.map((n,d)=>e.jsx("div",{className:"flex cursor-pointer items-center gap-x-1 p-1 text-xs leading-none hover:text-blue-700",onClick:()=>{p(`${t(a||s?"Update":"Add New")} ${n.label}`,n.prompt),o(!1)},children:e.jsxs("span",{className:"truncate whitespace-nowrap",children:[s?null:e.jsx("span",{className:"font-thin text-muted-foreground",children:t("Add New")})," ",n.label]})},d))})]})};exports.default=u;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),l=require("@chaibuilder/sdk"),m=require("lucide-react"),x=require("react"),r=require("./prompt-helper-DIy7u3rt.cjs"),u=({onSelect:p,currentBlock:s,selectedLang:a})=>{const{t}=l.useTranslation(),[i,o]=x.useState(!1),c=a?r.LANGUAGE_CONTENT_ACTIONS:s?r.UPDATE_ACTIONS:r.ADD_NEW_SECTIONS;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{onClick:()=>o(!i),className:l.mergeClasses("flex h-6 w-full cursor-pointer items-center justify-between gap-2 px-2",s?"bg-green-50/80 text-green-500 hover:bg-green-50":"bg-primary/5 text-primary hover:bg-primary/10"),children:[e.jsx("span",{className:"truncate whitespace-nowrap text-xs font-medium leading-none",children:s?e.jsxs("span",{children:[e.jsx("span",{className:"font-extralight",children:t(a?"Edit Content:":"Edit:")})," ",s._name||s._type]}):t("Quick Prompts")}),e.jsx(m.ChevronsUpDown,{className:"h-3 w-3"})]}),i&&e.jsx("div",{className:"max-h-60 w-full overflow-y-auto bg-white px-1 pb-1",children:c.map((n,d)=>e.jsx("div",{className:"flex cursor-pointer items-center gap-x-1 p-1 text-xs leading-none hover:text-blue-700",onClick:()=>{p(`${t(a||s?"Update":"Add New")} ${n.label}`,n.prompt),o(!1)},children:e.jsxs("span",{className:"truncate whitespace-nowrap",children:[s?null:e.jsx("span",{className:"font-thin text-muted-foreground",children:t("Add New")})," ",n.label]})},d))})]})};exports.default=u;
@@ -77,7 +77,7 @@ const b = [
77
77
  a.id
78
78
  )) })
79
79
  ] });
80
- }, J = q(() => import("./ai-panel-quick-prompts-BPrA9nvg.js")), I = "chai-ai-selected-model", ae = ({
80
+ }, J = q(() => import("./ai-panel-quick-prompts-BfMsNuRu.js")), I = "chai-ai-selected-model", ae = ({
81
81
  input: r,
82
82
  setInput: c,
83
83
  onSend: d,
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),z=require("@chaibuilder/sdk"),d=require("lucide-react"),l=require("react"),g=require("@chaibuilder/sdk/ui"),v=[{id:"google/gemini-2.5-flash",name:"Gemini 2.5 Flash",creditsPer1000Tokens:1},{id:"openai/gpt-5",name:"GPT-5",creditsPer1000Tokens:3},{id:"openai/gpt-4o",name:"GPT-4o",creditsPer1000Tokens:2.5},{id:"anthropic/claude-3-5-haiku-20241022",name:"Haiku 4.5",creditsPer1000Tokens:1.5},{id:"anthropic/claude-3-5-sonnet-20241022",name:"Sonnet 4.5",creditsPer1000Tokens:2.8},{id:"anthropic/claude-3-5-sonnet-20240620",name:"Sonnet 4",creditsPer1000Tokens:2.5},{id:"google/gemini-pro",name:"Gemini Pro",creditsPer1000Tokens:1.2},{id:"xai/grok-4",name:"Grok 4",creditsPer1000Tokens:2.2}],K=s=>`${Math.ceil(s)}x`,O=({selectedModel:s,onModelChange:c,disabled:m})=>{const b=v.find(r=>r.id===s)||v[0],a=r=>{c(r)};return e.jsxs(g.DropdownMenu,{children:[e.jsx(g.DropdownMenuTrigger,{asChild:!0,children:e.jsxs("button",{type:"button",disabled:m,className:`flex !hidden items-center gap-1 rounded border border-gray-200 bg-white px-2 py-1 text-xs transition-colors ${m?"cursor-not-allowed opacity-50":"cursor-pointer hover:border-gray-300"}`,children:[e.jsx(d.Zap,{className:"h-3 w-3 text-blue-500"}),e.jsx("span",{className:"max-w-20 truncate font-medium",children:b.name})]})}),e.jsx(g.DropdownMenuContent,{className:"w-64",align:"start",children:v.map(r=>e.jsxs(g.DropdownMenuItem,{onClick:()=>a(r.id),className:`flex items-center justify-between ${s===r.id?"bg-blue-50":""}`,children:[e.jsx("span",{className:"text-sm font-medium",children:r.name}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(d.Zap,{className:"h-3 w-3 text-blue-500"}),e.jsx("span",{className:"text-xs font-medium text-gray-700",children:K(r.creditsPer1000Tokens)})]})]},r.id))})]})},_=l.lazy(()=>Promise.resolve().then(()=>require("./ai-panel-quick-prompts-BGBdrdP7.cjs"))),T="chai-ai-selected-model",C=({input:s,setInput:c,onSend:m,onStop:b,isLoading:a,disabled:r,currentBlock:w,selectedLang:n,selectedModel:R="google/gemini-2.5-flash",onModelChange:o})=>{const{t:i}=z.useTranslation(),f=l.useRef(null),y=l.useRef(null),[u,p]=l.useState(null),[j,k]=l.useState(R);l.useEffect(()=>{if(!n){const t=localStorage.getItem(T);t&&(k(t),o==null||o(t))}},[n,o]);const D=t=>{k(t),o==null||o(t),n||localStorage.setItem(T,t)},A=t=>{t.key==="Enter"&&!t.shiftKey&&(t.preventDefault(),s.trim()&&!a&&(m(s==null?void 0:s.trim(),void 0,u||void 0,j),p(null)))},I=()=>{const t=f.current;t&&(t.style.height="auto",t.style.height=Math.min(t.scrollHeight,120)+"px")},M=t=>{var h;const x=(h=t.target.files)==null?void 0:h[0];if(x&&x.type.startsWith("image/")){const N=new FileReader;N.onload=G=>{var S,P;const $=(S=G.target)==null?void 0:S.result;p($),c(i("Generate UI based on given image ")),(P=f.current)==null||P.focus()},N.readAsDataURL(x)}t.target.value=""},q=()=>{var t;(t=y.current)==null||t.click()},E=()=>{m(s==null?void 0:s.trim(),void 0,u||void 0,j),p(null)};return l.useEffect(()=>{I()},[s]),e.jsxs("div",{className:"relative",children:[!u&&!(n&&!w)&&e.jsx("div",{className:`mx-auto flex w-full max-w-[95%] flex-col items-center overflow-hidden rounded-t-md border-x border-t border-gray-200 ${a?"pointer-events-none opacity-50":""}`,children:e.jsx(_,{currentBlock:w,selectedLang:n,onSelect:(t,x)=>{var h;c(x+" "),(h=f.current)==null||h.focus()}})}),e.jsxs("div",{className:"rounded-lg border border-gray-200 bg-white",children:[u&&e.jsxs("div",{className:"relative flex w-max items-center justify-start gap-x-2 px-2 pt-2",children:[e.jsx("img",{src:u,alt:"Selected attachment",className:"max-h-16 max-w-full rounded-md border"}),e.jsx("button",{onClick:()=>p(null),className:"absolute -right-0 -top-0 flex items-center rounded-full bg-red-400 p-1 text-xs text-white hover:bg-red-500",title:i("Remove image"),children:e.jsx(d.X,{className:"h-2 w-2"})})]}),e.jsx("textarea",{ref:f,value:s,onChange:t=>c(t.target.value),onKeyDown:A,placeholder:i(n?"Ask to update content":"Ask me anything..."),className:`max-h-[200px] min-h-[60px] w-full resize-none rounded-lg border-none px-3 py-2 text-sm outline-none ${a?"cursor-not-allowed opacity-50":""}`,rows:3,disabled:a}),e.jsxs("div",{className:"flex items-center justify-between p-2",children:[n?e.jsx("div",{}):e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{disabled:a,onClick:q,className:`p-1.5 text-gray-400 hover:text-gray-500 ${a||n?"cursor-not-allowed opacity-50":""}`,title:i("Attach Image"),children:e.jsx(d.Paperclip,{size:16})}),e.jsx(O,{selectedModel:j,onModelChange:D,disabled:a})]}),e.jsx("input",{disabled:a,ref:y,type:"file",accept:"image/*",onChange:M,className:"hidden"}),a?e.jsxs("button",{onClick:b,className:"z-50 flex items-center gap-x-1 rounded-md bg-red-500 p-1.5 text-white transition-colors hover:bg-red-600",title:i("Stop generation"),children:[e.jsx(d.Square,{size:16})," ",e.jsx("span",{className:"text-xs",children:i("Stop")})]}):e.jsx("button",{onClick:E,disabled:!s.trim()||r,className:`rounded-md bg-blue-500 p-1.5 text-white ${!s.trim()||r?"cursor-not-allowed opacity-50":"transition-colors hover:bg-blue-600"}`,children:e.jsx(d.Send,{size:16})})]})]})]})};exports.default=C;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),z=require("@chaibuilder/sdk"),d=require("lucide-react"),l=require("react"),g=require("@chaibuilder/sdk/ui"),v=[{id:"google/gemini-2.5-flash",name:"Gemini 2.5 Flash",creditsPer1000Tokens:1},{id:"openai/gpt-5",name:"GPT-5",creditsPer1000Tokens:3},{id:"openai/gpt-4o",name:"GPT-4o",creditsPer1000Tokens:2.5},{id:"anthropic/claude-3-5-haiku-20241022",name:"Haiku 4.5",creditsPer1000Tokens:1.5},{id:"anthropic/claude-3-5-sonnet-20241022",name:"Sonnet 4.5",creditsPer1000Tokens:2.8},{id:"anthropic/claude-3-5-sonnet-20240620",name:"Sonnet 4",creditsPer1000Tokens:2.5},{id:"google/gemini-pro",name:"Gemini Pro",creditsPer1000Tokens:1.2},{id:"xai/grok-4",name:"Grok 4",creditsPer1000Tokens:2.2}],K=s=>`${Math.ceil(s)}x`,O=({selectedModel:s,onModelChange:c,disabled:m})=>{const b=v.find(r=>r.id===s)||v[0],a=r=>{c(r)};return e.jsxs(g.DropdownMenu,{children:[e.jsx(g.DropdownMenuTrigger,{asChild:!0,children:e.jsxs("button",{type:"button",disabled:m,className:`flex !hidden items-center gap-1 rounded border border-gray-200 bg-white px-2 py-1 text-xs transition-colors ${m?"cursor-not-allowed opacity-50":"cursor-pointer hover:border-gray-300"}`,children:[e.jsx(d.Zap,{className:"h-3 w-3 text-blue-500"}),e.jsx("span",{className:"max-w-20 truncate font-medium",children:b.name})]})}),e.jsx(g.DropdownMenuContent,{className:"w-64",align:"start",children:v.map(r=>e.jsxs(g.DropdownMenuItem,{onClick:()=>a(r.id),className:`flex items-center justify-between ${s===r.id?"bg-blue-50":""}`,children:[e.jsx("span",{className:"text-sm font-medium",children:r.name}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(d.Zap,{className:"h-3 w-3 text-blue-500"}),e.jsx("span",{className:"text-xs font-medium text-gray-700",children:K(r.creditsPer1000Tokens)})]})]},r.id))})]})},_=l.lazy(()=>Promise.resolve().then(()=>require("./ai-panel-quick-prompts-CGKAAn9A.cjs"))),T="chai-ai-selected-model",C=({input:s,setInput:c,onSend:m,onStop:b,isLoading:a,disabled:r,currentBlock:w,selectedLang:n,selectedModel:R="google/gemini-2.5-flash",onModelChange:o})=>{const{t:i}=z.useTranslation(),f=l.useRef(null),y=l.useRef(null),[u,p]=l.useState(null),[j,k]=l.useState(R);l.useEffect(()=>{if(!n){const t=localStorage.getItem(T);t&&(k(t),o==null||o(t))}},[n,o]);const D=t=>{k(t),o==null||o(t),n||localStorage.setItem(T,t)},A=t=>{t.key==="Enter"&&!t.shiftKey&&(t.preventDefault(),s.trim()&&!a&&(m(s==null?void 0:s.trim(),void 0,u||void 0,j),p(null)))},I=()=>{const t=f.current;t&&(t.style.height="auto",t.style.height=Math.min(t.scrollHeight,120)+"px")},M=t=>{var h;const x=(h=t.target.files)==null?void 0:h[0];if(x&&x.type.startsWith("image/")){const N=new FileReader;N.onload=G=>{var S,P;const $=(S=G.target)==null?void 0:S.result;p($),c(i("Generate UI based on given image ")),(P=f.current)==null||P.focus()},N.readAsDataURL(x)}t.target.value=""},q=()=>{var t;(t=y.current)==null||t.click()},E=()=>{m(s==null?void 0:s.trim(),void 0,u||void 0,j),p(null)};return l.useEffect(()=>{I()},[s]),e.jsxs("div",{className:"relative",children:[!u&&!(n&&!w)&&e.jsx("div",{className:`mx-auto flex w-full max-w-[95%] flex-col items-center overflow-hidden rounded-t-md border-x border-t border-gray-200 ${a?"pointer-events-none opacity-50":""}`,children:e.jsx(_,{currentBlock:w,selectedLang:n,onSelect:(t,x)=>{var h;c(x+" "),(h=f.current)==null||h.focus()}})}),e.jsxs("div",{className:"rounded-lg border border-gray-200 bg-white",children:[u&&e.jsxs("div",{className:"relative flex w-max items-center justify-start gap-x-2 px-2 pt-2",children:[e.jsx("img",{src:u,alt:"Selected attachment",className:"max-h-16 max-w-full rounded-md border"}),e.jsx("button",{onClick:()=>p(null),className:"absolute -right-0 -top-0 flex items-center rounded-full bg-red-400 p-1 text-xs text-white hover:bg-red-500",title:i("Remove image"),children:e.jsx(d.X,{className:"h-2 w-2"})})]}),e.jsx("textarea",{ref:f,value:s,onChange:t=>c(t.target.value),onKeyDown:A,placeholder:i(n?"Ask to update content":"Ask me anything..."),className:`max-h-[200px] min-h-[60px] w-full resize-none rounded-lg border-none px-3 py-2 text-sm outline-none ${a?"cursor-not-allowed opacity-50":""}`,rows:3,disabled:a}),e.jsxs("div",{className:"flex items-center justify-between p-2",children:[n?e.jsx("div",{}):e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{disabled:a,onClick:q,className:`p-1.5 text-gray-400 hover:text-gray-500 ${a||n?"cursor-not-allowed opacity-50":""}`,title:i("Attach Image"),children:e.jsx(d.Paperclip,{size:16})}),e.jsx(O,{selectedModel:j,onModelChange:D,disabled:a})]}),e.jsx("input",{disabled:a,ref:y,type:"file",accept:"image/*",onChange:M,className:"hidden"}),a?e.jsxs("button",{onClick:b,className:"z-50 flex items-center gap-x-1 rounded-md bg-red-500 p-1.5 text-white transition-colors hover:bg-red-600",title:i("Stop generation"),children:[e.jsx(d.Square,{size:16})," ",e.jsx("span",{className:"text-xs",children:i("Stop")})]}):e.jsx("button",{onClick:E,disabled:!s.trim()||r,className:`rounded-md bg-blue-500 p-1.5 text-white ${!s.trim()||r?"cursor-not-allowed opacity-50":"transition-colors hover:bg-blue-600"}`,children:e.jsx(d.Send,{size:16})})]})]})]})};exports.default=C;
@@ -1,5 +1,5 @@
1
1
  import { jsx as t, jsxs as l } from "react/jsx-runtime";
2
- import { L as r } from "./index-DRQI9rlW.js";
2
+ import { L as r } from "./index-DdQbaicX.js";
3
3
  import { useTranslation as i } from "@chaibuilder/sdk";
4
4
  import { Button as c } from "@chaibuilder/sdk/ui";
5
5
  import { ArrowRight as m } from "lucide-react";
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),a=require("./index-CyHmr87X.cjs"),c=require("@chaibuilder/sdk"),r=require("@chaibuilder/sdk/ui"),o=require("lucide-react"),x=({selectedLang:s,isLoading:n,selectedBlock:l,onClick:i})=>{const{t}=c.useTranslation();return e.jsx("div",{className:"flex flex-col gap-2",children:e.jsx("div",{className:`flex flex-col gap-2 ${n?"pointer-events-none opacity-50":""}`,children:l?e.jsx(r.Button,{variant:"outline",className:"h-auto",onClick:()=>i("TRANSLATE"),children:e.jsxs("div",{className:"flex flex-col",children:[e.jsx("p",{className:"text-left text-xs font-thin",children:t("Quick Action:")}),e.jsxs("span",{className:"flex items-center gap-x-2 text-sm font-medium",children:[t("Translate Content")," ",t("to")," ",a.LANGUAGES[s]," ",e.jsx(o.ArrowRight,{className:"h-4 w-4"})]})]})}):null})})};exports.default=x;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),a=require("./index-B1OACNv-.cjs"),c=require("@chaibuilder/sdk"),r=require("@chaibuilder/sdk/ui"),o=require("lucide-react"),x=({selectedLang:s,isLoading:n,selectedBlock:l,onClick:i})=>{const{t}=c.useTranslation();return e.jsx("div",{className:"flex flex-col gap-2",children:e.jsx("div",{className:`flex flex-col gap-2 ${n?"pointer-events-none opacity-50":""}`,children:l?e.jsx(r.Button,{variant:"outline",className:"h-auto",onClick:()=>i("TRANSLATE"),children:e.jsxs("div",{className:"flex flex-col",children:[e.jsx("p",{className:"text-left text-xs font-thin",children:t("Quick Action:")}),e.jsxs("span",{className:"flex items-center gap-x-2 text-sm font-medium",children:[t("Translate Content")," ",t("to")," ",a.LANGUAGES[s]," ",e.jsx(o.ArrowRight,{className:"h-4 w-4"})]})]})}):null})})};exports.default=x;
@@ -1,5 +1,5 @@
1
1
  import { jsx as i, jsxs as r } from "react/jsx-runtime";
2
- import { i as f, m as w, h as y, L as S } from "./index-DRQI9rlW.js";
2
+ import { i as f, m as w, h as y, L as S } from "./index-DdQbaicX.js";
3
3
  import { useTranslation as v, useLanguages as L, useSidebarActivePanel as x } from "@chaibuilder/sdk";
4
4
  import { Dialog as A, DialogContent as k, DialogHeader as C, DialogTitle as N, DialogDescription as g, DialogFooter as E, Button as c } from "@chaibuilder/sdk/ui";
5
5
  import { get as U } from "lodash-es";
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react/jsx-runtime"),r=require("./index-CyHmr87X.cjs"),c=require("@chaibuilder/sdk"),s=require("@chaibuilder/sdk/ui"),y=require("lodash-es");function S({page:e,onClose:l}){const{t}=c.useTranslation(),[,d]=r.useSearchParams(),{mutate:u,isPending:a}=r.useDeletePage(),{data:o}=r.usePageTypes(),{setSelectedLang:h,fallbackLang:m}=c.useLanguages(),[,x]=c.useSidebarActivePanel(),P=()=>{a||u(e,{onSuccess:()=>{e!=null&&e.primaryPage?(window.history.replaceState({},"",`/?page=${e.primaryPage}`),d(new URLSearchParams({page:e.primaryPage}))):(window.history.replaceState({},"","/"),d(new URLSearchParams)),window.dispatchEvent(new PopStateEvent("popstate")),h(m),x("outline"),l()}})},i=o==null?void 0:o.find(D=>D.key===(e==null?void 0:e.pageType));return n.jsx(s.Dialog,{open:!!e,onOpenChange:l,children:n.jsxs(s.DialogContent,{children:[n.jsxs(s.DialogHeader,{children:[n.jsx(s.DialogTitle,{children:t("Confirm Deletion")}),n.jsxs(s.DialogDescription,{className:"py-4 text-slate-500",children:[n.jsxs("div",{children:[t("Are you sure you want to remove")," ",n.jsx("b",{children:(e==null?void 0:e.name)??(e==null?void 0:e.slug)})," ",i!=null&&i.hasSlug?(i==null?void 0:i.name)+"?":`${t("page?")} ${e!=null&&e.primaryPage?"":t("This will also delete all associated language pages.")}`]}),e.lang&&n.jsxs("div",{className:"py-2 text-sm",children:[t("Language"),": ",n.jsx("span",{className:"font-medium text-gray-500",children:y.get(r.LANGUAGES,e.lang,e.lang)})]})]})]}),n.jsxs(s.DialogFooter,{children:[n.jsx(s.Button,{variant:"outline",onClick:l,children:t("Cancel")}),n.jsx(s.Button,{variant:"destructive",disabled:a,onClick:P,children:t(a?"Deleting...":"Delete")})]})]})})}exports.default=S;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react/jsx-runtime"),r=require("./index-B1OACNv-.cjs"),c=require("@chaibuilder/sdk"),s=require("@chaibuilder/sdk/ui"),y=require("lodash-es");function S({page:e,onClose:l}){const{t}=c.useTranslation(),[,d]=r.useSearchParams(),{mutate:u,isPending:a}=r.useDeletePage(),{data:o}=r.usePageTypes(),{setSelectedLang:h,fallbackLang:m}=c.useLanguages(),[,x]=c.useSidebarActivePanel(),P=()=>{a||u(e,{onSuccess:()=>{e!=null&&e.primaryPage?(window.history.replaceState({},"",`/?page=${e.primaryPage}`),d(new URLSearchParams({page:e.primaryPage}))):(window.history.replaceState({},"","/"),d(new URLSearchParams)),window.dispatchEvent(new PopStateEvent("popstate")),h(m),x("outline"),l()}})},i=o==null?void 0:o.find(D=>D.key===(e==null?void 0:e.pageType));return n.jsx(s.Dialog,{open:!!e,onOpenChange:l,children:n.jsxs(s.DialogContent,{children:[n.jsxs(s.DialogHeader,{children:[n.jsx(s.DialogTitle,{children:t("Confirm Deletion")}),n.jsxs(s.DialogDescription,{className:"py-4 text-slate-500",children:[n.jsxs("div",{children:[t("Are you sure you want to remove")," ",n.jsx("b",{children:(e==null?void 0:e.name)??(e==null?void 0:e.slug)})," ",i!=null&&i.hasSlug?(i==null?void 0:i.name)+"?":`${t("page?")} ${e!=null&&e.primaryPage?"":t("This will also delete all associated language pages.")}`]}),e.lang&&n.jsxs("div",{className:"py-2 text-sm",children:[t("Language"),": ",n.jsx("span",{className:"font-medium text-gray-500",children:y.get(r.LANGUAGES,e.lang,e.lang)})]})]})]}),n.jsxs(s.DialogFooter,{children:[n.jsx(s.Button,{variant:"outline",onClick:l,children:t("Cancel")}),n.jsx(s.Button,{variant:"destructive",disabled:a,onClick:P,children:t(a?"Deleting...":"Delete")})]})]})})}exports.default=S;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),M=require("@chaibuilder/sdk"),a=require("@chaibuilder/sdk/ui"),F=require("lodash-es"),f=require("lucide-react"),u=require("react"),fe=require("react-dropzone"),g=require("./index-CyHmr87X.cjs"),w=require("sonner"),Y=require("./image-compression-DZ9WMmyn.cjs"),z=require("@tanstack/react-query"),pe=()=>{const n=g.useAssetsApiUrl(),r=z.useQueryClient(),x=g.useFetch();return z.useMutation({mutationFn:async i=>{const o=i.map(async l=>x(n,{action:g.ACTIONS.UPLOAD_ASSET,data:l}));return await Promise.all(o)},onSuccess:i=>{var o;if(i!=null&&i.some(s=>s.error))throw new Error(((o=i==null?void 0:i.find(s=>s.error))==null?void 0:o.error)||"Failed to upload asset");{r.invalidateQueries({queryKey:[g.ACTIONS.GET_ASSETS]});const s=i==null?void 0:i.length;w.toast.success(`${s===1?"Asset":s+" Assets"} uploaded successfully`)}},onError:()=>{w.toast.error("Failed to upload asset")}})},ge=()=>{const n=g.useAssetsApiUrl(),r=z.useQueryClient(),x=g.useFetch();return z.useMutation({mutationFn:async i=>x(n,{action:g.ACTIONS.DELETE_ASSET,data:{id:i}}),onSuccess:i=>{if(i!=null&&i.error)throw new Error(i==null?void 0:i.error);r.invalidateQueries({queryKey:[g.ACTIONS.GET_ASSETS]}),w.toast.success("Asset deleted successfully")},onError:()=>{w.toast.error("Failed to delete asset")}})},je=()=>{const n=g.useAssetsApiUrl(),r=z.useQueryClient(),x=g.useFetch();return z.useMutation({mutationFn:async i=>x(n,{action:g.ACTIONS.UPDATE_ASSET,data:i}),onSuccess:i=>{if(i!=null&&i.error)throw new Error(i==null?void 0:i.error);r.invalidateQueries({queryKey:[g.ACTIONS.GET_ASSETS]}),i!=null&&i.id&&r.invalidateQueries({queryKey:[g.ACTIONS.GET_ASSET,i.id]}),w.toast.success("Asset updated successfully")},onError:()=>{w.toast.error("Failed to update asset")}})};function ve({currentPage:n,totalPages:r,onPageChange:x,pageRangeDisplayed:i=3,showPageInput:o=!0,className:s=""}){const[l,E]=u.useState(String(n)),N=u.useMemo(()=>{const c=Math.floor(i/2);let m=Math.max(1,n-c),d=Math.min(r,n+c);d-m+1<i&&(m===1?d=Math.min(r,m+i-1):d===r&&(m=Math.max(1,d-i+1)));const p=[];m>1&&(p.push(1),m>2&&p.push("..."));for(let y=m;y<=d;y++)p.push(y);return d<r&&(d<r-1&&p.push("..."),p.push(r)),p},[n,r,i]),v=c=>{c!==n&&c>=1&&c<=r&&(x(c),E(String(c)))},j=()=>{n>1&&v(n-1)},b=()=>{n<r&&v(n+1)},C=()=>{const c=Number(l);!isNaN(c)&&c>=1&&c<=r&&v(c)},A=c=>{c.key==="Enter"&&C()};return r<=1?null:e.jsxs("div",{className:`flex flex-wrap items-center justify-center gap-3 ${s}`,children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(a.Button,{variant:"outline",size:"sm",onClick:j,disabled:n===1,className:"px-2 py-1 text-sm hover:bg-gray-50",children:[e.jsx(f.ChevronLeft,{className:" h-4 w-4"}),"Previous"]}),e.jsx("div",{className:"flex items-center gap-2",children:N.map((c,m)=>{if(c==="...")return e.jsx("span",{className:"px-2 text-muted-foreground",children:"..."},`ellipsis-${m}`);const d=c,p=d===n;return e.jsx(a.Button,{variant:p?"default":"outline",size:"sm",onClick:()=>v(d),className:p?"border-blue-600 bg-blue-600 px-3 py-1 text-sm text-white":"border px-3 py-1 text-sm hover:bg-gray-50 hover:text-black",children:d},d)})}),e.jsxs(a.Button,{variant:"outline",size:"sm",onClick:b,disabled:n===r,className:"px-2 py-1 text-sm hover:bg-gray-50",children:["Next",e.jsx(f.ChevronRight,{className:" h-4 w-4"})]})]}),o&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:"Go to"}),e.jsx(a.Input,{type:"number",min:1,max:r,value:l,onChange:c=>{const m=c.target.value.replace(/[^\d]/g,"");E(m)},onKeyDown:A,className:"h-8 w-16 px-2 py-1"}),e.jsx(a.Button,{variant:"outline",size:"sm",onClick:C,disabled:l===""||Number(l)<1||Number(l)>r,children:"Go"})]})]})}const ye=(n={})=>{const r=g.useAssetsApiUrl(),x=g.useFetch(),{search:i,page:o=1,limit:s=30}=n;return z.useQuery({queryKey:[g.ACTIONS.GET_ASSETS,i,o,s],queryFn:async()=>{const l=await x(r,{action:g.ACTIONS.GET_ASSETS,data:{search:i,page:o,limit:s}});return l.page=o,l.limit=s,l},staleTime:1/0,retry:1})},Ne=n=>{const r=g.useAssetsApiUrl(),x=g.useFetch();return z.useQuery({queryKey:[g.ACTIONS.GET_ASSET,n],queryFn:async()=>n?await x(r,{action:g.ACTIONS.GET_ASSET,data:{id:n}}):null,staleTime:1/0,retry:1})};function be(n){const r=isNaN(n)?0:typeof n=="number"?n:parseInt(n);return r?r<1024?`${r.toFixed(2)} B`:r<1024*1024?`${(r/1024).toFixed(2)} KB`:`${(r/(1024*1024)).toFixed(2)} MB`:"0 B"}function Z(n){if(!n)return"N/A";const r=new Date(n);return new Intl.DateTimeFormat("en-US",{month:"short",day:"numeric",year:"numeric",hour:"2-digit",minute:"2-digit"}).format(r)}function J(n,r){let x=n,i=r==null?void 0:r.description;return(!i||typeof i!="string")&&(i=""),(!x||typeof x!="string")&&(x=""),x!==i}const we=({assetId:n,onBack:r,onEdit:x,onSave:i,isSaving:o})=>{var c,m;const{t:s}=M.useTranslation(),{data:l,isLoading:E,isError:N}=Ne(n||""),[v,j]=u.useState(""),[b,C]=u.useState(!1);u.useEffect(()=>{const d=new Image;return d.src=(l==null?void 0:l.url)||"",d.onload=()=>C(!0),()=>{d.onload=null}},[l]);const A=async(d,p)=>{try{await navigator.clipboard.writeText(d),w.toast.success(s("{{type}} copied to clipboard",{type:p}))}catch(y){w.toast.error(s("Failed to copy {{type}}",{type:p}),{description:y==null?void 0:y.message})}};return u.useEffect(()=>{l!=null&&l.description&&j(l.description)},[l]),E||!b?e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsx(f.Loader,{className:"h-8 w-8 animate-spin"})}):N||!(l!=null&&l.id)?e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsxs("div",{className:"text-center max-w-md mx-auto p-6",children:[e.jsx("div",{className:"flex justify-center mb-4",children:e.jsx(f.AlertCircle,{className:"h-12 w-12 text-gray-400"})}),e.jsx("h3",{className:"text-lg font-medium text-gray-900 mb-2",children:s("No Asset Found")}),e.jsx("p",{className:"text-sm text-gray-500 mb-6",children:s(N?"There was an error loading the asset. Please try again later.":"The asset you're looking for doesn't exist or has been removed.")}),e.jsxs("div",{className:"flex justify-center gap-4",children:[e.jsx(a.Button,{variant:"outline",onClick:r,children:s("Back to Assets")}),N&&e.jsx(a.Button,{variant:"default",onClick:()=>window.location.reload(),children:s("Try Again")})]})]})}):e.jsxs("div",{className:"flex-1 flex flex-col gap-y-4 overflow-hidden",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(a.Button,{variant:"outline",size:"sm",onClick:r,disabled:o,children:[e.jsx(f.ChevronLeft,{className:"h-4 w-4"}),s("Back to Assets")]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(a.Button,{variant:"outline",onClick:r,disabled:o,children:s("Cancel")}),e.jsxs(a.Button,{variant:"outline",onClick:()=>A(l.url,s("Asset URL")),disabled:o,children:[e.jsx(f.Copy,{className:"h-4 w-4 mr-2"}),s("Copy URL")]}),e.jsxs(a.Button,{variant:"default",onClick:()=>x(l),disabled:o,children:[e.jsx(f.Pencil,{className:"h-4 w-4"}),s("Edit Image")]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 items-start gap-6 flex-1 overflow-hidden",children:[e.jsx("div",{className:"relative h-[calc(80vh-200px)] w-full flex items-start justify-center",children:e.jsx("img",{src:l.url,alt:l.name,className:"w-full h-full object-contain rounded-lg max-h-max max-w-max"})}),e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"grid gap-3 border rounded-md pt-2 bg-gray-100",children:[e.jsx(a.Label,{className:"w-full text-center",children:s("Details")}),e.jsx("div",{className:"grid grid-cols-1 gap-2 text-sm border rounded-md p-2 bg-white",children:[{label:s("File Name"),value:l.name},{label:s("Type"),value:l.type,capitalize:!0},{label:s("Format"),value:((c=l.metadata)==null?void 0:c.format)||l.type,capitalize:!0},{label:s("Size"),value:be(l.size)},{label:s("Dimensions"),value:`${l.width||0} × ${l.height||0}`},{label:s("Created"),value:Z(l.createdAt)},{label:s("Updated"),value:Z(((m=l.metadata)==null?void 0:m.updatedAt)||(l==null?void 0:l.updatedAt)||l.createdAt)},{label:s("URL"),value:l.url,copyable:!0}].map(d=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(a.Label,{className:"w-max text-left px-2 w-1/4 font-normal text-gray-700",children:d.label}),":",e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-max text-left font-medium text-gray-900"+(d.capitalize?" capitalize":""),children:d.value}),d.copyable&&e.jsx(a.Button,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:()=>A(d.value,d.label),children:e.jsx(f.Link,{className:"h-3 w-3"})})]})]},d.label))})]}),l.usedOn&&l.usedOn.length>0&&e.jsxs("div",{className:"grid gap-3",children:[e.jsx(a.Label,{children:s("Used On")}),e.jsx("div",{className:"grid grid-cols-1 gap-2 text-sm border rounded-md p-2",children:l.usedOn.map((d,p)=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-max text-left font-medium text-gray-900",children:d.name}),e.jsxs("div",{className:"text-gray-500",children:["(",d.slug,")"]})]},p))})]}),e.jsxs("div",{className:"grid gap-3 border rounded-md pt-2 bg-gray-100 relative",children:[e.jsx(a.Label,{className:"w-full text-center",children:s("Description")}),e.jsx(a.Textarea,{id:"description",value:v,placeholder:s("Enter a description for the asset"),onChange:d=>j(d.target.value),rows:3,disabled:o,className:"hover:border-black/40 bg-white"}),e.jsx("div",{className:"flex justify-end items-start absolute top-1.5 right-2",children:e.jsx("button",{type:"button",onClick:()=>i(v),disabled:o||!J(v,l),className:`py-0 bg-blue-500 text-white px-3 py-0.5 rounded-md text-sm ${o||!J(v,l)?"opacity-50 cursor-not-allowed":""}`,children:o?e.jsxs(e.Fragment,{children:[e.jsx(f.Loader,{className:"h-4 w-4 mr-2 animate-spin"}),s("Saving...")]}):s("Save")})})]})]})]})]})},Ce=u.lazy(()=>Promise.resolve().then(()=>require("./image-editor-CnDnY97s.cjs"))),Ae=25*1024*1024,Se=({isUpdatingAsset:n,allowedTypes:r,uploadAssets:x,isUploadingAsset:i,onUploaded:o})=>{const{t:s}=M.useTranslation(),[l,E]=u.useState(()=>{const c=localStorage.getItem("chai_optimize_images");return c!==null?c==="true":!0});u.useEffect(()=>{localStorage.setItem("chai_optimize_images",l.toString())},[l]);const N=n||i,v=u.useCallback(async c=>{try{const m=c;if(!m.every(S=>S.type.startsWith("image/")))return w.toast.error(s("Invalid file type. Please upload a valid file.")),Promise.reject(new Error("Invalid file type"));const d=m.map(async S=>{let U=S;return S.type.startsWith("image/")&&(U=await Y.compressImageIfNeeded(S)),new Promise((_,B)=>{const L=new FileReader;L.readAsDataURL(U),L.onload=async()=>{_({file:L.result,folderId:void 0,name:S.name,optimize:l})},L.onerror=()=>B(null)})}),p=await Promise.all(d),y=await x(p);return(y==null?void 0:y.length)===1&&o(y[0]),y}catch(m){return Promise.reject(m)}},[x,l,o,s]),j=c=>{const m=[];let d=0;return c.forEach(p=>{p.size>Ae?d++:m.push(p)}),d>0&&w.toast.error(`${d===1&&c.length===1?s("File"):d+s(d===1?" file":" files")} ${s("exceed the maximum size limit of 10MB.")}`),F.isEmpty(m)?[]:v(m)},{getRootProps:b,getInputProps:C,isDragActive:A}=fe.useDropzone({onDrop:j,accept:{"image/*":r.includes("image")?[]:[]},disabled:n||i,multiple:!0});return e.jsx("div",{className:`flex h-[60px] w-full flex-col items-center justify-center rounded-lg border-2 border-dashed border-slate-300 p-0 py-2 hover:border-black/50 ${N?"pointer-events-none bg-gray-100 opacity-90":"bg-gray-100 hover:border-black/50 hover:bg-gray-100"}`,children:e.jsxs("div",{...b(),className:M.mergeClasses("flex h-max w-full cursor-pointer flex-col justify-center rounded-lg text-center",N?"items-start":"items-center",A?"border-primary bg-primary/5":"border-muted-foreground/20"),children:[e.jsx("input",{...C()}),N?e.jsx("div",{className:"flex flex-col items-center px-6",children:e.jsxs("div",{className:"flex items-center justify-center gap-2 leading-tight",children:[e.jsx("div",{className:"flex items-center justify-center rounded-full bg-indigo-100 p-2",children:e.jsx(f.Loader,{className:"h-4 w-4 animate-spin text-indigo-500"})}),e.jsxs("div",{className:"text-left",children:[e.jsx("div",{className:"font-medium",children:s(n?"Updating file...":"Uploading file...")}),e.jsxs("div",{className:"text-xs font-light text-muted-foreground",children:[s("Please wait while we")," ",s(n?"update":"upload")," ",s("your file...")]})]})]})}):e.jsxs("div",{className:"flex w-full items-center justify-between px-6",children:[e.jsx("div",{className:"flex flex-col items-center",children:e.jsxs("div",{className:"flex items-center justify-between gap-2 leading-tight",children:[e.jsx("div",{className:"flex items-center justify-center rounded-full border border-indigo-500 bg-indigo-100 p-2",children:e.jsx(f.Upload,{className:"h-4 w-4 text-indigo-500"})}),e.jsxs("div",{className:"text-left",children:[e.jsxs("div",{className:"font-medium",children:[s("Drop your file here or")," ",e.jsx("span",{className:"cursor-pointer text-indigo-500 hover:underline",children:s("browse")})]}),e.jsx("div",{className:"text-xs font-light text-muted-foreground",children:e.jsxs("span",{className:"",children:[s("Accepted file types:")," ",e.jsx("span",{className:"capitalize text-indigo-400",children:r.join(", ")})]})})]})]})}),e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:"text-xs",children:[s("Optimization:")," "," ",e.jsx("span",{className:l?"text-indigo-600":"text-gray-400",children:s(l?"On":"Off")})]}),e.jsx(a.Switch,{checked:l,onCheckedChange:c=>{E(c)},onClick:c=>{c.stopPropagation()},className:"data-[state=checked]:bg-indigo-500"})]}),e.jsx(a.TooltipProvider,{children:e.jsxs(a.Tooltip,{children:[e.jsx(a.TooltipTrigger,{asChild:!0,children:e.jsx("span",{className:`flex cursor-help items-center text-amber-500 ${l?"invisible":""}`,children:e.jsx(f.AlertTriangle,{className:"mr-1 h-4 w-4"})})}),e.jsx(a.TooltipContent,{side:"top",children:e.jsx("p",{className:"text-xs text-white",children:s("Warning: Unoptimized images may affect performance and page load times")})})]})})]})]})]})})};function Te({close:n,onSelect:r,mode:x="image",assetId:i}){const{t:o}=M.useTranslation(),s=!1,l=10,E=u.useMemo(()=>[x],[x]),[N,v]=u.useState(null),[j,b]=u.useState(null),[C,A]=u.useState(null),[c,m]=u.useState({show:!1,file:""}),[d,p]=u.useState(!1),[y,S]=u.useState(i?"details":"grid"),[U,_]=u.useState(""),[B,L]=u.useState(""),[P,Q]=u.useState(1),[R]=u.useState(30),[T,G]=u.useState([]);u.useEffect(()=>{i&&(v(i),S("details"))},[i]),u.useEffect(()=>{const t=setTimeout(()=>{_(B),Q(1)},300);return()=>clearTimeout(t)},[B]);const{data:q,isLoading:$,refetch:ee}=ye({search:U.toLowerCase().trim(),page:P,limit:R}),D=(q==null?void 0:q.assets)||[],te=(q==null?void 0:q.total)||0,I=Math.ceil(te/R);u.useEffect(()=>{$||I<=0||Q(t=>t>I?I:t<1?1:t)},[$,I]);const se=(D==null?void 0:D.length)>0,{mutate:ie}=ge(),{mutateAsync:K,isPending:le}=pe(),{mutateAsync:W,isPending:ae}=je(),V=u.useCallback(t=>{const h=Math.min(Math.max(1,t),Math.max(1,I));h!==P&&Q(h)},[I,P]),re=t=>{L(t.target.value)},ne=u.useCallback(t=>{G(h=>F.find(h,{id:t.id})?[]:[t])},[s]),oe=u.useCallback(()=>{G([])},[]),H=t=>{(t==null?void 0:t.length)!==0&&(r(F.pick(F.first(t||T),["id","url","width","height","description"])),n())},ce=async t=>{b(t)},de=async()=>{j&&(A(j==null?void 0:j.id),await ie(j.id,{onSuccess:()=>{A(null),b(null)},onError:()=>{A(null)}}),b(null))},ue=t=>{v(t.id),S("details")},me=async(t,h)=>{try{const O=localStorage.getItem("chai_optimize_images")!=="false";if(h){const k=await K([{file:t,folderId:void 0,name:c.name||"",optimize:O}]);if((k==null?void 0:k.length)>0){const X=k[0];r({...F.pick(X,["id","width","height","description"]),url:X.url})}}else{const k=await W({id:c.id||"",file:t});k&&r({...F.pick(k,["id","width","height","description"]),url:k.url})}m({show:!1,file:""}),n()}catch(O){console.error(o("Error saving edited image:"),O)}},he=u.useCallback(t=>{G([t])},[]),xe=u.useCallback(t=>{V(t)},[V]);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex h-[80vh] max-h-[1232px] w-[80vw] max-w-[1232px] flex-col space-y-4",children:[e.jsx("h1",{className:"text-lg font-medium",children:o("Digital Asset Manager")}),y==="grid"?e.jsxs(e.Fragment,{children:[e.jsx(Se,{maxFileSize:l,allowedTypes:E,uploadAssets:K,isUpdatingAsset:ae,isUploadingAsset:le,onUploaded:he}),e.jsxs("div",{className:"relative flex flex-1 flex-col gap-y-3 overflow-hidden rounded-lg border p-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"relative w-1/2",children:[e.jsx(f.Search,{strokeWidth:3,className:`absolute left-2 top-2.5 h-4 w-4 text-muted-foreground ${B.length>0?"text-indigo-800":""}`}),e.jsx(a.Input,{placeholder:o("Search assets..."),onChange:re,value:B,className:"pl-8"})]}),e.jsxs("div",{className:"flex items-center gap-x-2",children:[T.length>0?e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("div",{className:"flex items-center gap-2",children:[T.length>0&&e.jsx(e.Fragment,{children:e.jsx(a.Button,{variant:"outline",size:"sm",onClick:()=>oe(),title:o("Clear selection"),children:o("Clear")})}),e.jsx(a.Button,{size:"sm",onClick:()=>H(T),disabled:T.length===0,children:o("Select Asset")})]})}):null,e.jsx(a.Button,{variant:"ghost",size:"icon",onClick:()=>ee(),children:e.jsx(f.RefreshCwIcon,{className:"h-4 w-4"})})]})]}),e.jsx("div",{className:"flex-1 overflow-y-auto pb-[66px]",children:$?e.jsxs("div",{className:"columns-1 gap-3 space-y-3 sm:columns-3 md:columns-5",children:[e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"})]}):!$&&!se?e.jsxs("div",{className:"flex h-full flex-col items-center justify-center rounded-lg border",children:[e.jsx("div",{className:"text-muted-foreground",children:e.jsx(f.Archive,{className:"h-9 w-9 text-indigo-500"})}),e.jsx("div",{className:"text-lg text-muted-foreground",children:o("No assets found")}),e.jsx("div",{className:"text-sm text-muted-foreground",children:U.length>0?o("No assets found for your search: {{query}}",{query:U}):o("Start uploading assets to get started")}),e.jsx("br",{})]}):e.jsx("div",{className:"flex flex-wrap gap-3 p-1",children:D==null?void 0:D.map(t=>e.jsxs("div",{className:M.mergeClasses("group relative flex max-h-[180px] max-w-[180px] cursor-pointer flex-col justify-between overflow-hidden rounded-lg border-2 transition-all",T.some(h=>h.id===t.id)?"border-blue-500":"hover:border-black/90",C&&(j==null?void 0:j.id)===t.id?"pointer-events-none opacity-50":"",C===t.id?"pointer-events-none opacity-50":""),onClick:()=>ne(t),onDoubleClick:()=>H([t]),children:[e.jsxs("div",{className:"aspect-square relative overflow-hidden",children:[C===t.id?e.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-black/50",children:e.jsx(f.Loader,{className:"h-8 w-8 animate-spin text-white"})}):null,t.type==="image"?e.jsx("img",{src:`${t.thumbnailUrl||"/placeholder.svg"}?v=${(t==null?void 0:t.updatedAt)||t.createdAt}`,alt:t.name,className:`h-full min-h-[80px] w-full object-contain ${T.some(h=>h.id===t.id)?"":"group-hover:blur group-hover:contrast-50"}`}):e.jsxs("div",{className:"flex h-full items-center justify-center",children:[e.jsx(f.Film,{className:"h-12 w-12 text-muted-foreground"}),t.thumbnailUrl&&e.jsx("img",{src:`${t.thumbnailUrl||"/placeholder.svg"}?v=${(t==null?void 0:t.updatedAt)||t.createdAt}`,alt:t.name,className:"absolute inset-0 h-full w-full object-cover"})]})]}),e.jsxs("div",{className:"flex items-end justify-between border-t-[1px] border-black/10 bg-white px-2 py-1",children:[e.jsx("div",{className:"truncate text-xs leading-tight",title:t.name,children:t.name}),e.jsx("div",{className:"flex items-center justify-between whitespace-nowrap text-[9px] font-light text-muted-foreground",children:e.jsx("span",{children:Y.formatFileSize((t==null?void 0:t.size)||0)})})]}),!T.some(h=>h.id===t.id)&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center opacity-0 transition-opacity group-hover:opacity-100",children:e.jsxs("div",{className:"grid grid-cols-4 gap-2 p-2",children:[e.jsx(a.TooltipProvider,{children:e.jsxs(a.Tooltip,{children:[e.jsx(a.TooltipTrigger,{asChild:!0,children:e.jsx(a.Button,{variant:"secondary",size:"icon",className:"h-8 w-8 rounded-full",onClick:h=>{h.stopPropagation(),ue(t)},children:e.jsx(f.ImageIcon,{className:"h-4 w-4"})})}),e.jsx(a.TooltipContent,{children:e.jsx("p",{children:o("View Details")})})]})}),e.jsx(a.TooltipProvider,{children:e.jsxs(a.Tooltip,{children:[e.jsx(a.TooltipTrigger,{asChild:!0,children:e.jsx(a.Button,{variant:"secondary",size:"icon",className:"h-8 w-8 rounded-full",onClick:h=>{h.stopPropagation(),navigator.clipboard.writeText(t.url),w.toast.success(o("Asset URL copied to clipboard"))},children:e.jsx(f.Copy,{className:"h-4 w-4"})})}),e.jsx(a.TooltipContent,{children:e.jsx("p",{children:o("Copy URL")})})]})}),e.jsx(a.TooltipProvider,{children:e.jsxs(a.Tooltip,{children:[e.jsx(a.TooltipTrigger,{asChild:!0,children:e.jsx(a.Button,{variant:"secondary",size:"icon",className:"h-8 w-8 rounded-full",onClick:h=>{h.stopPropagation(),m({id:t.id,show:!0,file:t.url,name:t.name})},children:e.jsx(f.Edit,{className:"h-4 w-4"})})}),e.jsx(a.TooltipContent,{children:e.jsx("p",{children:o("Edit Image")})})]})}),e.jsx(a.TooltipProvider,{children:e.jsxs(a.Tooltip,{children:[e.jsx(a.TooltipTrigger,{asChild:!0,children:e.jsx(a.Button,{variant:"destructive",size:"icon",className:"h-8 w-8 rounded-full",onClick:h=>{h.stopPropagation(),ce(t)},children:e.jsx(f.Trash2,{className:"h-4 w-4"})})}),e.jsx(a.TooltipContent,{children:e.jsx("p",{children:o("Delete Asset")})})]})})]})}),T.some(h=>h.id===t.id)&&e.jsx("div",{className:"absolute right-1 top-1 h-max rounded-full border border-white bg-blue-500 p-1",children:e.jsx(f.Check,{className:"h-3 w-3 text-white",strokeWidth:5})})]},t.id))})}),I>1&&e.jsx("div",{className:"absolute bottom-0 left-0 right-0 border-t bg-white p-4",children:e.jsx(g.ErrorBoundary,{fallback:e.jsx("div",{className:"text-red-500",children:o("Error loading pagination")}),children:e.jsx(ve,{currentPage:P,totalPages:I,onPageChange:xe,pageRangeDisplayed:3,showPageInput:!0})})})]})]}):e.jsx(we,{assetId:N||i||"",onBack:()=>{S("grid"),v(null)},onEdit:t=>{m({id:t.id,show:!0,file:t.url,name:t.name})},onSave:async t=>{if(N){p(!0);try{const h=D.find(O=>O.id===N);h&&await W(F.merge(h,{description:t}))}finally{p(!1)}}},isSaving:d})]}),c.show&&e.jsx(u.Suspense,{fallback:e.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:e.jsx(f.Loader,{className:"h-8 w-8 animate-spin"})}),children:e.jsx(Ce,{imageUrl:c.file,onSave:me,onClose:()=>m({show:!1,file:""}),defaultSavedImageName:c.name,isEditing:!!c.id})}),j&&e.jsx(a.Dialog,{open:!!j,onOpenChange:()=>b(null),children:e.jsxs(a.DialogContent,{children:[e.jsxs(a.DialogHeader,{children:[e.jsx(a.DialogTitle,{children:o("Delete Asset")}),e.jsx(a.DialogDescription,{children:o('Are you sure you want to delete "{{name}}"? This action cannot be undone.',{name:j.name})})]}),e.jsxs(a.DialogFooter,{className:"gap-2 sm:gap-0",children:[e.jsx(a.Button,{variant:"outline",onClick:()=>b(null),children:o("Cancel")}),e.jsx(a.Button,{variant:"destructive",onClick:de,children:o("Delete")})]})]})})]})}exports.default=Te;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),M=require("@chaibuilder/sdk"),a=require("@chaibuilder/sdk/ui"),F=require("lodash-es"),f=require("lucide-react"),u=require("react"),fe=require("react-dropzone"),g=require("./index-B1OACNv-.cjs"),w=require("sonner"),Y=require("./image-compression-DZ9WMmyn.cjs"),z=require("@tanstack/react-query"),pe=()=>{const n=g.useAssetsApiUrl(),r=z.useQueryClient(),x=g.useFetch();return z.useMutation({mutationFn:async i=>{const o=i.map(async l=>x(n,{action:g.ACTIONS.UPLOAD_ASSET,data:l}));return await Promise.all(o)},onSuccess:i=>{var o;if(i!=null&&i.some(s=>s.error))throw new Error(((o=i==null?void 0:i.find(s=>s.error))==null?void 0:o.error)||"Failed to upload asset");{r.invalidateQueries({queryKey:[g.ACTIONS.GET_ASSETS]});const s=i==null?void 0:i.length;w.toast.success(`${s===1?"Asset":s+" Assets"} uploaded successfully`)}},onError:()=>{w.toast.error("Failed to upload asset")}})},ge=()=>{const n=g.useAssetsApiUrl(),r=z.useQueryClient(),x=g.useFetch();return z.useMutation({mutationFn:async i=>x(n,{action:g.ACTIONS.DELETE_ASSET,data:{id:i}}),onSuccess:i=>{if(i!=null&&i.error)throw new Error(i==null?void 0:i.error);r.invalidateQueries({queryKey:[g.ACTIONS.GET_ASSETS]}),w.toast.success("Asset deleted successfully")},onError:()=>{w.toast.error("Failed to delete asset")}})},je=()=>{const n=g.useAssetsApiUrl(),r=z.useQueryClient(),x=g.useFetch();return z.useMutation({mutationFn:async i=>x(n,{action:g.ACTIONS.UPDATE_ASSET,data:i}),onSuccess:i=>{if(i!=null&&i.error)throw new Error(i==null?void 0:i.error);r.invalidateQueries({queryKey:[g.ACTIONS.GET_ASSETS]}),i!=null&&i.id&&r.invalidateQueries({queryKey:[g.ACTIONS.GET_ASSET,i.id]}),w.toast.success("Asset updated successfully")},onError:()=>{w.toast.error("Failed to update asset")}})};function ve({currentPage:n,totalPages:r,onPageChange:x,pageRangeDisplayed:i=3,showPageInput:o=!0,className:s=""}){const[l,E]=u.useState(String(n)),N=u.useMemo(()=>{const c=Math.floor(i/2);let m=Math.max(1,n-c),d=Math.min(r,n+c);d-m+1<i&&(m===1?d=Math.min(r,m+i-1):d===r&&(m=Math.max(1,d-i+1)));const p=[];m>1&&(p.push(1),m>2&&p.push("..."));for(let y=m;y<=d;y++)p.push(y);return d<r&&(d<r-1&&p.push("..."),p.push(r)),p},[n,r,i]),v=c=>{c!==n&&c>=1&&c<=r&&(x(c),E(String(c)))},j=()=>{n>1&&v(n-1)},b=()=>{n<r&&v(n+1)},C=()=>{const c=Number(l);!isNaN(c)&&c>=1&&c<=r&&v(c)},A=c=>{c.key==="Enter"&&C()};return r<=1?null:e.jsxs("div",{className:`flex flex-wrap items-center justify-center gap-3 ${s}`,children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(a.Button,{variant:"outline",size:"sm",onClick:j,disabled:n===1,className:"px-2 py-1 text-sm hover:bg-gray-50",children:[e.jsx(f.ChevronLeft,{className:" h-4 w-4"}),"Previous"]}),e.jsx("div",{className:"flex items-center gap-2",children:N.map((c,m)=>{if(c==="...")return e.jsx("span",{className:"px-2 text-muted-foreground",children:"..."},`ellipsis-${m}`);const d=c,p=d===n;return e.jsx(a.Button,{variant:p?"default":"outline",size:"sm",onClick:()=>v(d),className:p?"border-blue-600 bg-blue-600 px-3 py-1 text-sm text-white":"border px-3 py-1 text-sm hover:bg-gray-50 hover:text-black",children:d},d)})}),e.jsxs(a.Button,{variant:"outline",size:"sm",onClick:b,disabled:n===r,className:"px-2 py-1 text-sm hover:bg-gray-50",children:["Next",e.jsx(f.ChevronRight,{className:" h-4 w-4"})]})]}),o&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:"Go to"}),e.jsx(a.Input,{type:"number",min:1,max:r,value:l,onChange:c=>{const m=c.target.value.replace(/[^\d]/g,"");E(m)},onKeyDown:A,className:"h-8 w-16 px-2 py-1"}),e.jsx(a.Button,{variant:"outline",size:"sm",onClick:C,disabled:l===""||Number(l)<1||Number(l)>r,children:"Go"})]})]})}const ye=(n={})=>{const r=g.useAssetsApiUrl(),x=g.useFetch(),{search:i,page:o=1,limit:s=30}=n;return z.useQuery({queryKey:[g.ACTIONS.GET_ASSETS,i,o,s],queryFn:async()=>{const l=await x(r,{action:g.ACTIONS.GET_ASSETS,data:{search:i,page:o,limit:s}});return l.page=o,l.limit=s,l},staleTime:1/0,retry:1})},Ne=n=>{const r=g.useAssetsApiUrl(),x=g.useFetch();return z.useQuery({queryKey:[g.ACTIONS.GET_ASSET,n],queryFn:async()=>n?await x(r,{action:g.ACTIONS.GET_ASSET,data:{id:n}}):null,staleTime:1/0,retry:1})};function be(n){const r=isNaN(n)?0:typeof n=="number"?n:parseInt(n);return r?r<1024?`${r.toFixed(2)} B`:r<1024*1024?`${(r/1024).toFixed(2)} KB`:`${(r/(1024*1024)).toFixed(2)} MB`:"0 B"}function Z(n){if(!n)return"N/A";const r=new Date(n);return new Intl.DateTimeFormat("en-US",{month:"short",day:"numeric",year:"numeric",hour:"2-digit",minute:"2-digit"}).format(r)}function J(n,r){let x=n,i=r==null?void 0:r.description;return(!i||typeof i!="string")&&(i=""),(!x||typeof x!="string")&&(x=""),x!==i}const we=({assetId:n,onBack:r,onEdit:x,onSave:i,isSaving:o})=>{var c,m;const{t:s}=M.useTranslation(),{data:l,isLoading:E,isError:N}=Ne(n||""),[v,j]=u.useState(""),[b,C]=u.useState(!1);u.useEffect(()=>{const d=new Image;return d.src=(l==null?void 0:l.url)||"",d.onload=()=>C(!0),()=>{d.onload=null}},[l]);const A=async(d,p)=>{try{await navigator.clipboard.writeText(d),w.toast.success(s("{{type}} copied to clipboard",{type:p}))}catch(y){w.toast.error(s("Failed to copy {{type}}",{type:p}),{description:y==null?void 0:y.message})}};return u.useEffect(()=>{l!=null&&l.description&&j(l.description)},[l]),E||!b?e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsx(f.Loader,{className:"h-8 w-8 animate-spin"})}):N||!(l!=null&&l.id)?e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsxs("div",{className:"text-center max-w-md mx-auto p-6",children:[e.jsx("div",{className:"flex justify-center mb-4",children:e.jsx(f.AlertCircle,{className:"h-12 w-12 text-gray-400"})}),e.jsx("h3",{className:"text-lg font-medium text-gray-900 mb-2",children:s("No Asset Found")}),e.jsx("p",{className:"text-sm text-gray-500 mb-6",children:s(N?"There was an error loading the asset. Please try again later.":"The asset you're looking for doesn't exist or has been removed.")}),e.jsxs("div",{className:"flex justify-center gap-4",children:[e.jsx(a.Button,{variant:"outline",onClick:r,children:s("Back to Assets")}),N&&e.jsx(a.Button,{variant:"default",onClick:()=>window.location.reload(),children:s("Try Again")})]})]})}):e.jsxs("div",{className:"flex-1 flex flex-col gap-y-4 overflow-hidden",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(a.Button,{variant:"outline",size:"sm",onClick:r,disabled:o,children:[e.jsx(f.ChevronLeft,{className:"h-4 w-4"}),s("Back to Assets")]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(a.Button,{variant:"outline",onClick:r,disabled:o,children:s("Cancel")}),e.jsxs(a.Button,{variant:"outline",onClick:()=>A(l.url,s("Asset URL")),disabled:o,children:[e.jsx(f.Copy,{className:"h-4 w-4 mr-2"}),s("Copy URL")]}),e.jsxs(a.Button,{variant:"default",onClick:()=>x(l),disabled:o,children:[e.jsx(f.Pencil,{className:"h-4 w-4"}),s("Edit Image")]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 items-start gap-6 flex-1 overflow-hidden",children:[e.jsx("div",{className:"relative h-[calc(80vh-200px)] w-full flex items-start justify-center",children:e.jsx("img",{src:l.url,alt:l.name,className:"w-full h-full object-contain rounded-lg max-h-max max-w-max"})}),e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"grid gap-3 border rounded-md pt-2 bg-gray-100",children:[e.jsx(a.Label,{className:"w-full text-center",children:s("Details")}),e.jsx("div",{className:"grid grid-cols-1 gap-2 text-sm border rounded-md p-2 bg-white",children:[{label:s("File Name"),value:l.name},{label:s("Type"),value:l.type,capitalize:!0},{label:s("Format"),value:((c=l.metadata)==null?void 0:c.format)||l.type,capitalize:!0},{label:s("Size"),value:be(l.size)},{label:s("Dimensions"),value:`${l.width||0} × ${l.height||0}`},{label:s("Created"),value:Z(l.createdAt)},{label:s("Updated"),value:Z(((m=l.metadata)==null?void 0:m.updatedAt)||(l==null?void 0:l.updatedAt)||l.createdAt)},{label:s("URL"),value:l.url,copyable:!0}].map(d=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(a.Label,{className:"w-max text-left px-2 w-1/4 font-normal text-gray-700",children:d.label}),":",e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-max text-left font-medium text-gray-900"+(d.capitalize?" capitalize":""),children:d.value}),d.copyable&&e.jsx(a.Button,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:()=>A(d.value,d.label),children:e.jsx(f.Link,{className:"h-3 w-3"})})]})]},d.label))})]}),l.usedOn&&l.usedOn.length>0&&e.jsxs("div",{className:"grid gap-3",children:[e.jsx(a.Label,{children:s("Used On")}),e.jsx("div",{className:"grid grid-cols-1 gap-2 text-sm border rounded-md p-2",children:l.usedOn.map((d,p)=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-max text-left font-medium text-gray-900",children:d.name}),e.jsxs("div",{className:"text-gray-500",children:["(",d.slug,")"]})]},p))})]}),e.jsxs("div",{className:"grid gap-3 border rounded-md pt-2 bg-gray-100 relative",children:[e.jsx(a.Label,{className:"w-full text-center",children:s("Description")}),e.jsx(a.Textarea,{id:"description",value:v,placeholder:s("Enter a description for the asset"),onChange:d=>j(d.target.value),rows:3,disabled:o,className:"hover:border-black/40 bg-white"}),e.jsx("div",{className:"flex justify-end items-start absolute top-1.5 right-2",children:e.jsx("button",{type:"button",onClick:()=>i(v),disabled:o||!J(v,l),className:`py-0 bg-blue-500 text-white px-3 py-0.5 rounded-md text-sm ${o||!J(v,l)?"opacity-50 cursor-not-allowed":""}`,children:o?e.jsxs(e.Fragment,{children:[e.jsx(f.Loader,{className:"h-4 w-4 mr-2 animate-spin"}),s("Saving...")]}):s("Save")})})]})]})]})]})},Ce=u.lazy(()=>Promise.resolve().then(()=>require("./image-editor-CnDnY97s.cjs"))),Ae=25*1024*1024,Se=({isUpdatingAsset:n,allowedTypes:r,uploadAssets:x,isUploadingAsset:i,onUploaded:o})=>{const{t:s}=M.useTranslation(),[l,E]=u.useState(()=>{const c=localStorage.getItem("chai_optimize_images");return c!==null?c==="true":!0});u.useEffect(()=>{localStorage.setItem("chai_optimize_images",l.toString())},[l]);const N=n||i,v=u.useCallback(async c=>{try{const m=c;if(!m.every(S=>S.type.startsWith("image/")))return w.toast.error(s("Invalid file type. Please upload a valid file.")),Promise.reject(new Error("Invalid file type"));const d=m.map(async S=>{let U=S;return S.type.startsWith("image/")&&(U=await Y.compressImageIfNeeded(S)),new Promise((_,B)=>{const L=new FileReader;L.readAsDataURL(U),L.onload=async()=>{_({file:L.result,folderId:void 0,name:S.name,optimize:l})},L.onerror=()=>B(null)})}),p=await Promise.all(d),y=await x(p);return(y==null?void 0:y.length)===1&&o(y[0]),y}catch(m){return Promise.reject(m)}},[x,l,o,s]),j=c=>{const m=[];let d=0;return c.forEach(p=>{p.size>Ae?d++:m.push(p)}),d>0&&w.toast.error(`${d===1&&c.length===1?s("File"):d+s(d===1?" file":" files")} ${s("exceed the maximum size limit of 10MB.")}`),F.isEmpty(m)?[]:v(m)},{getRootProps:b,getInputProps:C,isDragActive:A}=fe.useDropzone({onDrop:j,accept:{"image/*":r.includes("image")?[]:[]},disabled:n||i,multiple:!0});return e.jsx("div",{className:`flex h-[60px] w-full flex-col items-center justify-center rounded-lg border-2 border-dashed border-slate-300 p-0 py-2 hover:border-black/50 ${N?"pointer-events-none bg-gray-100 opacity-90":"bg-gray-100 hover:border-black/50 hover:bg-gray-100"}`,children:e.jsxs("div",{...b(),className:M.mergeClasses("flex h-max w-full cursor-pointer flex-col justify-center rounded-lg text-center",N?"items-start":"items-center",A?"border-primary bg-primary/5":"border-muted-foreground/20"),children:[e.jsx("input",{...C()}),N?e.jsx("div",{className:"flex flex-col items-center px-6",children:e.jsxs("div",{className:"flex items-center justify-center gap-2 leading-tight",children:[e.jsx("div",{className:"flex items-center justify-center rounded-full bg-indigo-100 p-2",children:e.jsx(f.Loader,{className:"h-4 w-4 animate-spin text-indigo-500"})}),e.jsxs("div",{className:"text-left",children:[e.jsx("div",{className:"font-medium",children:s(n?"Updating file...":"Uploading file...")}),e.jsxs("div",{className:"text-xs font-light text-muted-foreground",children:[s("Please wait while we")," ",s(n?"update":"upload")," ",s("your file...")]})]})]})}):e.jsxs("div",{className:"flex w-full items-center justify-between px-6",children:[e.jsx("div",{className:"flex flex-col items-center",children:e.jsxs("div",{className:"flex items-center justify-between gap-2 leading-tight",children:[e.jsx("div",{className:"flex items-center justify-center rounded-full border border-indigo-500 bg-indigo-100 p-2",children:e.jsx(f.Upload,{className:"h-4 w-4 text-indigo-500"})}),e.jsxs("div",{className:"text-left",children:[e.jsxs("div",{className:"font-medium",children:[s("Drop your file here or")," ",e.jsx("span",{className:"cursor-pointer text-indigo-500 hover:underline",children:s("browse")})]}),e.jsx("div",{className:"text-xs font-light text-muted-foreground",children:e.jsxs("span",{className:"",children:[s("Accepted file types:")," ",e.jsx("span",{className:"capitalize text-indigo-400",children:r.join(", ")})]})})]})]})}),e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:"text-xs",children:[s("Optimization:")," "," ",e.jsx("span",{className:l?"text-indigo-600":"text-gray-400",children:s(l?"On":"Off")})]}),e.jsx(a.Switch,{checked:l,onCheckedChange:c=>{E(c)},onClick:c=>{c.stopPropagation()},className:"data-[state=checked]:bg-indigo-500"})]}),e.jsx(a.TooltipProvider,{children:e.jsxs(a.Tooltip,{children:[e.jsx(a.TooltipTrigger,{asChild:!0,children:e.jsx("span",{className:`flex cursor-help items-center text-amber-500 ${l?"invisible":""}`,children:e.jsx(f.AlertTriangle,{className:"mr-1 h-4 w-4"})})}),e.jsx(a.TooltipContent,{side:"top",children:e.jsx("p",{className:"text-xs text-white",children:s("Warning: Unoptimized images may affect performance and page load times")})})]})})]})]})]})})};function Te({close:n,onSelect:r,mode:x="image",assetId:i}){const{t:o}=M.useTranslation(),s=!1,l=10,E=u.useMemo(()=>[x],[x]),[N,v]=u.useState(null),[j,b]=u.useState(null),[C,A]=u.useState(null),[c,m]=u.useState({show:!1,file:""}),[d,p]=u.useState(!1),[y,S]=u.useState(i?"details":"grid"),[U,_]=u.useState(""),[B,L]=u.useState(""),[P,Q]=u.useState(1),[R]=u.useState(30),[T,G]=u.useState([]);u.useEffect(()=>{i&&(v(i),S("details"))},[i]),u.useEffect(()=>{const t=setTimeout(()=>{_(B),Q(1)},300);return()=>clearTimeout(t)},[B]);const{data:q,isLoading:$,refetch:ee}=ye({search:U.toLowerCase().trim(),page:P,limit:R}),D=(q==null?void 0:q.assets)||[],te=(q==null?void 0:q.total)||0,I=Math.ceil(te/R);u.useEffect(()=>{$||I<=0||Q(t=>t>I?I:t<1?1:t)},[$,I]);const se=(D==null?void 0:D.length)>0,{mutate:ie}=ge(),{mutateAsync:K,isPending:le}=pe(),{mutateAsync:W,isPending:ae}=je(),V=u.useCallback(t=>{const h=Math.min(Math.max(1,t),Math.max(1,I));h!==P&&Q(h)},[I,P]),re=t=>{L(t.target.value)},ne=u.useCallback(t=>{G(h=>F.find(h,{id:t.id})?[]:[t])},[s]),oe=u.useCallback(()=>{G([])},[]),H=t=>{(t==null?void 0:t.length)!==0&&(r(F.pick(F.first(t||T),["id","url","width","height","description"])),n())},ce=async t=>{b(t)},de=async()=>{j&&(A(j==null?void 0:j.id),await ie(j.id,{onSuccess:()=>{A(null),b(null)},onError:()=>{A(null)}}),b(null))},ue=t=>{v(t.id),S("details")},me=async(t,h)=>{try{const O=localStorage.getItem("chai_optimize_images")!=="false";if(h){const k=await K([{file:t,folderId:void 0,name:c.name||"",optimize:O}]);if((k==null?void 0:k.length)>0){const X=k[0];r({...F.pick(X,["id","width","height","description"]),url:X.url})}}else{const k=await W({id:c.id||"",file:t});k&&r({...F.pick(k,["id","width","height","description"]),url:k.url})}m({show:!1,file:""}),n()}catch(O){console.error(o("Error saving edited image:"),O)}},he=u.useCallback(t=>{G([t])},[]),xe=u.useCallback(t=>{V(t)},[V]);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex h-[80vh] max-h-[1232px] w-[80vw] max-w-[1232px] flex-col space-y-4",children:[e.jsx("h1",{className:"text-lg font-medium",children:o("Digital Asset Manager")}),y==="grid"?e.jsxs(e.Fragment,{children:[e.jsx(Se,{maxFileSize:l,allowedTypes:E,uploadAssets:K,isUpdatingAsset:ae,isUploadingAsset:le,onUploaded:he}),e.jsxs("div",{className:"relative flex flex-1 flex-col gap-y-3 overflow-hidden rounded-lg border p-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"relative w-1/2",children:[e.jsx(f.Search,{strokeWidth:3,className:`absolute left-2 top-2.5 h-4 w-4 text-muted-foreground ${B.length>0?"text-indigo-800":""}`}),e.jsx(a.Input,{placeholder:o("Search assets..."),onChange:re,value:B,className:"pl-8"})]}),e.jsxs("div",{className:"flex items-center gap-x-2",children:[T.length>0?e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("div",{className:"flex items-center gap-2",children:[T.length>0&&e.jsx(e.Fragment,{children:e.jsx(a.Button,{variant:"outline",size:"sm",onClick:()=>oe(),title:o("Clear selection"),children:o("Clear")})}),e.jsx(a.Button,{size:"sm",onClick:()=>H(T),disabled:T.length===0,children:o("Select Asset")})]})}):null,e.jsx(a.Button,{variant:"ghost",size:"icon",onClick:()=>ee(),children:e.jsx(f.RefreshCwIcon,{className:"h-4 w-4"})})]})]}),e.jsx("div",{className:"flex-1 overflow-y-auto pb-[66px]",children:$?e.jsxs("div",{className:"columns-1 gap-3 space-y-3 sm:columns-3 md:columns-5",children:[e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"})]}):!$&&!se?e.jsxs("div",{className:"flex h-full flex-col items-center justify-center rounded-lg border",children:[e.jsx("div",{className:"text-muted-foreground",children:e.jsx(f.Archive,{className:"h-9 w-9 text-indigo-500"})}),e.jsx("div",{className:"text-lg text-muted-foreground",children:o("No assets found")}),e.jsx("div",{className:"text-sm text-muted-foreground",children:U.length>0?o("No assets found for your search: {{query}}",{query:U}):o("Start uploading assets to get started")}),e.jsx("br",{})]}):e.jsx("div",{className:"flex flex-wrap gap-3 p-1",children:D==null?void 0:D.map(t=>e.jsxs("div",{className:M.mergeClasses("group relative flex max-h-[180px] max-w-[180px] cursor-pointer flex-col justify-between overflow-hidden rounded-lg border-2 transition-all",T.some(h=>h.id===t.id)?"border-blue-500":"hover:border-black/90",C&&(j==null?void 0:j.id)===t.id?"pointer-events-none opacity-50":"",C===t.id?"pointer-events-none opacity-50":""),onClick:()=>ne(t),onDoubleClick:()=>H([t]),children:[e.jsxs("div",{className:"aspect-square relative overflow-hidden",children:[C===t.id?e.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-black/50",children:e.jsx(f.Loader,{className:"h-8 w-8 animate-spin text-white"})}):null,t.type==="image"?e.jsx("img",{src:`${t.thumbnailUrl||"/placeholder.svg"}?v=${(t==null?void 0:t.updatedAt)||t.createdAt}`,alt:t.name,className:`h-full min-h-[80px] w-full object-contain ${T.some(h=>h.id===t.id)?"":"group-hover:blur group-hover:contrast-50"}`}):e.jsxs("div",{className:"flex h-full items-center justify-center",children:[e.jsx(f.Film,{className:"h-12 w-12 text-muted-foreground"}),t.thumbnailUrl&&e.jsx("img",{src:`${t.thumbnailUrl||"/placeholder.svg"}?v=${(t==null?void 0:t.updatedAt)||t.createdAt}`,alt:t.name,className:"absolute inset-0 h-full w-full object-cover"})]})]}),e.jsxs("div",{className:"flex items-end justify-between border-t-[1px] border-black/10 bg-white px-2 py-1",children:[e.jsx("div",{className:"truncate text-xs leading-tight",title:t.name,children:t.name}),e.jsx("div",{className:"flex items-center justify-between whitespace-nowrap text-[9px] font-light text-muted-foreground",children:e.jsx("span",{children:Y.formatFileSize((t==null?void 0:t.size)||0)})})]}),!T.some(h=>h.id===t.id)&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center opacity-0 transition-opacity group-hover:opacity-100",children:e.jsxs("div",{className:"grid grid-cols-4 gap-2 p-2",children:[e.jsx(a.TooltipProvider,{children:e.jsxs(a.Tooltip,{children:[e.jsx(a.TooltipTrigger,{asChild:!0,children:e.jsx(a.Button,{variant:"secondary",size:"icon",className:"h-8 w-8 rounded-full",onClick:h=>{h.stopPropagation(),ue(t)},children:e.jsx(f.ImageIcon,{className:"h-4 w-4"})})}),e.jsx(a.TooltipContent,{children:e.jsx("p",{children:o("View Details")})})]})}),e.jsx(a.TooltipProvider,{children:e.jsxs(a.Tooltip,{children:[e.jsx(a.TooltipTrigger,{asChild:!0,children:e.jsx(a.Button,{variant:"secondary",size:"icon",className:"h-8 w-8 rounded-full",onClick:h=>{h.stopPropagation(),navigator.clipboard.writeText(t.url),w.toast.success(o("Asset URL copied to clipboard"))},children:e.jsx(f.Copy,{className:"h-4 w-4"})})}),e.jsx(a.TooltipContent,{children:e.jsx("p",{children:o("Copy URL")})})]})}),e.jsx(a.TooltipProvider,{children:e.jsxs(a.Tooltip,{children:[e.jsx(a.TooltipTrigger,{asChild:!0,children:e.jsx(a.Button,{variant:"secondary",size:"icon",className:"h-8 w-8 rounded-full",onClick:h=>{h.stopPropagation(),m({id:t.id,show:!0,file:t.url,name:t.name})},children:e.jsx(f.Edit,{className:"h-4 w-4"})})}),e.jsx(a.TooltipContent,{children:e.jsx("p",{children:o("Edit Image")})})]})}),e.jsx(a.TooltipProvider,{children:e.jsxs(a.Tooltip,{children:[e.jsx(a.TooltipTrigger,{asChild:!0,children:e.jsx(a.Button,{variant:"destructive",size:"icon",className:"h-8 w-8 rounded-full",onClick:h=>{h.stopPropagation(),ce(t)},children:e.jsx(f.Trash2,{className:"h-4 w-4"})})}),e.jsx(a.TooltipContent,{children:e.jsx("p",{children:o("Delete Asset")})})]})})]})}),T.some(h=>h.id===t.id)&&e.jsx("div",{className:"absolute right-1 top-1 h-max rounded-full border border-white bg-blue-500 p-1",children:e.jsx(f.Check,{className:"h-3 w-3 text-white",strokeWidth:5})})]},t.id))})}),I>1&&e.jsx("div",{className:"absolute bottom-0 left-0 right-0 border-t bg-white p-4",children:e.jsx(g.ErrorBoundary,{fallback:e.jsx("div",{className:"text-red-500",children:o("Error loading pagination")}),children:e.jsx(ve,{currentPage:P,totalPages:I,onPageChange:xe,pageRangeDisplayed:3,showPageInput:!0})})})]})]}):e.jsx(we,{assetId:N||i||"",onBack:()=>{S("grid"),v(null)},onEdit:t=>{m({id:t.id,show:!0,file:t.url,name:t.name})},onSave:async t=>{if(N){p(!0);try{const h=D.find(O=>O.id===N);h&&await W(F.merge(h,{description:t}))}finally{p(!1)}}},isSaving:d})]}),c.show&&e.jsx(u.Suspense,{fallback:e.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:e.jsx(f.Loader,{className:"h-8 w-8 animate-spin"})}),children:e.jsx(Ce,{imageUrl:c.file,onSave:me,onClose:()=>m({show:!1,file:""}),defaultSavedImageName:c.name,isEditing:!!c.id})}),j&&e.jsx(a.Dialog,{open:!!j,onOpenChange:()=>b(null),children:e.jsxs(a.DialogContent,{children:[e.jsxs(a.DialogHeader,{children:[e.jsx(a.DialogTitle,{children:o("Delete Asset")}),e.jsx(a.DialogDescription,{children:o('Are you sure you want to delete "{{name}}"? This action cannot be undone.',{name:j.name})})]}),e.jsxs(a.DialogFooter,{className:"gap-2 sm:gap-0",children:[e.jsx(a.Button,{variant:"outline",onClick:()=>b(null),children:o("Cancel")}),e.jsx(a.Button,{variant:"destructive",onClick:de,children:o("Delete")})]})]})})]})}exports.default=Te;
@@ -5,7 +5,7 @@ import { find as Ge, merge as Oe, pick as Y, first as Be, isEmpty as Ke } from "
5
5
  import { ChevronLeft as he, ChevronRight as Qe, Loader as B, AlertCircle as Re, Copy as fe, Pencil as We, Link as Ve, Search as He, RefreshCwIcon as Xe, Archive as Ze, Film as Je, ImageIcon as Ye, Edit as et, Trash2 as tt, Check as it, Upload as lt, AlertTriangle as at } from "lucide-react";
6
6
  import pe, { useState as y, useMemo as ge, useEffect as O, useCallback as M, Suspense as rt } from "react";
7
7
  import { useDropzone as nt } from "react-dropzone";
8
- import { aM as K, an as Q, A as b, aN as st } from "./index-DRQI9rlW.js";
8
+ import { aM as K, an as Q, A as b, aN as st } from "./index-DdQbaicX.js";
9
9
  import { toast as A } from "sonner";
10
10
  import { f as ct, c as ot } from "./image-compression-DsZ1oqpb.js";
11
11
  import { useQueryClient as te, useMutation as ie, useQuery as xe } from "@tanstack/react-query";
@@ -1,5 +1,5 @@
1
1
  import { jsx as t, jsxs as a } from "react/jsx-runtime";
2
- import { am as C, an as A, A as T, ao as w } from "./index-DRQI9rlW.js";
2
+ import { am as C, an as A, A as T, ao as w } from "./index-DdQbaicX.js";
3
3
  import { useQueryClient as F, useMutation as _ } from "@tanstack/react-query";
4
4
  import { toast as v } from "sonner";
5
5
  import { useTranslation as q } from "@chaibuilder/sdk";
@@ -7,7 +7,7 @@ import { Dialog as G, DialogContent as L, DialogHeader as U, DialogTitle as j, D
7
7
  import { isEmpty as M, initial as Q } from "lodash-es";
8
8
  import { AlertCircle as V } from "lucide-react";
9
9
  import { useState as p } from "react";
10
- import { S as k } from "./slug-input-RCGUFL2T.js";
10
+ import { S as k } from "./slug-input-DTA7c8c6.js";
11
11
  const H = () => {
12
12
  const s = C(), o = F(), g = A();
13
13
  return _({
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),p=require("./index-CyHmr87X.cjs"),N=require("@tanstack/react-query"),v=require("sonner"),E=require("@chaibuilder/sdk"),a=require("@chaibuilder/sdk/ui"),P=require("lodash-es"),C=require("lucide-react"),g=require("react"),A=require("./slug-input-BewLv-d8.cjs"),T=()=>{const t=p.useApiUrl(),u=N.useQueryClient(),h=p.useFetch();return N.useMutation({mutationFn:async({pageId:s,name:x,slug:r})=>{const o={pageId:s,name:x};return r&&(o.slug=r),await h(t,{action:"DUPLICATE_PAGE",data:o})},onSuccess:()=>{u.invalidateQueries({queryKey:[p.ACTIONS.GET_WEBSITE_PAGES]}),v.toast.success("Page duplicated successfully")},onError:s=>{v.toast.error("Failed to duplicate page",{description:s.message||"An error occurred while duplicating the page"})}})},w=({page:t,onClose:u,closePanel:h=()=>{}})=>{const{t:s}=E.useTranslation(),{mutate:x,isPending:r}=T(),[o,i]=g.useState(null),[d,D]=g.useState(`${t.name} (Copy)`),b=p.useChangePage(),n=P.isEmpty(t.slug),[m,I]=g.useState(n?"":`${t.slug.split("/").pop()}-copy`),f=n?"":P.initial(t.slug.split("/")).join("/"),[y,j]=g.useState(!1),q=l=>{if(l.preventDefault(),!d.trim()){i(s("Name is required"));return}if(!n&&!m.trim()){i(s("Slug is required"));return}i(null),j(!0);const S={pageId:t.id,name:d};n||(S.slug=`${f}/${m}`),x(S,{onSuccess:c=>{j(!1),u(),b(c.id,h)},onError:c=>{j(!1),c.code==="SLUG_EXISTS"?i(s("A page with this slug already exists. Please choose a different slug.")):c.code==="INVALID_SLUG"?i(s("The slug format is invalid. Please use only lowercase letters, numbers, and hyphens.")):c.code==="PERMISSION_DENIED"?i(s("You don't have permission to duplicate this page.")):i(c.message||s("Failed to duplicate page. Please try again later."))}})};return e.jsx(a.Dialog,{open:!!t,onOpenChange:u,children:e.jsxs(a.DialogContent,{className:"sm:max-w-[425px]",children:[e.jsxs(a.DialogHeader,{children:[e.jsx(a.DialogTitle,{children:s("Duplicate Page")}),e.jsx(a.DialogDescription,{children:s("Create a copy of the page with a new name and slug")})]}),e.jsxs("div",{className:"mb-4 rounded-md bg-gray-50 p-3",children:[e.jsxs("h3",{className:"mb-1 text-sm font-medium",children:[s("Duplicating:"),":"]}),e.jsxs("div",{className:"flex flex-col gap-1 text-sm text-gray-700",children:[e.jsxs("div",{children:[e.jsxs("span",{className:"font-medium",children:[s("Name"),":"]})," ",t.name]}),!n&&e.jsxs("div",{children:[e.jsxs("span",{className:"font-medium",children:[s("Slug"),":"]})," ",t.slug]}),e.jsxs("div",{children:[e.jsxs("span",{className:"font-medium",children:[s("Type"),":"]})," ",t.pageType]})]})]}),e.jsxs("form",{onSubmit:q,className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(a.Label,{htmlFor:"name",className:"text-sm",children:s("Name")}),e.jsx(a.Input,{id:"name",value:d,onChange:l=>D(l.target.value),required:!0})]}),!n&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(a.Label,{htmlFor:"slug",className:"text-sm",children:s("Slug")}),e.jsx(A.SlugInput,{value:m,onChange:l=>I(l),parentSlug:f,onValidationChange:l=>{i(l?null:s("Invalid slug"))}})]}),o&&e.jsxs(a.Alert,{variant:"destructive",className:"py-2",children:[e.jsx(C.AlertCircle,{className:"h-4 w-4"}),e.jsx("span",{className:"text-sm",children:o})]}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(a.Button,{type:"button",variant:"outline",onClick:u,disabled:r,children:s("Cancel")}),e.jsx(a.Button,{type:"submit",disabled:!d.trim()||!n&&!m.trim()||r||y,children:s(r||y?"Duplicating...":"Duplicate")})]})]})]})})};exports.default=w;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),p=require("./index-B1OACNv-.cjs"),N=require("@tanstack/react-query"),v=require("sonner"),E=require("@chaibuilder/sdk"),a=require("@chaibuilder/sdk/ui"),P=require("lodash-es"),C=require("lucide-react"),g=require("react"),A=require("./slug-input-BbkCbVMY.cjs"),T=()=>{const t=p.useApiUrl(),u=N.useQueryClient(),h=p.useFetch();return N.useMutation({mutationFn:async({pageId:s,name:x,slug:r})=>{const o={pageId:s,name:x};return r&&(o.slug=r),await h(t,{action:"DUPLICATE_PAGE",data:o})},onSuccess:()=>{u.invalidateQueries({queryKey:[p.ACTIONS.GET_WEBSITE_PAGES]}),v.toast.success("Page duplicated successfully")},onError:s=>{v.toast.error("Failed to duplicate page",{description:s.message||"An error occurred while duplicating the page"})}})},w=({page:t,onClose:u,closePanel:h=()=>{}})=>{const{t:s}=E.useTranslation(),{mutate:x,isPending:r}=T(),[o,i]=g.useState(null),[d,D]=g.useState(`${t.name} (Copy)`),b=p.useChangePage(),n=P.isEmpty(t.slug),[m,I]=g.useState(n?"":`${t.slug.split("/").pop()}-copy`),f=n?"":P.initial(t.slug.split("/")).join("/"),[y,j]=g.useState(!1),q=l=>{if(l.preventDefault(),!d.trim()){i(s("Name is required"));return}if(!n&&!m.trim()){i(s("Slug is required"));return}i(null),j(!0);const S={pageId:t.id,name:d};n||(S.slug=`${f}/${m}`),x(S,{onSuccess:c=>{j(!1),u(),b(c.id,h)},onError:c=>{j(!1),c.code==="SLUG_EXISTS"?i(s("A page with this slug already exists. Please choose a different slug.")):c.code==="INVALID_SLUG"?i(s("The slug format is invalid. Please use only lowercase letters, numbers, and hyphens.")):c.code==="PERMISSION_DENIED"?i(s("You don't have permission to duplicate this page.")):i(c.message||s("Failed to duplicate page. Please try again later."))}})};return e.jsx(a.Dialog,{open:!!t,onOpenChange:u,children:e.jsxs(a.DialogContent,{className:"sm:max-w-[425px]",children:[e.jsxs(a.DialogHeader,{children:[e.jsx(a.DialogTitle,{children:s("Duplicate Page")}),e.jsx(a.DialogDescription,{children:s("Create a copy of the page with a new name and slug")})]}),e.jsxs("div",{className:"mb-4 rounded-md bg-gray-50 p-3",children:[e.jsxs("h3",{className:"mb-1 text-sm font-medium",children:[s("Duplicating:"),":"]}),e.jsxs("div",{className:"flex flex-col gap-1 text-sm text-gray-700",children:[e.jsxs("div",{children:[e.jsxs("span",{className:"font-medium",children:[s("Name"),":"]})," ",t.name]}),!n&&e.jsxs("div",{children:[e.jsxs("span",{className:"font-medium",children:[s("Slug"),":"]})," ",t.slug]}),e.jsxs("div",{children:[e.jsxs("span",{className:"font-medium",children:[s("Type"),":"]})," ",t.pageType]})]})]}),e.jsxs("form",{onSubmit:q,className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(a.Label,{htmlFor:"name",className:"text-sm",children:s("Name")}),e.jsx(a.Input,{id:"name",value:d,onChange:l=>D(l.target.value),required:!0})]}),!n&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(a.Label,{htmlFor:"slug",className:"text-sm",children:s("Slug")}),e.jsx(A.SlugInput,{value:m,onChange:l=>I(l),parentSlug:f,onValidationChange:l=>{i(l?null:s("Invalid slug"))}})]}),o&&e.jsxs(a.Alert,{variant:"destructive",className:"py-2",children:[e.jsx(C.AlertCircle,{className:"h-4 w-4"}),e.jsx("span",{className:"text-sm",children:o})]}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(a.Button,{type:"button",variant:"outline",onClick:u,disabled:r,children:s("Cancel")}),e.jsx(a.Button,{type:"submit",disabled:!d.trim()||!n&&!m.trim()||r||y,children:s(r||y?"Duplicating...":"Duplicate")})]})]})]})})};exports.default=w;
@@ -4,7 +4,7 @@ import { DropdownMenu as h, DropdownMenuTrigger as p, Button as m, DropdownMenuC
4
4
  import { get as v } from "lodash-es";
5
5
  import { ChevronDown as w } from "lucide-react";
6
6
  import { useRef as b, useEffect as N } from "react";
7
- import { k as y } from "./index-DRQI9rlW.js";
7
+ import { k as y } from "./index-DdQbaicX.js";
8
8
  const D = ({
9
9
  isDefaultLang: e,
10
10
  searchQuery: l,
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),x=require("@chaibuilder/sdk"),a=require("@chaibuilder/sdk/ui"),h=require("lodash-es"),p=require("lucide-react"),d=require("react"),g=require("./index-CyHmr87X.cjs"),f=({isDefaultLang:r,searchQuery:l,setSearchQuery:c})=>e.jsx(a.Input,{type:"text",autoFocus:!0,value:r?l:"",onChange:t=>c(t.target.value),placeholder:r?"Search pages...":"To search select default language",disabled:!r,onKeyDown:t=>t.stopPropagation()}),m=({dynamicPage:r,setDynamicPage:l,searchQuery:c,setSearchQuery:t,dynamicPages:n})=>{const{selectedLang:o,fallbackLang:i}=x.useLanguages(),u=(o==null?void 0:o.length)===0;return e.jsxs(a.DropdownMenu,{children:[e.jsx(a.DropdownMenuTrigger,{asChild:!0,children:e.jsxs(a.Button,{variant:"ghost",className:"w-max focus:outline-none focus:ring-0 border-[0px] rounded-md py-1 text-sm h-max border border-gray-200 hover:bg-gray-100 pl-4",children:[r?h.get(r,"name"):"Select Page",e.jsx(p.ChevronDown,{className:"ml-2 h-4 w-4"})]})}),e.jsxs(a.DropdownMenuContent,{className:"w-96 divide-y shadow-xl p-0 max-h-[75vh]",children:[e.jsx("div",{className:"p-1.5 bg-gray-50/30",children:e.jsx(f,{isDefaultLang:u,searchQuery:c,setSearchQuery:t})}),(n==null?void 0:n.length)===0?e.jsx("div",{className:"h-24 text-xs flex items-center justify-center",children:"No pages found"}):n==null?void 0:n.map(s=>e.jsx(a.DropdownMenuItem,{onClick:()=>l(s),disabled:u?i!==s.lang:o!==s.lang,className:`flex flex-col justify-start cursor-pointer overflow-x-auto whitespace-nowrap no-scrollbar ${s.id===(r==null?void 0:r.id)?"bg-blue-50":"hover:bg-gray-50"}`,children:e.jsx("div",{className:"w-full text-xs whitespace-nowrap px-2 py-[2px]",children:e.jsxs("div",{className:"flex items-center gap-x-2",children:[e.jsx("span",{className:"font-medium",children:s.name}),e.jsx("span",{className:"font-mono font-medium text-gray-500 text-xs rounded-full px-2 py-[1px] border border-gray-300 truncate",children:s.slug})]})})},s.id))]})]})},j=()=>{const{dynamicPage:r,dynamicPages:l,allLangPages:c,selectedLang:t,searchQuery:n,updateDynamicPage:o,updateSearchQuery:i,onChangeLanguage:u}=g.useDynamicPageSelector(),s=d.useRef(void 0);return d.useEffect(()=>{s.current!==t&&r&&(u(),s.current=t)},[t,l]),e.jsx("div",{className:"relative",children:e.jsx(m,{dynamicPage:r,setDynamicPage:o,searchQuery:n,setSearchQuery:i,dynamicPages:c})})};exports.default=j;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),x=require("@chaibuilder/sdk"),a=require("@chaibuilder/sdk/ui"),h=require("lodash-es"),p=require("lucide-react"),d=require("react"),g=require("./index-B1OACNv-.cjs"),f=({isDefaultLang:r,searchQuery:l,setSearchQuery:c})=>e.jsx(a.Input,{type:"text",autoFocus:!0,value:r?l:"",onChange:t=>c(t.target.value),placeholder:r?"Search pages...":"To search select default language",disabled:!r,onKeyDown:t=>t.stopPropagation()}),m=({dynamicPage:r,setDynamicPage:l,searchQuery:c,setSearchQuery:t,dynamicPages:n})=>{const{selectedLang:o,fallbackLang:i}=x.useLanguages(),u=(o==null?void 0:o.length)===0;return e.jsxs(a.DropdownMenu,{children:[e.jsx(a.DropdownMenuTrigger,{asChild:!0,children:e.jsxs(a.Button,{variant:"ghost",className:"w-max focus:outline-none focus:ring-0 border-[0px] rounded-md py-1 text-sm h-max border border-gray-200 hover:bg-gray-100 pl-4",children:[r?h.get(r,"name"):"Select Page",e.jsx(p.ChevronDown,{className:"ml-2 h-4 w-4"})]})}),e.jsxs(a.DropdownMenuContent,{className:"w-96 divide-y shadow-xl p-0 max-h-[75vh]",children:[e.jsx("div",{className:"p-1.5 bg-gray-50/30",children:e.jsx(f,{isDefaultLang:u,searchQuery:c,setSearchQuery:t})}),(n==null?void 0:n.length)===0?e.jsx("div",{className:"h-24 text-xs flex items-center justify-center",children:"No pages found"}):n==null?void 0:n.map(s=>e.jsx(a.DropdownMenuItem,{onClick:()=>l(s),disabled:u?i!==s.lang:o!==s.lang,className:`flex flex-col justify-start cursor-pointer overflow-x-auto whitespace-nowrap no-scrollbar ${s.id===(r==null?void 0:r.id)?"bg-blue-50":"hover:bg-gray-50"}`,children:e.jsx("div",{className:"w-full text-xs whitespace-nowrap px-2 py-[2px]",children:e.jsxs("div",{className:"flex items-center gap-x-2",children:[e.jsx("span",{className:"font-medium",children:s.name}),e.jsx("span",{className:"font-mono font-medium text-gray-500 text-xs rounded-full px-2 py-[1px] border border-gray-300 truncate",children:s.slug})]})})},s.id))]})]})},j=()=>{const{dynamicPage:r,dynamicPages:l,allLangPages:c,selectedLang:t,searchQuery:n,updateDynamicPage:o,updateSearchQuery:i,onChangeLanguage:u}=g.useDynamicPageSelector(),s=d.useRef(void 0);return d.useEffect(()=>{s.current!==t&&r&&(u(),s.current=t)},[t,l]),e.jsx("div",{className:"relative",children:e.jsx(m,{dynamicPage:r,setDynamicPage:o,searchQuery:n,setSearchQuery:i,dynamicPages:c})})};exports.default=j;