@chaibuilder/pages 0.4.12 → 0.4.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{B4MFY5CR-U296-XCc.js → B4MFY5CR-BAaAGAXs.js} +1 -1
- package/dist/{B4MFY5CR-CMKhm_cO.cjs → B4MFY5CR-CeGZGu8R.cjs} +1 -1
- package/dist/{HO4MOOFI-Cl7Y_Hiz.cjs → HO4MOOFI-C1bDs1HY.cjs} +1 -1
- package/dist/{HO4MOOFI-DlO9_sj0.js → HO4MOOFI-CAG7BWJu.js} +2 -2
- package/dist/{HUY7CZI3-DGBcR9kM.js → HUY7CZI3-BiyRQa11.js} +2 -2
- package/dist/{HUY7CZI3-DIo60go4.cjs → HUY7CZI3-CZ6PS0vP.cjs} +1 -1
- package/dist/{digital-asset-manager-pEAK8sn7.js → digital-asset-manager-C_IzloX5.js} +1 -1
- package/dist/{digital-asset-manager-ITE5Abrb.cjs → digital-asset-manager-I67frLkV.cjs} +1 -1
- package/dist/index-GG8u_jcv.cjs +2 -0
- package/dist/{index-CMdQT0mW.js → index-HGE7qAuk.js} +1356 -1347
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/dist/index-B9Lp7kXg.cjs +0 -2
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("./index-
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("./index-GG8u_jcv.cjs"),t=require("@chaibuilder/sdk");exports.PermissionChecker=e.PermissionChecker;exports.default=e.ChaiBuilderPages;exports.registerChaiLoginComponent=e.registerLoginComponent;exports.useChaiAuth=e.useChaiAuth;exports.useChaiCurrentPage=e.useCurrentPage;exports.useChaiFetch=e.useChaiFetch;exports.useChaiUserInfo=e.useChaiUserInfo;exports.useFetch=e.useFetch;exports.useFetchUpload=e.useFetchUpload;exports.useLanguagePages=e.useLanguagePages;exports.useUserPermissions=e.useUserRoleAndPermissions;exports.useWebsitePages=e.useWebsitePages;exports.useWebsiteSetting=e.useWebsiteSetting;Object.keys(t).forEach(s=>{s!=="default"&&!Object.prototype.hasOwnProperty.call(exports,s)&&Object.defineProperty(exports,s,{enumerable:!0,get:()=>t[s]})});
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a0 as s, _ as i, a1 as t, a6 as u, a2 as r, a8 as o, aa as h, X as n, a9 as g, a3 as C, a7 as m, a4 as P, a5 as c } from "./index-
|
|
1
|
+
import { a0 as s, _ as i, a1 as t, a6 as u, a2 as r, a8 as o, aa as h, X as n, a9 as g, a3 as C, a7 as m, a4 as P, a5 as c } from "./index-HGE7qAuk.js";
|
|
2
2
|
export * from "@chaibuilder/sdk";
|
|
3
3
|
export {
|
|
4
4
|
s as PermissionChecker,
|
package/package.json
CHANGED
package/dist/index-B9Lp7kXg.cjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";var Bs=e=>{throw TypeError(e)};var Gs=(e,t,n)=>t.has(e)||Bs("Cannot "+n);var O=(e,t,n)=>(Gs(e,t,"read from private field"),n?n.call(e):t.get(e)),ce=(e,t,n)=>t.has(e)?Bs("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),oe=(e,t,n,r)=>(Gs(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n);const s=require("react/jsx-runtime"),g=require("lodash-es"),p=require("react"),Ve=require("jotai"),k=require("@tanstack/react-query"),te=require("sonner"),J=require("@chaibuilder/sdk"),c=require("@chaibuilder/sdk/ui"),P=require("lucide-react"),Mt=require("date-fns"),Ys=require("@chaibuilder/runtime"),Ht=require("zod"),lr=require("@chaibuilder/sdk/web-blocks");function cr(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}const ge=cr(p),_e={ab:"Abkhazian",aa:"Afar",af:"Afrikaans",ak:"Akan",sq:"Albanian",am:"Amharic",ar:"Arabic",an:"Aragonese",hy:"Armenian",as:"Assamese",av:"Avaric",ae:"Avestan",ay:"Aymara",az:"Azerbaijani",bm:"Bambara",ba:"Bashkir",eu:"Basque",be:"Belarusian",bn:"Bengali",bh:"Bihari",bi:"Bislama",bs:"Bosnian",br:"Breton",bg:"Bulgarian",my:"Burmese",ca:"Catalan",ch:"Chamorro",ce:"Chechen",ny:"Chichewa",zh:"Chinese","zh-Hans":"Chinese (Simplified)","zh-Hant":"Chinese (Traditional)",cv:"Chuvash",kw:"Cornish",co:"Corsican",cr:"Cree",hr:"Croatian",cs:"Czech",da:"Danish",dv:"Maldivian",nl:"Dutch",dz:"Dzongkha",en:"English",eo:"Esperanto",et:"Estonian",ee:"Ewe",fo:"Faroese",fj:"Fijian",fi:"Finnish",fr:"French",ff:"Fula, Pular",gl:"Galician",gd:"Gaelic (Scottish)",gv:"Manx",ka:"Georgian",de:"German",el:"Greek",kl:"Kalaallisut",gn:"Guarani",gu:"Gujarati",ht:"Haitian Creole",ha:"Hausa",he:"Hebrew",hz:"Herero",hi:"Hindi",ho:"Hiri Motu",hu:"Hungarian",is:"Icelandic",io:"Ido",ig:"Igbo",id:"Indonesian",ia:"Interlingua",ie:"Interlingue",iu:"Inuktitut",ik:"Inupiak",ga:"Irish",it:"Italian",ja:"Japanese",jv:"Javanese",kn:"Kannada",kr:"Kanuri",ks:"Kashmiri",kk:"Kazakh",km:"Khmer",ki:"Kikuyu",rw:"Kinyarwanda",rn:"Kirundi",ky:"Kyrgyz",kv:"Komi",kg:"Kongo",ko:"Korean",ku:"Kurdish",kj:"Kwanyama",lo:"Lao",la:"Latin",lv:"Latvian",li:"Limburgish",ln:"Lingala",lt:"Lithuanian",lu:"Luga-Katanga",lg:"Luganda, Ganda",lb:"Luxembourgish",mk:"Macedonian",mg:"Malagasy",ms:"Malay",ml:"Malayalam",mt:"Maltese",mi:"Maori",mr:"Marathi",mh:"Marshallese",mo:"Moldavian",mn:"Mongolian",na:"Nauru",nv:"Navajo",ng:"Ndonga",nd:"Northern Ndebele",ne:"Nepali",no:"Norwegian",nb:"Norwegian bokmål",nn:"Norwegian nynorsk",ii:"Sichuan Yi",oc:"Occitan",oj:"Ojibwe",cu:"Old Church Slavonic",or:"Oriya",om:"Oromo",os:"Ossetian",pi:"Pāli",ps:"Pashto, Pushto",fa:"Persian (Farsi)",pl:"Polish",pt:"Portuguese",pa:"Punjabi (Eastern)",qu:"Quechua",rm:"Romansh",ro:"Romanian",ru:"Russian",se:"Sami",sm:"Samoan",sg:"Sango",sa:"Sanskrit",sr:"Serbian",sh:"Serbo-Croatian",st:"Sesotho",tn:"Setswana",sn:"Shona",sd:"Sindhi",si:"Sinhalese",ss:"Swati",sk:"Slovak",sl:"Slovenian",so:"Somali",nr:"Southern Ndebele",es:"Spanish",su:"Sundanese",sw:"Swahili (Kiswahili)",sv:"Swedish",tl:"Tagalog",ty:"Tahitian",tg:"Tajik",ta:"Tamil",tt:"Tatar",te:"Telugu",th:"Thai",bo:"Tibetan",ti:"Tigrinya",to:"Tonga",ts:"Tsonga",tr:"Turkish",tk:"Turkmen",tw:"Twi",ug:"Uyghur",uk:"Ukrainian",ur:"Urdu",uz:"Uzbek",ve:"Venda",vi:"Vietnamese",vo:"Volapük",wa:"Wallon",cy:"Welsh",wo:"Wolof",fy:"Western Frisian",xh:"Xhosa",yi:"Yiddish",yo:"Yoruba",za:"Zhuang, Chuang",zu:"Zulu"},_={ASK_AI:"ASK_AI",GET_DRAFT_PAGE:"GET_DRAFT_PAGE",CREATE_PAGE:"CREATE_PAGE",UPDATE_PAGE:"UPDATE_PAGE",DELETE_PAGE:"DELETE_PAGE",CHANGE_SLUG:"CHANGE_SLUG",TAKE_OFFLINE:"TAKE_OFFLINE",PUBLISH_PAGE:"PUBLISH_PAGE",PUBLISH_CHANGES:"PUBLISH_CHANGES",ADD_NEW_LANGUAGE:"ADD_NEW_LANGUAGE",EDIT_LANGUAGE:"EDIT_LANGUAGE",DELETE_LANGUAGE:"DELETE_LANGUAGE",GET_CHANGES:"GET_CHANGES",GET_SERVER_BLOCK:"GET_SERVER_BLOCK",GET_LANGUAGE_PAGES:"GET_LANGUAGE_PAGES",GET_PROJECT_PAGES:"GET_PROJECT_PAGES",GET_WEBSITE_PAGES:"GET_WEBSITE_PAGES",UPDATE_WEBSITE_SETTINGS:"UPDATE_WEBSITE_SETTINGS",GET_COLLECTIONS:"GET_COLLECTIONS",GET_PAGE_TYPES:"GET_PAGE_TYPES",SEARCH_PAGES:"SEARCH_PAGES",GET_WEBSITE_DRAFT_SETTINGS:"GET_WEBSITE_DRAFT_SETTINGS",AI_CONTEXT:"AI_CONTEXT",GET_WEBSITE_DATA:"GET_WEBSITE_DATA",UPDATE_WEBSITE_DATA:"UPDATE_WEBSITE_DATA",GET_CHAI_USER:"GET_CHAI_USER",RELEASE_LOCK:"RELEASE_LOCK",GET_SEO_FIELDS:"GET_SEO_FIELDS",GET_BUILDER_PAGE_DATA:"GET_BUILDER_PAGE_DATA",GET_PAGE_REVISIONS:"GET_PAGE_REVISIONS",DELETE_PAGE_REVISION:"DELETE_PAGE_REVISION",RESTORE_PAGE_REVISION:"RESTORE_PAGE_REVISION",GET_ROLE_AND_PERMISSIONS:"GET_ROLE_AND_PERMISSIONS",UPSERT_LIBRARY_ITEM:"UPSERT_LIBRARY_ITEM",GET_LIBRARIES:"GET_LIBRARIES",GET_LIBRARY_ITEM:"GET_LIBRARY_ITEM",GET_LIBRARY_ITEMS:"GET_LIBRARY_ITEMS",DELETE_LIBRARY_ITEM:"DELETE_LIBRARY_ITEM",MARK_AS_TEMPLATE:"MARK_AS_TEMPLATE",UNMARK_AS_TEMPLATE:"UNMARK_AS_TEMPLATE",GET_TEMPLATES_BY_TYPE:"GET_TEMPLATES_BY_TYPE",UPLOAD_ASSET:"UPLOAD_ASSET",DELETE_ASSET:"DELETE_ASSET",UPDATE_ASSET:"UPDATE_ASSET",GET_ASSETS:"GET_ASSETS"},W="chaibuilder";let ur=0;function Ms(e,t){const n=`atom${++ur}`,r={toString(){return n}};return typeof e=="function"?r.read=e:(r.init=e,r.read=dr,r.write=hr),t&&(r.write=t),r}function dr(e){return e(this)}function hr(e,t,n){return t(this,typeof n=="function"?n(e(this)):n)}const mr=Symbol(""),fr=e=>typeof(e==null?void 0:e.then)=="function";function gr(e=()=>{try{return window.localStorage}catch{return}},t){var n;let r,a;const i={getItem:(u,d)=>{var f,h;const v=y=>{if(y=y||"",r!==y){try{a=JSON.parse(y,t==null?void 0:t.reviver)}catch{return d}r=y}return a},E=(h=(f=e())==null?void 0:f.getItem(u))!=null?h:null;return fr(E)?E.then(v):v(E)},setItem:(u,d)=>{var f;return(f=e())==null?void 0:f.setItem(u,JSON.stringify(d,void 0))},removeItem:u=>{var d;return(d=e())==null?void 0:d.removeItem(u)}},o=u=>(d,f,h)=>u(d,v=>{let E;try{E=JSON.parse(v||"")}catch{E=h}f(E)});let l;try{l=(n=e())==null?void 0:n.subscribe}catch{}return!l&&typeof window<"u"&&typeof window.addEventListener=="function"&&window.Storage&&(l=(u,d)=>{if(!(e()instanceof window.Storage))return()=>{};const f=h=>{h.storageArea===e()&&h.key===u&&d(h.newValue)};return window.addEventListener("storage",f),()=>{window.removeEventListener("storage",f)}}),l&&(i.subscribe=o(l)),i}const pr=gr();function xr(e,t,n=pr,r){const a=Ms(t);return a.onMount=o=>{o(n.getItem(e,t));let l;return n.subscribe&&(l=n.subscribe(e,o,t)),l},Ms(o=>o(a),(o,l,u)=>{const d=typeof u=="function"?u(o(a)):u;return d===mr?(l(a,t),n.removeItem(e)):d instanceof Promise?d.then(f=>(l(a,f),n.setItem(e,f))):(l(a,d),n.setItem(e,d))})}const yr=xr("__chai__user",null),De=()=>{const[e,t]=Ve.useAtom(yr),n=p.useCallback(()=>{t(null)},[t]);return{isLoggedIn:!!e,user:e,setUser:t,logout:n}},Xs=()=>{const{user:e,setUser:t,logout:n}=De(),r=es(),a=k.useQueryClient();return k.useQuery({queryKey:["refresh_token"],queryFn:async()=>{const i=await fetch(r,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${e==null?void 0:e.accessToken}`},body:JSON.stringify({action:"REFRESH_TOKEN",data:{accessToken:e==null?void 0:e.accessToken,refreshToken:e==null?void 0:e.refreshToken}})});if(i.ok){const o=await i.json();t(o),a.invalidateQueries({queryKey:[W],refetchType:"all"})}else n()},retry:!1,enabled:!1})},Zs=async(e,t,n={})=>await fetch(e,{method:"POST",headers:{"Content-Type":"application/json",...n},body:JSON.stringify(t)}),vr=()=>{const{user:e}=De(),t=Re("onSessionExpired"),n=p.useMemo(()=>e==null?void 0:e.accessToken,[e==null?void 0:e.accessToken]);return p.useCallback(async(r,a,i={})=>{if(!n){console.log("no auth token");return}try{const o=await fetch(r,{method:"POST",body:a,headers:{...i,Authorization:`Bearer ${n}`,"x-chai-upload":"true"}});if(o.status===401)throw t(),new Error("Session expired");if(o.status===400)throw new Error((await o.json()).error);return await o.json()}catch(o){throw console.log("Something went wrong",a,o),o}},[n,t])},X=()=>{const{user:e}=De(),t=p.useMemo(()=>e==null?void 0:e.accessToken,[e==null?void 0:e.accessToken]),{refetch:n}=Xs();return p.useCallback(async(r,a,i={})=>{if(t)try{const o=g.get(a,"action","").toLowerCase(),l=await Zs(r+(o?`?action=${o}`:""),a,{...i,Authorization:`Bearer ${t}`});if(l.status===401&&await n(),l.status===400)throw new Error((await l.json()).error);return await l.json()}catch(o){throw console.log("Something went wrong",a,o),o}},[t,n])},Js=()=>{const e=se(),t=k.useQueryClient(),n=X();return k.useMutation({mutationFn:async r=>n(e,{action:_.RELEASE_LOCK,data:r}),onSuccess:()=>{t.invalidateQueries({queryKey:[W,_.GET_DRAFT_PAGE]})}})},en=()=>{const e=se(),t=k.useQueryClient(),n=X();return k.useMutation({mutationFn:async r=>n(e,{action:_.UPDATE_WEBSITE_SETTINGS,data:r}),onSuccess:(r,a)=>{var i;t.invalidateQueries({queryKey:[W,_.GET_WEBSITE_DRAFT_SETTINGS]}),(i=a==null?void 0:a.settings)!=null&&i.theme||te.toast.success("Website settings updated successfully.")},onError:r=>{te.toast.error("Failed to update website settings",{description:r.message})}})},Er=()=>{const e=se(),t=k.useQueryClient(),n=X();return k.useMutation({mutationFn:async r=>n(e,{action:_.UPDATE_WEBSITE_DATA,data:r}),onSuccess:()=>{t.invalidateQueries({queryKey:[W,_.GET_WEBSITE_DATA]}),te.toast.success("Website data updated successfully.")},onError:r=>{te.toast.error("Failed to update website data",{description:r.message})}})};function Ne(){const[e,t]=p.useState(new URLSearchParams(window.location.search));return p.useEffect(()=>{const n=()=>{t(new URLSearchParams(window.location.search))};return window.addEventListener("popstate",n),()=>{window.removeEventListener("popstate",n)}},[]),[e,t]}const br=Ve.atom({}),tn=()=>Ve.useAtom(br),jr=()=>{const[e]=Ne(),t=e.get("page"),n=p.useRef(""),{mutate:r}=Js();p.useEffect(()=>{!g.isEmpty(n.current)&&t!==n.current&&r({id:n.current}),n.current=t},[t,r,n])},Re=(e,t)=>{const[n]=tn();return p.useMemo(()=>g.get(n,e,t),[n,e,t])},se=()=>Re("apiUrl","/chai/api"),es=()=>Re("usersApiUrl","/chai/users"),Sr=()=>Re("assetsApiUrl","/chai/assets"),mt=()=>{const e=se(),[t]=Ne(),n=t.get("page"),r=X();return k.useQuery({queryKey:[W,_.GET_LANGUAGE_PAGES,n],initialData:[],queryFn:async()=>{if(!n)return null;const a=await r(e,{action:_.GET_LANGUAGE_PAGES,data:{id:n}});return g.reverse(g.sortBy(a,"primaryPage"))},enabled:!!n})},ft=()=>{const e=se(),t=X();return k.useQuery({queryKey:[_.GET_WEBSITE_DRAFT_SETTINGS],initialData:{theme:{},fallbackLang:"en",languages:[]},queryFn:async()=>t(e,{action:_.GET_WEBSITE_DRAFT_SETTINGS,data:{draft:!0}})})},sn=e=>{const{fallbackLang:t}=J.useLanguages(),{data:n}=ft(),{data:r,isFetching:a}=mt(),i=p.useMemo(()=>{const o={[t]:!0};return g.each(g.get(n,"languages"),l=>{const u=g.find(r,{lang:l});o[l]=!!u}),o},[t,r,n]);return a||g.isEmpty(e)||e&&i[e]},Es=()=>{const e=k.useQueryClient(),{data:t}=k.useQuery({queryKey:["chaibuilder",_.AI_CONTEXT],initialData:"",queryFn:()=>""});return{setAiContext:p.useCallback(r=>{e.setQueryData([_.AI_CONTEXT],r)},[e]),aiContext:t}},Rt=()=>{const e=X(),t=se();return k.useQuery({queryKey:[W,_.GET_WEBSITE_PAGES],staleTime:1e3*60*5,queryFn:async()=>e(t,{action:_.GET_WEBSITE_PAGES})||[]})},wr=Ve.atom({lastSaved:void 0}),bs=()=>Ve.useAtom(wr),Ae=()=>{const[e]=Ne(),t=e.get("page"),{data:n,isFetching:r}=Rt();return{data:p.useMemo(()=>g.find(n,{id:t})||{},[n,t]),isFetching:r}},gt=e=>{const t=es(),n=X();return k.useQuery({queryKey:[W,"chaiUserInfo",e],queryFn:async()=>await n(t,{action:_.GET_CHAI_USER,data:{userId:e}}),enabled:!!e&&e!=="EXPIRED"})},Nr=Ve.atom(void 0),Ut=()=>{const[e]=Ne(),t=e.get("page"),{user:n}=De(),[r,a]=Ve.useAtom(Nr);return p.useMemo(()=>({isLocked:t&&(n==null?void 0:n.id)!==r,currentEditor:r,setCurrentEditor:i=>a(i)}),[n==null?void 0:n.id,r,t,a])},nn=()=>{const[e]=Ne(),t=e.get("page"),n=se(),{setAiContext:r}=Es(),{setCurrentEditor:a}=Ut(),[,i]=bs(),o=X();return k.useQuery({queryKey:[W,_.GET_DRAFT_PAGE,t],staleTime:1/0,gcTime:1/0,queryFn:async()=>{a("");const l=await o(n,{action:_.GET_DRAFT_PAGE,data:{id:t,draft:!0}});a(l.currentEditor);const u=l.blocks??[],d=g.find(u,{_type:"@chai/ai-context"});return r(g.get(d,"_value","")||""),i(f=>({...f,lastSaved:l.lastSaved})),u},enabled:!!t})},rn=({pageType:e,lang:t})=>{const n=se(),r=X();return k.useQuery({queryKey:[W,_.GET_BUILDER_PAGE_DATA,e,t],initialData:{},queryFn:async()=>r(n,{action:_.GET_BUILDER_PAGE_DATA,data:{pageType:e,lang:t}}),enabled:!!e&&!!t})};function Ar({avatar:e,name:t,email:n,onTakeOver:r,currentEditor:a}){const[i,o]=p.useState(!1),l=()=>{o(!1),r()};return s.jsx("div",{className:"fixed bottom-0 left-0 right-0 z-[20] flex items-center justify-center w-screen top-14 bg-black/30 backdrop-blur-sm",children:s.jsxs(c.Card,{className:"w-full max-w-md mx-auto",children:[s.jsx(c.CardHeader,{className:"space-y-1",children:s.jsxs(c.CardTitle,{className:"flex items-center gap-2 text-2xl",children:[s.jsx(P.LockIcon,{className:"w-6 h-6 text-yellow-500"}),a==="EXPIRED"?"Editing access timed out":"Page locked for editing"]})}),s.jsx(c.CardContent,{className:"grid gap-4",children:a==="EXPIRED"?s.jsx("div",{children:s.jsx("p",{children:"Your editing access has been paused due to inactivity. Please refresh the page to continue"})}):s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center space-x-4",children:[e?s.jsx("img",{src:e,alt:t,className:"w-12 h-12 border border-gray-300 rounded-full"}):s.jsx(P.UserIcon,{className:"w-12 h-12 p-2 border border-gray-300 rounded-full"}),s.jsxs("div",{className:"space-y-1",children:[s.jsx("h3",{className:"font-semibold",children:t}),n&&s.jsx("p",{className:"text-sm text-muted-foreground",children:n})]})]}),s.jsx("div",{className:"text-sm mt-4",children:s.jsx("p",{children:"This user is currently editing the page. You cannot make changes."})})]})}),s.jsx(c.CardFooter,{children:a==="EXPIRED"?s.jsx("div",{children:s.jsx(c.Button,{className:"w-full",onClick:()=>window.location.reload(),variant:"destructive",children:"Refresh"})}):s.jsxs(c.AlertDialog,{open:i,onOpenChange:o,children:[s.jsx(c.AlertDialogTrigger,{asChild:!0,children:s.jsxs("span",{className:"flex flex-col items-center",children:[s.jsx(c.Button,{className:"w-full",variant:"destructive",children:"Take Over"}),s.jsx("p",{className:"mt-2 text-xs text-muted-foreground",children:"If you need to edit, you can take over the lock, but be aware that the other user might lose unsaved changes."})]})}),s.jsxs(c.AlertDialogContent,{className:"z-[99]",children:[s.jsxs(c.AlertDialogHeader,{children:[s.jsx(c.AlertDialogTitle,{children:"Are you sure you want to take over?"}),s.jsxs(c.AlertDialogDescription,{children:[s.jsxs("span",{className:"flex items-center space-x-2 text-yellow-500",children:[s.jsx(P.AlertTriangleIcon,{className:"w-5 h-5"}),s.jsx("span",{children:"This action might cause the other user to lose unsaved changes."})]}),s.jsx("br",{}),s.jsxs("span",{className:"mt-2",children:["By taking over, you will become the active editor of this page, and ",t," will lose their editing access."]})]})]}),s.jsxs(c.AlertDialogFooter,{children:[s.jsx(c.AlertDialogCancel,{children:"Cancel"}),s.jsx(c.AlertDialogAction,{onClick:l,children:"Yes, Take Over"})]})]})]})})]})})}const Tr=()=>{const{isLocked:e,currentEditor:t}=Ut(),{data:n}=gt(t),[r]=Ne(),a=r.get("page"),{mutate:i}=Js(),{isFetching:o}=nn(),l=p.useCallback(()=>{i({id:a})},[a,i]);return!e||o?s.jsx("div",{className:""}):s.jsx(Ar,{...n,name:(n==null?void 0:n.name)||"Unknown User",email:(n==null?void 0:n.email)||"",currentEditor:t??null,onTakeOver:l})},Cr=()=>{const[e,t]=Ne(),n=e.get("lang"),r=sn(n),{setSelectedLang:a}=J.useLanguages(),i=()=>{const l=new URLSearchParams(window.location.search);l.delete("lang");const u=l.toString(),d=`${window.location.pathname}${u?`?${u}`:""}`;window.history.pushState({},"",d),t(l),a(""),window.dispatchEvent(new PopStateEvent("popstate"))};if(r)return null;const o=g.get(_e,n);return s.jsx("div",{className:"fixed bottom-0 left-0 right-0 z-[20] flex items-center justify-center w-screen top-14 bg-black/30 backdrop-blur-sm",children:s.jsxs(c.Card,{className:"w-full max-w-md mx-auto",children:[s.jsx(c.CardHeader,{className:"space-y-1",children:s.jsxs(c.CardTitle,{className:"flex items-center gap-2 text-2xl",children:[s.jsx(P.LockIcon,{className:"w-6 h-6 text-yellow-500"}),'Page missing for "',o,'" language.']})}),s.jsx(c.CardContent,{className:"grid gap-4",children:s.jsxs("div",{children:['Page is not available in the "',o,'" language. Either create the page in the "',o,'" language or switch to the base language.']})}),s.jsx(c.CardFooter,{children:s.jsx(c.Button,{onClick:i,className:"w-full",variant:"destructive",children:"Switch to default language"})})]})})},Pr=e=>{const t=se(),n=X();return k.useMutation({mutationFn:async r=>n(t,{action:_.UPSERT_LIBRARY_ITEM,data:r}),onSuccess:r=>{e(r)},onError:r=>{console.error("Error saving block:",r),te.toast.error("Failed to save block",{description:r instanceof Error?r.message:"Unknown error"})}})},_r=e=>{const t=se(),n=X();return k.useQuery({queryKey:[W,"uiBlockDetails",e],enabled:!!e,queryFn:async()=>{if(!e)return null;try{return await n(t,{action:_.GET_LIBRARY_ITEM,data:{id:e}})}catch(r){throw console.error(r),new Error("The block could not be found on the server. It may have been deleted.")}},retry:!1})},Ir=e=>{const t=se(),n=X();return k.useMutation({mutationFn:async r=>n(t,{action:_.DELETE_LIBRARY_ITEM,data:{id:r}}),onSuccess:()=>{e()},onError:r=>{console.error("Error deleting block:",r),te.toast.error("Failed to delete block",{description:r instanceof Error?r.message:"Unknown error"})}})},kr=({blockId:e,libBlockId:t,isOpen:n,onClose:r,blockName:a,trigger:i})=>{const[o,l]=p.useState(!1),u=J.useUpdateBlocksPropsRealtime(),d=Ir(()=>{u([e],{_libBlockId:void 0}),te.toast.success("Block deleted successfully"),l(!1),r()}),f=()=>{l(!0),d.mutate(t)},h=s.jsxs(c.Button,{type:"button",variant:"destructive",size:"sm",onClick:v=>v.preventDefault(),disabled:o,children:[s.jsx(P.Trash2,{className:"h-4 w-4 mr-2"}),"Delete"]});return s.jsxs(c.Popover,{open:n,onOpenChange:v=>!v&&r(),children:[s.jsx(c.PopoverTrigger,{asChild:!0,children:i||h}),s.jsx(c.PopoverContent,{className:"w-72 p-4 z-[9999]",sideOffset:5,align:"center",children:s.jsxs("div",{className:"space-y-3",children:[s.jsx("h4",{className:"font-medium",children:"Delete Block"}),s.jsxs("p",{className:"text-sm",children:["Are you sure you want to delete the block",s.jsxs("span",{className:"font-medium",children:[' "',a,'"']}),"?"]}),s.jsx("p",{className:"text-xs text-muted-foreground",children:"This block will be permanently removed from the library. This action cannot be undone."}),s.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[s.jsx(c.Button,{type:"button",variant:"outline",size:"sm",onClick:r,disabled:o,children:"Cancel"}),s.jsx(c.Button,{type:"button",variant:"destructive",size:"sm",onClick:f,disabled:o,children:o?"Deleting...":"Delete"})]})]})})]})},Lr=({blockId:e,libBlockId:t,blockName:n,size:r="sm",className:a="",close:i})=>{const[o,l]=p.useState(!1);return s.jsx(kr,{blockId:e,libBlockId:t,isOpen:o,onClose:()=>{l(!1),i()},blockName:n,trigger:s.jsxs(c.Button,{type:"button",variant:"destructive",size:r,className:a,onClick:()=>l(!0),children:[s.jsx(P.Trash2,{className:"h-4 w-4 mr-2"}),"Delete"]})})},Dr=()=>{const e=se(),t=X(),n=k.useQueryClient(),{data:r=[],isLoading:a,error:i}=k.useQuery({queryKey:[W,"library-groups"],queryFn:async()=>{try{return await t(e,{action:"GET_LIBRARY_GROUPS"})||[]}catch(u){return console.error("Error fetching library groups:",u),[]}},initialData:[]}),{mutateAsync:o,isPending:l}=k.useMutation({mutationFn:async u=>{if(!u.trim())throw new Error("Group name is required");return t(e,{action:"CREATE_BLOCK_GROUP",data:{name:u}})},onSuccess:()=>{n.invalidateQueries({queryKey:[W,"library-groups"]}),te.toast.success("Group created successfully")},onError:u=>{console.error("Error creating group:",u),te.toast.error("Failed to create group",{description:u instanceof Error?u.message:"Unknown error"})}});return{groups:r,isLoading:a,error:i,createGroup:o,isCreating:l}},Br=({value:e,onChange:t})=>{const[n,r]=p.useState(!1),[a,i]=p.useState(""),o=p.useRef(null),{groups:l}=Dr(),[u,d]=p.useState([{id:"hero",name:"Hero"},{id:"feature",name:"Feature"},{id:"footer",name:"Footer"},{id:"content",name:"Content"},{id:"testimonial",name:"Testimonial"},{id:"pricing",name:"Pricing"},{id:"login",name:"Login"},{id:"logos",name:"Logos"},{id:"about",name:"About"},{id:"banner",name:"Banner"},{id:"blog",name:"Blog"},{id:"careers",name:"Careers"},{id:"casestudy",name:"Casestudy"},{id:"changelog",name:"Changelog"},{id:"compare",name:"Compare"},{id:"contact",name:"Contact"},{id:"cta",name:"Cta"},{id:"faq",name:"Faq"},{id:"gallery",name:"Gallery"},{id:"integration",name:"Integration"},{id:"list",name:"List"},{id:"navbar",name:"Navbar"},{id:"product",name:"Product"},{id:"signup",name:"Signup"},{id:"stats",name:"Stats"},{id:"team",name:"Team"},{id:"timeline",name:"Timeline"}]),f=p.useMemo(()=>[...l,...u.filter(E=>!l.some(y=>y.id===E.id))],[l,u]),h=()=>{const E=a.trim();if(!E)return;const y={id:E,name:E};d(N=>[...N,y]),t(y.id),i(""),r(!1)};p.useEffect(()=>{n&&o.current&&o.current.focus()},[n]);const v=E=>{E.key==="Enter"&&(E.preventDefault(),h())};return p.useEffect(()=>{e&&!f.some(E=>E.id===e)&&t("")},[e,f,t]),n?s.jsxs("div",{className:"space-y-2",children:[s.jsx(c.Input,{ref:o,placeholder:"Enter new group name",value:a,onChange:E=>i(E.target.value),onKeyDown:v}),s.jsxs("div",{className:"flex justify-end gap-2",children:[s.jsx(c.Button,{variant:"outline",size:"sm",onClick:()=>r(!1),children:"Cancel"}),s.jsx(c.Button,{size:"sm",onClick:h,children:"Create"})]})]}):s.jsxs("div",{className:"flex gap-2",children:[s.jsxs("select",{className:"w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",value:e,onChange:E=>t(E.target.value),children:[s.jsx("option",{value:"",children:"Select a group"}),l.length>0&&s.jsx("optgroup",{label:"Library Groups",children:l.map(E=>s.jsx("option",{value:E.id,children:E.name},`lib-${E.id}`))}),u.length>0&&s.jsx("optgroup",{label:"Predefined Groups",children:u.filter(E=>!l.some(y=>y.id===E.id)).map(E=>s.jsx("option",{value:E.id,children:E.name},`local-${E.id}`))})]}),s.jsx(c.Button,{type:"button",size:"icon",variant:"outline",onClick:()=>r(!0),children:s.jsx(P.Plus,{className:"h-4 w-4"})})]})},Gr=1*1024*1024,Mr=({value:e,onChange:t})=>{const[n,r]=p.useState(!1),a=p.useRef(null),i=p.useCallback(u=>{var f;const d=(f=u.target.files)==null?void 0:f[0];if(d){if(d.size>Gr){te.toast.error("File too large",{description:`Maximum file size is 1mb. Selected file is ${(d.size/1024/1024).toFixed(2)}MB.`}),a.current&&(a.current.value="");return}try{r(!0);const h=new FileReader;h.onloadend=()=>{t(h.result),r(!1)},h.readAsDataURL(d)}catch(h){console.error("Error reading file:",h),r(!1),te.toast.error("Failed to process image",{description:h instanceof Error?h.message:"Unknown error"})}}},[t]),o=()=>{t(""),a.current&&(a.current.value="")},l=()=>{var u;(u=a.current)==null||u.click()};return s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(c.Input,{type:"file",ref:a,onChange:i,accept:"image/*",className:"hidden"}),s.jsx(c.Button,{type:"button",variant:"outline",onClick:l,disabled:n,className:"w-full",children:n?s.jsxs("span",{className:"flex items-center gap-2",children:[s.jsx("div",{className:"animate-spin h-4 w-4 border-2 border-current border-t-transparent rounded-full"}),"Uploading..."]}):s.jsxs("span",{className:"flex items-center gap-2",children:[s.jsx(P.ImageIcon,{className:"h-4 w-4"}),"Select image"]})}),e&&s.jsx(c.Button,{type:"button",variant:"outline",size:"icon",onClick:o,children:s.jsx(P.X,{className:"h-4 w-4"})})]}),e&&s.jsx("div",{className:"rounded-md max-h-[200px] h-[200px] overflow-hidden border aspect-video",children:s.jsx("img",{src:e,alt:"Preview",className:"w-full h-full object-contain"})})]})},he={...J.PERMISSIONS,ADD_PAGE:"add_page",EDIT_PAGE:"edit_page",EDIT_SLUG:"edit_slug",DELETE_PAGE:"delete_page",CHANGE_PAGE_TYPE:"change_page_type",PUBLISH_PAGE:"publish_page",UNPUBLISH_PAGE:"unpublish_page",MARK_AS_TEMPLATE:"mark_as_template",UNMARK_AS_TEMPLATE:"unmark_as_template",ADD_PARTIAL:"add_partial",EDIT_PARTIAL:"edit_partial",DELETE_PARTIAL:"delete_partial",PUBLISH_PARTIAL:"publish_partial",UNPUBLISH_PARTIAL:"unpublish_partial",EDIT_SEO:"edit_seo",RESTORE_REVISION:"restore_revision",DELETE_REVISION:"delete_revision",PUBLISH_THEME:"publish_theme",EDIT_SETTINGS:"edit_settings",ADD_LIBRARY_BLOCK:"create_library_block",ADD_LIBRARY_TEMPLATE:"add_library_template",EDIT_LIBRARY_BLOCK:"edit_library_block",EDIT_LIBRARY_TEMPLATE:"edit_library_template",DELETE_LIBRARY_BLOCK:"delete_library_block",DELETE_LIBRARY_TEMPLATE:"delete_library_template",ADD_MEDIA:"add_media",EDIT_MEDIA:"edit_media",DELETE_MEDIA:"delete_media"},Rr=e=>{const{blocks:t,close:n,blockId:r}=e,{getPartailBlocks:a}=J.usePartailBlocksStore(),i=t.find(T=>T._id===r),o=i==null?void 0:i._libBlockId,l=!!o,u=p.useMemo(()=>t.some(T=>T._type==="PartialBlock"||T._type==="GlobalBlock"),[t]),d=p.useMemo(()=>{let T=[];for(const L of t)if(L._type==="PartialBlock"||L._type==="GlobalBlock"){const R=a(L.partialBlockId);g.set(R,"0._parent",L._parent),T=[...T,...R]}else T.push(L);return T},[t,a]),[f,h]=p.useState(""),[v,E]=p.useState(""),[y,N]=p.useState(""),[b,A]=p.useState(""),[M,w]=p.useState({}),[S,I]=p.useState(!1),[D,le]=p.useState(l),[ne,B]=p.useState(!1),{hasPermission:U}=J.usePermissions(),C=U(he.DELETE_LIBRARY_BLOCK),F=J.useUpdateBlocksPropsRealtime(),re=()=>{F([r],{_libBlockId:void 0}),te.toast.success("Block delinked from library"),n()},{data:me,isLoading:ee,isError:fe}=_r(o);p.useEffect(()=>{fe&&l&&(B(!0),le(!1))},[fe,l]),p.useEffect(()=>{me&&!ee&&(h(me.name||""),E(me.group||""),N(me.description||""),A(me.preview||""),le(!1))},[me,ee]),p.useEffect(()=>{const T=f.trim().length>=2,L=v.trim()!=="";I(T&&L&&!u)},[f,v,u]);const V=()=>{const T={};return f.trim()?f.length<2&&(T.name="Name must be at least 2 characters"):T.name="Name is required",v||(T.group="Group is required"),w(T),Object.keys(T).length===0&&!u},{resetLibrary:pe}=J.useLibraryBlocks({id:""}),Q=Pr(T=>{l||F([r],{_libBlockId:T.id}),te.toast.success(`Block ${l?"updated":"saved"} successfully`),pe(T.library),n()}),x=async T=>{if(T.preventDefault(),!V())return;const L=d.map(R=>(g.has(R,"_libBlockId")&&delete R._libBlockId,R));Q.mutate({name:f.trim(),group:v,blocks:L,description:y.trim(),...b&&b.startsWith("data:")?{previewImage:b}:{},...l?{id:o}:{}})},m=Q.isPending;return D||ee?s.jsx("div",{className:"flex items-center justify-center p-8",children:s.jsx("div",{className:"h-8 w-8 animate-spin rounded-full border-4 border-primary border-t-transparent"})}):ne?s.jsxs("div",{className:"p-6 space-y-4",children:[s.jsx("div",{className:"text-destructive font-medium",children:"Block Not Found"}),s.jsx("p",{className:"text-sm text-muted-foreground",children:"This block could not be found on the server. It may have been deleted."}),s.jsxs("div",{className:"flex justify-end gap-2 pt-4",children:[s.jsx(c.Button,{type:"button",variant:"outline",onClick:n,children:"Cancel"}),s.jsx(c.Button,{onClick:re,variant:"destructive",children:"Delink Block"})]})]}):s.jsxs("div",{children:[u&&s.jsxs("div",{className:"mb-4 p-3 border border-destructive/50 bg-destructive/10 text-destructive rounded-md flex items-start gap-2",children:[s.jsx(P.AlertCircle,{className:"h-5 w-5 flex-shrink-0 mt-0.5"}),s.jsxs("div",{children:[s.jsx("p",{className:"font-medium",children:"Partial Blocks Detected"}),s.jsx("p",{className:"text-xs mt-1",children:"This block contains one or more Partial Blocks. Partial blocks will be merged into the library block"})]})]}),s.jsxs("form",{onSubmit:x,className:"space-y-4",children:[s.jsxs("div",{className:"space-y-2",children:[s.jsx(c.Label,{htmlFor:"name",className:M.name?"text-destructive":"",children:"Name"}),s.jsx(c.Input,{id:"name",placeholder:"Enter block name",value:f,onChange:T=>h(T.target.value),className:M.name?"border-destructive":""}),M.name&&s.jsx("p",{className:"text-xs text-destructive",children:M.name})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsx(c.Label,{htmlFor:"group",className:M.group?"text-destructive":"",children:"Group"}),s.jsx(Br,{value:v,onChange:E}),M.group&&s.jsx("p",{className:"text-xs text-destructive",children:M.group})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsx(c.Label,{htmlFor:"description",children:"Description (optional)"}),s.jsx(c.Input,{id:"description",placeholder:"Enter a brief description",className:"resize-none",value:y,onChange:T=>N(T.target.value)})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsx(c.Label,{htmlFor:"previewImage",children:"Preview Image (optional)"}),s.jsx(Mr,{value:b,onChange:A}),s.jsx("p",{className:"text-xs text-muted-foreground",children:"max 1mb"})]}),s.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[l&&C&&s.jsx(Lr,{blockId:r,libBlockId:o,blockName:f,className:"mr-auto",close:n}),s.jsx(c.Button,{type:"button",variant:"outline",onClick:n,disabled:m,children:"Cancel"}),s.jsx(c.Button,{type:"submit",disabled:m||!S,children:m?"Saving...":l?"Update Block":"Save Block"})]})]})]})},H={PREVIEW:"Preview",THEME:"Theme",SAVEDRAFT:"Save draft",SAVING:"Saving",SAVED:"Saved",PUBLISHED:"Published",PUBLISH:"Publish",UNPUBLISH:"Unpublish",WEBSITEDATA:"Website data",OPEN:"Open",EDIT_LANGUAGE:"Edit language",ADD_NEW_LANGUAGE:"Add new language page",ENTER_LANGUAGE_DETAILS:"Enter the details for the language",LANGUAGE:"Language",PAGE_NAME:"Page Name",SLUG:"Slug",UPDATE:"Update",UPDATING:"Updating...",ADDING:"Adding...",CHOOSE_LANGUAGE:"Choose language",ALL_AVAILABLE_LANGUAGE_PAGE:"All available language page is created.",TO_UPDATE_SLUG:"To update slug use 'Change slug' action",SLUG_SHOULD_START_WITH:" (Slug should start with /{lang})",CHOOSE_LANGUAGE_TO_ADD_SLUG:"Choose language to add slug",ENTER_PAGE_SLUG:"Enter page slug",ENTER_PAGE_NAME:"Enter page name",DELETE:"Delete",CHANGE_SLUG:"Change slug",PRIMARY:"Primary",SLUG_MUST_START_WITH:"Slug must start with /",EDIT:"Edit",UNPUBLISH_MSG:"Are you sure you want to unpublish",MARK_AS_TEMPLATE:"Mark as template",UNMARK_AS_TEMPLATE:"Unmark as template",PAGE_ADD_SUCCESS:"New page added successfully.",GLOBAL_BLOCK_ADD_SUCCESS:"New global block added successfully.",SEO_SETTINGS_UPDATE_SUCCESS:"SEO Settings updated successfully.",PAGE_UPDATE_SUCCESS:"Page updated successfully.",GLOBAL_BLOCK_UPDATE_SUCCESS:"Global block updated successfully.",PAGE_DELETE_SUCCESS:"Page deleted successfully.",GLOBAL_BLOCK_DELETE_SUCCESS:"Global block deleted successfully.",PAGE_UNPUBLISH_SUCCESS:"Page unpublished successfully.",GLOBAL_BLOCK_UNPUBLISH_SUCCESS:"Global block unpublished successfully.",PAGE_PUBLISH_SUCCESS:"Page published successfully.",GLOBAL_BLOCK_PUBLISH_SUCCESS:"Global block published successfully.",PAGES_PUBLISH_SUCCESS:"Your changes have been published successfully.",SLUG_CHANGE_SUCCESS:"Slug changed successfully."},Ur={SLUG_ALREADY_USED:"This slug is already in use. Please choose a different one."},Se=()=>{const e=se(),t=X();return k.useQuery({queryKey:[W,_.GET_PAGE_TYPES],initialData:[],queryFn:async()=>t(e,{action:_.GET_PAGE_TYPES})})},Or=e=>{const{data:t}=Se();return p.useMemo(()=>t==null?void 0:t.find(n=>n.key===e),[t,e])},Fr=()=>{const e=se(),t=X();return k.useMutation({mutationFn:async({pageType:n,query:r})=>{try{return t(e,{action:_.SEARCH_PAGES,data:{pageType:n,query:Array.isArray(r)&&r.length>0?r[0]:r}})||[]}catch(a){return console.error(a),[]}}})},an=()=>{const e=se(),t=k.useQueryClient(),n=X(),{data:r}=Se();return k.useMutation({mutationFn:async a=>(a.template&&console.log("Creating page from template:",a.template),await n(e,{action:_.CREATE_PAGE,data:a})),onSuccess:(a,i)=>{var l;i&&(i!=null&&i.primaryPage)?t.invalidateQueries({queryKey:[W,_.GET_LANGUAGE_PAGES,i==null?void 0:i.primaryPage]}):t.invalidateQueries({queryKey:[W,_.GET_WEBSITE_PAGES]});const o=i.template?`Page created from "${i.template.name}" template`:i.hasSlug===!1?"New "+((l=g.find(r,{key:i.pageType}))==null?void 0:l.name)+" added successfully":"New page added successfully";te.toast.success(o)},onError:(a,i)=>{const o=g.find(r,{key:i.pageType});te.toast.error(`Failed to add new ${o!=null&&o.hasSlug?"page":o.name}.`,{description:g.get(Ur,a.message,a.message)})}})},js=()=>{const e=se(),t=k.useQueryClient(),n=X(),{data:r}=Se();return k.useMutation({mutationFn:async a=>await n(e,{action:_.UPDATE_PAGE,data:a}),onSuccess:(a,i)=>{i&&(i!=null&&i.primaryPage||i!=null&&i.seo)?t.invalidateQueries({queryKey:[W,_.GET_LANGUAGE_PAGES,i==null?void 0:i.primaryPage]}):t.invalidateQueries({queryKey:[W,_.GET_WEBSITE_PAGES]})},onError:(a,i)=>{const o=g.find(r,{key:i.pageType});te.toast.error(`Failed to update ${o!=null&&o.hasSlug?"page":o.name}.`,{description:a.message})}})},qr=()=>{const e=se(),t=k.useQueryClient(),n=X(),{data:r}=Se();return k.useMutation({mutationFn:async a=>n(e,{action:_.DELETE_PAGE,data:{id:a==null?void 0:a.id}}),onSuccess:(a,i)=>{if(a.code==="PAGE_LOCKED"){te.toast.error("Delete not allowed",{description:"Page is currently being edited by another user."});return}i&&(i!=null&&i.primaryPage)?t.invalidateQueries({queryKey:[W,_.GET_LANGUAGE_PAGES,i==null?void 0:i.primaryPage]}):t.invalidateQueries({queryKey:[W,_.GET_WEBSITE_PAGES]})},onError:(a,i)=>{const o=g.find(r,{key:i.pageType});te.toast.error(`Failed to delete ${o!=null&&o.hasSlug?"page":o.name}.`,{description:a.message})}})},Hr=()=>{const e=se(),t=k.useQueryClient(),n=X(),{data:r}=Se();return k.useMutation({mutationFn:async a=>n(e,{action:_.TAKE_OFFLINE,data:{id:a==null?void 0:a.id}}),onSuccess:(a,i)=>{i&&(i!=null&&i.primaryPage)?t.invalidateQueries({queryKey:[W,_.GET_LANGUAGE_PAGES,i==null?void 0:i.primaryPage]}):t.invalidateQueries({queryKey:[W,_.GET_WEBSITE_PAGES]});const o=g.find(r,{key:i.pageType});te.toast.success(o!=null&&o.hasSlug?H.PAGE_UNPUBLISH_SUCCESS:"New "+o.name+" added successfully.")},onError:(a,i)=>{const o=g.find(r,{key:i.pageType});te.toast.error(`Failed to take offline ${o!=null&&o.hasSlug?"page":o.name}.`,{description:a.message})}})},Ss=()=>{const e=se(),t=X(),n=k.useQueryClient(),{data:r}=Ae();return k.useMutation({mutationFn:async({ids:a})=>t(e,{action:_.PUBLISH_CHANGES,data:{ids:a}}),onSuccess:()=>{n.invalidateQueries({queryKey:[W,_.GET_CHANGES]}),n.invalidateQueries({queryKey:[W,_.GET_WEBSITE_PAGES]}),n.invalidateQueries({queryKey:[W,_.GET_LANGUAGE_PAGES,r==null?void 0:r.id]})},onError:()=>{te.toast.error("Failed to publish pages.")}})},Kr=()=>{const e=se(),t=X(),n=k.useQueryClient();return k.useMutation({mutationFn:async r=>{var a;return t(e,{action:_.MARK_AS_TEMPLATE,data:{id:(a=r.page)==null?void 0:a.id,name:r.name,description:r.description,pageType:r.pageType,previewImage:r.previewImage}})},onSuccess:()=>{n.invalidateQueries({queryKey:[W,_.GET_WEBSITE_PAGES]}),te.toast.success("Page marked as template successfully.")},onError:()=>{te.toast.error("Failed to mark page as template.")}})},zr=()=>{const e=se(),t=X(),n=k.useQueryClient();return k.useMutation({mutationFn:async r=>t(e,{action:_.UNMARK_AS_TEMPLATE,data:{id:r==null?void 0:r.id}}),onSuccess:()=>{n.invalidateQueries({queryKey:[W,_.GET_WEBSITE_PAGES]}),te.toast.success("Page unmarked as template successfully.")},onError:()=>{te.toast.error("Failed to unmark page as template.")}})},Vr=()=>{const e=se(),t=X(),n=k.useQueryClient();return k.useMutation({mutationFn:async({id:r,slug:a})=>t(e,{action:_.CHANGE_SLUG,data:{id:r,slug:a}}),onSuccess:(r,{primaryPage:a})=>{te.toast.success(H.SLUG_CHANGE_SUCCESS),a?n.invalidateQueries({queryKey:[W,_.GET_LANGUAGE_PAGES,a]}):n.invalidateQueries({queryKey:[W,_.GET_WEBSITE_PAGES]})},onError:()=>{te.toast.error("Failed to change slug")}})};var ws={};(function e(t,n,r,a){var i=!!(t.Worker&&t.Blob&&t.Promise&&t.OffscreenCanvas&&t.OffscreenCanvasRenderingContext2D&&t.HTMLCanvasElement&&t.HTMLCanvasElement.prototype.transferControlToOffscreen&&t.URL&&t.URL.createObjectURL),o=typeof Path2D=="function"&&typeof DOMMatrix=="function",l=function(){if(!t.OffscreenCanvas)return!1;var x=new OffscreenCanvas(1,1),m=x.getContext("2d");m.fillRect(0,0,1,1);var T=x.transferToImageBitmap();try{m.createPattern(T,"no-repeat")}catch{return!1}return!0}();function u(){}function d(x){var m=n.exports.Promise,T=m!==void 0?m:t.Promise;return typeof T=="function"?new T(x):(x(u,u),null)}var f=function(x,m){return{transform:function(T){if(x)return T;if(m.has(T))return m.get(T);var L=new OffscreenCanvas(T.width,T.height),R=L.getContext("2d");return R.drawImage(T,0,0),m.set(T,L),L},clear:function(){m.clear()}}}(l,new Map),h=function(){var x=Math.floor(16.666666666666668),m,T,L={},R=0;return typeof requestAnimationFrame=="function"&&typeof cancelAnimationFrame=="function"?(m=function(K){var $=Math.random();return L[$]=requestAnimationFrame(function G(j){R===j||R+x-1<j?(R=j,delete L[$],K()):L[$]=requestAnimationFrame(G)}),$},T=function(K){L[K]&&cancelAnimationFrame(L[K])}):(m=function(K){return setTimeout(K,x)},T=function(K){return clearTimeout(K)}),{frame:m,cancel:T}}(),v=function(){var x,m,T={};function L(R){function K($,G){R.postMessage({options:$||{},callback:G})}R.init=function(G){var j=G.transferControlToOffscreen();R.postMessage({canvas:j},[j])},R.fire=function(G,j,z){if(m)return K(G,null),m;var ae=Math.random().toString(36).slice(2);return m=d(function(Z){function xe(Ee){Ee.data.callback===ae&&(delete T[ae],R.removeEventListener("message",xe),m=null,f.clear(),z(),Z())}R.addEventListener("message",xe),K(G,ae),T[ae]=xe.bind(null,{data:{callback:ae}})}),m},R.reset=function(){R.postMessage({reset:!0});for(var G in T)T[G](),delete T[G]}}return function(){if(x)return x;if(!r&&i){var R=["var CONFETTI, SIZE = {}, module = {};","("+e.toString()+")(this, module, true, SIZE);","onmessage = function(msg) {"," if (msg.data.options) {"," CONFETTI(msg.data.options).then(function () {"," if (msg.data.callback) {"," postMessage({ callback: msg.data.callback });"," }"," });"," } else if (msg.data.reset) {"," CONFETTI && CONFETTI.reset();"," } else if (msg.data.resize) {"," SIZE.width = msg.data.resize.width;"," SIZE.height = msg.data.resize.height;"," } else if (msg.data.canvas) {"," SIZE.width = msg.data.canvas.width;"," SIZE.height = msg.data.canvas.height;"," CONFETTI = module.exports.create(msg.data.canvas);"," }","}"].join(`
|
|
2
|
-
`);try{x=new Worker(URL.createObjectURL(new Blob([R])))}catch(K){return typeof console!==void 0&&typeof console.warn=="function"&&console.warn("🎊 Could not load worker",K),null}L(x)}return x}}(),E={particleCount:50,angle:90,spread:45,startVelocity:45,decay:.9,gravity:1,drift:0,ticks:200,x:.5,y:.5,shapes:["square","circle"],zIndex:100,colors:["#26ccff","#a25afd","#ff5e7e","#88ff5a","#fcff42","#ffa62d","#ff36ff"],disableForReducedMotion:!1,scalar:1};function y(x,m){return m?m(x):x}function N(x){return x!=null}function b(x,m,T){return y(x&&N(x[m])?x[m]:E[m],T)}function A(x){return x<0?0:Math.floor(x)}function M(x,m){return Math.floor(Math.random()*(m-x))+x}function w(x){return parseInt(x,16)}function S(x){return x.map(I)}function I(x){var m=String(x).replace(/[^0-9a-f]/gi,"");return m.length<6&&(m=m[0]+m[0]+m[1]+m[1]+m[2]+m[2]),{r:w(m.substring(0,2)),g:w(m.substring(2,4)),b:w(m.substring(4,6))}}function D(x){var m=b(x,"origin",Object);return m.x=b(m,"x",Number),m.y=b(m,"y",Number),m}function le(x){x.width=document.documentElement.clientWidth,x.height=document.documentElement.clientHeight}function ne(x){var m=x.getBoundingClientRect();x.width=m.width,x.height=m.height}function B(x){var m=document.createElement("canvas");return m.style.position="fixed",m.style.top="0px",m.style.left="0px",m.style.pointerEvents="none",m.style.zIndex=x,m}function U(x,m,T,L,R,K,$,G,j){x.save(),x.translate(m,T),x.rotate(K),x.scale(L,R),x.arc(0,0,1,$,G,j),x.restore()}function C(x){var m=x.angle*(Math.PI/180),T=x.spread*(Math.PI/180);return{x:x.x,y:x.y,wobble:Math.random()*10,wobbleSpeed:Math.min(.11,Math.random()*.1+.05),velocity:x.startVelocity*.5+Math.random()*x.startVelocity,angle2D:-m+(.5*T-Math.random()*T),tiltAngle:(Math.random()*(.75-.25)+.25)*Math.PI,color:x.color,shape:x.shape,tick:0,totalTicks:x.ticks,decay:x.decay,drift:x.drift,random:Math.random()+2,tiltSin:0,tiltCos:0,wobbleX:0,wobbleY:0,gravity:x.gravity*3,ovalScalar:.6,scalar:x.scalar,flat:x.flat}}function F(x,m){m.x+=Math.cos(m.angle2D)*m.velocity+m.drift,m.y+=Math.sin(m.angle2D)*m.velocity+m.gravity,m.velocity*=m.decay,m.flat?(m.wobble=0,m.wobbleX=m.x+10*m.scalar,m.wobbleY=m.y+10*m.scalar,m.tiltSin=0,m.tiltCos=0,m.random=1):(m.wobble+=m.wobbleSpeed,m.wobbleX=m.x+10*m.scalar*Math.cos(m.wobble),m.wobbleY=m.y+10*m.scalar*Math.sin(m.wobble),m.tiltAngle+=.1,m.tiltSin=Math.sin(m.tiltAngle),m.tiltCos=Math.cos(m.tiltAngle),m.random=Math.random()+2);var T=m.tick++/m.totalTicks,L=m.x+m.random*m.tiltCos,R=m.y+m.random*m.tiltSin,K=m.wobbleX+m.random*m.tiltCos,$=m.wobbleY+m.random*m.tiltSin;if(x.fillStyle="rgba("+m.color.r+", "+m.color.g+", "+m.color.b+", "+(1-T)+")",x.beginPath(),o&&m.shape.type==="path"&&typeof m.shape.path=="string"&&Array.isArray(m.shape.matrix))x.fill(V(m.shape.path,m.shape.matrix,m.x,m.y,Math.abs(K-L)*.1,Math.abs($-R)*.1,Math.PI/10*m.wobble));else if(m.shape.type==="bitmap"){var G=Math.PI/10*m.wobble,j=Math.abs(K-L)*.1,z=Math.abs($-R)*.1,ae=m.shape.bitmap.width*m.scalar,Z=m.shape.bitmap.height*m.scalar,xe=new DOMMatrix([Math.cos(G)*j,Math.sin(G)*j,-Math.sin(G)*z,Math.cos(G)*z,m.x,m.y]);xe.multiplySelf(new DOMMatrix(m.shape.matrix));var Ee=x.createPattern(f.transform(m.shape.bitmap),"no-repeat");Ee.setTransform(xe),x.globalAlpha=1-T,x.fillStyle=Ee,x.fillRect(m.x-ae/2,m.y-Z/2,ae,Z),x.globalAlpha=1}else if(m.shape==="circle")x.ellipse?x.ellipse(m.x,m.y,Math.abs(K-L)*m.ovalScalar,Math.abs($-R)*m.ovalScalar,Math.PI/10*m.wobble,0,2*Math.PI):U(x,m.x,m.y,Math.abs(K-L)*m.ovalScalar,Math.abs($-R)*m.ovalScalar,Math.PI/10*m.wobble,0,2*Math.PI);else if(m.shape==="star")for(var Y=Math.PI/2*3,ye=4*m.scalar,Ce=8*m.scalar,Pe=m.x,Be=m.y,He=5,Ie=Math.PI/He;He--;)Pe=m.x+Math.cos(Y)*Ce,Be=m.y+Math.sin(Y)*Ce,x.lineTo(Pe,Be),Y+=Ie,Pe=m.x+Math.cos(Y)*ye,Be=m.y+Math.sin(Y)*ye,x.lineTo(Pe,Be),Y+=Ie;else x.moveTo(Math.floor(m.x),Math.floor(m.y)),x.lineTo(Math.floor(m.wobbleX),Math.floor(R)),x.lineTo(Math.floor(K),Math.floor($)),x.lineTo(Math.floor(L),Math.floor(m.wobbleY));return x.closePath(),x.fill(),m.tick<m.totalTicks}function re(x,m,T,L,R){var K=m.slice(),$=x.getContext("2d"),G,j,z=d(function(ae){function Z(){G=j=null,$.clearRect(0,0,L.width,L.height),f.clear(),R(),ae()}function xe(){r&&!(L.width===a.width&&L.height===a.height)&&(L.width=x.width=a.width,L.height=x.height=a.height),!L.width&&!L.height&&(T(x),L.width=x.width,L.height=x.height),$.clearRect(0,0,L.width,L.height),K=K.filter(function(Ee){return F($,Ee)}),K.length?G=h.frame(xe):Z()}G=h.frame(xe),j=Z});return{addFettis:function(ae){return K=K.concat(ae),z},canvas:x,promise:z,reset:function(){G&&h.cancel(G),j&&j()}}}function me(x,m){var T=!x,L=!!b(m||{},"resize"),R=!1,K=b(m,"disableForReducedMotion",Boolean),$=i&&!!b(m||{},"useWorker"),G=$?v():null,j=T?le:ne,z=x&&G?!!x.__confetti_initialized:!1,ae=typeof matchMedia=="function"&&matchMedia("(prefers-reduced-motion)").matches,Z;function xe(Y,ye,Ce){for(var Pe=b(Y,"particleCount",A),Be=b(Y,"angle",Number),He=b(Y,"spread",Number),Ie=b(Y,"startVelocity",Number),er=b(Y,"decay",Number),tr=b(Y,"gravity",Number),sr=b(Y,"drift",Number),Is=b(Y,"colors",S),nr=b(Y,"ticks",Number),ks=b(Y,"shapes"),rr=b(Y,"scalar"),ar=!!b(Y,"flat"),Ls=D(Y),Ds=Pe,rs=[],ir=x.width*Ls.x,or=x.height*Ls.y;Ds--;)rs.push(C({x:ir,y:or,angle:Be,spread:He,startVelocity:Ie,color:Is[Ds%Is.length],shape:ks[M(0,ks.length)],ticks:nr,decay:er,gravity:tr,drift:sr,scalar:rr,flat:ar}));return Z?Z.addFettis(rs):(Z=re(x,rs,j,ye,Ce),Z.promise)}function Ee(Y){var ye=K||b(Y,"disableForReducedMotion",Boolean),Ce=b(Y,"zIndex",Number);if(ye&&ae)return d(function(Ie){Ie()});T&&Z?x=Z.canvas:T&&!x&&(x=B(Ce),document.body.appendChild(x)),L&&!z&&j(x);var Pe={width:x.width,height:x.height};G&&!z&&G.init(x),z=!0,G&&(x.__confetti_initialized=!0);function Be(){if(G){var Ie={getBoundingClientRect:function(){if(!T)return x.getBoundingClientRect()}};j(Ie),G.postMessage({resize:{width:Ie.width,height:Ie.height}});return}Pe.width=Pe.height=null}function He(){Z=null,L&&(R=!1,t.removeEventListener("resize",Be)),T&&x&&(document.body.contains(x)&&document.body.removeChild(x),x=null,z=!1)}return L&&!R&&(R=!0,t.addEventListener("resize",Be,!1)),G?G.fire(Y,Pe,He):xe(Y,Pe,He)}return Ee.reset=function(){G&&G.reset(),Z&&Z.reset()},Ee}var ee;function fe(){return ee||(ee=me(null,{useWorker:!0,resize:!0})),ee}function V(x,m,T,L,R,K,$){var G=new Path2D(x),j=new Path2D;j.addPath(G,new DOMMatrix(m));var z=new Path2D;return z.addPath(j,new DOMMatrix([Math.cos($)*R,Math.sin($)*R,-Math.sin($)*K,Math.cos($)*K,T,L])),z}function pe(x){if(!o)throw new Error("path confetti are not supported in this browser");var m,T;typeof x=="string"?m=x:(m=x.path,T=x.matrix);var L=new Path2D(m),R=document.createElement("canvas"),K=R.getContext("2d");if(!T){for(var $=1e3,G=$,j=$,z=0,ae=0,Z,xe,Ee=0;Ee<$;Ee+=2)for(var Y=0;Y<$;Y+=2)K.isPointInPath(L,Ee,Y,"nonzero")&&(G=Math.min(G,Ee),j=Math.min(j,Y),z=Math.max(z,Ee),ae=Math.max(ae,Y));Z=z-G,xe=ae-j;var ye=10,Ce=Math.min(ye/Z,ye/xe);T=[Ce,0,0,Ce,-Math.round(Z/2+G)*Ce,-Math.round(xe/2+j)*Ce]}return{type:"path",path:m,matrix:T}}function Q(x){var m,T=1,L="#000000",R='"Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji", "EmojiOne Color", "Android Emoji", "Twemoji Mozilla", "system emoji", sans-serif';typeof x=="string"?m=x:(m=x.text,T="scalar"in x?x.scalar:T,R="fontFamily"in x?x.fontFamily:R,L="color"in x?x.color:L);var K=10*T,$=""+K+"px "+R,G=new OffscreenCanvas(K,K),j=G.getContext("2d");j.font=$;var z=j.measureText(m),ae=Math.ceil(z.actualBoundingBoxRight+z.actualBoundingBoxLeft),Z=Math.ceil(z.actualBoundingBoxAscent+z.actualBoundingBoxDescent),xe=2,Ee=z.actualBoundingBoxLeft+xe,Y=z.actualBoundingBoxAscent+xe;ae+=xe+xe,Z+=xe+xe,G=new OffscreenCanvas(ae,Z),j=G.getContext("2d"),j.font=$,j.fillStyle=L,j.fillText(m,Ee,Y);var ye=1/T;return{type:"bitmap",bitmap:G.transferToImageBitmap(),matrix:[ye,0,0,ye,-ae*ye/2,-Z*ye/2]}}n.exports=function(){return fe().apply(this,arguments)},n.exports.reset=function(){fe().reset()},n.exports.create=me,n.exports.shapeFromPath=pe,n.exports.shapeFromText=Q})(function(){return typeof window<"u"?window:typeof self<"u"?self:this||{}}(),ws,!1);const $r=ws.exports;ws.exports.create;const Wr={particleCount:350,spread:120,origin:{y:.6},angle:90},Qr={TOP_RIGHT:{angle:225,origin:{x:.9,y:0}},BOTTOM_RIGHT:{angle:100,origin:{x:.9,y:.9}}},zt=e=>{let t=Qr[e];t||(t={});const n={...Wr,...t};$r(n)},Yr=()=>{const[e]=J.useTheme(),{mutate:t,isPending:n}=Ss(),{mutateAsync:r,isPending:a}=en(),i=()=>{r({settings:{theme:e}})},o=()=>{t({ids:["THEME"]},{onSuccess:()=>{zt("BOTTOM_RIGHT")}})};return s.jsxs("div",{className:"bg-white py-3 flex items-center justify-center gap-x-3 border-t",children:[s.jsx(c.Button,{size:"sm",variant:"outline",disabled:n||a,onClick:i,children:"Save draft"}),s.jsx(c.Button,{size:"sm",disabled:n||a,onClick:o,children:"Publish"})]})},Xr=({page:e,onClose:t})=>{const[n,r]=p.useState(e.slug||""),{mutate:a,isPending:i}=Vr(),{data:o}=Se(),l=g.find(o,{key:e==null?void 0:e.pageType}),u=f=>{if(f.preventDefault(),!(e!=null&&e.primaryPage)&&Object.keys(_e).some(E=>n===`/${E}`||g.startsWith(n,`/${E}/`))){te.toast.error("Error",{description:"Slugs cannot start with a language code for primary page"});return}a({...e,slug:n},{onSuccess:t})},d=(e==null?void 0:e.lang)||"";return s.jsx(c.Dialog,{open:!!e,onOpenChange:t,children:s.jsxs(c.DialogContent,{children:[s.jsxs(c.DialogHeader,{children:[s.jsx(c.DialogTitle,{children:"Change Slug"}),s.jsx(c.DialogDescription,{className:"text-xs",children:s.jsxs(c.Alert,{variant:"destructive",className:"mt-2",children:[s.jsx(P.AlertCircle,{className:"h-4 w-4"}),"Changing the slug may have impact on your SEO. Please proceed with caution."]})})]}),s.jsxs("form",{onSubmit:u,children:[s.jsxs("div",{className:"space-y-4 py-4 text-sm ",children:[s.jsxs("div",{className:"space-y-1",children:[s.jsxs("div",{children:[s.jsx("span",{children:"Type:"}),s.jsxs("span",{className:"font-medium text-gray-600",children:[" ",(l==null?void 0:l.name)||(e==null?void 0:e.pageType)]})]}),s.jsxs("div",{children:[s.jsx("span",{children:"Name:"}),s.jsxs("span",{className:"font-medium text-gray-600",children:[" ",e.name]})]})]}),s.jsxs("div",{className:"space-y-1",children:[s.jsxs(c.Label,{htmlFor:"slug",className:"text-right",children:["Slug"," ",s.jsxs("small",{className:"font-light text-gray-500",children:["Slug should start with /",d]})]}),s.jsx(c.Input,{id:"slug",value:n,onChange:f=>{const h=f.target.value;g.startsWith(h,`/${d}`)&&r(h)},className:"col-span-3",required:!0,pattern:"^/.*",title:"Slug must start with /",placeholder:"Enter page slug"})]})]}),s.jsx(c.DialogFooter,{children:s.jsx(c.Button,{type:"submit",disabled:i||!g.startsWith(n,`/${d}`)||g.isEqual(e==null?void 0:e.slug,n),children:i?"Changing...":"Change Slug"})})]})]})})};function on({page:e,onClose:t}){const[,n]=Ne(),{mutate:r,isPending:a}=qr(),{data:i}=Se(),o=()=>{r(e,{onSuccess:()=>{e!=null&&e.primaryPage||(window.history.replaceState(null,"","/"),n(new URLSearchParams({})),window.dispatchEvent(new PopStateEvent("popstate"))),t()}})},l=i==null?void 0:i.find(u=>u.key===(e==null?void 0:e.pageType));return s.jsx(c.Dialog,{open:!!e,onOpenChange:t,children:s.jsxs(c.DialogContent,{children:[s.jsxs(c.DialogHeader,{children:[s.jsx(c.DialogTitle,{children:"Confirm Deletion"}),s.jsxs(c.DialogDescription,{className:"py-4 text-slate-500",children:[s.jsxs("div",{children:["Are you sure you want to remove ",s.jsx("b",{children:(e==null?void 0:e.name)??(e==null?void 0:e.slug)})," ",l!=null&&l.hasSlug?(l==null?void 0:l.name)+"?":`page? ${e!=null&&e.primaryPage?"":"This will also delete all associated language pages."}`]}),e.lang&&s.jsxs("div",{className:"py-2 text-sm",children:["Language:"," ",s.jsx("span",{className:"font-medium text-gray-500",children:g.get(_e,e.lang,e.lang)})]})]})]}),s.jsxs(c.DialogFooter,{children:[s.jsx(c.Button,{variant:"outline",onClick:t,children:"Cancel"}),s.jsx(c.Button,{variant:"destructive",disabled:a,onClick:o,children:a?"Deleting...":"Delete"})]})]})})}const Te=({permission:e,permissions:t,children:n,fallback:r=null})=>{const{hasPermission:a}=J.usePermissions();return e&&!a(e)||t&&!t.some(i=>a(i))?r:n},Ns=({page:e,onClose:t})=>{const{mutate:n,isPending:r}=Hr(),a=async()=>{n(e,{onSuccess:t})};return s.jsx(c.Dialog,{open:!!e,onOpenChange:t,children:s.jsxs(c.DialogContent,{children:[s.jsxs(c.DialogHeader,{children:[s.jsx(c.DialogTitle,{children:"Confirm action"}),s.jsxs(c.DialogDescription,{children:[H.UNPUBLISH_MSG," ",s.jsx("b",{children:(e==null?void 0:e.name)??(e==null?void 0:e.slug)}),"?"]})]}),s.jsxs(c.DialogFooter,{children:[s.jsx(c.Button,{variant:"outline",onClick:t,children:"Cancel"}),s.jsx(c.Button,{variant:"destructive",disabled:r,onClick:a,children:r?H.UPDATING:H.UNPUBLISH})]})]})})},ln=({langProps:e,onClose:t,languages:n})=>{const{data:r}=Ae(),{data:a}=Se(),[i,o]=p.useState(e.name||""),[l,u]=p.useState(e.edit?e.lang:""),[d,f]=p.useState(e.edit?e.slug:""),{mutate:h,isPending:v}=an(),{mutate:E,isPending:y}=js(),N=p.useMemo(()=>a==null?void 0:a.find(w=>w.key===e.pageType),[a,e.pageType]),b=!(N!=null&&N.hasSlug),A=v||y,M=w=>{w.preventDefault();const S={name:i,lang:l,primaryPage:r==null?void 0:r.id,slug:d,pageType:r==null?void 0:r.pageType};S.pageType=e.pageType,e.edit&&(S.id=e==null?void 0:e.id),e.edit?E(S,{onSuccess:t}):h(S,{onSuccess:t})};return s.jsx(c.Dialog,{open:!!e,onOpenChange:t,children:s.jsxs(c.DialogContent,{className:"sm:max-w-[425px] text-slate-600",children:[s.jsxs(c.DialogHeader,{children:[s.jsx(c.DialogTitle,{children:e.edit?H.EDIT_LANGUAGE:H.ADD_NEW_LANGUAGE}),s.jsx(c.DialogDescription,{className:"font-light",children:H.ENTER_LANGUAGE_DETAILS})]}),s.jsxs("form",{onSubmit:M,children:[s.jsxs("div",{className:"grid gap-4 py-4",children:[s.jsxs("div",{className:"space-y-1",children:[s.jsx(c.Label,{htmlFor:"lang",className:"text-right",children:H.LANGUAGE}),s.jsxs("select",{value:l,disabled:e.edit||g.isEmpty(n),onChange:w=>{const S=w.target.value;u(S),!b&&f(`/${S}`)},className:"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 col-span-3",children:[s.jsx("option",{value:"",disabled:!0,selected:!0,children:e.edit?g.get(_e,e.lang,e.lang):g.isEmpty(n)?H.ALL_AVAILABLE_LANGUAGE_PAGE:H.CHOOSE_LANGUAGE}),g.map(n,w=>s.jsx("option",{value:w,children:g.get(_e,w,w)},w))]})]}),s.jsxs("div",{className:"space-y-1",children:[s.jsx(c.Label,{htmlFor:"slug",className:"text-right",children:H.PAGE_NAME}),s.jsx(c.Input,{id:"name",value:i,onChange:w=>o(w.target.value),className:"col-span-3",required:!0,placeholder:H.ENTER_PAGE_NAME})]}),!b&&s.jsxs("div",{className:"space-y-1",children:[s.jsxs(c.Label,{htmlFor:"slug",className:"text-right",children:[H.SLUG," ",s.jsx("small",{className:"font-light",children:H.SLUG_SHOULD_START_WITH})]}),s.jsx(c.Input,{id:"slug",value:d,onChange:w=>{const S=w.target.value;g.startsWith(S,`/${l}`)&&f(g.toLower(g.trim(S)))},className:"col-span-3",required:!0,pattern:"^/.*",disabled:g.isEmpty(l),title:H.SLUG_MUST_START_WITH,placeholder:g.isEmpty(l)?H.CHOOSE_LANGUAGE_TO_ADD_SLUG:H.ENTER_PAGE_SLUG})]})]}),s.jsx(c.DialogFooter,{children:s.jsx(c.Button,{type:"submit",disabled:A||!i||!l||!b&&!g.startsWith(d,`/${l}`),children:A?e.edit?H.UPDATING:H.ADDING:e.edit?H.UPDATE:H.ADD_NEW_LANGUAGE})})]})]})})},Zr=()=>{const[e,t]=p.useState(null),{selectedLang:n,fallbackLang:r,setSelectedLang:a}=J.useLanguages(),{data:i,isFetching:o}=mt(),{data:l}=Ae(),[u,d]=p.useState(null),[f,h]=p.useState(null),[v,E]=p.useState(null),{data:y}=ft(),N=g.filter(g.get(y,"languages")||["en"],b=>!g.find(i,{lang:b})&&b!==g.get(y,"fallbackLang"));return s.jsxs("div",{className:"space-y-4",children:[s.jsx("ul",{className:"space-y-2",children:o?s.jsxs("div",{className:"w-full space-y-3 py-4",children:[s.jsx("div",{className:"w-full h-8 rounded bg-gray-300 animate-pulse"}),s.jsx("div",{className:"w-full h-8 rounded bg-gray-300 animate-pulse"}),s.jsx("div",{className:"w-full h-8 rounded bg-gray-300 animate-pulse"})]}):g.map(i,b=>{const A=b.lang,M=b.slug,w=!b.primaryPage,S=A===n;return s.jsxs(s.Fragment,{children:[s.jsxs("li",{className:`text-slate-500 w-full p-2 rounded cursor-pointer flex items-center justify-between ${S?"bg-gray-200":"hover:bg-gray-100"}`,onClick:()=>a(A),children:[s.jsxs("div",{className:" flex-1 gap-x-3",children:[s.jsxs("div",{className:"text-[13px] text-slate-800 flex items-center gap-x-2",children:[s.jsx("div",{className:`w-2.5 h-2.5 rounded-full ${b.online?"bg-green-300":"bg-gray-300"}`}),g.get(_e,w?r:A,A)]}),s.jsxs("div",{children:[M&&s.jsxs("div",{className:"text-[11px] text-slate-600 font-light",children:["Slug: ",s.jsx("b",{className:"font-medium",children:M})]}),s.jsxs("div",{className:"text-[11px] text-slate-600 font-light",children:["Name:",s.jsxs("b",{className:"font-medium",children:[" ",b.name," "]})]})]})]}),w?s.jsxs("div",{className:"flex items-center text-[11px] text-orange-500 gap-x-1",children:[s.jsx(P.StarIcon,{fill:"orange",className:"w-3 h-3"}),s.jsx("b",{children:" Primary"})]}):s.jsx("div",{className:"flex items-center gap-x-3",children:s.jsx(Te,{permissions:[he.EDIT_PAGE,he.DELETE_PAGE,he.UNPUBLISH_PAGE],children:s.jsxs(c.DropdownMenu,{children:[s.jsx(c.DropdownMenuTrigger,{asChild:!0,onClick:I=>I.stopPropagation(),children:s.jsx(c.Button,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0",children:s.jsx(P.MoreHorizontal,{className:"h-4 w-4"})})}),s.jsxs(c.DropdownMenuContent,{align:"end",className:"text-sm z-[9999]",children:[s.jsx(Te,{permissions:[he.EDIT_PAGE],children:s.jsxs(c.DropdownMenuItem,{className:"flex items-center gap-2 cursor-pointer",onClick:I=>{I.stopPropagation(),t({...b,edit:!0})},children:[s.jsx(P.PencilIcon,{className:"size-3"}),H.EDIT]})}),s.jsx(Te,{permissions:[he.UNPUBLISH_PAGE],children:(b==null?void 0:b.online)&&s.jsxs(c.DropdownMenuItem,{className:"flex items-center gap-2 cursor-pointer",onClick:I=>{I.stopPropagation(),h(b)},children:[s.jsx(P.Power,{className:"size-3"}),H.UNPUBLISH]})}),s.jsx(Te,{permissions:[he.DELETE_PAGE],children:s.jsxs(c.DropdownMenuItem,{className:"flex items-center gap-2 cursor-pointer",onClick:I=>{I.stopPropagation(),d(b)},children:[s.jsx(P.TrashIcon,{className:"size-3"}),H.DELETE]})})]})]})})})]},b.id),s.jsx("div",{className:"h-1 w-full border-b"})]})})}),s.jsx(Te,{permissions:[he.ADD_PAGE],children:s.jsx("div",{className:"flex justify-center w-full",children:s.jsx(c.Button,{variant:"default",size:"sm",disabled:g.isEmpty(N),onClick:()=>{t({name:l==null?void 0:l.name,pageType:l==null?void 0:l.pageType,lang:"",slug:"",edit:!1})},children:H.ADD_NEW_LANGUAGE})})}),e&&s.jsx(ln,{languages:N,langProps:e,onClose:()=>t(null)}),u&&s.jsx(on,{page:u,onClose:()=>d(null)}),f&&s.jsx(Ns,{page:f,onClose:()=>h(null)}),v&&s.jsx(Xr,{page:v,onClose:()=>E(null)})]})};function Jr({pages:e,selectedParentId:t,onChange:n,className:r="w-full rounded-md border border-gray-300 px-3 py-2",id:a="parentPage"}){const i=p.useMemo(()=>!e||e.length===0?[]:e.filter(f=>!g.isEmpty(f.slug)).filter(f=>f.slug!=="/").sort((f,h)=>f.slug.localeCompare(h.slug)),[e]),o=d=>Math.max(0,(d.match(/\//g)||[]).length-1),l=d=>" ".repeat(d),u=d=>{if(d==="/")return"/";const f=d.split("/").filter(Boolean);return f.length<=1?`/${f[0]||""}`:`/${f[f.length-1]}`};return s.jsxs("div",{className:"space-y-0.5",children:[s.jsx(c.Label,{htmlFor:a,className:"text-sm",children:"Parent"}),s.jsxs("select",{id:a,value:t||"none",onChange:d=>n(d.target.value),className:r,"data-testid":"parent-page-selector",children:[s.jsx("option",{value:"none",children:"None"}),i.map(d=>{const f=o(d.slug),h=f>0?l(f):"",v=u(d.slug);return s.jsxs("option",{value:d.id,children:[h,d.name," (",v,")"]},d.id)})]})]})}function ea({value:e,onChange:t,placeholder:n,parentSlug:r}){const[a,i]=p.useState(e);p.useEffect(()=>{i(e)},[e]);const o=l=>{const d=l.target.value.replace(/\//g,"").replace(/\s+/g,"-").replace(/[^a-zA-Z0-9-_]/g,"-").replace(/-+/g,"-").replace(/^-+/,"").toLowerCase();i(d),t(d)};return s.jsxs("div",{children:[r&&s.jsx("div",{className:"flex items-center mb-1",children:s.jsxs("span",{className:"text-xs text-gray-500",children:["Parent: ",r]})}),s.jsx("div",{className:"relative",children:s.jsx(c.Input,{value:a,onChange:o,placeholder:n})})]})}const ta=({templates:e,selectedTemplateId:t,onSelectTemplate:n,isLoading:r=!1})=>{const[a,i]=p.useState("");if(p.useEffect(()=>{if(t){const l=e.find(u=>u.id===t);i((l==null?void 0:l.preview)||"")}else i("")},[t,e]),r)return s.jsx("div",{className:"flex items-center justify-center h-fit text-sm text-gray-500",children:"Loading templates..."});if(e.length===0)return null;const o={};return e.forEach(l=>{const u=l.libraryName;o[u]||(o[u]=[]),o[u].push(l)}),s.jsxs("div",{className:"space-y-4",children:[s.jsxs("select",{className:"w-full rounded-md border border-gray-300 px-3 py-2",value:t,onChange:l=>n(l.target.value),children:[s.jsx("option",{value:"",children:"No Template"}),Object.entries(o).map(([l,u])=>s.jsx("optgroup",{label:l,children:u.map(d=>s.jsx("option",{value:d.id,children:g.startCase(d.name)},d.id))},l))]}),a&&s.jsxs("div",{className:"mt-3 border rounded overflow-hidden",children:[s.jsx("div",{className:"max-h-[200px] overflow-auto",children:s.jsx("img",{src:a,alt:"Template Preview",className:"w-full object-contain"})}),s.jsx("div",{className:"p-2 text-xs text-gray-500 bg-gray-50 border-t",children:"Template preview"})]})]})},sa=()=>{const e=se(),t=X();return k.useQuery({queryKey:[W,_.GET_LIBRARIES],queryFn:async()=>await t(e,{action:_.GET_LIBRARIES})||[]})},na=e=>{const t=se(),n=X();return k.useQuery({queryKey:[W,_.GET_TEMPLATES_BY_TYPE,e],enabled:!!e,queryFn:async()=>{const r=await n(t,{action:_.GET_TEMPLATES_BY_TYPE,data:{pageType:e}});return(e?g.filter(r,{pageType:e}):r)||[]}})},ra=e=>{const{data:t=[],isLoading:n}=na(e),{data:r=[],isLoading:a}=sa(),i=p.useMemo(()=>n||a?[]:t.map(l=>{const u=g.find(r,{id:l.library});return{...l,libraryName:(u==null?void 0:u.type)!=="shared"?"Site Library":(u==null?void 0:u.name)+" Library",libraryType:u==null?void 0:u.type}}),[t,r,n,a]),o=p.useMemo(()=>g.groupBy(i,"libraryName"),[i]);return{data:i,groupedData:o,isLoading:n||a}},cn=()=>{const[,e]=Ne();return p.useCallback((t,n)=>{const a=new URLSearchParams(window.location.search).get("lang"),i=new URLSearchParams({page:t});a&&i.set("lang",a),window.history.pushState({},"",`?${i.toString()}`),e(i),window.dispatchEvent(new PopStateEvent("popstate")),n==null||n()},[e])};function aa({addEditPage:e,additionalPageTypes:t=[],close:n,closePanel:r}){var $,G;const a=cn(),i=!!(e!=null&&e.id),{data:o}=Rt(),{mutate:l,isPending:u}=an(),{mutate:d,isPending:f}=js(),[h,v]=p.useState(null),[E,y]=p.useState((e==null?void 0:e.pageType)??"page"),{hasPermission:N}=J.usePermissions(),b=N(he.CHANGE_PAGE_TYPE),[A,M]=p.useState(!1),[w,S]=p.useState(""),I=p.useMemo(()=>{const j=t.find(z=>z.key===E);return(j==null?void 0:j.hasSlug)===!1},[E,t]),[D,le]=p.useState((e==null?void 0:e.parent)??""),[ne,B]=p.useState((e==null?void 0:e.name)??""),[U,C]=p.useState((e==null?void 0:e.dynamic)??!1),[F,re]=p.useState(U?"":((e==null?void 0:e.slug)??"").split("/").pop()||""),[me,ee]=p.useState(""),{data:fe,isLoading:V}=ra(E),pe=u||f,Q=t.find(j=>j.key===E),x=j=>{if(i&&E!==j){S(j),M(!0);return}y(j)},m=()=>{y(w),M(!1),C(!1)},T=j=>{C(j),j&&re("")},L=j=>{if(le(j),j&&j!=="none"){const z=o==null?void 0:o.find(Z=>Z.id===j),ae=(z==null?void 0:z.slug)||"";if(F.startsWith(ae)){const Z=F.slice(ae.length).replace(/^\/+/,"");re(Z)}else re(F.replace(/^\/+/,""))}else re(F?`${F}`:"")},R=j=>{ee(j)},K=j=>{if(j.preventDefault(),v(null),!ne.trim()){te.toast.error("Name is required");return}if(U&&!g.isEmpty(F)){v("Slug must be empty when using dynamic slug");return}if(!(Q!=null&&Q.hasSlug)){const z={pageType:Q==null?void 0:Q.key,name:ne,slug:"",hasSlug:!1};if(i){d({id:e==null?void 0:e.id,name:ne},{onSuccess:()=>{te.toast.success((Q==null?void 0:Q.name)+" updated successfully"),n()}});return}else l(z,{onSuccess:ae=>{console.log("response",ae),n(),a(ae.page.id,r)}});return}if(D&&D!=="none"){if(!F.trim()&&!U){v("Child page slug is required");return}const z=o==null?void 0:o.find(ye=>ye.id===D),ae=(z==null?void 0:z.slug)||"",Z=ae==="/"?`/${F}`:`${ae}/${F}`;if(Object.keys(_e).some(ye=>Z===`/${ye}`||(Z==null?void 0:Z.startsWith(`/${ye}/`)))){v("Slugs cannot start with a language code for primary page");return}const Y={pageType:E,name:ne,slug:Z.replace(/\/$/,""),parent:D,dynamic:U,hasSlug:!0,template:me||void 0};if(i){d({id:e==null?void 0:e.id,...Y},{onSuccess:()=>{te.toast.success("Page updated successfully"),n()}});return}l(Y,{onSuccess:ye=>{console.log("response",ye),n(),a(ye.page.id,r)}})}else{const z={pageType:E,name:ne,slug:F===""?"/":`/${F.replace(/\/$/,"")}`,template:me||void 0};if(i){d({id:e==null?void 0:e.id,...z},{onSuccess:()=>{te.toast.success("Page updated successfully"),n()}});return}l(z,{onSuccess:()=>{n()}})}};return Q!=null&&Q.hasSlug?s.jsxs("form",{onSubmit:K,className:"w-full max-w-md mx-auto space-y-4",children:[s.jsxs("div",{className:"space-y-0.5",children:[s.jsx(c.Label,{htmlFor:"pageType",className:"text-sm",children:"Type"}),s.jsx("select",{id:"pageType",value:E,disabled:i&&!b,onChange:j=>x(j.target.value),className:`w-full rounded-md border border-gray-300 px-3 py-2 ${i&&!b?"cursor-not-allowed text-gray-500":""}`,children:i?I?s.jsx("optgroup",{label:"Partials",children:t.filter(j=>j.hasSlug===!1).map(j=>s.jsx("option",{value:j.key,children:j.name},j.key))}):s.jsx("optgroup",{label:"Pages",children:t.filter(j=>j.hasSlug!==!1).map(j=>s.jsx("option",{value:j.key,children:j.name},j.key))}):s.jsxs(s.Fragment,{children:[s.jsx("optgroup",{label:"Pages",children:t.filter(j=>j.hasSlug!==!1).map(j=>s.jsx("option",{value:j.key,children:j.name},j.key))}),s.jsx("optgroup",{label:"Partials",children:t.filter(j=>j.hasSlug===!1).map(j=>s.jsx("option",{value:j.key,children:j.name},j.key))})]})}),A&&s.jsxs("div",{className:"mt-2 p-3 bg-yellow-50 border border-yellow-200 rounded-md",children:[s.jsx("p",{className:"text-sm text-yellow-800",children:"Changing the page type may impact the page data. Are you sure you want to proceed?"}),s.jsxs("div",{className:"mt-2 flex gap-2",children:[s.jsx(c.Button,{variant:"outline",size:"sm",onClick:()=>M(!1),children:"Cancel"}),s.jsx(c.Button,{variant:"default",size:"sm",onClick:m,children:"Confirm"})]})]})]}),!i&&(Q==null?void 0:Q.hasSlug)&&fe.length>0&&s.jsxs("div",{className:"space-y-1",children:[s.jsx(c.Label,{className:"text-sm mb-1 block",children:"Template"}),s.jsx(ta,{templates:fe,selectedTemplateId:me,onSelectTemplate:R,isLoading:V})]}),s.jsx(Jr,{pages:o,selectedParentId:D,onChange:L}),s.jsxs("div",{className:"space-y-0.5",children:[s.jsx(c.Label,{htmlFor:"name",className:"text-sm",children:"Name"}),s.jsx(c.Input,{id:"name",value:ne,onChange:j=>B(j.target.value),required:!0,"aria-required":"true"})]}),(Q==null?void 0:Q.dynamicSegments)&&D&&D!=="none"&&s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center space-x-2",children:[s.jsx("input",{type:"checkbox",id:"useDynamicSlug",checked:U,onChange:j=>T(j.target.checked),className:"rounded border-gray-300"}),s.jsx(c.Label,{htmlFor:"useDynamicSlug",className:"text-sm",children:"Use Dynamic Slug"})]}),U&&s.jsxs("div",{className:"text-sm text-gray-500",children:["Pages will use pattern: ",Q==null?void 0:Q.dynamicSlug]})]}),(!(Q!=null&&Q.dynamicSegments)||!U)&&s.jsxs("div",{className:"space-y-0.5",children:[s.jsx(c.Label,{htmlFor:"slug",className:"text-sm",children:"Slug"}),s.jsx(ea,{value:F,onChange:re,placeholder:D&&D!=="none"?"Enter page slug":E==="page"?"Leave empty for home page":"Required - e.g. your-slug",parentSlug:D&&D!=="none"?(G=o==null?void 0:o.find(j=>j.id===D))==null?void 0:G.slug:void 0}),h&&s.jsx("p",{className:"text-xs text-red-500",children:h})]}),s.jsx(c.Button,{disabled:pe,type:"submit",className:"w-full",children:i?pe?"Updating...":"Update page":pe?"Creating...":"Create Page"})]}):s.jsxs("form",{onSubmit:K,className:"w-full max-w-md mx-auto space-y-4",children:[s.jsxs("div",{className:"space-y-0.5",children:[s.jsx(c.Label,{htmlFor:"pageType",className:"text-sm",children:"Type"}),s.jsx("select",{id:"pageType",value:E,disabled:i&&!b,onChange:j=>x(j.target.value),className:`w-full rounded-md border border-gray-300 px-3 py-2 ${i&&!b?"cursor-not-allowed text-gray-500":""}`,children:s.jsx("optgroup",{label:"Partials",children:t.filter(j=>j.hasSlug===!1).map(j=>s.jsx("option",{value:j.key,children:j.name},j.key))})}),A&&s.jsxs("div",{className:"mt-2 p-3 bg-yellow-50 border border-yellow-200 rounded-md",children:[s.jsx("p",{className:"text-sm text-yellow-800",children:"Changing the page type may impact the page data. Are you sure you want to proceed?"}),s.jsxs("div",{className:"mt-2 flex gap-2",children:[s.jsx(c.Button,{variant:"outline",size:"sm",onClick:()=>M(!1),children:"Cancel"}),s.jsx(c.Button,{variant:"default",size:"sm",onClick:m,children:"Confirm"})]})]}),s.jsx("p",{className:"text-xs text-gray-500",children:($=t.find(j=>j.key===E))==null?void 0:$.helpText})]}),s.jsxs("div",{className:"space-y-0.5",children:[s.jsx(c.Label,{htmlFor:"name",className:"text-sm",children:"Name"}),s.jsx(c.Input,{id:"name",value:ne,onChange:j=>B(j.target.value),required:!0,"aria-required":"true"})]}),s.jsx(c.Button,{disabled:pe,type:"submit",className:"w-full",children:i?pe?"Updating...":"Update "+(Q==null?void 0:Q.name):pe?"Creating...":"Create "+(Q==null?void 0:Q.name)})]})}const ia=({addEditPage:e,setAddEditPage:t,closePanel:n})=>{const{data:r}=Se(),a=!!(e!=null&&e.id);return s.jsx(c.Dialog,{open:!!e,onOpenChange:()=>t(void 0),children:s.jsxs(c.DialogContent,{className:"sm:max-w-[425px]",children:[s.jsxs(c.DialogHeader,{children:[s.jsxs(c.DialogTitle,{children:[a?"Edit":"Add New"," "]}),s.jsx(c.DialogDescription,{children:a?"Update your page name":"Enter details to create a new page"})]}),s.jsx(aa,{closePanel:n,addEditPage:e,close:()=>t(void 0),additionalPageTypes:r??[]})]})})},oa=1*1024*1024,la=({page:e,onClose:t})=>{const[n,r]=p.useState(!1),[a,i]=p.useState(""),[o,l]=p.useState(""),[u,d]=p.useState(!1),f=p.useRef(null),h=Kr(),{data:v}=Se(),E=v==null?void 0:v.find(w=>w.key===e.pageType),y=(E==null?void 0:E.name)||g.startCase(e.pageType),N=p.useCallback(w=>{var I;const S=(I=w.target.files)==null?void 0:I[0];if(S){if(S.size>oa){te.toast.error("File too large",{description:`Maximum file size is 1MB. Selected file is ${(S.size/1024).toFixed(2)}KB.`}),f.current&&(f.current.value="");return}try{d(!0);const D=new FileReader;D.onloadend=()=>{l(D.result),d(!1)},D.readAsDataURL(S)}catch(D){console.error("Error reading file:",D),d(!1),te.toast.error("Failed to process image",{description:D instanceof Error?D.message:"Unknown error"})}}},[]),b=()=>{l(""),f.current&&(f.current.value="")},A=()=>{var w;(w=f.current)==null||w.click()},M=()=>{r(!0),h.mutate({page:e,name:e.name,description:a.trim()||void 0,pageType:e.pageType,...o?{previewImage:o}:{}},{onSuccess:()=>{r(!1),t()},onError:()=>{r(!1)}})};return s.jsx(c.Dialog,{open:!0,onOpenChange:t,children:s.jsxs(c.DialogContent,{children:[s.jsxs(c.DialogHeader,{children:[s.jsx(c.DialogTitle,{children:"Mark as template"}),s.jsxs(c.DialogDescription,{className:"py-4 text-slate-500 space-y-1 text-xs",children:["Are you sure you want to mark this page as a template?",s.jsx("br",{}),"Templates can be used to create new pages with the same content."]})]}),s.jsxs("div",{className:"space-y-4 mb-4 text-xs",children:[s.jsxs("div",{className:"p-4 border rounded bg-slate-50 space-y-3",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(P.Tag,{className:"w-4 h-4 text-slate-500"}),s.jsx("span",{className:"font-medium text-slate-500",children:"Page Name:"}),s.jsx("span",{className:"font-semibold",children:g.startCase(e.name)})]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(P.File,{className:"w-4 h-4 text-slate-500"}),s.jsx("span",{className:"font-medium text-slate-500",children:"Type:"}),s.jsx("span",{className:"font-semibold",children:y})]})]}),s.jsxs("div",{children:[s.jsx(c.Label,{htmlFor:"description",className:"text-xs font-medium",children:"Description (Optional)"}),s.jsx(c.Textarea,{id:"description",placeholder:"Describe this template's purpose",className:"text-xs resize-none h-24 mt-1",value:a,onChange:w=>i(w.target.value)})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsx(c.Label,{htmlFor:"previewImage",className:"text-xs font-medium",children:"Preview Image (Optional)"}),s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(c.Input,{type:"file",id:"previewImage",ref:f,onChange:N,accept:"image/*",className:"hidden"}),s.jsx(c.Button,{type:"button",variant:"outline",onClick:A,disabled:u,className:"w-full",children:u?s.jsxs("span",{className:"flex items-center gap-2",children:[s.jsx("div",{className:"animate-spin h-4 w-4 border-2 border-current border-t-transparent rounded-full"}),"Uploading..."]}):s.jsxs("span",{className:"flex items-center gap-2",children:[s.jsx(P.ImageIcon,{className:"h-4 w-4"}),"Select image"]})}),o&&s.jsx(c.Button,{type:"button",variant:"outline",size:"icon",onClick:b,children:s.jsx(P.X,{className:"h-4 w-4"})})]}),o&&s.jsx("div",{className:"rounded-md overflow-hidden border aspect-video",children:s.jsx("img",{src:o,alt:"Preview",className:"w-full h-full max-h-[200px] object-contain"})}),s.jsx("p",{className:"text-xs text-muted-foreground",children:"max 1mb"})]})]})]}),s.jsxs(c.DialogFooter,{className:n?"opacity-75 pointer-events-none":"",children:[s.jsx(c.Button,{variant:"outline",onClick:w=>{w.stopPropagation(),t()},children:"Cancel"}),s.jsx(c.Button,{variant:"default",disabled:n,onClick:M,children:"Mark as template"})]})]})})},ca=({page:e,onClose:t})=>{const[n,r]=p.useState(!1),a=zr(),i=()=>{r(!0),a.mutate(e,{onSuccess:()=>{r(!1),t()},onError:()=>{r(!1)}})};return s.jsx(c.Dialog,{open:!0,onOpenChange:t,children:s.jsxs(c.DialogContent,{children:[s.jsxs(c.DialogHeader,{children:[s.jsx(c.DialogTitle,{children:"Unmark as template"}),s.jsx(c.DialogDescription,{className:"py-4 text-slate-500 space-y-1 text-xs",children:"Are you sure you want to unmark this page as a template?"})]}),s.jsxs(c.DialogFooter,{className:n?"opacity-75 pointer-events-none":"",children:[s.jsx(c.Button,{variant:"outline",onClick:o=>{o.stopPropagation(),t()},children:"Cancel"}),s.jsx(c.Button,{variant:"default",disabled:n,onClick:i,children:"Unmark as template"})]})]})})},as=({parentSlug:e,page:t,active:n,closePanel:r,setUnpublishPage:a,setDeletePage:i,setAddEditPage:o,setMarkAsTemplate:l,setUnmarkAsTemplate:u})=>{const d=cn(),{data:f}=Se(),{hasPermission:h}=J.usePermissions(),v=p.useMemo(()=>g.find(f,{key:t.pageType}),[f,t.pageType]),E=g.get(t,"slug","").replace(e,"")||"/",y=!h(he.EDIT_PAGE)&&!h(he.DELETE_PAGE)&&!h(he.UNPUBLISH_PAGE),N=p.useMemo(()=>!!t.isTemplate,[t.isTemplate]),b=p.useMemo(()=>!!(v!=null&&v.hasSlug),[v==null?void 0:v.hasSlug]);return s.jsxs("div",{onClick:()=>d(g.get(t,"id"),r),className:`rounded flex p-1.5 items-center justify-between leading-none duration-300 cursor-pointer px-3 py-1.5 ${n?"bg-gray-200":"hover:bg-gray-100"}`,children:[s.jsxs("div",{className:"flex items-center gap-x-2",children:[t.dynamic?s.jsx("div",{className:"w-4 h-4 text-slate-500 stroke-[1]",children:s.jsx(P.StarsIcon,{className:"w-4 h-4 text-yellow-400"})}):v!=null&&v.icon?s.jsx("div",{className:"w-4 h-4 text-slate-500 stroke-[1]",dangerouslySetInnerHTML:{__html:v.icon}}):v!=null&&v.hasSlug?s.jsx(P.File,{className:"w-4 h-4 text-slate-500 stroke-[1]"}):s.jsx(P.Globe,{className:"w-4 h-4 text-slate-500 stroke-[1]"}),s.jsx("div",{className:`w-2.5 h-2.5 rounded-full ${t.online?"bg-green-300":"bg-gray-300"}`}),s.jsx("span",{className:"font-light leading-none truncate text-slate-800",children:g.startCase(t.name)??""}),v!=null&&v.hasSlug?s.jsxs(c.Badge,{variant:"outline",className:`ml-2 text-xs max-w-full leading-tight py-px font-normal rounded-full text-gray-400 border ${n?"border-gray-300":"border-gray-200"}`,children:[E,t.dynamic&&s.jsx("span",{className:"text-xs font-light leading-none text-slate-500",children:g.endsWith(E,"/")?`${v==null?void 0:v.dynamicSlug}`:`/${v==null?void 0:v.dynamicSlug}`})]}):s.jsx(c.Badge,{variant:"outline",className:`ml-2 text-xs max-w-full leading-tight py-px font-normal rounded-full text-gray-400 border ${n?"border-gray-300":"border-gray-200"}`,children:v==null?void 0:v.name}),N&&s.jsx(c.Badge,{variant:"outline",className:"ml-2 text-xs py-0 font-normal text-blue-500 border border-blue-200 bg-blue-50",children:"Template"})]}),s.jsx("div",{className:"flex items-center space-x-4",children:!y&&s.jsxs(c.DropdownMenu,{children:[s.jsx(c.DropdownMenuTrigger,{asChild:!0,onClick:A=>A.stopPropagation(),children:s.jsx(P.MoreHorizontal,{className:"h-4 w-4 hover:stroke-[3]"})}),s.jsxs(c.DropdownMenuContent,{align:"end",className:"text-sm",children:[h(he.EDIT_PAGE)&&s.jsxs(c.DropdownMenuItem,{className:"flex items-center gap-2 cursor-pointer",onClick:A=>{A.stopPropagation(),o({...t,global:!(v!=null&&v.hasSlug)})},children:[s.jsx(P.Pencil,{className:"size-3"}),"Edit"]}),(t==null?void 0:t.online)&&h(he.UNPUBLISH_PAGE)&&s.jsxs(c.DropdownMenuItem,{className:"flex items-center gap-2 cursor-pointer",onClick:A=>{A.stopPropagation(),a(t)},children:[s.jsx(P.Power,{className:"size-3"}),H.UNPUBLISH]}),h(he.DELETE_PAGE)&&s.jsxs(c.DropdownMenuItem,{className:"flex items-center gap-2 cursor-pointer",onClick:A=>{A.stopPropagation(),i(t)},children:[s.jsx(P.Trash,{className:"size-3"}),H.DELETE]}),h(he.MARK_AS_TEMPLATE)&&b&&s.jsx(s.Fragment,{children:N?s.jsxs(c.DropdownMenuItem,{className:"flex items-center gap-2 cursor-pointer",onClick:A=>{A.stopPropagation(),u(t)},children:[s.jsx(P.SquareLibrary,{className:"size-3"}),H.UNMARK_AS_TEMPLATE]}):s.jsxs(c.DropdownMenuItem,{className:"flex items-center gap-2 cursor-pointer",onClick:A=>{A.stopPropagation(),l(t)},children:[s.jsx(P.SquareLibrary,{className:"size-3"}),H.MARK_AS_TEMPLATE]})})]})]})})]})},ua=({close:e})=>{const[,t]=p.useState([]),[n,r]=p.useState(""),[a,i]=p.useState(null),[o,l]=p.useState(null),[u,d]=p.useState(null),[f,h]=p.useState(null),[v,E]=p.useState(null),{data:y,isFetching:N}=Rt(),[b,A]=p.useState(""),{hasPermission:M}=J.usePermissions(),[w,S]=Ne(),I=w.get("page"),{data:D}=Se(),le=p.useCallback(C=>{var F;return(F=g.find(D,{key:C}))==null?void 0:F.hasSlug},[D]);p.useEffect(()=>{if(!g.isEmpty(b))return;const C=sessionStorage.getItem("pageTypeFilter")||"all";!g.isEmpty(D)&&C&&(g.find(D,{key:C})?A(C):A("all"))},[D,b]);const ne=C=>{A(C),sessionStorage.setItem("pageTypeFilter",C)},B=p.useCallback(C=>{const re=new URLSearchParams(window.location.search).get("lang"),me=new URLSearchParams({page:C});re&&me.set("lang",re),window.history.pushState({},"",`?${me.toString()}`),S(me),window.dispatchEvent(new PopStateEvent("popstate")),e()},[S,e]);p.useEffect(()=>{if(I&&!N){const C=g.find(y,{id:I});C&&(C!=null&&C.pageType)?t(F=>[...F,C==null?void 0:C.pageType]):(window.history.replaceState(null,"","/"),S(new URLSearchParams({})),window.dispatchEvent(new PopStateEvent("popstate")))}},[y,I,N,S]);const U=p.useMemo(()=>{const C=g.compact(g.filter(y,V=>g.isEmpty(n)?!0:g.includes(g.toLower(V==null?void 0:V.name),g.toLower(n))||g.includes(g.toLower(V==null?void 0:V.slug),g.toLower(n))));if(b!=="all")return g.compact(g.filter(C,{pageType:b}));const F=new Map;C.forEach(V=>{F.set(V.id,{...V,children:[]})});const re=[],me=[];F.forEach(V=>{if(V.parent){const pe=F.get(V.parent);pe?pe.children.push(V):re.push(V)}else me.push(V)}),re.sort((V,pe)=>V.name.localeCompare(pe.name)),re.forEach(V=>{V.children.sort((pe,Q)=>pe.name.localeCompare(Q.name))});const ee=g.filter(me,V=>!le(V.pageType)),fe=g.filter(me,V=>le(V.pageType)).sort((V,pe)=>V.name.localeCompare(pe.name));return g.compact([...fe,...ee,...re])},[y,le,n,b]);return s.jsxs("div",{className:"flex flex-col justify-between h-full",children:[s.jsxs("div",{className:"flex flex-col h-full space-y-6",children:[s.jsxs("div",{className:"relative flex item-center gap-x-4",children:[s.jsx(P.Search,{strokeWidth:2.5,className:"absolute left-3 top-2.5 h-4 w-4 text-gray-400"}),s.jsx(c.Input,{placeholder:"Search pages...",className:"text-xs font-medium leading-none text-gray-700 pl-9 pr-24 placeholder:text-gray-400",value:n,onChange:C=>r(C.target.value)}),!g.isEmpty(b)&&s.jsxs(c.Select,{value:b,onValueChange:ne,children:[s.jsx(c.SelectTrigger,{className:`${b==="all"?"bg-gray-50 hover:bg-gray-100":"bg-gray-100 hover:bg-gray-50"} min-w-[120px] h-max p-0 py-1 pl-2 pr-1 top-1.5 -mt-px absolute text-gray-600 right-1.5 w-max text-xs whitespace-nowrap ring-0 focus:ring-0 shadow-none`,children:s.jsx(c.SelectValue,{placeholder:"Select page type"})}),s.jsx(c.SelectContent,{align:"end",children:g.map(g.concat([{key:"all",name:"All"}],D),C=>s.jsx(c.SelectItem,{value:g.get(C,"key"),children:g.get(C,"name")}))})]})]}),N?s.jsx("div",{className:"space-y-2",children:g.map([...Array(5).keys()],C=>s.jsx("div",{className:"w-full bg-gray-200 rounded h-9 animate-pulse"},C))}):g.isEmpty(U)?s.jsxs("div",{className:"h-[70vh] flex flex-col gap-y-1 items-center justify-center text-slate-500 text-sm font-medium",children:[s.jsx(P.File,{className:"h-6 w-6 stroke-[1]"}),"Empty List!",s.jsx("span",{className:"font-light",children:"Add new page to start"})]}):s.jsx("div",{className:"text-sm text-slate-700 space-y-2 h-[70vh] overflow-y-auto",children:g.map(U,C=>g.isEmpty(C==null?void 0:C.children)?s.jsx(as,{closePanel:e,setUnpublishPage:l,setDeletePage:i,setAddEditPage:d,setMarkAsTemplate:h,setUnmarkAsTemplate:E,active:I===C.id,page:C},C.id):s.jsxs("div",{className:"border-0",children:[s.jsx(as,{closePanel:e,setUnpublishPage:l,setDeletePage:i,setAddEditPage:d,setMarkAsTemplate:h,setUnmarkAsTemplate:E,active:I===C.id,page:C}),s.jsx("div",{className:"pt-2 pl-6 bg-white",children:g.map(g.get(C,"children",[]),F=>{const re=I===g.get(F,"id");return s.jsx(as,{parentSlug:C.slug,closePanel:e,setUnpublishPage:l,setDeletePage:i,setAddEditPage:d,setMarkAsTemplate:h,setUnmarkAsTemplate:E,active:re,page:F},F.id)})})]},C.key))})]}),M(he.ADD_PAGE)&&s.jsxs(c.Button,{className:"flex text-sm gap-x-2",onClick:()=>{d({slug:"",name:"",pageType:b==="all"?"page":b})},children:[s.jsx(P.Plus,{className:"w-4 h-4"})," Add New"]}),u&&s.jsx(ia,{closePanel:e,editPage:B,addEditPage:u,setAddEditPage:d}),a&&s.jsx(on,{page:a,onClose:()=>i(null)}),o&&s.jsx(Ns,{page:o,onClose:()=>l(null)}),f&&s.jsx(la,{page:f,onClose:()=>h(null)}),v&&s.jsx(ca,{page:v,onClose:()=>E(null)})]})},da=()=>{const e=Re("logo",null);return e?s.jsx("div",{className:"w-full max-h-9 overflow-hidden pr-2",children:p.createElement(e,{})}):null},ha=()=>{const[e]=Ne(),t=e.get("page"),{data:n,isFetching:r}=Ae(),[a,i]=p.useState(!1),{savePage:o}=J.useSavePage(),l=!!t&&!g.isEmpty(n),u=!t||!r&&g.isEmpty(n)||a;return s.jsxs(s.Fragment,{children:[s.jsxs(c.Button,{variant:"secondary",className:"flex items-center w-full space-x-2 py-1",onClick:()=>{o(),i(!0)},children:[s.jsx("div",{children:s.jsx(P.Logs,{className:"h-4 w-4"})}),s.jsxs("span",{className:"truncate leading-tight flex items-center max-w-[200px]",children:[s.jsx("span",{className:"text-slate-600 pr-1 font-light",children:"Editing:"}),r?s.jsx(P.Loader,{className:"h-4 w-4 animate-spin text-slate-400 ml-2"}):g.startCase(g.get(n,"name"))??""]})]},"template-viewer"),s.jsx(c.Sheet,{open:u,onOpenChange:d=>!d&&l&&i(!1),children:s.jsxs(c.SheetContent,{side:"left",className:`!max-w-screen-md z-50 border-border w-full ${l?"":"sheet-hide-close-btn"}`,children:[s.jsx(c.SheetHeader,{className:"mb-3",children:s.jsxs(c.SheetTitle,{className:"text-sm flex items-center gap-2 font-semibold",children:[s.jsx("div",{className:"p-2 rounded-md bg-primary text-primary-foreground",children:s.jsx(P.File,{className:"w-6 h-6"})}),s.jsxs("div",{className:"flex flex-col",children:[s.jsx("span",{className:"text-sm font-semibold",children:"Pages"}),s.jsx("span",{className:"text-xs text-muted-foreground",children:"Manage your site structure"})]})]})}),s.jsx("div",{className:"h-[calc(100vh-100px)] overflow-y-auto",children:s.jsx(ua,{close:()=>i(!1)})})]})})]})},ma=()=>{const{fallbackLang:e,languages:t,selectedLang:n,setSelectedLang:r}=J.useLanguages(),a=g.isEmpty(n)?e:n,[,i]=Ne();p.useEffect(()=>{const y=new URLSearchParams(window.location.search),N=y.get("lang");N&&(t.includes(N)?r(N):(y.delete("lang"),i(y),r("")))},[t,i,r]);const[o,l]=p.useState(null),{data:u}=Ae(),{data:d}=ft(),{data:f,isFetching:h}=mt(),v=p.useMemo(()=>{const y=g.compact(g.map(g.get(d,"languages"),N=>{const b=g.find(f,{lang:N});return{key:N,value:g.get(_e,N,N),isLangPageAdded:!!b}})).filter(Boolean);return[{key:e,value:g.get(_e,e),isLangPageAdded:!0},...y]},[e,f,d]),E=y=>{r(y);const N=new URLSearchParams(window.location.search);y===e?N.delete("lang"):N.set("lang",y);const b=N.toString(),A=`${window.location.pathname}${b?`?${b}`:""}`;window.history.pushState({},"",A),i(N),window.dispatchEvent(new PopStateEvent("popstate"))};return g.isEmpty(t)||h?null:s.jsxs(s.Fragment,{children:[s.jsxs(c.DropdownMenu,{children:[s.jsx(c.DropdownMenuTrigger,{asChild:!0,className:"focus:outline-none",children:s.jsxs(c.Button,{variant:"ghost",size:"sm",className:"gap-2",children:[s.jsx(P.Languages,{className:"w-4 h-4"}),g.get(_e,a,a),s.jsx(P.ChevronDown,{className:"w-4 h-4"})]})}),s.jsxs(c.DropdownMenuContent,{className:"border-border space-y-1",children:[g.map(v.filter(y=>y.isLangPageAdded),y=>s.jsxs(c.DropdownMenuItem,{className:J.mergeClasses("flex cursor-pointer items-center justify-between text-xs font-medium text-gray-800",y.key===a&&"!bg-gray-200 text-gray-700"),onClick:()=>E(y.key),children:[s.jsx("div",{className:"text-slate-600",children:y.value}),y.key===e&&s.jsxs("small",{className:"text-[9px] flex items-center gap-x-1 text-orange-500 leading-none",children:[s.jsx(P.Star,{fill:"orange",className:"w-2 h-2"}),"Primary"]})]},y.value)),!g.isEmpty(v.filter(y=>!y.isLangPageAdded))&&s.jsxs(s.Fragment,{children:[s.jsx(c.Separator,{}),s.jsxs(c.Button,{size:"sm",variant:"ghost",onClick:()=>{l({name:u==null?void 0:u.name,pageType:u==null?void 0:u.pageType,lang:"",slug:"",edit:!1})},className:"hover:bg-slate-300 duration-200 font-normal text-xs hover:text-slate-800",children:[s.jsx(P.Plus,{className:"w-3 h-3 mr-1"})," Add Langauge"]})]})]})]}),o&&s.jsx(ln,{languages:t,langProps:o,onClose:()=>l(null)})]})};function fa(){return s.jsxs("div",{className:"flex relative z-10 items-center justify-end gap-1",children:[s.jsx(da,{}),s.jsx(ha,{}),s.jsx(ma,{})]})}function ga(e){const t=se(),n=X();return k.useQuery({queryKey:[W,"revisions",e],queryFn:async()=>await n(t,{action:_.GET_PAGE_REVISIONS,data:{pageId:e}}),enabled:!!e,gcTime:0,staleTime:0})}const pa=()=>{const e=se(),t=X(),n=k.useQueryClient();return k.useMutation({mutationFn:async r=>await t(e,{action:_.DELETE_PAGE_REVISION,data:{revisionId:r}}),onSuccess:()=>{n.invalidateQueries({queryKey:[W,"revisions"]})}})},xa=()=>{const e=se(),t=X(),n=k.useQueryClient();return k.useMutation({mutationFn:async({revisionId:r,discardCurrent:a})=>await t(e,{action:_.RESTORE_PAGE_REVISION,data:{revisionId:r,discardCurrent:a}}),onSuccess:()=>{n.invalidateQueries({queryKey:[W,"revisions"]})}})};function ya(){const{data:e}=Ae(),{saveState:t}=J.useSavePage(),[n]=bs();return e?s.jsx("div",{className:"flex items-start gap-3 rounded-md border p-2 hover:bg-accent/50 bg-primary/5 mb-4",children:s.jsxs("div",{className:"flex-1 space-y-1",children:[s.jsx("div",{className:"flex items-center justify-between",children:s.jsx("p",{className:"text-sm flex items-center gap-1 font-medium leading-none",children:s.jsx("span",{className:"font-bold",children:"Currently editing"})})}),s.jsx("div",{className:"flex items-center text-xs text-muted-foreground",children:!g.isEmpty(n.lastSaved)&&s.jsxs("span",{children:["Last updated"," ",Mt.formatDistanceToNow(new Date(n.lastSaved),{addSuffix:!0})]})}),s.jsxs("div",{className:"flex items-center gap-2 pt-0.5",children:[s.jsxs("div",{className:"flex items-center gap-1 rounded-full bg-amber-500/10 px-1.5 py-0.5 text-xs text-amber-600",children:[s.jsx(P.Edit,{className:"h-3 w-3"}),s.jsx("span",{children:"Draft"})]}),t==="UNSAVED"?s.jsxs("div",{className:"flex items-center gap-1 rounded-full bg-red-500/10 px-1.5 py-0.5 text-xs text-red-600",children:[s.jsx(P.Save,{className:"h-3 w-3"}),s.jsx("span",{children:" Unsaved changes"})]}):null]})]})}):null}function va(){const[e,t]=ge.useState(!1),[n,r]=ge.useState(null),[a,i]=ge.useState(!1),[o,l]=ge.useState(!1),{data:u}=Ae(),{data:d,isFetching:f,error:h,refetch:v}=ga(u==null?void 0:u.id),{mutate:E,isPending:y}=pa(),{mutate:N,isPending:b}=xa(),A=k.useQueryClient(),M=D=>{n&&N({revisionId:n.uid,discardCurrent:D},{onSuccess:()=>{i(!1),r(null),A.invalidateQueries({queryKey:[W,_.GET_DRAFT_PAGE]})}})},w=D=>{r(D),i(!0)},S=D=>{r(D),l(!0)},I=()=>{n&&E(n.uid,{onSuccess:()=>{l(!1),r(null)}})};return p.useEffect(()=>{e&&v()},[e,v]),s.jsxs(s.Fragment,{children:[s.jsx(c.TooltipProvider,{children:s.jsxs(c.Tooltip,{children:[s.jsxs(c.Sheet,{open:e,onOpenChange:t,children:[s.jsx(c.SheetTrigger,{asChild:!0,children:s.jsx(c.TooltipTrigger,{asChild:!0,children:s.jsxs("span",{className:"flex items-center gap-2",children:[s.jsxs(c.Button,{variant:"ghost",size:"icon",className:"h-8 w-8",children:[s.jsx(P.History,{className:"h-4 w-4"}),s.jsx("span",{className:"sr-only",children:"View revision history"})]}),s.jsx("div",{className:"w-px h-4 bg-gray-200 dark:bg-gray-700"})]})})}),s.jsxs(c.SheetContent,{className:"sm:max-w-md p-4",children:[s.jsxs(c.SheetHeader,{className:"pb-2",children:[s.jsxs(c.SheetTitle,{className:"flex items-center gap-2",children:[s.jsx(P.History,{className:"h-5 w-5"}),"Revision History"]}),(u==null?void 0:u.createdAt)&&s.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:["Page created on"," ",Mt.format(new Date(u.createdAt),"MMM d, yyyy 'at' h:mm a")]})]}),s.jsx(c.ScrollArea,{className:"h-[calc(100vh-6rem)] pr-2",children:f?s.jsx(Ea,{}):h?s.jsx("div",{className:"p-4 text-center text-sm text-muted-foreground",children:"Failed to load revisions. Please try again."}):s.jsxs("div",{className:"mt-2 space-y-2",children:[s.jsx(ya,{}),d==null?void 0:d.map(D=>s.jsx(ba,{revision:D,isLatest:D.uid==="current",onRestore:()=>w(D),onDelete:()=>S(D)},D.uid))]})})]})]}),s.jsx(c.TooltipContent,{side:"bottom",children:s.jsx("p",{children:"Revision history"})})]})}),s.jsx(Sa,{open:a,onOpenChange:i,revision:n,onRestore:M,isRestoring:b}),s.jsx(wa,{open:o,onOpenChange:l,revision:n,onDelete:I,isDeleting:y})]})}function Ea(){return s.jsx("div",{className:"space-y-2 mt-2",children:Array.from({length:5}).map((e,t)=>s.jsxs("div",{className:"flex items-start gap-3 rounded-md border p-2",children:[s.jsxs("div",{className:"flex-1 space-y-1",children:[s.jsx(c.Skeleton,{className:"h-4 w-3/4"}),s.jsx(c.Skeleton,{className:"h-3 w-1/2"}),s.jsx(c.Skeleton,{className:"h-5 w-20 mt-1"})]}),s.jsx(c.Skeleton,{className:"h-8 w-8 rounded-full"})]},t))})}function ba({revision:e,isLatest:t,onRestore:n,onDelete:r}){const{data:a}=gt(e.currentEditor),i=(a==null?void 0:a.name)||"Unknown";return s.jsxs("div",{className:"flex items-start gap-3 rounded-md border p-2 hover:bg-accent/50",children:[s.jsxs("div",{className:"flex-1 space-y-1",children:[s.jsx("div",{className:"flex items-center justify-between",children:s.jsxs("p",{className:"text-sm flex items-center gap-1 font-medium leading-none",children:[e.type==="published"?"Published":"Draft"," by ",s.jsx("span",{className:"font-bold",children:i}),t&&s.jsxs("span",{className:"ml-2 flex items-center gap-1 rounded-full bg-primary/10 px-1.5 py-0.5 text-xs text-primary",children:[s.jsxs("span",{className:"mr-1 relative flex h-2 w-2",children:[s.jsx("span",{className:"animate-ping absolute inline-flex h-full w-full rounded-full bg-green-400 opacity-75"}),s.jsx("span",{className:"relative inline-flex rounded-full h-2 w-2 bg-green-500"})]}),"Live"]})]})}),s.jsx("div",{className:"flex items-center text-xs text-muted-foreground",children:s.jsx("span",{children:Mt.format(e.createdAt,"MMM d, h:mm a")})}),s.jsx("div",{className:"flex items-center gap-2 pt-0.5",children:e.type==="published"?s.jsxs("div",{className:"flex items-center gap-1 rounded-full bg-green-500/10 px-1.5 py-0.5 text-xs text-green-600",children:[s.jsx(P.ArrowUpRight,{className:"h-3 w-3"}),s.jsx("span",{children:"Published"})]}):s.jsxs("div",{className:"flex items-center gap-1 rounded-full bg-amber-500/10 px-1.5 py-0.5 text-xs text-amber-600",children:[s.jsx(P.Clock,{className:"h-3 w-3"}),s.jsx("span",{children:"Draft"})]})})]}),s.jsx(Te,{permissions:[he.RESTORE_REVISION,he.DELETE_REVISION],children:s.jsx(ja,{revision:e,onRestore:n,onDelete:r})})]})}function ja({revision:e,onRestore:t,onDelete:n}){return s.jsxs(c.DropdownMenu,{children:[s.jsx(c.DropdownMenuTrigger,{asChild:!0,children:s.jsxs(c.Button,{variant:"ghost",size:"icon",className:"h-7 w-7 -mr-1",children:[s.jsx(P.MoreHorizontal,{className:"h-4 w-4"}),s.jsx("span",{className:"sr-only",children:"More options"})]})}),s.jsxs(c.DropdownMenuContent,{align:"end",className:"text-xs",children:[s.jsx(Te,{permission:he.RESTORE_REVISION,children:s.jsxs(c.DropdownMenuItem,{onClick:t,className:"cursor-pointer",children:[s.jsx(P.Undo2,{className:"mr-2 h-4 w-4"}),s.jsx("span",{children:"Restore this version"})]})}),s.jsx(Te,{permission:he.DELETE_REVISION,children:e.uid!=="current"&&s.jsxs(s.Fragment,{children:[s.jsx(c.DropdownMenuSeparator,{}),s.jsxs(c.DropdownMenuItem,{onClick:n,className:"cursor-pointer text-destructive",children:[s.jsx(P.Trash,{className:"mr-2 h-4 w-4"}),s.jsx("span",{children:"Delete this version"})]})]})})]})]})}function Sa({open:e,onOpenChange:t,revision:n,onRestore:r,isRestoring:a}){const{data:i}=gt((n==null?void 0:n.currentEditor)||""),o=(i==null?void 0:i.name)||"Unknown";return n?s.jsx(c.Dialog,{open:e,onOpenChange:l=>{a||t(l)},children:s.jsxs(c.DialogContent,{className:"sm:max-w-md",children:[s.jsxs(c.DialogHeader,{children:[s.jsx(c.DialogTitle,{children:"Restore Revision"}),s.jsxs(c.DialogDescription,{children:["You are about to restore to revision ",n.uid.substring(0,8)," ","from ",Mt.format(n.createdAt,"MMM d, yyyy 'at' h:mm a")," by"," ",o]})]}),s.jsx("div",{className:"py-2",children:s.jsx("p",{className:"text-sm text-muted-foreground",children:"How would you like to handle your current edits?"})}),s.jsxs(c.DialogFooter,{className:"flex flex-col sm:flex-row gap-2",children:[s.jsx(c.Button,{variant:"outline",className:"sm:flex-1",onClick:()=>r(!1),disabled:a,children:a?s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"mr-2 h-4 w-4 animate-spin rounded-full border-2 border-current border-t-transparent"}),"Saving as draft..."]}):s.jsxs(s.Fragment,{children:[s.jsx(P.CloudOff,{className:"mr-2 h-4 w-4"}),"Save as draft"]})}),s.jsx(c.Button,{variant:"default",className:"sm:flex-1",onClick:()=>r(!0),disabled:a,children:a?s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"mr-2 h-4 w-4 animate-spin rounded-full border-2 border-current border-t-transparent"}),"Discarding current..."]}):s.jsxs(s.Fragment,{children:[s.jsx(P.Undo2,{className:"mr-2 h-4 w-4"}),"Discard current"]})})]})]})}):null}function wa({open:e,onOpenChange:t,revision:n,onDelete:r,isDeleting:a}){const{data:i}=gt((n==null?void 0:n.currentEditor)||""),o=(i==null?void 0:i.name)||"Unknown";return n?s.jsx(c.Dialog,{open:e,onOpenChange:l=>{a||t(l)},children:s.jsxs(c.DialogContent,{className:"sm:max-w-md",children:[s.jsxs(c.DialogHeader,{children:[s.jsx(c.DialogTitle,{children:"Delete Revision"}),s.jsxs(c.DialogDescription,{children:["You are about to delete revision ",n.uid.substring(0,8)," from"," ",Mt.format(n.createdAt,"MMM d, yyyy 'at' h:mm a")," by"," ",o]})]}),s.jsx("div",{className:"py-2",children:s.jsx("p",{className:"text-sm text-muted-foreground",children:"This action cannot be undone. Are you sure you want to proceed?"})}),s.jsxs(c.DialogFooter,{className:"flex flex-col sm:flex-row gap-2",children:[s.jsx(c.Button,{variant:"outline",className:"sm:flex-1",onClick:()=>t(!1),disabled:a,children:"Cancel"}),s.jsx(c.Button,{variant:"destructive",className:"sm:flex-1",onClick:r,disabled:a,children:a?s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"mr-2 h-4 w-4 animate-spin rounded-full border-2 border-current border-t-transparent"}),"Deleting..."]}):s.jsxs(s.Fragment,{children:[s.jsx(P.Trash,{className:"mr-2 h-4 w-4"}),"Delete Revision"]})})]})]})}):null}const Na=()=>{const e=se(),t=X();return k.useQuery({queryKey:[W,_.GET_CHANGES],queryFn:async()=>t(e,{action:_.GET_CHANGES})})},Aa=({currentEditor:e})=>{const{data:t}=gt(e);return t==null?void 0:t.name};function Ta({showModal:e=!1,onClose:t=()=>console.log("Cancelled")}){const[n,r]=p.useState([]),{data:a,isFetching:i}=Na(),{data:o}=Se(),l=p.useCallback(S=>{var I;return(I=g.find(o,{key:S}))==null?void 0:I.hasSlug},[o]),u=p.useMemo(()=>g.filter(o,S=>!l(S.key)).map(S=>S.key),[l,o]),d=p.useMemo(()=>g.filter(a,S=>!u.includes(S.pageType)),[a,u]),f=p.useMemo(()=>g.filter(a,S=>u.includes(S.pageType)),[a,u]),h=p.useMemo(()=>g.find(a,{pageType:"theme",id:"THEME"}),[a]),{mutate:v,isPending:E}=Ss();p.useEffect(()=>{const S=g.map(g.filter(a,{online:!0}),"id");h&&S.push(h==null?void 0:h.id),r(S)},[a,h]);const y=n.length===(a==null?void 0:a.length),N=S=>{r(I=>g.includes(I,S)?g.filter(I,D=>D!==S):g.concat(I,S))},b=()=>{r(y?[]:g.map(a,"id"))},A=()=>{v({ids:g.uniq(n)},{onSuccess:()=>{t(),zt("CENTER_CENTER")}})},M=S=>{if(S==="theme")return"Theme";const I=g.find(o,{key:S});return I?I==null?void 0:I.name:S},w=p.useMemo(()=>{const S=[{label:"Updated",top:"pt-2"},...g.orderBy(g.filter(d,{online:!0}),"pageType"),...g.orderBy(g.filter(f,{online:!0}),"pageType")].filter(le=>le.pageType!=="theme"),I=[{label:"Offline",top:"pt-6"},...g.orderBy(g.filter(d,{online:!1}),"pageType"),...g.orderBy(g.filter(f,{online:!1}),"pageType")],D=h?[{label:"Theme",top:"pt-6"},h]:[];return[...S,...D,...I]},[d,f,h]);return s.jsx(c.Dialog,{open:e,onOpenChange:E?()=>{}:t,children:s.jsxs(c.DialogContent,{className:"max-w-4xl max-h-[80%] flex flex-col",children:[s.jsxs(c.DialogHeader,{children:[s.jsx(c.DialogTitle,{children:"Publish changes"}),s.jsx(c.DialogDescription,{className:"text-xs",children:"Select the pages you want to publish. Click publish when you're done."})]}),s.jsx("div",{className:"relative h-full max-h-full -mx-4 overflow-y-auto no-scrollbar",children:i?s.jsxs("div",{className:"px-1 space-y-2",children:[s.jsx("div",{className:"w-full h-6 mt-2 bg-gray-200 rounded animate-pulse"}),s.jsx("div",{className:"w-full h-6 bg-gray-200 rounded animate-pulse"}),s.jsx("div",{className:"w-full h-6 bg-gray-200 rounded animate-pulse"}),s.jsx("div",{className:"w-full h-6 bg-gray-200 rounded animate-pulse"})]}):s.jsxs("table",{className:"w-full text-xs text-left text-gray-500 rtl:text-right dark:text-gray-400",children:[s.jsx("thead",{className:"text-gray-700 border-b bg-gray-50 dark:bg-gray-700 dark:text-gray-400",children:s.jsxs("tr",{children:[s.jsxs("th",{scope:"col",className:"px-6 py-3 flex items-center gap-x-2 w-[1 50px]",children:[s.jsx("input",{checked:y,onClick:S=>{S.stopPropagation(),b()},type:"checkbox",className:"mt-1 rounded cursor-pointer focus:outline-none focus:ring-0"}),"Name"]}),s.jsx("th",{scope:"col",className:"px-2 py-3 w-[100px]",children:"Language"}),s.jsx("th",{scope:"col",className:"px-2 py-3 w-[100px]",children:"Type"}),s.jsx("th",{scope:"col",className:"px-4 py-3 w-[150px] text-right",children:"Status"})]})}),s.jsx("tbody",{children:g.map(w,S=>S.label?s.jsx("tr",{children:s.jsxs("td",{colSpan:4,className:`px-6 py-2 text-xs font-medium text-gray-800 relative ${S.top}`,children:[s.jsx("div",{className:"absolute inset-0 flex items-center left-6",children:s.jsx("div",{className:"w-full order-gray-300"})}),s.jsx("div",{className:"relative flex justify-start",children:s.jsx("span",{className:"pr-2 bg-gray-50",children:S.label})})]})},"separator"):s.jsxs("tr",{className:"border-b group hover:bg-gray-50 last:border-b-0",children:[s.jsxs("td",{scope:"row",className:"flex items-center px-6 py-2 text-gray-900 whitespace-nowrap dark:text-white gap-x-1",children:[s.jsx("input",{checked:g.includes(n,S==null?void 0:S.id),onClick:I=>{I.stopPropagation(),N(S==null?void 0:S.id)},type:"checkbox",className:"rounded cursor-pointer focus:outline-none focus:ring-0"})," ",l(S.pageType)?s.jsx(P.File,{className:"w-4 h-4"}):s.jsx(P.GlobeIcon,{className:"w-4 h-4"}),S.name,S.slug&&s.jsxs("span",{className:"text-xs text-gray-500",children:["(",S.slug,")"]}),S.currentEditor&&s.jsx("div",{className:"flex items-center gap-x-1",children:s.jsxs("span",{className:"flex text-xs font-bold text-gray-500",children:[" ","-"," ",s.jsx(Aa,{currentEditor:S.currentEditor})," ","is editing"]})})]}),s.jsx("td",{className:"px-2",children:S.lang}),s.jsx("td",{className:"px-2",children:M(S==null?void 0:S.pageType)}),s.jsx("td",{className:"px-4 text-right",children:g.first(S.changes)||""})]},S==null?void 0:S.id))})]})}),s.jsxs(c.DialogFooter,{className:"mt-10",children:[s.jsx(c.Button,{disabled:E,variant:"outline",onClick:t,children:"Cancel"}),s.jsx(c.Button,{disabled:E||i||g.isEmpty(a),onClick:A,children:E?"Publishing...":"Publish"})]})]})})}const Ca=()=>{const e=X(),t=se();return k.useQuery({queryKey:[_.GET_WEBSITE_DATA],staleTime:1e3*60*5,queryFn:async()=>e(t,{action:_.GET_WEBSITE_DATA,data:{draft:!0}})})};function Pa({onClose:e}){const{data:t,isFetching:n}=Ca(),{mutateAsync:r,isPending:a}=Er(),i=Re("settingComponent",null),o=g.debounce(async l=>(await r({data:l}),!0),300);return i?s.jsx(c.Dialog,{open:!0,onOpenChange:e,children:s.jsxs(c.DialogContent,{className:"w-full",children:[s.jsx(c.DialogHeader,{children:s.jsx(c.DialogTitle,{children:"Website Settings"})}),n?s.jsxs("div",{className:"w-full space-y-3 py-4",children:[s.jsx("div",{className:"w-full h-8 rounded bg-gray-300 animate-pulse"}),s.jsx("div",{className:"w-full h-8 rounded bg-gray-300 animate-pulse"}),s.jsx("div",{className:"w-full h-8 rounded bg-gray-300 animate-pulse"}),s.jsx("div",{className:"w-full h-8 rounded bg-gray-300 animate-pulse"}),s.jsx("div",{className:"w-full h-8 rounded bg-gray-300 animate-pulse"}),s.jsx("div",{className:"w-full h-8 rounded bg-gray-300 animate-pulse"})]}):s.jsx("div",{children:p.createElement(i,{data:t||{},onSave:a?()=>{}:o,cancel:a?()=>{}:e})})]})}):null}function un({children:e,content:t}){return s.jsx(c.TooltipProvider,{children:s.jsxs(c.Tooltip,{children:[s.jsx(c.TooltipTrigger,{asChild:!0,children:e}),s.jsx(c.TooltipContent,{side:"bottom",sideOffset:10,children:s.jsx("p",{children:t})})]})})}const _a=()=>{const{selectedLang:e}=J.useLanguages(),t=Re("getPreviewUrl",async f=>f),[n,r]=p.useState(""),{data:a,isFetching:i}=Ae(),{data:o}=mt(),{data:l}=Se(),u=p.useMemo(()=>{var f;return(f=o==null?void 0:o.find(h=>(h==null?void 0:h.lang)===e))==null?void 0:f.slug},[e,o]),d=p.useCallback(f=>{var h;return(h=g.find(l,{key:f}))==null?void 0:h.hasSlug},[l]);return p.useEffect(()=>{(async()=>{if(u&&typeof t=="function"){const f=await t(u||"");r(f)}else r("")})()},[t,u]),!n||!d(a==null?void 0:a.pageType)||i?null:s.jsx(s.Fragment,{children:s.jsx("a",{href:n,target:"_blank",rel:"noopener noreferrer",children:s.jsxs(c.Button,{variant:"ghost",size:"sm",className:"gap-2",children:[s.jsx(P.Eye,{className:"w-4 h-4"})," ",H.PREVIEW]})})})},Ia=()=>{const[e,t]=J.useRightPanel();return s.jsxs(s.Fragment,{children:[s.jsx(un,{content:H.THEME,children:s.jsx(c.Button,{variant:e==="theme"?"outline":"ghost",size:"icon",className:"gap-2",onClick:()=>t(e==="theme"?"block":"theme"),children:s.jsx(P.Palette,{className:"w-4 h-4"})})}),s.jsx("div",{className:"w-px h-4 bg-gray-200 dark:bg-gray-700"})]})},ka=()=>{const[e,t]=p.useState(!1),{isLocked:n}=Ut(),{savePage:r,saveState:a}=J.useSavePage();p.useEffect(()=>{const f=h=>{a==="UNSAVED"&&(h.preventDefault(),h.returnValue=!1)};return a==="UNSAVED"&&window.addEventListener("beforeunload",f),()=>{window.removeEventListener("beforeunload",f)}},[a]);const i=p.useCallback(async()=>{t(!0),await r(!1)},[r]);p.useEffect(()=>{a==="SAVED"&&t(!1)},[a]);const o=p.useMemo(()=>{if(a==="SAVED"||a==="UNSAVED")return a;if(a==="SAVING")return e?a:"SAVED"},[e,a]),{buttonIcon:l,buttonClass:u,tooltipContent:d}=p.useMemo(()=>{switch(o){case"UNSAVED":return{tooltipContent:H.SAVEDRAFT,buttonIcon:s.jsx(P.Save,{className:"w-4 h-4"}),buttonClass:"flex items-center gap-x-1 leading-tight"};case"SAVING":return{tooltipContent:H.SAVING,buttonIcon:s.jsx(P.Loader,{className:"w-4 h-4 animate-spin"}),buttonClass:"flex items-center gap-x-1 leading-tight"};case"SAVED":return{tooltipContent:H.SAVED,buttonIcon:s.jsx(P.CheckCircle,{className:"w-4 h-4"}),buttonClass:"text-green-500 flex items-center gap-x-1 leading-tight"}}},[o]);return n?null:s.jsxs(c.Button,{size:"sm",variant:"ghost",onClick:i,className:u,children:[l," ",d]})},La=()=>{const[e,t]=p.useState(!1),[n,r]=p.useState(!1),[a,i]=p.useState(null),{data:o}=Ae(),{mutate:l,isPending:u}=Ss(),[d]=J.useBlocksStore(),{buttonText:f,buttonClassName:h,isPublished:v}=p.useMemo(()=>{const y=o&&(o==null?void 0:o.online);return{buttonClassName:y?"hover:bg-green-600 bg-green-500":"",isPublished:y,buttonText:y?H.PUBLISHED:H.PUBLISH}},[o]),E=async()=>{var N,b;const y=((b=(N=d==null?void 0:d.filter(A=>(A==null?void 0:A._type)==="GlobalBlock"))==null?void 0:N.map(A=>A==null?void 0:A.globalBlock))==null?void 0:b.filter(A=>typeof A=="string"))||[];l({ids:[o==null?void 0:o.id,...y]},{onSuccess:()=>zt("TOP_RIGHT")})};return s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"flex",children:[s.jsxs(c.Button,{size:"sm",onClick:E,disabled:u||!(o!=null&&o.id),className:`relative overflow-hidden transition-all duration-300 ease-in-out text-white flex items-center gap-1 rounded-r-none ${h}`,onMouseEnter:()=>r(!0),onMouseLeave:()=>r(!1),children:[s.jsx("span",{className:`flex items-center transition-transform duration-300 ease-in-out ${n?"-translate-y-10":""}`,children:v?s.jsx(P.Send,{className:"w-4 h-4"}):s.jsx(P.Rocket,{className:"w-4 h-4"})}),s.jsx("span",{className:`absolute inset-0 flex items-center left-3 transition-transform duration-300 ease-in-out ${n?"":"translate-y-10"}`,children:v?s.jsx(P.Rocket,{className:"w-4 h-4"}):s.jsx(P.Send,{className:"w-4 h-4"})}),s.jsx("span",{children:f})]}),s.jsxs(c.DropdownMenu,{children:[s.jsx(c.DropdownMenuTrigger,{asChild:!0,children:s.jsx(c.Button,{size:"sm",disabled:u||!(o!=null&&o.id),className:`px-2 text-white border-l border-white/50 rounded-l-none ${h}`,children:s.jsx(P.ChevronDown,{className:"w-4 h-4"})})}),s.jsxs(c.DropdownMenuContent,{align:"end",className:"w-36",children:[!v&&s.jsxs(c.DropdownMenuItem,{disabled:u,className:"text-xs cursor-pointer",onClick:()=>l({ids:[o==null?void 0:o.id]},{onSuccess:()=>zt("TOP_RIGHT")}),children:[H.PUBLISH," page"]}),s.jsxs(c.DropdownMenuItem,{onClick:()=>t(!0),className:"text-xs cursor-pointer",children:[H.OPEN," publish menu"]}),v&&s.jsxs(c.DropdownMenuItem,{onClick:()=>i(o),className:"text-xs cursor-pointer",children:[H.UNPUBLISH," page"]})]})]})]}),s.jsx(Ta,{showModal:e,onClose:()=>t(!1)}),a&&s.jsx(Ns,{page:a,onClose:()=>i(null)})]})},Da=()=>{const e=Re("settingComponent",null),[t,n]=p.useState(!1);return e?s.jsxs(s.Fragment,{children:[s.jsx(un,{content:H.WEBSITEDATA,children:s.jsx(c.Button,{variant:"ghost",size:"icon",className:"gap-2",onClick:()=>n(!0),children:s.jsx(P.Settings,{className:"w-4 h-4"})})}),t&&s.jsx(Pa,{onClose:()=>n(!1)}),s.jsx("div",{className:"w-px h-4 bg-gray-200 dark:bg-gray-700"})]}):null},Ba=()=>{const{data:e}=Ae(),t=e&&(e==null?void 0:e.online),{data:n}=Se();return p.useCallback(a=>{var i;return(i=g.find(n,{key:a}))==null?void 0:i.hasSlug},[n])(e==null?void 0:e.pageType)?s.jsxs(c.Button,{onClick:()=>t&&window.open(`${window.location.origin}${e.slug}`,"_blank"),disabled:!t,variant:"ghost",size:"sm",className:"flex items-center gap-1",children:[s.jsx(P.ExternalLink,{className:"w-4 h-4"}),s.jsx("span",{className:"hidden sm:inline",children:H.OPEN})]}):null};function Ga(){const{isLocked:e}=Ut(),[t]=Ne(),n=t.get("lang"),r=sn(n);return e||!r?null:s.jsxs("div",{className:"flex items-center justify-end gap-1",children:[s.jsx(va,{}),s.jsx(Te,{permission:he.EDIT_THEME,children:s.jsx(Ia,{})}),s.jsx(Te,{permission:he.EDIT_SETTINGS,children:s.jsx(Da,{})}),s.jsx(_a,{}),s.jsx(Te,{permission:he.SAVE_PAGE,children:s.jsx(ka,{})}),s.jsx(Te,{permission:he.PUBLISH_PAGE,children:s.jsx(La,{})}),s.jsx(Ba,{})]})}const Ma=()=>s.jsxs("div",{className:"flex px-2 h-full items-center justify-between w-full",children:[s.jsx(fa,{}),s.jsx(Ga,{})]}),Ra=()=>{const e=se(),{aiContext:t}=Es(),n=X();return p.useCallback(async(r,a,i,o)=>n(e,{action:_.ASK_AI,data:{type:r,prompt:a,blocks:i,context:t,lang:o}}),[e,t,n])},Ua=(e,t)=>t.map(n=>{if(g.has(e,n._type)){const r=Ys.getDefaultBlockProps(n._type);return{...r,...g.pick(n,[...g.keys(r),"_type","_id","_name","_parent","_bindings"]),...g.pickBy(n,(a,i)=>g.endsWith(i,"_attrs")),...n}}return n}),Oa=e=>{const t=Ys.useRegisteredChaiBlocks();return p.useMemo(()=>{if(!e||g.isEmpty(e))return{blocks:[]};const n=g.filter(e,r=>!g.includes(r==null?void 0:r._type,"@chai/"));return{blocks:Ua(t,n)}},[e,t])},Fa=()=>{const e=se(),t=X();return k.useQuery({queryKey:[W,"uiLibraries"],initialData:[],queryFn:async()=>(await t(e,{action:"GET_LIBRARIES"})).map(r=>({...r}))})},dn=()=>{const e=es(),t=X(),{user:n}=De(),r=n==null?void 0:n.id;return k.useQuery({queryKey:[W,"permissions",r],queryFn:()=>t(e,{action:_.GET_ROLE_AND_PERMISSIONS,data:{userId:r}}),enabled:!!r})},qa=()=>{const e=se(),t=X(),{setCurrentEditor:n}=Ut(),[,r]=bs();return{getUILibraryBlock:async(l,u)=>{const d=await t(e,{action:"GET_LIBRARY_ITEM",data:{id:u.id}}),f=g.get(d,"html",""),h=g.get(d,"blocks",[]);return g.isArray(h)?h:J.getBlocksFromHTML(f)},getUILibraryBlocks:async l=>{try{return(await t(e,{action:"GET_LIBRARY_ITEMS",data:{id:l.id}})).map(d=>({...d}))}catch(u){return console.error(u),[]}},onSave:async({page:l,blocks:u})=>{try{const d=await t(e,{action:"UPDATE_PAGE",data:{id:l,blocks:u}});return d.code==="PAGE_LOCKED"?(n(d.editor===null?"EXPIRED":d.editor),!0):(r(f=>({...f,lastSaved:new Date().toISOString()})),d)}catch(d){return console.error(d),new Error("Failed to save blocks")}}}},Ha=()=>{const{data:e}=Rt(),t=se(),n=X();return{getPartialBlocks:p.useCallback(async()=>{const r={};for(const a of e??[])g.isEmpty(a==null?void 0:a.slug)&&(r[a.id]={type:a.pageType,name:g.startCase(a.name??a.slug),description:""});return r},[e]),getPartialBlockBlocks:p.useCallback(async r=>{if(!r)return[];try{const a=await n(t,{action:"GET_DRAFT_PAGE",data:{id:r,draft:!0,editor:!1}});return g.filter(a.blocks,i=>g.has(i,"_id"))}catch(a){return console.error(a),[]}},[n,t])}},Rs=Ht.z.object({email:Ht.z.string().email({message:"Please enter a valid email address"}),password:Ht.z.string().min(6,{message:"Password must be at least 6 characters"})}),Ka=()=>{const{setUser:e}=De(),t=es(),[n,r]=p.useState(""),[a,i]=p.useState(""),[o,l]=p.useState({}),[u,d]=p.useState(!1),[f,h]=p.useState(""),v=k.useMutation({mutationFn:async N=>{h("");const b=await Zs(t,{action:"LOGIN",data:N});if(!b.ok){const M=await b.json();throw new Error(M.error||"Login failed")}const A=await b.json();return e(A),A},onSuccess:()=>{l({}),h("")},onError:N=>{l({email:" ",password:" "}),h(N.message||"Something went wrong")}}),E=async N=>{N.preventDefault(),l({});const b={email:n,password:a};try{const A=Rs.parse(b);v.mutate(A)}catch(A){if(A instanceof Ht.z.ZodError){const M=A.errors.reduce((w,S)=>{const I=S.path[0];return w[I]=S.message,w},{});l(M)}}},y=Rs.safeParse({email:n,password:a}).success;return s.jsx("div",{className:"flex justify-center items-center min-h-screen bg-slate-50",children:s.jsxs(c.Card,{className:"w-full max-w-md",children:[s.jsxs(c.CardHeader,{children:[s.jsx(c.CardTitle,{className:"text-2xl",children:"Sign in"}),s.jsx(c.CardDescription,{children:"Enter your credentials to sign in to visual builder"})]}),s.jsx(c.CardContent,{children:s.jsxs("form",{onSubmit:E,className:"space-y-4",children:[s.jsxs("div",{className:"space-y-1",children:[s.jsx(c.Label,{htmlFor:"email",children:"Email"}),s.jsx(c.Input,{id:"email",placeholder:"you@example.com",type:"email",value:n,onChange:N=>r(N.target.value),className:o.email?"border-destructive":""}),o.email&&s.jsx("p",{className:"text-sm text-destructive",children:o.email})]}),s.jsxs("div",{className:"space-y-1",children:[s.jsx(c.Label,{htmlFor:"password",children:"Password"}),s.jsxs("div",{className:"relative",children:[s.jsx(c.Input,{id:"password",placeholder:"Enter your password",type:u?"text":"password",value:a,onChange:N=>i(N.target.value),className:o.password?"border-destructive":""}),s.jsx("button",{type:"button",className:"absolute right-3 top-1/2 -translate-y-1/2 text-muted-foreground",onClick:()=>d(!u),children:u?s.jsx(P.EyeOff,{className:"h-4 w-4"}):s.jsx(P.Eye,{className:"h-4 w-4"})})]}),o.password&&s.jsx("p",{className:"text-sm text-destructive",children:o.password})]}),s.jsx("div",{children:s.jsx("p",{className:"text-sm text-destructive",children:f})}),s.jsx(c.Button,{type:"submit",className:"w-full",disabled:!y||v.isPending,children:v.isPending?s.jsxs(s.Fragment,{children:[s.jsx(P.Loader2,{className:"mr-2 h-4 w-4 animate-spin"}),"Logging in..."]}):"Login"})]})}),s.jsxs(c.CardFooter,{className:"flex flex-col justify-center",children:[s.jsxs("p",{className:"text-sm text-muted-foreground",children:["Forgot your password?"," ",s.jsx("a",{target:"_blank",href:"https://chaibuilder.com/forgot-password",className:"text-primary hover:underline",children:"Reset password"})]}),s.jsx("br",{}),s.jsx("br",{}),s.jsxs("div",{className:"flex items-center border-t pt-2 px-10 gap-2",children:["Powered by"," ",s.jsxs("a",{target:"_blank",href:"https://chaibuilder.com",className:"text-primary hover:underline flex items-center gap-1",children:[s.jsx("img",{src:"https://ucarecdn.com/a82e256c-1cf2-4755-b65c-5d85e7652daa/-/preview/400x400",alt:"Chai Builder",className:"w-4 h-4 rounded uppercase font-bold"}),"Chai Builder"]})]})]})]})})};let us=Ka;const za=()=>p.useMemo(()=>us,[us]),Va=e=>{us=e},$a=()=>{const e=za();return s.jsx(p.Suspense,{fallback:s.jsx("div",{children:"Loading..."}),children:s.jsx(e,{})})},Wa=({isActive:e,show:t})=>{const{data:n}=ft();return!g.has(n,"languages")||!g.get(n,"languages",[]).length?null:s.jsx(c.Button,{size:"sm",onClick:t,variant:e?"default":"ghost",children:s.jsx(P.LanguagesIcon,{className:"w-4 h-4"})})},hn="lang",Qa={id:hn,label:"Languages",position:"top",panel:Zr,button:Wa,view:"modal",width:400};function Ge({data:e,onSelect:t,dataType:n="value",disabled:r=!1}){const[a,i]=ge.useState(!1),[o,l]=ge.useState([]),[u,d]=ge.useState(e);ge.useEffect(()=>{a||l([]),d(e)},[e,a]);const f=y=>Array.isArray(y)?"array":typeof y=="object"&&y!==null?"object":"value",h=ge.useCallback(y=>{const N=b=>n==="value"?b==="value"||b==="object":n==="array"?b==="array":b===n;y.type==="object"?(l(b=>[...b,y.key]),d(y.value)):N(y.type)&&(t([...o,y.key].join(".")),i(!1))},[o,t,n]),v=ge.useCallback(()=>{if(o.length>0){const y=o.slice(0,-1);l(y),d(y.reduce((N,b)=>N[b],e))}},[o,e]),E=ge.useMemo(()=>Object.entries(u).map(([y,N])=>({key:y,value:N,type:f(N)})).filter(y=>n==="value"?y.type==="value"||y.type==="object":n==="array"?y.type==="array"||y.type==="object":n==="object"?y.type==="object":!0),[u,n]);return s.jsxs(c.Popover,{open:a,onOpenChange:i,children:[s.jsxs(c.Tooltip,{children:[s.jsx(c.TooltipTrigger,{asChild:!0,children:s.jsx(c.PopoverTrigger,{asChild:!0,children:s.jsx(c.Button,{size:"sm",variant:"outline",className:"h-6 w-6 px-1 py-0 text-[9px] text-muted-foreground",role:"combobox","aria-expanded":a,disabled:r,children:s.jsx(P.DatabaseIcon,{className:"h-3 w-3"})})})}),s.jsx(c.TooltipContent,{children:"Add field"})]}),s.jsx(c.PopoverContent,{className:"w-[200px] z-[9999] p-0",children:s.jsxs(c.Command,{children:[s.jsx(c.CommandInput,{className:"border-none",placeholder:"Search..."}),s.jsxs(c.CommandList,{children:[s.jsx(c.CommandEmpty,{children:"No option found."}),s.jsxs(c.CommandGroup,{children:[o.length>0&&s.jsxs(c.CommandItem,{onSelect:v,className:"flex items-center text-sm",children:[s.jsx(P.ChevronLeft,{className:"w-4 h-4 mr-2"}),"Back"]}),E.map(y=>s.jsxs(c.CommandItem,{onSelect:()=>h(y),className:"flex items-center justify-between",children:[s.jsx("span",{children:y.key}),s.jsxs("div",{className:"flex items-center gap-2",children:[n==="object"&&y.type==="object"&&s.jsx(c.Button,{size:"sm",variant:"ghost",className:"h-6 px-2 hover:bg-primary hover:text-primary-foreground",onClick:N=>{N.stopPropagation(),t([...o,y.key].join(".")),i(!1)},children:"Select"}),(y.type==="object"||y.type==="array")&&s.jsx("div",{className:"p-1 rounded hover:bg-muted cursor-pointer",children:s.jsx(P.ChevronRight,{className:"w-4 h-4 opacity-50"})})]})]},y.key))]})]})]})})]})}const Ya=()=>{const{selectedLang:e}=J.useLanguages(),{data:t,isFetching:n}=mt();return{data:p.useMemo(()=>g.find(t,{lang:e||""})||{},[t,e]),isFetching:n}},Xa=(e,t)=>{const n=e.selectionStart||0,r=e.selectionEnd||0,a=e.value,i=a.substring(0,n),o=a.substring(r);let l=!1;if(n>0&&i.length>0){const y=i.charAt(i.length-1);l=!/[\s.,!?;:()[\]{}]/.test(y)&&y!==""}let u=!1;if(o.length>0){const y=o.charAt(0);u=!/[\s.,!?;:()[\]{}]/.test(y)&&y!==""}const d=l?" ":"",f=u?" ":"",h=`{{${t}}}`,v=i+(l?d:"")+h+(u?f:"")+o,E=n+(l?1:0)+h.length;return{value:v,newCursorPos:E}},mn=()=>{const{t:e}=J.useTranslation(),{selectedLang:t,fallbackLang:n,languages:r}=J.useLanguages(),[,a]=J.useSidebarActivePanel(),{data:i}=Ae(),{data:o}=rn({lang:t||n,pageType:i==null?void 0:i.pageType}),{data:l,isFetching:u}=Ya(),d=l==null?void 0:l.seo,f=p.useRef(null),[h,v]=p.useState({title:"",description:"",cononicalUrl:"",noIndex:!1,noFollow:"",ogTitle:"",ogDescription:"",ogImage:"",searchTitle:"",searchDescription:"",jsonLD:"",...d}),E=p.useRef({initial:h,updated:h}),y=t.length?t:n,{mutate:N,isPending:b}=js(),A=b,{hasPermission:M}=J.usePermissions(),w=M(he.EDIT_SEO);p.useEffect(()=>{!u&&d&&v({title:"",description:"",cononicalUrl:"",noIndex:!1,noFollow:"",ogTitle:"",ogDescription:"",ogImage:"",searchTitle:"",searchDescription:"",jsonLD:"",...d})},[u,d]);const S=async()=>{N({id:l==null?void 0:l.id,seo:h},{onSuccess:()=>{E.current.initial=h,E.current.updated=h,a("outline")}})},I=()=>{v({...h,ogTitle:h.title,ogDescription:h.description})},D=()=>{v({...h,searchTitle:h.ogTitle,searchDescription:h.ogDescription})},le=(B,U)=>{const C=document.getElementById(U);if(C){const{value:F,newCursorPos:re}=Xa(C,B);f.current={id:U,position:re},C.tagName.toLowerCase()==="input"?(C.value=F,v(fe=>({...fe,[C.name]:F})),C.focus(),C.setSelectionRange(re,re),[0,10,50,100,200].forEach(fe=>{setTimeout(()=>{const V=document.getElementById(U);V&&(V.focus(),V.setSelectionRange(re,re))},fe)})):(v(ee=>({...ee,[C.name]:F})),requestAnimationFrame(()=>{const ee=document.getElementById(U);ee&&(ee.focus(),ee.setSelectionRange(re,re),setTimeout(()=>{const fe=document.getElementById(U);fe&&(fe.focus(),fe.setSelectionRange(re,re))},50))}))}},ne=B=>{const U={...h,[B.target.name]:B.target.name==="noIndex"||B.target.name==="noFollow"?B.target.checked:B.target.value};v(U),E.current.updated=U};return s.jsxs("div",{className:"relative h-full flex flex-col",children:[!w&&s.jsx("div",{className:"absolute inset-0 z-10 backdrop-blur-sm flex items-center justify-center",children:s.jsx(c.Alert,{variant:"default",className:"w-[80%] max-w-md text-xs",children:s.jsx(c.AlertDescription,{children:e("You don't have permission to edit SEO settings. Contact your administrator for access.")})})}),s.jsxs("div",{className:"flex-grow overflow-y-auto no-scrollbar px-2",children:[s.jsxs("div",{className:"p-2 text-xs text-left bg-gray-100 rounded-md mb-4",children:[e("Slug"),": ",l==null?void 0:l.slug," ",r.length>0&&s.jsxs("span",{className:"font-semibold text-blue-500",children:["(",g.get(_e,y,y),")"]})]}),s.jsx("form",{className:"space-y-8",children:s.jsxs(c.Accordion,{type:"multiple",defaultValue:["page"],children:[s.jsxs(c.AccordionItem,{value:"page",children:[s.jsx(c.AccordionTrigger,{className:"font-semibold text-slate-700",children:e("SEO")}),s.jsx(c.AccordionContent,{className:"pt-2",children:s.jsxs("div",{className:"space-y-4",children:[s.jsxs("div",{className:"space-y-1",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx(c.Label,{className:"text-xs",htmlFor:"title",children:e("SEO Title")}),w&&s.jsx(Ge,{dataType:"value",data:o??{},onSelect:B=>le(B,"title")})]}),s.jsx(c.Input,{type:"text",id:"title",name:"title",value:h.title,onChange:ne,disabled:A||!w,placeholder:e("Enter SEO title"),readOnly:!w})]}),s.jsxs("div",{className:"space-y-1",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx(c.Label,{className:"text-xs",htmlFor:"description",children:e("SEO Description")}),w&&s.jsx(Ge,{data:o??{},onSelect:B=>le(B,"description")})]}),s.jsx(c.Textarea,{id:"description",name:"description",rows:5,value:h.description,onChange:ne,disabled:A||!w,placeholder:e("Enter SEO description"),readOnly:!w})]}),s.jsxs("div",{className:"space-y-1",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx(c.Label,{className:"text-xs",htmlFor:"title",children:e("Canonical URL")}),w&&s.jsx(Ge,{dataType:"value",data:o??{},onSelect:B=>le(B,"canonicalUrl")})]}),s.jsx(c.Input,{type:"text",id:"canonicalUrl",name:"canonicalUrl",value:h.canonicalUrl,onChange:ne,disabled:A||!w,placeholder:e("Enter Canonical URL"),readOnly:!w})]}),s.jsxs("div",{className:"",children:[s.jsxs("div",{className:"flex items-center gap-x-2",children:[s.jsx(c.Input,{type:"checkbox",id:"noIndex",name:"noIndex",checked:h.noIndex,onChange:ne,disabled:A||!w,className:"w-4 h-4"}),s.jsx(c.Label,{className:"pb-1 text-xs",htmlFor:"noIndex",children:e("No Index")})]}),s.jsx("p",{className:"mt-0 text-[10px] font-light text-gray-400 leading-4",children:e("Check this if you don't want search engines to index this page.")})]}),s.jsxs("div",{className:"",children:[s.jsxs("div",{className:"flex items-center gap-x-2",children:[s.jsx(c.Input,{type:"checkbox",id:"noFollow",name:"noFollow",checked:h.noFollow,onChange:ne,disabled:A||!w,className:"w-4 h-4"}),s.jsx(c.Label,{className:"pb-1 text-xs",htmlFor:"noIndex",children:e("No Follow")})]}),s.jsx("p",{className:"text-[10px] font-light text-gray-400 leading-4",children:e("Check this if you don't want search engines to follow links on this page.")})]})]})})]}),s.jsxs(c.AccordionItem,{value:"og",children:[s.jsx(c.AccordionTrigger,{className:"font-bold text-slate-700",children:e("Open Graph")}),s.jsx(c.AccordionContent,{children:s.jsxs("div",{className:"space-y-4",children:[s.jsx("div",{className:"flex items-center justify-between",children:s.jsx(c.Button,{type:"button",variant:"outline",size:"sm",onClick:I,disabled:!w,children:e("Copy from SEO Settings")})}),s.jsxs("div",{className:"space-y-1",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx(c.Label,{className:"text-xs",htmlFor:"ogTitle",children:e("OG Title")}),w&&s.jsx(Ge,{dataType:"value",data:o??{},onSelect:B=>le(B,"ogTitle")})]}),s.jsx(c.Input,{type:"text",id:"ogTitle",name:"ogTitle",value:h.ogTitle,onChange:ne,disabled:A||!w,placeholder:e("Enter OG title"),readOnly:!w})]}),s.jsxs("div",{className:"space-y-1",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx(c.Label,{className:"text-xs",htmlFor:"ogDescription",children:e("OG Description")}),w&&s.jsx(Ge,{dataType:"value",data:o??{},onSelect:B=>le(B,"ogDescription")})]}),s.jsx(c.Textarea,{id:"ogDescription",name:"ogDescription",rows:5,value:h.ogDescription,onChange:ne,disabled:A||!w,placeholder:e("Enter OG description"),readOnly:!w})]}),s.jsxs("div",{className:"space-y-1",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx(c.Label,{className:"text-xs",htmlFor:"ogImage",children:e("OG Image URL")}),w&&s.jsx(Ge,{dataType:"value",data:o??{},onSelect:B=>le(B,"ogImage")})]}),s.jsx(c.Input,{type:"text",id:"ogImage",name:"ogImage",value:h.ogImage,onChange:ne,disabled:A||!w,placeholder:e("Enter OG image URL"),readOnly:!w})]})]})})]}),s.jsxs(c.AccordionItem,{value:"search",children:[s.jsx(c.AccordionTrigger,{className:"font-bold text-slate-700",children:e("Search")}),s.jsx(c.AccordionContent,{children:s.jsxs("div",{className:"space-y-4",children:[s.jsx("div",{className:"flex items-center justify-between",children:s.jsx(c.Button,{type:"button",variant:"outline",size:"sm",onClick:D,disabled:!w,children:e("Copy from OG Settings")})}),s.jsxs("div",{className:"space-y-1",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx(c.Label,{className:"text-xs",htmlFor:"searchTitle",children:e("Search Title")}),w&&s.jsx(Ge,{dataType:"value",data:o??{},onSelect:B=>le(B,"searchTitle")})]}),s.jsx(c.Input,{type:"text",id:"searchTitle",name:"searchTitle",value:h.searchTitle,onChange:ne,disabled:A||!w,placeholder:e("Enter search title"),readOnly:!w})]}),s.jsxs("div",{className:"space-y-1",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx(c.Label,{className:"text-xs",htmlFor:"searchDescription",children:e("Search Description")}),w&&s.jsx(Ge,{dataType:"value",data:o??{},onSelect:B=>le(B,"searchDescription")})]}),s.jsx(c.Textarea,{id:"searchDescription",rows:5,name:"searchDescription",value:h.searchDescription,onChange:ne,placeholder:e("Enter search description"),disabled:A||!w,readOnly:!w})]})]})})]}),s.jsxs(c.AccordionItem,{value:"jsonLD",className:"border-none",children:[s.jsx(c.AccordionTrigger,{className:"font-bold text-slate-700",children:e("JSON-LD")}),s.jsx(c.AccordionContent,{children:s.jsx("div",{className:"space-y-4",children:s.jsxs("div",{className:"space-y-1",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx(c.Label,{className:"text-xs",htmlFor:"jsonLD",children:e("JSON-LD")}),w&&s.jsx(Ge,{dataType:"value",data:o??{},onSelect:B=>le(B,"jsonLD")})]}),s.jsx(c.Textarea,{id:"jsonLD",name:"jsonLD",rows:6,value:h.jsonLD,onChange:ne,placeholder:e("Enter JSON-LD"),disabled:A||!w,readOnly:!w})]})})})]})]})})]}),w&&s.jsx("div",{className:"flex-shrink-0 flex items-center justify-end w-full p-4 bg-background border-t",children:s.jsx(c.Button,{size:"lg",variant:"default",onClick:S,disabled:g.isEqual(E.current.initial,h)||A||!w,children:e(b?"Saving...":"Save")})})]})};mn.displayName="SeoPanel";const fn="seo",Za=({isActive:e,show:t})=>{const{data:n}=Ae(),r=Or(n==null?void 0:n.pageType);return!g.has(r,"hasSlug")||!r.hasSlug?null:s.jsx(c.Button,{size:"sm",className:"my-1",onClick:t,variant:e?"default":"ghost",children:s.jsxs("svg",{className:"w-4 h-4",xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 21 21",fill:"currentColor",children:[s.jsx("path",{d:"M9.931 6.818c-1.238 0-2.136.925-2.136 2.2 0 1.279.898 2.207 2.136 2.207.664 0 1.257-.246 1.67-.694a.15.15 0 0 0-.009-.213l-.311-.286a.15.15 0 0 0-.213.009c-.273.297-.677.46-1.137.46-.699 0-1.233-.444-1.375-1.12h3.295a.15.15 0 0 0 .151-.151v-.211c0-1.295-.852-2.2-2.072-2.2m0 .724c.697 0 1.188.422 1.315 1.113h-2.69c.142-.673.676-1.113 1.374-1.113m4.332-.724c-1.246 0-2.15.925-2.15 2.2 0 1.279.904 2.207 2.15 2.207.596 0 1.143-.223 1.538-.628s.612-.965.612-1.579c0-1.275-.904-2.2-2.15-2.2m0 3.683c-.826 0-1.426-.624-1.426-1.483 0-.855.6-1.475 1.426-1.475s1.426.621 1.426 1.476c0 .423-.144.804-.406 1.073-.258.264-.62.41-1.019.41M6.318 8.71c-.665-.206-.902-.335-.902-.645 0-.47.564-.521.806-.521.29 0 .552.07.801.215a.15.15 0 0 0 .206-.055l.212-.366a.15.15 0 0 0-.055-.206 2.27 2.27 0 0 0-1.165-.312c-.915 0-1.53.501-1.53 1.245 0 .899.816 1.152 1.411 1.336.655.203.812.307.804.53-.016.398-.567.429-.735.429-.386 0-.722-.129-.972-.374q-.043-.042-.107-.043a.15.15 0 0 0-.106.045l-.295.302a.15.15 0 0 0 .002.213c.383.374.908.58 1.478.58.859 0 1.432-.441 1.459-1.125.031-.833-.746-1.074-1.313-1.249"}),s.jsx("path",{d:"M20.396 2.049H.604A.604.604 0 0 0 0 2.653v12.7c0 .333.27.604.604.604h6.941c-.266 1.296-.881 1.966-.886 1.971a.604.604 0 0 0 .434 1.024h6.815a.604.604 0 0 0 .434-1.024c-.007-.007-.621-.675-.886-1.971h6.941c.333 0 .604-.27.604-.604V2.652a.604.604 0 0 0-.604-.604m-.604 12.701h-.985v-.17a.604.604 0 0 0-1.208 0v.17h-.63v-.17a.604.604 0 0 0-1.208 0v.17H1.207V3.256h18.585z"})]})})},Ja={id:fn,label:"SEO",panel:mn,button:Za,position:"top",view:"modal",width:600},ei=()=>{J.registerChaiSidebarPanel(fn,Ja),J.registerChaiSidebarPanel(hn,Qa)},ti="user-info",si=()=>{const{user:e,logout:t}=De(),n=Re("onLogout",g.noop);return e?s.jsxs(c.HoverCard,{children:[s.jsx(c.HoverCardTrigger,{asChild:!0,children:s.jsx(c.Button,{variant:"ghost",className:"text-sm font-medium",children:s.jsx(P.User,{className:"w-4 h-4"})})}),s.jsxs(c.HoverCardContent,{className:"w-auto p-4 space-y-2",children:[s.jsx("div",{className:"text-sm font-medium",children:e.name??e.email}),s.jsx("div",{className:"text-xs text-muted-foreground",children:e.email}),s.jsxs(c.AlertDialog,{children:[s.jsx(c.AlertDialogTrigger,{asChild:!0,children:s.jsx(c.Button,{variant:"outline",size:"sm",className:"w-full",children:"Logout"})}),s.jsxs(c.AlertDialogContent,{children:[s.jsxs(c.AlertDialogHeader,{children:[s.jsx(c.AlertDialogTitle,{children:"Are you sure you want to logout?"}),s.jsx(c.AlertDialogDescription,{children:"You will be redirected to the login page."})]}),s.jsxs(c.AlertDialogFooter,{children:[s.jsx(c.AlertDialogCancel,{children:"Cancel"}),s.jsx(c.AlertDialogAction,{onClick:()=>{t(),g.isFunction(n)&&n()},children:"Logout"})]})]})]})]})]}):null},ni={id:ti,label:"User Info",button:si,position:"bottom"};var q={context:void 0,registry:void 0,effects:void 0,done:!1,getContextId(){return Us(this.context.count)},getNextContextId(){return Us(this.context.count++)}};function Us(e){const t=String(e),n=t.length-1;return q.context.id+(n?String.fromCharCode(96+n):"")+t}function xt(e){q.context=e}var ri=(e,t)=>e===t,Vt=Symbol("solid-proxy"),gn=typeof Proxy=="function",As=Symbol("solid-track"),$t={equals:ri},pn=Sn,Ue=1,Wt=2,xn={owned:null,cleanups:null,context:null,owner:null},is={},ie=null,os=null,ai=null,ue=null,je=null,Me=null,ts=0;function Oe(e,t){const n=ue,r=ie,a=e.length===0,i=t===void 0?r:t,o=a?xn:{owned:null,cleanups:null,context:i?i.context:null,owner:i},l=a?e:()=>e(()=>be(()=>jt(o)));ie=o,ue=null;try{return Le(l,!0)}finally{ue=n,ie=r}}function ve(e,t){t=t?Object.assign({},$t,t):$t;const n={value:e,observers:null,observerSlots:null,comparator:t.equals||void 0},r=a=>(typeof a=="function"&&(a=a(n.value)),jn(n,a));return[bn.bind(n),r]}function yn(e,t,n){const r=ss(e,t,!0,Ue);pt(r)}function Fe(e,t,n){const r=ss(e,t,!1,Ue);pt(r)}function Ts(e,t,n){pn=vi;const r=ss(e,t,!1,Ue);(!n||!n.render)&&(r.user=!0),Me?Me.push(r):pt(r)}function we(e,t,n){n=n?Object.assign({},$t,n):$t;const r=ss(e,t,!0,0);return r.observers=null,r.observerSlots=null,r.comparator=n.equals||void 0,pt(r),bn.bind(r)}function ii(e){return e&&typeof e=="object"&&"then"in e}function oi(e,t,n){let r,a,i;arguments.length===1?(r=!0,a=e,i={}):(r=e,a=t,i={});let o=null,l=is,u=null,d=!1,f="initialValue"in i,h=typeof r=="function"&&we(r);const v=new Set,[E,y]=(i.storage||ve)(i.initialValue),[N,b]=ve(void 0),[A,M]=ve(void 0,{equals:!1}),[w,S]=ve(f?"ready":"unresolved");q.context&&(u=q.getNextContextId(),i.ssrLoadFrom==="initial"?l=i.initialValue:q.load&&q.has(u)&&(l=q.load(u)));function I(B,U,C,F){return o===B&&(o=null,F!==void 0&&(f=!0),(B===l||U===l)&&i.onHydrated&&queueMicrotask(()=>i.onHydrated(F,{value:U})),l=is,D(U,C)),U}function D(B,U){Le(()=>{U===void 0&&y(()=>B),S(U!==void 0?"errored":f?"ready":"unresolved"),b(U);for(const C of v.keys())C.decrement();v.clear()},!1)}function le(){const B=pi,U=E(),C=N();if(C!==void 0&&!o)throw C;return ue&&ue.user,U}function ne(B=!0){if(B!==!1&&d)return;d=!1;const U=h?h():r;if(U==null||U===!1){I(o,be(E));return}const C=l!==is?l:be(()=>a(U,{value:E(),refetching:B}));return ii(C)?(o=C,"value"in C?(C.status==="success"?I(o,C.value,void 0,U):I(o,void 0,ds(C.value),U),C):(d=!0,queueMicrotask(()=>d=!1),Le(()=>{S(f?"refreshing":"pending"),M()},!1),C.then(F=>I(C,F,void 0,U),F=>I(C,void 0,ds(F),U)))):(I(o,C,void 0,U),C)}return Object.defineProperties(le,{state:{get:()=>w()},error:{get:()=>N()},loading:{get(){const B=w();return B==="pending"||B==="refreshing"}},latest:{get(){if(!f)return le();const B=N();if(B&&!o)throw B;return E()}}}),h?yn(()=>ne(!1)):ne(!1),[le,{refetch:ne,mutate:y}]}function li(e){return Le(e,!1)}function be(e){if(ue===null)return e();const t=ue;ue=null;try{return e()}finally{ue=t}}function ci(e,t,n){const r=Array.isArray(e);let a,i=n&&n.defer;return o=>{let l;if(r){l=Array(e.length);for(let d=0;d<e.length;d++)l[d]=e[d]()}else l=e();if(i)return i=!1,o;const u=be(()=>t(l,a,o));return a=l,u}}function vn(e){Ts(()=>be(e))}function dt(e){return ie===null||(ie.cleanups===null?ie.cleanups=[e]:ie.cleanups.push(e)),e}function Os(){return ie}function ui(e,t){const n=ie,r=ue;ie=e,ue=null;try{return Le(t,!0)}catch(a){Cs(a)}finally{ie=n,ue=r}}function di(e){const t=ue,n=ie;return Promise.resolve().then(()=>{ue=t,ie=n;let r;return Le(e,!1),ue=ie=null,r?r.done:void 0})}var[hi,tl]=ve(!1);function mi(){return[hi,di]}function fi(e,t){const n=Symbol("context");return{id:n,Provider:Ei(n),defaultValue:e}}function gi(e){let t;return ie&&ie.context&&(t=ie.context[e.id])!==void 0?t:e.defaultValue}function En(e){const t=we(e),n=we(()=>hs(t()));return n.toArray=()=>{const r=n();return Array.isArray(r)?r:r!=null?[r]:[]},n}var pi;function bn(){if(this.sources&&this.state)if(this.state===Ue)pt(this);else{const e=je;je=null,Le(()=>Yt(this),!1),je=e}if(ue){const e=this.observers?this.observers.length:0;ue.sources?(ue.sources.push(this),ue.sourceSlots.push(e)):(ue.sources=[this],ue.sourceSlots=[e]),this.observers?(this.observers.push(ue),this.observerSlots.push(ue.sources.length-1)):(this.observers=[ue],this.observerSlots=[ue.sources.length-1])}return this.value}function jn(e,t,n){let r=e.value;return(!e.comparator||!e.comparator(r,t))&&(e.value=t,e.observers&&e.observers.length&&Le(()=>{for(let a=0;a<e.observers.length;a+=1){const i=e.observers[a],o=os&&os.running;o&&os.disposed.has(i),(o?!i.tState:!i.state)&&(i.pure?je.push(i):Me.push(i),i.observers&&wn(i)),o||(i.state=Ue)}if(je.length>1e6)throw je=[],new Error},!1)),t}function pt(e){if(!e.fn)return;jt(e);const t=ts;xi(e,e.value,t)}function xi(e,t,n){let r;const a=ie,i=ue;ue=ie=e;try{r=e.fn(t)}catch(o){return e.pure&&(e.state=Ue,e.owned&&e.owned.forEach(jt),e.owned=null),e.updatedAt=n+1,Cs(o)}finally{ue=i,ie=a}(!e.updatedAt||e.updatedAt<=n)&&(e.updatedAt!=null&&"observers"in e?jn(e,r):e.value=r,e.updatedAt=n)}function ss(e,t,n,r=Ue,a){const i={fn:e,state:r,updatedAt:null,owned:null,sources:null,sourceSlots:null,cleanups:null,value:t,owner:ie,context:ie?ie.context:null,pure:n};return ie===null||ie!==xn&&(ie.owned?ie.owned.push(i):ie.owned=[i]),i}function Qt(e){if(e.state===0)return;if(e.state===Wt)return Yt(e);if(e.suspense&&be(e.suspense.inFallback))return e.suspense.effects.push(e);const t=[e];for(;(e=e.owner)&&(!e.updatedAt||e.updatedAt<ts);)e.state&&t.push(e);for(let n=t.length-1;n>=0;n--)if(e=t[n],e.state===Ue)pt(e);else if(e.state===Wt){const r=je;je=null,Le(()=>Yt(e,t[0]),!1),je=r}}function Le(e,t){if(je)return e();let n=!1;t||(je=[]),Me?n=!0:Me=[],ts++;try{const r=e();return yi(n),r}catch(r){n||(Me=null),je=null,Cs(r)}}function yi(e){if(je&&(Sn(je),je=null),e)return;const t=Me;Me=null,t.length&&Le(()=>pn(t),!1)}function Sn(e){for(let t=0;t<e.length;t++)Qt(e[t])}function vi(e){let t,n=0;for(t=0;t<e.length;t++){const r=e[t];r.user?e[n++]=r:Qt(r)}if(q.context){if(q.count){q.effects||(q.effects=[]),q.effects.push(...e.slice(0,n));return}xt()}for(q.effects&&(q.done||!q.count)&&(e=[...q.effects,...e],n+=q.effects.length,delete q.effects),t=0;t<n;t++)Qt(e[t])}function Yt(e,t){e.state=0;for(let n=0;n<e.sources.length;n+=1){const r=e.sources[n];if(r.sources){const a=r.state;a===Ue?r!==t&&(!r.updatedAt||r.updatedAt<ts)&&Qt(r):a===Wt&&Yt(r,t)}}}function wn(e){for(let t=0;t<e.observers.length;t+=1){const n=e.observers[t];n.state||(n.state=Wt,n.pure?je.push(n):Me.push(n),n.observers&&wn(n))}}function jt(e){let t;if(e.sources)for(;e.sources.length;){const n=e.sources.pop(),r=e.sourceSlots.pop(),a=n.observers;if(a&&a.length){const i=a.pop(),o=n.observerSlots.pop();r<a.length&&(i.sourceSlots[o]=r,a[r]=i,n.observerSlots[r]=o)}}if(e.tOwned){for(t=e.tOwned.length-1;t>=0;t--)jt(e.tOwned[t]);delete e.tOwned}if(e.owned){for(t=e.owned.length-1;t>=0;t--)jt(e.owned[t]);e.owned=null}if(e.cleanups){for(t=e.cleanups.length-1;t>=0;t--)e.cleanups[t]();e.cleanups=null}e.state=0}function ds(e){return e instanceof Error?e:new Error(typeof e=="string"?e:"Unknown error",{cause:e})}function Cs(e,t=ie){throw ds(e)}function hs(e){if(typeof e=="function"&&!e.length)return hs(e());if(Array.isArray(e)){const t=[];for(let n=0;n<e.length;n++){const r=hs(e[n]);Array.isArray(r)?t.push.apply(t,r):t.push(r)}return t}return e}function Ei(e,t){return function(r){let a;return Fe(()=>a=be(()=>(ie.context={...ie.context,[e]:r.value},En(()=>r.children))),void 0),a}}var ms=Symbol("fallback");function Xt(e){for(let t=0;t<e.length;t++)e[t]()}function bi(e,t,n={}){let r=[],a=[],i=[],o=0,l=t.length>1?[]:null;return dt(()=>Xt(i)),()=>{let u=e()||[],d=u.length,f,h;return u[As],be(()=>{let E,y,N,b,A,M,w,S,I;if(d===0)o!==0&&(Xt(i),i=[],r=[],a=[],o=0,l&&(l=[])),n.fallback&&(r=[ms],a[0]=Oe(D=>(i[0]=D,n.fallback())),o=1);else if(o===0){for(a=new Array(d),h=0;h<d;h++)r[h]=u[h],a[h]=Oe(v);o=d}else{for(N=new Array(d),b=new Array(d),l&&(A=new Array(d)),M=0,w=Math.min(o,d);M<w&&r[M]===u[M];M++);for(w=o-1,S=d-1;w>=M&&S>=M&&r[w]===u[S];w--,S--)N[S]=a[w],b[S]=i[w],l&&(A[S]=l[w]);for(E=new Map,y=new Array(S+1),h=S;h>=M;h--)I=u[h],f=E.get(I),y[h]=f===void 0?-1:f,E.set(I,h);for(f=M;f<=w;f++)I=r[f],h=E.get(I),h!==void 0&&h!==-1?(N[h]=a[f],b[h]=i[f],l&&(A[h]=l[f]),h=y[h],E.set(I,h)):i[f]();for(h=M;h<d;h++)h in N?(a[h]=N[h],i[h]=b[h],l&&(l[h]=A[h],l[h](h))):a[h]=Oe(v);a=a.slice(0,o=d),r=u.slice(0)}return a});function v(E){if(i[h]=E,l){const[y,N]=ve(h);return l[h]=N,t(u[h],y)}return t(u[h])}}}function ji(e,t,n={}){let r=[],a=[],i=[],o=[],l=0,u;return dt(()=>Xt(i)),()=>{const d=e()||[],f=d.length;return d[As],be(()=>{if(f===0)return l!==0&&(Xt(i),i=[],r=[],a=[],l=0,o=[]),n.fallback&&(r=[ms],a[0]=Oe(v=>(i[0]=v,n.fallback())),l=1),a;for(r[0]===ms&&(i[0](),i=[],r=[],a=[],l=0),u=0;u<f;u++)u<r.length&&r[u]!==d[u]?o[u](()=>d[u]):u>=r.length&&(a[u]=Oe(h));for(;u<r.length;u++)i[u]();return l=o.length=i.length=f,r=d.slice(0),a=a.slice(0,l)});function h(v){i[u]=v;const[E,y]=ve(d[u]);return o[u]=y,t(E,u)}}}function Ps(e,t){return be(()=>e(t||{}))}function Ot(){return!0}var fs={get(e,t,n){return t===Vt?n:e.get(t)},has(e,t){return t===Vt?!0:e.has(t)},set:Ot,deleteProperty:Ot,getOwnPropertyDescriptor(e,t){return{configurable:!0,enumerable:!0,get(){return e.get(t)},set:Ot,deleteProperty:Ot}},ownKeys(e){return e.keys()}};function ls(e){return(e=typeof e=="function"?e():e)?e:{}}function Si(){for(let e=0,t=this.length;e<t;++e){const n=this[e]();if(n!==void 0)return n}}function _s(...e){let t=!1;for(let o=0;o<e.length;o++){const l=e[o];t=t||!!l&&Vt in l,e[o]=typeof l=="function"?(t=!0,we(l)):l}if(gn&&t)return new Proxy({get(o){for(let l=e.length-1;l>=0;l--){const u=ls(e[l])[o];if(u!==void 0)return u}},has(o){for(let l=e.length-1;l>=0;l--)if(o in ls(e[l]))return!0;return!1},keys(){const o=[];for(let l=0;l<e.length;l++)o.push(...Object.keys(ls(e[l])));return[...new Set(o)]}},fs);const n={},r=Object.create(null);for(let o=e.length-1;o>=0;o--){const l=e[o];if(!l)continue;const u=Object.getOwnPropertyNames(l);for(let d=u.length-1;d>=0;d--){const f=u[d];if(f==="__proto__"||f==="constructor")continue;const h=Object.getOwnPropertyDescriptor(l,f);if(!r[f])r[f]=h.get?{enumerable:!0,configurable:!0,get:Si.bind(n[f]=[h.get.bind(l)])}:h.value!==void 0?h:void 0;else{const v=n[f];v&&(h.get?v.push(h.get.bind(l)):h.value!==void 0&&v.push(()=>h.value))}}}const a={},i=Object.keys(r);for(let o=i.length-1;o>=0;o--){const l=i[o],u=r[l];u&&u.get?Object.defineProperty(a,l,u):a[l]=u?u.value:void 0}return a}function Nn(e,...t){if(gn&&Vt in e){const a=new Set(t.length>1?t.flat():t[0]),i=t.map(o=>new Proxy({get(l){return o.includes(l)?e[l]:void 0},has(l){return o.includes(l)&&l in e},keys(){return o.filter(l=>l in e)}},fs));return i.push(new Proxy({get(o){return a.has(o)?void 0:e[o]},has(o){return a.has(o)?!1:o in e},keys(){return Object.keys(e).filter(o=>!a.has(o))}},fs)),i}const n={},r=t.map(()=>({}));for(const a of Object.getOwnPropertyNames(e)){const i=Object.getOwnPropertyDescriptor(e,a),o=!i.get&&!i.set&&i.enumerable&&i.writable&&i.configurable;let l=!1,u=0;for(const d of t)d.includes(a)&&(l=!0,o?r[u][a]=i.value:Object.defineProperty(r[u],a,i)),++u;l||(o?n[a]=i.value:Object.defineProperty(n,a,i))}return[...r,n]}function An(e){let t,n;const r=a=>{const i=q.context;if(i){const[l,u]=ve();q.count||(q.count=0),q.count++,(n||(n=e())).then(d=>{!q.done&&xt(i),q.count--,u(()=>d.default),xt()}),t=l}else if(!t){const[l]=oi(()=>(n||(n=e())).then(u=>u.default));t=l}let o;return we(()=>(o=t())?be(()=>{if(!i||q.done)return o(a);const l=q.context;xt(i);const u=o(a);return xt(l),u}):"")};return r.preload=()=>n||((n=e()).then(a=>t=()=>a.default),n),r}var wi=0;function Ni(){return q.context?q.getNextContextId():`cl-${wi++}`}var Tn=e=>`Stale read from <${e}>.`;function Ai(e){const t="fallback"in e&&{fallback:()=>e.fallback};return we(bi(()=>e.each,e.children,t||void 0))}function Ti(e){const t="fallback"in e&&{fallback:()=>e.fallback};return we(ji(()=>e.each,e.children,t||void 0))}function Ci(e){const t=e.keyed,n=we(()=>e.when,void 0,{equals:(r,a)=>t?r===a:!r==!a});return we(()=>{const r=n();if(r){const a=e.children;return typeof a=="function"&&a.length>0?be(()=>a(t?r:()=>{if(!be(n))throw Tn("Show");return e.when})):a}return e.fallback},void 0,void 0)}function Pi(e){let t=!1;const n=(i,o)=>(t?i[1]===o[1]:!i[1]==!o[1])&&i[2]===o[2],r=En(()=>e.children),a=we(()=>{let i=r();Array.isArray(i)||(i=[i]);for(let o=0;o<i.length;o++){const l=i[o].when;if(l)return t=!!i[o].keyed,[o,l,i[o]]}return[-1]},void 0,{equals:n});return we(()=>{const[i,o,l]=a();if(i<0)return e.fallback;const u=l.children;return typeof u=="function"&&u.length>0?be(()=>u(t?o:()=>{if(be(a)[0]!==i)throw Tn("Match");return l.when})):u},void 0,void 0)}function _i(e){return e}var Ii=["allowfullscreen","async","autofocus","autoplay","checked","controls","default","disabled","formnovalidate","hidden","indeterminate","inert","ismap","loop","multiple","muted","nomodule","novalidate","open","playsinline","readonly","required","reversed","seamless","selected"],ki=new Set(["className","value","readOnly","formNoValidate","isMap","noModule","playsInline",...Ii]),Li=new Set(["innerHTML","textContent","innerText","children"]),Di=Object.assign(Object.create(null),{className:"class",htmlFor:"for"}),Bi=Object.assign(Object.create(null),{class:"className",formnovalidate:{$:"formNoValidate",BUTTON:1,INPUT:1},ismap:{$:"isMap",IMG:1},nomodule:{$:"noModule",SCRIPT:1},playsinline:{$:"playsInline",VIDEO:1},readonly:{$:"readOnly",INPUT:1,TEXTAREA:1}});function Gi(e,t){const n=Bi[e];return typeof n=="object"?n[t]?n.$:void 0:n}var Mi=new Set(["beforeinput","click","dblclick","contextmenu","focusin","focusout","input","keydown","keyup","mousedown","mousemove","mouseout","mouseover","mouseup","pointerdown","pointermove","pointerout","pointerover","pointerup","touchend","touchmove","touchstart"]),Ri=new Set(["altGlyph","altGlyphDef","altGlyphItem","animate","animateColor","animateMotion","animateTransform","circle","clipPath","color-profile","cursor","defs","desc","ellipse","feBlend","feColorMatrix","feComponentTransfer","feComposite","feConvolveMatrix","feDiffuseLighting","feDisplacementMap","feDistantLight","feDropShadow","feFlood","feFuncA","feFuncB","feFuncG","feFuncR","feGaussianBlur","feImage","feMerge","feMergeNode","feMorphology","feOffset","fePointLight","feSpecularLighting","feSpotLight","feTile","feTurbulence","filter","font","font-face","font-face-format","font-face-name","font-face-src","font-face-uri","foreignObject","g","glyph","glyphRef","hkern","image","line","linearGradient","marker","mask","metadata","missing-glyph","mpath","path","pattern","polygon","polyline","radialGradient","rect","set","stop","svg","switch","symbol","text","textPath","tref","tspan","use","view","vkern"]),Ui={xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace"};function Oi(e,t,n){let r=n.length,a=t.length,i=r,o=0,l=0,u=t[a-1].nextSibling,d=null;for(;o<a||l<i;){if(t[o]===n[l]){o++,l++;continue}for(;t[a-1]===n[i-1];)a--,i--;if(a===o){const f=i<r?l?n[l-1].nextSibling:n[i-l]:u;for(;l<i;)e.insertBefore(n[l++],f)}else if(i===l)for(;o<a;)(!d||!d.has(t[o]))&&t[o].remove(),o++;else if(t[o]===n[i-1]&&n[l]===t[a-1]){const f=t[--a].nextSibling;e.insertBefore(n[l++],t[o++].nextSibling),e.insertBefore(n[--i],f),t[a]=n[i]}else{if(!d){d=new Map;let h=l;for(;h<i;)d.set(n[h],h++)}const f=d.get(t[o]);if(f!=null)if(l<f&&f<i){let h=o,v=1,E;for(;++h<a&&h<i&&!((E=d.get(t[h]))==null||E!==f+v);)v++;if(v>f-l){const y=t[o];for(;l<f;)e.insertBefore(n[l++],y)}else e.replaceChild(n[l++],t[o++])}else o++;else t[o++].remove()}}}var Et="_$DX_DELEGATE";function Cn(e,t,n,r={}){let a;return Oe(i=>{a=i,t===document?e():Jt(t,e(),t.firstChild?null:void 0,n)},r.owner),()=>{a(),t.textContent=""}}function Fi(e,t,n){let r;const a=()=>{const o=document.createElement("template");return o.innerHTML=e,o.content.firstChild},i=()=>(r||(r=a())).cloneNode(!0);return i.cloneNode=i,i}function Pn(e,t=window.document){const n=t[Et]||(t[Et]=new Set);for(let r=0,a=e.length;r<a;r++){const i=e[r];n.has(i)||(n.add(i),t.addEventListener(i,Dn))}}function qi(e=window.document){if(e[Et]){for(let t of e[Et].keys())e.removeEventListener(t,Dn);delete e[Et]}}function Zt(e,t,n){$e(e)||(n==null?e.removeAttribute(t):e.setAttribute(t,n))}function Hi(e,t,n,r){$e(e)||(r==null?e.removeAttributeNS(t,n):e.setAttributeNS(t,n,r))}function Ki(e,t,n){$e(e)||(n?e.setAttribute(t,""):e.removeAttribute(t))}function _n(e,t){$e(e)||(t==null?e.removeAttribute("class"):e.className=t)}function In(e,t,n,r){if(r)Array.isArray(n)?(e[`$$${t}`]=n[0],e[`$$${t}Data`]=n[1]):e[`$$${t}`]=n;else if(Array.isArray(n)){const a=n[0];e.addEventListener(t,n[0]=i=>a.call(e,n[1],i))}else e.addEventListener(t,n,typeof n!="function"&&n)}function zi(e,t,n={}){const r=Object.keys(t||{}),a=Object.keys(n);let i,o;for(i=0,o=a.length;i<o;i++){const l=a[i];!l||l==="undefined"||t[l]||(Fs(e,l,!1),delete n[l])}for(i=0,o=r.length;i<o;i++){const l=r[i],u=!!t[l];!l||l==="undefined"||n[l]===u||!u||(Fs(e,l,!0),n[l]=u)}return n}function Vi(e,t,n){if(!t)return n?Zt(e,"style"):t;const r=e.style;if(typeof t=="string")return r.cssText=t;typeof n=="string"&&(r.cssText=n=void 0),n||(n={}),t||(t={});let a,i;for(i in n)t[i]==null&&r.removeProperty(i),delete n[i];for(i in t)a=t[i],a!==n[i]&&(r.setProperty(i,a),n[i]=a);return n}function kn(e,t={},n,r){const a={};return r||Fe(()=>a.children=St(e,t.children,a.children)),Fe(()=>typeof t.ref=="function"&&Ln(t.ref,e)),Fe(()=>$i(e,t,n,!0,a,!0)),a}function Ln(e,t,n){return be(()=>e(t,n))}function Jt(e,t,n,r){if(n!==void 0&&!r&&(r=[]),typeof t!="function")return St(e,t,r,n);Fe(a=>St(e,t(),a,n),r)}function $i(e,t,n,r,a={},i=!1){t||(t={});for(const o in a)if(!(o in t)){if(o==="children")continue;a[o]=qs(e,o,null,a[o],n,i,t)}for(const o in t){if(o==="children")continue;const l=t[o];a[o]=qs(e,o,l,a[o],n,i,t)}}function Wi(e){let t,n;return!$e()||!(t=q.registry.get(n=Yi()))?e():(q.completed&&q.completed.add(t),q.registry.delete(n),t)}function $e(e){return!!q.context&&!q.done&&(!e||e.isConnected)}function Qi(e){return e.toLowerCase().replace(/-([a-z])/g,(t,n)=>n.toUpperCase())}function Fs(e,t,n){const r=t.trim().split(/\s+/);for(let a=0,i=r.length;a<i;a++)e.classList.toggle(r[a],n)}function qs(e,t,n,r,a,i,o){let l,u,d,f,h;if(t==="style")return Vi(e,n,r);if(t==="classList")return zi(e,n,r);if(n===r)return r;if(t==="ref")i||n(e);else if(t.slice(0,3)==="on:"){const v=t.slice(3);r&&e.removeEventListener(v,r,typeof r!="function"&&r),n&&e.addEventListener(v,n,typeof n!="function"&&n)}else if(t.slice(0,10)==="oncapture:"){const v=t.slice(10);r&&e.removeEventListener(v,r,!0),n&&e.addEventListener(v,n,!0)}else if(t.slice(0,2)==="on"){const v=t.slice(2).toLowerCase(),E=Mi.has(v);if(!E&&r){const y=Array.isArray(r)?r[0]:r;e.removeEventListener(v,y)}(E||n)&&(In(e,v,n,E),E&&Pn([v]))}else if(t.slice(0,5)==="attr:")Zt(e,t.slice(5),n);else if(t.slice(0,5)==="bool:")Ki(e,t.slice(5),n);else if((h=t.slice(0,5)==="prop:")||(d=Li.has(t))||!a&&((f=Gi(t,e.tagName))||(u=ki.has(t)))||(l=e.nodeName.includes("-")||"is"in o)){if(h)t=t.slice(5),u=!0;else if($e(e))return n;t==="class"||t==="className"?_n(e,n):l&&!u&&!d?e[Qi(t)]=n:e[f||t]=n}else{const v=a&&t.indexOf(":")>-1&&Ui[t.split(":")[0]];v?Hi(e,v,t,n):Zt(e,Di[t]||t,n)}return n}function Dn(e){if(q.registry&&q.events&&q.events.find(([u,d])=>d===e))return;let t=e.target;const n=`$$${e.type}`,r=e.target,a=e.currentTarget,i=u=>Object.defineProperty(e,"target",{configurable:!0,value:u}),o=()=>{const u=t[n];if(u&&!t.disabled){const d=t[`${n}Data`];if(d!==void 0?u.call(t,d,e):u.call(t,e),e.cancelBubble)return}return t.host&&typeof t.host!="string"&&!t.host._$host&&t.contains(e.target)&&i(t.host),!0},l=()=>{for(;o()&&(t=t._$host||t.parentNode||t.host););};if(Object.defineProperty(e,"currentTarget",{configurable:!0,get(){return t||document}}),q.registry&&!q.done&&(q.done=_$HY.done=!0),e.composedPath){const u=e.composedPath();i(u[0]);for(let d=0;d<u.length-2&&(t=u[d],!!o());d++){if(t._$host){t=t._$host,l();break}if(t.parentNode===a)break}}else l();i(r)}function St(e,t,n,r,a){const i=$e(e);if(i){!n&&(n=[...e.childNodes]);let u=[];for(let d=0;d<n.length;d++){const f=n[d];f.nodeType===8&&f.data.slice(0,2)==="!$"?f.remove():u.push(f)}n=u}for(;typeof n=="function";)n=n();if(t===n)return n;const o=typeof t,l=r!==void 0;if(e=l&&n[0]&&n[0].parentNode||e,o==="string"||o==="number"){if(i||o==="number"&&(t=t.toString(),t===n))return n;if(l){let u=n[0];u&&u.nodeType===3?u.data!==t&&(u.data=t):u=document.createTextNode(t),n=We(e,n,r,u)}else n!==""&&typeof n=="string"?n=e.firstChild.data=t:n=e.textContent=t}else if(t==null||o==="boolean"){if(i)return n;n=We(e,n,r)}else{if(o==="function")return Fe(()=>{let u=t();for(;typeof u=="function";)u=u();n=St(e,u,n,r)}),()=>n;if(Array.isArray(t)){const u=[],d=n&&Array.isArray(n);if(gs(u,t,n,a))return Fe(()=>n=St(e,u,n,r,!0)),()=>n;if(i){if(!u.length)return n;if(r===void 0)return n=[...e.childNodes];let f=u[0];if(f.parentNode!==e)return n;const h=[f];for(;(f=f.nextSibling)!==r;)h.push(f);return n=h}if(u.length===0){if(n=We(e,n,r),l)return n}else d?n.length===0?Hs(e,u,r):Oi(e,n,u):(n&&We(e),Hs(e,u));n=u}else if(t.nodeType){if(i&&t.parentNode)return n=l?[t]:t;if(Array.isArray(n)){if(l)return n=We(e,n,r,t);We(e,n,null,t)}else n==null||n===""||!e.firstChild?e.appendChild(t):e.replaceChild(t,e.firstChild);n=t}}return n}function gs(e,t,n,r){let a=!1;for(let i=0,o=t.length;i<o;i++){let l=t[i],u=n&&n[e.length],d;if(!(l==null||l===!0||l===!1))if((d=typeof l)=="object"&&l.nodeType)e.push(l);else if(Array.isArray(l))a=gs(e,l,u)||a;else if(d==="function")if(r){for(;typeof l=="function";)l=l();a=gs(e,Array.isArray(l)?l:[l],Array.isArray(u)?u:[u])||a}else e.push(l),a=!0;else{const f=String(l);u&&u.nodeType===3&&u.data===f?e.push(u):e.push(document.createTextNode(f))}}return a}function Hs(e,t,n=null){for(let r=0,a=t.length;r<a;r++)e.insertBefore(t[r],n)}function We(e,t,n,r){if(n===void 0)return e.textContent="";const a=r||document.createTextNode("");if(t.length){let i=!1;for(let o=t.length-1;o>=0;o--){const l=t[o];if(a!==l){const u=l.parentNode===e;!i&&!o?u?e.replaceChild(a,l):e.insertBefore(a,n):u&&l.remove()}else i=!0}}else e.insertBefore(a,n);return[a]}function Yi(){return q.getNextContextId()}var Xi="http://www.w3.org/2000/svg";function Bn(e,t=!1){return t?document.createElementNS(Xi,e):document.createElement(e)}function Zi(e){const{useShadow:t}=e,n=document.createTextNode(""),r=()=>e.mount||document.body,a=Os();let i,o=!!q.context;return Ts(()=>{o&&(Os().user=o=!1),i||(i=ui(a,()=>we(()=>e.children)));const l=r();if(l instanceof HTMLHeadElement){const[u,d]=ve(!1),f=()=>d(!0);Oe(h=>Jt(l,()=>u()?h():i(),null)),dt(f)}else{const u=Bn(e.isSVG?"g":"div",e.isSVG),d=t&&u.attachShadow?u.attachShadow({mode:"open"}):u;Object.defineProperty(u,"_$host",{get(){return n.parentNode},configurable:!0}),Jt(d,i),l.appendChild(u),e.ref&&e.ref(u),dt(()=>l.removeChild(u))}},void 0,{render:!o}),n}function Ji(e){const[t,n]=Nn(e,["component"]),r=we(()=>t.component);return we(()=>{const a=r();switch(typeof a){case"function":return be(()=>a(n));case"string":const i=Ri.has(a),o=q.context?Wi():Bn(a,i);return kn(o,n,i),o}})}var eo=class{constructor(){this.keyToValue=new Map,this.valueToKey=new Map}set(e,t){this.keyToValue.set(e,t),this.valueToKey.set(t,e)}getByKey(e){return this.keyToValue.get(e)}getByValue(e){return this.valueToKey.get(e)}clear(){this.keyToValue.clear(),this.valueToKey.clear()}},Gn=class{constructor(e){this.generateIdentifier=e,this.kv=new eo}register(e,t){this.kv.getByValue(e)||(t||(t=this.generateIdentifier(e)),this.kv.set(t,e))}clear(){this.kv.clear()}getIdentifier(e){return this.kv.getByValue(e)}getValue(e){return this.kv.getByKey(e)}},to=class extends Gn{constructor(){super(e=>e.name),this.classToAllowedProps=new Map}register(e,t){typeof t=="object"?(t.allowProps&&this.classToAllowedProps.set(e,t.allowProps),super.register(e,t.identifier)):super.register(e,t)}getAllowedProps(e){return this.classToAllowedProps.get(e)}};function so(e){if("values"in Object)return Object.values(e);const t=[];for(const n in e)e.hasOwnProperty(n)&&t.push(e[n]);return t}function no(e,t){const n=so(e);if("find"in n)return n.find(t);const r=n;for(let a=0;a<r.length;a++){const i=r[a];if(t(i))return i}}function ht(e,t){Object.entries(e).forEach(([n,r])=>t(r,n))}function Kt(e,t){return e.indexOf(t)!==-1}function Ks(e,t){for(let n=0;n<e.length;n++){const r=e[n];if(t(r))return r}}var ro=class{constructor(){this.transfomers={}}register(e){this.transfomers[e.name]=e}findApplicable(e){return no(this.transfomers,t=>t.isApplicable(e))}findByName(e){return this.transfomers[e]}},ao=e=>Object.prototype.toString.call(e).slice(8,-1),Mn=e=>typeof e>"u",io=e=>e===null,wt=e=>typeof e!="object"||e===null||e===Object.prototype?!1:Object.getPrototypeOf(e)===null?!0:Object.getPrototypeOf(e)===Object.prototype,ps=e=>wt(e)&&Object.keys(e).length===0,qe=e=>Array.isArray(e),oo=e=>typeof e=="string",lo=e=>typeof e=="number"&&!isNaN(e),co=e=>typeof e=="boolean",uo=e=>e instanceof RegExp,Nt=e=>e instanceof Map,At=e=>e instanceof Set,Rn=e=>ao(e)==="Symbol",ho=e=>e instanceof Date&&!isNaN(e.valueOf()),mo=e=>e instanceof Error,zs=e=>typeof e=="number"&&isNaN(e),fo=e=>co(e)||io(e)||Mn(e)||lo(e)||oo(e)||Rn(e),go=e=>typeof e=="bigint",po=e=>e===1/0||e===-1/0,xo=e=>ArrayBuffer.isView(e)&&!(e instanceof DataView),yo=e=>e instanceof URL,Un=e=>e.replace(/\./g,"\\."),cs=e=>e.map(String).map(Un).join("."),bt=e=>{const t=[];let n="";for(let a=0;a<e.length;a++){let i=e.charAt(a);if(i==="\\"&&e.charAt(a+1)==="."){n+=".",a++;continue}if(i==="."){t.push(n),n="";continue}n+=i}const r=n;return t.push(r),t};function ke(e,t,n,r){return{isApplicable:e,annotation:t,transform:n,untransform:r}}var On=[ke(Mn,"undefined",()=>null,()=>{}),ke(go,"bigint",e=>e.toString(),e=>typeof BigInt<"u"?BigInt(e):e),ke(ho,"Date",e=>e.toISOString(),e=>new Date(e)),ke(mo,"Error",(e,t)=>{const n={name:e.name,message:e.message};return t.allowedErrorProps.forEach(r=>{n[r]=e[r]}),n},(e,t)=>{const n=new Error(e.message);return n.name=e.name,n.stack=e.stack,t.allowedErrorProps.forEach(r=>{n[r]=e[r]}),n}),ke(uo,"regexp",e=>""+e,e=>{const t=e.slice(1,e.lastIndexOf("/")),n=e.slice(e.lastIndexOf("/")+1);return new RegExp(t,n)}),ke(At,"set",e=>[...e.values()],e=>new Set(e)),ke(Nt,"map",e=>[...e.entries()],e=>new Map(e)),ke(e=>zs(e)||po(e),"number",e=>zs(e)?"NaN":e>0?"Infinity":"-Infinity",Number),ke(e=>e===0&&1/e===-1/0,"number",()=>"-0",Number),ke(yo,"URL",e=>e.toString(),e=>new URL(e))];function ns(e,t,n,r){return{isApplicable:e,annotation:t,transform:n,untransform:r}}var Fn=ns((e,t)=>Rn(e)?!!t.symbolRegistry.getIdentifier(e):!1,(e,t)=>["symbol",t.symbolRegistry.getIdentifier(e)],e=>e.description,(e,t,n)=>{const r=n.symbolRegistry.getValue(t[1]);if(!r)throw new Error("Trying to deserialize unknown symbol");return r}),vo=[Int8Array,Uint8Array,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array,Uint8ClampedArray].reduce((e,t)=>(e[t.name]=t,e),{}),qn=ns(xo,e=>["typed-array",e.constructor.name],e=>[...e],(e,t)=>{const n=vo[t[1]];if(!n)throw new Error("Trying to deserialize unknown typed array");return new n(e)});function Hn(e,t){return e!=null&&e.constructor?!!t.classRegistry.getIdentifier(e.constructor):!1}var Kn=ns(Hn,(e,t)=>["class",t.classRegistry.getIdentifier(e.constructor)],(e,t)=>{const n=t.classRegistry.getAllowedProps(e.constructor);if(!n)return{...e};const r={};return n.forEach(a=>{r[a]=e[a]}),r},(e,t,n)=>{const r=n.classRegistry.getValue(t[1]);if(!r)throw new Error("Trying to deserialize unknown class - check https://github.com/blitz-js/superjson/issues/116#issuecomment-773996564");return Object.assign(Object.create(r.prototype),e)}),zn=ns((e,t)=>!!t.customTransformerRegistry.findApplicable(e),(e,t)=>["custom",t.customTransformerRegistry.findApplicable(e).name],(e,t)=>t.customTransformerRegistry.findApplicable(e).serialize(e),(e,t,n)=>{const r=n.customTransformerRegistry.findByName(t[1]);if(!r)throw new Error("Trying to deserialize unknown custom value");return r.deserialize(e)}),Eo=[Kn,Fn,zn,qn],Vs=(e,t)=>{const n=Ks(Eo,a=>a.isApplicable(e,t));if(n)return{value:n.transform(e,t),type:n.annotation(e,t)};const r=Ks(On,a=>a.isApplicable(e,t));if(r)return{value:r.transform(e,t),type:r.annotation}},Vn={};On.forEach(e=>{Vn[e.annotation]=e});var bo=(e,t,n)=>{if(qe(t))switch(t[0]){case"symbol":return Fn.untransform(e,t,n);case"class":return Kn.untransform(e,t,n);case"custom":return zn.untransform(e,t,n);case"typed-array":return qn.untransform(e,t,n);default:throw new Error("Unknown transformation: "+t)}else{const r=Vn[t];if(!r)throw new Error("Unknown transformation: "+t);return r.untransform(e,n)}},Qe=(e,t)=>{const n=e.keys();for(;t>0;)n.next(),t--;return n.next().value};function $n(e){if(Kt(e,"__proto__"))throw new Error("__proto__ is not allowed as a property");if(Kt(e,"prototype"))throw new Error("prototype is not allowed as a property");if(Kt(e,"constructor"))throw new Error("constructor is not allowed as a property")}var jo=(e,t)=>{$n(t);for(let n=0;n<t.length;n++){const r=t[n];if(At(e))e=Qe(e,+r);else if(Nt(e)){const a=+r,i=+t[++n]==0?"key":"value",o=Qe(e,a);switch(i){case"key":e=o;break;case"value":e=e.get(o);break}}else e=e[r]}return e},xs=(e,t,n)=>{if($n(t),t.length===0)return n(e);let r=e;for(let i=0;i<t.length-1;i++){const o=t[i];if(qe(r)){const l=+o;r=r[l]}else if(wt(r))r=r[o];else if(At(r)){const l=+o;r=Qe(r,l)}else if(Nt(r)){if(i===t.length-2)break;const u=+o,d=+t[++i]==0?"key":"value",f=Qe(r,u);switch(d){case"key":r=f;break;case"value":r=r.get(f);break}}}const a=t[t.length-1];if(qe(r)?r[+a]=n(r[+a]):wt(r)&&(r[a]=n(r[a])),At(r)){const i=Qe(r,+a),o=n(i);i!==o&&(r.delete(i),r.add(o))}if(Nt(r)){const i=+t[t.length-2],o=Qe(r,i);switch(+a==0?"key":"value"){case"key":{const u=n(o);r.set(u,r.get(o)),u!==o&&r.delete(o);break}case"value":{r.set(o,n(r.get(o)));break}}}return e};function ys(e,t,n=[]){if(!e)return;if(!qe(e)){ht(e,(i,o)=>ys(i,t,[...n,...bt(o)]));return}const[r,a]=e;a&&ht(a,(i,o)=>{ys(i,t,[...n,...bt(o)])}),t(r,n)}function So(e,t,n){return ys(t,(r,a)=>{e=xs(e,a,i=>bo(i,r,n))}),e}function wo(e,t){function n(r,a){const i=jo(e,bt(a));r.map(bt).forEach(o=>{e=xs(e,o,()=>i)})}if(qe(t)){const[r,a]=t;r.forEach(i=>{e=xs(e,bt(i),()=>e)}),a&&ht(a,n)}else ht(t,n);return e}var No=(e,t)=>wt(e)||qe(e)||Nt(e)||At(e)||Hn(e,t);function Ao(e,t,n){const r=n.get(e);r?r.push(t):n.set(e,[t])}function To(e,t){const n={};let r;return e.forEach(a=>{if(a.length<=1)return;t||(a=a.map(l=>l.map(String)).sort((l,u)=>l.length-u.length));const[i,...o]=a;i.length===0?r=o.map(cs):n[cs(i)]=o.map(cs)}),r?ps(n)?[r]:[r,n]:ps(n)?void 0:n}var Wn=(e,t,n,r,a=[],i=[],o=new Map)=>{const l=fo(e);if(!l){Ao(e,a,t);const E=o.get(e);if(E)return r?{transformedValue:null}:E}if(!No(e,n)){const E=Vs(e,n),y=E?{transformedValue:E.value,annotations:[E.type]}:{transformedValue:e};return l||o.set(e,y),y}if(Kt(i,e))return{transformedValue:null};const u=Vs(e,n),d=(u==null?void 0:u.value)??e,f=qe(d)?[]:{},h={};ht(d,(E,y)=>{if(y==="__proto__"||y==="constructor"||y==="prototype")throw new Error(`Detected property ${y}. This is a prototype pollution risk, please remove it from your object.`);const N=Wn(E,t,n,r,[...a,y],[...i,e],o);f[y]=N.transformedValue,qe(N.annotations)?h[y]=N.annotations:wt(N.annotations)&&ht(N.annotations,(b,A)=>{h[Un(y)+"."+A]=b})});const v=ps(h)?{transformedValue:f,annotations:u?[u.type]:void 0}:{transformedValue:f,annotations:u?[u.type,h]:h};return l||o.set(e,v),v};function Qn(e){return Object.prototype.toString.call(e).slice(8,-1)}function $s(e){return Qn(e)==="Array"}function Co(e){if(Qn(e)!=="Object")return!1;const t=Object.getPrototypeOf(e);return!!t&&t.constructor===Object&&t===Object.prototype}function Po(e,t,n,r,a){const i={}.propertyIsEnumerable.call(r,t)?"enumerable":"nonenumerable";i==="enumerable"&&(e[t]=n),a&&i==="nonenumerable"&&Object.defineProperty(e,t,{value:n,enumerable:!1,writable:!0,configurable:!0})}function vs(e,t={}){if($s(e))return e.map(a=>vs(a,t));if(!Co(e))return e;const n=Object.getOwnPropertyNames(e),r=Object.getOwnPropertySymbols(e);return[...n,...r].reduce((a,i)=>{if($s(t.props)&&!t.props.includes(i))return a;const o=e[i],l=vs(o,t);return Po(a,i,l,e,t.nonenumerable),a},{})}var de=class{constructor({dedupe:e=!1}={}){this.classRegistry=new to,this.symbolRegistry=new Gn(t=>t.description??""),this.customTransformerRegistry=new ro,this.allowedErrorProps=[],this.dedupe=e}serialize(e){const t=new Map,n=Wn(e,t,this,this.dedupe),r={json:n.transformedValue};n.annotations&&(r.meta={...r.meta,values:n.annotations});const a=To(t,this.dedupe);return a&&(r.meta={...r.meta,referentialEqualities:a}),r}deserialize(e){const{json:t,meta:n}=e;let r=vs(t);return n!=null&&n.values&&(r=So(r,n.values,this)),n!=null&&n.referentialEqualities&&(r=wo(r,n.referentialEqualities)),r}stringify(e){return JSON.stringify(this.serialize(e))}parse(e){return this.deserialize(JSON.parse(e))}registerClass(e,t){this.classRegistry.register(e,t)}registerSymbol(e,t){this.symbolRegistry.register(e,t)}registerCustom(e,t){this.customTransformerRegistry.register({name:t,...e})}allowErrorProps(...e){this.allowedErrorProps.push(...e)}};de.defaultInstance=new de;de.serialize=de.defaultInstance.serialize.bind(de.defaultInstance);de.deserialize=de.defaultInstance.deserialize.bind(de.defaultInstance);de.stringify=de.defaultInstance.stringify.bind(de.defaultInstance);de.parse=de.defaultInstance.parse.bind(de.defaultInstance);de.registerClass=de.defaultInstance.registerClass.bind(de.defaultInstance);de.registerSymbol=de.defaultInstance.registerSymbol.bind(de.defaultInstance);de.registerCustom=de.defaultInstance.registerCustom.bind(de.defaultInstance);de.allowErrorProps=de.defaultInstance.allowErrorProps.bind(de.defaultInstance);var Yn=de.serialize,_o=de.stringify;function Io(e){return e.state.fetchStatus==="fetching"?"fetching":e.getObserversCount()?e.state.fetchStatus==="paused"?"paused":e.isStale()?"stale":"fresh":"inactive"}function ko(e,t){return`${e}${t.charAt(0).toUpperCase()+t.slice(1)}`}function Lo({queryState:e,observerCount:t,isStale:n}){return e.fetchStatus==="fetching"?"blue":t?e.fetchStatus==="paused"?"purple":n?"yellow":"green":"gray"}function Do({status:e,isPaused:t}){return t?"purple":e==="error"?"red":e==="pending"?"yellow":e==="success"?"green":"gray"}function Bo(e){return e==="fresh"?"green":e==="stale"?"yellow":e==="paused"?"purple":e==="inactive"?"gray":"blue"}var Go=(e,t=!1)=>{const{json:n}=Yn(e);return JSON.stringify(n,null,t?2:void 0)},Ft=e=>e.state.fetchStatus!=="idle"?0:e.getObserversCount()?e.isStale()?2:1:3,Mo=(e,t)=>e.queryHash.localeCompare(t.queryHash),Xn=(e,t)=>e.state.dataUpdatedAt<t.state.dataUpdatedAt?1:-1,Ro=(e,t)=>Ft(e)===Ft(t)?Xn(e,t):Ft(e)>Ft(t)?1:-1,Uo={status:Ro,"query hash":Mo,"last updated":Xn},qt=e=>e.state.isPaused?0:e.state.status==="error"?2:e.state.status==="pending"?1:3,Zn=(e,t)=>e.state.submittedAt<t.state.submittedAt?1:-1,Oo=(e,t)=>qt(e)===qt(t)?Zn(e,t):qt(e)>qt(t)?1:-1,Fo={status:Oo,"last updated":Zn},qo=e=>e*parseFloat(getComputedStyle(document.documentElement).fontSize),Ho=()=>{const[e,t]=ve("dark");return vn(()=>{const n=window.matchMedia("(prefers-color-scheme: dark)");t(n.matches?"dark":"light");const r=a=>{t(a.matches?"dark":"light")};n.addEventListener("change",r),dt(()=>n.removeEventListener("change",r))}),e},yt=(e,t,n)=>{if(t.length===0)return n;if(e instanceof Map){const r=new Map(e);if(t.length===1)return r.set(t[0],n),r;const[a,...i]=t;return r.set(a,yt(r.get(a),i,n)),r}if(e instanceof Set){const r=yt(Array.from(e),t,n);return new Set(r)}if(Array.isArray(e)){const r=[...e];if(t.length===1)return r[t[0]]=n,r;const[a,...i]=t;return r[a]=yt(r[a],i,n),r}if(e instanceof Object){const r={...e};if(t.length===1)return r[t[0]]=n,r;const[a,...i]=t;return r[a]=yt(r[a],i,n),r}return e},vt=(e,t)=>{if(e instanceof Map){const n=new Map(e);if(t.length===1)return n.delete(t[0]),n;const[r,...a]=t;return n.set(r,vt(n.get(r),a)),n}if(e instanceof Set){const n=vt(Array.from(e),t);return new Set(n)}if(Array.isArray(e)){const n=[...e];if(t.length===1)return n.filter((i,o)=>o.toString()!==t[0]);const[r,...a]=t;return n[r]=vt(n[r],a),n}if(e instanceof Object){const n={...e};if(t.length===1)return delete n[t[0]],n;const[r,...a]=t;return n[r]=vt(n[r],a),n}return e},Jn=(e,t)=>{if(!e||document.querySelector("#_goober")||(t==null?void 0:t.querySelector("#_goober")))return;const r=document.createElement("style"),a=document.createTextNode("");r.appendChild(a),r.id="_goober",r.setAttribute("nonce",e),t?t.appendChild(r):document.head.appendChild(r)},Ye,Tt,Ct,Pt,Ke,_t,Xe,Ze,Je,et,tt,st,It,Ws,Ko=(Ws=class{constructor(e){ce(this,Ye);ce(this,Tt);ce(this,Ct);ce(this,Pt);ce(this,Ke,!1);ce(this,_t);ce(this,Xe);ce(this,Ze);ce(this,Je);ce(this,et);ce(this,tt);ce(this,st);ce(this,It);const{client:t,queryFlavor:n,version:r,onlineManager:a,buttonPosition:i,position:o,initialIsOpen:l,errorTypes:u,styleNonce:d,shadowDOMTarget:f}=e;oe(this,Ye,ve(t)),oe(this,Ct,n),oe(this,Pt,r),oe(this,Tt,a),oe(this,_t,d),oe(this,Xe,f),oe(this,Ze,ve(i)),oe(this,Je,ve(o)),oe(this,et,ve(l)),oe(this,tt,ve(u))}setButtonPosition(e){O(this,Ze)[1](e)}setPosition(e){O(this,Je)[1](e)}setInitialIsOpen(e){O(this,et)[1](e)}setErrorTypes(e){O(this,tt)[1](e)}setClient(e){O(this,Ye)[1](e)}mount(e){if(O(this,Ke))throw new Error("Devtools is already mounted");const t=Cn(()=>{const n=this,[r]=O(this,Ze),[a]=O(this,Je),[i]=O(this,et),[o]=O(this,tt),[l]=O(this,Ye);let u;return O(this,st)?u=O(this,st):(u=An(()=>Promise.resolve().then(()=>require("./HO4MOOFI-Cl7Y_Hiz.cjs"))),oe(this,st,u)),Jn(O(this,_t),O(this,Xe)),Ps(u,_s({get queryFlavor(){return O(n,Ct)},get version(){return O(n,Pt)},get onlineManager(){return O(n,Tt)},get shadowDOMTarget(){return O(n,Xe)}},{get client(){return l()},get buttonPosition(){return r()},get position(){return a()},get initialIsOpen(){return i()},get errorTypes(){return o()}}))},e);oe(this,Ke,!0),oe(this,It,t)}unmount(){var e;if(!O(this,Ke))throw new Error("Devtools is not mounted");(e=O(this,It))==null||e.call(this),oe(this,Ke,!1)}},Ye=new WeakMap,Tt=new WeakMap,Ct=new WeakMap,Pt=new WeakMap,Ke=new WeakMap,_t=new WeakMap,Xe=new WeakMap,Ze=new WeakMap,Je=new WeakMap,et=new WeakMap,tt=new WeakMap,st=new WeakMap,It=new WeakMap,Ws),nt,kt,Lt,Dt,ze,Bt,rt,at,it,ot,lt,ct,ut,Gt,Qs,zo=(Qs=class{constructor(e){ce(this,nt);ce(this,kt);ce(this,Lt);ce(this,Dt);ce(this,ze,!1);ce(this,Bt);ce(this,rt);ce(this,at);ce(this,it);ce(this,ot);ce(this,lt);ce(this,ct);ce(this,ut);ce(this,Gt);const{client:t,queryFlavor:n,version:r,onlineManager:a,buttonPosition:i,position:o,initialIsOpen:l,errorTypes:u,styleNonce:d,shadowDOMTarget:f,onClose:h}=e;oe(this,nt,ve(t)),oe(this,Lt,n),oe(this,Dt,r),oe(this,kt,a),oe(this,Bt,d),oe(this,rt,f),oe(this,at,ve(i)),oe(this,it,ve(o)),oe(this,ot,ve(l)),oe(this,lt,ve(u)),oe(this,ct,ve(h))}setButtonPosition(e){O(this,at)[1](e)}setPosition(e){O(this,it)[1](e)}setInitialIsOpen(e){O(this,ot)[1](e)}setErrorTypes(e){O(this,lt)[1](e)}setClient(e){O(this,nt)[1](e)}setOnClose(e){O(this,ct)[1](()=>e)}mount(e){if(O(this,ze))throw new Error("Devtools is already mounted");const t=Cn(()=>{const n=this,[r]=O(this,at),[a]=O(this,it),[i]=O(this,ot),[o]=O(this,lt),[l]=O(this,nt),[u]=O(this,ct);let d;return O(this,ut)?d=O(this,ut):(d=An(()=>Promise.resolve().then(()=>require("./HUY7CZI3-DIo60go4.cjs"))),oe(this,ut,d)),Jn(O(this,Bt),O(this,rt)),Ps(d,_s({get queryFlavor(){return O(n,Lt)},get version(){return O(n,Dt)},get onlineManager(){return O(n,kt)},get shadowDOMTarget(){return O(n,rt)}},{get client(){return l()},get buttonPosition(){return r()},get position(){return a()},get initialIsOpen(){return i()},get errorTypes(){return o()},get onClose(){return u()}}))},e);oe(this,ze,!0),oe(this,Gt,t)}unmount(){var e;if(!O(this,ze))throw new Error("Devtools is not mounted");(e=O(this,Gt))==null||e.call(this),oe(this,ze,!1)}},nt=new WeakMap,kt=new WeakMap,Lt=new WeakMap,Dt=new WeakMap,ze=new WeakMap,Bt=new WeakMap,rt=new WeakMap,at=new WeakMap,it=new WeakMap,ot=new WeakMap,lt=new WeakMap,ct=new WeakMap,ut=new WeakMap,Gt=new WeakMap,Qs);function Vo(e){const t=k.useQueryClient(e.client),n=ge.useRef(null),{buttonPosition:r,position:a,initialIsOpen:i,errorTypes:o,styleNonce:l,shadowDOMTarget:u}=e,[d]=ge.useState(new Ko({client:t,queryFlavor:"React Query",version:"5",onlineManager:k.onlineManager,buttonPosition:r,position:a,initialIsOpen:i,errorTypes:o,styleNonce:l,shadowDOMTarget:u}));return ge.useEffect(()=>{d.setClient(t)},[t,d]),ge.useEffect(()=>{r&&d.setButtonPosition(r)},[r,d]),ge.useEffect(()=>{a&&d.setPosition(a)},[a,d]),ge.useEffect(()=>{d.setInitialIsOpen(i||!1)},[i,d]),ge.useEffect(()=>{d.setErrorTypes(o||[])},[o,d]),ge.useEffect(()=>(n.current&&d.mount(n.current),()=>{d.unmount()}),[d]),s.jsx("div",{className:"tsqd-parent-container",ref:n})}function $o(e){const t=k.useQueryClient(e.client),n=ge.useRef(null),{errorTypes:r,styleNonce:a,shadowDOMTarget:i}=e,[o]=ge.useState(new zo({client:t,queryFlavor:"React Query",version:"5",onlineManager:k.onlineManager,buttonPosition:"bottom-left",position:"bottom",initialIsOpen:!0,errorTypes:r,styleNonce:a,shadowDOMTarget:i,onClose:e.onClose}));return ge.useEffect(()=>{o.setClient(t)},[t,o]),ge.useEffect(()=>{o.setOnClose(e.onClose??(()=>{}))},[e.onClose,o]),ge.useEffect(()=>{o.setErrorTypes(r||[])},[r,o]),ge.useEffect(()=>(n.current&&o.mount(n.current),()=>{o.unmount()}),[o]),s.jsx("div",{style:{height:"500px",...e.style},className:"tsqd-parent-container",ref:n})}var Wo=process.env.NODE_ENV!=="development"?function(){return null}:Vo;process.env.NODE_ENV;const Qo=p.lazy(()=>Promise.resolve().then(()=>require("./digital-asset-manager-ITE5Abrb.cjs")));lr.loadWebBlocks();ei();J.registerChaiTopBar(Ma);J.registerChaiMediaManager(Qo);J.registerChaiSaveToLibrary(Rr);J.registerChaiSidebarPanel("user-info",ni);const Yo=e=>{const t=p.useRef([]),[n]=Ne(),r=n.get("page"),a=n.get("lang"),{data:i}=Ae(),{data:o={role:"",permissions:null}}=dn(),{data:l}=Fa(),{data:u,isFetching:d}=nn(),{blocks:f}=Oa(u),{data:h}=ft(),{data:v}=Se(),{mutateAsync:E}=en(),y=Ra(),{getUILibraryBlock:N,getUILibraryBlocks:b,onSave:A}=qa(),{getPartialBlocks:M,getPartialBlockBlocks:w}=Ha(),{aiContext:S,setAiContext:I}=Es(),{mutateAsync:D}=Fr(),[le,ne]=p.useState(!1),B=p.useMemo(()=>(h==null?void 0:h.fallbackLang)||"en",[h]),{data:U}=rn({pageType:i==null?void 0:i.pageType,lang:a||B});jr(),p.useEffect(()=>{const ee=()=>{document.hidden?ne(!0):ne(!1)};return window.addEventListener("visibilitychange",ee),()=>window.removeEventListener("visibilitychange",ee)},[]),t.current=f;const C=p.useMemo(()=>{const ee={};return o&&(ee.permissions=g.get(o,"permissions",null),ee.role=g.get(o,"role","user")),ee},[o]),F=p.useMemo(()=>l,[l]),re=p.useCallback(async(ee,fe)=>await D({pageType:ee,query:fe}),[D]),me=p.useMemo(()=>g.get(h,"theme",{})||{},[h]);return s.jsxs(s.Fragment,{children:[d&&s.jsx("div",{className:"absolute inset-0 z-50 flex items-center justify-center w-screen h-screen bg-white/30",children:s.jsx("div",{className:"flex items-center justify-center bg-white rounded-full size-10",children:s.jsx(P.Loader2,{className:"size-5 animate-spin"})})}),s.jsx(J.ChaiBuilderEditor,{pageExternalData:U,themePresets:e.themePresets??[],pageId:i==null?void 0:i.id,loading:d,fallbackLang:B,languages:(h==null?void 0:h.languages)||[],brandingOptions:(h==null?void 0:h.theme)||{},translations:e.translations||{},locale:e.locale||"en",htmlDir:e.htmlDir||"ltr",autoSaveSupport:!le&&(e.autoSaveSupport??!0),autoSaveInterval:e.autoSaveInterval??15,onError:e.onError||console.error,getPartialBlockBlocks:w,getPartialBlocks:M,blocks:d?[]:f,theme:g.cloneDeep(me),getUILibraryBlock:N,getUILibraryBlocks:b,uiLibraries:F,pageTypes:v,searchPageTypeItems:re,saveAiContextCallback:async ee=>{if(!r)return!0;const fe=t.current,V={_type:"@chai/ai-context",_value:g.isString(ee)?ee:""},pe=[...fe,V];return await A({page:r,blocks:pe}),I(ee),!0},aiContext:S,askAiCallBack:y,onSave:async({blocks:ee,theme:fe})=>{if(!r)return!0;t.current=ee;const V={_type:"@chai/ai-context",_value:g.isString(S)?S:""},pe=[...ee,V];return await A({page:r,blocks:pe}),t.current=pe,g.isEqual(fe,me)||await E({settings:{theme:fe}}),!0},themePanelComponent:Yr,...C}),s.jsxs("div",{children:[s.jsx(Tr,{}),s.jsx(Cr,{})]})]})},Xo=new k.QueryClient({defaultOptions:{queries:{refetchOnWindowFocus:!1,refetchOnReconnect:!1}}}),Zo=e=>{const{isLoggedIn:t}=De(),[,n]=tn(),[r,a]=p.useState(!1);return p.useEffect(()=>(n(g.pick(e,["apiUrl","usersApiUrl","assetsApiUrl","getPreviewUrl","logo","onLogout"])),setTimeout(()=>{a(!0)},200),()=>{a(!1),n({})}),[e,n]),r?s.jsxs(k.QueryClientProvider,{client:Xo,children:[t?s.jsx(Yo,{...e}):s.jsx($a,{}),s.jsx(Wo,{})]}):s.jsx("div",{})},Jo=()=>{const{user:e}=De(),t=p.useMemo(()=>e==null?void 0:e.accessToken,[e==null?void 0:e.accessToken]),{refetch:n}=Xs();return p.useCallback(async({url:r,method:a="GET",body:i={},headers:o={}})=>{if(t){if(!r)throw new Error("URL is required");try{const l=await fetch(r,{method:a,headers:{"Content-Type":"application/json",Authorization:`Bearer ${t}`,...o},body:JSON.stringify(i)});if(l.status===401&&await n(),l.status===400)throw new Error((await l.json()).error);return await l.json()}catch(l){throw console.log("Something went wrong",l),l}}},[t,n])};if(typeof window>"u")throw new Error("@chaibuilder/pages is not available on the server");exports.$TRACK=As;exports.ACTIONS=_;exports.ChaiBuilderPages=Zo;exports.Dynamic=Ji;exports.For=Ai;exports.Index=Ti;exports.Match=_i;exports.PermissionChecker=Te;exports.Portal=Zi;exports.QUERY_KEY_BASE=W;exports.Show=Ci;exports.Switch=Pi;exports.addEventListener=In;exports.batch=li;exports.className=_n;exports.clearDelegatedEvents=qi;exports.convertRemToPixels=qo;exports.createComponent=Ps;exports.createComputed=yn;exports.createContext=fi;exports.createEffect=Ts;exports.createMemo=we;exports.createRenderEffect=Fe;exports.createRoot=Oe;exports.createSignal=ve;exports.createUniqueId=Ni;exports.delegateEvents=Pn;exports.deleteNestedDataByPath=vt;exports.displayValue=Go;exports.getMutationStatusColor=Do;exports.getPreferredColorScheme=Ho;exports.getQueryStatusColor=Lo;exports.getQueryStatusColorByLabel=Bo;exports.getQueryStatusLabel=Io;exports.getSidedProp=ko;exports.insert=Jt;exports.mergeProps=_s;exports.mutationSortFns=Fo;exports.on=ci;exports.onCleanup=dt;exports.onMount=vn;exports.registerLoginComponent=Va;exports.serialize=Yn;exports.setAttribute=Zt;exports.sortFns=Uo;exports.splitProps=Nn;exports.spread=kn;exports.stringify=_o;exports.template=Fi;exports.untrack=be;exports.updateNestedDataByPath=yt;exports.use=Ln;exports.useAssetsApiUrl=Sr;exports.useChaiAuth=De;exports.useChaiFetch=Jo;exports.useChaiUserInfo=gt;exports.useContext=gi;exports.useCurrentPage=Ae;exports.useFetch=X;exports.useFetchUpload=vr;exports.useLanguagePages=mt;exports.useTransition=mi;exports.useUserRoleAndPermissions=dn;exports.useWebsitePages=Rt;exports.useWebsiteSetting=ft;
|