@chaibuilder/pages 0.5.3 → 0.5.4
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--lNS1XOZ.cjs → B4MFY5CR-DLMF4Fia.cjs} +1 -1
- package/dist/{B4MFY5CR-SntV1tRS.js → B4MFY5CR-DlwPVpmD.js} +1 -1
- package/dist/{HO4MOOFI-Dtsz_siU.cjs → HO4MOOFI-CH5TIJEX.cjs} +1 -1
- package/dist/{HO4MOOFI-BqUF7yRt.js → HO4MOOFI-CTW4q_go.js} +2 -2
- package/dist/{HUY7CZI3-BQnbnmHI.js → HUY7CZI3-Bic9WgW9.js} +2 -2
- package/dist/{HUY7CZI3-D_CODqZw.cjs → HUY7CZI3-CvHF_hS5.cjs} +1 -1
- package/dist/index-BBnsUqd9.cjs +2 -0
- package/dist/index-Cmn1hFYF.js +9240 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +27 -1
- package/dist/index.js +14 -10
- package/dist/server.cjs +1 -1
- package/dist/server.d.ts +14 -1
- package/dist/server.js +29 -25
- package/package.json +5 -5
- package/dist/digital-asset-manager-Biz2tg8j.js +0 -801
- package/dist/digital-asset-manager-_BA_7qEh.cjs +0 -1
- package/dist/index-B0BuMI6F.cjs +0 -2
- package/dist/index-cpLk6vnM.js +0 -8262
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var Fs=e=>{throw TypeError(e)};var qs=(e,s,n)=>s.has(e)||Fs("Cannot "+n);var H=(e,s,n)=>(qs(e,s,"read from private field"),n?n.call(e):s.get(e)),ue=(e,s,n)=>s.has(e)?Fs("Cannot add the same private member more than once"):s instanceof WeakSet?s.add(e):s.set(e,n),oe=(e,s,n,a)=>(qs(e,s,"write to private field"),a?a.call(e,n):s.set(e,n),n);const t=require("react/jsx-runtime"),x=require("lodash-es"),g=require("react"),Oe=require("jotai"),L=require("@tanstack/react-query"),Y=require("sonner"),ee=require("@chaibuilder/sdk"),c=require("@chaibuilder/sdk/ui"),N=require("lucide-react"),qt=require("date-fns"),ln=require("@chaibuilder/runtime"),Yt=require("zod"),ja=require("react-dropzone"),ba=require("@chaibuilder/sdk/web-blocks");function Ea(e){const s=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const a=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(s,n,a.get?a:{enumerable:!0,get:()=>e[n]})}}return s.default=e,Object.freeze(s)}const pe=Ea(g),Le={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"},P={UPDATE_PAGE_METADATA:"UPDATE_PAGE_METADATA",GET_BLOCK_ASYNC_PROPS:"GET_BLOCK_ASYNC_PROPS",ASK_AI:"ASK_AI",GET_DRAFT_PAGE:"GET_DRAFT_PAGE",CREATE_PAGE:"CREATE_PAGE",UPDATE_PAGE:"UPDATE_PAGE",DELETE_PAGE:"DELETE_PAGE",DUPLICATE_PAGE:"DUPLICATE_PAGE",CHANGE_SLUG:"CHANGE_SLUG",TAKE_OFFLINE:"TAKE_OFFLINE",PUBLISH_PAGE:"PUBLISH_PAGE",PUBLISH_CHANGES:"PUBLISH_CHANGES",ADD_NEW_LANGUAGE:"ADD_NEW_LANGUAGE",EDIT_LANGUAGE:"EDIT_LANGUAGE",DELETE_LANGUAGE:"DELETE_LANGUAGE",GET_CHANGES:"GET_CHANGES",GET_SERVER_BLOCK:"GET_SERVER_BLOCK",GET_LANGUAGE_PAGES:"GET_LANGUAGE_PAGES",GET_PROJECT_PAGES:"GET_PROJECT_PAGES",GET_WEBSITE_PAGES:"GET_WEBSITE_PAGES",UPDATE_WEBSITE_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",GET_ASSET:"GET_ASSET"},z="chaibuilder";let Sa=0;function zs(e,s){const n=`atom${++Sa}`,a={toString(){return n}};return typeof e=="function"?a.read=e:(a.init=e,a.read=wa,a.write=Na),s&&(a.write=s),a}function wa(e){return e(this)}function Na(e,s,n){return s(this,typeof n=="function"?n(e(this)):n)}const Aa=Symbol(""),Ca=e=>typeof(e==null?void 0:e.then)=="function";function Ta(e=()=>{try{return window.localStorage}catch{return}},s){var n;let a,r;const i={getItem:(u,d)=>{var m,f;const v=p=>{if(p=p||"",a!==p){try{r=JSON.parse(p,s==null?void 0:s.reviver)}catch{return d}a=p}return r},y=(f=(m=e())==null?void 0:m.getItem(u))!=null?f:null;return Ca(y)?y.then(v):v(y)},setItem:(u,d)=>{var m;return(m=e())==null?void 0:m.setItem(u,JSON.stringify(d,void 0))},removeItem:u=>{var d;return(d=e())==null?void 0:d.removeItem(u)}},l=u=>(d,m,f)=>u(d,v=>{let y;try{y=JSON.parse(v||"")}catch{y=f}m(y)});let o;try{o=(n=e())==null?void 0:n.subscribe}catch{}return!o&&typeof window<"u"&&typeof window.addEventListener=="function"&&window.Storage&&(o=(u,d)=>{if(!(e()instanceof window.Storage))return()=>{};const m=f=>{f.storageArea===e()&&f.key===u&&d(f.newValue)};return window.addEventListener("storage",m),()=>{window.removeEventListener("storage",m)}}),o&&(i.subscribe=l(o)),i}const Pa=Ta();function Ia(e,s,n=Pa,a){const r=zs(s);return r.onMount=l=>{l(n.getItem(e,s));let o;return n.subscribe&&(o=n.subscribe(e,l,s)),o},zs(l=>l(r),(l,o,u)=>{const d=typeof u=="function"?u(l(r)):u;return d===Aa?(o(r,s),n.removeItem(e)):d instanceof Promise?d.then(m=>(o(r,m),n.setItem(e,m))):(o(r,d),n.setItem(e,d))})}localStorage.removeItem("_chai_user");localStorage.removeItem("__chai__user");const on="__logged_in_user",_a=Ia(on,null),Re=()=>{const[e,s]=Oe.useAtom(_a),n=g.useCallback(()=>{s(null),localStorage.removeItem(on)},[s]);return{isLoggedIn:!!e,user:e,setUser:s,logout:n}},cn=async(e,s,n={})=>await fetch(e,{method:"POST",headers:{"Content-Type":"application/json",...n},body:JSON.stringify(s)}),$=()=>{const{user:e,logout:s}=Re(),n=L.useQueryClient(),a=e==null?void 0:e.accessToken;return g.useCallback(async(r,i,l={})=>{if(!a)return null;try{const o=x.get(i,"action","").toLowerCase(),u=await cn(r+(o?`?action=${o}`:""),i,{...l,Authorization:`Bearer ${a}`});if(u.status===401)return console.log("401 Response",u),n.invalidateQueries({queryKey:[z]}),s(),null;if(!u.ok){const d=await u.json();throw console.error(`API Error (${u.status}):`,d),{status:u.status,statusText:u.statusText,...d,message:d.error||d.message||`Server error: ${u.status}`}}return await u.json()}catch(o){throw console.error("API request failed:",i,o),o}},[a,s,n])},un=()=>{const e=ne(),s=L.useQueryClient(),n=$();return L.useMutation({mutationFn:async a=>n(e,{action:P.RELEASE_LOCK,data:a}),onSuccess:()=>{s.invalidateQueries({queryKey:[z,P.GET_DRAFT_PAGE]})}})},dn=()=>{const e=ne(),s=L.useQueryClient(),n=$();return L.useMutation({mutationFn:async a=>n(e,{action:P.UPDATE_WEBSITE_SETTINGS,data:a}),onSuccess:(a,r)=>{var i;s.invalidateQueries({queryKey:[z,P.GET_WEBSITE_DRAFT_SETTINGS]}),(i=r==null?void 0:r.settings)!=null&&i.theme||Y.toast.success("Website settings updated successfully.")},onError:a=>{Y.toast.error("Failed to update website settings",{description:a.message})}})},ka=()=>{const e=ne(),s=L.useQueryClient(),n=$();return L.useMutation({mutationFn:async a=>n(e,{action:P.UPDATE_WEBSITE_DATA,data:a}),onSuccess:()=>{s.invalidateQueries({queryKey:[z,P.GET_WEBSITE_DATA]}),Y.toast.success("Website data updated successfully.")},onError:a=>{Y.toast.error("Failed to update website data",{description:a.message})}})};function Pe(){const[e,s]=g.useState(new URLSearchParams(window.location.search));return g.useEffect(()=>{const n=()=>{s(new URLSearchParams(window.location.search))};return window.addEventListener("popstate",n),()=>{window.removeEventListener("popstate",n)}},[]),[e,s]}const Da=Oe.atom({}),mn=()=>Oe.useAtom(Da),La=()=>{const[e]=Pe(),s=e.get("page"),n=g.useRef(""),{mutate:a}=un();g.useEffect(()=>{!x.isEmpty(n.current)&&s!==n.current&&a({id:n.current}),n.current=s},[s,a,n])},Fe=(e,s)=>{const[n]=mn();return g.useMemo(()=>x.get(n,e,s),[n,e,s])},ne=()=>Fe("apiUrl","/chai/api"),Ns=()=>Fe("usersApiUrl","/chai/users"),zt=()=>Fe("assetsApiUrl","/chai/assets"),Xe=()=>{const e=ne(),[s]=Pe(),n=s.get("page"),a=$();return L.useQuery({queryKey:[z,P.GET_LANGUAGE_PAGES,n],initialData:[],queryFn:async()=>{if(!n)return null;const r=await a(e,{action:P.GET_LANGUAGE_PAGES,data:{id:n}});return x.reverse(x.sortBy(r,"primaryPage"))},enabled:!!n})},Ve=()=>{const e=ne(),s=$();return L.useQuery({queryKey:[z,P.GET_WEBSITE_DRAFT_SETTINGS],initialData:{theme:{},fallbackLang:"en",languages:[]},queryFn:async()=>s(e,{action:P.GET_WEBSITE_DRAFT_SETTINGS,data:{draft:!0}})})},hn=e=>{const{fallbackLang:s}=ee.useLanguages(),{data:n}=Ve(),{data:a,isFetching:r}=Xe(),i=g.useMemo(()=>{const l={[s]:!0};return x.each(x.get(n,"languages"),o=>{const u=x.find(a,{lang:o});l[o]=!!u}),l},[s,a,n]);return r||x.isEmpty(e)||e&&i[e]},As=()=>{const e=L.useQueryClient(),{data:s}=L.useQuery({queryKey:[z,P.AI_CONTEXT],initialData:"",queryFn:()=>"",staleTime:0});return{setAiContext:g.useCallback(a=>{e.setQueryData([z,P.AI_CONTEXT],a)},[e]),aiContext:s}},Ht=()=>{const e=$(),s=ne();return L.useQuery({queryKey:[z,P.GET_WEBSITE_PAGES],staleTime:1e3*60*5,queryFn:async()=>e(s,{action:P.GET_WEBSITE_PAGES})||[],placeholderData:n=>n})},Ba=Oe.atom({lastSaved:void 0}),Cs=()=>Oe.useAtom(Ba),Ie=()=>{const[e]=Pe(),s=e.get("page"),[n]=gn(),{data:a,isFetching:r}=Ht();return{data:g.useMemo(()=>({...x.find(a,{id:s})||{},metadata:n}),[a,s,n]),isFetching:r}},fn=()=>{const[e]=Pe(),s=e.get("lang")??"",{data:n,isFetching:a}=Xe();return{data:g.useMemo(()=>x.find(n,{lang:s})||{},[n,s]),isFetching:a}},Ga=Oe.atom({}),gn=()=>Oe.useAtom(Ga),Ze=e=>{const s=Ns(),n=$();return L.useQuery({queryKey:[z,"chaiUserInfo",e],queryFn:async()=>await n(s,{action:P.GET_CHAI_USER,data:{userId:e}}),enabled:!x.isEmpty(e)})},Ma=Oe.atom(void 0),$t=()=>{const[e]=Pe(),s=e.get("page"),{user:n}=Re(),[a,r]=Oe.useAtom(Ma);return g.useMemo(()=>({isLocked:s&&(n==null?void 0:n.id)!==a,currentEditor:a,setCurrentEditor:i=>r(i)}),[n==null?void 0:n.id,a,s,r])},Ts=()=>{const{data:e}=Ve();return g.useMemo(()=>(e==null?void 0:e.fallbackLang)||"en",[e])},xn=()=>{const[e]=Pe(),s=e.get("page"),n=ne(),{setAiContext:a}=As(),{setCurrentEditor:r}=$t(),[,i]=Cs(),[,l]=gn(),o=$();return L.useQuery({queryKey:[z,P.GET_DRAFT_PAGE,s],staleTime:1/0,gcTime:1/0,queryFn:async()=>{r("");const u=await o(n,{action:P.GET_DRAFT_PAGE,data:{id:s,draft:!0}});r(u.currentEditor);const d=u.blocks??[],m=x.find(d,{_type:"@chai/ai-context"});return a(x.get(m,"_value","")||""),i(f=>({...f,lastSaved:u.lastSaved})),l(x.get(u,"metadata",{})),d},enabled:!!s})},pn=()=>{const{data:e}=Ie(),s=ne(),n=$(),a=Ts();return L.useQuery({queryKey:[z,P.GET_BUILDER_PAGE_DATA,e==null?void 0:e.pageType,(e==null?void 0:e.lang)||a,e==null?void 0:e.dynamic,e==null?void 0:e.slug],initialData:{},queryFn:async()=>n(s,{action:P.GET_BUILDER_PAGE_DATA,data:{pageType:e==null?void 0:e.pageType,lang:(e==null?void 0:e.lang)||a,dynamic:e==null?void 0:e.dynamic,pageProps:{slug:e==null?void 0:e.slug,searchParams:{}}}}),enabled:!!(e!=null&&e.pageType)})};function Ua({avatar:e,name:s,email:n,onTakeOver:a}){const[r,i]=g.useState(!1),l=()=>{i(!1),a()};return t.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:t.jsxs(c.Card,{className:"w-full max-w-md mx-auto",children:[t.jsx(c.CardHeader,{className:"space-y-1",children:t.jsxs(c.CardTitle,{className:"flex items-center gap-2 text-2xl",children:[t.jsx(N.LockIcon,{className:"w-6 h-6 text-yellow-500"}),"Page locked for editing"]})}),t.jsx(c.CardContent,{className:"grid gap-4",children:t.jsxs("div",{children:[t.jsxs("div",{className:"flex items-center space-x-4",children:[e?t.jsx("img",{src:e,alt:s,className:"w-12 h-12 border border-gray-300 rounded-full"}):t.jsx(N.UserIcon,{className:"w-12 h-12 p-2 border border-gray-300 rounded-full"}),t.jsxs("div",{className:"space-y-1",children:[t.jsx("h3",{className:"font-semibold",children:s}),n&&t.jsx("p",{className:"text-sm text-muted-foreground",children:n})]})]}),t.jsx("div",{className:"text-sm mt-4",children:t.jsx("p",{children:"This user is currently editing the page. You cannot make changes."})})]})}),t.jsx(c.CardFooter,{children:t.jsxs(c.AlertDialog,{open:r,onOpenChange:i,children:[t.jsx(c.AlertDialogTrigger,{asChild:!0,children:t.jsxs("span",{className:"flex flex-col items-center",children:[t.jsx(c.Button,{className:"w-full",variant:"destructive",children:"Take Over"}),t.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."})]})}),t.jsxs(c.AlertDialogContent,{className:"z-[99]",children:[t.jsxs(c.AlertDialogHeader,{children:[t.jsx(c.AlertDialogTitle,{children:"Are you sure you want to take over?"}),t.jsxs(c.AlertDialogDescription,{children:[t.jsxs("span",{className:"flex items-center space-x-2 text-yellow-500",children:[t.jsx(N.AlertTriangleIcon,{className:"w-5 h-5"}),t.jsx("span",{children:"This action might cause the other user to lose unsaved changes."})]}),t.jsx("br",{}),t.jsxs("span",{className:"mt-2",children:["By taking over, you will become the active editor of this page, and ",s," will lose their editing access."]})]})]}),t.jsxs(c.AlertDialogFooter,{children:[t.jsx(c.AlertDialogCancel,{children:"Cancel"}),t.jsx(c.AlertDialogAction,{onClick:l,children:"Yes, Take Over"})]})]})]})})]})})}const Oa=()=>{const{isLocked:e,currentEditor:s}=$t(),{data:n}=Ze(s),[a]=Pe(),r=a.get("page"),{mutate:i}=un(),{isFetching:l}=xn(),o=g.useCallback(()=>{i({id:r})},[r,i]);return!e||l?t.jsx("div",{className:""}):t.jsx(Ua,{...n,name:(n==null?void 0:n.name)||"Unknown User",email:(n==null?void 0:n.email)||"",onTakeOver:o})},Ra=()=>{const[e,s]=Pe(),n=e.get("lang"),a=hn(n),{setSelectedLang:r}=ee.useLanguages(),i=()=>{const o=new URLSearchParams(window.location.search);o.delete("lang");const u=o.toString(),d=`${window.location.pathname}${u?`?${u}`:""}`;window.history.pushState({},"",d),s(o),r(""),window.dispatchEvent(new PopStateEvent("popstate"))};if(a)return null;const l=x.get(Le,n);return t.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:t.jsxs(c.Card,{className:"w-full max-w-md mx-auto",children:[t.jsx(c.CardHeader,{className:"space-y-1",children:t.jsxs(c.CardTitle,{className:"flex items-center gap-2 text-2xl",children:[t.jsx(N.LockIcon,{className:"w-6 h-6 text-yellow-500"}),'Page missing for "',l,'" language.']})}),t.jsx(c.CardContent,{className:"grid gap-4",children:t.jsxs("div",{children:['Page is not available in the "',l,'" language. Either create the page in the "',l,'" language or switch to the base language.']})}),t.jsx(c.CardFooter,{children:t.jsx(c.Button,{onClick:i,className:"w-full",variant:"destructive",children:"Switch to default language"})})]})})},Fa=e=>{const s=ne(),n=$();return L.useMutation({mutationFn:async a=>n(s,{action:P.UPSERT_LIBRARY_ITEM,data:a}),onSuccess:a=>{e(a)},onError:a=>{console.error("Error saving block:",a),Y.toast.error("Failed to save block",{description:a instanceof Error?a.message:"Unknown error"})}})},qa=e=>{const s=ne(),n=$();return L.useQuery({queryKey:[z,"uiBlockDetails",e],enabled:!!e,queryFn:async()=>{if(!e)return null;try{return await n(s,{action:P.GET_LIBRARY_ITEM,data:{id:e}})}catch(a){throw console.error(a),new Error("The block could not be found on the server. It may have been deleted.")}},retry:!1})},za=e=>{const s=ne(),n=$();return L.useMutation({mutationFn:async a=>n(s,{action:P.DELETE_LIBRARY_ITEM,data:{id:a}}),onSuccess:()=>{e()},onError:a=>{console.error("Error deleting block:",a),Y.toast.error("Failed to delete block",{description:a instanceof Error?a.message:"Unknown error"})}})},Ha=({blockId:e,libBlockId:s,isOpen:n,onClose:a,blockName:r,trigger:i})=>{const[l,o]=g.useState(!1),u=ee.useUpdateBlocksPropsRealtime(),d=za(()=>{u([e],{_libBlockId:void 0}),Y.toast.success("Block deleted successfully"),o(!1),a()}),m=()=>{o(!0),d.mutate(s)},f=t.jsxs(c.Button,{type:"button",variant:"destructive",size:"sm",onClick:v=>v.preventDefault(),disabled:l,children:[t.jsx(N.Trash2,{className:"h-4 w-4 mr-2"}),"Delete"]});return t.jsxs(c.Popover,{open:n,onOpenChange:v=>!v&&a(),children:[t.jsx(c.PopoverTrigger,{asChild:!0,children:i||f}),t.jsx(c.PopoverContent,{className:"w-72 p-4 z-[9999]",sideOffset:5,align:"center",children:t.jsxs("div",{className:"space-y-3",children:[t.jsx("h4",{className:"font-medium",children:"Delete Block"}),t.jsxs("p",{className:"text-sm",children:["Are you sure you want to delete the block",t.jsxs("span",{className:"font-medium",children:[' "',r,'"']}),"?"]}),t.jsx("p",{className:"text-xs text-muted-foreground",children:"This block will be permanently removed from the library. This action cannot be undone."}),t.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[t.jsx(c.Button,{type:"button",variant:"outline",size:"sm",onClick:a,disabled:l,children:"Cancel"}),t.jsx(c.Button,{type:"button",variant:"destructive",size:"sm",onClick:m,disabled:l,children:l?"Deleting...":"Delete"})]})]})})]})},$a=({blockId:e,libBlockId:s,blockName:n,size:a="sm",className:r="",close:i})=>{const[l,o]=g.useState(!1);return t.jsx(Ha,{blockId:e,libBlockId:s,isOpen:l,onClose:()=>{o(!1),i()},blockName:n,trigger:t.jsxs(c.Button,{type:"button",variant:"destructive",size:a,className:r,onClick:()=>o(!0),children:[t.jsx(N.Trash2,{className:"h-4 w-4 mr-2"}),"Delete"]})})},Ka=()=>{const e=ne(),s=$(),n=L.useQueryClient(),{data:a=[],isLoading:r,error:i}=L.useQuery({queryKey:[z,"library-groups"],queryFn:async()=>{try{return await s(e,{action:"GET_LIBRARY_GROUPS"})||[]}catch(u){return console.error("Error fetching library groups:",u),[]}},initialData:[]}),{mutateAsync:l,isPending:o}=L.useMutation({mutationFn:async u=>{if(!u.trim())throw new Error("Group name is required");return s(e,{action:"CREATE_BLOCK_GROUP",data:{name:u}})},onSuccess:()=>{n.invalidateQueries({queryKey:[z,"library-groups"]}),Y.toast.success("Group created successfully")},onError:u=>{console.error("Error creating group:",u),Y.toast.error("Failed to create group",{description:u instanceof Error?u.message:"Unknown error"})}});return{groups:a,isLoading:r,error:i,createGroup:l,isCreating:o}},Va=({value:e,onChange:s})=>{const[n,a]=g.useState(!1),[r,i]=g.useState(""),l=g.useRef(null),{groups:o}=Ka(),[u,d]=g.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"}]),m=g.useMemo(()=>[...o,...u.filter(y=>!o.some(p=>p.id===y.id))],[o,u]),f=()=>{const y=r.trim();if(!y)return;const p={id:y,name:y};d(S=>[...S,p]),s(p.id),i(""),a(!1)};g.useEffect(()=>{n&&l.current&&l.current.focus()},[n]);const v=y=>{y.key==="Enter"&&(y.preventDefault(),f())};return g.useEffect(()=>{e&&!m.some(y=>y.id===e)&&s("")},[e,m,s]),n?t.jsxs("div",{className:"space-y-2",children:[t.jsx(c.Input,{ref:l,placeholder:"Enter new group name",value:r,onChange:y=>i(y.target.value),onKeyDown:v}),t.jsxs("div",{className:"flex justify-end gap-2",children:[t.jsx(c.Button,{variant:"outline",size:"sm",onClick:()=>a(!1),children:"Cancel"}),t.jsx(c.Button,{size:"sm",onClick:f,children:"Create"})]})]}):t.jsxs("div",{className:"flex gap-2",children:[t.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:y=>s(y.target.value),children:[t.jsx("option",{value:"",children:"Select a group"}),o.length>0&&t.jsx("optgroup",{label:"Library Groups",children:o.map(y=>t.jsx("option",{value:y.id,children:y.name},`lib-${y.id}`))}),u.length>0&&t.jsx("optgroup",{label:"Predefined Groups",children:u.filter(y=>!o.some(p=>p.id===y.id)).map(y=>t.jsx("option",{value:y.id,children:y.name},`local-${y.id}`))})]}),t.jsx(c.Button,{type:"button",size:"icon",variant:"outline",onClick:()=>a(!0),children:t.jsx(N.Plus,{className:"h-4 w-4"})})]})},Wa=10*1024*1024,Qa=({value:e,onChange:s})=>{const[n,a]=g.useState(!1),r=g.useRef(null),i=g.useCallback(u=>{var m;const d=(m=u.target.files)==null?void 0:m[0];if(d){if(d.size>Wa){Y.toast.error("File too large",{description:`Maximum file size is 10mb. Selected file is ${(d.size/1024/1024).toFixed(2)}MB.`}),r.current&&(r.current.value="");return}try{a(!0);const f=new FileReader;f.onloadend=()=>{s(f.result),a(!1)},f.readAsDataURL(d)}catch(f){console.error("Error reading file:",f),a(!1),Y.toast.error("Failed to process image",{description:f instanceof Error?f.message:"Unknown error"})}}},[s]),l=()=>{s(""),r.current&&(r.current.value="")},o=()=>{var u;(u=r.current)==null||u.click()};return t.jsxs("div",{className:"space-y-2",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(c.Input,{type:"file",ref:r,onChange:i,accept:"image/*",className:"hidden"}),t.jsx(c.Button,{type:"button",variant:"outline",onClick:o,disabled:n,className:"w-full",children:n?t.jsxs("span",{className:"flex items-center gap-2",children:[t.jsx("div",{className:"animate-spin h-4 w-4 border-2 border-current border-t-transparent rounded-full"}),"Uploading..."]}):t.jsxs("span",{className:"flex items-center gap-2",children:[t.jsx(N.ImageIcon,{className:"h-4 w-4"}),"Select image"]})}),e&&t.jsx(c.Button,{type:"button",variant:"outline",size:"icon",onClick:l,children:t.jsx(N.X,{className:"h-4 w-4"})})]}),e&&t.jsx("div",{className:"rounded-md max-h-[200px] h-[200px] overflow-hidden border aspect-video",children:t.jsx("img",{src:e,alt:"Preview",className:"w-full h-full object-contain"})})]})},fe={...ee.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"},Ya=e=>{const{blocks:s,close:n,blockId:a}=e,{getPartailBlocks:r}=ee.usePartailBlocksStore(),i=s.find(A=>A._id===a),l=i==null?void 0:i._libBlockId,o=!!l,u=g.useMemo(()=>s.some(A=>A._type==="PartialBlock"||A._type==="GlobalBlock"),[s]),d=g.useMemo(()=>{let A=[];for(const G of s)if(G._type==="PartialBlock"||G._type==="GlobalBlock"){let U=r(G.partialBlockId);G._parent&&(U==null?void 0:U.length)>0&&(U=U.map(T=>(x.isEmpty(T._parent)&&x.set(T,"_parent",G._parent),T))),A=[...A,...U]}else A.push(G);return A},[s,r]),[m,f]=g.useState(""),[v,y]=g.useState(""),[p,S]=g.useState(""),[E,_]=g.useState(""),[w,k]=g.useState({}),[b,B]=g.useState(!1),[F,te]=g.useState(o),[R,K]=g.useState(!1),{hasPermission:M}=ee.usePermissions(),X=M(fe.DELETE_LIBRARY_BLOCK),O=ee.useUpdateBlocksPropsRealtime(),je=()=>{O([a],{_libBlockId:void 0}),Y.toast.success("Block delinked from library"),n()},{data:V,isLoading:I,isError:ae}=qa(l);g.useEffect(()=>{ae&&o&&(K(!0),te(!1))},[ae,o]),g.useEffect(()=>{V&&!I&&(f(V.name||""),y(V.group||""),S(V.description||""),_(V.preview||""),te(!1))},[V,I]),g.useEffect(()=>{const A=m.trim().length>=2,G=v.trim()!=="";B(A&&G)},[m,v]);const be=()=>{const A={};return m.trim()?m.length<2&&(A.name="Name must be at least 2 characters"):A.name="Name is required",v||(A.group="Group is required"),k(A),Object.keys(A).length===0},{resetLibrary:we}=ee.useLibraryBlocks({id:""}),Be=Fa(A=>{o||O([a],{_libBlockId:A.id}),Y.toast.success(`Block ${o?"updated":"saved"} successfully`),we(A.library),n()}),j=async A=>{if(A.preventDefault(),!be())return;const G=d.map(U=>(x.has(U,"_libBlockId")&&delete U._libBlockId,U));Be.mutate({name:m.trim(),group:v,blocks:G,description:p.trim(),...E&&E.startsWith("data:")?{previewImage:E}:{},...o?{id:l}:{}})},h=Be.isPending;return F||I?t.jsx("div",{className:"flex items-center justify-center p-8",children:t.jsx("div",{className:"h-8 w-8 animate-spin rounded-full border-4 border-primary border-t-transparent"})}):R?t.jsxs("div",{className:"p-6 space-y-4",children:[t.jsx("div",{className:"text-destructive font-medium",children:"Block Not Found"}),t.jsx("p",{className:"text-sm text-muted-foreground",children:"This block could not be found on the server. It may have been deleted."}),t.jsxs("div",{className:"flex justify-end gap-2 pt-4",children:[t.jsx(c.Button,{type:"button",variant:"outline",onClick:n,children:"Cancel"}),t.jsx(c.Button,{onClick:je,variant:"destructive",children:"Delink Block"})]})]}):t.jsxs("div",{children:[u&&t.jsxs("div",{className:"mb-4 p-3 border border-destructive/50 bg-destructive/10 text-destructive rounded-md flex items-start gap-2",children:[t.jsx(N.AlertCircle,{className:"h-5 w-5 flex-shrink-0 mt-0.5"}),t.jsxs("div",{children:[t.jsx("p",{className:"font-medium",children:"Partial Blocks Detected"}),t.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"})]})]}),t.jsxs("form",{onSubmit:j,className:"space-y-4",children:[t.jsxs("div",{className:"space-y-2",children:[t.jsx(c.Label,{htmlFor:"name",className:w.name?"text-destructive":"",children:"Name"}),t.jsx(c.Input,{id:"name",placeholder:"Enter block name",value:m,onChange:A=>f(A.target.value),className:w.name?"border-destructive":""}),w.name&&t.jsx("p",{className:"text-xs text-destructive",children:w.name})]}),t.jsxs("div",{className:"space-y-2",children:[t.jsx(c.Label,{htmlFor:"group",className:w.group?"text-destructive":"",children:"Group"}),t.jsx(Va,{value:v,onChange:y}),w.group&&t.jsx("p",{className:"text-xs text-destructive",children:w.group})]}),t.jsxs("div",{className:"space-y-2",children:[t.jsx(c.Label,{htmlFor:"description",children:"Description (optional)"}),t.jsx(c.Input,{id:"description",placeholder:"Enter a brief description",className:"resize-none",value:p,onChange:A=>S(A.target.value)})]}),t.jsxs("div",{className:"space-y-2",children:[t.jsx(c.Label,{htmlFor:"previewImage",children:"Preview Image (optional)"}),t.jsx(Qa,{value:E,onChange:_})]}),t.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[o&&X&&t.jsx($a,{blockId:a,libBlockId:l,blockName:m,className:"mr-auto",close:n}),t.jsx(c.Button,{type:"button",variant:"outline",onClick:n,disabled:h,children:"Cancel"}),t.jsx(c.Button,{type:"submit",disabled:h||!b,children:h?"Saving...":o?"Update Block":"Save Block"})]})]})]})},Q={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."},Xa={SLUG_ALREADY_USED:"This slug is already in use. Please choose a different one."},Ce=()=>{const e=ne(),s=$();return L.useQuery({queryKey:[z,P.GET_PAGE_TYPES],initialData:[],queryFn:async()=>s(e,{action:P.GET_PAGE_TYPES})})},Za=e=>{const{data:s}=Ce();return g.useMemo(()=>s==null?void 0:s.find(n=>n.key===e),[s,e])},Ja=()=>{const e=ne(),s=$();return L.useMutation({mutationFn:async({pageType:n,query:a})=>{try{return s(e,{action:P.SEARCH_PAGES,data:{pageType:n,query:Array.isArray(a)&&a.length>0?a[0]:a}})||[]}catch(r){return console.error(r),[]}}})},yn=()=>{const e=ne(),s=L.useQueryClient(),n=$(),{data:a}=Ce();return L.useMutation({mutationFn:async r=>await n(e,{action:P.CREATE_PAGE,data:r}),onSuccess:(r,i)=>{var o;i&&(i!=null&&i.primaryPage)?s.invalidateQueries({queryKey:[z,P.GET_LANGUAGE_PAGES,i==null?void 0:i.primaryPage]}):s.invalidateQueries({queryKey:[z,P.GET_WEBSITE_PAGES]});const l=i.template?`Page created from "${i.template.name}" template`:i.hasSlug===!1?"New "+((o=x.find(a,{key:i.pageType}))==null?void 0:o.name)+" added successfully":"New page added successfully";Y.toast.success(l)},onError:(r,i)=>{const l=x.find(a,{key:i.pageType});Y.toast.error(`Failed to add new ${l!=null&&l.hasSlug?"page":l.name}.`,{description:x.get(Xa,r.message,r.message)})}})},Ps=()=>{const e=ne(),s=L.useQueryClient(),n=$(),{data:a}=Ce();return L.useMutation({mutationFn:async r=>await n(e,{action:P.UPDATE_PAGE,data:r}),onSuccess:(r,i)=>{i&&(i!=null&&i.primaryPage||i!=null&&i.seo)?s.invalidateQueries({queryKey:[z,P.GET_LANGUAGE_PAGES,i==null?void 0:i.primaryPage]}):s.invalidateQueries({queryKey:[z,P.GET_WEBSITE_PAGES]})},onError:(r,i)=>{const l=x.find(a,{key:i.pageType});Y.toast.error(`Failed to update ${l!=null&&l.hasSlug?"page":l.name}.`,{description:r.message})}})},er=()=>{const e=ne(),s=L.useQueryClient(),n=$(),{data:a}=Ce();return L.useMutation({mutationFn:async r=>n(e,{action:P.DELETE_PAGE,data:{id:r==null?void 0:r.id}}),onSuccess:(r,i)=>{if(r.code==="PAGE_LOCKED"){Y.toast.error("Delete not allowed",{description:"Page is currently being edited by another user."});return}i&&(i!=null&&i.primaryPage)?s.invalidateQueries({queryKey:[z,P.GET_LANGUAGE_PAGES,i==null?void 0:i.primaryPage]}):s.invalidateQueries({queryKey:[z,P.GET_WEBSITE_PAGES]})},onError:(r,i)=>{const l=x.find(a,{key:i.pageType});Y.toast.error(`Failed to delete ${l!=null&&l.hasSlug?"page":l.name}.`,{description:r.message})}})},tr=()=>{const e=ne(),s=L.useQueryClient(),n=$(),{data:a}=Ce();return L.useMutation({mutationFn:async r=>n(e,{action:P.TAKE_OFFLINE,data:{id:r==null?void 0:r.id}}),onSuccess:(r,i)=>{i&&(i!=null&&i.primaryPage)?s.invalidateQueries({queryKey:[z,P.GET_LANGUAGE_PAGES,i==null?void 0:i.primaryPage]}):s.invalidateQueries({queryKey:[z,P.GET_WEBSITE_PAGES]});const l=x.find(a,{key:i.pageType});Y.toast.success(l!=null&&l.hasSlug?Q.PAGE_UNPUBLISH_SUCCESS:"New "+l.name+" added successfully.")},onError:(r,i)=>{const l=x.find(a,{key:i.pageType});Y.toast.error(`Failed to take offline ${l!=null&&l.hasSlug?"page":l.name}.`,{description:r.message})}})},Is=()=>{const e=ne(),s=$(),n=L.useQueryClient(),{data:a}=Ie();return L.useMutation({mutationFn:async({ids:r})=>s(e,{action:P.PUBLISH_CHANGES,data:{ids:r}}),onSuccess:()=>{n.invalidateQueries({queryKey:[z,P.GET_CHANGES]}),n.invalidateQueries({queryKey:[z,P.GET_WEBSITE_PAGES]}),n.invalidateQueries({queryKey:[z,P.GET_LANGUAGE_PAGES,a==null?void 0:a.id]})},onError:()=>{Y.toast.error("Failed to publish pages.")}})},sr=()=>{const e=ne(),s=$(),n=L.useQueryClient();return L.useMutation({mutationFn:async a=>{var r;return s(e,{action:P.MARK_AS_TEMPLATE,data:{id:(r=a.page)==null?void 0:r.id,name:a.name,description:a.description,pageType:a.pageType,previewImage:a.previewImage}})},onSuccess:()=>{n.invalidateQueries({queryKey:[z,P.GET_WEBSITE_PAGES]}),Y.toast.success("Page marked as template successfully.")},onError:()=>{Y.toast.error("Failed to mark page as template.")}})},nr=()=>{const e=ne(),s=$(),n=L.useQueryClient();return L.useMutation({mutationFn:async a=>s(e,{action:P.UNMARK_AS_TEMPLATE,data:{id:a==null?void 0:a.id}}),onSuccess:()=>{n.invalidateQueries({queryKey:[z,P.GET_WEBSITE_PAGES]}),Y.toast.success("Page unmarked as template successfully.")},onError:()=>{Y.toast.error("Failed to unmark page as template.")}})},ar=()=>{const e=ne(),s=$(),n=L.useQueryClient();return L.useMutation({mutationFn:async({id:a,slug:r})=>s(e,{action:P.CHANGE_SLUG,data:{id:a,slug:r}}),onSuccess:(a,{primaryPage:r})=>{Y.toast.success(Q.SLUG_CHANGE_SUCCESS),r?n.invalidateQueries({queryKey:[z,P.GET_LANGUAGE_PAGES,r]}):n.invalidateQueries({queryKey:[z,P.GET_WEBSITE_PAGES]})},onError:()=>{Y.toast.error("Failed to change slug")}})};var _s={};(function e(s,n,a,r){var i=!!(s.Worker&&s.Blob&&s.Promise&&s.OffscreenCanvas&&s.OffscreenCanvasRenderingContext2D&&s.HTMLCanvasElement&&s.HTMLCanvasElement.prototype.transferControlToOffscreen&&s.URL&&s.URL.createObjectURL),l=typeof Path2D=="function"&&typeof DOMMatrix=="function",o=function(){if(!s.OffscreenCanvas)return!1;var j=new OffscreenCanvas(1,1),h=j.getContext("2d");h.fillRect(0,0,1,1);var A=j.transferToImageBitmap();try{h.createPattern(A,"no-repeat")}catch{return!1}return!0}();function u(){}function d(j){var h=n.exports.Promise,A=h!==void 0?h:s.Promise;return typeof A=="function"?new A(j):(j(u,u),null)}var m=function(j,h){return{transform:function(A){if(j)return A;if(h.has(A))return h.get(A);var G=new OffscreenCanvas(A.width,A.height),U=G.getContext("2d");return U.drawImage(A,0,0),h.set(A,G),G},clear:function(){h.clear()}}}(o,new Map),f=function(){var j=Math.floor(16.666666666666668),h,A,G={},U=0;return typeof requestAnimationFrame=="function"&&typeof cancelAnimationFrame=="function"?(h=function(T){var Z=Math.random();return G[Z]=requestAnimationFrame(function q(J){U===J||U+j-1<J?(U=J,delete G[Z],T()):G[Z]=requestAnimationFrame(q)}),Z},A=function(T){G[T]&&cancelAnimationFrame(G[T])}):(h=function(T){return setTimeout(T,j)},A=function(T){return clearTimeout(T)}),{frame:h,cancel:A}}(),v=function(){var j,h,A={};function G(U){function T(Z,q){U.postMessage({options:Z||{},callback:q})}U.init=function(q){var J=q.transferControlToOffscreen();U.postMessage({canvas:J},[J])},U.fire=function(q,J,le){if(h)return T(q,null),h;var ge=Math.random().toString(36).slice(2);return h=d(function(ce){function xe(ve){ve.data.callback===ge&&(delete A[ge],U.removeEventListener("message",xe),h=null,m.clear(),le(),ce())}U.addEventListener("message",xe),T(q,ge),A[ge]=xe.bind(null,{data:{callback:ge}})}),h},U.reset=function(){U.postMessage({reset:!0});for(var q in A)A[q](),delete A[q]}}return function(){if(j)return j;if(!a&&i){var U=["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{j=new Worker(URL.createObjectURL(new Blob([U])))}catch(T){return typeof console!==void 0&&typeof console.warn=="function"&&console.warn("🎊 Could not load worker",T),null}G(j)}return j}}(),y={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 p(j,h){return h?h(j):j}function S(j){return j!=null}function E(j,h,A){return p(j&&S(j[h])?j[h]:y[h],A)}function _(j){return j<0?0:Math.floor(j)}function w(j,h){return Math.floor(Math.random()*(h-j))+j}function k(j){return parseInt(j,16)}function b(j){return j.map(B)}function B(j){var h=String(j).replace(/[^0-9a-f]/gi,"");return h.length<6&&(h=h[0]+h[0]+h[1]+h[1]+h[2]+h[2]),{r:k(h.substring(0,2)),g:k(h.substring(2,4)),b:k(h.substring(4,6))}}function F(j){var h=E(j,"origin",Object);return h.x=E(h,"x",Number),h.y=E(h,"y",Number),h}function te(j){j.width=document.documentElement.clientWidth,j.height=document.documentElement.clientHeight}function R(j){var h=j.getBoundingClientRect();j.width=h.width,j.height=h.height}function K(j){var h=document.createElement("canvas");return h.style.position="fixed",h.style.top="0px",h.style.left="0px",h.style.pointerEvents="none",h.style.zIndex=j,h}function M(j,h,A,G,U,T,Z,q,J){j.save(),j.translate(h,A),j.rotate(T),j.scale(G,U),j.arc(0,0,1,Z,q,J),j.restore()}function X(j){var h=j.angle*(Math.PI/180),A=j.spread*(Math.PI/180);return{x:j.x,y:j.y,wobble:Math.random()*10,wobbleSpeed:Math.min(.11,Math.random()*.1+.05),velocity:j.startVelocity*.5+Math.random()*j.startVelocity,angle2D:-h+(.5*A-Math.random()*A),tiltAngle:(Math.random()*(.75-.25)+.25)*Math.PI,color:j.color,shape:j.shape,tick:0,totalTicks:j.ticks,decay:j.decay,drift:j.drift,random:Math.random()+2,tiltSin:0,tiltCos:0,wobbleX:0,wobbleY:0,gravity:j.gravity*3,ovalScalar:.6,scalar:j.scalar,flat:j.flat}}function O(j,h){h.x+=Math.cos(h.angle2D)*h.velocity+h.drift,h.y+=Math.sin(h.angle2D)*h.velocity+h.gravity,h.velocity*=h.decay,h.flat?(h.wobble=0,h.wobbleX=h.x+10*h.scalar,h.wobbleY=h.y+10*h.scalar,h.tiltSin=0,h.tiltCos=0,h.random=1):(h.wobble+=h.wobbleSpeed,h.wobbleX=h.x+10*h.scalar*Math.cos(h.wobble),h.wobbleY=h.y+10*h.scalar*Math.sin(h.wobble),h.tiltAngle+=.1,h.tiltSin=Math.sin(h.tiltAngle),h.tiltCos=Math.cos(h.tiltAngle),h.random=Math.random()+2);var A=h.tick++/h.totalTicks,G=h.x+h.random*h.tiltCos,U=h.y+h.random*h.tiltSin,T=h.wobbleX+h.random*h.tiltCos,Z=h.wobbleY+h.random*h.tiltSin;if(j.fillStyle="rgba("+h.color.r+", "+h.color.g+", "+h.color.b+", "+(1-A)+")",j.beginPath(),l&&h.shape.type==="path"&&typeof h.shape.path=="string"&&Array.isArray(h.shape.matrix))j.fill(be(h.shape.path,h.shape.matrix,h.x,h.y,Math.abs(T-G)*.1,Math.abs(Z-U)*.1,Math.PI/10*h.wobble));else if(h.shape.type==="bitmap"){var q=Math.PI/10*h.wobble,J=Math.abs(T-G)*.1,le=Math.abs(Z-U)*.1,ge=h.shape.bitmap.width*h.scalar,ce=h.shape.bitmap.height*h.scalar,xe=new DOMMatrix([Math.cos(q)*J,Math.sin(q)*J,-Math.sin(q)*le,Math.cos(q)*le,h.x,h.y]);xe.multiplySelf(new DOMMatrix(h.shape.matrix));var ve=j.createPattern(m.transform(h.shape.bitmap),"no-repeat");ve.setTransform(xe),j.globalAlpha=1-A,j.fillStyle=ve,j.fillRect(h.x-ge/2,h.y-ce/2,ge,ce),j.globalAlpha=1}else if(h.shape==="circle")j.ellipse?j.ellipse(h.x,h.y,Math.abs(T-G)*h.ovalScalar,Math.abs(Z-U)*h.ovalScalar,Math.PI/10*h.wobble,0,2*Math.PI):M(j,h.x,h.y,Math.abs(T-G)*h.ovalScalar,Math.abs(Z-U)*h.ovalScalar,Math.PI/10*h.wobble,0,2*Math.PI);else if(h.shape==="star")for(var se=Math.PI/2*3,Ee=4*h.scalar,Ne=8*h.scalar,D=h.x,re=h.y,C=5,he=Math.PI/C;C--;)D=h.x+Math.cos(se)*Ne,re=h.y+Math.sin(se)*Ne,j.lineTo(D,re),se+=he,D=h.x+Math.cos(se)*Ee,re=h.y+Math.sin(se)*Ee,j.lineTo(D,re),se+=he;else j.moveTo(Math.floor(h.x),Math.floor(h.y)),j.lineTo(Math.floor(h.wobbleX),Math.floor(U)),j.lineTo(Math.floor(T),Math.floor(Z)),j.lineTo(Math.floor(G),Math.floor(h.wobbleY));return j.closePath(),j.fill(),h.tick<h.totalTicks}function je(j,h,A,G,U){var T=h.slice(),Z=j.getContext("2d"),q,J,le=d(function(ge){function ce(){q=J=null,Z.clearRect(0,0,G.width,G.height),m.clear(),U(),ge()}function xe(){a&&!(G.width===r.width&&G.height===r.height)&&(G.width=j.width=r.width,G.height=j.height=r.height),!G.width&&!G.height&&(A(j),G.width=j.width,G.height=j.height),Z.clearRect(0,0,G.width,G.height),T=T.filter(function(ve){return O(Z,ve)}),T.length?q=f.frame(xe):ce()}q=f.frame(xe),J=ce});return{addFettis:function(ge){return T=T.concat(ge),le},canvas:j,promise:le,reset:function(){q&&f.cancel(q),J&&J()}}}function V(j,h){var A=!j,G=!!E(h||{},"resize"),U=!1,T=E(h,"disableForReducedMotion",Boolean),Z=i&&!!E(h||{},"useWorker"),q=Z?v():null,J=A?te:R,le=j&&q?!!j.__confetti_initialized:!1,ge=typeof matchMedia=="function"&&matchMedia("(prefers-reduced-motion)").matches,ce;function xe(se,Ee,Ne){for(var D=E(se,"particleCount",_),re=E(se,"angle",Number),C=E(se,"spread",Number),he=E(se,"startVelocity",Number),De=E(se,"decay",Number),_e=E(se,"gravity",Number),et=E(se,"drift",Number),tt=E(se,"colors",b),Kt=E(se,"ticks",Number),Us=E(se,"shapes"),xa=E(se,"scalar"),pa=!!E(se,"flat"),Os=F(se),Rs=D,us=[],ya=j.width*Os.x,va=j.height*Os.y;Rs--;)us.push(X({x:ya,y:va,angle:re,spread:C,startVelocity:he,color:tt[Rs%tt.length],shape:Us[w(0,Us.length)],ticks:Kt,decay:De,gravity:_e,drift:et,scalar:xa,flat:pa}));return ce?ce.addFettis(us):(ce=je(j,us,J,Ee,Ne),ce.promise)}function ve(se){var Ee=T||E(se,"disableForReducedMotion",Boolean),Ne=E(se,"zIndex",Number);if(Ee&&ge)return d(function(he){he()});A&&ce?j=ce.canvas:A&&!j&&(j=K(Ne),document.body.appendChild(j)),G&&!le&&J(j);var D={width:j.width,height:j.height};q&&!le&&q.init(j),le=!0,q&&(j.__confetti_initialized=!0);function re(){if(q){var he={getBoundingClientRect:function(){if(!A)return j.getBoundingClientRect()}};J(he),q.postMessage({resize:{width:he.width,height:he.height}});return}D.width=D.height=null}function C(){ce=null,G&&(U=!1,s.removeEventListener("resize",re)),A&&j&&(document.body.contains(j)&&document.body.removeChild(j),j=null,le=!1)}return G&&!U&&(U=!0,s.addEventListener("resize",re,!1)),q?q.fire(se,D,C):xe(se,D,C)}return ve.reset=function(){q&&q.reset(),ce&&ce.reset()},ve}var I;function ae(){return I||(I=V(null,{useWorker:!0,resize:!0})),I}function be(j,h,A,G,U,T,Z){var q=new Path2D(j),J=new Path2D;J.addPath(q,new DOMMatrix(h));var le=new Path2D;return le.addPath(J,new DOMMatrix([Math.cos(Z)*U,Math.sin(Z)*U,-Math.sin(Z)*T,Math.cos(Z)*T,A,G])),le}function we(j){if(!l)throw new Error("path confetti are not supported in this browser");var h,A;typeof j=="string"?h=j:(h=j.path,A=j.matrix);var G=new Path2D(h),U=document.createElement("canvas"),T=U.getContext("2d");if(!A){for(var Z=1e3,q=Z,J=Z,le=0,ge=0,ce,xe,ve=0;ve<Z;ve+=2)for(var se=0;se<Z;se+=2)T.isPointInPath(G,ve,se,"nonzero")&&(q=Math.min(q,ve),J=Math.min(J,se),le=Math.max(le,ve),ge=Math.max(ge,se));ce=le-q,xe=ge-J;var Ee=10,Ne=Math.min(Ee/ce,Ee/xe);A=[Ne,0,0,Ne,-Math.round(ce/2+q)*Ne,-Math.round(xe/2+J)*Ne]}return{type:"path",path:h,matrix:A}}function Be(j){var h,A=1,G="#000000",U='"Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji", "EmojiOne Color", "Android Emoji", "Twemoji Mozilla", "system emoji", sans-serif';typeof j=="string"?h=j:(h=j.text,A="scalar"in j?j.scalar:A,U="fontFamily"in j?j.fontFamily:U,G="color"in j?j.color:G);var T=10*A,Z=""+T+"px "+U,q=new OffscreenCanvas(T,T),J=q.getContext("2d");J.font=Z;var le=J.measureText(h),ge=Math.ceil(le.actualBoundingBoxRight+le.actualBoundingBoxLeft),ce=Math.ceil(le.actualBoundingBoxAscent+le.actualBoundingBoxDescent),xe=2,ve=le.actualBoundingBoxLeft+xe,se=le.actualBoundingBoxAscent+xe;ge+=xe+xe,ce+=xe+xe,q=new OffscreenCanvas(ge,ce),J=q.getContext("2d"),J.font=Z,J.fillStyle=G,J.fillText(h,ve,se);var Ee=1/A;return{type:"bitmap",bitmap:q.transferToImageBitmap(),matrix:[Ee,0,0,Ee,-ge*Ee/2,-ce*Ee/2]}}n.exports=function(){return ae().apply(this,arguments)},n.exports.reset=function(){ae().reset()},n.exports.create=V,n.exports.shapeFromPath=we,n.exports.shapeFromText=Be})(function(){return typeof window<"u"?window:typeof self<"u"?self:this||{}}(),_s,!1);const rr=_s.exports;_s.exports.create;const ir={particleCount:350,spread:120,origin:{y:.6},angle:90},lr={TOP_RIGHT:{angle:225,origin:{x:.9,y:0}},BOTTOM_RIGHT:{angle:100,origin:{x:.9,y:.9}}},Zt=e=>{let s=lr[e];s||(s={});const n={...ir,...s};rr(n)},or=()=>{const[e]=ee.useTheme(),{mutate:s,isPending:n}=Is(),{mutateAsync:a,isPending:r}=dn(),i=()=>{a({settings:{theme:e}})},l=()=>{s({ids:["THEME"]},{onSuccess:()=>{Zt("BOTTOM_RIGHT")}})};return t.jsxs("div",{className:"bg-white py-3 flex items-center justify-center gap-x-3 border-t",children:[t.jsx(c.Button,{size:"sm",variant:"outline",disabled:n||r,onClick:i,children:"Save draft"}),t.jsx(c.Button,{size:"sm",disabled:n||r,onClick:l,children:"Publish"})]})},cr=({page:e,onClose:s})=>{const[n,a]=g.useState(e.slug||""),{mutate:r,isPending:i}=ar(),{data:l}=Ce(),o=x.find(l,{key:e==null?void 0:e.pageType}),u=m=>{if(m.preventDefault(),!(e!=null&&e.primaryPage)&&Object.keys(Le).some(y=>n===`/${y}`||x.startsWith(n,`/${y}/`))){Y.toast.error("Error",{description:"Slugs cannot start with a language code for primary page"});return}r({...e,slug:n},{onSuccess:s})},d=(e==null?void 0:e.lang)||"";return t.jsx(c.Dialog,{open:!!e,onOpenChange:s,children:t.jsxs(c.DialogContent,{children:[t.jsxs(c.DialogHeader,{children:[t.jsx(c.DialogTitle,{children:"Change Slug"}),t.jsx(c.DialogDescription,{className:"text-xs",children:t.jsxs(c.Alert,{variant:"destructive",className:"mt-2",children:[t.jsx(N.AlertCircle,{className:"h-4 w-4"}),"Changing the slug may have impact on your SEO. Please proceed with caution."]})})]}),t.jsxs("form",{onSubmit:u,children:[t.jsxs("div",{className:"space-y-4 py-4 text-sm ",children:[t.jsxs("div",{className:"space-y-1",children:[t.jsxs("div",{children:[t.jsx("span",{children:"Type:"}),t.jsxs("span",{className:"font-medium text-gray-600",children:[" ",(o==null?void 0:o.name)||(e==null?void 0:e.pageType)]})]}),t.jsxs("div",{children:[t.jsx("span",{children:"Name:"}),t.jsxs("span",{className:"font-medium text-gray-600",children:[" ",e.name]})]})]}),t.jsxs("div",{className:"space-y-1",children:[t.jsxs(c.Label,{htmlFor:"slug",className:"text-right",children:["Slug"," ",t.jsxs("small",{className:"font-light text-gray-500",children:["Slug should start with /",d]})]}),t.jsx(c.Input,{id:"slug",value:n,onChange:m=>{const f=m.target.value;x.startsWith(f,`/${d}`)&&a(f)},className:"col-span-3",required:!0,pattern:"^/.*",title:"Slug must start with /",placeholder:"Enter page slug"})]})]}),t.jsx(c.DialogFooter,{children:t.jsx(c.Button,{type:"submit",disabled:i||!x.startsWith(n,`/${d}`)||x.isEqual(e==null?void 0:e.slug,n),children:i?"Changing...":"Change Slug"})})]})]})})};function vn({page:e,onClose:s}){const[,n]=Pe(),{mutate:a,isPending:r}=er(),{data:i}=Ce(),l=()=>{a(e,{onSuccess:()=>{e!=null&&e.primaryPage||(window.history.replaceState(null,"","/"),n(new URLSearchParams({})),window.dispatchEvent(new PopStateEvent("popstate"))),s()}})},o=i==null?void 0:i.find(u=>u.key===(e==null?void 0:e.pageType));return t.jsx(c.Dialog,{open:!!e,onOpenChange:s,children:t.jsxs(c.DialogContent,{children:[t.jsxs(c.DialogHeader,{children:[t.jsx(c.DialogTitle,{children:"Confirm Deletion"}),t.jsxs(c.DialogDescription,{className:"py-4 text-slate-500",children:[t.jsxs("div",{children:["Are you sure you want to remove ",t.jsx("b",{children:(e==null?void 0:e.name)??(e==null?void 0:e.slug)})," ",o!=null&&o.hasSlug?(o==null?void 0:o.name)+"?":`page? ${e!=null&&e.primaryPage?"":"This will also delete all associated language pages."}`]}),e.lang&&t.jsxs("div",{className:"py-2 text-sm",children:["Language:"," ",t.jsx("span",{className:"font-medium text-gray-500",children:x.get(Le,e.lang,e.lang)})]})]})]}),t.jsxs(c.DialogFooter,{children:[t.jsx(c.Button,{variant:"outline",onClick:s,children:"Cancel"}),t.jsx(c.Button,{variant:"destructive",disabled:r,onClick:l,children:r?"Deleting...":"Delete"})]})]})})}const ke=({permission:e,permissions:s,children:n,fallback:a=null})=>{const{hasPermission:r}=ee.usePermissions();return e&&!r(e)||s&&!s.some(i=>r(i))?a:n},ks=({page:e,onClose:s})=>{const{mutate:n,isPending:a}=tr(),r=async()=>{n(e,{onSuccess:s})};return t.jsx(c.Dialog,{open:!!e,onOpenChange:s,children:t.jsxs(c.DialogContent,{children:[t.jsxs(c.DialogHeader,{children:[t.jsx(c.DialogTitle,{children:"Confirm action"}),t.jsxs(c.DialogDescription,{children:[Q.UNPUBLISH_MSG," ",t.jsx("b",{children:(e==null?void 0:e.name)??(e==null?void 0:e.slug)}),"?"]})]}),t.jsxs(c.DialogFooter,{children:[t.jsx(c.Button,{variant:"outline",onClick:s,children:"Cancel"}),t.jsx(c.Button,{variant:"destructive",disabled:a,onClick:r,children:a?Q.UPDATING:Q.UNPUBLISH})]})]})})},jn=({langProps:e,onClose:s,languages:n})=>{const{data:a}=Ie(),{data:r}=Ce(),[i,l]=g.useState(e.name||""),[o,u]=g.useState(e.edit?e.lang:""),[d,m]=g.useState(e.edit?e.slug:""),{mutate:f,isPending:v}=yn(),{mutate:y,isPending:p}=Ps(),S=g.useMemo(()=>r==null?void 0:r.find(k=>k.key===e.pageType),[r,e.pageType]),E=!(S!=null&&S.hasSlug),_=v||p,w=k=>{k.preventDefault();const b={name:i,lang:o,primaryPage:a==null?void 0:a.id,slug:d,pageType:a==null?void 0:a.pageType};b.pageType=e.pageType,e.edit&&(b.id=e==null?void 0:e.id),e.edit?y(b,{onSuccess:s}):f(b,{onSuccess:s})};return t.jsx(c.Dialog,{open:!!e,onOpenChange:s,children:t.jsxs(c.DialogContent,{className:"sm:max-w-[425px] text-slate-600",children:[t.jsxs(c.DialogHeader,{children:[t.jsx(c.DialogTitle,{children:e.edit?Q.EDIT_LANGUAGE:Q.ADD_NEW_LANGUAGE}),t.jsx(c.DialogDescription,{className:"font-light",children:Q.ENTER_LANGUAGE_DETAILS})]}),t.jsxs("form",{onSubmit:w,children:[t.jsxs("div",{className:"grid gap-4 py-4",children:[t.jsxs("div",{className:"space-y-1",children:[t.jsx(c.Label,{htmlFor:"lang",className:"text-right",children:Q.LANGUAGE}),t.jsxs("select",{value:o,disabled:e.edit||x.isEmpty(n),onChange:k=>{const b=k.target.value;u(b),!E&&m(`/${b}`)},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:[t.jsx("option",{value:"",disabled:!0,selected:!0,children:e.edit?x.get(Le,e.lang,e.lang):x.isEmpty(n)?Q.ALL_AVAILABLE_LANGUAGE_PAGE:Q.CHOOSE_LANGUAGE}),x.map(n,k=>t.jsx("option",{value:k,children:x.get(Le,k,k)},k))]})]}),t.jsxs("div",{className:"space-y-1",children:[t.jsx(c.Label,{htmlFor:"slug",className:"text-right",children:Q.PAGE_NAME}),t.jsx(c.Input,{id:"name",value:i,onChange:k=>l(k.target.value),className:"col-span-3",required:!0,placeholder:Q.ENTER_PAGE_NAME})]}),!E&&t.jsxs("div",{className:"space-y-1",children:[t.jsxs(c.Label,{htmlFor:"slug",className:"text-right",children:[Q.SLUG," ",t.jsx("small",{className:"font-light",children:Q.SLUG_SHOULD_START_WITH})]}),t.jsx(c.Input,{id:"slug",value:d,onChange:k=>{const b=k.target.value;x.startsWith(b,`/${o}`)&&m(x.toLower(x.trim(b)))},className:"col-span-3",required:!0,pattern:"^/.*",disabled:x.isEmpty(o),title:Q.SLUG_MUST_START_WITH,placeholder:x.isEmpty(o)?Q.CHOOSE_LANGUAGE_TO_ADD_SLUG:Q.ENTER_PAGE_SLUG})]})]}),t.jsx(c.DialogFooter,{children:t.jsx(c.Button,{type:"submit",disabled:_||!i||!o||!E&&!x.startsWith(d,`/${o}`),children:_?e.edit?Q.UPDATING:Q.ADDING:e.edit?Q.UPDATE:Q.ADD_NEW_LANGUAGE})})]})]})})},ur=()=>{const[e,s]=g.useState(null),{selectedLang:n,fallbackLang:a,setSelectedLang:r}=ee.useLanguages(),{data:i,isFetching:l}=Xe(),{data:o}=Ie(),[u,d]=g.useState(null),[m,f]=g.useState(null),[v,y]=g.useState(null),{data:p}=Ve(),S=x.filter(x.get(p,"languages")||["en"],E=>!x.find(i,{lang:E})&&E!==x.get(p,"fallbackLang"));return t.jsxs("div",{className:"space-y-4",children:[t.jsx("ul",{className:"space-y-2",children:l?t.jsxs("div",{className:"w-full space-y-3 py-4",children:[t.jsx("div",{className:"w-full h-8 rounded bg-gray-300 animate-pulse"}),t.jsx("div",{className:"w-full h-8 rounded bg-gray-300 animate-pulse"}),t.jsx("div",{className:"w-full h-8 rounded bg-gray-300 animate-pulse"})]}):x.map(i,E=>{const _=E.lang,w=E.slug,k=!E.primaryPage,b=_===n;return t.jsxs(t.Fragment,{children:[t.jsxs("li",{className:`text-slate-500 w-full p-2 rounded cursor-pointer flex items-center justify-between ${b?"bg-gray-200":"hover:bg-gray-100"}`,onClick:()=>r(_),children:[t.jsxs("div",{className:" flex-1 gap-x-3",children:[t.jsxs("div",{className:"text-[13px] text-slate-800 flex items-center gap-x-2",children:[t.jsx("div",{className:`w-2.5 h-2.5 rounded-full ${E.online?"bg-green-300":"bg-gray-300"}`}),x.get(Le,k?a:_,_)]}),t.jsxs("div",{children:[w&&t.jsxs("div",{className:"text-[11px] text-slate-600 font-light",children:["Slug: ",t.jsx("b",{className:"font-medium",children:w})]}),t.jsxs("div",{className:"text-[11px] text-slate-600 font-light",children:["Name:",t.jsxs("b",{className:"font-medium",children:[" ",E.name," "]})]})]})]}),k?t.jsxs("div",{className:"flex items-center text-[11px] text-orange-500 gap-x-1",children:[t.jsx(N.StarIcon,{fill:"orange",className:"w-3 h-3"}),t.jsx("b",{children:" Primary"})]}):t.jsx("div",{className:"flex items-center gap-x-3",children:t.jsx(ke,{permissions:[fe.EDIT_PAGE,fe.DELETE_PAGE,fe.UNPUBLISH_PAGE],children:t.jsxs(c.DropdownMenu,{children:[t.jsx(c.DropdownMenuTrigger,{asChild:!0,onClick:B=>B.stopPropagation(),children:t.jsx(c.Button,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0",children:t.jsx(N.MoreHorizontal,{className:"h-4 w-4"})})}),t.jsxs(c.DropdownMenuContent,{align:"end",className:"text-sm z-[9999]",children:[t.jsx(ke,{permissions:[fe.EDIT_PAGE],children:t.jsxs(c.DropdownMenuItem,{className:"flex items-center gap-2 cursor-pointer",onClick:B=>{B.stopPropagation(),s({...E,edit:!0})},children:[t.jsx(N.PencilIcon,{className:"size-3"}),Q.EDIT]})}),t.jsx(ke,{permissions:[fe.UNPUBLISH_PAGE],children:(E==null?void 0:E.online)&&t.jsxs(c.DropdownMenuItem,{className:"flex items-center gap-2 cursor-pointer",onClick:B=>{B.stopPropagation(),f(E)},children:[t.jsx(N.Power,{className:"size-3"}),Q.UNPUBLISH]})}),t.jsx(ke,{permissions:[fe.DELETE_PAGE],children:t.jsxs(c.DropdownMenuItem,{className:"flex items-center gap-2 cursor-pointer",onClick:B=>{B.stopPropagation(),d(E)},children:[t.jsx(N.TrashIcon,{className:"size-3"}),Q.DELETE]})})]})]})})})]},E.id),t.jsx("div",{className:"h-1 w-full border-b"})]})})}),t.jsx(ke,{permissions:[fe.ADD_PAGE],children:t.jsx("div",{className:"flex justify-center w-full",children:t.jsx(c.Button,{variant:"default",size:"sm",disabled:x.isEmpty(S),onClick:()=>{s({name:o==null?void 0:o.name,pageType:o==null?void 0:o.pageType,lang:"",slug:"",edit:!1})},children:Q.ADD_NEW_LANGUAGE})})}),e&&t.jsx(jn,{languages:S,langProps:e,onClose:()=>s(null)}),u&&t.jsx(vn,{page:u,onClose:()=>d(null)}),m&&t.jsx(ks,{page:m,onClose:()=>f(null)}),v&&t.jsx(cr,{page:v,onClose:()=>y(null)})]})};function dr({value:e,onChange:s,placeholder:n="Enter custom slug part",dynamicPattern:a,onValidationChange:r}){const[i,l]=g.useState(null),o=g.useRef(null),[u,d]=g.useState(a+e);g.useEffect(()=>{d(a+e)},[e,a]);const m=y=>{const p=y.target.value;if(!p.startsWith(a)){const b=p.replace(a,""),B=a+b;d(B),s(b);return}const E=p.substring(a.length).replace(/\//g,"").replace(/\s+/g,"-").replace(/[^a-zA-Z0-9-_.]/g,"-").replace(/-+/g,"-").replace(/^-+/,"").toLowerCase(),_=(E.match(/\./g)||[]).length,w=_<=1;_>1?l("Invalid slug. Only one dot (.) is allowed in the slug"):l(null),r&&r(w);const k=a+E;d(k),s(E)},f=()=>{if(o.current){const y=o.current;setTimeout(()=>{const p=a.length;y.setSelectionRange(p,p)},0)}},v=y=>{const p=y.currentTarget;(p.selectionStart||0)<=a.length&&setTimeout(()=>{const E=a.length;p.setSelectionRange(E,E)},0)};return t.jsx("div",{children:t.jsxs("div",{className:"relative",children:[t.jsxs("p",{className:"text-gray-500 text-xs mb-2",children:[`${a}`," is a dynamic segment of slug"]}),t.jsx(c.Input,{ref:o,value:u,onChange:m,onFocus:f,onClick:v,placeholder:n,className:i?"border-red-500":""}),i&&t.jsx("div",{className:"text-red-500 text-xs mt-1",children:i})]})})}const mr=e=>{if(!e)return{base:e,extension:null};const s=e.lastIndexOf(".");if(s<=0)return{base:e,extension:null};const n=e.substring(s);return{base:e.substring(0,s),extension:n}},Ye=e=>{if(!e)return e;const{base:s}=mr(e);return s},hr=e=>e&&Ye(e),Hs=(e,s)=>{const n=Ye(e||"");return!n||n==="/"?`/${s}`:`${n}/${s}`};function fr({pages:e,selectedParentId:s,onChange:n,className:a="w-full rounded-md border border-gray-300 px-3 py-2",id:r="parentPage"}){const i=g.useMemo(()=>!e||e.length===0?[]:e.filter(m=>!x.isEmpty(m.slug)).filter(m=>m.slug!=="/").sort((m,f)=>m.slug.localeCompare(f.slug)),[e]),l=d=>Math.max(0,(d.match(/\//g)||[]).length-1),o=d=>" ".repeat(d),u=d=>{if(d==="/")return"/";const m=d.split("/").filter(Boolean);if(m.length<=1){const y=m[0]||"";return`/${Ye(y)}`}const f=m[m.length-1];return`/${Ye(f)}`};return t.jsxs("div",{className:"space-y-0.5",children:[t.jsx(c.Label,{htmlFor:r,className:"text-sm",children:"Parent"}),t.jsxs("select",{id:r,value:s||"none",onChange:d=>n(d.target.value),className:a,"data-testid":"parent-page-selector",children:[t.jsx("option",{value:"none",children:"None"}),i.map(d=>{const m=l(d.slug),f=m>0?o(m):"",v=u(d.slug);return t.jsxs("option",{value:d.id,children:[f,d.name," (",v,")"]},d.id)})]})]})}function bn({value:e,onChange:s,placeholder:n,parentSlug:a,onValidationChange:r}){const[i,l]=g.useState(e),[o,u]=g.useState(null);g.useEffect(()=>{l(e)},[e]);const d=m=>{const v=m.target.value.replace(/\//g,"").replace(/\s+/g,"-").replace(/[^a-zA-Z0-9-_.]/g,"-").replace(/-+/g,"-").replace(/^-+/,"").toLowerCase(),y=(v.match(/\./g)||[]).length,p=y<=1;y>1?u("Invalid slug. Only one dot (.) is allowed in the slug"):u(null),r&&r(p),l(v),s(v)};return t.jsxs("div",{children:[a&&t.jsx("div",{className:"flex items-center mb-1",children:t.jsxs("span",{className:"text-xs text-gray-500",children:["Parent: ",hr(a)]})}),t.jsxs("div",{className:"relative",children:[t.jsx(c.Input,{value:i,onChange:d,placeholder:n,className:o?"border-red-500":""}),o&&t.jsx("div",{className:"text-red-500 text-xs mt-1",children:o})]})]})}const gr=({templates:e,selectedTemplateId:s,onSelectTemplate:n,isLoading:a=!1})=>{const[r,i]=g.useState("");if(g.useEffect(()=>{if(s){const o=e.find(u=>u.id===s);i((o==null?void 0:o.preview)||"")}else i("")},[s,e]),a)return t.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 l={};return e.forEach(o=>{const u=o.libraryName;l[u]||(l[u]=[]),l[u].push(o)}),t.jsxs("div",{className:"space-y-4",children:[t.jsxs("select",{className:"w-full rounded-md border border-gray-300 px-3 py-2",value:s,onChange:o=>n(o.target.value),children:[t.jsx("option",{value:"",children:"No Template"}),Object.entries(l).map(([o,u])=>t.jsx("optgroup",{label:o,children:u.map(d=>t.jsx("option",{value:d.id,children:x.startCase(d.name)},d.id))},o))]}),r&&t.jsxs("div",{className:"mt-3 border rounded overflow-hidden",children:[t.jsx("div",{className:"max-h-[200px] overflow-auto",children:t.jsx("img",{src:r,alt:"Template Preview",className:"w-full object-contain"})}),t.jsx("div",{className:"p-2 text-xs text-gray-500 bg-gray-50 border-t",children:"Template preview"})]})]})},xr=()=>{const e=ne(),s=$();return L.useQuery({queryKey:[z,P.GET_LIBRARIES],queryFn:async()=>await s(e,{action:P.GET_LIBRARIES})||[]})},pr=e=>{const s=ne(),n=$();return L.useQuery({queryKey:[z,P.GET_TEMPLATES_BY_TYPE,e],enabled:!!e,queryFn:async()=>{const a=await n(s,{action:P.GET_TEMPLATES_BY_TYPE,data:{pageType:e}});return(e?x.filter(a,{pageType:e}):a)||[]}})},yr=e=>{const{data:s=[],isLoading:n}=pr(e),{data:a=[],isLoading:r}=xr(),i=g.useMemo(()=>n||r?[]:s.map(o=>{const u=x.find(a,{id:o.library});return{...o,libraryName:(u==null?void 0:u.type)!=="shared"?"Site Library":(u==null?void 0:u.name)+" Library",libraryType:u==null?void 0:u.type}}),[s,a,n,r]),l=g.useMemo(()=>x.groupBy(i,"libraryName"),[i]);return{data:i,groupedData:l,isLoading:n||r}},En=()=>{const[,e]=Pe();return g.useCallback((s,n)=>{const r=new URLSearchParams(window.location.search).get("lang"),i=new URLSearchParams({page:s});r&&i.set("lang",r),window.history.pushState({},"",`?${i.toString()}`),e(i),window.dispatchEvent(new PopStateEvent("popstate")),n==null||n()},[e])};function vr({addEditPage:e,additionalPageTypes:s=[],close:n,closePanel:a}){var D,re;const r=En(),i=!!(e!=null&&e.id),{data:l}=Ht(),{mutate:o,isPending:u}=yn(),{mutate:d,isPending:m}=Ps(),[f,v]=g.useState(null),[y,p]=g.useState(!0),[S,E]=g.useState((e==null?void 0:e.pageType)??"page"),{hasPermission:_}=ee.usePermissions(),w=_(fe.CHANGE_PAGE_TYPE),[k,b]=g.useState(!1),[B,F]=g.useState(""),te=g.useMemo(()=>{const C=s.find(he=>he.key===S);return(C==null?void 0:C.hasSlug)===!1},[S,s]),[R,K]=g.useState((e==null?void 0:e.parent)??""),[M,X]=g.useState((e==null?void 0:e.name)??""),[O,je]=g.useState((e==null?void 0:e.dynamic)??!1),[V,I]=g.useState(O?"":((e==null?void 0:e.slug)??"").split("/").pop()||""),[ae,be]=g.useState((e==null?void 0:e.dynamicSlugCustom)??""),[we,Be]=g.useState(!0),[j,h]=g.useState(""),{data:A,isLoading:G}=yr(S),U=u||m,T=s.find(C=>C.key===S),Z=C=>{if(i&&S!==C){F(C),b(!0);return}E(C)},q=()=>{E(B),b(!1),je(!1)},J=C=>{je(C),C?I(""):be("")},le=C=>{if(K(C),C&&C!=="none"){const he=l==null?void 0:l.find(_e=>_e.id===C),De=(he==null?void 0:he.slug)||"";if(V.startsWith(De)){const _e=V.slice(De.length).replace(/^\/+/,"");I(_e)}else I(V.replace(/^\/+/,""))}else I(V?`${V}`:"")},ge=C=>{h(C)},ce=()=>M.trim()?O&&!x.isEmpty(V)?(v("Slug must be empty when using dynamic slug"),!1):O&&!we?(v("Dynamic slug is invalid"),!1):!0:(Y.toast.error("Name is required"),!1),xe=()=>{const C={pageType:T==null?void 0:T.key,name:M,slug:"",hasSlug:!1};i?d({id:e==null?void 0:e.id,name:M},{onSuccess:()=>{Y.toast.success((T==null?void 0:T.name)+" updated successfully"),n()}}):o(C,{onSuccess:he=>{console.log("response",he),n(),r(he.page.id,a)}})},ve=(C,he)=>{if(!C.trim()&&!O)return v("Child page slug is required"),!1;const De=Ye(he),_e=Hs(De,C);return Object.keys(Le).some(Kt=>_e===`/${Kt}`||(_e==null?void 0:_e.startsWith(`/${Kt}/`)))?(v("Slugs cannot start with a language code for primary page"),!1):!0},se=(C,he)=>{const De=Ye(he),_e=Hs(De,C),et={pageType:S,name:M,slug:_e.replace(/\/$/,""),parent:R,dynamic:O,hasSlug:!0,template:j||void 0};O&&(et.dynamicSlugCustom=ae),i?d({id:e==null?void 0:e.id,...et},{onSuccess:()=>{Y.toast.success("Page updated successfully"),n()}}):o(et,{onSuccess:tt=>{console.log("response",tt),n(),r(tt.page.id,a)}})},Ee=()=>{const C={pageType:S,name:M,slug:V===""?"/":`/${V.replace(/\/$/,"")}`,template:j||void 0,parent:null};i?d({id:e==null?void 0:e.id,...C},{onSuccess:()=>{Y.toast.success("Page updated successfully"),n()}}):o(C,{onSuccess:()=>{n()}})},Ne=C=>{if(C.preventDefault(),v(null),!!ce()){if(!(T!=null&&T.hasSlug)){xe();return}if(R&&R!=="none"){const he=l==null?void 0:l.find(_e=>_e.id===R),De=(he==null?void 0:he.slug)||"";if(!ve(V,De))return;se(V,De)}else Ee()}};return T!=null&&T.hasSlug?t.jsxs("form",{onSubmit:Ne,className:"w-full max-w-md mx-auto space-y-4",children:[t.jsxs("div",{className:"space-y-0.5",children:[t.jsx(c.Label,{htmlFor:"pageType",className:"text-sm",children:"Type"}),t.jsx("select",{id:"pageType",value:S,disabled:i&&!w,onChange:C=>Z(C.target.value),className:`w-full rounded-md border border-gray-300 px-3 py-2 ${i&&!w?"cursor-not-allowed text-gray-500":""}`,children:i?te?t.jsx("optgroup",{label:"Partials",children:s.filter(C=>C.hasSlug===!1).map(C=>t.jsx("option",{value:C.key,children:C.name},C.key))}):t.jsx("optgroup",{label:"Pages",children:s.filter(C=>C.hasSlug!==!1).map(C=>t.jsx("option",{value:C.key,children:C.name},C.key))}):t.jsxs(t.Fragment,{children:[t.jsx("optgroup",{label:"Pages",children:s.filter(C=>C.hasSlug!==!1).map(C=>t.jsx("option",{value:C.key,children:C.name},C.key))}),t.jsx("optgroup",{label:"Partials",children:s.filter(C=>C.hasSlug===!1).map(C=>t.jsx("option",{value:C.key,children:C.name},C.key))})]})}),k&&t.jsxs("div",{className:"mt-2 p-3 bg-yellow-50 border border-yellow-200 rounded-md",children:[t.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?"}),t.jsxs("div",{className:"mt-2 flex gap-2",children:[t.jsx(c.Button,{variant:"outline",size:"sm",onClick:()=>b(!1),children:"Cancel"}),t.jsx(c.Button,{variant:"default",size:"sm",onClick:q,children:"Confirm"})]})]})]}),!i&&(T==null?void 0:T.hasSlug)&&A.length>0&&t.jsxs("div",{className:"space-y-1",children:[t.jsx(c.Label,{className:"text-sm mb-1 block",children:"Template"}),t.jsx(gr,{templates:A,selectedTemplateId:j,onSelectTemplate:ge,isLoading:G})]}),t.jsx(fr,{pages:l,selectedParentId:R,onChange:le}),t.jsxs("div",{className:"space-y-0.5",children:[t.jsx(c.Label,{htmlFor:"name",className:"text-sm",children:"Name"}),t.jsx(c.Input,{id:"name",value:M,onChange:C=>X(C.target.value),required:!0,"aria-required":"true"})]}),(T==null?void 0:T.dynamicSegments)&&R&&R!=="none"&&t.jsxs("div",{className:"space-y-2",children:[t.jsxs("div",{className:"flex items-center space-x-2",children:[t.jsx("input",{type:"checkbox",id:"useDynamicSlug",checked:O,onChange:C=>J(C.target.checked),className:"rounded border-gray-300"}),t.jsx(c.Label,{htmlFor:"useDynamicSlug",className:"text-sm",children:"Use Dynamic Slug"})]}),O&&t.jsx("div",{className:"space-y-2",children:t.jsx("div",{className:"space-y-0.5",children:t.jsx(dr,{value:ae,onChange:be,dynamicPattern:(T==null?void 0:T.dynamicSlug)||"{{id}}",placeholder:"Enter custom slug part (optional)",onValidationChange:Be})})})]}),(!(T!=null&&T.dynamicSegments)||!O)&&t.jsxs("div",{className:"space-y-0.5",children:[t.jsx(c.Label,{htmlFor:"slug",className:"text-sm",children:"Slug"}),t.jsx(bn,{value:V,onChange:I,placeholder:R&&R!=="none"?"Enter page slug":S==="page"?"Leave empty for home page":"Required - e.g. your-slug",parentSlug:R&&R!=="none"?(re=l==null?void 0:l.find(C=>C.id===R))==null?void 0:re.slug:void 0,onValidationChange:p}),f&&t.jsx("p",{className:"text-xs text-red-500",children:f})]}),t.jsx(c.Button,{disabled:U||!y&&(!(T!=null&&T.dynamicSegments)||!O)||O&&!we,type:"submit",className:"w-full",children:i?U?"Updating...":"Update page":U?"Creating...":"Create Page"})]}):t.jsxs("form",{onSubmit:Ne,className:"w-full max-w-md mx-auto space-y-4",children:[t.jsxs("div",{className:"space-y-0.5",children:[t.jsx(c.Label,{htmlFor:"pageType",className:"text-sm",children:"Type"}),t.jsx("select",{id:"pageType",value:S,disabled:i&&!w,onChange:C=>Z(C.target.value),className:`w-full rounded-md border border-gray-300 px-3 py-2 ${i&&!w?"cursor-not-allowed text-gray-500":""}`,children:t.jsx("optgroup",{label:"Partials",children:s.filter(C=>C.hasSlug===!1).map(C=>t.jsx("option",{value:C.key,children:C.name},C.key))})}),k&&t.jsxs("div",{className:"mt-2 p-3 bg-yellow-50 border border-yellow-200 rounded-md",children:[t.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?"}),t.jsxs("div",{className:"mt-2 flex gap-2",children:[t.jsx(c.Button,{variant:"outline",size:"sm",onClick:()=>b(!1),children:"Cancel"}),t.jsx(c.Button,{variant:"default",size:"sm",onClick:q,children:"Confirm"})]})]}),t.jsx("p",{className:"text-xs text-gray-500",children:(D=s.find(C=>C.key===S))==null?void 0:D.helpText})]}),t.jsxs("div",{className:"space-y-0.5",children:[t.jsx(c.Label,{htmlFor:"name",className:"text-sm",children:"Name"}),t.jsx(c.Input,{id:"name",value:M,onChange:C=>X(C.target.value),required:!0,"aria-required":"true"})]}),t.jsx(c.Button,{disabled:U,type:"submit",className:"w-full",children:i?U?"Updating...":"Update "+(T==null?void 0:T.name):U?"Creating...":"Create "+(T==null?void 0:T.name)})]})}const jr=({addEditPage:e,setAddEditPage:s,closePanel:n})=>{const{data:a}=Ce(),r=!!(e!=null&&e.id);return t.jsx(c.Dialog,{open:!!e,onOpenChange:()=>s(void 0),children:t.jsxs(c.DialogContent,{className:"sm:max-w-[425px]",children:[t.jsxs(c.DialogHeader,{children:[t.jsxs(c.DialogTitle,{children:[r?"Edit":"Add New"," "]}),t.jsx(c.DialogDescription,{children:r?"Update your page name":"Enter details to create a new page"})]}),t.jsx(vr,{closePanel:n,addEditPage:e,close:()=>s(void 0),additionalPageTypes:a??[]})]})})},br=()=>{const e=ne(),s=L.useQueryClient(),n=$();return L.useMutation({mutationFn:async({pageId:a,name:r,slug:i})=>{const l={pageId:a,name:r};return i&&(l.slug=i),await n(e,{action:"DUPLICATE_PAGE",data:l})},onSuccess:()=>{s.invalidateQueries({queryKey:[z,P.GET_WEBSITE_PAGES]}),Y.toast.success("Page duplicated successfully")},onError:a=>{Y.toast.error("Failed to duplicate page",{description:a.message||"An error occurred while duplicating the page"})}})},Er=({page:e,onClose:s})=>{const{mutate:n,isPending:a}=br(),[r,i]=g.useState(null),[l,o]=g.useState(`${e.name} (Copy)`),u=x.isEmpty(e.slug),[d,m]=g.useState(u?"":`${e.slug.split("/").pop()}-copy`),f=u?"":x.initial(e.slug.split("/")).join("/"),[v,y]=g.useState(!1),p=S=>{if(S.preventDefault(),!l.trim()){i("Name is required");return}if(!u&&!d.trim()){i("Slug is required");return}i(null),y(!0);const E={pageId:e.id,name:l};u||(E.slug=`${f}/${d}`),n(E,{onSuccess:()=>{y(!1),s()},onError:_=>{y(!1),_.code==="SLUG_EXISTS"?i("A page with this slug already exists. Please choose a different slug."):_.code==="INVALID_SLUG"?i("The slug format is invalid. Please use only lowercase letters, numbers, and hyphens."):_.code==="PERMISSION_DENIED"?i("You don't have permission to duplicate this page."):i(_.message||"Failed to duplicate page. Please try again later.")}})};return t.jsx(c.Dialog,{open:!!e,onOpenChange:s,children:t.jsxs(c.DialogContent,{className:"sm:max-w-[425px]",children:[t.jsxs(c.DialogHeader,{children:[t.jsx(c.DialogTitle,{children:"Duplicate Page"}),t.jsx(c.DialogDescription,{children:"Create a copy of the page with a new name and slug"})]}),t.jsxs("div",{className:"bg-gray-50 p-3 rounded-md mb-4",children:[t.jsx("h3",{className:"text-sm font-medium mb-1",children:"Duplicating:"}),t.jsxs("div",{className:"text-sm text-gray-700 flex flex-col gap-1",children:[t.jsxs("div",{children:[t.jsx("span",{className:"font-medium",children:"Name:"})," ",e.name]}),!u&&t.jsxs("div",{children:[t.jsx("span",{className:"font-medium",children:"Slug:"})," ",e.slug]}),t.jsxs("div",{children:[t.jsx("span",{className:"font-medium",children:"Type:"})," ",e.pageType]})]})]}),t.jsxs("form",{onSubmit:p,className:"space-y-4",children:[t.jsxs("div",{className:"space-y-2",children:[t.jsx(c.Label,{htmlFor:"name",className:"text-sm",children:"Name"}),t.jsx(c.Input,{id:"name",value:l,onChange:S=>o(S.target.value),required:!0})]}),!u&&t.jsxs("div",{className:"space-y-2",children:[t.jsx(c.Label,{htmlFor:"slug",className:"text-sm",children:"Slug"}),t.jsx(bn,{value:d,onChange:S=>m(S),parentSlug:f,onValidationChange:S=>{i(S?null:"Invalid slug")}})]}),r&&t.jsxs(c.Alert,{variant:"destructive",className:"py-2",children:[t.jsx(N.AlertCircle,{className:"h-4 w-4"}),t.jsx("span",{className:"text-sm",children:r})]}),t.jsxs("div",{className:"flex justify-end gap-2",children:[t.jsx(c.Button,{type:"button",variant:"outline",onClick:s,disabled:a,children:"Cancel"}),t.jsx(c.Button,{type:"submit",disabled:!l.trim()||!u&&!d.trim()||a||v,children:a||v?"Duplicating...":"Duplicate"})]})]})]})})},Sr=1*1024*1024,wr=({page:e,onClose:s})=>{const[n,a]=g.useState(!1),[r,i]=g.useState(""),[l,o]=g.useState(""),[u,d]=g.useState(!1),m=g.useRef(null),f=sr(),{data:v}=Ce(),y=v==null?void 0:v.find(k=>k.key===e.pageType),p=(y==null?void 0:y.name)||x.startCase(e.pageType),S=g.useCallback(k=>{var B;const b=(B=k.target.files)==null?void 0:B[0];if(b){if(b.size>Sr){Y.toast.error("File too large",{description:`Maximum file size is 1MB. Selected file is ${(b.size/1024).toFixed(2)}KB.`}),m.current&&(m.current.value="");return}try{d(!0);const F=new FileReader;F.onloadend=()=>{o(F.result),d(!1)},F.readAsDataURL(b)}catch(F){console.error("Error reading file:",F),d(!1),Y.toast.error("Failed to process image",{description:F instanceof Error?F.message:"Unknown error"})}}},[]),E=()=>{o(""),m.current&&(m.current.value="")},_=()=>{var k;(k=m.current)==null||k.click()},w=()=>{a(!0),f.mutate({page:e,name:e.name,description:r.trim()||void 0,pageType:e.pageType,...l?{previewImage:l}:{}},{onSuccess:()=>{a(!1),s()},onError:()=>{a(!1)}})};return t.jsx(c.Dialog,{open:!0,onOpenChange:s,children:t.jsxs(c.DialogContent,{children:[t.jsxs(c.DialogHeader,{children:[t.jsx(c.DialogTitle,{children:"Mark as template"}),t.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?",t.jsx("br",{}),"Templates can be used to create new pages with the same content."]})]}),t.jsxs("div",{className:"space-y-4 mb-4 text-xs",children:[t.jsxs("div",{className:"p-4 border rounded bg-slate-50 space-y-3",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(N.Tag,{className:"w-4 h-4 text-slate-500"}),t.jsx("span",{className:"font-medium text-slate-500",children:"Page Name:"}),t.jsx("span",{className:"font-semibold",children:x.startCase(e.name)})]}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(N.File,{className:"w-4 h-4 text-slate-500"}),t.jsx("span",{className:"font-medium text-slate-500",children:"Type:"}),t.jsx("span",{className:"font-semibold",children:p})]})]}),t.jsxs("div",{children:[t.jsx(c.Label,{htmlFor:"description",className:"text-xs font-medium",children:"Description (Optional)"}),t.jsx(c.Textarea,{id:"description",placeholder:"Describe this template's purpose",className:"text-xs resize-none h-24 mt-1",value:r,onChange:k=>i(k.target.value)})]}),t.jsxs("div",{className:"space-y-2",children:[t.jsx(c.Label,{htmlFor:"previewImage",className:"text-xs font-medium",children:"Preview Image (Optional)"}),t.jsxs("div",{className:"space-y-2",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(c.Input,{type:"file",id:"previewImage",ref:m,onChange:S,accept:"image/*",className:"hidden"}),t.jsx(c.Button,{type:"button",variant:"outline",onClick:_,disabled:u,className:"w-full",children:u?t.jsxs("span",{className:"flex items-center gap-2",children:[t.jsx("div",{className:"animate-spin h-4 w-4 border-2 border-current border-t-transparent rounded-full"}),"Uploading..."]}):t.jsxs("span",{className:"flex items-center gap-2",children:[t.jsx(N.ImageIcon,{className:"h-4 w-4"}),"Select image"]})}),l&&t.jsx(c.Button,{type:"button",variant:"outline",size:"icon",onClick:E,children:t.jsx(N.X,{className:"h-4 w-4"})})]}),l&&t.jsx("div",{className:"rounded-md overflow-hidden border aspect-video",children:t.jsx("img",{src:l,alt:"Preview",className:"w-full h-full max-h-[200px] object-contain"})}),t.jsx("p",{className:"text-xs text-muted-foreground",children:"max 1mb"})]})]})]}),t.jsxs(c.DialogFooter,{className:n?"opacity-75 pointer-events-none":"",children:[t.jsx(c.Button,{variant:"outline",onClick:k=>{k.stopPropagation(),s()},children:"Cancel"}),t.jsx(c.Button,{variant:"default",disabled:n,onClick:w,children:"Mark as template"})]})]})})},Nr=({page:e,onClose:s})=>{const[n,a]=g.useState(!1),r=nr(),i=()=>{a(!0),r.mutate(e,{onSuccess:()=>{a(!1),s()},onError:()=>{a(!1)}})};return t.jsx(c.Dialog,{open:!0,onOpenChange:s,children:t.jsxs(c.DialogContent,{children:[t.jsxs(c.DialogHeader,{children:[t.jsx(c.DialogTitle,{children:"Unmark as template"}),t.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?"})]}),t.jsxs(c.DialogFooter,{className:n?"opacity-75 pointer-events-none":"",children:[t.jsx(c.Button,{variant:"outline",onClick:l=>{l.stopPropagation(),s()},children:"Cancel"}),t.jsx(c.Button,{variant:"default",disabled:n,onClick:i,children:"Unmark as template"})]})]})})},Ar=({currentEditor:e})=>{const{user:s}=Re(),{data:n}=Ze(e);return!n||!e||e===(s==null?void 0:s.id)?null:t.jsx("span",{className:"ml-2 text-xs font-light text-gray-500 flex items-center gap-1",children:t.jsxs(c.Tooltip,{children:[t.jsx(c.TooltipTrigger,{children:t.jsx(N.LockIcon,{className:"w-3 h-3"})}),t.jsx(c.TooltipContent,{children:t.jsxs("p",{children:[n.name," is editing"]})})]})})},Cr=({parentSlug:e,page:s,active:n,closePanel:a,setUnpublishPage:r,setDeletePage:i,setAddEditPage:l,setMarkAsTemplate:o,setUnmarkAsTemplate:u,setDuplicatePage:d})=>{const m=En(),{data:f}=Ce(),{hasPermission:v}=ee.usePermissions(),[,y]=ee.useSidebarActivePanel(),p=g.useMemo(()=>x.find(f,{key:s.pageType}),[f,s.pageType]),S=g.useMemo(()=>{const b=x.get(s,"slug",""),B=e?Ye(e):"",F=B?b.replace(B,""):b;return F||"/"},[s,e]),E=!v(fe.EDIT_PAGE)&&!v(fe.DELETE_PAGE)&&!v(fe.UNPUBLISH_PAGE),_=g.useMemo(()=>!!s.isTemplate,[s.isTemplate]),w=g.useMemo(()=>!!(p!=null&&p.hasSlug),[p==null?void 0:p.hasSlug]),k=g.useCallback(()=>{y("outline"),m(x.get(s,"id"),a)},[m,a,s,y]);return t.jsxs("div",{onClick:k,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:[t.jsxs("div",{className:"flex items-center gap-x-2",children:[s.dynamic?t.jsx("div",{className:"w-4 h-4 text-slate-500 stroke-[1]",children:t.jsx(N.StarsIcon,{className:"w-4 h-4 text-yellow-400"})}):p!=null&&p.icon?t.jsx("div",{className:"w-4 h-4 text-slate-500 stroke-[1]",dangerouslySetInnerHTML:{__html:p.icon}}):p!=null&&p.hasSlug?t.jsx(N.File,{className:"w-4 h-4 text-slate-500 stroke-[1]"}):t.jsx(N.Globe,{className:"w-4 h-4 text-slate-500 stroke-[1]"}),t.jsx("div",{className:`w-2.5 h-2.5 rounded-full ${s.online?"bg-green-300":"bg-gray-300"}`}),t.jsx("span",{className:"font-light leading-none truncate text-slate-800",children:s.name}),p!=null&&p.hasSlug?t.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:[S,s.dynamic&&t.jsxs("span",{className:"text-xs font-light leading-none text-slate-500",children:[x.endsWith(S,"/")?`${p==null?void 0:p.dynamicSlug}`:`/${p==null?void 0:p.dynamicSlug}`,s.dynamicSlugCustom]})]}):t.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:p==null?void 0:p.name}),_&&t.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"})]}),t.jsxs("div",{className:"flex items-center space-x-4",children:[t.jsx(Ar,{currentEditor:s.currentEditor}),!E&&t.jsxs(c.DropdownMenu,{children:[t.jsx(c.DropdownMenuTrigger,{asChild:!0,onClick:b=>b.stopPropagation(),children:t.jsx(N.MoreHorizontal,{className:"h-4 w-4 hover:stroke-[3]"})}),t.jsxs(c.DropdownMenuContent,{align:"end",className:"text-sm",children:[v(fe.ADD_PAGE)&&t.jsxs(c.DropdownMenuItem,{className:"flex items-center gap-2 cursor-pointer",onClick:b=>{b.stopPropagation(),d(s)},children:[t.jsx(N.CopyPlusIcon,{className:"size-3"}),"Duplicate page"]}),v(fe.EDIT_PAGE)&&t.jsxs(c.DropdownMenuItem,{className:"flex items-center gap-2 cursor-pointer",onClick:b=>{b.stopPropagation(),l({...s,global:!(p!=null&&p.hasSlug)})},children:[t.jsx(N.Pencil,{className:"size-3"}),"Edit"]}),(s==null?void 0:s.online)&&v(fe.UNPUBLISH_PAGE)&&t.jsxs(c.DropdownMenuItem,{className:"flex items-center gap-2 cursor-pointer",onClick:b=>{b.stopPropagation(),r(s)},children:[t.jsx(N.Power,{className:"size-3"}),Q.UNPUBLISH]}),v(fe.DELETE_PAGE)&&t.jsxs(c.DropdownMenuItem,{className:"flex items-center gap-2 cursor-pointer",onClick:b=>{b.stopPropagation(),i(s)},children:[t.jsx(N.Trash,{className:"size-3"}),Q.DELETE]}),v(fe.MARK_AS_TEMPLATE)&&w&&t.jsx(t.Fragment,{children:_?t.jsxs(c.DropdownMenuItem,{className:"flex items-center gap-2 cursor-pointer",onClick:b=>{b.stopPropagation(),u(s)},children:[t.jsx(N.SquareLibrary,{className:"size-3"}),Q.UNMARK_AS_TEMPLATE]}):t.jsxs(c.DropdownMenuItem,{className:"flex items-center gap-2 cursor-pointer",onClick:b=>{b.stopPropagation(),o(s)},children:[t.jsx(N.SquareLibrary,{className:"size-3"}),Q.MARK_AS_TEMPLATE]})})]})]})]})]})},Tr=({close:e,isOpen:s})=>{const[,n]=g.useState([]),[a,r]=g.useState(null),[i,l]=g.useState(""),[o,u]=g.useState(null),[d,m]=g.useState(null),[f,v]=g.useState(null),[y,p]=g.useState(null),[S,E]=g.useState(null),{data:_,isFetching:w,refetch:k}=Ht(),[b,B]=g.useState(""),{hasPermission:F}=ee.usePermissions(),[te,R]=Pe(),K=te.get("page"),{data:M}=Ce(),X=g.useCallback(I=>{var ae;return(ae=x.find(M,{key:I}))==null?void 0:ae.hasSlug},[M]);g.useEffect(()=>{s&&k()},[s,k]),g.useEffect(()=>{if(!x.isEmpty(b))return;const I=sessionStorage.getItem("pageTypeFilter")||"all";!x.isEmpty(M)&&I&&(x.find(M,{key:I})?B(I):B("all"))},[M,b]);const O=I=>{B(I),sessionStorage.setItem("pageTypeFilter",I)},je=g.useCallback(I=>{const be=new URLSearchParams(window.location.search).get("lang"),we=new URLSearchParams({page:I});be&&we.set("lang",be),window.history.pushState({},"",`?${we.toString()}`),R(we),window.dispatchEvent(new PopStateEvent("popstate")),e()},[R,e]);g.useEffect(()=>{if(K&&!w){const I=x.find(_,{id:K});I&&(I!=null&&I.pageType)?n(ae=>[...ae,I==null?void 0:I.pageType]):(window.history.replaceState(null,"","/"),R(new URLSearchParams({})),window.dispatchEvent(new PopStateEvent("popstate")))}},[_,K,w,R]);const V=g.useMemo(()=>{const I=x.compact(x.filter(_,h=>x.isEmpty(i)?!0:x.includes(x.toLower(h==null?void 0:h.name),x.toLower(i))||x.includes(x.toLower(h==null?void 0:h.slug),x.toLower(i))));if(b!=="all")return x.compact(x.filter(I,{pageType:b}));const ae=new Map;I.forEach(h=>{ae.set(h.id,{...h,children:[]})});const be=[];ae.forEach(h=>{if(h.parent){const A=ae.get(h.parent);A?A.children.push(h):be.push(h)}else be.push(h)});const we=h=>(h.sort((A,G)=>A.name.localeCompare(G.name)),h.forEach(A=>{A.children&&A.children.length>0&&we(A.children)}),h);we(be);const Be=x.filter(be,h=>X(h.pageType)).sort((h,A)=>h.name.localeCompare(A.name)),j=x.filter(be,h=>!X(h.pageType));return x.compact([...Be,...j])},[_,X,i,b]);return t.jsxs("div",{className:"flex flex-col justify-between h-full",children:[t.jsxs("div",{className:"flex flex-col h-full space-y-6",children:[t.jsxs("div",{className:"relative flex item-center gap-x-4",children:[t.jsx(N.Search,{strokeWidth:2.5,className:"absolute left-3 top-2.5 h-4 w-4 text-gray-400"}),t.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:i,onChange:I=>l(I.target.value)}),!x.isEmpty(b)&&t.jsxs(c.Select,{value:b,onValueChange:O,children:[t.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:t.jsx(c.SelectValue,{placeholder:"Select page type"})}),t.jsxs(c.SelectContent,{align:"end",children:[t.jsx(c.SelectItem,{value:"all",children:"All"},"all"),!x.isEmpty(x.filter(M,I=>I.hasSlug))&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"px-2 py-1.5 text-xs font-semibold text-gray-500 mt-2 border-t pt-2",children:"Pages"}),x.map([...x.filter(M,I=>I.hasSlug)].sort((I,ae)=>x.get(I,"name","").localeCompare(x.get(ae,"name",""))),I=>t.jsx(c.SelectItem,{value:x.get(I,"key"),children:x.get(I,"name")},x.get(I,"key")))]}),!x.isEmpty(x.filter(M,I=>!I.hasSlug))&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"px-2 py-1.5 text-xs font-semibold text-gray-500 mt-2 border-t pt-2",children:"Partials"}),x.map([...x.filter(M,I=>!I.hasSlug)].sort((I,ae)=>x.get(I,"name","").localeCompare(x.get(ae,"name",""))),I=>t.jsx(c.SelectItem,{value:x.get(I,"key"),children:x.get(I,"name")},x.get(I,"key")))]})]})]})]}),w?t.jsx("div",{className:"space-y-2",children:x.map([...Array(5).keys()],I=>t.jsx("div",{className:"w-full bg-gray-200 rounded h-9 animate-pulse"},I))}):x.isEmpty(V)?t.jsxs("div",{className:"h-[70vh] flex flex-col gap-y-1 items-center justify-center text-slate-500 text-sm font-medium",children:[t.jsx(N.File,{className:"h-6 w-6 stroke-[1]"}),"Empty List!",t.jsx("span",{className:"font-light",children:"Add new page to start"})]}):t.jsx("div",{className:"text-sm text-slate-700 space-y-2 h-[70vh] overflow-y-auto",children:x.map(V,I=>t.jsx(Sn,{item:I,currentPage:K,close:e,setUnpublishPage:m,setDeletePage:u,setAddEditPage:v,setMarkAsTemplate:p,setUnmarkAsTemplate:E,setDuplicatePage:r,level:0},`page-item-${I.id}`))})]}),F(fe.ADD_PAGE)&&t.jsxs(c.Button,{className:"flex text-sm gap-x-2",onClick:()=>{v({slug:"",name:"",pageType:b==="all"?"page":b})},children:[t.jsx(N.Plus,{className:"w-4 h-4"})," Add New"]}),f&&t.jsx(jr,{closePanel:e,editPage:je,addEditPage:f,setAddEditPage:v}),o&&t.jsx(vn,{page:o,onClose:()=>u(null)}),d&&t.jsx(ks,{page:d,onClose:()=>m(null)}),y&&t.jsx(wr,{page:y,onClose:()=>p(null)}),S&&t.jsx(Nr,{page:S,onClose:()=>E(null)}),a&&t.jsx(Er,{page:a,onClose:()=>r(null)})]})},Sn=({item:e,currentPage:s,close:n,setUnpublishPage:a,setDeletePage:r,setAddEditPage:i,setMarkAsTemplate:l,setUnmarkAsTemplate:o,setDuplicatePage:u,parentSlug:d,level:m=0})=>{const f=!x.isEmpty(e==null?void 0:e.children);return t.jsxs("div",{className:"border-0",children:[t.jsx(Cr,{closePanel:n,setUnpublishPage:a,setDeletePage:r,setAddEditPage:i,setMarkAsTemplate:l,setUnmarkAsTemplate:o,setDuplicatePage:u,active:s===e.id,page:e,parentSlug:d}),f&&t.jsx("div",{className:"pt-2 pl-6 bg-white",children:x.map(x.get(e,"children",[]),v=>t.jsx(Sn,{item:v,currentPage:s,close:n,setUnpublishPage:a,setDeletePage:r,setAddEditPage:i,setMarkAsTemplate:l,setUnmarkAsTemplate:o,setDuplicatePage:u,parentSlug:e.slug,level:m+1},v.id||`child-${m}-${v.key}`))})]},e.id||`level-${m}-${e.key}`)},Pr=()=>{const e=Fe("logo",null);return e?t.jsx("div",{className:"w-full max-h-9 overflow-hidden pr-2",children:g.createElement(e,{})}):null},Ir=()=>{const[e]=Pe(),s=e.get("page"),{data:n,isFetching:a}=Ie(),[r,i]=g.useState(!1),{savePage:l}=ee.useSavePage(),o=!!s&&!x.isEmpty(n),u=!s||!a&&x.isEmpty(n)||r;return t.jsxs(t.Fragment,{children:[t.jsxs(c.Button,{variant:"secondary",className:"flex items-center w-full space-x-2 py-1",onClick:()=>{l(),i(!0)},children:[t.jsx("div",{children:t.jsx(N.Logs,{className:"h-4 w-4"})}),t.jsxs("span",{className:"truncate leading-tight flex items-center max-w-[200px]",children:[t.jsx("span",{className:"text-slate-600 pr-1 font-light",children:"Editing:"}),a?t.jsx(N.Loader,{className:"h-4 w-4 animate-spin text-slate-400 ml-2"}):x.startCase(x.get(n,"name"))??""]})]},"template-viewer"),t.jsx(c.Sheet,{open:u,onOpenChange:d=>!d&&o&&i(!1),children:t.jsxs(c.SheetContent,{side:"left","aria-describedby":"pages-manager-description",className:`!max-w-screen-md z-50 border-border w-full ${o?"":"sheet-hide-close-btn"}`,children:[t.jsxs(c.SheetHeader,{className:"mb-3",children:[t.jsxs(c.SheetTitle,{className:"text-sm flex items-center gap-2 font-semibold",children:[t.jsx("div",{className:"p-2 rounded-md bg-primary text-primary-foreground",children:t.jsx(N.File,{className:"w-6 h-6"})}),t.jsxs("div",{className:"flex flex-col",children:[t.jsx("span",{className:"text-sm font-semibold",children:"Pages"}),t.jsx("span",{id:"pages-manager-description",className:"text-xs text-muted-foreground",children:"Manage your site structure"})]})]}),t.jsx(c.SheetDescription,{className:"sr-only",children:"Manage your site structure"})]}),t.jsx("div",{className:"h-[calc(100vh-100px)] overflow-y-auto",children:t.jsx(Tr,{isOpen:u,close:()=>i(!1)})})]})})]})},_r=()=>{const{fallbackLang:e,languages:s,selectedLang:n,setSelectedLang:a}=ee.useLanguages(),r=x.isEmpty(n)?e:n,[,i]=Pe();g.useEffect(()=>{const p=new URLSearchParams(window.location.search),S=p.get("lang");S&&(s.includes(S)?a(S):(p.delete("lang"),i(p),a("")))},[s,i,a]);const[l,o]=g.useState(null),{data:u}=Ie(),{data:d}=Ve(),{data:m,isFetching:f}=Xe(),v=g.useMemo(()=>{const p=x.compact(x.map(x.get(d,"languages"),S=>{const E=x.find(m,{lang:S});return{key:S,value:x.get(Le,S,S),isLangPageAdded:!!E}})).filter(Boolean);return[{key:e,value:x.get(Le,e),isLangPageAdded:!0},...p]},[e,m,d]),y=p=>{a(p);const S=new URLSearchParams(window.location.search);p===e?S.delete("lang"):S.set("lang",p);const E=S.toString(),_=`${window.location.pathname}${E?`?${E}`:""}`;window.history.pushState({},"",_),i(S),window.dispatchEvent(new PopStateEvent("popstate"))};return x.isEmpty(s)||f?null:t.jsxs(t.Fragment,{children:[t.jsxs(c.DropdownMenu,{children:[t.jsx(c.DropdownMenuTrigger,{asChild:!0,className:"focus:outline-none",children:t.jsxs(c.Button,{variant:"ghost",size:"sm",className:"gap-2",children:[t.jsx(N.Languages,{className:"w-4 h-4"}),x.get(Le,r,r),t.jsx(N.ChevronDown,{className:"w-4 h-4"})]})}),t.jsxs(c.DropdownMenuContent,{className:"border-border space-y-1",children:[x.map(v.filter(p=>p.isLangPageAdded),p=>t.jsxs(c.DropdownMenuItem,{className:ee.mergeClasses("flex cursor-pointer items-center justify-between text-xs font-medium text-gray-800",p.key===r&&"!bg-gray-200 text-gray-700"),onClick:()=>y(p.key),children:[t.jsx("div",{className:"text-slate-600",children:p.value}),p.key===e&&t.jsxs("small",{className:"text-[9px] flex items-center gap-x-1 text-orange-500 leading-none",children:[t.jsx(N.Star,{fill:"orange",className:"w-2 h-2"}),"Primary"]})]},p.value)),!x.isEmpty(v.filter(p=>!p.isLangPageAdded))&&t.jsxs(t.Fragment,{children:[t.jsx(c.Separator,{}),t.jsxs(c.Button,{size:"sm",variant:"ghost",onClick:()=>{o({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:[t.jsx(N.Plus,{className:"w-3 h-3 mr-1"})," Add Langauge"]})]})]})]}),l&&t.jsx(jn,{languages:s,langProps:l,onClose:()=>o(null)})]})};function kr(){return t.jsxs("div",{className:"flex relative z-10 items-center justify-end gap-1",children:[t.jsx(Pr,{}),t.jsx(Ir,{}),t.jsx(_r,{})]})}function Dr(e){const s=ne(),n=$();return L.useQuery({queryKey:[z,"revisions",e],queryFn:async()=>await n(s,{action:P.GET_PAGE_REVISIONS,data:{pageId:e}}),enabled:!!e,gcTime:0,staleTime:0})}const Lr=()=>{const e=ne(),s=$(),n=L.useQueryClient();return L.useMutation({mutationFn:async a=>await s(e,{action:P.DELETE_PAGE_REVISION,data:{revisionId:a}}),onSuccess:()=>{n.invalidateQueries({queryKey:[z,"revisions"]})}})},Br=()=>{const e=ne(),s=$(),n=L.useQueryClient();return L.useMutation({mutationFn:async({revisionId:a,discardCurrent:r})=>await s(e,{action:P.RESTORE_PAGE_REVISION,data:{revisionId:a,discardCurrent:r}}),onSuccess:()=>{n.invalidateQueries({queryKey:[z,"revisions"]})}})};function Gr(){const{data:e}=Ie(),{saveState:s}=ee.useSavePage(),[n]=Cs();return e?t.jsx("div",{className:"flex items-start gap-3 rounded-md border p-2 hover:bg-accent/50 bg-primary/5 mb-4",children:t.jsxs("div",{className:"flex-1 space-y-1",children:[t.jsx("div",{className:"flex items-center justify-between",children:t.jsx("p",{className:"text-sm flex items-center gap-1 font-medium leading-none",children:t.jsx("span",{className:"font-bold",children:"Currently editing"})})}),t.jsx("div",{className:"flex items-center text-xs text-muted-foreground",children:!x.isEmpty(n.lastSaved)&&t.jsxs("span",{children:["Last updated"," ",qt.formatDistanceToNow(new Date(n.lastSaved),{addSuffix:!0})]})}),t.jsxs("div",{className:"flex items-center gap-2 pt-0.5",children:[t.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:[t.jsx(N.Edit,{className:"h-3 w-3"}),t.jsx("span",{children:"Draft"})]}),s==="UNSAVED"?t.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:[t.jsx(N.Save,{className:"h-3 w-3"}),t.jsx("span",{children:" Unsaved changes"})]}):null]})]})}):null}function Mr(){const[e,s]=pe.useState(!1),[n,a]=pe.useState(null),[r,i]=pe.useState(!1),[l,o]=pe.useState(!1),{data:u}=Ie(),{data:d,isFetching:m,error:f,refetch:v}=Dr(u==null?void 0:u.id),{mutate:y,isPending:p}=Lr(),{mutate:S,isPending:E}=Br(),_=L.useQueryClient(),w=F=>{n&&S({revisionId:n.uid,discardCurrent:F},{onSuccess:()=>{i(!1),a(null),_.invalidateQueries({queryKey:[z,P.GET_DRAFT_PAGE]})}})},k=F=>{a(F),i(!0)},b=F=>{a(F),o(!0)},B=()=>{n&&y(n.uid,{onSuccess:()=>{o(!1),a(null)}})};return g.useEffect(()=>{e&&v()},[e,v]),t.jsxs(t.Fragment,{children:[t.jsx(c.TooltipProvider,{children:t.jsxs(c.Tooltip,{children:[t.jsxs(c.Sheet,{open:e,onOpenChange:s,children:[t.jsx(c.SheetTrigger,{asChild:!0,children:t.jsx(c.TooltipTrigger,{asChild:!0,children:t.jsxs("span",{className:"flex items-center gap-2",children:[t.jsxs(c.Button,{variant:"ghost",size:"icon",className:"h-8 w-8",children:[t.jsx(N.History,{className:"h-4 w-4"}),t.jsx("span",{className:"sr-only",children:"View revision history"})]}),t.jsx("div",{className:"w-px h-4 bg-gray-200 dark:bg-gray-700"})]})})}),t.jsxs(c.SheetContent,{className:"sm:max-w-md p-4",children:[t.jsxs(c.SheetHeader,{className:"pb-2",children:[t.jsxs(c.SheetTitle,{className:"flex items-center gap-2",children:[t.jsx(N.History,{className:"h-5 w-5"}),"Revision History"]}),(u==null?void 0:u.createdAt)&&t.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:["Page created on"," ",qt.format(new Date(u.createdAt),"MMM d, yyyy 'at' h:mm a")]})]}),t.jsx(c.ScrollArea,{className:"h-[calc(100vh-6rem)] pr-2",children:m?t.jsx(Ur,{}):f?t.jsx("div",{className:"p-4 text-center text-sm text-muted-foreground",children:"Failed to load revisions. Please try again."}):t.jsxs("div",{className:"mt-2 space-y-2",children:[t.jsx(Gr,{}),d==null?void 0:d.map(F=>t.jsx(Or,{revision:F,isLatest:F.uid==="current",onRestore:()=>k(F),onDelete:()=>b(F)},F.uid))]})})]})]}),t.jsx(c.TooltipContent,{side:"bottom",children:t.jsx("p",{children:"Revision history"})})]})}),t.jsx(Fr,{open:r,onOpenChange:i,revision:n,onRestore:w,isRestoring:E}),t.jsx(qr,{open:l,onOpenChange:o,revision:n,onDelete:B,isDeleting:p})]})}function Ur(){return t.jsx("div",{className:"space-y-2 mt-2",children:Array.from({length:5}).map((e,s)=>t.jsxs("div",{className:"flex items-start gap-3 rounded-md border p-2",children:[t.jsxs("div",{className:"flex-1 space-y-1",children:[t.jsx(c.Skeleton,{className:"h-4 w-3/4"}),t.jsx(c.Skeleton,{className:"h-3 w-1/2"}),t.jsx(c.Skeleton,{className:"h-5 w-20 mt-1"})]}),t.jsx(c.Skeleton,{className:"h-8 w-8 rounded-full"})]},s))})}function Or({revision:e,isLatest:s,onRestore:n,onDelete:a}){const{data:r}=Ze(e.currentEditor),i=(r==null?void 0:r.name)||"Unknown";return t.jsxs("div",{className:"flex items-start gap-3 rounded-md border p-2 hover:bg-accent/50",children:[t.jsxs("div",{className:"flex-1 space-y-1",children:[t.jsx("div",{className:"flex items-center justify-between",children:t.jsxs("p",{className:"text-sm flex items-center gap-1 font-medium leading-none",children:[e.type==="published"?"Published":"Draft"," by ",t.jsx("span",{className:"font-bold",children:i}),s&&t.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:[t.jsxs("span",{className:"mr-1 relative flex h-2 w-2",children:[t.jsx("span",{className:"animate-ping absolute inline-flex h-full w-full rounded-full bg-green-400 opacity-75"}),t.jsx("span",{className:"relative inline-flex rounded-full h-2 w-2 bg-green-500"})]}),"Live"]})]})}),t.jsx("div",{className:"flex items-center text-xs text-muted-foreground",children:t.jsx("span",{children:qt.format(e.createdAt,"MMM d, h:mm a")})}),t.jsx("div",{className:"flex items-center gap-2 pt-0.5",children:e.type==="published"?t.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:[t.jsx(N.ArrowUpRight,{className:"h-3 w-3"}),t.jsx("span",{children:"Published"})]}):t.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:[t.jsx(N.Clock,{className:"h-3 w-3"}),t.jsx("span",{children:"Draft"})]})})]}),t.jsx(ke,{permissions:[fe.RESTORE_REVISION,fe.DELETE_REVISION],children:t.jsx(Rr,{revision:e,onRestore:n,onDelete:a})})]})}function Rr({revision:e,onRestore:s,onDelete:n}){return t.jsxs(c.DropdownMenu,{children:[t.jsx(c.DropdownMenuTrigger,{asChild:!0,children:t.jsxs(c.Button,{variant:"ghost",size:"icon",className:"h-7 w-7 -mr-1",children:[t.jsx(N.MoreHorizontal,{className:"h-4 w-4"}),t.jsx("span",{className:"sr-only",children:"More options"})]})}),t.jsxs(c.DropdownMenuContent,{align:"end",className:"text-xs",children:[t.jsx(ke,{permission:fe.RESTORE_REVISION,children:t.jsxs(c.DropdownMenuItem,{onClick:s,className:"cursor-pointer",children:[t.jsx(N.Undo2,{className:"mr-2 h-4 w-4"}),t.jsx("span",{children:"Restore this version"})]})}),t.jsx(ke,{permission:fe.DELETE_REVISION,children:e.uid!=="current"&&t.jsxs(t.Fragment,{children:[t.jsx(c.DropdownMenuSeparator,{}),t.jsxs(c.DropdownMenuItem,{onClick:n,className:"cursor-pointer text-destructive",children:[t.jsx(N.Trash,{className:"mr-2 h-4 w-4"}),t.jsx("span",{children:"Delete this version"})]})]})})]})]})}function Fr({open:e,onOpenChange:s,revision:n,onRestore:a,isRestoring:r}){const{data:i}=Ze((n==null?void 0:n.currentEditor)||""),l=(i==null?void 0:i.name)||"Unknown";return n?t.jsx(c.Dialog,{open:e,onOpenChange:o=>{r||s(o)},children:t.jsxs(c.DialogContent,{className:"sm:max-w-md",children:[t.jsxs(c.DialogHeader,{children:[t.jsx(c.DialogTitle,{children:"Restore Revision"}),t.jsxs(c.DialogDescription,{children:["You are about to restore to revision ",n.uid.substring(0,8)," ","from ",qt.format(n.createdAt,"MMM d, yyyy 'at' h:mm a")," by"," ",l]})]}),t.jsx("div",{className:"py-2",children:t.jsx("p",{className:"text-sm text-muted-foreground",children:"How would you like to handle your current edits?"})}),t.jsxs(c.DialogFooter,{className:"flex flex-col sm:flex-row gap-2",children:[t.jsx(c.Button,{variant:"outline",className:"sm:flex-1",onClick:()=>a(!1),disabled:r,children:r?t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"mr-2 h-4 w-4 animate-spin rounded-full border-2 border-current border-t-transparent"}),"Saving as draft..."]}):t.jsxs(t.Fragment,{children:[t.jsx(N.CloudOff,{className:"mr-2 h-4 w-4"}),"Save as draft"]})}),t.jsx(c.Button,{variant:"default",className:"sm:flex-1",onClick:()=>a(!0),disabled:r,children:r?t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"mr-2 h-4 w-4 animate-spin rounded-full border-2 border-current border-t-transparent"}),"Discarding current..."]}):t.jsxs(t.Fragment,{children:[t.jsx(N.Undo2,{className:"mr-2 h-4 w-4"}),"Discard current"]})})]})]})}):null}function qr({open:e,onOpenChange:s,revision:n,onDelete:a,isDeleting:r}){const{data:i}=Ze((n==null?void 0:n.currentEditor)||""),l=(i==null?void 0:i.name)||"Unknown";return n?t.jsx(c.Dialog,{open:e,onOpenChange:o=>{r||s(o)},children:t.jsxs(c.DialogContent,{className:"sm:max-w-md",children:[t.jsxs(c.DialogHeader,{children:[t.jsx(c.DialogTitle,{children:"Delete Revision"}),t.jsxs(c.DialogDescription,{children:["You are about to delete revision ",n.uid.substring(0,8)," from"," ",qt.format(n.createdAt,"MMM d, yyyy 'at' h:mm a")," by"," ",l]})]}),t.jsx("div",{className:"py-2",children:t.jsx("p",{className:"text-sm text-muted-foreground",children:"This action cannot be undone. Are you sure you want to proceed?"})}),t.jsxs(c.DialogFooter,{className:"flex flex-col sm:flex-row gap-2",children:[t.jsx(c.Button,{variant:"outline",className:"sm:flex-1",onClick:()=>s(!1),disabled:r,children:"Cancel"}),t.jsx(c.Button,{variant:"destructive",className:"sm:flex-1",onClick:a,disabled:r,children:r?t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"mr-2 h-4 w-4 animate-spin rounded-full border-2 border-current border-t-transparent"}),"Deleting..."]}):t.jsxs(t.Fragment,{children:[t.jsx(N.Trash,{className:"mr-2 h-4 w-4"}),"Delete Revision"]})})]})]})}):null}const zr=()=>{const e=ne(),s=$();return L.useQuery({queryKey:[z,P.GET_CHANGES],queryFn:async()=>s(e,{action:P.GET_CHANGES})})},Hr=({currentEditor:e})=>{const{data:s}=Ze(e);return s==null?void 0:s.name};function $r({showModal:e=!1,onClose:s=()=>console.log("Cancelled")}){const[n,a]=g.useState([]),{data:r,isFetching:i}=zr(),{data:l}=Ce(),o=g.useCallback(b=>{var B;return(B=x.find(l,{key:b}))==null?void 0:B.hasSlug},[l]),u=g.useMemo(()=>x.filter(l,b=>!o(b.key)).map(b=>b.key),[o,l]),d=g.useMemo(()=>x.filter(r,b=>!u.includes(b.pageType)),[r,u]),m=g.useMemo(()=>x.filter(r,b=>u.includes(b.pageType)),[r,u]),f=g.useMemo(()=>x.find(r,{pageType:"theme",id:"THEME"}),[r]),{mutate:v,isPending:y}=Is();g.useEffect(()=>{const b=x.map(x.filter(r,{online:!0}),"id");f&&b.push(f==null?void 0:f.id),a(b)},[r,f]);const p=n.length===(r==null?void 0:r.length),S=b=>{a(B=>x.includes(B,b)?x.filter(B,F=>F!==b):x.concat(B,b))},E=()=>{a(p?[]:x.map(r,"id"))},_=()=>{v({ids:x.uniq(n)},{onSuccess:()=>{s(),Zt("CENTER_CENTER")}})},w=b=>{if(b==="theme")return"Theme";const B=x.find(l,{key:b});return B?B==null?void 0:B.name:b},k=g.useMemo(()=>{const b=[{label:"Updated",top:"pt-2"},...x.orderBy(x.filter(d,{online:!0}),"pageType"),...x.orderBy(x.filter(m,{online:!0}),"pageType")].filter(te=>te.pageType!=="theme"),B=[{label:"Offline",top:"pt-6"},...x.orderBy(x.filter(d,{online:!1}),"pageType"),...x.orderBy(x.filter(m,{online:!1}),"pageType")],F=f?[{label:"Theme",top:"pt-6"},f]:[];return[...b,...F,...B]},[d,m,f]);return t.jsx(c.Dialog,{open:e,onOpenChange:y?()=>{}:s,children:t.jsxs(c.DialogContent,{className:"max-w-4xl max-h-[80%] flex flex-col",children:[t.jsxs(c.DialogHeader,{children:[t.jsx(c.DialogTitle,{children:"Publish changes"}),t.jsx(c.DialogDescription,{className:"text-xs",children:"Select the pages you want to publish. Click publish when you're done."})]}),t.jsx("div",{className:"relative h-full max-h-full -mx-4 overflow-y-auto no-scrollbar",children:i?t.jsxs("div",{className:"px-1 space-y-2",children:[t.jsx("div",{className:"w-full h-6 mt-2 bg-gray-200 rounded animate-pulse"}),t.jsx("div",{className:"w-full h-6 bg-gray-200 rounded animate-pulse"}),t.jsx("div",{className:"w-full h-6 bg-gray-200 rounded animate-pulse"}),t.jsx("div",{className:"w-full h-6 bg-gray-200 rounded animate-pulse"})]}):t.jsxs("table",{className:"w-full text-xs text-left text-gray-500 rtl:text-right dark:text-gray-400",children:[t.jsx("thead",{className:"text-gray-700 border-b bg-gray-50 dark:bg-gray-700 dark:text-gray-400",children:t.jsxs("tr",{children:[t.jsxs("th",{scope:"col",className:"px-6 py-3 flex items-center gap-x-2 w-[1 50px]",children:[t.jsx("input",{checked:p,onClick:b=>{b.stopPropagation(),E()},type:"checkbox",className:"mt-1 rounded cursor-pointer focus:outline-none focus:ring-0"}),"Name"]}),t.jsx("th",{scope:"col",className:"px-2 py-3 w-[100px]",children:"Language"}),t.jsx("th",{scope:"col",className:"px-2 py-3 w-[100px]",children:"Type"}),t.jsx("th",{scope:"col",className:"px-4 py-3 w-[150px] text-right",children:"Status"})]})}),t.jsx("tbody",{children:x.map(k,b=>b.label?t.jsx("tr",{children:t.jsxs("td",{colSpan:4,className:`px-6 py-2 text-xs font-medium text-gray-800 relative ${b.top}`,children:[t.jsx("div",{className:"absolute inset-0 flex items-center left-6",children:t.jsx("div",{className:"w-full order-gray-300"})}),t.jsx("div",{className:"relative flex justify-start",children:t.jsx("span",{className:"pr-2 bg-gray-50",children:b.label})})]})},"separator"):t.jsxs("tr",{className:"border-b group hover:bg-gray-50 last:border-b-0",children:[t.jsxs("td",{scope:"row",className:"flex items-center px-6 py-2 text-gray-900 whitespace-nowrap dark:text-white gap-x-1",children:[t.jsx("input",{checked:x.includes(n,b==null?void 0:b.id),onClick:B=>{B.stopPropagation(),S(b==null?void 0:b.id)},type:"checkbox",className:"rounded cursor-pointer focus:outline-none focus:ring-0"})," ",o(b.pageType)?t.jsx(N.File,{className:"w-4 h-4"}):t.jsx(N.GlobeIcon,{className:"w-4 h-4"}),b.name,b.slug&&t.jsxs("span",{className:"text-xs text-gray-500",children:["(",b.slug,")"]}),b.currentEditor&&t.jsx("div",{className:"flex items-center gap-x-1",children:t.jsxs("span",{className:"flex text-xs font-bold text-gray-500",children:[" ","-"," ",t.jsx(Hr,{currentEditor:b.currentEditor})," ","is editing"]})})]}),t.jsx("td",{className:"px-2",children:b.lang}),t.jsx("td",{className:"px-2",children:w(b==null?void 0:b.pageType)}),t.jsx("td",{className:"px-4 text-right",children:x.first(b.changes)||""})]},b==null?void 0:b.id))})]})}),t.jsxs(c.DialogFooter,{className:"mt-10",children:[t.jsx(c.Button,{disabled:y,variant:"outline",onClick:s,children:"Cancel"}),t.jsx(c.Button,{disabled:y||i||x.isEmpty(r),onClick:_,children:y?"Publishing...":"Publish"})]})]})})}const Kr=()=>{const e=$(),s=ne();return L.useQuery({queryKey:[P.GET_WEBSITE_DATA],staleTime:1e3*60*5,queryFn:async()=>e(s,{action:P.GET_WEBSITE_DATA,data:{draft:!0}})})};function Vr({onClose:e}){const{data:s,isFetching:n}=Kr(),{mutateAsync:a,isPending:r}=ka(),i=Fe("settingComponent",null),l=x.debounce(async o=>(await a({data:o}),!0),300);return i?t.jsx(c.Dialog,{open:!0,onOpenChange:e,children:t.jsxs(c.DialogContent,{className:"w-full",children:[t.jsx(c.DialogHeader,{children:t.jsx(c.DialogTitle,{children:"Website Settings"})}),n?t.jsxs("div",{className:"w-full space-y-3 py-4",children:[t.jsx("div",{className:"w-full h-8 rounded bg-gray-300 animate-pulse"}),t.jsx("div",{className:"w-full h-8 rounded bg-gray-300 animate-pulse"}),t.jsx("div",{className:"w-full h-8 rounded bg-gray-300 animate-pulse"}),t.jsx("div",{className:"w-full h-8 rounded bg-gray-300 animate-pulse"}),t.jsx("div",{className:"w-full h-8 rounded bg-gray-300 animate-pulse"}),t.jsx("div",{className:"w-full h-8 rounded bg-gray-300 animate-pulse"})]}):t.jsx("div",{children:g.createElement(i,{data:s||{},onSave:r?()=>{}:l,cancel:r?()=>{}:e})})]})}):null}function wn({children:e,content:s}){return t.jsx(c.TooltipProvider,{children:t.jsxs(c.Tooltip,{children:[t.jsx(c.TooltipTrigger,{asChild:!0,children:e}),t.jsx(c.TooltipContent,{side:"bottom",sideOffset:10,children:t.jsx("p",{children:s})})]})})}const Wr=()=>{const{selectedLang:e,fallbackLang:s}=ee.useLanguages(),n=Fe("getPreviewUrl",async f=>f),[a,r]=g.useState(""),{data:i}=Ie(),{data:l}=Xe(),{data:o}=Ce(),u=g.useMemo(()=>{var f;return(f=l==null?void 0:l.find(v=>(v==null?void 0:v.lang)===e))==null?void 0:f.slug},[e,l]),d=g.useCallback(f=>{var v;return(v=x.find(o,{key:f}))==null?void 0:v.hasSlug},[o]),m=e===s?"":e;return g.useEffect(()=>{(async()=>{if(typeof n=="function"){const f=!d(i==null?void 0:i.pageType),v=await n(f?`${m!==""?m+"/":""}${i==null?void 0:i.id}`:u||"");r(v)}else r("")})()},[n,u,i==null?void 0:i.pageType,d,i==null?void 0:i.id,m]),t.jsx(t.Fragment,{children:t.jsx("a",{href:a,target:"_blank",rel:"noopener noreferrer",children:t.jsxs(c.Button,{variant:"ghost",size:"sm",className:"gap-2",children:[t.jsx(N.Eye,{className:"w-4 h-4"})," ",Q.PREVIEW]})})})},Qr=()=>{const[e,s]=ee.useRightPanel();return t.jsxs(t.Fragment,{children:[t.jsx(wn,{content:Q.THEME,children:t.jsx(c.Button,{variant:e==="theme"?"outline":"ghost",size:"icon",className:"gap-2",onClick:()=>s(e==="theme"?"block":"theme"),children:t.jsx(N.Palette,{className:"w-4 h-4"})})}),t.jsx("div",{className:"w-px h-4 bg-gray-200 dark:bg-gray-700"})]})},Yr=()=>{const[e,s]=g.useState(!1),{isLocked:n}=$t(),{savePage:a,saveState:r}=ee.useSavePage();g.useEffect(()=>{const m=f=>{r==="UNSAVED"&&(f.preventDefault(),f.returnValue=!1)};return r==="UNSAVED"&&window.addEventListener("beforeunload",m),()=>{window.removeEventListener("beforeunload",m)}},[r]);const i=g.useCallback(async()=>{s(!0),await a(!1)},[a]);g.useEffect(()=>{r==="SAVED"&&s(!1)},[r]);const l=g.useMemo(()=>{if(r==="SAVED"||r==="UNSAVED")return r;if(r==="SAVING")return e?r:"SAVED"},[e,r]),{buttonIcon:o,buttonClass:u,tooltipContent:d}=g.useMemo(()=>{switch(l){case"UNSAVED":return{tooltipContent:Q.SAVEDRAFT,buttonIcon:t.jsx(N.Save,{className:"w-4 h-4"}),buttonClass:"flex items-center gap-x-1 leading-tight"};case"SAVING":return{tooltipContent:Q.SAVING,buttonIcon:t.jsx(N.Loader,{className:"w-4 h-4 animate-spin"}),buttonClass:"flex items-center gap-x-1 leading-tight"};case"SAVED":return{tooltipContent:Q.SAVED,buttonIcon:t.jsx(N.CheckCircle,{className:"w-4 h-4"}),buttonClass:"text-green-500 flex items-center gap-x-1 leading-tight"}}},[l]);return n?null:t.jsxs(c.Button,{size:"sm",variant:"ghost",onClick:i,className:u,children:[o," ",d]})},Xr=()=>{const[e,s]=g.useState(!1),[n,a]=g.useState(!1),[r,i]=g.useState(null),{data:l}=Ie(),{mutate:o,isPending:u}=Is(),[d]=ee.useBlocksStore(),{buttonText:m,buttonClassName:f,isPublished:v}=g.useMemo(()=>{const p=l&&(l==null?void 0:l.online);return{buttonClassName:p?"hover:bg-green-600 bg-green-500":"",isPublished:p,buttonText:p?Q.PUBLISHED:Q.PUBLISH}},[l]),y=async()=>{var S,E;const p=((E=(S=d==null?void 0:d.filter(_=>(_==null?void 0:_._type)==="PartialBlock"))==null?void 0:S.map(_=>_==null?void 0:_.partialBlockId))==null?void 0:E.filter(_=>typeof _=="string"&&_!==""))||[];o({ids:[l==null?void 0:l.id,...p]},{onSuccess:()=>Zt("TOP_RIGHT")})};return t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"flex",children:[t.jsxs(c.Button,{size:"sm",onClick:y,disabled:u||!(l!=null&&l.id),className:`relative overflow-hidden transition-all duration-300 ease-in-out text-white flex items-center gap-1 rounded-r-none ${f}`,onMouseEnter:()=>a(!0),onMouseLeave:()=>a(!1),children:[t.jsx("span",{className:`flex items-center transition-transform duration-300 ease-in-out ${n?"-translate-y-10":""}`,children:v?t.jsx(N.Send,{className:"w-4 h-4"}):t.jsx(N.Rocket,{className:"w-4 h-4"})}),t.jsx("span",{className:`absolute inset-0 flex items-center left-3 transition-transform duration-300 ease-in-out ${n?"":"translate-y-10"}`,children:v?t.jsx(N.Rocket,{className:"w-4 h-4"}):t.jsx(N.Send,{className:"w-4 h-4"})}),t.jsx("span",{children:m})]}),t.jsxs(c.DropdownMenu,{children:[t.jsx(c.DropdownMenuTrigger,{asChild:!0,children:t.jsx(c.Button,{size:"sm",disabled:u||!(l!=null&&l.id),className:`px-2 text-white border-l border-white/50 rounded-l-none ${f}`,children:t.jsx(N.ChevronDown,{className:"w-4 h-4"})})}),t.jsxs(c.DropdownMenuContent,{align:"end",className:"w-36",children:[!v&&t.jsxs(c.DropdownMenuItem,{disabled:u,className:"text-xs cursor-pointer",onClick:()=>o({ids:[l==null?void 0:l.id]},{onSuccess:()=>Zt("TOP_RIGHT")}),children:[Q.PUBLISH," page"]}),t.jsxs(c.DropdownMenuItem,{onClick:()=>s(!0),className:"text-xs cursor-pointer",children:[Q.OPEN," publish menu"]}),v&&t.jsxs(c.DropdownMenuItem,{onClick:()=>i(l),className:"text-xs cursor-pointer",children:[Q.UNPUBLISH," page"]})]})]})]}),t.jsx($r,{showModal:e,onClose:()=>s(!1)}),r&&t.jsx(ks,{page:r,onClose:()=>i(null)})]})},Zr=()=>{const e=Fe("settingComponent",null),[s,n]=g.useState(!1);return e?t.jsxs(t.Fragment,{children:[t.jsx(wn,{content:Q.WEBSITEDATA,children:t.jsx(c.Button,{variant:"ghost",size:"icon",className:"gap-2",onClick:()=>n(!0),children:t.jsx(N.Settings,{className:"w-4 h-4"})})}),s&&t.jsx(Vr,{onClose:()=>n(!1)}),t.jsx("div",{className:"w-px h-4 bg-gray-200 dark:bg-gray-700"})]}):null},Jr=()=>{const{data:e}=Ie(),[s,n]=g.useState(""),a=e&&(e==null?void 0:e.online),{data:r}=Ce(),i=Fe("getLiveUrl",async v=>v),l=g.useCallback(v=>{var y;return(y=x.find(r,{key:v}))==null?void 0:y.hasSlug},[r]),{selectedLang:o,fallbackLang:u}=ee.useLanguages(),d=e==null?void 0:e.id,m=e==null?void 0:e.slug,f=o===u?"":o;return g.useEffect(()=>{(async()=>{if(typeof i=="function"){const v=!l(e==null?void 0:e.pageType),y=await i(v?`${f===""?"":f+"/"}${d}`:m||"");n(y)}else n("")})()},[i,e==null?void 0:e.pageType,l,d,m,f]),t.jsxs(c.Button,{onClick:()=>a&&window.open(s,"_blank"),disabled:!a,variant:"ghost",size:"sm",className:"flex items-center gap-1",children:[t.jsx(N.ExternalLink,{className:"w-4 h-4"}),t.jsx("span",{className:"hidden sm:inline",children:Q.OPEN})]})};function ei(){const{isLocked:e}=$t(),[s]=Pe(),n=s.get("lang"),a=hn(n);return e||!a?null:t.jsxs("div",{className:"flex items-center justify-end gap-1",children:[t.jsx(Mr,{}),t.jsx(ke,{permission:fe.EDIT_THEME,children:t.jsx(Qr,{})}),t.jsx(ke,{permission:fe.EDIT_SETTINGS,children:t.jsx(Zr,{})}),t.jsx(Wr,{}),t.jsx(ke,{permission:fe.SAVE_PAGE,children:t.jsx(Yr,{})}),t.jsx(ke,{permission:fe.PUBLISH_PAGE,children:t.jsx(Xr,{})}),t.jsx(Jr,{})]})}const ti=()=>t.jsxs("div",{className:"flex px-2 h-full items-center justify-between w-full",children:[t.jsx(kr,{}),t.jsx(ei,{})]}),si=()=>{const e=ne(),{aiContext:s}=As(),n=$();return g.useCallback(async(a,r,i,l)=>n(e,{action:P.ASK_AI,data:{type:a,prompt:r,blocks:i,context:s,lang:l}}),[e,s,n])},ni=(e,s)=>s.map(n=>{if(x.has(e,n._type)){const a=ln.getDefaultBlockProps(n._type);return{...a,...x.pick(n,[...x.keys(a),"_type","_id","_name","_parent","_bindings"]),...x.pickBy(n,(r,i)=>x.endsWith(i,"_attrs")),...n}}return n}),ai=e=>{const s=ln.useRegisteredChaiBlocks();return g.useMemo(()=>{if(!e||x.isEmpty(e))return{blocks:[]};const n=x.filter(e,a=>!x.includes(a==null?void 0:a._type,"@chai/"));return{blocks:ni(s,n)}},[e,s])},$s={async getUILibraryBlock(e,s,n){const a=await s(n,{action:"GET_LIBRARY_ITEM",data:{id:e.id}}),r=x.get(a,"html",""),i=x.get(a,"blocks",[]);return x.isArray(i)?i:ee.getBlocksFromHTML(r)},async getUILibraryBlocks(e,s,n){try{return(await s(n,{action:"GET_LIBRARY_ITEMS",data:{id:e.id}})).map(r=>({...r}))}catch(a){return console.error(a),[]}}},ri=()=>{const e=ne(),s=$();return L.useQuery({queryKey:[z,"uiLibraries"],initialData:[],queryFn:async()=>{const a=(await s(e,{action:"GET_LIBRARIES"})).map(r=>({...r}));return a.forEach(r=>{ee.registerChaiLibrary(r.id,{name:r.name,description:r.description,getBlocksList:i=>$s.getUILibraryBlocks(i,s,e),getBlock:({block:i})=>$s.getUILibraryBlock(i,s,e)})}),a}})},Nn=()=>{const e=Ns(),s=$(),{user:n}=Re(),a=n==null?void 0:n.id;return L.useQuery({queryKey:[z,"permissions",a],queryFn:()=>s(e,{action:P.GET_ROLE_AND_PERMISSIONS,data:{userId:a}}),enabled:!!a})},ii=()=>{const e=ne(),s=$(),{setCurrentEditor:n}=$t(),[,a]=Cs();return{onSave:async({page:i,blocks:l})=>{try{const o=await s(e,{action:"UPDATE_PAGE",data:{id:i,blocks:l}});return o.code==="PAGE_LOCKED"?(n(o.editor),!0):(a(u=>({...u,lastSaved:new Date().toISOString()})),o)}catch(o){return console.error(o),new Error("Failed to save blocks")}}}},li=()=>{const{data:e}=Ht(),s=ne(),n=$();return{getPartialBlocks:g.useCallback(async()=>{const a={};for(const r of e??[])x.isEmpty(r==null?void 0:r.slug)&&(a[r.id]={type:r.pageType,name:x.startCase(r.name??r.slug),description:""});return a},[e]),getPartialBlockBlocks:g.useCallback(async a=>{if(!a)return[];try{const r=await n(s,{action:"GET_DRAFT_PAGE",data:{id:a,draft:!0,editor:!1}});return x.filter(r.blocks,i=>x.has(i,"_id"))}catch(r){return console.error(r),[]}},[n,s])}},Ks=Yt.z.object({email:Yt.z.string().email({message:"Please enter a valid email address"}),password:Yt.z.string().min(6,{message:"Password must be at least 6 characters"})}),oi=()=>{const{setUser:e,logout:s}=Re(),n=Ns(),[a,r]=g.useState(""),[i,l]=g.useState(""),[o,u]=g.useState({}),[d,m]=g.useState(!1),[f,v]=g.useState(""),y=L.useMutation({mutationFn:async E=>{v("");const _=await cn(n,{action:"LOGIN",data:E});if(!_.ok){const k=await _.json();throw new Error(k.error||"Login failed")}const w=await _.json();if(x.has(w,"id")&&x.has(w,"email")&&x.has(w,"accessToken")&&x.has(w,"refreshToken"))e(w);else throw s(),new Error("Something went wrong. Please try again.");return w},onSuccess:()=>{u({}),v("")},onError:E=>{u({email:" ",password:" "}),v(E.message||"Something went wrong")}}),p=async E=>{E.preventDefault(),u({});const _={email:a,password:i};try{const w=Ks.parse(_);y.mutate(w)}catch(w){if(w instanceof Yt.z.ZodError){const k=w.errors.reduce((b,B)=>{const F=B.path[0];return b[F]=B.message,b},{});u(k)}}},S=Ks.safeParse({email:a,password:i}).success;return t.jsx("div",{className:"flex justify-center items-center min-h-screen bg-slate-50",children:t.jsxs(c.Card,{className:"w-full max-w-md",children:[t.jsxs(c.CardHeader,{children:[t.jsx(c.CardTitle,{className:"text-2xl",children:"Sign in"}),t.jsx(c.CardDescription,{children:"Enter your credentials to sign in to visual builder"})]}),t.jsx(c.CardContent,{children:t.jsxs("form",{onSubmit:p,className:"space-y-4",children:[t.jsxs("div",{className:"space-y-1",children:[t.jsx(c.Label,{htmlFor:"email",children:"Email"}),t.jsx(c.Input,{id:"email",placeholder:"you@example.com",type:"email",value:a,onChange:E=>r(E.target.value),className:o.email?"border-destructive":""}),o.email&&t.jsx("p",{className:"text-sm text-destructive",children:o.email})]}),t.jsxs("div",{className:"space-y-1",children:[t.jsx(c.Label,{htmlFor:"password",children:"Password"}),t.jsxs("div",{className:"relative",children:[t.jsx(c.Input,{id:"password",placeholder:"Enter your password",type:d?"text":"password",value:i,onChange:E=>l(E.target.value),className:o.password?"border-destructive":""}),t.jsx("button",{type:"button",className:"absolute right-3 top-1/2 -translate-y-1/2 text-muted-foreground",onClick:()=>m(!d),children:d?t.jsx(N.EyeOff,{className:"h-4 w-4"}):t.jsx(N.Eye,{className:"h-4 w-4"})})]}),o.password&&t.jsx("p",{className:"text-sm text-destructive",children:o.password})]}),t.jsx("div",{children:t.jsx("p",{className:"text-sm text-destructive",children:f})}),t.jsx(c.Button,{type:"submit",className:"w-full",disabled:!S||y.isPending,children:y.isPending?t.jsxs(t.Fragment,{children:[t.jsx(N.Loader2,{className:"mr-2 h-4 w-4 animate-spin"}),"Logging in..."]}):"Login"})]})}),t.jsxs(c.CardFooter,{className:"flex flex-col justify-center",children:[t.jsxs("p",{className:"text-sm text-muted-foreground",children:["Forgot your password?"," ",t.jsx("a",{target:"_blank",href:"https://chaibuilder.com/forgot-password",className:"text-primary hover:underline",children:"Reset password"})]}),t.jsx("br",{}),t.jsx("br",{}),t.jsxs("div",{className:"flex items-center border-t pt-2 px-10 gap-2",children:["Powered by"," ",t.jsxs("a",{target:"_blank",href:"https://chaibuilder.com",className:"text-primary hover:underline flex items-center gap-1",children:[t.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 gs=oi;const ci=()=>g.useMemo(()=>gs,[gs]),ui=e=>{gs=e},di=()=>{const e=ci();return t.jsx(g.Suspense,{fallback:t.jsx("div",{children:"Loading..."}),children:t.jsx(e,{})})},mi=({isActive:e,show:s})=>{const{data:n}=Ve();return!x.has(n,"languages")||!x.get(n,"languages",[]).length?null:t.jsx(c.Button,{size:"sm",onClick:s,variant:e?"default":"ghost",children:t.jsx(N.LanguagesIcon,{className:"w-4 h-4"})})},An="lang",hi={id:An,label:"Languages",position:"top",panel:ur,button:mi,view:"modal",width:400};function ze({data:e,onSelect:s,dataType:n="value",disabled:a=!1}){const[r,i]=pe.useState(!1),[l,o]=pe.useState([]),[u,d]=pe.useState(e);pe.useEffect(()=>{r||o([]),d(e)},[e,r]);const m=p=>Array.isArray(p)?"array":typeof p=="object"&&p!==null?"object":"value",f=pe.useCallback(p=>{const S=E=>n==="value"?E==="value"||E==="object":n==="array"?E==="array":E===n;p.type==="object"?(o(E=>[...E,p.key]),d(p.value)):S(p.type)&&(s([...l,p.key].join(".")),i(!1))},[l,s,n]),v=pe.useCallback(()=>{if(l.length>0){const p=l.slice(0,-1);o(p),d(p.reduce((S,E)=>S[E],e))}},[l,e]),y=pe.useMemo(()=>Object.entries(u).map(([p,S])=>({key:p,value:S,type:m(S)})).filter(p=>n==="value"?p.type==="value"||p.type==="object":n==="array"?p.type==="array"||p.type==="object":n==="object"?p.type==="object":!0),[u,n]);return t.jsxs(c.Popover,{open:r,onOpenChange:i,children:[t.jsxs(c.Tooltip,{children:[t.jsx(c.TooltipTrigger,{asChild:!0,children:t.jsx(c.PopoverTrigger,{asChild:!0,children:t.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":r,disabled:a,children:t.jsx(N.DatabaseIcon,{className:"h-3 w-3"})})})}),t.jsx(c.TooltipContent,{children:"Add field"})]}),t.jsx(c.PopoverContent,{className:"w-[200px] z-[9999] p-0",children:t.jsxs(c.Command,{children:[t.jsx(c.CommandInput,{className:"border-none",placeholder:"Search..."}),t.jsxs(c.CommandList,{children:[t.jsx(c.CommandEmpty,{children:"No option found."}),t.jsxs(c.CommandGroup,{children:[l.length>0&&t.jsxs(c.CommandItem,{onSelect:v,className:"flex items-center text-sm",children:[t.jsx(N.ChevronLeft,{className:"w-4 h-4 mr-2"}),"Back"]}),y.map(p=>t.jsxs(c.CommandItem,{onSelect:()=>f(p),className:"flex items-center justify-between",children:[t.jsx("span",{children:p.key}),t.jsxs("div",{className:"flex items-center gap-2",children:[n==="object"&&p.type==="object"&&t.jsx(c.Button,{size:"sm",variant:"ghost",className:"h-6 px-2 hover:bg-primary hover:text-primary-foreground",onClick:S=>{S.stopPropagation(),s([...l,p.key].join(".")),i(!1)},children:"Select"}),(p.type==="object"||p.type==="array")&&t.jsx("div",{className:"p-1 rounded hover:bg-muted cursor-pointer",children:t.jsx(N.ChevronRight,{className:"w-4 h-4 opacity-50"})})]})]},p.key))]})]})]})})]})}const fi=()=>{const e=zt(),s=L.useQueryClient(),n=$();return L.useMutation({mutationFn:async({file:a,folderId:r,name:i,optimize:l=!0})=>n(e,{action:P.UPLOAD_ASSET,data:{file:a,folderId:r,name:i,optimize:l}}),onSuccess:a=>{if(a!=null&&a.error)throw new Error(a==null?void 0:a.error);s.invalidateQueries({queryKey:[z,P.GET_ASSETS]}),Y.toast.success("Asset uploaded successfully")},onError:()=>{Y.toast.error("Failed to upload asset")}})},gi=()=>{const e=zt(),s=L.useQueryClient(),n=$();return L.useMutation({mutationFn:async a=>n(e,{action:P.DELETE_ASSET,data:{id:a}}),onSuccess:a=>{if(a!=null&&a.error)throw new Error(a==null?void 0:a.error);s.invalidateQueries({queryKey:[z,P.GET_ASSETS]}),Y.toast.success("Asset deleted successfully")},onError:()=>{Y.toast.error("Failed to delete asset")}})},xi=()=>{const e=zt(),s=L.useQueryClient(),n=$();return L.useMutation({mutationFn:async a=>n(e,{action:P.UPDATE_ASSET,data:a}),onSuccess:a=>{if(a!=null&&a.error)throw new Error(a==null?void 0:a.error);s.invalidateQueries({queryKey:[z,P.GET_ASSETS]}),Y.toast.success("Asset updated successfully")},onError:()=>{Y.toast.error("Failed to update asset")}})},pi=(e={})=>{const s=zt(),n=$(),{search:a,page:r=1,limit:i=30}=e;return L.useQuery({queryKey:[z,P.GET_ASSETS,a,r,i],queryFn:async()=>{const l=await n(s,{action:P.GET_ASSETS,data:{search:a,page:r,limit:i}});return l.page=r,l.limit=i,l},staleTime:1e3*60*5,retry:1})},yi=e=>{const s=zt(),n=$();return L.useQuery({queryKey:[z,P.GET_ASSET,e],queryFn:async()=>e?await n(s,{action:P.GET_ASSET,data:{id:e}}):null,staleTime:1e3*60*5,retry:1})};function vi(e){const s=isNaN(e)?0:typeof e=="number"?e:parseInt(e);return s?s<1024?`${s.toFixed(2)} B`:s<1024*1024?`${(s/1024).toFixed(2)} KB`:`${(s/(1024*1024)).toFixed(2)} MB`:"0 B"}function Vs(e){if(!e)return"N/A";const s=new Date(e);return new Intl.DateTimeFormat("en-US",{month:"short",day:"numeric",year:"numeric",hour:"2-digit",minute:"2-digit"}).format(s)}function Ws(e,s){let n=e,a=s==null?void 0:s.description;return(!a||typeof a!="string")&&(a=""),(!n||typeof n!="string")&&(n=""),n!==a}const ji=({assetId:e,onBack:s,onEdit:n,onSave:a,isSaving:r})=>{var m,f,v;const{data:i,isLoading:l,isError:o}=yi(e||""),[u,d]=g.useState("");return g.useEffect(()=>{i!=null&&i.description&&d(i.description)},[i]),l?t.jsx("div",{className:"flex-1 flex items-center justify-center",children:t.jsx(N.Loader,{className:"h-8 w-8 animate-spin"})}):o||!(i!=null&&i.id)?t.jsx("div",{className:"flex-1 flex items-center justify-center",children:t.jsxs("div",{className:"text-center max-w-md mx-auto p-6",children:[t.jsx("div",{className:"flex justify-center mb-4",children:t.jsx(N.AlertCircle,{className:"h-12 w-12 text-gray-400"})}),t.jsx("h3",{className:"text-lg font-medium text-gray-900 mb-2",children:"No Asset Found"}),t.jsx("p",{className:"text-sm text-gray-500 mb-6",children:o?"There was an error loading the asset. Please try again later.":"The asset you're looking for doesn't exist or has been removed."}),t.jsxs("div",{className:"flex justify-center gap-4",children:[t.jsx(c.Button,{variant:"outline",onClick:s,children:"Back to Assets"}),o&&t.jsx(c.Button,{variant:"default",onClick:()=>window.location.reload(),children:"Try Again"})]})]})}):t.jsxs("div",{className:"flex-1 flex flex-col gap-y-4 overflow-hidden",children:[t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsxs(c.Button,{variant:"outline",size:"sm",onClick:s,disabled:r,children:[t.jsx(N.ChevronLeft,{className:"h-4 w-4"}),"Back to Assets"]}),t.jsxs("div",{className:"flex gap-2",children:[t.jsx(c.Button,{variant:"outline",onClick:s,disabled:r,children:"Cancel"}),t.jsxs(c.Button,{variant:"default",onClick:()=>n(i),disabled:r,children:[t.jsx(N.Pencil,{className:"h-4 w-4"}),"Edit Image"]})]})]}),t.jsxs("div",{className:"grid grid-cols-2 items-start gap-6 flex-1 overflow-hidden",children:[t.jsx("div",{className:"relative h-[calc(80vh-200px)] w-full flex items-start justify-center",children:t.jsx("img",{src:`${i.url}?v=${((m=i.metadata)==null?void 0:m.updatedAt)||i.createdAt}`,alt:i.name,className:"w-full h-full object-contain rounded-lg max-h-max max-w-max"})}),t.jsxs("div",{className:"space-y-6",children:[t.jsxs("div",{className:"grid gap-3 border rounded-md pt-2 bg-gray-100",children:[t.jsx(c.Label,{className:"w-full text-center",children:"Details"}),t.jsx("div",{className:"grid grid-cols-1 gap-2 text-sm border rounded-md p-2 bg-white",children:[{label:"File Name",value:i.name},{label:"Type",value:i.type,capitalize:!0},{label:"Format",value:((f=i.metadata)==null?void 0:f.format)||i.type,capitalize:!0},{label:"Size",value:vi(i.size)},{label:"Dimensions",value:`${i.width||0} × ${i.height||0}`},{label:"Created",value:Vs(i.createdAt)},{label:"Updated",value:Vs(((v=i.metadata)==null?void 0:v.updatedAt)||i.createdAt)}].map(y=>t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(c.Label,{className:"w-max text-left px-2 w-1/4 font-normal text-gray-700",children:y.label}),":",t.jsx("div",{className:"w-max text-left font-medium text-gray-900"+y.capitalize?" capitalize":"",children:y.value})]},y.label))})]}),i.usedOn&&i.usedOn.length>0&&t.jsxs("div",{className:"grid gap-3",children:[t.jsx(c.Label,{children:"Used On"}),t.jsx("div",{className:"grid grid-cols-1 gap-2 text-sm border rounded-md p-2",children:i.usedOn.map((y,p)=>t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("div",{className:"w-max text-left font-medium text-gray-900",children:y.name}),t.jsxs("div",{className:"text-gray-500",children:["(",y.slug,")"]})]},p))})]}),t.jsxs("div",{className:"grid gap-3 border rounded-md pt-2 bg-gray-100 relative",children:[t.jsx(c.Label,{className:"w-full text-center",children:"Description"}),t.jsx(c.Textarea,{id:"description",value:u,placeholder:"Enter a description for the asset",onChange:y=>d(y.target.value),rows:3,disabled:r,className:"hover:border-black/40 bg-white"}),t.jsx("div",{className:"flex justify-end items-start absolute top-1.5 right-2",children:t.jsx("button",{type:"button",onClick:()=>a(u),disabled:r||!Ws(u,i),className:`py-0 bg-blue-500 text-white px-3 py-0.5 rounded-md text-sm ${r||!Ws(u,i)?"opacity-50 cursor-not-allowed":""}`,children:r?t.jsxs(t.Fragment,{children:[t.jsx(N.Loader,{className:"h-4 w-4 mr-2 animate-spin"}),"Saving..."]}):"Save"})})]})]})]})]})},bi=g.lazy(()=>Promise.resolve().then(()=>require("./image-editor-BWLJT1mr.cjs")));function Ei(e){const s=isNaN(e)?0:typeof e=="number"?e:parseInt(e);return s?s<1024?`${s.toFixed(2)} B`:s<1024*1024?`${(s/1024).toFixed(2)} KB`:`${(s/(1024*1024)).toFixed(2)} MB`:"0 B"}const Si=({isUpdatingAsset:e,allowedTypes:s,maxFileSize:n,uploadAsset:a,isUploadingAsset:r,onUploaded:i})=>{const[l,o]=g.useState(()=>{const y=localStorage.getItem("chai_optimize_images");return y!==null?y==="true":!0});g.useEffect(()=>{localStorage.setItem("chai_optimize_images",l.toString())},[l]);const u=e||r,d=g.useCallback(async y=>new Promise((p,S)=>{const E=y[0],_=new FileReader;_.readAsDataURL(E),_.onload=async()=>{a({file:_.result,folderId:void 0,name:E.name,optimize:l},{onSuccess:w=>{i&&i(w),p(w)},onError:w=>{S(w)}})},_.onerror=w=>S(w)}),[a,l,i]),{getRootProps:m,getInputProps:f,isDragActive:v}=ja.useDropzone({onDrop:d,accept:{"image/*":s.includes("image")?[]:[]},maxSize:n*1024*1024,disabled:e||r});return t.jsx("div",{className:`flex flex-col items-center justify-center w-full border-2 hover:border-black/50 border-dashed p-0 rounded-lg border-slate-300 py-2 h-[60px] ${u?"opacity-90 bg-gray-100 pointer-events-none":"hover:border-black/50 bg-gray-100 hover:bg-gray-100"}`,children:t.jsxs("div",{...m(),className:ee.mergeClasses("rounded-lg text-center cursor-pointer w-full h-max flex flex-col justify-center",u?"items-start":"items-center",v?"border-primary bg-primary/5":"border-muted-foreground/20"),children:[t.jsx("input",{...f()}),u?t.jsx("div",{className:"flex flex-col items-center px-6",children:t.jsxs("div",{className:"leading-tight flex items-center justify-center gap-2",children:[t.jsx("div",{className:"flex items-center justify-center rounded-full bg-indigo-100 p-2",children:t.jsx(N.Loader,{className:"h-4 w-4 text-indigo-500 animate-spin"})}),t.jsxs("div",{className:"text-left",children:[t.jsx("div",{className:"font-medium",children:e?"Updating file...":"Uploading file..."}),t.jsxs("div",{className:"text-xs text-muted-foreground font-light",children:["Please wait while we ",e?"update":"upload"," ","your file..."]})]})]})}):t.jsxs("div",{className:"flex items-center justify-between w-full px-6",children:[t.jsx("div",{className:"flex flex-col items-center",children:t.jsxs("div",{className:"leading-tight flex items-center justify-between gap-2",children:[t.jsx("div",{className:"flex items-center justify-center rounded-full bg-indigo-100 p-2 border border-indigo-500",children:t.jsx(N.Upload,{className:"h-4 w-4 text-indigo-500"})}),t.jsxs("div",{className:"text-left",children:[t.jsxs("div",{className:"font-medium",children:["Drop your file here or"," ",t.jsx("span",{className:"text-indigo-500 cursor-pointer hover:underline",children:"browse"})]}),t.jsxs("div",{className:"text-xs text-muted-foreground font-light",children:[t.jsxs("span",{className:"",children:["Accepted file types:"," ",t.jsx("span",{className:"capitalize text-indigo-400",children:s.join(", ")})," & "]}),t.jsxs("span",{children:["Max file size:"," ",t.jsxs("span",{className:"capitalize text-indigo-400",children:[n," MB"]})]})]})]})]})}),t.jsxs("div",{className:"text-xs text-muted-foreground flex items-center gap-2",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsxs("span",{className:"text-xs",children:["Optimization:"," ",t.jsx("span",{className:l?"text-indigo-600":"text-gray-400",children:l?"On":"Off"})]}),t.jsx(c.Switch,{checked:l,onCheckedChange:y=>{o(y)},onClick:y=>{y.stopPropagation()},className:"data-[state=checked]:bg-indigo-500"})]}),t.jsx(c.TooltipProvider,{children:t.jsxs(c.Tooltip,{children:[t.jsx(c.TooltipTrigger,{asChild:!0,children:t.jsx("span",{className:`text-amber-500 flex items-center cursor-help ${l?"invisible":""}`,children:t.jsx(N.AlertTriangle,{className:"h-4 w-4 mr-1"})})}),t.jsx(c.TooltipContent,{side:"top",children:t.jsxs("p",{className:"text-white text-xs",children:["Warning: Unoptimized images may affect ",t.jsx("br",{})," performance and page load times"]})})]})})]})]})]})})};function Cn({close:e,onSelect:s,mode:n="image",assetId:a}){const l=g.useMemo(()=>[n],[n]),[o,u]=g.useState(null),[d,m]=g.useState(null),[f,v]=g.useState(null),[y,p]=g.useState({show:!1,file:""}),[S,E]=g.useState(!1),[_,w]=g.useState(a?"details":"grid"),[k,b]=g.useState(""),[B,F]=g.useState(""),[te,R]=g.useState(1),[K]=g.useState(30),[M,X]=g.useState([]);g.useEffect(()=>{a&&(u(a),w("details"))},[a]),g.useEffect(()=>{const D=setTimeout(()=>{b(B),R(1)},300);return()=>clearTimeout(D)},[B]);const{data:O,isLoading:je}=pi({search:k.toLowerCase().trim(),page:te,limit:K}),V=(O==null?void 0:O.assets)||[],I=(O==null?void 0:O.total)||0,ae=Math.ceil(I/K),be=te<ae,we=te>1,Be=(V==null?void 0:V.length)>0,{mutate:j}=gi(),{mutate:h,isPending:A}=fi(),{mutate:G,isPending:U}=xi(),T=g.useCallback(D=>{D>=1&&D<=ae&&R(D)},[ae]),Z=g.useCallback(()=>{be&&T(te+1)},[te,be,T]),q=g.useCallback(()=>{we&&T(te-1)},[te,we,T]),J=D=>{F(D.target.value)},le=g.useCallback(D=>{X(re=>x.find(re,{id:D.id})?[]:[D])},[!1]),ge=g.useCallback(()=>{X([])},[]),ce=()=>{M.length!==0&&(s(x.pick(x.first(M),["id","url","width","height","description"])),e())},xe=async D=>{m(D)},ve=async()=>{d&&(v(d==null?void 0:d.id),await j(d.id,{onSuccess:()=>{v(null),m(null)},onError:()=>{v(null)}}),m(null))},se=D=>{u(D.id),w("details")},Ee=async(D,re)=>{try{const C=localStorage.getItem("chai_optimize_images")!=="false";re?(await h({file:D,folderId:void 0,name:y.name||"",optimize:C}),p({show:!1,file:""})):(await G({id:y.id||"",file:D}),p({show:!1,file:""}))}catch(C){console.error("Error saving edited image:",C)}},Ne=g.useCallback(D=>{X([D])},[]);return t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"max-w-[1232px] max-h-[1232px] w-[80vw] h-[80vh] space-y-4 flex flex-col",children:[t.jsx("h1",{className:"text-lg font-medium",children:"Digital Asset Manager"}),_==="grid"?t.jsxs(t.Fragment,{children:[t.jsx(Si,{maxFileSize:10,allowedTypes:l,uploadAsset:h,isUpdatingAsset:U,isUploadingAsset:A,onUploaded:Ne}),t.jsxs("div",{className:"border p-2 rounded-lg flex-1 flex flex-col gap-y-3 overflow-hidden relative",children:[t.jsxs("div",{className:"flex items-center justify-between gap-3",children:[t.jsxs("div",{className:"relative w-1/2 ",children:[t.jsx(N.Search,{strokeWidth:3,className:`absolute left-2 top-2.5 h-4 w-4 text-muted-foreground ${B.length>0?"text-indigo-800":""}`}),t.jsx(c.Input,{placeholder:"Search assets...",onChange:J,value:B,className:"pl-8"})]}),M.length>0?t.jsx("div",{className:"flex justify-between items-center",children:t.jsxs("div",{className:"flex items-center gap-2",children:[M.length>0&&t.jsx(t.Fragment,{children:t.jsx(c.Button,{variant:"outline",size:"sm",onClick:()=>ge(),title:"Clear selection",children:"Clear"})}),t.jsx(c.Button,{size:"sm",onClick:ce,disabled:M.length===0,children:"Select Asset"})]})}):null]}),t.jsx("div",{className:"flex-1 overflow-y-auto pb-[66px]",children:je?t.jsxs("div",{className:"columns-1 gap-3 space-y-3 sm:columns-3 md:columns-5",children:[t.jsx("div",{className:"bg-gray-200 h-64 w-full animate-pulse rounded"}),t.jsx("div",{className:"bg-gray-200 h-64 w-full animate-pulse rounded"}),t.jsx("div",{className:"bg-gray-200 h-64 w-full animate-pulse rounded"}),t.jsx("div",{className:"bg-gray-200 h-64 w-full animate-pulse rounded"}),t.jsx("div",{className:"bg-gray-200 h-64 w-full animate-pulse rounded"}),t.jsx("div",{className:"bg-gray-200 h-64 w-full animate-pulse rounded"}),t.jsx("div",{className:"bg-gray-200 h-64 w-full animate-pulse rounded"}),t.jsx("div",{className:"bg-gray-200 h-64 w-full animate-pulse rounded"}),t.jsx("div",{className:"bg-gray-200 h-64 w-full animate-pulse rounded"}),t.jsx("div",{className:"bg-gray-200 h-64 w-full animate-pulse rounded"})]}):!je&&!Be?t.jsxs("div",{className:"flex flex-col items-center justify-center h-full border rounded-lg",children:[t.jsx("div",{className:"text-muted-foreground",children:t.jsx(N.Archive,{className:"h-9 w-9 text-indigo-500"})}),t.jsx("div",{className:"text-muted-foreground text-lg",children:"No assets found"}),t.jsx("div",{className:"text-muted-foreground text-sm",children:k.length>0?"No assets found for your search: "+k:"Start uploading assets to get started"}),t.jsx("br",{})]}):t.jsx("div",{className:"flex flex-wrap gap-3 p-1",children:V==null?void 0:V.map(D=>t.jsxs("div",{className:ee.mergeClasses("relative cursor-pointer overflow-hidden transition-all rounded-lg border-2 group max-w-[180px] max-h-[180px] flex flex-col justify-between",M.some(re=>re.id===D.id)?"border-blue-500":"hover:border-black/90",f&&(d==null?void 0:d.id)===D.id?"opacity-50 pointer-events-none":"",f===D.id?"opacity-50 pointer-events-none":""),onClick:()=>le(D),children:[t.jsxs("div",{className:"aspect-square relative overflow-hidden",children:[f===D.id?t.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-black/50",children:t.jsx(N.Loader,{className:"h-8 w-8 animate-spin text-white"})}):null,D.type==="image"?t.jsx("img",{src:`${D.thumbnailUrl||"/placeholder.svg"}?v=${(D==null?void 0:D.updatedAt)||D.createdAt}`,alt:D.name,className:`object-contain w-full h-full min-h-[80px] ${M.some(re=>re.id===D.id)?"":"group-hover:blur group-hover:contrast-50"}`}):t.jsxs("div",{className:"flex items-center justify-center h-full",children:[t.jsx(N.Film,{className:"h-12 w-12 text-muted-foreground"}),D.thumbnailUrl&&t.jsx("img",{src:`${D.thumbnailUrl||"/placeholder.svg"}?v=${(D==null?void 0:D.updatedAt)||D.createdAt}`,alt:D.name,className:"absolute inset-0 object-cover w-full h-full"})]})]}),t.jsxs("div",{className:"py-1 px-2 flex items-end justify-between bg-white border-t-[1px] border-black/10",children:[t.jsx("div",{className:"text-xs truncate leading-tight",title:D.name,children:D.name}),t.jsx("div",{className:"text-[9px] whitespace-nowrap font-light text-muted-foreground flex items-center justify-between",children:t.jsx("span",{children:Ei((D==null?void 0:D.size)||0)})})]}),!M.some(re=>re.id===D.id)&&t.jsxs("div",{className:"absolute inset-0 opacity-0 group-hover:opacity-100 transition-opacity flex items-center justify-center gap-2",children:[t.jsx(c.Button,{variant:"secondary",size:"icon",className:"h-8 w-8 rounded-full",onClick:re=>{re.stopPropagation(),se(D)},children:t.jsx(N.ImageIcon,{className:"h-4 w-4"})}),t.jsx(c.Button,{variant:"secondary",size:"icon",className:"h-8 w-8 rounded-full",onClick:re=>{re.stopPropagation(),p({id:D.id,show:!0,file:D.url,name:D.name})},children:t.jsx(N.Edit,{className:"h-4 w-4"})}),t.jsx(c.Button,{variant:"destructive",size:"icon",className:"h-8 w-8 rounded-full",onClick:re=>{re.stopPropagation(),xe(D)},children:t.jsx(N.Trash2,{className:"h-4 w-4"})})]}),M.some(re=>re.id===D.id)&&t.jsx("div",{className:"absolute top-1 right-1 border border-white h-max rounded-full bg-blue-500 p-1",children:t.jsx(N.Check,{className:"w-3 h-3 text-white",strokeWidth:5})})]},D.id))})}),ae>1&&t.jsx("div",{className:"absolute bottom-0 left-0 right-0 bg-white border-t p-4",children:t.jsxs("div",{className:"flex items-center justify-center space-x-2",children:[t.jsx(c.Button,{variant:"outline",size:"sm",onClick:q,disabled:!we,children:"Previous"}),Array.from({length:Math.min(5,ae)},(D,re)=>{const C=re+1;return t.jsx(c.Button,{variant:te===C?"default":"outline",size:"sm",onClick:()=>T(C),children:C},C)}),ae>5&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"text-muted-foreground",children:"..."}),t.jsx(c.Button,{variant:te===ae?"default":"outline",size:"sm",onClick:()=>T(ae),children:ae})]}),t.jsx(c.Button,{variant:"outline",size:"sm",onClick:Z,disabled:!be,children:"Next"})]})})]})]}):t.jsx(ji,{assetId:o||a||"",onBack:()=>{w("grid"),u(null)},onEdit:D=>{p({id:D.id,show:!0,file:D.url,name:D.name})},onSave:async D=>{if(o){E(!0);try{const re=V.find(C=>C.id===o);re&&await G(x.merge(re,{description:D}))}finally{E(!1)}}},isSaving:S})]}),y.show&&t.jsx(g.Suspense,{fallback:t.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:t.jsx(N.Loader,{className:"h-8 w-8 animate-spin"})}),children:t.jsx(bi,{imageUrl:y.file,onSave:Ee,onClose:()=>p({show:!1,file:""}),defaultSavedImageName:y.name,isEditing:!!y.id})}),d&&t.jsx(c.Dialog,{open:!!d,onOpenChange:()=>m(null),children:t.jsxs(c.DialogContent,{children:[t.jsxs(c.DialogHeader,{children:[t.jsx(c.DialogTitle,{children:"Delete Asset"}),t.jsxs(c.DialogDescription,{children:['Are you sure you want to delete "',d.name,'"? This action cannot be undone.']})]}),t.jsxs(c.DialogFooter,{className:"gap-2 sm:gap-0",children:[t.jsx(c.Button,{variant:"outline",onClick:()=>m(null),children:"Cancel"}),t.jsx(c.Button,{variant:"destructive",onClick:ve,children:"Delete"})]})]})})]})}const wi=Object.freeze(Object.defineProperty({__proto__:null,default:Cn},Symbol.toStringTag,{value:"Module"})),Tn=({assetId:e,assetUrl:s,onChange:n,className:a="",placeholder:r="Select an image",disabled:i=!1})=>{const[l,o]=g.useState(!1),u=()=>{i||o(!0)},d=()=>{o(!1)},m=v=>{const y=Array.isArray(v)?v[0]:v;y!=null&&y.url&&n(x.pick(y,["url","id"])),o(!1)},f=()=>{n({url:"",id:""})};return t.jsxs("div",{className:`w-full ${a}`,children:[s?t.jsxs("div",{className:"relative border rounded-md overflow-hidden",children:[t.jsx("img",{onClick:u,src:s,alt:"Selected image",className:"w-full h-auto bg-gray-300 object-contain max-h-[100px]"}),t.jsxs("div",{className:"absolute top-2 right-2 flex gap-2",children:[t.jsx(c.Button,{type:"button",variant:"destructive",size:"icon",className:"h-8 w-8 rounded-full bg-white/80 text-red-500 hover:bg-white/90",onClick:f,disabled:i,children:t.jsx(N.Trash2,{className:"h-4 w-4"})}),t.jsx(c.Button,{type:"button",variant:"secondary",size:"icon",className:"h-8 w-8 rounded-full bg-white/80 hover:bg-white/90",onClick:u,disabled:i,children:t.jsx(N.ImageIcon,{className:"h-4 w-4"})})]})]}):t.jsx("div",{className:`flex items-center justify-center border border-dashed rounded-md p-6 cursor-pointer ${i?"opacity-50 cursor-not-allowed":"hover:border-gray-400"}`,onClick:u,children:t.jsxs("div",{className:"flex flex-col items-center gap-2",children:[t.jsx(N.ImageIcon,{className:"h-10 w-10 text-gray-400"}),t.jsx("p",{className:"text-sm text-gray-500",children:r})]})}),t.jsx(c.Dialog,{open:l,onOpenChange:o,children:t.jsxs(c.DialogContent,{className:"w-full max-w-7xl h-fit p-0 overflow-hidden",children:[t.jsxs(c.DialogHeader,{className:"px-4 py-2 border-b hidden",children:[t.jsx(c.DialogTitle,{children:"Select Image"}),t.jsx(c.Button,{type:"button",variant:"ghost",size:"icon",className:"absolute right-4 top-2",onClick:d,children:t.jsx(N.X,{className:"h-4 w-4"})})]}),t.jsx("div",{className:"flex-1 p-4 h-full",children:t.jsx(Cn,{close:d,onSelect:m,mode:"image",assetId:e})})]})})]})},Ni=()=>{const{selectedLang:e}=ee.useLanguages(),{data:s,isFetching:n}=Xe();return{data:g.useMemo(()=>x.find(s,{lang:e||""})||{},[s,e]),isFetching:n}},Ai=(e,s)=>{const n=e.selectionStart||0,a=e.selectionEnd||0,r=e.value,i=r.substring(0,n),l=r.substring(a);let o=!1;if(n>0&&i.length>0){const p=i.charAt(i.length-1);o=!/[\s.,!?;:()[\]{}]/.test(p)&&p!==""}let u=!1;if(l.length>0){const p=l.charAt(0);u=!/[\s.,!?;:()[\]{}]/.test(p)&&p!==""}const d=o?" ":"",m=u?" ":"",f=`{{${s}}}`,v=i+(o?d:"")+f+(u?m:"")+l,y=n+(o?1:0)+f.length;return{value:v,newCursorPos:y}},Pn=()=>{const{t:e}=ee.useTranslation(),{selectedLang:s,fallbackLang:n,languages:a}=ee.useLanguages(),[,r]=ee.useSidebarActivePanel(),{data:i}=pn(),{data:l,isFetching:o}=Ni(),u=l==null?void 0:l.seo,d=g.useRef(null),[m,f]=g.useState({title:"",description:"",cononicalUrl:"",noIndex:!1,noFollow:"",ogTitle:"",ogDescription:"",ogImage:"",ogImageId:"",searchTitle:"",searchDescription:"",jsonLD:"",...u}),v=g.useRef({initial:m,updated:m}),y=s.length?s:n,{mutate:p,isPending:S}=Ps(),E=S,{hasPermission:_}=ee.usePermissions(),w=_(fe.EDIT_SEO);g.useEffect(()=>{!o&&u&&f({title:"",description:"",cononicalUrl:"",noIndex:!1,noFollow:"",ogTitle:"",ogDescription:"",ogImage:"",searchTitle:"",searchDescription:"",jsonLD:"",...u})},[o,u]);const k=async()=>{p({id:l==null?void 0:l.id,seo:m},{onSuccess:()=>{v.current.initial=m,v.current.updated=m,r("outline")}})},b=()=>{f({...m,ogTitle:m.title,ogDescription:m.description})},B=()=>{f({...m,searchTitle:m.ogTitle,searchDescription:m.ogDescription})},F=(R,K)=>{const M=document.getElementById(K);if(M){const{value:X,newCursorPos:O}=Ai(M,R);d.current={id:K,position:O},M.tagName.toLowerCase()==="input"?(M.value=X,f(I=>({...I,[M.name]:X})),M.focus(),M.setSelectionRange(O,O),[0,10,50,100,200].forEach(I=>{setTimeout(()=>{const ae=document.getElementById(K);ae&&(ae.focus(),ae.setSelectionRange(O,O))},I)})):(f(V=>({...V,[M.name]:X})),requestAnimationFrame(()=>{const V=document.getElementById(K);V&&(V.focus(),V.setSelectionRange(O,O),setTimeout(()=>{const I=document.getElementById(K);I&&(I.focus(),I.setSelectionRange(O,O))},50))}))}},te=R=>{const K={...m,[R.target.name]:R.target.name==="noIndex"||R.target.name==="noFollow"?R.target.checked:R.target.value};f(K),v.current.updated=K};return t.jsxs("div",{className:"relative h-full flex flex-col",children:[!w&&t.jsx("div",{className:"absolute inset-0 z-10 backdrop-blur-sm flex items-center justify-center",children:t.jsx(c.Alert,{variant:"default",className:"w-[80%] max-w-md text-xs",children:t.jsx(c.AlertDescription,{children:e("You don't have permission to edit SEO settings. Contact your administrator for access.")})})}),t.jsxs("div",{className:"flex-grow overflow-y-auto no-scrollbar px-2",children:[t.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," ",a.length>0&&t.jsxs("span",{className:"font-semibold text-blue-500",children:["(",x.get(Le,y,y),")"]})]}),t.jsx("form",{className:"space-y-8",children:t.jsxs(c.Accordion,{type:"multiple",defaultValue:["page"],children:[t.jsxs(c.AccordionItem,{value:"page",children:[t.jsx(c.AccordionTrigger,{className:"font-semibold text-slate-700",children:e("SEO")}),t.jsx(c.AccordionContent,{className:"pt-2",children:t.jsxs("div",{className:"space-y-4",children:[t.jsxs("div",{className:"space-y-1",children:[t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsx(c.Label,{className:"text-xs",htmlFor:"title",children:e("SEO Title")}),w&&t.jsx(ze,{dataType:"value",data:i??{},onSelect:R=>F(R,"title")})]}),t.jsx(c.Input,{type:"text",id:"title",name:"title",value:m.title,onChange:te,disabled:E||!w,placeholder:e("Enter SEO title"),readOnly:!w})]}),t.jsxs("div",{className:"space-y-1",children:[t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsx(c.Label,{className:"text-xs",htmlFor:"description",children:e("SEO Description")}),w&&t.jsx(ze,{data:i??{},onSelect:R=>F(R,"description")})]}),t.jsx(c.Textarea,{id:"description",name:"description",rows:5,value:m.description,onChange:te,disabled:E||!w,placeholder:e("Enter SEO description"),readOnly:!w})]}),t.jsxs("div",{className:"space-y-1",children:[t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsx(c.Label,{className:"text-xs",htmlFor:"title",children:e("Canonical URL")}),w&&t.jsx(ze,{dataType:"value",data:i??{},onSelect:R=>F(R,"canonicalUrl")})]}),t.jsx(c.Input,{type:"text",id:"canonicalUrl",name:"canonicalUrl",value:m.canonicalUrl,onChange:te,disabled:E||!w,placeholder:e("Enter Canonical URL"),readOnly:!w})]}),t.jsxs("div",{className:"",children:[t.jsxs("div",{className:"flex items-center gap-x-2",children:[t.jsx(c.Input,{type:"checkbox",id:"noIndex",name:"noIndex",checked:m.noIndex,onChange:te,disabled:E||!w,className:"w-4 h-4"}),t.jsx(c.Label,{className:"pb-1 text-xs",htmlFor:"noIndex",children:e("No Index")})]}),t.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.")})]}),t.jsxs("div",{className:"",children:[t.jsxs("div",{className:"flex items-center gap-x-2",children:[t.jsx(c.Input,{type:"checkbox",id:"noFollow",name:"noFollow",checked:m.noFollow,onChange:te,disabled:E||!w,className:"w-4 h-4"}),t.jsx(c.Label,{className:"pb-1 text-xs",htmlFor:"noIndex",children:e("No Follow")})]}),t.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.")})]})]})})]}),t.jsxs(c.AccordionItem,{value:"og",children:[t.jsx(c.AccordionTrigger,{className:"font-bold text-slate-700",children:e("Open Graph")}),t.jsx(c.AccordionContent,{children:t.jsxs("div",{className:"space-y-4",children:[t.jsx("div",{className:"flex items-center justify-between",children:t.jsx(c.Button,{type:"button",variant:"outline",size:"sm",onClick:b,disabled:!w,children:e("Copy from SEO Settings")})}),t.jsxs("div",{className:"space-y-1",children:[t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsx(c.Label,{className:"text-xs",htmlFor:"ogTitle",children:e("OG Title")}),w&&t.jsx(ze,{dataType:"value",data:i??{},onSelect:R=>F(R,"ogTitle")})]}),t.jsx(c.Input,{type:"text",id:"ogTitle",name:"ogTitle",value:m.ogTitle,onChange:te,disabled:E||!w,placeholder:e("Enter OG title"),readOnly:!w})]}),t.jsxs("div",{className:"space-y-1",children:[t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsx(c.Label,{className:"text-xs",htmlFor:"ogDescription",children:e("OG Description")}),w&&t.jsx(ze,{dataType:"value",data:i??{},onSelect:R=>F(R,"ogDescription")})]}),t.jsx(c.Textarea,{id:"ogDescription",name:"ogDescription",rows:5,value:m.ogDescription,onChange:te,disabled:E||!w,placeholder:e("Enter OG description"),readOnly:!w})]}),t.jsxs("div",{className:"space-y-1",children:[t.jsx("div",{className:"flex items-center justify-between",children:t.jsx(c.Label,{className:"text-xs",htmlFor:"ogImage",children:e("OG Image")})}),t.jsx(Tn,{assetId:m.ogImageId,assetUrl:m.ogImage,onChange:R=>{const K={...m,ogImage:R.url,ogImageId:R.id};f(K),v.current.updated=K},disabled:E||!w,placeholder:e("Select OG image"),className:"mb-2"})]})]})})]}),t.jsxs(c.AccordionItem,{value:"search",children:[t.jsx(c.AccordionTrigger,{className:"font-bold text-slate-700",children:e("Search")}),t.jsx(c.AccordionContent,{children:t.jsxs("div",{className:"space-y-4",children:[t.jsx("div",{className:"flex items-center justify-between",children:t.jsx(c.Button,{type:"button",variant:"outline",size:"sm",onClick:B,disabled:!w,children:e("Copy from OG Settings")})}),t.jsxs("div",{className:"space-y-1",children:[t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsx(c.Label,{className:"text-xs",htmlFor:"searchTitle",children:e("Search Title")}),w&&t.jsx(ze,{dataType:"value",data:i??{},onSelect:R=>F(R,"searchTitle")})]}),t.jsx(c.Input,{type:"text",id:"searchTitle",name:"searchTitle",value:m.searchTitle,onChange:te,disabled:E||!w,placeholder:e("Enter search title"),readOnly:!w})]}),t.jsxs("div",{className:"space-y-1",children:[t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsx(c.Label,{className:"text-xs",htmlFor:"searchDescription",children:e("Search Description")}),w&&t.jsx(ze,{dataType:"value",data:i??{},onSelect:R=>F(R,"searchDescription")})]}),t.jsx(c.Textarea,{id:"searchDescription",rows:5,name:"searchDescription",value:m.searchDescription,onChange:te,placeholder:e("Enter search description"),disabled:E||!w,readOnly:!w})]})]})})]}),t.jsxs(c.AccordionItem,{value:"jsonLD",className:"border-none",children:[t.jsx(c.AccordionTrigger,{className:"font-bold text-slate-700",children:e("JSON-LD")}),t.jsx(c.AccordionContent,{children:t.jsx("div",{className:"space-y-4",children:t.jsxs("div",{className:"space-y-1",children:[t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsx(c.Label,{className:"text-xs",htmlFor:"jsonLD",children:e("JSON-LD")}),w&&t.jsx(ze,{dataType:"value",data:i??{},onSelect:R=>F(R,"jsonLD")})]}),t.jsx(c.Textarea,{id:"jsonLD",name:"jsonLD",rows:6,value:m.jsonLD,onChange:te,placeholder:e("Enter JSON-LD"),disabled:E||!w,readOnly:!w})]})})})]})]})})]}),w&&t.jsx("div",{className:"flex-shrink-0 flex items-center justify-end w-full p-4 bg-background border-t",children:t.jsx(c.Button,{size:"lg",variant:"default",onClick:k,disabled:x.isEqual(v.current.initial,m)||E||!w,children:e(S?"Saving...":"Save")})})]})};Pn.displayName="SeoPanel";const In="seo",Ci=({isActive:e,show:s})=>{const{data:n}=Ie(),a=Za(n==null?void 0:n.pageType);return!x.has(a,"hasSlug")||!a.hasSlug?null:t.jsx(c.Button,{size:"sm",className:"my-1",onClick:s,variant:e?"default":"ghost",children:t.jsxs("svg",{className:"w-4 h-4",xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 21 21",fill:"currentColor",children:[t.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"}),t.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"})]})})},Ti={id:In,label:"SEO",panel:Pn,button:Ci,position:"top",view:"modal",width:600},Pi="user-info",Ii=()=>{const{user:e,logout:s}=Re(),n=L.useQueryClient(),a=Fe("onLogout",x.noop);return e?t.jsxs(c.HoverCard,{children:[t.jsx(c.HoverCardTrigger,{asChild:!0,children:t.jsx(c.Button,{variant:"ghost",className:"text-sm font-medium",children:t.jsx(N.User,{className:"w-4 h-4"})})}),t.jsxs(c.HoverCardContent,{className:"w-auto p-4 space-y-2",children:[t.jsx("div",{className:"text-sm font-medium",children:e.name??e.email}),t.jsx("div",{className:"text-xs text-muted-foreground",children:e.email}),t.jsxs(c.AlertDialog,{children:[t.jsx(c.AlertDialogTrigger,{asChild:!0,children:t.jsx(c.Button,{variant:"outline",size:"sm",className:"w-full",children:"Logout"})}),t.jsxs(c.AlertDialogContent,{children:[t.jsxs(c.AlertDialogHeader,{children:[t.jsx(c.AlertDialogTitle,{children:"Are you sure you want to logout?"}),t.jsx(c.AlertDialogDescription,{children:"You will be redirected to the login page."})]}),t.jsxs(c.AlertDialogFooter,{children:[t.jsx(c.AlertDialogCancel,{children:"Cancel"}),t.jsx(c.AlertDialogAction,{onClick:()=>{s(),n.invalidateQueries({queryKey:[z]}),x.isFunction(a)&&a()},children:"Logout"})]})]})]})]})]}):null},_i={id:Pi,label:"User Info",button:Ii,position:"bottom"},ki=()=>{ee.registerChaiSidebarPanel(In,Ti),ee.registerChaiSidebarPanel(An,hi),ee.registerChaiSidebarPanel("user-info",_i)};var W={context:void 0,registry:void 0,effects:void 0,done:!1,getContextId(){return Qs(this.context.count)},getNextContextId(){return Qs(this.context.count++)}};function Qs(e){const s=String(e),n=s.length-1;return W.context.id+(n?String.fromCharCode(96+n):"")+s}function Et(e){W.context=e}var Di=(e,s)=>e===s,Jt=Symbol("solid-proxy"),_n=typeof Proxy=="function",Ds=Symbol("solid-track"),es={equals:Di},kn=On,qe=1,ts=2,Dn={owned:null,cleanups:null,context:null,owner:null},ds={},ie=null,ms=null,Li=null,de=null,Ae=null,Ue=null,ls=0;function He(e,s){const n=de,a=ie,r=e.length===0,i=s===void 0?a:s,l=r?Dn:{owned:null,cleanups:null,context:i?i.context:null,owner:i},o=r?e:()=>e(()=>Se(()=>Ct(l)));ie=l,de=null;try{return Me(o,!0)}finally{de=n,ie=a}}function ye(e,s){s=s?Object.assign({},es,s):es;const n={value:e,observers:null,observerSlots:null,comparator:s.equals||void 0},a=r=>(typeof r=="function"&&(r=r(n.value)),Un(n,r));return[Mn.bind(n),a]}function Ln(e,s,n){const a=os(e,s,!0,qe);bt(a)}function $e(e,s,n){const a=os(e,s,!1,qe);bt(a)}function Ls(e,s,n){kn=Wi;const a=os(e,s,!1,qe);(!n||!n.render)&&(a.user=!0),Ue?Ue.push(a):bt(a)}function Te(e,s,n){n=n?Object.assign({},es,n):es;const a=os(e,s,!0,0);return a.observers=null,a.observerSlots=null,a.comparator=n.equals||void 0,bt(a),Mn.bind(a)}function Bi(e){return e&&typeof e=="object"&&"then"in e}function Gi(e,s,n){let a,r,i;arguments.length===1?(a=!0,r=e,i={}):(a=e,r=s,i={});let l=null,o=ds,u=null,d=!1,m="initialValue"in i,f=typeof a=="function"&&Te(a);const v=new Set,[y,p]=(i.storage||ye)(i.initialValue),[S,E]=ye(void 0),[_,w]=ye(void 0,{equals:!1}),[k,b]=ye(m?"ready":"unresolved");W.context&&(u=W.getNextContextId(),i.ssrLoadFrom==="initial"?o=i.initialValue:W.load&&W.has(u)&&(o=W.load(u)));function B(K,M,X,O){return l===K&&(l=null,O!==void 0&&(m=!0),(K===o||M===o)&&i.onHydrated&&queueMicrotask(()=>i.onHydrated(O,{value:M})),o=ds,F(M,X)),M}function F(K,M){Me(()=>{M===void 0&&p(()=>K),b(M!==void 0?"errored":m?"ready":"unresolved"),E(M);for(const X of v.keys())X.decrement();v.clear()},!1)}function te(){const K=$i,M=y(),X=S();if(X!==void 0&&!l)throw X;return de&&de.user,M}function R(K=!0){if(K!==!1&&d)return;d=!1;const M=f?f():a;if(M==null||M===!1){B(l,Se(y));return}const X=o!==ds?o:Se(()=>r(M,{value:y(),refetching:K}));return Bi(X)?(l=X,"value"in X?(X.status==="success"?B(l,X.value,void 0,M):B(l,void 0,xs(X.value),M),X):(d=!0,queueMicrotask(()=>d=!1),Me(()=>{b(m?"refreshing":"pending"),w()},!1),X.then(O=>B(X,O,void 0,M),O=>B(X,void 0,xs(O),M)))):(B(l,X,void 0,M),X)}return Object.defineProperties(te,{state:{get:()=>k()},error:{get:()=>S()},loading:{get(){const K=k();return K==="pending"||K==="refreshing"}},latest:{get(){if(!m)return te();const K=S();if(K&&!l)throw K;return y()}}}),f?Ln(()=>R(!1)):R(!1),[te,{refetch:R,mutate:p}]}function Mi(e){return Me(e,!1)}function Se(e){if(de===null)return e();const s=de;de=null;try{return e()}finally{de=s}}function Ui(e,s,n){const a=Array.isArray(e);let r,i=n&&n.defer;return l=>{let o;if(a){o=Array(e.length);for(let d=0;d<e.length;d++)o[d]=e[d]()}else o=e();if(i)return i=!1,l;const u=Se(()=>s(o,r,l));return r=o,u}}function Bn(e){Ls(()=>Se(e))}function vt(e){return ie===null||(ie.cleanups===null?ie.cleanups=[e]:ie.cleanups.push(e)),e}function Ys(){return ie}function Oi(e,s){const n=ie,a=de;ie=e,de=null;try{return Me(s,!0)}catch(r){Bs(r)}finally{ie=n,de=a}}function Ri(e){const s=de,n=ie;return Promise.resolve().then(()=>{de=s,ie=n;let a;return Me(e,!1),de=ie=null,a?a.done:void 0})}var[Fi,Do]=ye(!1);function qi(){return[Fi,Ri]}function zi(e,s){const n=Symbol("context");return{id:n,Provider:Qi(n),defaultValue:e}}function Hi(e){let s;return ie&&ie.context&&(s=ie.context[e.id])!==void 0?s:e.defaultValue}function Gn(e){const s=Te(e),n=Te(()=>ps(s()));return n.toArray=()=>{const a=n();return Array.isArray(a)?a:a!=null?[a]:[]},n}var $i;function Mn(){if(this.sources&&this.state)if(this.state===qe)bt(this);else{const e=Ae;Ae=null,Me(()=>ns(this),!1),Ae=e}if(de){const e=this.observers?this.observers.length:0;de.sources?(de.sources.push(this),de.sourceSlots.push(e)):(de.sources=[this],de.sourceSlots=[e]),this.observers?(this.observers.push(de),this.observerSlots.push(de.sources.length-1)):(this.observers=[de],this.observerSlots=[de.sources.length-1])}return this.value}function Un(e,s,n){let a=e.value;return(!e.comparator||!e.comparator(a,s))&&(e.value=s,e.observers&&e.observers.length&&Me(()=>{for(let r=0;r<e.observers.length;r+=1){const i=e.observers[r],l=ms&&ms.running;l&&ms.disposed.has(i),(l?!i.tState:!i.state)&&(i.pure?Ae.push(i):Ue.push(i),i.observers&&Rn(i)),l||(i.state=qe)}if(Ae.length>1e6)throw Ae=[],new Error},!1)),s}function bt(e){if(!e.fn)return;Ct(e);const s=ls;Ki(e,e.value,s)}function Ki(e,s,n){let a;const r=ie,i=de;de=ie=e;try{a=e.fn(s)}catch(l){return e.pure&&(e.state=qe,e.owned&&e.owned.forEach(Ct),e.owned=null),e.updatedAt=n+1,Bs(l)}finally{de=i,ie=r}(!e.updatedAt||e.updatedAt<=n)&&(e.updatedAt!=null&&"observers"in e?Un(e,a):e.value=a,e.updatedAt=n)}function os(e,s,n,a=qe,r){const i={fn:e,state:a,updatedAt:null,owned:null,sources:null,sourceSlots:null,cleanups:null,value:s,owner:ie,context:ie?ie.context:null,pure:n};return ie===null||ie!==Dn&&(ie.owned?ie.owned.push(i):ie.owned=[i]),i}function ss(e){if(e.state===0)return;if(e.state===ts)return ns(e);if(e.suspense&&Se(e.suspense.inFallback))return e.suspense.effects.push(e);const s=[e];for(;(e=e.owner)&&(!e.updatedAt||e.updatedAt<ls);)e.state&&s.push(e);for(let n=s.length-1;n>=0;n--)if(e=s[n],e.state===qe)bt(e);else if(e.state===ts){const a=Ae;Ae=null,Me(()=>ns(e,s[0]),!1),Ae=a}}function Me(e,s){if(Ae)return e();let n=!1;s||(Ae=[]),Ue?n=!0:Ue=[],ls++;try{const a=e();return Vi(n),a}catch(a){n||(Ue=null),Ae=null,Bs(a)}}function Vi(e){if(Ae&&(On(Ae),Ae=null),e)return;const s=Ue;Ue=null,s.length&&Me(()=>kn(s),!1)}function On(e){for(let s=0;s<e.length;s++)ss(e[s])}function Wi(e){let s,n=0;for(s=0;s<e.length;s++){const a=e[s];a.user?e[n++]=a:ss(a)}if(W.context){if(W.count){W.effects||(W.effects=[]),W.effects.push(...e.slice(0,n));return}Et()}for(W.effects&&(W.done||!W.count)&&(e=[...W.effects,...e],n+=W.effects.length,delete W.effects),s=0;s<n;s++)ss(e[s])}function ns(e,s){e.state=0;for(let n=0;n<e.sources.length;n+=1){const a=e.sources[n];if(a.sources){const r=a.state;r===qe?a!==s&&(!a.updatedAt||a.updatedAt<ls)&&ss(a):r===ts&&ns(a,s)}}}function Rn(e){for(let s=0;s<e.observers.length;s+=1){const n=e.observers[s];n.state||(n.state=ts,n.pure?Ae.push(n):Ue.push(n),n.observers&&Rn(n))}}function Ct(e){let s;if(e.sources)for(;e.sources.length;){const n=e.sources.pop(),a=e.sourceSlots.pop(),r=n.observers;if(r&&r.length){const i=r.pop(),l=n.observerSlots.pop();a<r.length&&(i.sourceSlots[l]=a,r[a]=i,n.observerSlots[a]=l)}}if(e.tOwned){for(s=e.tOwned.length-1;s>=0;s--)Ct(e.tOwned[s]);delete e.tOwned}if(e.owned){for(s=e.owned.length-1;s>=0;s--)Ct(e.owned[s]);e.owned=null}if(e.cleanups){for(s=e.cleanups.length-1;s>=0;s--)e.cleanups[s]();e.cleanups=null}e.state=0}function xs(e){return e instanceof Error?e:new Error(typeof e=="string"?e:"Unknown error",{cause:e})}function Bs(e,s=ie){throw xs(e)}function ps(e){if(typeof e=="function"&&!e.length)return ps(e());if(Array.isArray(e)){const s=[];for(let n=0;n<e.length;n++){const a=ps(e[n]);Array.isArray(a)?s.push.apply(s,a):s.push(a)}return s}return e}function Qi(e,s){return function(a){let r;return $e(()=>r=Se(()=>(ie.context={...ie.context,[e]:a.value},Gn(()=>a.children))),void 0),r}}var ys=Symbol("fallback");function as(e){for(let s=0;s<e.length;s++)e[s]()}function Yi(e,s,n={}){let a=[],r=[],i=[],l=0,o=s.length>1?[]:null;return vt(()=>as(i)),()=>{let u=e()||[],d=u.length,m,f;return u[Ds],Se(()=>{let y,p,S,E,_,w,k,b,B;if(d===0)l!==0&&(as(i),i=[],a=[],r=[],l=0,o&&(o=[])),n.fallback&&(a=[ys],r[0]=He(F=>(i[0]=F,n.fallback())),l=1);else if(l===0){for(r=new Array(d),f=0;f<d;f++)a[f]=u[f],r[f]=He(v);l=d}else{for(S=new Array(d),E=new Array(d),o&&(_=new Array(d)),w=0,k=Math.min(l,d);w<k&&a[w]===u[w];w++);for(k=l-1,b=d-1;k>=w&&b>=w&&a[k]===u[b];k--,b--)S[b]=r[k],E[b]=i[k],o&&(_[b]=o[k]);for(y=new Map,p=new Array(b+1),f=b;f>=w;f--)B=u[f],m=y.get(B),p[f]=m===void 0?-1:m,y.set(B,f);for(m=w;m<=k;m++)B=a[m],f=y.get(B),f!==void 0&&f!==-1?(S[f]=r[m],E[f]=i[m],o&&(_[f]=o[m]),f=p[f],y.set(B,f)):i[m]();for(f=w;f<d;f++)f in S?(r[f]=S[f],i[f]=E[f],o&&(o[f]=_[f],o[f](f))):r[f]=He(v);r=r.slice(0,l=d),a=u.slice(0)}return r});function v(y){if(i[f]=y,o){const[p,S]=ye(f);return o[f]=S,s(u[f],p)}return s(u[f])}}}function Xi(e,s,n={}){let a=[],r=[],i=[],l=[],o=0,u;return vt(()=>as(i)),()=>{const d=e()||[],m=d.length;return d[Ds],Se(()=>{if(m===0)return o!==0&&(as(i),i=[],a=[],r=[],o=0,l=[]),n.fallback&&(a=[ys],r[0]=He(v=>(i[0]=v,n.fallback())),o=1),r;for(a[0]===ys&&(i[0](),i=[],a=[],r=[],o=0),u=0;u<m;u++)u<a.length&&a[u]!==d[u]?l[u](()=>d[u]):u>=a.length&&(r[u]=He(f));for(;u<a.length;u++)i[u]();return o=l.length=i.length=m,a=d.slice(0),r=r.slice(0,o)});function f(v){i[u]=v;const[y,p]=ye(d[u]);return l[u]=p,s(y,u)}}}function Gs(e,s){return Se(()=>e(s||{}))}function Vt(){return!0}var vs={get(e,s,n){return s===Jt?n:e.get(s)},has(e,s){return s===Jt?!0:e.has(s)},set:Vt,deleteProperty:Vt,getOwnPropertyDescriptor(e,s){return{configurable:!0,enumerable:!0,get(){return e.get(s)},set:Vt,deleteProperty:Vt}},ownKeys(e){return e.keys()}};function hs(e){return(e=typeof e=="function"?e():e)?e:{}}function Zi(){for(let e=0,s=this.length;e<s;++e){const n=this[e]();if(n!==void 0)return n}}function Ms(...e){let s=!1;for(let l=0;l<e.length;l++){const o=e[l];s=s||!!o&&Jt in o,e[l]=typeof o=="function"?(s=!0,Te(o)):o}if(_n&&s)return new Proxy({get(l){for(let o=e.length-1;o>=0;o--){const u=hs(e[o])[l];if(u!==void 0)return u}},has(l){for(let o=e.length-1;o>=0;o--)if(l in hs(e[o]))return!0;return!1},keys(){const l=[];for(let o=0;o<e.length;o++)l.push(...Object.keys(hs(e[o])));return[...new Set(l)]}},vs);const n={},a=Object.create(null);for(let l=e.length-1;l>=0;l--){const o=e[l];if(!o)continue;const u=Object.getOwnPropertyNames(o);for(let d=u.length-1;d>=0;d--){const m=u[d];if(m==="__proto__"||m==="constructor")continue;const f=Object.getOwnPropertyDescriptor(o,m);if(!a[m])a[m]=f.get?{enumerable:!0,configurable:!0,get:Zi.bind(n[m]=[f.get.bind(o)])}:f.value!==void 0?f:void 0;else{const v=n[m];v&&(f.get?v.push(f.get.bind(o)):f.value!==void 0&&v.push(()=>f.value))}}}const r={},i=Object.keys(a);for(let l=i.length-1;l>=0;l--){const o=i[l],u=a[o];u&&u.get?Object.defineProperty(r,o,u):r[o]=u?u.value:void 0}return r}function Fn(e,...s){if(_n&&Jt in e){const r=new Set(s.length>1?s.flat():s[0]),i=s.map(l=>new Proxy({get(o){return l.includes(o)?e[o]:void 0},has(o){return l.includes(o)&&o in e},keys(){return l.filter(o=>o in e)}},vs));return i.push(new Proxy({get(l){return r.has(l)?void 0:e[l]},has(l){return r.has(l)?!1:l in e},keys(){return Object.keys(e).filter(l=>!r.has(l))}},vs)),i}const n={},a=s.map(()=>({}));for(const r of Object.getOwnPropertyNames(e)){const i=Object.getOwnPropertyDescriptor(e,r),l=!i.get&&!i.set&&i.enumerable&&i.writable&&i.configurable;let o=!1,u=0;for(const d of s)d.includes(r)&&(o=!0,l?a[u][r]=i.value:Object.defineProperty(a[u],r,i)),++u;o||(l?n[r]=i.value:Object.defineProperty(n,r,i))}return[...a,n]}function qn(e){let s,n;const a=r=>{const i=W.context;if(i){const[o,u]=ye();W.count||(W.count=0),W.count++,(n||(n=e())).then(d=>{!W.done&&Et(i),W.count--,u(()=>d.default),Et()}),s=o}else if(!s){const[o]=Gi(()=>(n||(n=e())).then(u=>u.default));s=o}let l;return Te(()=>(l=s())?Se(()=>{if(!i||W.done)return l(r);const o=W.context;Et(i);const u=l(r);return Et(o),u}):"")};return a.preload=()=>n||((n=e()).then(r=>s=()=>r.default),n),a}var Ji=0;function el(){return W.context?W.getNextContextId():`cl-${Ji++}`}var zn=e=>`Stale read from <${e}>.`;function tl(e){const s="fallback"in e&&{fallback:()=>e.fallback};return Te(Yi(()=>e.each,e.children,s||void 0))}function sl(e){const s="fallback"in e&&{fallback:()=>e.fallback};return Te(Xi(()=>e.each,e.children,s||void 0))}function nl(e){const s=e.keyed,n=Te(()=>e.when,void 0,{equals:(a,r)=>s?a===r:!a==!r});return Te(()=>{const a=n();if(a){const r=e.children;return typeof r=="function"&&r.length>0?Se(()=>r(s?a:()=>{if(!Se(n))throw zn("Show");return e.when})):r}return e.fallback},void 0,void 0)}function al(e){let s=!1;const n=(i,l)=>(s?i[1]===l[1]:!i[1]==!l[1])&&i[2]===l[2],a=Gn(()=>e.children),r=Te(()=>{let i=a();Array.isArray(i)||(i=[i]);for(let l=0;l<i.length;l++){const o=i[l].when;if(o)return s=!!i[l].keyed,[l,o,i[l]]}return[-1]},void 0,{equals:n});return Te(()=>{const[i,l,o]=r();if(i<0)return e.fallback;const u=o.children;return typeof u=="function"&&u.length>0?Se(()=>u(s?l:()=>{if(Se(r)[0]!==i)throw zn("Match");return o.when})):u},void 0,void 0)}function rl(e){return e}var il=["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"],ll=new Set(["className","value","readOnly","formNoValidate","isMap","noModule","playsInline",...il]),ol=new Set(["innerHTML","textContent","innerText","children"]),cl=Object.assign(Object.create(null),{className:"class",htmlFor:"for"}),ul=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 dl(e,s){const n=ul[e];return typeof n=="object"?n[s]?n.$:void 0:n}var ml=new Set(["beforeinput","click","dblclick","contextmenu","focusin","focusout","input","keydown","keyup","mousedown","mousemove","mouseout","mouseover","mouseup","pointerdown","pointermove","pointerout","pointerover","pointerup","touchend","touchmove","touchstart"]),hl=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"]),fl={xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace"};function gl(e,s,n){let a=n.length,r=s.length,i=a,l=0,o=0,u=s[r-1].nextSibling,d=null;for(;l<r||o<i;){if(s[l]===n[o]){l++,o++;continue}for(;s[r-1]===n[i-1];)r--,i--;if(r===l){const m=i<a?o?n[o-1].nextSibling:n[i-o]:u;for(;o<i;)e.insertBefore(n[o++],m)}else if(i===o)for(;l<r;)(!d||!d.has(s[l]))&&s[l].remove(),l++;else if(s[l]===n[i-1]&&n[o]===s[r-1]){const m=s[--r].nextSibling;e.insertBefore(n[o++],s[l++].nextSibling),e.insertBefore(n[--i],m),s[r]=n[i]}else{if(!d){d=new Map;let f=o;for(;f<i;)d.set(n[f],f++)}const m=d.get(s[l]);if(m!=null)if(o<m&&m<i){let f=l,v=1,y;for(;++f<r&&f<i&&!((y=d.get(s[f]))==null||y!==m+v);)v++;if(v>m-o){const p=s[l];for(;o<m;)e.insertBefore(n[o++],p)}else e.replaceChild(n[o++],s[l++])}else l++;else s[l++].remove()}}}var Nt="_$DX_DELEGATE";function Hn(e,s,n,a={}){let r;return He(i=>{r=i,s===document?e():is(s,e(),s.firstChild?null:void 0,n)},a.owner),()=>{r(),s.textContent=""}}function xl(e,s,n){let a;const r=()=>{const l=document.createElement("template");return l.innerHTML=e,l.content.firstChild},i=()=>(a||(a=r())).cloneNode(!0);return i.cloneNode=i,i}function $n(e,s=window.document){const n=s[Nt]||(s[Nt]=new Set);for(let a=0,r=e.length;a<r;a++){const i=e[a];n.has(i)||(n.add(i),s.addEventListener(i,Yn))}}function pl(e=window.document){if(e[Nt]){for(let s of e[Nt].keys())e.removeEventListener(s,Yn);delete e[Nt]}}function rs(e,s,n){Je(e)||(n==null?e.removeAttribute(s):e.setAttribute(s,n))}function yl(e,s,n,a){Je(e)||(a==null?e.removeAttributeNS(s,n):e.setAttributeNS(s,n,a))}function vl(e,s,n){Je(e)||(n?e.setAttribute(s,""):e.removeAttribute(s))}function Kn(e,s){Je(e)||(s==null?e.removeAttribute("class"):e.className=s)}function Vn(e,s,n,a){if(a)Array.isArray(n)?(e[`$$${s}`]=n[0],e[`$$${s}Data`]=n[1]):e[`$$${s}`]=n;else if(Array.isArray(n)){const r=n[0];e.addEventListener(s,n[0]=i=>r.call(e,n[1],i))}else e.addEventListener(s,n,typeof n!="function"&&n)}function jl(e,s,n={}){const a=Object.keys(s||{}),r=Object.keys(n);let i,l;for(i=0,l=r.length;i<l;i++){const o=r[i];!o||o==="undefined"||s[o]||(Xs(e,o,!1),delete n[o])}for(i=0,l=a.length;i<l;i++){const o=a[i],u=!!s[o];!o||o==="undefined"||n[o]===u||!u||(Xs(e,o,!0),n[o]=u)}return n}function bl(e,s,n){if(!s)return n?rs(e,"style"):s;const a=e.style;if(typeof s=="string")return a.cssText=s;typeof n=="string"&&(a.cssText=n=void 0),n||(n={}),s||(s={});let r,i;for(i in n)s[i]==null&&a.removeProperty(i),delete n[i];for(i in s)r=s[i],r!==n[i]&&(a.setProperty(i,r),n[i]=r);return n}function Wn(e,s={},n,a){const r={};return a||$e(()=>r.children=Tt(e,s.children,r.children)),$e(()=>typeof s.ref=="function"&&Qn(s.ref,e)),$e(()=>El(e,s,n,!0,r,!0)),r}function Qn(e,s,n){return Se(()=>e(s,n))}function is(e,s,n,a){if(n!==void 0&&!a&&(a=[]),typeof s!="function")return Tt(e,s,a,n);$e(r=>Tt(e,s(),r,n),a)}function El(e,s,n,a,r={},i=!1){s||(s={});for(const l in r)if(!(l in s)){if(l==="children")continue;r[l]=Zs(e,l,null,r[l],n,i,s)}for(const l in s){if(l==="children")continue;const o=s[l];r[l]=Zs(e,l,o,r[l],n,i,s)}}function Sl(e){let s,n;return!Je()||!(s=W.registry.get(n=Nl()))?e():(W.completed&&W.completed.add(s),W.registry.delete(n),s)}function Je(e){return!!W.context&&!W.done&&(!e||e.isConnected)}function wl(e){return e.toLowerCase().replace(/-([a-z])/g,(s,n)=>n.toUpperCase())}function Xs(e,s,n){const a=s.trim().split(/\s+/);for(let r=0,i=a.length;r<i;r++)e.classList.toggle(a[r],n)}function Zs(e,s,n,a,r,i,l){let o,u,d,m,f;if(s==="style")return bl(e,n,a);if(s==="classList")return jl(e,n,a);if(n===a)return a;if(s==="ref")i||n(e);else if(s.slice(0,3)==="on:"){const v=s.slice(3);a&&e.removeEventListener(v,a,typeof a!="function"&&a),n&&e.addEventListener(v,n,typeof n!="function"&&n)}else if(s.slice(0,10)==="oncapture:"){const v=s.slice(10);a&&e.removeEventListener(v,a,!0),n&&e.addEventListener(v,n,!0)}else if(s.slice(0,2)==="on"){const v=s.slice(2).toLowerCase(),y=ml.has(v);if(!y&&a){const p=Array.isArray(a)?a[0]:a;e.removeEventListener(v,p)}(y||n)&&(Vn(e,v,n,y),y&&$n([v]))}else if(s.slice(0,5)==="attr:")rs(e,s.slice(5),n);else if(s.slice(0,5)==="bool:")vl(e,s.slice(5),n);else if((f=s.slice(0,5)==="prop:")||(d=ol.has(s))||!r&&((m=dl(s,e.tagName))||(u=ll.has(s)))||(o=e.nodeName.includes("-")||"is"in l)){if(f)s=s.slice(5),u=!0;else if(Je(e))return n;s==="class"||s==="className"?Kn(e,n):o&&!u&&!d?e[wl(s)]=n:e[m||s]=n}else{const v=r&&s.indexOf(":")>-1&&fl[s.split(":")[0]];v?yl(e,v,s,n):rs(e,cl[s]||s,n)}return n}function Yn(e){if(W.registry&&W.events&&W.events.find(([u,d])=>d===e))return;let s=e.target;const n=`$$${e.type}`,a=e.target,r=e.currentTarget,i=u=>Object.defineProperty(e,"target",{configurable:!0,value:u}),l=()=>{const u=s[n];if(u&&!s.disabled){const d=s[`${n}Data`];if(d!==void 0?u.call(s,d,e):u.call(s,e),e.cancelBubble)return}return s.host&&typeof s.host!="string"&&!s.host._$host&&s.contains(e.target)&&i(s.host),!0},o=()=>{for(;l()&&(s=s._$host||s.parentNode||s.host););};if(Object.defineProperty(e,"currentTarget",{configurable:!0,get(){return s||document}}),W.registry&&!W.done&&(W.done=_$HY.done=!0),e.composedPath){const u=e.composedPath();i(u[0]);for(let d=0;d<u.length-2&&(s=u[d],!!l());d++){if(s._$host){s=s._$host,o();break}if(s.parentNode===r)break}}else o();i(a)}function Tt(e,s,n,a,r){const i=Je(e);if(i){!n&&(n=[...e.childNodes]);let u=[];for(let d=0;d<n.length;d++){const m=n[d];m.nodeType===8&&m.data.slice(0,2)==="!$"?m.remove():u.push(m)}n=u}for(;typeof n=="function";)n=n();if(s===n)return n;const l=typeof s,o=a!==void 0;if(e=o&&n[0]&&n[0].parentNode||e,l==="string"||l==="number"){if(i||l==="number"&&(s=s.toString(),s===n))return n;if(o){let u=n[0];u&&u.nodeType===3?u.data!==s&&(u.data=s):u=document.createTextNode(s),n=st(e,n,a,u)}else n!==""&&typeof n=="string"?n=e.firstChild.data=s:n=e.textContent=s}else if(s==null||l==="boolean"){if(i)return n;n=st(e,n,a)}else{if(l==="function")return $e(()=>{let u=s();for(;typeof u=="function";)u=u();n=Tt(e,u,n,a)}),()=>n;if(Array.isArray(s)){const u=[],d=n&&Array.isArray(n);if(js(u,s,n,r))return $e(()=>n=Tt(e,u,n,a,!0)),()=>n;if(i){if(!u.length)return n;if(a===void 0)return n=[...e.childNodes];let m=u[0];if(m.parentNode!==e)return n;const f=[m];for(;(m=m.nextSibling)!==a;)f.push(m);return n=f}if(u.length===0){if(n=st(e,n,a),o)return n}else d?n.length===0?Js(e,u,a):gl(e,n,u):(n&&st(e),Js(e,u));n=u}else if(s.nodeType){if(i&&s.parentNode)return n=o?[s]:s;if(Array.isArray(n)){if(o)return n=st(e,n,a,s);st(e,n,null,s)}else n==null||n===""||!e.firstChild?e.appendChild(s):e.replaceChild(s,e.firstChild);n=s}}return n}function js(e,s,n,a){let r=!1;for(let i=0,l=s.length;i<l;i++){let o=s[i],u=n&&n[e.length],d;if(!(o==null||o===!0||o===!1))if((d=typeof o)=="object"&&o.nodeType)e.push(o);else if(Array.isArray(o))r=js(e,o,u)||r;else if(d==="function")if(a){for(;typeof o=="function";)o=o();r=js(e,Array.isArray(o)?o:[o],Array.isArray(u)?u:[u])||r}else e.push(o),r=!0;else{const m=String(o);u&&u.nodeType===3&&u.data===m?e.push(u):e.push(document.createTextNode(m))}}return r}function Js(e,s,n=null){for(let a=0,r=s.length;a<r;a++)e.insertBefore(s[a],n)}function st(e,s,n,a){if(n===void 0)return e.textContent="";const r=a||document.createTextNode("");if(s.length){let i=!1;for(let l=s.length-1;l>=0;l--){const o=s[l];if(r!==o){const u=o.parentNode===e;!i&&!l?u?e.replaceChild(r,o):e.insertBefore(r,n):u&&o.remove()}else i=!0}}else e.insertBefore(r,n);return[r]}function Nl(){return W.getNextContextId()}var Al="http://www.w3.org/2000/svg";function Xn(e,s=!1){return s?document.createElementNS(Al,e):document.createElement(e)}function Cl(e){const{useShadow:s}=e,n=document.createTextNode(""),a=()=>e.mount||document.body,r=Ys();let i,l=!!W.context;return Ls(()=>{l&&(Ys().user=l=!1),i||(i=Oi(r,()=>Te(()=>e.children)));const o=a();if(o instanceof HTMLHeadElement){const[u,d]=ye(!1),m=()=>d(!0);He(f=>is(o,()=>u()?f():i(),null)),vt(m)}else{const u=Xn(e.isSVG?"g":"div",e.isSVG),d=s&&u.attachShadow?u.attachShadow({mode:"open"}):u;Object.defineProperty(u,"_$host",{get(){return n.parentNode},configurable:!0}),is(d,i),o.appendChild(u),e.ref&&e.ref(u),vt(()=>o.removeChild(u))}},void 0,{render:!l}),n}function Tl(e){const[s,n]=Fn(e,["component"]),a=Te(()=>s.component);return Te(()=>{const r=a();switch(typeof r){case"function":return Se(()=>r(n));case"string":const i=hl.has(r),l=W.context?Sl():Xn(r,i);return Wn(l,n,i),l}})}var Pl=class{constructor(){this.keyToValue=new Map,this.valueToKey=new Map}set(e,s){this.keyToValue.set(e,s),this.valueToKey.set(s,e)}getByKey(e){return this.keyToValue.get(e)}getByValue(e){return this.valueToKey.get(e)}clear(){this.keyToValue.clear(),this.valueToKey.clear()}},Zn=class{constructor(e){this.generateIdentifier=e,this.kv=new Pl}register(e,s){this.kv.getByValue(e)||(s||(s=this.generateIdentifier(e)),this.kv.set(s,e))}clear(){this.kv.clear()}getIdentifier(e){return this.kv.getByValue(e)}getValue(e){return this.kv.getByKey(e)}},Il=class extends Zn{constructor(){super(e=>e.name),this.classToAllowedProps=new Map}register(e,s){typeof s=="object"?(s.allowProps&&this.classToAllowedProps.set(e,s.allowProps),super.register(e,s.identifier)):super.register(e,s)}getAllowedProps(e){return this.classToAllowedProps.get(e)}};function _l(e){if("values"in Object)return Object.values(e);const s=[];for(const n in e)e.hasOwnProperty(n)&&s.push(e[n]);return s}function kl(e,s){const n=_l(e);if("find"in n)return n.find(s);const a=n;for(let r=0;r<a.length;r++){const i=a[r];if(s(i))return i}}function jt(e,s){Object.entries(e).forEach(([n,a])=>s(a,n))}function Xt(e,s){return e.indexOf(s)!==-1}function en(e,s){for(let n=0;n<e.length;n++){const a=e[n];if(s(a))return a}}var Dl=class{constructor(){this.transfomers={}}register(e){this.transfomers[e.name]=e}findApplicable(e){return kl(this.transfomers,s=>s.isApplicable(e))}findByName(e){return this.transfomers[e]}},Ll=e=>Object.prototype.toString.call(e).slice(8,-1),Jn=e=>typeof e>"u",Bl=e=>e===null,Pt=e=>typeof e!="object"||e===null||e===Object.prototype?!1:Object.getPrototypeOf(e)===null?!0:Object.getPrototypeOf(e)===Object.prototype,bs=e=>Pt(e)&&Object.keys(e).length===0,Ke=e=>Array.isArray(e),Gl=e=>typeof e=="string",Ml=e=>typeof e=="number"&&!isNaN(e),Ul=e=>typeof e=="boolean",Ol=e=>e instanceof RegExp,It=e=>e instanceof Map,_t=e=>e instanceof Set,ea=e=>Ll(e)==="Symbol",Rl=e=>e instanceof Date&&!isNaN(e.valueOf()),Fl=e=>e instanceof Error,tn=e=>typeof e=="number"&&isNaN(e),ql=e=>Ul(e)||Bl(e)||Jn(e)||Ml(e)||Gl(e)||ea(e),zl=e=>typeof e=="bigint",Hl=e=>e===1/0||e===-1/0,$l=e=>ArrayBuffer.isView(e)&&!(e instanceof DataView),Kl=e=>e instanceof URL,ta=e=>e.replace(/\./g,"\\."),fs=e=>e.map(String).map(ta).join("."),At=e=>{const s=[];let n="";for(let r=0;r<e.length;r++){let i=e.charAt(r);if(i==="\\"&&e.charAt(r+1)==="."){n+=".",r++;continue}if(i==="."){s.push(n),n="";continue}n+=i}const a=n;return s.push(a),s};function Ge(e,s,n,a){return{isApplicable:e,annotation:s,transform:n,untransform:a}}var sa=[Ge(Jn,"undefined",()=>null,()=>{}),Ge(zl,"bigint",e=>e.toString(),e=>typeof BigInt<"u"?BigInt(e):e),Ge(Rl,"Date",e=>e.toISOString(),e=>new Date(e)),Ge(Fl,"Error",(e,s)=>{const n={name:e.name,message:e.message};return s.allowedErrorProps.forEach(a=>{n[a]=e[a]}),n},(e,s)=>{const n=new Error(e.message);return n.name=e.name,n.stack=e.stack,s.allowedErrorProps.forEach(a=>{n[a]=e[a]}),n}),Ge(Ol,"regexp",e=>""+e,e=>{const s=e.slice(1,e.lastIndexOf("/")),n=e.slice(e.lastIndexOf("/")+1);return new RegExp(s,n)}),Ge(_t,"set",e=>[...e.values()],e=>new Set(e)),Ge(It,"map",e=>[...e.entries()],e=>new Map(e)),Ge(e=>tn(e)||Hl(e),"number",e=>tn(e)?"NaN":e>0?"Infinity":"-Infinity",Number),Ge(e=>e===0&&1/e===-1/0,"number",()=>"-0",Number),Ge(Kl,"URL",e=>e.toString(),e=>new URL(e))];function cs(e,s,n,a){return{isApplicable:e,annotation:s,transform:n,untransform:a}}var na=cs((e,s)=>ea(e)?!!s.symbolRegistry.getIdentifier(e):!1,(e,s)=>["symbol",s.symbolRegistry.getIdentifier(e)],e=>e.description,(e,s,n)=>{const a=n.symbolRegistry.getValue(s[1]);if(!a)throw new Error("Trying to deserialize unknown symbol");return a}),Vl=[Int8Array,Uint8Array,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array,Uint8ClampedArray].reduce((e,s)=>(e[s.name]=s,e),{}),aa=cs($l,e=>["typed-array",e.constructor.name],e=>[...e],(e,s)=>{const n=Vl[s[1]];if(!n)throw new Error("Trying to deserialize unknown typed array");return new n(e)});function ra(e,s){return e!=null&&e.constructor?!!s.classRegistry.getIdentifier(e.constructor):!1}var ia=cs(ra,(e,s)=>["class",s.classRegistry.getIdentifier(e.constructor)],(e,s)=>{const n=s.classRegistry.getAllowedProps(e.constructor);if(!n)return{...e};const a={};return n.forEach(r=>{a[r]=e[r]}),a},(e,s,n)=>{const a=n.classRegistry.getValue(s[1]);if(!a)throw new Error("Trying to deserialize unknown class - check https://github.com/blitz-js/superjson/issues/116#issuecomment-773996564");return Object.assign(Object.create(a.prototype),e)}),la=cs((e,s)=>!!s.customTransformerRegistry.findApplicable(e),(e,s)=>["custom",s.customTransformerRegistry.findApplicable(e).name],(e,s)=>s.customTransformerRegistry.findApplicable(e).serialize(e),(e,s,n)=>{const a=n.customTransformerRegistry.findByName(s[1]);if(!a)throw new Error("Trying to deserialize unknown custom value");return a.deserialize(e)}),Wl=[ia,na,la,aa],sn=(e,s)=>{const n=en(Wl,r=>r.isApplicable(e,s));if(n)return{value:n.transform(e,s),type:n.annotation(e,s)};const a=en(sa,r=>r.isApplicable(e,s));if(a)return{value:a.transform(e,s),type:a.annotation}},oa={};sa.forEach(e=>{oa[e.annotation]=e});var Ql=(e,s,n)=>{if(Ke(s))switch(s[0]){case"symbol":return na.untransform(e,s,n);case"class":return ia.untransform(e,s,n);case"custom":return la.untransform(e,s,n);case"typed-array":return aa.untransform(e,s,n);default:throw new Error("Unknown transformation: "+s)}else{const a=oa[s];if(!a)throw new Error("Unknown transformation: "+s);return a.untransform(e,n)}},nt=(e,s)=>{const n=e.keys();for(;s>0;)n.next(),s--;return n.next().value};function ca(e){if(Xt(e,"__proto__"))throw new Error("__proto__ is not allowed as a property");if(Xt(e,"prototype"))throw new Error("prototype is not allowed as a property");if(Xt(e,"constructor"))throw new Error("constructor is not allowed as a property")}var Yl=(e,s)=>{ca(s);for(let n=0;n<s.length;n++){const a=s[n];if(_t(e))e=nt(e,+a);else if(It(e)){const r=+a,i=+s[++n]==0?"key":"value",l=nt(e,r);switch(i){case"key":e=l;break;case"value":e=e.get(l);break}}else e=e[a]}return e},Es=(e,s,n)=>{if(ca(s),s.length===0)return n(e);let a=e;for(let i=0;i<s.length-1;i++){const l=s[i];if(Ke(a)){const o=+l;a=a[o]}else if(Pt(a))a=a[l];else if(_t(a)){const o=+l;a=nt(a,o)}else if(It(a)){if(i===s.length-2)break;const u=+l,d=+s[++i]==0?"key":"value",m=nt(a,u);switch(d){case"key":a=m;break;case"value":a=a.get(m);break}}}const r=s[s.length-1];if(Ke(a)?a[+r]=n(a[+r]):Pt(a)&&(a[r]=n(a[r])),_t(a)){const i=nt(a,+r),l=n(i);i!==l&&(a.delete(i),a.add(l))}if(It(a)){const i=+s[s.length-2],l=nt(a,i);switch(+r==0?"key":"value"){case"key":{const u=n(l);a.set(u,a.get(l)),u!==l&&a.delete(l);break}case"value":{a.set(l,n(a.get(l)));break}}}return e};function Ss(e,s,n=[]){if(!e)return;if(!Ke(e)){jt(e,(i,l)=>Ss(i,s,[...n,...At(l)]));return}const[a,r]=e;r&&jt(r,(i,l)=>{Ss(i,s,[...n,...At(l)])}),s(a,n)}function Xl(e,s,n){return Ss(s,(a,r)=>{e=Es(e,r,i=>Ql(i,a,n))}),e}function Zl(e,s){function n(a,r){const i=Yl(e,At(r));a.map(At).forEach(l=>{e=Es(e,l,()=>i)})}if(Ke(s)){const[a,r]=s;a.forEach(i=>{e=Es(e,At(i),()=>e)}),r&&jt(r,n)}else jt(s,n);return e}var Jl=(e,s)=>Pt(e)||Ke(e)||It(e)||_t(e)||ra(e,s);function eo(e,s,n){const a=n.get(e);a?a.push(s):n.set(e,[s])}function to(e,s){const n={};let a;return e.forEach(r=>{if(r.length<=1)return;s||(r=r.map(o=>o.map(String)).sort((o,u)=>o.length-u.length));const[i,...l]=r;i.length===0?a=l.map(fs):n[fs(i)]=l.map(fs)}),a?bs(n)?[a]:[a,n]:bs(n)?void 0:n}var ua=(e,s,n,a,r=[],i=[],l=new Map)=>{const o=ql(e);if(!o){eo(e,r,s);const y=l.get(e);if(y)return a?{transformedValue:null}:y}if(!Jl(e,n)){const y=sn(e,n),p=y?{transformedValue:y.value,annotations:[y.type]}:{transformedValue:e};return o||l.set(e,p),p}if(Xt(i,e))return{transformedValue:null};const u=sn(e,n),d=(u==null?void 0:u.value)??e,m=Ke(d)?[]:{},f={};jt(d,(y,p)=>{if(p==="__proto__"||p==="constructor"||p==="prototype")throw new Error(`Detected property ${p}. This is a prototype pollution risk, please remove it from your object.`);const S=ua(y,s,n,a,[...r,p],[...i,e],l);m[p]=S.transformedValue,Ke(S.annotations)?f[p]=S.annotations:Pt(S.annotations)&&jt(S.annotations,(E,_)=>{f[ta(p)+"."+_]=E})});const v=bs(f)?{transformedValue:m,annotations:u?[u.type]:void 0}:{transformedValue:m,annotations:u?[u.type,f]:f};return o||l.set(e,v),v};function da(e){return Object.prototype.toString.call(e).slice(8,-1)}function nn(e){return da(e)==="Array"}function so(e){if(da(e)!=="Object")return!1;const s=Object.getPrototypeOf(e);return!!s&&s.constructor===Object&&s===Object.prototype}function no(e,s,n,a,r){const i={}.propertyIsEnumerable.call(a,s)?"enumerable":"nonenumerable";i==="enumerable"&&(e[s]=n),r&&i==="nonenumerable"&&Object.defineProperty(e,s,{value:n,enumerable:!1,writable:!0,configurable:!0})}function ws(e,s={}){if(nn(e))return e.map(r=>ws(r,s));if(!so(e))return e;const n=Object.getOwnPropertyNames(e),a=Object.getOwnPropertySymbols(e);return[...n,...a].reduce((r,i)=>{if(nn(s.props)&&!s.props.includes(i))return r;const l=e[i],o=ws(l,s);return no(r,i,o,e,s.nonenumerable),r},{})}var me=class{constructor({dedupe:e=!1}={}){this.classRegistry=new Il,this.symbolRegistry=new Zn(s=>s.description??""),this.customTransformerRegistry=new Dl,this.allowedErrorProps=[],this.dedupe=e}serialize(e){const s=new Map,n=ua(e,s,this,this.dedupe),a={json:n.transformedValue};n.annotations&&(a.meta={...a.meta,values:n.annotations});const r=to(s,this.dedupe);return r&&(a.meta={...a.meta,referentialEqualities:r}),a}deserialize(e){const{json:s,meta:n}=e;let a=ws(s);return n!=null&&n.values&&(a=Xl(a,n.values,this)),n!=null&&n.referentialEqualities&&(a=Zl(a,n.referentialEqualities)),a}stringify(e){return JSON.stringify(this.serialize(e))}parse(e){return this.deserialize(JSON.parse(e))}registerClass(e,s){this.classRegistry.register(e,s)}registerSymbol(e,s){this.symbolRegistry.register(e,s)}registerCustom(e,s){this.customTransformerRegistry.register({name:s,...e})}allowErrorProps(...e){this.allowedErrorProps.push(...e)}};me.defaultInstance=new me;me.serialize=me.defaultInstance.serialize.bind(me.defaultInstance);me.deserialize=me.defaultInstance.deserialize.bind(me.defaultInstance);me.stringify=me.defaultInstance.stringify.bind(me.defaultInstance);me.parse=me.defaultInstance.parse.bind(me.defaultInstance);me.registerClass=me.defaultInstance.registerClass.bind(me.defaultInstance);me.registerSymbol=me.defaultInstance.registerSymbol.bind(me.defaultInstance);me.registerCustom=me.defaultInstance.registerCustom.bind(me.defaultInstance);me.allowErrorProps=me.defaultInstance.allowErrorProps.bind(me.defaultInstance);var ma=me.serialize,ao=me.stringify;function ro(e){return e.state.fetchStatus==="fetching"?"fetching":e.getObserversCount()?e.state.fetchStatus==="paused"?"paused":e.isStale()?"stale":"fresh":"inactive"}function io(e,s){return`${e}${s.charAt(0).toUpperCase()+s.slice(1)}`}function lo({queryState:e,observerCount:s,isStale:n}){return e.fetchStatus==="fetching"?"blue":s?e.fetchStatus==="paused"?"purple":n?"yellow":"green":"gray"}function oo({status:e,isPaused:s}){return s?"purple":e==="error"?"red":e==="pending"?"yellow":e==="success"?"green":"gray"}function co(e){return e==="fresh"?"green":e==="stale"?"yellow":e==="paused"?"purple":e==="inactive"?"gray":"blue"}var uo=(e,s=!1)=>{const{json:n}=ma(e);return JSON.stringify(n,null,s?2:void 0)},Wt=e=>e.state.fetchStatus!=="idle"?0:e.getObserversCount()?e.isStale()?2:1:3,mo=(e,s)=>e.queryHash.localeCompare(s.queryHash),ha=(e,s)=>e.state.dataUpdatedAt<s.state.dataUpdatedAt?1:-1,ho=(e,s)=>Wt(e)===Wt(s)?ha(e,s):Wt(e)>Wt(s)?1:-1,fo={status:ho,"query hash":mo,"last updated":ha},Qt=e=>e.state.isPaused?0:e.state.status==="error"?2:e.state.status==="pending"?1:3,fa=(e,s)=>e.state.submittedAt<s.state.submittedAt?1:-1,go=(e,s)=>Qt(e)===Qt(s)?fa(e,s):Qt(e)>Qt(s)?1:-1,xo={status:go,"last updated":fa},po=e=>e*parseFloat(getComputedStyle(document.documentElement).fontSize),yo=()=>{const[e,s]=ye("dark");return Bn(()=>{const n=window.matchMedia("(prefers-color-scheme: dark)");s(n.matches?"dark":"light");const a=r=>{s(r.matches?"dark":"light")};n.addEventListener("change",a),vt(()=>n.removeEventListener("change",a))}),e},St=(e,s,n)=>{if(s.length===0)return n;if(e instanceof Map){const a=new Map(e);if(s.length===1)return a.set(s[0],n),a;const[r,...i]=s;return a.set(r,St(a.get(r),i,n)),a}if(e instanceof Set){const a=St(Array.from(e),s,n);return new Set(a)}if(Array.isArray(e)){const a=[...e];if(s.length===1)return a[s[0]]=n,a;const[r,...i]=s;return a[r]=St(a[r],i,n),a}if(e instanceof Object){const a={...e};if(s.length===1)return a[s[0]]=n,a;const[r,...i]=s;return a[r]=St(a[r],i,n),a}return e},wt=(e,s)=>{if(e instanceof Map){const n=new Map(e);if(s.length===1)return n.delete(s[0]),n;const[a,...r]=s;return n.set(a,wt(n.get(a),r)),n}if(e instanceof Set){const n=wt(Array.from(e),s);return new Set(n)}if(Array.isArray(e)){const n=[...e];if(s.length===1)return n.filter((i,l)=>l.toString()!==s[0]);const[a,...r]=s;return n[a]=wt(n[a],r),n}if(e instanceof Object){const n={...e};if(s.length===1)return delete n[s[0]],n;const[a,...r]=s;return n[a]=wt(n[a],r),n}return e},ga=(e,s)=>{if(!e||document.querySelector("#_goober")||(s==null?void 0:s.querySelector("#_goober")))return;const a=document.createElement("style"),r=document.createTextNode("");a.appendChild(r),a.id="_goober",a.setAttribute("nonce",e),s?s.appendChild(a):document.head.appendChild(a)},at,kt,Dt,Lt,We,Bt,rt,it,lt,ot,ct,ut,Gt,an,vo=(an=class{constructor(e){ue(this,at);ue(this,kt);ue(this,Dt);ue(this,Lt);ue(this,We,!1);ue(this,Bt);ue(this,rt);ue(this,it);ue(this,lt);ue(this,ot);ue(this,ct);ue(this,ut);ue(this,Gt);const{client:s,queryFlavor:n,version:a,onlineManager:r,buttonPosition:i,position:l,initialIsOpen:o,errorTypes:u,styleNonce:d,shadowDOMTarget:m}=e;oe(this,at,ye(s)),oe(this,Dt,n),oe(this,Lt,a),oe(this,kt,r),oe(this,Bt,d),oe(this,rt,m),oe(this,it,ye(i)),oe(this,lt,ye(l)),oe(this,ot,ye(o)),oe(this,ct,ye(u))}setButtonPosition(e){H(this,it)[1](e)}setPosition(e){H(this,lt)[1](e)}setInitialIsOpen(e){H(this,ot)[1](e)}setErrorTypes(e){H(this,ct)[1](e)}setClient(e){H(this,at)[1](e)}mount(e){if(H(this,We))throw new Error("Devtools is already mounted");const s=Hn(()=>{const n=this,[a]=H(this,it),[r]=H(this,lt),[i]=H(this,ot),[l]=H(this,ct),[o]=H(this,at);let u;return H(this,ut)?u=H(this,ut):(u=qn(()=>Promise.resolve().then(()=>require("./HO4MOOFI-CH5TIJEX.cjs"))),oe(this,ut,u)),ga(H(this,Bt),H(this,rt)),Gs(u,Ms({get queryFlavor(){return H(n,Dt)},get version(){return H(n,Lt)},get onlineManager(){return H(n,kt)},get shadowDOMTarget(){return H(n,rt)}},{get client(){return o()},get buttonPosition(){return a()},get position(){return r()},get initialIsOpen(){return i()},get errorTypes(){return l()}}))},e);oe(this,We,!0),oe(this,Gt,s)}unmount(){var e;if(!H(this,We))throw new Error("Devtools is not mounted");(e=H(this,Gt))==null||e.call(this),oe(this,We,!1)}},at=new WeakMap,kt=new WeakMap,Dt=new WeakMap,Lt=new WeakMap,We=new WeakMap,Bt=new WeakMap,rt=new WeakMap,it=new WeakMap,lt=new WeakMap,ot=new WeakMap,ct=new WeakMap,ut=new WeakMap,Gt=new WeakMap,an),dt,Mt,Ut,Ot,Qe,Rt,mt,ht,ft,gt,xt,pt,yt,Ft,rn,jo=(rn=class{constructor(e){ue(this,dt);ue(this,Mt);ue(this,Ut);ue(this,Ot);ue(this,Qe,!1);ue(this,Rt);ue(this,mt);ue(this,ht);ue(this,ft);ue(this,gt);ue(this,xt);ue(this,pt);ue(this,yt);ue(this,Ft);const{client:s,queryFlavor:n,version:a,onlineManager:r,buttonPosition:i,position:l,initialIsOpen:o,errorTypes:u,styleNonce:d,shadowDOMTarget:m,onClose:f}=e;oe(this,dt,ye(s)),oe(this,Ut,n),oe(this,Ot,a),oe(this,Mt,r),oe(this,Rt,d),oe(this,mt,m),oe(this,ht,ye(i)),oe(this,ft,ye(l)),oe(this,gt,ye(o)),oe(this,xt,ye(u)),oe(this,pt,ye(f))}setButtonPosition(e){H(this,ht)[1](e)}setPosition(e){H(this,ft)[1](e)}setInitialIsOpen(e){H(this,gt)[1](e)}setErrorTypes(e){H(this,xt)[1](e)}setClient(e){H(this,dt)[1](e)}setOnClose(e){H(this,pt)[1](()=>e)}mount(e){if(H(this,Qe))throw new Error("Devtools is already mounted");const s=Hn(()=>{const n=this,[a]=H(this,ht),[r]=H(this,ft),[i]=H(this,gt),[l]=H(this,xt),[o]=H(this,dt),[u]=H(this,pt);let d;return H(this,yt)?d=H(this,yt):(d=qn(()=>Promise.resolve().then(()=>require("./HUY7CZI3-CvHF_hS5.cjs"))),oe(this,yt,d)),ga(H(this,Rt),H(this,mt)),Gs(d,Ms({get queryFlavor(){return H(n,Ut)},get version(){return H(n,Ot)},get onlineManager(){return H(n,Mt)},get shadowDOMTarget(){return H(n,mt)}},{get client(){return o()},get buttonPosition(){return a()},get position(){return r()},get initialIsOpen(){return i()},get errorTypes(){return l()},get onClose(){return u()}}))},e);oe(this,Qe,!0),oe(this,Ft,s)}unmount(){var e;if(!H(this,Qe))throw new Error("Devtools is not mounted");(e=H(this,Ft))==null||e.call(this),oe(this,Qe,!1)}},dt=new WeakMap,Mt=new WeakMap,Ut=new WeakMap,Ot=new WeakMap,Qe=new WeakMap,Rt=new WeakMap,mt=new WeakMap,ht=new WeakMap,ft=new WeakMap,gt=new WeakMap,xt=new WeakMap,pt=new WeakMap,yt=new WeakMap,Ft=new WeakMap,rn);function bo(e){const s=L.useQueryClient(e.client),n=pe.useRef(null),{buttonPosition:a,position:r,initialIsOpen:i,errorTypes:l,styleNonce:o,shadowDOMTarget:u}=e,[d]=pe.useState(new vo({client:s,queryFlavor:"React Query",version:"5",onlineManager:L.onlineManager,buttonPosition:a,position:r,initialIsOpen:i,errorTypes:l,styleNonce:o,shadowDOMTarget:u}));return pe.useEffect(()=>{d.setClient(s)},[s,d]),pe.useEffect(()=>{a&&d.setButtonPosition(a)},[a,d]),pe.useEffect(()=>{r&&d.setPosition(r)},[r,d]),pe.useEffect(()=>{d.setInitialIsOpen(i||!1)},[i,d]),pe.useEffect(()=>{d.setErrorTypes(l||[])},[l,d]),pe.useEffect(()=>(n.current&&d.mount(n.current),()=>{d.unmount()}),[d]),t.jsx("div",{className:"tsqd-parent-container",ref:n})}function Eo(e){const s=L.useQueryClient(e.client),n=pe.useRef(null),{errorTypes:a,styleNonce:r,shadowDOMTarget:i}=e,[l]=pe.useState(new jo({client:s,queryFlavor:"React Query",version:"5",onlineManager:L.onlineManager,buttonPosition:"bottom-left",position:"bottom",initialIsOpen:!0,errorTypes:a,styleNonce:r,shadowDOMTarget:i,onClose:e.onClose}));return pe.useEffect(()=>{l.setClient(s)},[s,l]),pe.useEffect(()=>{l.setOnClose(e.onClose??(()=>{}))},[e.onClose,l]),pe.useEffect(()=>{l.setErrorTypes(a||[])},[a,l]),pe.useEffect(()=>(n.current&&l.mount(n.current),()=>{l.unmount()}),[l]),t.jsx("div",{style:{height:"500px",...e.style},className:"tsqd-parent-container",ref:n})}var So=process.env.NODE_ENV!=="development"?function(){return null}:bo;process.env.NODE_ENV;const wo=()=>{const e=ne(),s=$();return L.useQuery({queryKey:[z,P.GET_COLLECTIONS],initialData:[],queryFn:async()=>s(e,{action:P.GET_COLLECTIONS})})},No=()=>{const{data:e}=Ie(),{data:s}=Ve(),n=ne(),a=$(),r=g.useMemo(()=>(s==null?void 0:s.fallbackLang)||"en",[s==null?void 0:s.fallbackLang]);return L.useMutation({mutationFn:async({block:i})=>a(n,{action:P.GET_BLOCK_ASYNC_PROPS,data:{block:i,lang:(e==null?void 0:e.lang)||r,pageProps:{slug:e==null?void 0:e.slug,searchParams:{}}}})})},Ao=g.lazy(()=>Promise.resolve().then(()=>wi));ba.loadWebBlocks();ee.registerChaiTopBar(ti);ki();ee.registerChaiMediaManager(Ao);ee.registerChaiSaveToLibrary(Ya);const Co=e=>{const s=g.useRef([]),[n]=Pe(),a=n.get("page"),{data:r}=Ie(),{data:i={role:"",permissions:null}}=Nn();ri();const{data:l,isFetching:o}=xn(),{blocks:u}=ai(l),{data:d}=Ce(),{mutateAsync:m}=dn(),f=si(),{onSave:v}=ii(),{getPartialBlocks:y,getPartialBlockBlocks:p}=li(),{aiContext:S,setAiContext:E}=As(),{mutateAsync:_}=Ja(),[w,k]=g.useState(!1),{data:b}=Ve(),B=Ts(),{data:F}=pn(),{data:te}=wo(),{mutateAsync:R}=No();La(),g.useEffect(()=>{const O=()=>{document.hidden?k(!0):k(!1)};return window.addEventListener("visibilitychange",O),()=>window.removeEventListener("visibilitychange",O)},[]),s.current=u;const K=g.useMemo(()=>{const O={};return i&&(O.permissions=x.get(i,"permissions",null),O.role=x.get(i,"role","user")),O},[i]),M=g.useCallback(async(O,je)=>await _({pageType:O,query:je}),[_]),X=g.useMemo(()=>x.get(b,"theme",{})||{},[b]);return t.jsxs(t.Fragment,{children:[o&&t.jsx("div",{className:"absolute inset-0 z-50 flex items-center justify-center w-screen h-screen bg-white/30",children:t.jsx("div",{className:"flex items-center justify-center bg-white rounded-full size-10",children:t.jsx(N.Loader2,{className:"size-5 animate-spin"})})}),t.jsx(ee.ChaiBuilderEditor,{collections:te??[],getBlockAsyncProps:R,pageExternalData:F,themePresets:e.themePresets??[],pageId:r==null?void 0:r.id,loading:o,fallbackLang:B,languages:(b==null?void 0:b.languages)||[],brandingOptions:(b==null?void 0:b.theme)||{},translations:e.translations||{},locale:e.locale||"en",htmlDir:e.htmlDir||"ltr",autoSaveSupport:!w&&(e.autoSaveSupport??!0),autoSaveInterval:e.autoSaveInterval??15,onError:e.onError||console.error,getPartialBlockBlocks:p,getPartialBlocks:y,blocks:o?[]:u,theme:x.cloneDeep(X),pageTypes:d,searchPageTypeItems:M,saveAiContextCallback:async O=>{if(!a)return!0;const je=s.current,V={_type:"@chai/ai-context",_value:x.isString(O)?O:""},I=[...je,V];return await v({page:a,blocks:I}),E(O),!0},aiContext:S,askAiCallBack:f,onSave:async({blocks:O,theme:je})=>{if(!a)return!0;s.current=O;const V={_type:"@chai/ai-context",_value:x.isString(S)?S:""},I=[...O,V];return await v({page:a,blocks:I}),s.current=I,x.isEqual(je,X)||await m({settings:{theme:je}}),!0},themePanelComponent:or,...K}),t.jsxs("div",{children:[t.jsx(Oa,{}),t.jsx(Ra,{})]})]})},To=new L.QueryClient({defaultOptions:{queries:{refetchOnWindowFocus:!1,refetchOnReconnect:!1}}}),Po=e=>{const{isLoggedIn:s}=Re(),[,n]=mn(),[a,r]=g.useState(!1);return g.useEffect(()=>(n(x.pick(e,["apiUrl","usersApiUrl","assetsApiUrl","getPreviewUrl","getLiveUrl","logo","onLogout"])),setTimeout(()=>{r(!0)},200),()=>{r(!1),n({})}),[e,n]),a?t.jsxs(L.QueryClientProvider,{client:To,children:[s?t.jsx(Co,{...e}):t.jsx(di,{}),t.jsx(So,{})]}):t.jsx("div",{})},Io=()=>{const e=ne(),s=$(),{data:n}=fn(),a=L.useQueryClient();return L.useMutation({mutationFn:async r=>{if(!(n!=null&&n.id))throw new Error("No active page found");return await s(`${e}`,{action:P.UPDATE_PAGE_METADATA,data:{id:n.id,metadata:r}})},onSuccess:()=>{a.invalidateQueries({queryKey:[z,P.GET_BUILDER_PAGE_DATA]}),a.invalidateQueries({queryKey:[z,P.GET_LANGUAGE_PAGES]})},onError:()=>{console.error("Failed to update metadata")}})},_o=()=>{const{user:e,logout:s}=Re(),n=e==null?void 0:e.accessToken;return g.useCallback(async({url:a,method:r="GET",body:i={},headers:l={}})=>{if(!n)throw new Error("No auth token");if(!a)throw new Error("URL is required");try{const o=await fetch(a,{method:r,headers:{"Content-Type":"application/json",Authorization:`Bearer ${n}`,...l},body:JSON.stringify(i)});if(o.status===401)return console.log("Session expired",o),await s(),null;if(o.status===400)throw new Error((await o.json()).error);return await o.json()}catch(o){throw console.log("Something went wrong",o),o}},[n,s])};if(typeof window>"u")throw new Error("@chaibuilder/pages is not available on the server");exports.$TRACK=Ds;exports.ChaiBuilderPages=Po;exports.Dynamic=Tl;exports.For=tl;exports.ImagePicker=Tn;exports.Index=sl;exports.Match=rl;exports.PermissionChecker=ke;exports.Portal=Cl;exports.Show=nl;exports.Switch=al;exports.addEventListener=Vn;exports.batch=Mi;exports.className=Kn;exports.clearDelegatedEvents=pl;exports.convertRemToPixels=po;exports.createComponent=Gs;exports.createComputed=Ln;exports.createContext=zi;exports.createEffect=Ls;exports.createMemo=Te;exports.createRenderEffect=$e;exports.createRoot=He;exports.createSignal=ye;exports.createUniqueId=el;exports.delegateEvents=$n;exports.deleteNestedDataByPath=wt;exports.displayValue=uo;exports.getMutationStatusColor=oo;exports.getPreferredColorScheme=yo;exports.getQueryStatusColor=lo;exports.getQueryStatusColorByLabel=co;exports.getQueryStatusLabel=ro;exports.getSidedProp=io;exports.insert=is;exports.mergeProps=Ms;exports.mutationSortFns=xo;exports.on=Ui;exports.onCleanup=vt;exports.onMount=Bn;exports.registerLoginComponent=ui;exports.serialize=ma;exports.setAttribute=rs;exports.sortFns=fo;exports.splitProps=Fn;exports.spread=Wn;exports.stringify=ao;exports.template=xl;exports.untrack=Se;exports.updateNestedDataByPath=St;exports.use=Qn;exports.useActivePage=fn;exports.useChaiAuth=Re;exports.useChaiFetch=_o;exports.useChaiUserInfo=Ze;exports.useContext=Hi;exports.useCurrentPage=Ie;exports.useFallbackLang=Ts;exports.useFetch=$;exports.useLanguagePages=Xe;exports.useTransition=qi;exports.useUpdateActivePageMetadata=Io;exports.useUserRoleAndPermissions=Nn;exports.useWebsitePages=Ht;exports.useWebsiteSetting=Ve;
|