@chaibuilder/pages 0.2.4 → 0.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +0,0 @@
1
- "use strict";var Is=e=>{throw TypeError(e)};var _s=(e,t,s)=>t.has(e)||Is("Cannot "+s);var R=(e,t,s)=>(_s(e,t,"read from private field"),s?s.call(e):t.get(e)),te=(e,t,s)=>t.has(e)?Is("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,s),J=(e,t,s,r)=>(_s(e,t,"write to private field"),r?r.call(e,s):t.set(e,s),s);const n=require("react/jsx-runtime"),ae=require("@chaibuilder/sdk"),er=require("@chaibuilder/sdk/web-blocks"),U=require("@tanstack/react-query"),S=require("react"),g=require("lodash-es"),I=require("lucide-react"),ct=require("jotai"),oe=require("sonner"),Vs=require("@chaibuilder/runtime"),c=require("@chaibuilder/sdk/ui"),kt=require("date-fns");function tr(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const s in e)if(s!=="default"){const r=Object.getOwnPropertyDescriptor(e,s);Object.defineProperty(t,s,r.get?r:{enumerable:!0,get:()=>e[s]})}}return t.default=e,Object.freeze(t)}const le=tr(S);var B={context:void 0,registry:void 0,effects:void 0,done:!1,getContextId(){return Ls(this.context.count)},getNextContextId(){return Ls(this.context.count++)}};function Ls(e){const t=String(e),s=t.length-1;return B.context.id+(s?String.fromCharCode(96+s):"")+t}function mt(e){B.context=e}var sr=(e,t)=>e===t,Ft=Symbol("solid-proxy"),$s=typeof Proxy=="function",ms=Symbol("solid-track"),qt={equals:sr},Ks=Js,Me=1,Ht=2,zs={owned:null,cleanups:null,context:null,owner:null},es={},X=null,ts=null,nr=null,se=null,pe=null,Ge=null,Yt=0;function Ue(e,t){const s=se,r=X,a=e.length===0,i=t===void 0?r:t,o=a?zs:{owned:null,cleanups:null,context:i?i.context:null,owner:i},l=a?e:()=>e(()=>fe(()=>Et(o)));X=o,se=null;try{return _e(l,!0)}finally{se=s,X=r}}function he(e,t){t=t?Object.assign({},qt,t):qt;const s={value:e,observers:null,observerSlots:null,comparator:t.equals||void 0},r=a=>(typeof a=="function"&&(a=a(s.value)),Zs(s,a));return[Xs.bind(s),r]}function Ws(e,t,s){const r=Xt(e,t,!0,Me);ut(r)}function Oe(e,t,s){const r=Xt(e,t,!1,Me);ut(r)}function gs(e,t,s){Ks=pr;const r=Xt(e,t,!1,Me);(!s||!s.render)&&(r.user=!0),Ge?Ge.push(r):ut(r)}function ye(e,t,s){s=s?Object.assign({},qt,s):qt;const r=Xt(e,t,!0,0);return r.observers=null,r.observerSlots=null,r.comparator=s.equals||void 0,ut(r),Xs.bind(r)}function rr(e){return e&&typeof e=="object"&&"then"in e}function ar(e,t,s){let r,a,i;arguments.length===1?(r=!0,a=e,i={}):(r=e,a=t,i={});let o=null,l=es,u=null,d=!1,f="initialValue"in i,m=typeof r=="function"&&ye(r);const w=new Set,[E,y]=(i.storage||he)(i.initialValue),[j,b]=he(void 0),[D,A]=he(void 0,{equals:!1}),[T,v]=he(f?"ready":"unresolved");B.context&&(u=B.getNextContextId(),i.ssrLoadFrom==="initial"?l=i.initialValue:B.load&&B.has(u)&&(l=B.load(u)));function P(N,G,H,Y){return o===N&&(o=null,Y!==void 0&&(f=!0),(N===l||G===l)&&i.onHydrated&&queueMicrotask(()=>i.onHydrated(Y,{value:G})),l=es,F(G,H)),G}function F(N,G){_e(()=>{G===void 0&&y(()=>N),v(G!==void 0?"errored":f?"ready":"unresolved"),b(G);for(const H of w.keys())H.decrement();w.clear()},!1)}function C(){const N=mr,G=E(),H=j();if(H!==void 0&&!o)throw H;return se&&se.user,G}function k(N=!0){if(N!==!1&&d)return;d=!1;const G=m?m():r;if(G==null||G===!1){P(o,fe(E));return}const H=l!==es?l:fe(()=>a(G,{value:E(),refetching:N}));return rr(H)?(o=H,"value"in H?(H.status==="success"?P(o,H.value,void 0,G):P(o,void 0,as(H.value),G),H):(d=!0,queueMicrotask(()=>d=!1),_e(()=>{v(f?"refreshing":"pending"),A()},!1),H.then(Y=>P(H,Y,void 0,G),Y=>P(H,void 0,as(Y),G)))):(P(o,H,void 0,G),H)}return Object.defineProperties(C,{state:{get:()=>T()},error:{get:()=>j()},loading:{get(){const N=T();return N==="pending"||N==="refreshing"}},latest:{get(){if(!f)return C();const N=j();if(N&&!o)throw N;return E()}}}),m?Ws(()=>k(!1)):k(!1),[C,{refetch:k,mutate:y}]}function ir(e){return _e(e,!1)}function fe(e){if(se===null)return e();const t=se;se=null;try{return e()}finally{se=t}}function or(e,t,s){const r=Array.isArray(e);let a,i=s&&s.defer;return o=>{let l;if(r){l=Array(e.length);for(let d=0;d<e.length;d++)l[d]=e[d]()}else l=e();if(i)return i=!1,o;const u=fe(()=>t(l,a,o));return a=l,u}}function Qs(e){gs(()=>fe(e))}function ot(e){return X===null||(X.cleanups===null?X.cleanups=[e]:X.cleanups.push(e)),e}function Ds(){return X}function lr(e,t){const s=X,r=se;X=e,se=null;try{return _e(t,!0)}catch(a){xs(a)}finally{X=s,se=r}}function cr(e){const t=se,s=X;return Promise.resolve().then(()=>{se=t,X=s;let r;return _e(e,!1),se=X=null,r?r.done:void 0})}var[ur,ho]=he(!1);function dr(){return[ur,cr]}function hr(e,t){const s=Symbol("context");return{id:s,Provider:yr(s),defaultValue:e}}function fr(e){let t;return X&&X.context&&(t=X.context[e.id])!==void 0?t:e.defaultValue}function Ys(e){const t=ye(e),s=ye(()=>is(t()));return s.toArray=()=>{const r=s();return Array.isArray(r)?r:r!=null?[r]:[]},s}var mr;function Xs(){if(this.sources&&this.state)if(this.state===Me)ut(this);else{const e=pe;pe=null,_e(()=>$t(this),!1),pe=e}if(se){const e=this.observers?this.observers.length:0;se.sources?(se.sources.push(this),se.sourceSlots.push(e)):(se.sources=[this],se.sourceSlots=[e]),this.observers?(this.observers.push(se),this.observerSlots.push(se.sources.length-1)):(this.observers=[se],this.observerSlots=[se.sources.length-1])}return this.value}function Zs(e,t,s){let r=e.value;return(!e.comparator||!e.comparator(r,t))&&(e.value=t,e.observers&&e.observers.length&&_e(()=>{for(let a=0;a<e.observers.length;a+=1){const i=e.observers[a],o=ts&&ts.running;o&&ts.disposed.has(i),(o?!i.tState:!i.state)&&(i.pure?pe.push(i):Ge.push(i),i.observers&&en(i)),o||(i.state=Me)}if(pe.length>1e6)throw pe=[],new Error},!1)),t}function ut(e){if(!e.fn)return;Et(e);const t=Yt;gr(e,e.value,t)}function gr(e,t,s){let r;const a=X,i=se;se=X=e;try{r=e.fn(t)}catch(o){return e.pure&&(e.state=Me,e.owned&&e.owned.forEach(Et),e.owned=null),e.updatedAt=s+1,xs(o)}finally{se=i,X=a}(!e.updatedAt||e.updatedAt<=s)&&(e.updatedAt!=null&&"observers"in e?Zs(e,r):e.value=r,e.updatedAt=s)}function Xt(e,t,s,r=Me,a){const i={fn:e,state:r,updatedAt:null,owned:null,sources:null,sourceSlots:null,cleanups:null,value:t,owner:X,context:X?X.context:null,pure:s};return X===null||X!==zs&&(X.owned?X.owned.push(i):X.owned=[i]),i}function Vt(e){if(e.state===0)return;if(e.state===Ht)return $t(e);if(e.suspense&&fe(e.suspense.inFallback))return e.suspense.effects.push(e);const t=[e];for(;(e=e.owner)&&(!e.updatedAt||e.updatedAt<Yt);)e.state&&t.push(e);for(let s=t.length-1;s>=0;s--)if(e=t[s],e.state===Me)ut(e);else if(e.state===Ht){const r=pe;pe=null,_e(()=>$t(e,t[0]),!1),pe=r}}function _e(e,t){if(pe)return e();let s=!1;t||(pe=[]),Ge?s=!0:Ge=[],Yt++;try{const r=e();return xr(s),r}catch(r){s||(Ge=null),pe=null,xs(r)}}function xr(e){if(pe&&(Js(pe),pe=null),e)return;const t=Ge;Ge=null,t.length&&_e(()=>Ks(t),!1)}function Js(e){for(let t=0;t<e.length;t++)Vt(e[t])}function pr(e){let t,s=0;for(t=0;t<e.length;t++){const r=e[t];r.user?e[s++]=r:Vt(r)}if(B.context){if(B.count){B.effects||(B.effects=[]),B.effects.push(...e.slice(0,s));return}mt()}for(B.effects&&(B.done||!B.count)&&(e=[...B.effects,...e],s+=B.effects.length,delete B.effects),t=0;t<s;t++)Vt(e[t])}function $t(e,t){e.state=0;for(let s=0;s<e.sources.length;s+=1){const r=e.sources[s];if(r.sources){const a=r.state;a===Me?r!==t&&(!r.updatedAt||r.updatedAt<Yt)&&Vt(r):a===Ht&&$t(r,t)}}}function en(e){for(let t=0;t<e.observers.length;t+=1){const s=e.observers[t];s.state||(s.state=Ht,s.pure?pe.push(s):Ge.push(s),s.observers&&en(s))}}function Et(e){let t;if(e.sources)for(;e.sources.length;){const s=e.sources.pop(),r=e.sourceSlots.pop(),a=s.observers;if(a&&a.length){const i=a.pop(),o=s.observerSlots.pop();r<a.length&&(i.sourceSlots[o]=r,a[r]=i,s.observerSlots[r]=o)}}if(e.tOwned){for(t=e.tOwned.length-1;t>=0;t--)Et(e.tOwned[t]);delete e.tOwned}if(e.owned){for(t=e.owned.length-1;t>=0;t--)Et(e.owned[t]);e.owned=null}if(e.cleanups){for(t=e.cleanups.length-1;t>=0;t--)e.cleanups[t]();e.cleanups=null}e.state=0}function as(e){return e instanceof Error?e:new Error(typeof e=="string"?e:"Unknown error",{cause:e})}function xs(e,t=X){throw as(e)}function is(e){if(typeof e=="function"&&!e.length)return is(e());if(Array.isArray(e)){const t=[];for(let s=0;s<e.length;s++){const r=is(e[s]);Array.isArray(r)?t.push.apply(t,r):t.push(r)}return t}return e}function yr(e,t){return function(r){let a;return Oe(()=>a=fe(()=>(X.context={...X.context,[e]:r.value},Ys(()=>r.children))),void 0),a}}var os=Symbol("fallback");function Kt(e){for(let t=0;t<e.length;t++)e[t]()}function Er(e,t,s={}){let r=[],a=[],i=[],o=0,l=t.length>1?[]:null;return ot(()=>Kt(i)),()=>{let u=e()||[],d=u.length,f,m;return u[ms],fe(()=>{let E,y,j,b,D,A,T,v,P;if(d===0)o!==0&&(Kt(i),i=[],r=[],a=[],o=0,l&&(l=[])),s.fallback&&(r=[os],a[0]=Ue(F=>(i[0]=F,s.fallback())),o=1);else if(o===0){for(a=new Array(d),m=0;m<d;m++)r[m]=u[m],a[m]=Ue(w);o=d}else{for(j=new Array(d),b=new Array(d),l&&(D=new Array(d)),A=0,T=Math.min(o,d);A<T&&r[A]===u[A];A++);for(T=o-1,v=d-1;T>=A&&v>=A&&r[T]===u[v];T--,v--)j[v]=a[T],b[v]=i[T],l&&(D[v]=l[T]);for(E=new Map,y=new Array(v+1),m=v;m>=A;m--)P=u[m],f=E.get(P),y[m]=f===void 0?-1:f,E.set(P,m);for(f=A;f<=T;f++)P=r[f],m=E.get(P),m!==void 0&&m!==-1?(j[m]=a[f],b[m]=i[f],l&&(D[m]=l[f]),m=y[m],E.set(P,m)):i[f]();for(m=A;m<d;m++)m in j?(a[m]=j[m],i[m]=b[m],l&&(l[m]=D[m],l[m](m))):a[m]=Ue(w);a=a.slice(0,o=d),r=u.slice(0)}return a});function w(E){if(i[m]=E,l){const[y,j]=he(m);return l[m]=j,t(u[m],y)}return t(u[m])}}}function vr(e,t,s={}){let r=[],a=[],i=[],o=[],l=0,u;return ot(()=>Kt(i)),()=>{const d=e()||[],f=d.length;return d[ms],fe(()=>{if(f===0)return l!==0&&(Kt(i),i=[],r=[],a=[],l=0,o=[]),s.fallback&&(r=[os],a[0]=Ue(w=>(i[0]=w,s.fallback())),l=1),a;for(r[0]===os&&(i[0](),i=[],r=[],a=[],l=0),u=0;u<f;u++)u<r.length&&r[u]!==d[u]?o[u](()=>d[u]):u>=r.length&&(a[u]=Ue(m));for(;u<r.length;u++)i[u]();return l=o.length=i.length=f,r=d.slice(0),a=a.slice(0,l)});function m(w){i[u]=w;const[E,y]=he(d[u]);return o[u]=y,t(E,u)}}}function ps(e,t){return fe(()=>e(t||{}))}function Ut(){return!0}var ls={get(e,t,s){return t===Ft?s:e.get(t)},has(e,t){return t===Ft?!0:e.has(t)},set:Ut,deleteProperty:Ut,getOwnPropertyDescriptor(e,t){return{configurable:!0,enumerable:!0,get(){return e.get(t)},set:Ut,deleteProperty:Ut}},ownKeys(e){return e.keys()}};function ss(e){return(e=typeof e=="function"?e():e)?e:{}}function Sr(){for(let e=0,t=this.length;e<t;++e){const s=this[e]();if(s!==void 0)return s}}function ys(...e){let t=!1;for(let o=0;o<e.length;o++){const l=e[o];t=t||!!l&&Ft in l,e[o]=typeof l=="function"?(t=!0,ye(l)):l}if($s&&t)return new Proxy({get(o){for(let l=e.length-1;l>=0;l--){const u=ss(e[l])[o];if(u!==void 0)return u}},has(o){for(let l=e.length-1;l>=0;l--)if(o in ss(e[l]))return!0;return!1},keys(){const o=[];for(let l=0;l<e.length;l++)o.push(...Object.keys(ss(e[l])));return[...new Set(o)]}},ls);const s={},r=Object.create(null);for(let o=e.length-1;o>=0;o--){const l=e[o];if(!l)continue;const u=Object.getOwnPropertyNames(l);for(let d=u.length-1;d>=0;d--){const f=u[d];if(f==="__proto__"||f==="constructor")continue;const m=Object.getOwnPropertyDescriptor(l,f);if(!r[f])r[f]=m.get?{enumerable:!0,configurable:!0,get:Sr.bind(s[f]=[m.get.bind(l)])}:m.value!==void 0?m:void 0;else{const w=s[f];w&&(m.get?w.push(m.get.bind(l)):m.value!==void 0&&w.push(()=>m.value))}}}const a={},i=Object.keys(r);for(let o=i.length-1;o>=0;o--){const l=i[o],u=r[l];u&&u.get?Object.defineProperty(a,l,u):a[l]=u?u.value:void 0}return a}function tn(e,...t){if($s&&Ft in e){const a=new Set(t.length>1?t.flat():t[0]),i=t.map(o=>new Proxy({get(l){return o.includes(l)?e[l]:void 0},has(l){return o.includes(l)&&l in e},keys(){return o.filter(l=>l in e)}},ls));return i.push(new Proxy({get(o){return a.has(o)?void 0:e[o]},has(o){return a.has(o)?!1:o in e},keys(){return Object.keys(e).filter(o=>!a.has(o))}},ls)),i}const s={},r=t.map(()=>({}));for(const a of Object.getOwnPropertyNames(e)){const i=Object.getOwnPropertyDescriptor(e,a),o=!i.get&&!i.set&&i.enumerable&&i.writable&&i.configurable;let l=!1,u=0;for(const d of t)d.includes(a)&&(l=!0,o?r[u][a]=i.value:Object.defineProperty(r[u],a,i)),++u;l||(o?s[a]=i.value:Object.defineProperty(s,a,i))}return[...r,s]}function sn(e){let t,s;const r=a=>{const i=B.context;if(i){const[l,u]=he();B.count||(B.count=0),B.count++,(s||(s=e())).then(d=>{!B.done&&mt(i),B.count--,u(()=>d.default),mt()}),t=l}else if(!t){const[l]=ar(()=>(s||(s=e())).then(u=>u.default));t=l}let o;return ye(()=>(o=t())?fe(()=>{if(!i||B.done)return o(a);const l=B.context;mt(i);const u=o(a);return mt(l),u}):"")};return r.preload=()=>s||((s=e()).then(a=>t=()=>a.default),s),r}var br=0;function wr(){return B.context?B.getNextContextId():`cl-${br++}`}var nn=e=>`Stale read from <${e}>.`;function jr(e){const t="fallback"in e&&{fallback:()=>e.fallback};return ye(Er(()=>e.each,e.children,t||void 0))}function Nr(e){const t="fallback"in e&&{fallback:()=>e.fallback};return ye(vr(()=>e.each,e.children,t||void 0))}function Ar(e){const t=e.keyed,s=ye(()=>e.when,void 0,{equals:(r,a)=>t?r===a:!r==!a});return ye(()=>{const r=s();if(r){const a=e.children;return typeof a=="function"&&a.length>0?fe(()=>a(t?r:()=>{if(!fe(s))throw nn("Show");return e.when})):a}return e.fallback},void 0,void 0)}function Tr(e){let t=!1;const s=(i,o)=>(t?i[1]===o[1]:!i[1]==!o[1])&&i[2]===o[2],r=Ys(()=>e.children),a=ye(()=>{let i=r();Array.isArray(i)||(i=[i]);for(let o=0;o<i.length;o++){const l=i[o].when;if(l)return t=!!i[o].keyed,[o,l,i[o]]}return[-1]},void 0,{equals:s});return ye(()=>{const[i,o,l]=a();if(i<0)return e.fallback;const u=l.children;return typeof u=="function"&&u.length>0?fe(()=>u(t?o:()=>{if(fe(a)[0]!==i)throw nn("Match");return l.when})):u},void 0,void 0)}function Cr(e){return e}var Pr=["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"],Ir=new Set(["className","value","readOnly","formNoValidate","isMap","noModule","playsInline",...Pr]),_r=new Set(["innerHTML","textContent","innerText","children"]),Lr=Object.assign(Object.create(null),{className:"class",htmlFor:"for"}),Dr=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 kr(e,t){const s=Dr[e];return typeof s=="object"?s[t]?s.$:void 0:s}var Gr=new Set(["beforeinput","click","dblclick","contextmenu","focusin","focusout","input","keydown","keyup","mousedown","mousemove","mouseout","mouseover","mouseup","pointerdown","pointermove","pointerout","pointerover","pointerup","touchend","touchmove","touchstart"]),Mr=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"]),Ur={xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace"};function Or(e,t,s){let r=s.length,a=t.length,i=r,o=0,l=0,u=t[a-1].nextSibling,d=null;for(;o<a||l<i;){if(t[o]===s[l]){o++,l++;continue}for(;t[a-1]===s[i-1];)a--,i--;if(a===o){const f=i<r?l?s[l-1].nextSibling:s[i-l]:u;for(;l<i;)e.insertBefore(s[l++],f)}else if(i===l)for(;o<a;)(!d||!d.has(t[o]))&&t[o].remove(),o++;else if(t[o]===s[i-1]&&s[l]===t[a-1]){const f=t[--a].nextSibling;e.insertBefore(s[l++],t[o++].nextSibling),e.insertBefore(s[--i],f),t[a]=s[i]}else{if(!d){d=new Map;let m=l;for(;m<i;)d.set(s[m],m++)}const f=d.get(t[o]);if(f!=null)if(l<f&&f<i){let m=o,w=1,E;for(;++m<a&&m<i&&!((E=d.get(t[m]))==null||E!==f+w);)w++;if(w>f-l){const y=t[o];for(;l<f;)e.insertBefore(s[l++],y)}else e.replaceChild(s[l++],t[o++])}else o++;else t[o++].remove()}}}var pt="_$DX_DELEGATE";function rn(e,t,s,r={}){let a;return Ue(i=>{a=i,t===document?e():Wt(t,e(),t.firstChild?null:void 0,s)},r.owner),()=>{a(),t.textContent=""}}function Rr(e,t,s){let r;const a=()=>{const o=document.createElement("template");return o.innerHTML=e,o.content.firstChild},i=()=>(r||(r=a())).cloneNode(!0);return i.cloneNode=i,i}function an(e,t=window.document){const s=t[pt]||(t[pt]=new Set);for(let r=0,a=e.length;r<a;r++){const i=e[r];s.has(i)||(s.add(i),t.addEventListener(i,dn))}}function Br(e=window.document){if(e[pt]){for(let t of e[pt].keys())e.removeEventListener(t,dn);delete e[pt]}}function zt(e,t,s){He(e)||(s==null?e.removeAttribute(t):e.setAttribute(t,s))}function Fr(e,t,s,r){He(e)||(r==null?e.removeAttributeNS(t,s):e.setAttributeNS(t,s,r))}function qr(e,t,s){He(e)||(s?e.setAttribute(t,""):e.removeAttribute(t))}function on(e,t){He(e)||(t==null?e.removeAttribute("class"):e.className=t)}function ln(e,t,s,r){if(r)Array.isArray(s)?(e[`$$${t}`]=s[0],e[`$$${t}Data`]=s[1]):e[`$$${t}`]=s;else if(Array.isArray(s)){const a=s[0];e.addEventListener(t,s[0]=i=>a.call(e,s[1],i))}else e.addEventListener(t,s,typeof s!="function"&&s)}function Hr(e,t,s={}){const r=Object.keys(t||{}),a=Object.keys(s);let i,o;for(i=0,o=a.length;i<o;i++){const l=a[i];!l||l==="undefined"||t[l]||(ks(e,l,!1),delete s[l])}for(i=0,o=r.length;i<o;i++){const l=r[i],u=!!t[l];!l||l==="undefined"||s[l]===u||!u||(ks(e,l,!0),s[l]=u)}return s}function Vr(e,t,s){if(!t)return s?zt(e,"style"):t;const r=e.style;if(typeof t=="string")return r.cssText=t;typeof s=="string"&&(r.cssText=s=void 0),s||(s={}),t||(t={});let a,i;for(i in s)t[i]==null&&r.removeProperty(i),delete s[i];for(i in t)a=t[i],a!==s[i]&&(r.setProperty(i,a),s[i]=a);return s}function cn(e,t={},s,r){const a={};return r||Oe(()=>a.children=vt(e,t.children,a.children)),Oe(()=>typeof t.ref=="function"&&un(t.ref,e)),Oe(()=>$r(e,t,s,!0,a,!0)),a}function un(e,t,s){return fe(()=>e(t,s))}function Wt(e,t,s,r){if(s!==void 0&&!r&&(r=[]),typeof t!="function")return vt(e,t,r,s);Oe(a=>vt(e,t(),a,s),r)}function $r(e,t,s,r,a={},i=!1){t||(t={});for(const o in a)if(!(o in t)){if(o==="children")continue;a[o]=Gs(e,o,null,a[o],s,i,t)}for(const o in t){if(o==="children")continue;const l=t[o];a[o]=Gs(e,o,l,a[o],s,i,t)}}function Kr(e){let t,s;return!He()||!(t=B.registry.get(s=Wr()))?e():(B.completed&&B.completed.add(t),B.registry.delete(s),t)}function He(e){return!!B.context&&!B.done&&(!e||e.isConnected)}function zr(e){return e.toLowerCase().replace(/-([a-z])/g,(t,s)=>s.toUpperCase())}function ks(e,t,s){const r=t.trim().split(/\s+/);for(let a=0,i=r.length;a<i;a++)e.classList.toggle(r[a],s)}function Gs(e,t,s,r,a,i,o){let l,u,d,f,m;if(t==="style")return Vr(e,s,r);if(t==="classList")return Hr(e,s,r);if(s===r)return r;if(t==="ref")i||s(e);else if(t.slice(0,3)==="on:"){const w=t.slice(3);r&&e.removeEventListener(w,r,typeof r!="function"&&r),s&&e.addEventListener(w,s,typeof s!="function"&&s)}else if(t.slice(0,10)==="oncapture:"){const w=t.slice(10);r&&e.removeEventListener(w,r,!0),s&&e.addEventListener(w,s,!0)}else if(t.slice(0,2)==="on"){const w=t.slice(2).toLowerCase(),E=Gr.has(w);if(!E&&r){const y=Array.isArray(r)?r[0]:r;e.removeEventListener(w,y)}(E||s)&&(ln(e,w,s,E),E&&an([w]))}else if(t.slice(0,5)==="attr:")zt(e,t.slice(5),s);else if(t.slice(0,5)==="bool:")qr(e,t.slice(5),s);else if((m=t.slice(0,5)==="prop:")||(d=_r.has(t))||!a&&((f=kr(t,e.tagName))||(u=Ir.has(t)))||(l=e.nodeName.includes("-")||"is"in o)){if(m)t=t.slice(5),u=!0;else if(He(e))return s;t==="class"||t==="className"?on(e,s):l&&!u&&!d?e[zr(t)]=s:e[f||t]=s}else{const w=a&&t.indexOf(":")>-1&&Ur[t.split(":")[0]];w?Fr(e,w,t,s):zt(e,Lr[t]||t,s)}return s}function dn(e){if(B.registry&&B.events&&B.events.find(([u,d])=>d===e))return;let t=e.target;const s=`$$${e.type}`,r=e.target,a=e.currentTarget,i=u=>Object.defineProperty(e,"target",{configurable:!0,value:u}),o=()=>{const u=t[s];if(u&&!t.disabled){const d=t[`${s}Data`];if(d!==void 0?u.call(t,d,e):u.call(t,e),e.cancelBubble)return}return t.host&&typeof t.host!="string"&&!t.host._$host&&t.contains(e.target)&&i(t.host),!0},l=()=>{for(;o()&&(t=t._$host||t.parentNode||t.host););};if(Object.defineProperty(e,"currentTarget",{configurable:!0,get(){return t||document}}),B.registry&&!B.done&&(B.done=_$HY.done=!0),e.composedPath){const u=e.composedPath();i(u[0]);for(let d=0;d<u.length-2&&(t=u[d],!!o());d++){if(t._$host){t=t._$host,l();break}if(t.parentNode===a)break}}else l();i(r)}function vt(e,t,s,r,a){const i=He(e);if(i){!s&&(s=[...e.childNodes]);let u=[];for(let d=0;d<s.length;d++){const f=s[d];f.nodeType===8&&f.data.slice(0,2)==="!$"?f.remove():u.push(f)}s=u}for(;typeof s=="function";)s=s();if(t===s)return s;const o=typeof t,l=r!==void 0;if(e=l&&s[0]&&s[0].parentNode||e,o==="string"||o==="number"){if(i||o==="number"&&(t=t.toString(),t===s))return s;if(l){let u=s[0];u&&u.nodeType===3?u.data!==t&&(u.data=t):u=document.createTextNode(t),s=Ve(e,s,r,u)}else s!==""&&typeof s=="string"?s=e.firstChild.data=t:s=e.textContent=t}else if(t==null||o==="boolean"){if(i)return s;s=Ve(e,s,r)}else{if(o==="function")return Oe(()=>{let u=t();for(;typeof u=="function";)u=u();s=vt(e,u,s,r)}),()=>s;if(Array.isArray(t)){const u=[],d=s&&Array.isArray(s);if(cs(u,t,s,a))return Oe(()=>s=vt(e,u,s,r,!0)),()=>s;if(i){if(!u.length)return s;if(r===void 0)return s=[...e.childNodes];let f=u[0];if(f.parentNode!==e)return s;const m=[f];for(;(f=f.nextSibling)!==r;)m.push(f);return s=m}if(u.length===0){if(s=Ve(e,s,r),l)return s}else d?s.length===0?Ms(e,u,r):Or(e,s,u):(s&&Ve(e),Ms(e,u));s=u}else if(t.nodeType){if(i&&t.parentNode)return s=l?[t]:t;if(Array.isArray(s)){if(l)return s=Ve(e,s,r,t);Ve(e,s,null,t)}else s==null||s===""||!e.firstChild?e.appendChild(t):e.replaceChild(t,e.firstChild);s=t}}return s}function cs(e,t,s,r){let a=!1;for(let i=0,o=t.length;i<o;i++){let l=t[i],u=s&&s[e.length],d;if(!(l==null||l===!0||l===!1))if((d=typeof l)=="object"&&l.nodeType)e.push(l);else if(Array.isArray(l))a=cs(e,l,u)||a;else if(d==="function")if(r){for(;typeof l=="function";)l=l();a=cs(e,Array.isArray(l)?l:[l],Array.isArray(u)?u:[u])||a}else e.push(l),a=!0;else{const f=String(l);u&&u.nodeType===3&&u.data===f?e.push(u):e.push(document.createTextNode(f))}}return a}function Ms(e,t,s=null){for(let r=0,a=t.length;r<a;r++)e.insertBefore(t[r],s)}function Ve(e,t,s,r){if(s===void 0)return e.textContent="";const a=r||document.createTextNode("");if(t.length){let i=!1;for(let o=t.length-1;o>=0;o--){const l=t[o];if(a!==l){const u=l.parentNode===e;!i&&!o?u?e.replaceChild(a,l):e.insertBefore(a,s):u&&l.remove()}else i=!0}}else e.insertBefore(a,s);return[a]}function Wr(){return B.getNextContextId()}var Qr="http://www.w3.org/2000/svg";function hn(e,t=!1){return t?document.createElementNS(Qr,e):document.createElement(e)}function Yr(e){const{useShadow:t}=e,s=document.createTextNode(""),r=()=>e.mount||document.body,a=Ds();let i,o=!!B.context;return gs(()=>{o&&(Ds().user=o=!1),i||(i=lr(a,()=>ye(()=>e.children)));const l=r();if(l instanceof HTMLHeadElement){const[u,d]=he(!1),f=()=>d(!0);Ue(m=>Wt(l,()=>u()?m():i(),null)),ot(f)}else{const u=hn(e.isSVG?"g":"div",e.isSVG),d=t&&u.attachShadow?u.attachShadow({mode:"open"}):u;Object.defineProperty(u,"_$host",{get(){return s.parentNode},configurable:!0}),Wt(d,i),l.appendChild(u),e.ref&&e.ref(u),ot(()=>l.removeChild(u))}},void 0,{render:!o}),s}function Xr(e){const[t,s]=tn(e,["component"]),r=ye(()=>t.component);return ye(()=>{const a=r();switch(typeof a){case"function":return fe(()=>a(s));case"string":const i=Mr.has(a),o=B.context?Kr():hn(a,i);return cn(o,s,i),o}})}var Zr=class{constructor(){this.keyToValue=new Map,this.valueToKey=new Map}set(e,t){this.keyToValue.set(e,t),this.valueToKey.set(t,e)}getByKey(e){return this.keyToValue.get(e)}getByValue(e){return this.valueToKey.get(e)}clear(){this.keyToValue.clear(),this.valueToKey.clear()}},fn=class{constructor(e){this.generateIdentifier=e,this.kv=new Zr}register(e,t){this.kv.getByValue(e)||(t||(t=this.generateIdentifier(e)),this.kv.set(t,e))}clear(){this.kv.clear()}getIdentifier(e){return this.kv.getByValue(e)}getValue(e){return this.kv.getByKey(e)}},Jr=class extends fn{constructor(){super(e=>e.name),this.classToAllowedProps=new Map}register(e,t){typeof t=="object"?(t.allowProps&&this.classToAllowedProps.set(e,t.allowProps),super.register(e,t.identifier)):super.register(e,t)}getAllowedProps(e){return this.classToAllowedProps.get(e)}};function ea(e){if("values"in Object)return Object.values(e);const t=[];for(const s in e)e.hasOwnProperty(s)&&t.push(e[s]);return t}function ta(e,t){const s=ea(e);if("find"in s)return s.find(t);const r=s;for(let a=0;a<r.length;a++){const i=r[a];if(t(i))return i}}function lt(e,t){Object.entries(e).forEach(([s,r])=>t(r,s))}function Bt(e,t){return e.indexOf(t)!==-1}function Us(e,t){for(let s=0;s<e.length;s++){const r=e[s];if(t(r))return r}}var sa=class{constructor(){this.transfomers={}}register(e){this.transfomers[e.name]=e}findApplicable(e){return ta(this.transfomers,t=>t.isApplicable(e))}findByName(e){return this.transfomers[e]}},na=e=>Object.prototype.toString.call(e).slice(8,-1),mn=e=>typeof e>"u",ra=e=>e===null,St=e=>typeof e!="object"||e===null||e===Object.prototype?!1:Object.getPrototypeOf(e)===null?!0:Object.getPrototypeOf(e)===Object.prototype,us=e=>St(e)&&Object.keys(e).length===0,Re=e=>Array.isArray(e),aa=e=>typeof e=="string",ia=e=>typeof e=="number"&&!isNaN(e),oa=e=>typeof e=="boolean",la=e=>e instanceof RegExp,bt=e=>e instanceof Map,wt=e=>e instanceof Set,gn=e=>na(e)==="Symbol",ca=e=>e instanceof Date&&!isNaN(e.valueOf()),ua=e=>e instanceof Error,Os=e=>typeof e=="number"&&isNaN(e),da=e=>oa(e)||ra(e)||mn(e)||ia(e)||aa(e)||gn(e),ha=e=>typeof e=="bigint",fa=e=>e===1/0||e===-1/0,ma=e=>ArrayBuffer.isView(e)&&!(e instanceof DataView),ga=e=>e instanceof URL,xn=e=>e.replace(/\./g,"\\."),ns=e=>e.map(String).map(xn).join("."),yt=e=>{const t=[];let s="";for(let a=0;a<e.length;a++){let i=e.charAt(a);if(i==="\\"&&e.charAt(a+1)==="."){s+=".",a++;continue}if(i==="."){t.push(s),s="";continue}s+=i}const r=s;return t.push(r),t};function Ie(e,t,s,r){return{isApplicable:e,annotation:t,transform:s,untransform:r}}var pn=[Ie(mn,"undefined",()=>null,()=>{}),Ie(ha,"bigint",e=>e.toString(),e=>typeof BigInt<"u"?BigInt(e):e),Ie(ca,"Date",e=>e.toISOString(),e=>new Date(e)),Ie(ua,"Error",(e,t)=>{const s={name:e.name,message:e.message};return t.allowedErrorProps.forEach(r=>{s[r]=e[r]}),s},(e,t)=>{const s=new Error(e.message);return s.name=e.name,s.stack=e.stack,t.allowedErrorProps.forEach(r=>{s[r]=e[r]}),s}),Ie(la,"regexp",e=>""+e,e=>{const t=e.slice(1,e.lastIndexOf("/")),s=e.slice(e.lastIndexOf("/")+1);return new RegExp(t,s)}),Ie(wt,"set",e=>[...e.values()],e=>new Set(e)),Ie(bt,"map",e=>[...e.entries()],e=>new Map(e)),Ie(e=>Os(e)||fa(e),"number",e=>Os(e)?"NaN":e>0?"Infinity":"-Infinity",Number),Ie(e=>e===0&&1/e===-1/0,"number",()=>"-0",Number),Ie(ga,"URL",e=>e.toString(),e=>new URL(e))];function Zt(e,t,s,r){return{isApplicable:e,annotation:t,transform:s,untransform:r}}var yn=Zt((e,t)=>gn(e)?!!t.symbolRegistry.getIdentifier(e):!1,(e,t)=>["symbol",t.symbolRegistry.getIdentifier(e)],e=>e.description,(e,t,s)=>{const r=s.symbolRegistry.getValue(t[1]);if(!r)throw new Error("Trying to deserialize unknown symbol");return r}),xa=[Int8Array,Uint8Array,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array,Uint8ClampedArray].reduce((e,t)=>(e[t.name]=t,e),{}),En=Zt(ma,e=>["typed-array",e.constructor.name],e=>[...e],(e,t)=>{const s=xa[t[1]];if(!s)throw new Error("Trying to deserialize unknown typed array");return new s(e)});function vn(e,t){return e!=null&&e.constructor?!!t.classRegistry.getIdentifier(e.constructor):!1}var Sn=Zt(vn,(e,t)=>["class",t.classRegistry.getIdentifier(e.constructor)],(e,t)=>{const s=t.classRegistry.getAllowedProps(e.constructor);if(!s)return{...e};const r={};return s.forEach(a=>{r[a]=e[a]}),r},(e,t,s)=>{const r=s.classRegistry.getValue(t[1]);if(!r)throw new Error("Trying to deserialize unknown class - check https://github.com/blitz-js/superjson/issues/116#issuecomment-773996564");return Object.assign(Object.create(r.prototype),e)}),bn=Zt((e,t)=>!!t.customTransformerRegistry.findApplicable(e),(e,t)=>["custom",t.customTransformerRegistry.findApplicable(e).name],(e,t)=>t.customTransformerRegistry.findApplicable(e).serialize(e),(e,t,s)=>{const r=s.customTransformerRegistry.findByName(t[1]);if(!r)throw new Error("Trying to deserialize unknown custom value");return r.deserialize(e)}),pa=[Sn,yn,bn,En],Rs=(e,t)=>{const s=Us(pa,a=>a.isApplicable(e,t));if(s)return{value:s.transform(e,t),type:s.annotation(e,t)};const r=Us(pn,a=>a.isApplicable(e,t));if(r)return{value:r.transform(e,t),type:r.annotation}},wn={};pn.forEach(e=>{wn[e.annotation]=e});var ya=(e,t,s)=>{if(Re(t))switch(t[0]){case"symbol":return yn.untransform(e,t,s);case"class":return Sn.untransform(e,t,s);case"custom":return bn.untransform(e,t,s);case"typed-array":return En.untransform(e,t,s);default:throw new Error("Unknown transformation: "+t)}else{const r=wn[t];if(!r)throw new Error("Unknown transformation: "+t);return r.untransform(e,s)}},$e=(e,t)=>{const s=e.keys();for(;t>0;)s.next(),t--;return s.next().value};function jn(e){if(Bt(e,"__proto__"))throw new Error("__proto__ is not allowed as a property");if(Bt(e,"prototype"))throw new Error("prototype is not allowed as a property");if(Bt(e,"constructor"))throw new Error("constructor is not allowed as a property")}var Ea=(e,t)=>{jn(t);for(let s=0;s<t.length;s++){const r=t[s];if(wt(e))e=$e(e,+r);else if(bt(e)){const a=+r,i=+t[++s]==0?"key":"value",o=$e(e,a);switch(i){case"key":e=o;break;case"value":e=e.get(o);break}}else e=e[r]}return e},ds=(e,t,s)=>{if(jn(t),t.length===0)return s(e);let r=e;for(let i=0;i<t.length-1;i++){const o=t[i];if(Re(r)){const l=+o;r=r[l]}else if(St(r))r=r[o];else if(wt(r)){const l=+o;r=$e(r,l)}else if(bt(r)){if(i===t.length-2)break;const u=+o,d=+t[++i]==0?"key":"value",f=$e(r,u);switch(d){case"key":r=f;break;case"value":r=r.get(f);break}}}const a=t[t.length-1];if(Re(r)?r[+a]=s(r[+a]):St(r)&&(r[a]=s(r[a])),wt(r)){const i=$e(r,+a),o=s(i);i!==o&&(r.delete(i),r.add(o))}if(bt(r)){const i=+t[t.length-2],o=$e(r,i);switch(+a==0?"key":"value"){case"key":{const u=s(o);r.set(u,r.get(o)),u!==o&&r.delete(o);break}case"value":{r.set(o,s(r.get(o)));break}}}return e};function hs(e,t,s=[]){if(!e)return;if(!Re(e)){lt(e,(i,o)=>hs(i,t,[...s,...yt(o)]));return}const[r,a]=e;a&&lt(a,(i,o)=>{hs(i,t,[...s,...yt(o)])}),t(r,s)}function va(e,t,s){return hs(t,(r,a)=>{e=ds(e,a,i=>ya(i,r,s))}),e}function Sa(e,t){function s(r,a){const i=Ea(e,yt(a));r.map(yt).forEach(o=>{e=ds(e,o,()=>i)})}if(Re(t)){const[r,a]=t;r.forEach(i=>{e=ds(e,yt(i),()=>e)}),a&&lt(a,s)}else lt(t,s);return e}var ba=(e,t)=>St(e)||Re(e)||bt(e)||wt(e)||vn(e,t);function wa(e,t,s){const r=s.get(e);r?r.push(t):s.set(e,[t])}function ja(e,t){const s={};let r;return e.forEach(a=>{if(a.length<=1)return;t||(a=a.map(l=>l.map(String)).sort((l,u)=>l.length-u.length));const[i,...o]=a;i.length===0?r=o.map(ns):s[ns(i)]=o.map(ns)}),r?us(s)?[r]:[r,s]:us(s)?void 0:s}var Nn=(e,t,s,r,a=[],i=[],o=new Map)=>{const l=da(e);if(!l){wa(e,a,t);const E=o.get(e);if(E)return r?{transformedValue:null}:E}if(!ba(e,s)){const E=Rs(e,s),y=E?{transformedValue:E.value,annotations:[E.type]}:{transformedValue:e};return l||o.set(e,y),y}if(Bt(i,e))return{transformedValue:null};const u=Rs(e,s),d=(u==null?void 0:u.value)??e,f=Re(d)?[]:{},m={};lt(d,(E,y)=>{if(y==="__proto__"||y==="constructor"||y==="prototype")throw new Error(`Detected property ${y}. This is a prototype pollution risk, please remove it from your object.`);const j=Nn(E,t,s,r,[...a,y],[...i,e],o);f[y]=j.transformedValue,Re(j.annotations)?m[y]=j.annotations:St(j.annotations)&&lt(j.annotations,(b,D)=>{m[xn(y)+"."+D]=b})});const w=us(m)?{transformedValue:f,annotations:u?[u.type]:void 0}:{transformedValue:f,annotations:u?[u.type,m]:m};return l||o.set(e,w),w};function An(e){return Object.prototype.toString.call(e).slice(8,-1)}function Bs(e){return An(e)==="Array"}function Na(e){if(An(e)!=="Object")return!1;const t=Object.getPrototypeOf(e);return!!t&&t.constructor===Object&&t===Object.prototype}function Aa(e,t,s,r,a){const i={}.propertyIsEnumerable.call(r,t)?"enumerable":"nonenumerable";i==="enumerable"&&(e[t]=s),a&&i==="nonenumerable"&&Object.defineProperty(e,t,{value:s,enumerable:!1,writable:!0,configurable:!0})}function fs(e,t={}){if(Bs(e))return e.map(a=>fs(a,t));if(!Na(e))return e;const s=Object.getOwnPropertyNames(e),r=Object.getOwnPropertySymbols(e);return[...s,...r].reduce((a,i)=>{if(Bs(t.props)&&!t.props.includes(i))return a;const o=e[i],l=fs(o,t);return Aa(a,i,l,e,t.nonenumerable),a},{})}var ne=class{constructor({dedupe:e=!1}={}){this.classRegistry=new Jr,this.symbolRegistry=new fn(t=>t.description??""),this.customTransformerRegistry=new sa,this.allowedErrorProps=[],this.dedupe=e}serialize(e){const t=new Map,s=Nn(e,t,this,this.dedupe),r={json:s.transformedValue};s.annotations&&(r.meta={...r.meta,values:s.annotations});const a=ja(t,this.dedupe);return a&&(r.meta={...r.meta,referentialEqualities:a}),r}deserialize(e){const{json:t,meta:s}=e;let r=fs(t);return s!=null&&s.values&&(r=va(r,s.values,this)),s!=null&&s.referentialEqualities&&(r=Sa(r,s.referentialEqualities)),r}stringify(e){return JSON.stringify(this.serialize(e))}parse(e){return this.deserialize(JSON.parse(e))}registerClass(e,t){this.classRegistry.register(e,t)}registerSymbol(e,t){this.symbolRegistry.register(e,t)}registerCustom(e,t){this.customTransformerRegistry.register({name:t,...e})}allowErrorProps(...e){this.allowedErrorProps.push(...e)}};ne.defaultInstance=new ne;ne.serialize=ne.defaultInstance.serialize.bind(ne.defaultInstance);ne.deserialize=ne.defaultInstance.deserialize.bind(ne.defaultInstance);ne.stringify=ne.defaultInstance.stringify.bind(ne.defaultInstance);ne.parse=ne.defaultInstance.parse.bind(ne.defaultInstance);ne.registerClass=ne.defaultInstance.registerClass.bind(ne.defaultInstance);ne.registerSymbol=ne.defaultInstance.registerSymbol.bind(ne.defaultInstance);ne.registerCustom=ne.defaultInstance.registerCustom.bind(ne.defaultInstance);ne.allowErrorProps=ne.defaultInstance.allowErrorProps.bind(ne.defaultInstance);var Tn=ne.serialize,Ta=ne.stringify;function Ca(e){return e.state.fetchStatus==="fetching"?"fetching":e.getObserversCount()?e.state.fetchStatus==="paused"?"paused":e.isStale()?"stale":"fresh":"inactive"}function Pa(e,t){return`${e}${t.charAt(0).toUpperCase()+t.slice(1)}`}function Ia({queryState:e,observerCount:t,isStale:s}){return e.fetchStatus==="fetching"?"blue":t?e.fetchStatus==="paused"?"purple":s?"yellow":"green":"gray"}function _a({status:e,isPaused:t}){return t?"purple":e==="error"?"red":e==="pending"?"yellow":e==="success"?"green":"gray"}function La(e){return e==="fresh"?"green":e==="stale"?"yellow":e==="paused"?"purple":e==="inactive"?"gray":"blue"}var Da=(e,t=!1)=>{const{json:s}=Tn(e);return JSON.stringify(s,null,t?2:void 0)},Ot=e=>e.state.fetchStatus!=="idle"?0:e.getObserversCount()?e.isStale()?2:1:3,ka=(e,t)=>e.queryHash.localeCompare(t.queryHash),Cn=(e,t)=>e.state.dataUpdatedAt<t.state.dataUpdatedAt?1:-1,Ga=(e,t)=>Ot(e)===Ot(t)?Cn(e,t):Ot(e)>Ot(t)?1:-1,Ma={status:Ga,"query hash":ka,"last updated":Cn},Rt=e=>e.state.isPaused?0:e.state.status==="error"?2:e.state.status==="pending"?1:3,Pn=(e,t)=>e.state.submittedAt<t.state.submittedAt?1:-1,Ua=(e,t)=>Rt(e)===Rt(t)?Pn(e,t):Rt(e)>Rt(t)?1:-1,Oa={status:Ua,"last updated":Pn},Ra=e=>e*parseFloat(getComputedStyle(document.documentElement).fontSize),Ba=()=>{const[e,t]=he("dark");return Qs(()=>{const s=window.matchMedia("(prefers-color-scheme: dark)");t(s.matches?"dark":"light");const r=a=>{t(a.matches?"dark":"light")};s.addEventListener("change",r),ot(()=>s.removeEventListener("change",r))}),e},gt=(e,t,s)=>{if(t.length===0)return s;if(e instanceof Map){const r=new Map(e);if(t.length===1)return r.set(t[0],s),r;const[a,...i]=t;return r.set(a,gt(r.get(a),i,s)),r}if(e instanceof Set){const r=gt(Array.from(e),t,s);return new Set(r)}if(Array.isArray(e)){const r=[...e];if(t.length===1)return r[t[0]]=s,r;const[a,...i]=t;return r[a]=gt(r[a],i,s),r}if(e instanceof Object){const r={...e};if(t.length===1)return r[t[0]]=s,r;const[a,...i]=t;return r[a]=gt(r[a],i,s),r}return e},xt=(e,t)=>{if(e instanceof Map){const s=new Map(e);if(t.length===1)return s.delete(t[0]),s;const[r,...a]=t;return s.set(r,xt(s.get(r),a)),s}if(e instanceof Set){const s=xt(Array.from(e),t);return new Set(s)}if(Array.isArray(e)){const s=[...e];if(t.length===1)return s.filter((i,o)=>o.toString()!==t[0]);const[r,...a]=t;return s[r]=xt(s[r],a),s}if(e instanceof Object){const s={...e};if(t.length===1)return delete s[t[0]],s;const[r,...a]=t;return s[r]=xt(s[r],a),s}return e},In=(e,t)=>{if(!e||document.querySelector("#_goober")||(t==null?void 0:t.querySelector("#_goober")))return;const r=document.createElement("style"),a=document.createTextNode("");r.appendChild(a),r.id="_goober",r.setAttribute("nonce",e),t?t.appendChild(r):document.head.appendChild(r)},Ke,jt,Nt,At,Fe,Tt,ze,We,Qe,Ye,Xe,Ze,Ct,qs,Fa=(qs=class{constructor(e){te(this,Ke);te(this,jt);te(this,Nt);te(this,At);te(this,Fe,!1);te(this,Tt);te(this,ze);te(this,We);te(this,Qe);te(this,Ye);te(this,Xe);te(this,Ze);te(this,Ct);const{client:t,queryFlavor:s,version:r,onlineManager:a,buttonPosition:i,position:o,initialIsOpen:l,errorTypes:u,styleNonce:d,shadowDOMTarget:f}=e;J(this,Ke,he(t)),J(this,Nt,s),J(this,At,r),J(this,jt,a),J(this,Tt,d),J(this,ze,f),J(this,We,he(i)),J(this,Qe,he(o)),J(this,Ye,he(l)),J(this,Xe,he(u))}setButtonPosition(e){R(this,We)[1](e)}setPosition(e){R(this,Qe)[1](e)}setInitialIsOpen(e){R(this,Ye)[1](e)}setErrorTypes(e){R(this,Xe)[1](e)}setClient(e){R(this,Ke)[1](e)}mount(e){if(R(this,Fe))throw new Error("Devtools is already mounted");const t=rn(()=>{const s=this,[r]=R(this,We),[a]=R(this,Qe),[i]=R(this,Ye),[o]=R(this,Xe),[l]=R(this,Ke);let u;return R(this,Ze)?u=R(this,Ze):(u=sn(()=>Promise.resolve().then(()=>require("./HO4MOOFI-BEngN_-2.cjs"))),J(this,Ze,u)),In(R(this,Tt),R(this,ze)),ps(u,ys({get queryFlavor(){return R(s,Nt)},get version(){return R(s,At)},get onlineManager(){return R(s,jt)},get shadowDOMTarget(){return R(s,ze)}},{get client(){return l()},get buttonPosition(){return r()},get position(){return a()},get initialIsOpen(){return i()},get errorTypes(){return o()}}))},e);J(this,Fe,!0),J(this,Ct,t)}unmount(){var e;if(!R(this,Fe))throw new Error("Devtools is not mounted");(e=R(this,Ct))==null||e.call(this),J(this,Fe,!1)}},Ke=new WeakMap,jt=new WeakMap,Nt=new WeakMap,At=new WeakMap,Fe=new WeakMap,Tt=new WeakMap,ze=new WeakMap,We=new WeakMap,Qe=new WeakMap,Ye=new WeakMap,Xe=new WeakMap,Ze=new WeakMap,Ct=new WeakMap,qs),Je,Pt,It,_t,qe,Lt,et,tt,st,nt,rt,at,it,Dt,Hs,qa=(Hs=class{constructor(e){te(this,Je);te(this,Pt);te(this,It);te(this,_t);te(this,qe,!1);te(this,Lt);te(this,et);te(this,tt);te(this,st);te(this,nt);te(this,rt);te(this,at);te(this,it);te(this,Dt);const{client:t,queryFlavor:s,version:r,onlineManager:a,buttonPosition:i,position:o,initialIsOpen:l,errorTypes:u,styleNonce:d,shadowDOMTarget:f,onClose:m}=e;J(this,Je,he(t)),J(this,It,s),J(this,_t,r),J(this,Pt,a),J(this,Lt,d),J(this,et,f),J(this,tt,he(i)),J(this,st,he(o)),J(this,nt,he(l)),J(this,rt,he(u)),J(this,at,he(m))}setButtonPosition(e){R(this,tt)[1](e)}setPosition(e){R(this,st)[1](e)}setInitialIsOpen(e){R(this,nt)[1](e)}setErrorTypes(e){R(this,rt)[1](e)}setClient(e){R(this,Je)[1](e)}setOnClose(e){R(this,at)[1](()=>e)}mount(e){if(R(this,qe))throw new Error("Devtools is already mounted");const t=rn(()=>{const s=this,[r]=R(this,tt),[a]=R(this,st),[i]=R(this,nt),[o]=R(this,rt),[l]=R(this,Je),[u]=R(this,at);let d;return R(this,it)?d=R(this,it):(d=sn(()=>Promise.resolve().then(()=>require("./HUY7CZI3-DLU0PcpD.cjs"))),J(this,it,d)),In(R(this,Lt),R(this,et)),ps(d,ys({get queryFlavor(){return R(s,It)},get version(){return R(s,_t)},get onlineManager(){return R(s,Pt)},get shadowDOMTarget(){return R(s,et)}},{get client(){return l()},get buttonPosition(){return r()},get position(){return a()},get initialIsOpen(){return i()},get errorTypes(){return o()},get onClose(){return u()}}))},e);J(this,qe,!0),J(this,Dt,t)}unmount(){var e;if(!R(this,qe))throw new Error("Devtools is not mounted");(e=R(this,Dt))==null||e.call(this),J(this,qe,!1)}},Je=new WeakMap,Pt=new WeakMap,It=new WeakMap,_t=new WeakMap,qe=new WeakMap,Lt=new WeakMap,et=new WeakMap,tt=new WeakMap,st=new WeakMap,nt=new WeakMap,rt=new WeakMap,at=new WeakMap,it=new WeakMap,Dt=new WeakMap,Hs);function Ha(e){const t=U.useQueryClient(e.client),s=le.useRef(null),{buttonPosition:r,position:a,initialIsOpen:i,errorTypes:o,styleNonce:l,shadowDOMTarget:u}=e,[d]=le.useState(new Fa({client:t,queryFlavor:"React Query",version:"5",onlineManager:U.onlineManager,buttonPosition:r,position:a,initialIsOpen:i,errorTypes:o,styleNonce:l,shadowDOMTarget:u}));return le.useEffect(()=>{d.setClient(t)},[t,d]),le.useEffect(()=>{r&&d.setButtonPosition(r)},[r,d]),le.useEffect(()=>{a&&d.setPosition(a)},[a,d]),le.useEffect(()=>{d.setInitialIsOpen(i||!1)},[i,d]),le.useEffect(()=>{d.setErrorTypes(o||[])},[o,d]),le.useEffect(()=>(s.current&&d.mount(s.current),()=>{d.unmount()}),[d]),n.jsx("div",{className:"tsqd-parent-container",ref:s})}function Va(e){const t=U.useQueryClient(e.client),s=le.useRef(null),{errorTypes:r,styleNonce:a,shadowDOMTarget:i}=e,[o]=le.useState(new qa({client:t,queryFlavor:"React Query",version:"5",onlineManager:U.onlineManager,buttonPosition:"bottom-left",position:"bottom",initialIsOpen:!0,errorTypes:r,styleNonce:a,shadowDOMTarget:i,onClose:e.onClose}));return le.useEffect(()=>{o.setClient(t)},[t,o]),le.useEffect(()=>{o.setOnClose(e.onClose??(()=>{}))},[e.onClose,o]),le.useEffect(()=>{o.setErrorTypes(r||[])},[r,o]),le.useEffect(()=>(s.current&&o.mount(s.current),()=>{o.unmount()}),[o]),n.jsx("div",{style:{height:"500px",...e.style},className:"tsqd-parent-container",ref:s})}var $a=process.env.NODE_ENV!=="development"?function(){return null}:Ha;process.env.NODE_ENV;const L={ASK_AI:"ASK_AI",GET_PAGE:"GET_PAGE",CREATE_PAGE:"CREATE_PAGE",UPDATE_PAGE:"UPDATE_PAGE",DELETE_PAGE:"DELETE_PAGE",CHANGE_SLUG:"CHANGE_SLUG",TAKE_OFFLINE:"TAKE_OFFLINE",PUBLISH_PAGE:"PUBLISH_PAGE",PUBLISH_CHANGES:"PUBLISH_CHANGES",ADD_NEW_LANGUAGE:"ADD_NEW_LANGUAGE",EDIT_LANGUAGE:"EDIT_LANGUAGE",DELETE_LANGUAGE:"DELETE_LANGUAGE",GET_CHANGES:"GET_CHANGES",GET_SERVER_BLOCK:"GET_SERVER_BLOCK",GET_LANGUAGE_PAGES:"GET_LANGUAGE_PAGES",GET_PROJECT_PAGES:"GET_PROJECT_PAGES",GET_WEBSITE_PAGES:"GET_WEBSITE_PAGES",UPDATE_WEBSITE_SETTINGS:"UPDATE_WEBSITE_SETTINGS",GET_COLLECTIONS:"GET_COLLECTIONS",GET_PAGE_TYPES:"GET_PAGE_TYPES",SEARCH_PAGES:"SEARCH_PAGES",GET_WEBSITE_SETTINGS:"GET_WEBSITE_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"},Es=()=>{const e=U.useQueryClient(),{data:t}=U.useQuery({queryKey:[L.AI_CONTEXT],initialData:"",queryFn:()=>""});return{setAiContext:S.useCallback(r=>{e.setQueryData([L.AI_CONTEXT],r)},[]),aiContext:t}},Ka=async(e,t,s={})=>await fetch(e,{method:"POST",headers:{"Content-Type":"application/json",...s},body:JSON.stringify(t)}),za=()=>{const e=Ce("user"),t=Ce("onSessionExpired"),s=S.useMemo(()=>e==null?void 0:e.authToken,[e==null?void 0:e.authToken]);return S.useCallback(async(r,a,i={})=>{if(s)try{const o=await fetch(r,{method:"POST",body:a,headers:{...i,Authorization:`Bearer ${s}`,"x-chai-upload":"true"}});if(o.status===401)throw console.log("session expired",a,o),t(),new Error("Session expired");if(o.status===400)throw console.log("Something went wrong",a,o),new Error((await o.json()).error);return await o.json()}catch(o){throw console.log("Something went wrong",a,o),o}},[s,t])},Z=()=>{const e=Ce("user"),t=Ce("onSessionExpired"),s=S.useMemo(()=>e==null?void 0:e.authToken,[e==null?void 0:e.authToken]);return S.useCallback(async(r,a,i={})=>{if(s)try{const o=g.get(a,"action","").toLowerCase(),l=await Ka(r+(o?`?action=${o}`:""),a,{...i,Authorization:`Bearer ${s}`});if(l.status===401)throw console.log("session expired",a,l),t(),new Error("Session expired");if(l.status===400)throw console.log("Something went wrong",a,l),new Error((await l.json()).error);return await l.json()}catch(o){throw console.log("Something went wrong",a,o),o}},[s,t])},_n=()=>{const e=ee(),t=U.useQueryClient(),s=Z();return U.useMutation({mutationFn:async r=>s(e,{action:L.RELEASE_LOCK,data:r}),onSuccess:(r,a)=>{t.invalidateQueries({queryKey:[L.GET_PAGE,a.id??""]})}})},Ln=()=>{const e=ee(),t=U.useQueryClient(),s=Z();return U.useMutation({mutationFn:async r=>s(e,{action:L.UPDATE_WEBSITE_SETTINGS,data:r}),onSuccess:(r,a)=>{var i;t.invalidateQueries({queryKey:[L.GET_WEBSITE_SETTINGS]}),(i=a==null?void 0:a.settings)!=null&&i.theme||oe.toast.success("Website settings updated successfully.")},onError:r=>{oe.toast.error("Failed to update website settings",{description:r.message})}})},Wa=()=>{const e=ee(),t=U.useQueryClient(),s=Z();return U.useMutation({mutationFn:async r=>s(e,{action:L.UPDATE_WEBSITE_DATA,data:r}),onSuccess:()=>{t.invalidateQueries({queryKey:[L.GET_WEBSITE_DATA]}),oe.toast.success("Website data updated successfully.")},onError:r=>{oe.toast.error("Failed to update website data",{description:r.message})}})},Qa=e=>{const t=ee(),s=Z(),{resetLibrary:r}=ae.useLibraryBlocks(e);return U.useMutation({mutationFn:async a=>s(t,{action:L.UPSERT_LIBRARY_ITEM,data:a}),onSuccess:()=>{console.log("resetLibrary",e),r(),oe.toast.success("Library updated successfully.")},onError:a=>{oe.toast.error("Failed to update library item",{description:a.message})}})};function je(){const[e,t]=S.useState(new URLSearchParams(window.location.search));return S.useEffect(()=>{const s=()=>{t(new URLSearchParams(window.location.search))};return window.addEventListener("popstate",s),()=>{window.removeEventListener("popstate",s)}},[]),[e,t]}const Ya=ct.atom({}),Dn=()=>ct.useAtom(Ya),Xa=()=>{const[e]=je(),t=e.get("page"),s=S.useRef(""),{mutate:r}=_n();S.useEffect(()=>{!g.isEmpty(s.current)&&t!==s.current&&r({id:s.current}),s.current=t},[t,r,s])},Ce=(e,t)=>{const[s]=Dn();return g.get(s,e,t)},ee=()=>Ce("apiUrl","/chai/api"),Za=()=>{const e=ee(),{aiContext:t}=Es(),s=Z();return S.useCallback(async(r,a,i,o)=>s(e,{action:L.ASK_AI,data:{type:r,prompt:a,blocks:i,context:t,lang:o}}),[e,t,s])},Gt=()=>{const e=Z(),t=ee();return U.useQuery({queryKey:[L.GET_WEBSITE_PAGES],staleTime:1e3*60*5,queryFn:async()=>e(t,{action:L.GET_WEBSITE_PAGES})||[]})},Ja=ct.atom({lastSaved:void 0}),vs=()=>ct.useAtom(Ja),Se=()=>{const[e]=je(),t=e.get("page"),{data:s,isFetching:r}=Gt();return{data:S.useMemo(()=>g.find(s,{id:t})||{},[s,t]),isFetching:r}},ei=(e,t)=>t.map(s=>{if(g.has(e,s._type)){const r=Vs.getDefaultBlockProps(s._type);return{...r,...g.pick(s,[...g.keys(r),"_type","_id","_name","_parent","_bindings"]),...g.pickBy(s,(a,i)=>g.endsWith(i,"_attrs")),...s}}return s}),ti=e=>{const t=Vs.useRegisteredChaiBlocks();return S.useMemo(()=>{if(!e||g.isEmpty(e))return{blocks:[]};const s=g.filter(e,r=>!g.includes(r==null?void 0:r._type,"@chai/"));return{blocks:ei(t,s)}},[e,t])},dt=e=>{const t=ee(),s=Z();return U.useQuery({queryKey:["chaiUserInfo",e],queryFn:async()=>await s(t,{action:L.GET_CHAI_USER,data:{userId:e}}),enabled:!!e&&e!=="EXPIRED"})},si=ct.atom(void 0),Mt=()=>{const[e]=je(),t=e.get("page"),s=Ce("user"),[r,a]=ct.useAtom(si);return S.useMemo(()=>({isLocked:t&&(s==null?void 0:s.id)!==r,currentEditor:r,setCurrentEditor:i=>a(i)}),[r,t,a,s==null?void 0:s.id])},kn=()=>{const[e]=je(),t=e.get("page"),s=ee(),{setAiContext:r}=Es(),{setCurrentEditor:a}=Mt(),[,i]=vs(),o=Z();return U.useQuery({queryKey:[L.GET_PAGE,t],staleTime:1/0,gcTime:1/0,queryFn:async()=>{a("");const l=await o(s,{action:L.GET_PAGE,data:{id:t,draft:!0}});a(l.currentEditor);const u=l.blocks??[],d=g.find(u,{_type:"@chai/ai-context"});return r(g.get(d,"_value","")||""),i(f=>({...f,lastSaved:l.lastSaved})),u},enabled:!!t})},Gn=({pageType:e,lang:t})=>{const s=ee(),r=Z();return U.useQuery({queryKey:[L.GET_BUILDER_PAGE_DATA,e,t],initialData:{},queryFn:async()=>r(s,{action:L.GET_BUILDER_PAGE_DATA,data:{pageType:e,lang:t}}),enabled:!!e&&!!t})},Ee=()=>{const e=ee(),t=Z();return U.useQuery({queryKey:[L.GET_PAGE_TYPES],initialData:[],queryFn:async()=>t(e,{action:L.GET_PAGE_TYPES})})},ni=e=>{const{data:t}=Ee();return S.useMemo(()=>t==null?void 0:t.find(s=>s.key===e),[t,e])},ri=()=>{const e=ee(),t=Z();return U.useMutation({mutationFn:async({pageType:s,query:r})=>{try{return t(e,{action:L.SEARCH_PAGES,data:{pageType:s,query:Array.isArray(r)&&r.length>0?r[0]:r}})||[]}catch(a){return console.error(a),[]}}})},ai=()=>{const e=ee(),t=Z();return U.useQuery({queryKey:["uiLibraries"],initialData:[],queryFn:async()=>(await t(e,{action:"GET_LIBRARIES"})).map(r=>({...r}))})},ht=()=>{const e=ee(),t=Z();return U.useQuery({queryKey:[L.GET_WEBSITE_SETTINGS],initialData:{theme:{},fallbackLang:"en",languages:[]},queryFn:async()=>t(e,{action:L.GET_WEBSITE_SETTINGS,data:{draft:!0}})})},ii=()=>{const e=ee(),t=Z(),{setCurrentEditor:s}=Mt(),[,r]=vs();return{getUILibraryBlock:async(l,u)=>{const d=await t(e,{action:"GET_LIBRARY_ITEM",data:{id:u.id}}),f=g.get(d,"html",""),m=g.get(d,"blocks",[]);return g.isArray(m)?m:ae.getBlocksFromHTML(f)},getUILibraryBlocks:async l=>{try{return(await t(e,{action:"GET_LIBRARY_ITEMS",data:{id:l.id}})).map(d=>({...d}))}catch(u){return console.error(u),[]}},onSave:async({page:l,blocks:u})=>{try{const d=await t(e,{action:"UPDATE_PAGE",data:{id:l,blocks:u}});return d.code==="PAGE_LOCKED"?(s(d.editor===null?"EXPIRED":d.editor),!0):(r(f=>({...f,lastSaved:new Date().toISOString()})),d)}catch(d){return console.error(d),new Error("Failed to save blocks")}}}},oi=()=>{const{data:e}=Gt(),t=ee(),s=Z();return{getPartialBlocks:S.useCallback(async()=>{const r={};for(const a of e??[])g.isEmpty(a==null?void 0:a.slug)&&(r[a.id]={type:a.pageType,name:g.startCase(a.name??a.slug),description:""});return r},[e]),getPartialBlockBlocks:S.useCallback(async r=>{if(!r)return[];const a=await s(t,{action:"GET_PAGE",data:{id:r,draft:!0,editor:!1}});return g.filter(a.blocks,i=>g.has(i,"_id"))},[s,t])}},Te={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"},ft=()=>{const e=ee(),[t]=je(),s=t.get("page"),r=Z();return U.useQuery({queryKey:[L.GET_LANGUAGE_PAGES,s],initialData:[],queryFn:async()=>{if(!s)return null;const a=await r(e,{action:L.GET_LANGUAGE_PAGES,data:{id:s}});return g.reverse(g.sortBy(a,"primaryPage"))},enabled:!!s})},Mn=e=>{const{fallbackLang:t}=ae.useLanguages(),{data:s}=ht(),{data:r,isFetching:a}=ft(),i=S.useMemo(()=>{const o={[t]:!0};return g.each(g.get(s,"languages"),l=>{const u=g.find(r,{lang:l});o[l]=!!u}),o},[t,r,s]);return a||g.isEmpty(e)||e&&i[e]};function li({avatar:e,name:t,email:s,onTakeOver:r,currentEditor:a}){const[i,o]=S.useState(!1),l=()=>{o(!1),r()};return n.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:n.jsxs(c.Card,{className:"w-full max-w-md mx-auto",children:[n.jsx(c.CardHeader,{className:"space-y-1",children:n.jsxs(c.CardTitle,{className:"flex items-center gap-2 text-2xl",children:[n.jsx(I.LockIcon,{className:"w-6 h-6 text-yellow-500"}),a==="EXPIRED"?"Editing access timed out":"Page locked for editing"]})}),n.jsx(c.CardContent,{className:"grid gap-4",children:a==="EXPIRED"?n.jsx("div",{children:n.jsx("p",{children:"Your editing access has been paused due to inactivity. Please refresh the page to continue"})}):n.jsxs("div",{children:[n.jsxs("div",{className:"flex items-center space-x-4",children:[e?n.jsx("img",{src:e,alt:t,className:"w-12 h-12 border border-gray-300 rounded-full"}):n.jsx(I.UserIcon,{className:"w-12 h-12 p-2 border border-gray-300 rounded-full"}),n.jsxs("div",{className:"space-y-1",children:[n.jsx("h3",{className:"font-semibold",children:t}),s&&n.jsx("p",{className:"text-sm text-muted-foreground",children:s})]})]}),n.jsx("div",{className:"text-sm mt-4",children:n.jsx("p",{children:"This user is currently editing the page. You cannot make changes."})})]})}),n.jsx(c.CardFooter,{children:a==="EXPIRED"?n.jsx("div",{children:n.jsx(c.Button,{className:"w-full",onClick:()=>window.location.reload(),variant:"destructive",children:"Refresh"})}):n.jsxs(c.AlertDialog,{open:i,onOpenChange:o,children:[n.jsx(c.AlertDialogTrigger,{asChild:!0,children:n.jsxs("span",{className:"flex flex-col items-center",children:[n.jsx(c.Button,{className:"w-full",variant:"destructive",children:"Take Over"}),n.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."})]})}),n.jsxs(c.AlertDialogContent,{className:"z-[99]",children:[n.jsxs(c.AlertDialogHeader,{children:[n.jsx(c.AlertDialogTitle,{children:"Are you sure you want to take over?"}),n.jsxs(c.AlertDialogDescription,{children:[n.jsxs("span",{className:"flex items-center space-x-2 text-yellow-500",children:[n.jsx(I.AlertTriangleIcon,{className:"w-5 h-5"}),n.jsx("span",{children:"This action might cause the other user to lose unsaved changes."})]}),n.jsx("br",{}),n.jsxs("span",{className:"mt-2",children:["By taking over, you will become the active editor of this page, and ",t," will lose their editing access."]})]})]}),n.jsxs(c.AlertDialogFooter,{children:[n.jsx(c.AlertDialogCancel,{children:"Cancel"}),n.jsx(c.AlertDialogAction,{onClick:l,children:"Yes, Take Over"})]})]})]})})]})})}const ci=()=>{const{isLocked:e,currentEditor:t}=Mt(),{data:s}=dt(t),[r]=je(),a=r.get("page"),{mutate:i}=_n(),{isFetching:o}=kn(),l=S.useCallback(()=>{i({id:a})},[a,i]);return!e||o?n.jsx("div",{className:""}):n.jsx(li,{...s,name:(s==null?void 0:s.name)||"Unknown User",email:(s==null?void 0:s.email)||"",currentEditor:t??null,onTakeOver:l})},ui=()=>{const[e,t]=je(),s=e.get("lang"),r=Mn(s),{setSelectedLang:a}=ae.useLanguages(),i=()=>{const l=new URLSearchParams(window.location.search);l.delete("lang");const u=l.toString(),d=`${window.location.pathname}${u?`?${u}`:""}`;window.history.pushState({},"",d),t(l),a(""),window.dispatchEvent(new PopStateEvent("popstate"))};if(r)return null;const o=g.get(Te,s);return n.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:n.jsxs(c.Card,{className:"w-full max-w-md mx-auto",children:[n.jsx(c.CardHeader,{className:"space-y-1",children:n.jsxs(c.CardTitle,{className:"flex items-center gap-2 text-2xl",children:[n.jsx(I.LockIcon,{className:"w-6 h-6 text-yellow-500"}),'Page missing for "',o,'" language.']})}),n.jsx(c.CardContent,{className:"grid gap-4",children:n.jsxs("div",{children:['Page is not available in the "',o,'" language. Either create the page in the "',o,'" language or switch to the base language.']})}),n.jsx(c.CardFooter,{children:n.jsx(c.Button,{onClick:i,className:"w-full",variant:"destructive",children:"Switch to default language"})})]})})},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",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",SAVE_AS_TEMPLATE:"Save 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."},di={SLUG_ALREADY_USED:"This slug is already in use. Please choose a different one."},Un=()=>{const e=ee(),t=U.useQueryClient(),s=Z(),{data:r}=Ee();return U.useMutation({mutationFn:async a=>s(e,{action:L.CREATE_PAGE,data:a}),onSuccess:(a,i)=>{i&&(i!=null&&i.primaryPage)?t.invalidateQueries({queryKey:[L.GET_LANGUAGE_PAGES,i==null?void 0:i.primaryPage]}):t.invalidateQueries({queryKey:[L.GET_WEBSITE_PAGES]})},onError:(a,i)=>{const o=g.find(r,{key:i.pageType});oe.toast.error(`Failed to add new ${o!=null&&o.hasSlug?"page":o.name}.`,{description:g.get(di,a.message,a.message)})}})},Ss=()=>{const e=ee(),t=U.useQueryClient(),s=Z(),{data:r}=Ee();return U.useMutation({mutationFn:async a=>await s(e,{action:L.UPDATE_PAGE,data:a}),onSuccess:(a,i)=>{i&&(i!=null&&i.primaryPage||i!=null&&i.seo)?t.invalidateQueries({queryKey:[L.GET_LANGUAGE_PAGES,i==null?void 0:i.primaryPage]}):t.invalidateQueries({queryKey:[L.GET_WEBSITE_PAGES]})},onError:(a,i)=>{const o=g.find(r,{key:i.pageType});oe.toast.error(`Failed to update ${o!=null&&o.hasSlug?"page":o.name}.`,{description:a.message})}})},hi=()=>{const e=ee(),t=U.useQueryClient(),s=Z(),{data:r}=Ee();return U.useMutation({mutationFn:async a=>s(e,{action:L.DELETE_PAGE,data:{id:a==null?void 0:a.id}}),onSuccess:(a,i)=>{if(a.code==="PAGE_LOCKED"){oe.toast.error("Delete not allowed",{description:"Page is currently being edited by another user."});return}i&&(i!=null&&i.primaryPage)?t.invalidateQueries({queryKey:[L.GET_LANGUAGE_PAGES,i==null?void 0:i.primaryPage]}):t.invalidateQueries({queryKey:[L.GET_WEBSITE_PAGES]})},onError:(a,i)=>{const o=g.find(r,{key:i.pageType});oe.toast.error(`Failed to delete ${o!=null&&o.hasSlug?"page":o.name}.`,{description:a.message})}})},fi=()=>{const e=ee(),t=U.useQueryClient(),s=Z(),{data:r}=Ee();return U.useMutation({mutationFn:async a=>s(e,{action:L.TAKE_OFFLINE,data:{id:a==null?void 0:a.id}}),onSuccess:(a,i)=>{i&&(i!=null&&i.primaryPage)?t.invalidateQueries({queryKey:[L.GET_LANGUAGE_PAGES,i==null?void 0:i.primaryPage]}):t.invalidateQueries({queryKey:[L.GET_WEBSITE_PAGES]});const o=g.find(r,{key:i.pageType});oe.toast.success(o!=null&&o.hasSlug?q.PAGE_UNPUBLISH_SUCCESS:"New "+o.name+" added successfully.")},onError:(a,i)=>{const o=g.find(r,{key:i.pageType});oe.toast.error(`Failed to take offline ${o!=null&&o.hasSlug?"page":o.name}.`,{description:a.message})}})},bs=()=>{const e=ee(),t=Z(),s=U.useQueryClient(),{data:r}=Se();return U.useMutation({mutationFn:async({ids:a})=>t(e,{action:L.PUBLISH_CHANGES,data:{ids:a}}),onSuccess:()=>{s.invalidateQueries({queryKey:[L.GET_CHANGES]}),s.invalidateQueries({queryKey:[L.GET_WEBSITE_PAGES]}),s.invalidateQueries({queryKey:[L.GET_LANGUAGE_PAGES,r==null?void 0:r.id]})},onError:()=>{oe.toast.error("Failed to publish pages.")}})},mi=()=>{const e=ee(),t=Z(),s=U.useQueryClient();return U.useMutation({mutationFn:async({id:r,slug:a})=>t(e,{action:L.CHANGE_SLUG,data:{id:r,slug:a}}),onSuccess:(r,{primaryPage:a})=>{oe.toast.success(q.SLUG_CHANGE_SUCCESS),a?s.invalidateQueries({queryKey:[L.GET_LANGUAGE_PAGES,a]}):s.invalidateQueries({queryKey:[L.GET_WEBSITE_PAGES]})},onError:()=>{oe.toast.error("Failed to change slug")}})};var ws={};(function e(t,s,r,a){var i=!!(t.Worker&&t.Blob&&t.Promise&&t.OffscreenCanvas&&t.OffscreenCanvasRenderingContext2D&&t.HTMLCanvasElement&&t.HTMLCanvasElement.prototype.transferControlToOffscreen&&t.URL&&t.URL.createObjectURL),o=typeof Path2D=="function"&&typeof DOMMatrix=="function",l=function(){if(!t.OffscreenCanvas)return!1;var x=new OffscreenCanvas(1,1),h=x.getContext("2d");h.fillRect(0,0,1,1);var _=x.transferToImageBitmap();try{h.createPattern(_,"no-repeat")}catch{return!1}return!0}();function u(){}function d(x){var h=s.exports.Promise,_=h!==void 0?h:t.Promise;return typeof _=="function"?new _(x):(x(u,u),null)}var f=function(x,h){return{transform:function(_){if(x)return _;if(h.has(_))return h.get(_);var O=new OffscreenCanvas(_.width,_.height),$=O.getContext("2d");return $.drawImage(_,0,0),h.set(_,O),O},clear:function(){h.clear()}}}(l,new Map),m=function(){var x=Math.floor(16.666666666666668),h,_,O={},$=0;return typeof requestAnimationFrame=="function"&&typeof cancelAnimationFrame=="function"?(h=function(K){var z=Math.random();return O[z]=requestAnimationFrame(function M(W){$===W||$+x-1<W?($=W,delete O[z],K()):O[z]=requestAnimationFrame(M)}),z},_=function(K){O[K]&&cancelAnimationFrame(O[K])}):(h=function(K){return setTimeout(K,x)},_=function(K){return clearTimeout(K)}),{frame:h,cancel:_}}(),w=function(){var x,h,_={};function O($){function K(z,M){$.postMessage({options:z||{},callback:M})}$.init=function(M){var W=M.transferControlToOffscreen();$.postMessage({canvas:W},[W])},$.fire=function(M,W,re){if(h)return K(M,null),h;var ue=Math.random().toString(36).slice(2);return h=d(function(ie){function de(ge){ge.data.callback===ue&&(delete _[ue],$.removeEventListener("message",de),h=null,f.clear(),re(),ie())}$.addEventListener("message",de),K(M,ue),_[ue]=de.bind(null,{data:{callback:ue}})}),h},$.reset=function(){$.postMessage({reset:!0});for(var M in _)_[M](),delete _[M]}}return function(){if(x)return x;if(!r&&i){var $=["var CONFETTI, SIZE = {}, module = {};","("+e.toString()+")(this, module, true, SIZE);","onmessage = function(msg) {"," if (msg.data.options) {"," CONFETTI(msg.data.options).then(function () {"," if (msg.data.callback) {"," postMessage({ callback: msg.data.callback });"," }"," });"," } else if (msg.data.reset) {"," CONFETTI && CONFETTI.reset();"," } else if (msg.data.resize) {"," SIZE.width = msg.data.resize.width;"," SIZE.height = msg.data.resize.height;"," } else if (msg.data.canvas) {"," SIZE.width = msg.data.canvas.width;"," SIZE.height = msg.data.canvas.height;"," CONFETTI = module.exports.create(msg.data.canvas);"," }","}"].join(`
2
- `);try{x=new Worker(URL.createObjectURL(new Blob([$])))}catch(K){return typeof console!==void 0&&typeof console.warn=="function"&&console.warn("🎊 Could not load worker",K),null}O(x)}return x}}(),E={particleCount:50,angle:90,spread:45,startVelocity:45,decay:.9,gravity:1,drift:0,ticks:200,x:.5,y:.5,shapes:["square","circle"],zIndex:100,colors:["#26ccff","#a25afd","#ff5e7e","#88ff5a","#fcff42","#ffa62d","#ff36ff"],disableForReducedMotion:!1,scalar:1};function y(x,h){return h?h(x):x}function j(x){return x!=null}function b(x,h,_){return y(x&&j(x[h])?x[h]:E[h],_)}function D(x){return x<0?0:Math.floor(x)}function A(x,h){return Math.floor(Math.random()*(h-x))+x}function T(x){return parseInt(x,16)}function v(x){return x.map(P)}function P(x){var h=String(x).replace(/[^0-9a-f]/gi,"");return h.length<6&&(h=h[0]+h[0]+h[1]+h[1]+h[2]+h[2]),{r:T(h.substring(0,2)),g:T(h.substring(2,4)),b:T(h.substring(4,6))}}function F(x){var h=b(x,"origin",Object);return h.x=b(h,"x",Number),h.y=b(h,"y",Number),h}function C(x){x.width=document.documentElement.clientWidth,x.height=document.documentElement.clientHeight}function k(x){var h=x.getBoundingClientRect();x.width=h.width,x.height=h.height}function N(x){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=x,h}function G(x,h,_,O,$,K,z,M,W){x.save(),x.translate(h,_),x.rotate(K),x.scale(O,$),x.arc(0,0,1,z,M,W),x.restore()}function H(x){var h=x.angle*(Math.PI/180),_=x.spread*(Math.PI/180);return{x:x.x,y:x.y,wobble:Math.random()*10,wobbleSpeed:Math.min(.11,Math.random()*.1+.05),velocity:x.startVelocity*.5+Math.random()*x.startVelocity,angle2D:-h+(.5*_-Math.random()*_),tiltAngle:(Math.random()*(.75-.25)+.25)*Math.PI,color:x.color,shape:x.shape,tick:0,totalTicks:x.ticks,decay:x.decay,drift:x.drift,random:Math.random()+2,tiltSin:0,tiltCos:0,wobbleX:0,wobbleY:0,gravity:x.gravity*3,ovalScalar:.6,scalar:x.scalar,flat:x.flat}}function Y(x,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 _=h.tick++/h.totalTicks,O=h.x+h.random*h.tiltCos,$=h.y+h.random*h.tiltSin,K=h.wobbleX+h.random*h.tiltCos,z=h.wobbleY+h.random*h.tiltSin;if(x.fillStyle="rgba("+h.color.r+", "+h.color.g+", "+h.color.b+", "+(1-_)+")",x.beginPath(),o&&h.shape.type==="path"&&typeof h.shape.path=="string"&&Array.isArray(h.shape.matrix))x.fill(be(h.shape.path,h.shape.matrix,h.x,h.y,Math.abs(K-O)*.1,Math.abs(z-$)*.1,Math.PI/10*h.wobble));else if(h.shape.type==="bitmap"){var M=Math.PI/10*h.wobble,W=Math.abs(K-O)*.1,re=Math.abs(z-$)*.1,ue=h.shape.bitmap.width*h.scalar,ie=h.shape.bitmap.height*h.scalar,de=new DOMMatrix([Math.cos(M)*W,Math.sin(M)*W,-Math.sin(M)*re,Math.cos(M)*re,h.x,h.y]);de.multiplySelf(new DOMMatrix(h.shape.matrix));var ge=x.createPattern(f.transform(h.shape.bitmap),"no-repeat");ge.setTransform(de),x.globalAlpha=1-_,x.fillStyle=ge,x.fillRect(h.x-ue/2,h.y-ie/2,ue,ie),x.globalAlpha=1}else if(h.shape==="circle")x.ellipse?x.ellipse(h.x,h.y,Math.abs(K-O)*h.ovalScalar,Math.abs(z-$)*h.ovalScalar,Math.PI/10*h.wobble,0,2*Math.PI):G(x,h.x,h.y,Math.abs(K-O)*h.ovalScalar,Math.abs(z-$)*h.ovalScalar,Math.PI/10*h.wobble,0,2*Math.PI);else if(h.shape==="star")for(var Q=Math.PI/2*3,ve=4*h.scalar,Ne=8*h.scalar,Ae=h.x,De=h.y,Be=5,Pe=Math.PI/Be;Be--;)Ae=h.x+Math.cos(Q)*Ne,De=h.y+Math.sin(Q)*Ne,x.lineTo(Ae,De),Q+=Pe,Ae=h.x+Math.cos(Q)*ve,De=h.y+Math.sin(Q)*ve,x.lineTo(Ae,De),Q+=Pe;else x.moveTo(Math.floor(h.x),Math.floor(h.y)),x.lineTo(Math.floor(h.wobbleX),Math.floor($)),x.lineTo(Math.floor(K),Math.floor(z)),x.lineTo(Math.floor(O),Math.floor(h.wobbleY));return x.closePath(),x.fill(),h.tick<h.totalTicks}function Le(x,h,_,O,$){var K=h.slice(),z=x.getContext("2d"),M,W,re=d(function(ue){function ie(){M=W=null,z.clearRect(0,0,O.width,O.height),f.clear(),$(),ue()}function de(){r&&!(O.width===a.width&&O.height===a.height)&&(O.width=x.width=a.width,O.height=x.height=a.height),!O.width&&!O.height&&(_(x),O.width=x.width,O.height=x.height),z.clearRect(0,0,O.width,O.height),K=K.filter(function(ge){return Y(z,ge)}),K.length?M=m.frame(de):ie()}M=m.frame(de),W=ie});return{addFettis:function(ue){return K=K.concat(ue),re},canvas:x,promise:re,reset:function(){M&&m.cancel(M),W&&W()}}}function me(x,h){var _=!x,O=!!b(h||{},"resize"),$=!1,K=b(h,"disableForReducedMotion",Boolean),z=i&&!!b(h||{},"useWorker"),M=z?w():null,W=_?C:k,re=x&&M?!!x.__confetti_initialized:!1,ue=typeof matchMedia=="function"&&matchMedia("(prefers-reduced-motion)").matches,ie;function de(Q,ve,Ne){for(var Ae=b(Q,"particleCount",D),De=b(Q,"angle",Number),Be=b(Q,"spread",Number),Pe=b(Q,"startVelocity",Number),Kn=b(Q,"decay",Number),zn=b(Q,"gravity",Number),Wn=b(Q,"drift",Number),As=b(Q,"colors",v),Qn=b(Q,"ticks",Number),Ts=b(Q,"shapes"),Yn=b(Q,"scalar"),Xn=!!b(Q,"flat"),Cs=F(Q),Ps=Ae,Jt=[],Zn=x.width*Cs.x,Jn=x.height*Cs.y;Ps--;)Jt.push(H({x:Zn,y:Jn,angle:De,spread:Be,startVelocity:Pe,color:As[Ps%As.length],shape:Ts[A(0,Ts.length)],ticks:Qn,decay:Kn,gravity:zn,drift:Wn,scalar:Yn,flat:Xn}));return ie?ie.addFettis(Jt):(ie=Le(x,Jt,W,ve,Ne),ie.promise)}function ge(Q){var ve=K||b(Q,"disableForReducedMotion",Boolean),Ne=b(Q,"zIndex",Number);if(ve&&ue)return d(function(Pe){Pe()});_&&ie?x=ie.canvas:_&&!x&&(x=N(Ne),document.body.appendChild(x)),O&&!re&&W(x);var Ae={width:x.width,height:x.height};M&&!re&&M.init(x),re=!0,M&&(x.__confetti_initialized=!0);function De(){if(M){var Pe={getBoundingClientRect:function(){if(!_)return x.getBoundingClientRect()}};W(Pe),M.postMessage({resize:{width:Pe.width,height:Pe.height}});return}Ae.width=Ae.height=null}function Be(){ie=null,O&&($=!1,t.removeEventListener("resize",De)),_&&x&&(document.body.contains(x)&&document.body.removeChild(x),x=null,re=!1)}return O&&!$&&($=!0,t.addEventListener("resize",De,!1)),M?M.fire(Q,Ae,Be):de(Q,Ae,Be)}return ge.reset=function(){M&&M.reset(),ie&&ie.reset()},ge}var p;function V(){return p||(p=me(null,{useWorker:!0,resize:!0})),p}function be(x,h,_,O,$,K,z){var M=new Path2D(x),W=new Path2D;W.addPath(M,new DOMMatrix(h));var re=new Path2D;return re.addPath(W,new DOMMatrix([Math.cos(z)*$,Math.sin(z)*$,-Math.sin(z)*K,Math.cos(z)*K,_,O])),re}function xe(x){if(!o)throw new Error("path confetti are not supported in this browser");var h,_;typeof x=="string"?h=x:(h=x.path,_=x.matrix);var O=new Path2D(h),$=document.createElement("canvas"),K=$.getContext("2d");if(!_){for(var z=1e3,M=z,W=z,re=0,ue=0,ie,de,ge=0;ge<z;ge+=2)for(var Q=0;Q<z;Q+=2)K.isPointInPath(O,ge,Q,"nonzero")&&(M=Math.min(M,ge),W=Math.min(W,Q),re=Math.max(re,ge),ue=Math.max(ue,Q));ie=re-M,de=ue-W;var ve=10,Ne=Math.min(ve/ie,ve/de);_=[Ne,0,0,Ne,-Math.round(ie/2+M)*Ne,-Math.round(de/2+W)*Ne]}return{type:"path",path:h,matrix:_}}function Ns(x){var h,_=1,O="#000000",$='"Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji", "EmojiOne Color", "Android Emoji", "Twemoji Mozilla", "system emoji", sans-serif';typeof x=="string"?h=x:(h=x.text,_="scalar"in x?x.scalar:_,$="fontFamily"in x?x.fontFamily:$,O="color"in x?x.color:O);var K=10*_,z=""+K+"px "+$,M=new OffscreenCanvas(K,K),W=M.getContext("2d");W.font=z;var re=W.measureText(h),ue=Math.ceil(re.actualBoundingBoxRight+re.actualBoundingBoxLeft),ie=Math.ceil(re.actualBoundingBoxAscent+re.actualBoundingBoxDescent),de=2,ge=re.actualBoundingBoxLeft+de,Q=re.actualBoundingBoxAscent+de;ue+=de+de,ie+=de+de,M=new OffscreenCanvas(ue,ie),W=M.getContext("2d"),W.font=z,W.fillStyle=O,W.fillText(h,ge,Q);var ve=1/_;return{type:"bitmap",bitmap:M.transferToImageBitmap(),matrix:[ve,0,0,ve,-ue*ve/2,-ie*ve/2]}}s.exports=function(){return V().apply(this,arguments)},s.exports.reset=function(){V().reset()},s.exports.create=me,s.exports.shapeFromPath=xe,s.exports.shapeFromText=Ns})(function(){return typeof window<"u"?window:typeof self<"u"?self:this||{}}(),ws,!1);const gi=ws.exports;ws.exports.create;const xi={particleCount:350,spread:120,origin:{y:.6},angle:90},pi={TOP_RIGHT:{angle:225,origin:{x:.9,y:0}},BOTTOM_RIGHT:{angle:100,origin:{x:.9,y:.9}}},Qt=e=>{let t=pi[e];t||(t={});const s={...xi,...t};gi(s)},yi=()=>{const[e]=ae.useTheme(),{mutate:t,isPending:s}=bs(),{mutateAsync:r,isPending:a}=Ln(),i=()=>{r({settings:{theme:e}})},o=()=>{t({ids:["THEME"]},{onSuccess:()=>{Qt("BOTTOM_RIGHT")}})};return n.jsxs("div",{className:"bg-white py-3 flex items-center justify-center gap-x-3 border-t",children:[n.jsx(c.Button,{size:"sm",variant:"outline",disabled:s||a,onClick:i,children:"Save draft"}),n.jsx(c.Button,{size:"sm",disabled:s||a,onClick:o,children:"Publish"})]})},ce={...ae.PERMISSIONS,ADD_PAGE:"add_page",EDIT_PAGE:"edit_page",EDIT_SLUG:"edit_slug",DELETE_PAGE:"delete_page",PUBLISH_PAGE:"publish_page",UNPUBLISH_PAGE:"unpublish_page",SAVE_AS_TEMPLATE:"save_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:"add_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"},Ei=({page:e,onClose:t})=>{const[s,r]=S.useState(e.slug||""),{mutate:a,isPending:i}=mi(),{data:o}=Ee(),l=g.find(o,{key:e==null?void 0:e.pageType}),u=f=>{if(f.preventDefault(),!(e!=null&&e.primaryPage)&&Object.keys(Te).some(E=>s===`/${E}`||g.startsWith(s,`/${E}/`))){oe.toast.error("Error",{description:"Slugs cannot start with a language code for primary page"});return}a({...e,slug:s},{onSuccess:t})},d=(e==null?void 0:e.lang)||"";return n.jsx(c.Dialog,{open:!!e,onOpenChange:t,children:n.jsxs(c.DialogContent,{children:[n.jsxs(c.DialogHeader,{children:[n.jsx(c.DialogTitle,{children:"Change Slug"}),n.jsx(c.DialogDescription,{className:"text-xs",children:n.jsxs(c.Alert,{variant:"destructive",className:"mt-2",children:[n.jsx(I.AlertCircle,{className:"h-4 w-4"}),"Changing the slug may have impact on your SEO. Please proceed with caution."]})})]}),n.jsxs("form",{onSubmit:u,children:[n.jsxs("div",{className:"space-y-4 py-4 text-sm ",children:[n.jsxs("div",{className:"space-y-1",children:[n.jsxs("div",{children:[n.jsx("span",{children:"Type:"}),n.jsxs("span",{className:"font-medium text-gray-600",children:[" ",(l==null?void 0:l.name)||(e==null?void 0:e.pageType)]})]}),n.jsxs("div",{children:[n.jsx("span",{children:"Name:"}),n.jsxs("span",{className:"font-medium text-gray-600",children:[" ",e.name]})]})]}),n.jsxs("div",{className:"space-y-1",children:[n.jsxs(c.Label,{htmlFor:"slug",className:"text-right",children:["Slug"," ",n.jsxs("small",{className:"font-light text-gray-500",children:["Slug should start with /",d]})]}),n.jsx(c.Input,{id:"slug",value:s,onChange:f=>{const m=f.target.value;g.startsWith(m,`/${d}`)&&r(m)},className:"col-span-3",required:!0,pattern:"^/.*",title:"Slug must start with /",placeholder:"Enter page slug"})]})]}),n.jsx(c.DialogFooter,{children:n.jsx(c.Button,{type:"submit",disabled:i||!g.startsWith(s,`/${d}`)||g.isEqual(e==null?void 0:e.slug,s),children:i?"Changing...":"Change Slug"})})]})]})})};function On({page:e,onClose:t}){const[,s]=je(),{mutate:r,isPending:a}=hi(),{data:i}=Ee(),o=()=>{r(e,{onSuccess:()=>{e!=null&&e.primaryPage||(window.history.replaceState(null,"","/"),s(new URLSearchParams({})),window.dispatchEvent(new PopStateEvent("popstate"))),t()}})},l=i==null?void 0:i.find(u=>u.key===(e==null?void 0:e.pageType));return n.jsx(c.Dialog,{open:!!e,onOpenChange:t,children:n.jsxs(c.DialogContent,{children:[n.jsxs(c.DialogHeader,{children:[n.jsx(c.DialogTitle,{children:"Confirm Deletion"}),n.jsxs(c.DialogDescription,{className:"py-4 text-slate-500",children:[n.jsxs("div",{children:["Are you sure you want to remove ",n.jsx("b",{children:(e==null?void 0:e.name)??(e==null?void 0:e.slug)})," ",l!=null&&l.hasSlug?(l==null?void 0:l.name)+"?":`page? ${e!=null&&e.primaryPage?"":"This will also delete all associated language pages."}`]}),e.lang&&n.jsxs("div",{className:"py-2 text-sm",children:["Language:"," ",n.jsx("span",{className:"font-medium text-gray-500",children:g.get(Te,e.lang,e.lang)})]})]})]}),n.jsxs(c.DialogFooter,{children:[n.jsx(c.Button,{variant:"outline",onClick:t,children:"Cancel"}),n.jsx(c.Button,{variant:"destructive",disabled:a,onClick:o,children:a?"Deleting...":"Delete"})]})]})})}const we=({permission:e,permissions:t,children:s,fallback:r=null})=>{const{hasPermission:a}=ae.usePermissions();return e&&!a(e)||t&&!t.some(i=>a(i))?r:s},js=({page:e,onClose:t})=>{const{mutate:s,isPending:r}=fi(),a=async()=>{s(e,{onSuccess:t})};return n.jsx(c.Dialog,{open:!!e,onOpenChange:t,children:n.jsxs(c.DialogContent,{children:[n.jsxs(c.DialogHeader,{children:[n.jsx(c.DialogTitle,{children:"Confirm action"}),n.jsxs(c.DialogDescription,{children:[q.UNPUBLISH_MSG," ",n.jsx("b",{children:(e==null?void 0:e.name)??(e==null?void 0:e.slug)}),"?"]})]}),n.jsxs(c.DialogFooter,{children:[n.jsx(c.Button,{variant:"outline",onClick:t,children:"Cancel"}),n.jsx(c.Button,{variant:"destructive",disabled:r,onClick:a,children:r?q.UPDATING:q.UNPUBLISH})]})]})})},Rn=({langProps:e,onClose:t,languages:s})=>{const{data:r}=Se(),{data:a}=Ee(),[i,o]=S.useState(e.name||""),[l,u]=S.useState(e.edit?e.lang:""),[d,f]=S.useState(e.edit?e.slug:""),{mutate:m,isPending:w}=Un(),{mutate:E,isPending:y}=Ss(),j=S.useMemo(()=>a==null?void 0:a.find(T=>T.key===e.pageType),[a,e.pageType]),b=!(j!=null&&j.hasSlug),D=w||y,A=T=>{T.preventDefault();const v={name:i,lang:l,primaryPage:r==null?void 0:r.id,slug:d,pageType:r==null?void 0:r.pageType};v.pageType=e.pageType,e.edit&&(v.id=e==null?void 0:e.id),e.edit?E(v,{onSuccess:t}):m(v,{onSuccess:t})};return n.jsx(c.Dialog,{open:!!e,onOpenChange:t,children:n.jsxs(c.DialogContent,{className:"sm:max-w-[425px] text-slate-600",children:[n.jsxs(c.DialogHeader,{children:[n.jsx(c.DialogTitle,{children:e.edit?q.EDIT_LANGUAGE:q.ADD_NEW_LANGUAGE}),n.jsx(c.DialogDescription,{className:"font-light",children:q.ENTER_LANGUAGE_DETAILS})]}),n.jsxs("form",{onSubmit:A,children:[n.jsxs("div",{className:"grid gap-4 py-4",children:[n.jsxs("div",{className:"space-y-1",children:[n.jsx(c.Label,{htmlFor:"lang",className:"text-right",children:q.LANGUAGE}),n.jsxs("select",{value:l,disabled:e.edit||g.isEmpty(s),onChange:T=>{const v=T.target.value;u(v),!b&&f(`/${v}`)},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:[n.jsx("option",{value:"",disabled:!0,selected:!0,children:e.edit?g.get(Te,e.lang,e.lang):g.isEmpty(s)?q.ALL_AVAILABLE_LANGUAGE_PAGE:q.CHOOSE_LANGUAGE}),g.map(s,T=>n.jsx("option",{value:T,children:g.get(Te,T,T)},T))]})]}),n.jsxs("div",{className:"space-y-1",children:[n.jsx(c.Label,{htmlFor:"slug",className:"text-right",children:q.PAGE_NAME}),n.jsx(c.Input,{id:"name",value:i,onChange:T=>o(T.target.value),className:"col-span-3",required:!0,placeholder:q.ENTER_PAGE_NAME})]}),!b&&n.jsxs("div",{className:"space-y-1",children:[n.jsxs(c.Label,{htmlFor:"slug",className:"text-right",children:[q.SLUG," ",n.jsx("small",{className:"font-light",children:q.SLUG_SHOULD_START_WITH})]}),n.jsx(c.Input,{id:"slug",value:d,onChange:T=>{const v=T.target.value;g.startsWith(v,`/${l}`)&&f(g.toLower(g.trim(v)))},className:"col-span-3",required:!0,pattern:"^/.*",disabled:g.isEmpty(l),title:q.SLUG_MUST_START_WITH,placeholder:g.isEmpty(l)?q.CHOOSE_LANGUAGE_TO_ADD_SLUG:q.ENTER_PAGE_SLUG})]})]}),n.jsx(c.DialogFooter,{children:n.jsx(c.Button,{type:"submit",disabled:D||!i||!l||!b&&!g.startsWith(d,`/${l}`),children:D?e.edit?q.UPDATING:q.ADDING:e.edit?q.UPDATE:q.ADD_NEW_LANGUAGE})})]})]})})},vi=()=>{const[e,t]=S.useState(null),{selectedLang:s,fallbackLang:r,setSelectedLang:a}=ae.useLanguages(),{data:i,isFetching:o}=ft(),{data:l}=Se(),[u,d]=S.useState(null),[f,m]=S.useState(null),[w,E]=S.useState(null),{data:y}=ht(),j=g.filter(g.get(y,"languages")||["en"],b=>!g.find(i,{lang:b})&&b!==g.get(y,"fallbackLang"));return n.jsxs("div",{className:"space-y-4 pt-2",children:[n.jsx("ul",{className:"space-y-2 mt-4",children:o?n.jsxs("div",{className:"w-full space-y-3 py-4",children:[n.jsx("div",{className:"w-full h-8 rounded bg-gray-300 animate-pulse"}),n.jsx("div",{className:"w-full h-8 rounded bg-gray-300 animate-pulse"}),n.jsx("div",{className:"w-full h-8 rounded bg-gray-300 animate-pulse"})]}):g.map(i,b=>{const D=b.lang,A=b.slug,T=!b.primaryPage,v=D===s;return n.jsxs(n.Fragment,{children:[n.jsxs("li",{className:`text-slate-500 w-full p-2 rounded cursor-pointer flex items-center justify-between ${v?"bg-gray-200":"hover:bg-gray-100"}`,onClick:()=>a(D),children:[n.jsxs("div",{className:" flex-1 gap-x-3",children:[n.jsxs("div",{className:"text-[13px] text-slate-800 flex items-center gap-x-2",children:[n.jsx("div",{className:`w-2.5 h-2.5 rounded-full ${b.online?"bg-green-300":"bg-gray-300"}`}),g.get(Te,T?r:D,D)]}),n.jsxs("div",{children:[A&&n.jsxs("div",{className:"text-[11px] text-slate-600 font-light",children:["Slug: ",n.jsx("b",{className:"font-medium",children:A})]}),n.jsxs("div",{className:"text-[11px] text-slate-600 font-light",children:["Name:",n.jsxs("b",{className:"font-medium",children:[" ",b.name," "]})]})]})]}),T?n.jsxs("div",{className:"flex items-center text-[11px] text-orange-500 gap-x-1",children:[n.jsx(I.StarIcon,{fill:"orange",className:"w-3 h-3"}),n.jsx("b",{children:" Primary"})]}):n.jsx("div",{className:"flex items-center gap-x-3",children:n.jsx(we,{permissions:[ce.EDIT_PAGE,ce.DELETE_PAGE,ce.UNPUBLISH_PAGE],children:n.jsxs(c.DropdownMenu,{children:[n.jsx(c.DropdownMenuTrigger,{asChild:!0,onClick:P=>P.stopPropagation(),children:n.jsx(c.Button,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0",children:n.jsx(I.MoreHorizontal,{className:"h-4 w-4"})})}),n.jsxs(c.DropdownMenuContent,{align:"end",className:"text-sm",children:[n.jsx(we,{permissions:[ce.EDIT_PAGE],children:n.jsxs(c.DropdownMenuItem,{className:"flex items-center gap-2 cursor-pointer",onClick:P=>{P.stopPropagation(),t({...b,edit:!0})},children:[n.jsx(I.PencilIcon,{className:"size-3"}),q.EDIT]})}),n.jsx(we,{permissions:[ce.UNPUBLISH_PAGE],children:(b==null?void 0:b.online)&&n.jsxs(c.DropdownMenuItem,{className:"flex items-center gap-2 cursor-pointer",onClick:P=>{P.stopPropagation(),m(b)},children:[n.jsx(I.Power,{className:"size-3"}),q.UNPUBLISH]})}),n.jsx(we,{permissions:[ce.DELETE_PAGE],children:n.jsxs(c.DropdownMenuItem,{className:"flex items-center gap-2 cursor-pointer",onClick:P=>{P.stopPropagation(),d(b)},children:[n.jsx(I.TrashIcon,{className:"size-3"}),q.DELETE]})})]})]})})})]},b.id),n.jsx("div",{className:"h-1 w-full border-b"})]})})}),n.jsx(we,{permissions:[ce.ADD_PAGE],children:n.jsx("div",{className:"flex justify-center w-full",children:n.jsx(c.Button,{variant:"default",size:"sm",disabled:g.isEmpty(j),onClick:()=>{t({name:l==null?void 0:l.name,pageType:l==null?void 0:l.pageType,lang:"",slug:"",edit:!1})},children:q.ADD_NEW_LANGUAGE})})}),e&&n.jsx(Rn,{languages:j,langProps:e,onClose:()=>t(null)}),u&&n.jsx(On,{page:u,onClose:()=>d(null)}),f&&n.jsx(js,{page:f,onClose:()=>m(null)}),w&&n.jsx(Ei,{page:w,onClose:()=>E(null)})]})};function Si({addEditPage:e,additionalPageTypes:t=[],close:s}){var Le,me;const r=!!(e!=null&&e.id),{data:a}=Gt(),{mutate:i,isPending:o}=Un(),{mutate:l,isPending:u}=Ss(),[d,f]=S.useState(null),[m,w]=S.useState((e==null?void 0:e.pageType)??"page"),[E,y]=S.useState(t.find(p=>p.key===m)),[j,b]=S.useState((e==null?void 0:e.parent)??""),[D,A]=S.useState((e==null?void 0:e.name)??""),[T,v]=S.useState(((e==null?void 0:e.slug)??"").split("/").pop()||""),[P,F]=S.useState((e==null?void 0:e.dynamic)??!1),C=o||u,k=t.find(p=>p.key===m),N=p=>{w(p),b(""),v(""),F(!1),y(t.find(V=>V.key===p))},G=p=>{F(p),p&&v("")},H=p=>{if(b(p),p&&p!=="none"){const V=a==null?void 0:a.find(xe=>xe.id===p),be=(V==null?void 0:V.slug)||"";if(T.startsWith(be)){const xe=T.slice(be.length).replace(/^\/+/,"");v(xe)}else v(T.replace(/^\/+/,""))}else v(T?`${T}`:"")},Y=p=>{if(p.preventDefault(),T.length>0&&!P&&!T.match(/^[a-zA-Z0-9-_]+$/)){f("Slug can only contain letters, numbers, and hyphens");return}if(P&&T!==""){f("Slug must be empty when using dynamic slug");return}if(!D.trim()){oe.toast.error("Name is required");return}if(!(E!=null&&E.hasSlug)){const V={pageType:E==null?void 0:E.key,name:D,slug:"",hasSlug:!1};if(r){l({id:e==null?void 0:e.id,name:D},{onSuccess:()=>{oe.toast.success((E==null?void 0:E.name)+" updated successfully"),s()}});return}i(V,{onSuccess:()=>{oe.toast.success((E==null?void 0:E.name)+" created successfully"),s()}});return}if(j&&j!=="none"){if(!T.trim()&&!P){oe.toast.error("Child page slug is required");return}const V=a==null?void 0:a.find(_=>_.id===j),be=(V==null?void 0:V.slug)||"",xe=be==="/"?`/${T}`:`${be}/${T}`;if(Object.keys(Te).some(_=>xe===`/${_}`||(xe==null?void 0:xe.startsWith(`/${_}/`)))){oe.toast.error("Slugs cannot start with a language code for primary page");return}const h={pageType:m,name:D,slug:xe.replace(/\/$/,""),parent:j,dynamic:P,hasSlug:!0};if(r){l({id:e==null?void 0:e.id,...h},{onSuccess:()=>{oe.toast.success("Page updated successfully"),s()}});return}i(h,{onSuccess:()=>{oe.toast.success("Page created successfully"),s()}})}else{const V={pageType:m,name:D,slug:T===""?"/":`/${T.replace(/\/$/,"")}`};if(r){l({id:e==null?void 0:e.id,...V},{onSuccess:()=>{oe.toast.success("Page updated successfully"),s()}});return}i(V,{onSuccess:()=>{oe.toast.success("Page created successfully"),s()}})}};return E!=null&&E.hasSlug?(console.log(a),n.jsxs("form",{onSubmit:Y,className:"w-full max-w-md mx-auto space-y-4",children:[n.jsxs("div",{className:"space-y-0.5",children:[n.jsx(c.Label,{htmlFor:"pageType",className:"text-sm",children:"Page Type"}),n.jsxs("select",{id:"pageType",value:m,disabled:r,onChange:p=>N(p.target.value),className:`w-full rounded-md border border-gray-300 px-3 py-2 ${r?"cursor-not-allowed text-gray-500":""}`,children:[n.jsx("optgroup",{label:"Pages",children:t.filter(p=>p.hasSlug!==!1).map(p=>n.jsx("option",{value:p.key,children:p.name},p.key))}),n.jsx("optgroup",{label:"Partials",children:t.filter(p=>p.hasSlug===!1).map(p=>n.jsx("option",{value:p.key,children:p.name},p.key))})]})]}),n.jsxs("div",{className:"space-y-0.5",children:[n.jsx(c.Label,{htmlFor:"parentPage",className:"text-sm",children:"Parent"}),n.jsxs("select",{id:"parentPage",value:j,onChange:p=>H(p.target.value),className:"w-full rounded-md border border-gray-300 px-3 py-2",children:[n.jsx("option",{value:"none",children:"None"}),a==null?void 0:a.filter(p=>!g.isEmpty(p.slug)).filter(p=>p.slug!=="/").sort((p,V)=>p.name.localeCompare(V.name)).map(p=>n.jsxs("option",{value:p.id,children:[p.name," (",p.slug,")"]},p.id))]})]}),n.jsxs("div",{className:"space-y-0.5",children:[n.jsx(c.Label,{htmlFor:"name",className:"text-sm",children:"Name"}),n.jsx(c.Input,{id:"name",value:D,onChange:p=>A(p.target.value),required:!0,"aria-required":"true"})]}),(k==null?void 0:k.dynamicSegments)&&j&&j!=="none"&&n.jsxs("div",{className:"space-y-2",children:[n.jsxs("div",{className:"flex items-center space-x-2",children:[n.jsx("input",{type:"checkbox",id:"useDynamicSlug",checked:P,onChange:p=>G(p.target.checked),className:"rounded border-gray-300"}),n.jsx(c.Label,{htmlFor:"useDynamicSlug",className:"text-sm",children:"Use Dynamic Slug"})]}),P&&n.jsxs("div",{className:"text-sm text-gray-500",children:["Pages will use pattern: ",k==null?void 0:k.dynamicSlug]})]}),(!(k!=null&&k.dynamicSegments)||!P)&&n.jsxs("div",{className:"space-y-0.5",children:[n.jsxs(c.Label,{htmlFor:"slug",className:"text-sm",children:["Slug",j&&j!=="none"&&n.jsxs("span",{className:"ml-2 text-sm text-gray-500",children:["Parent:"," ",(me=a==null?void 0:a.find(p=>p.id===j))==null?void 0:me.slug]})]}),n.jsx(c.Input,{id:"slug",value:T,onChange:p=>v(p.target.value),placeholder:j&&j!=="none"?"Enter page slug":m==="page"?"Leave empty for home page":"Required - e.g. /your-slug"}),d&&n.jsx("p",{className:"text-xs text-red-500",children:d})]}),n.jsx(c.Button,{disabled:C,type:"submit",className:"w-full",children:r?C?"Updating...":"Update page":C?"Creating...":"Create Page"})]})):n.jsxs("form",{onSubmit:Y,className:"w-full max-w-md mx-auto space-y-4",children:[n.jsxs("div",{className:"space-y-0.5",children:[n.jsx(c.Label,{htmlFor:"pageType",className:"text-sm",children:"Page Type"}),n.jsxs("select",{id:"pageType",value:m,disabled:r,onChange:p=>N(p.target.value),className:`w-full rounded-md border border-gray-300 px-3 py-2 ${r?"cursor-not-allowed text-gray-500":""}`,children:[n.jsx("optgroup",{label:"Pages",children:t.filter(p=>p.hasSlug!==!1).map(p=>n.jsx("option",{value:p.key,children:p.name},p.key))}),n.jsx("optgroup",{label:"Partials",children:t.filter(p=>p.hasSlug===!1).map(p=>n.jsx("option",{value:p.key,children:p.name},p.key))})]}),n.jsx("p",{className:"text-sm text-gray-500",children:(Le=t.find(p=>p.key===m))==null?void 0:Le.helpText})]}),n.jsxs("div",{className:"space-y-0.5",children:[n.jsx(c.Label,{htmlFor:"name",className:"text-sm",children:"Name"}),n.jsx(c.Input,{id:"name",value:D,onChange:p=>A(p.target.value),required:!0,"aria-required":"true"})]}),n.jsx(c.Button,{disabled:C,type:"submit",className:"w-full",children:r?C?"Updating...":"Update "+(E==null?void 0:E.name):C?"Creating...":"Create "+(E==null?void 0:E.name)})]})}const bi=({addEditPage:e,setAddEditPage:t})=>{const{data:s}=Ee(),r=!!(e!=null&&e.id);return n.jsx(c.Dialog,{open:!!e,onOpenChange:()=>t(void 0),children:n.jsxs(c.DialogContent,{className:"sm:max-w-[425px]",children:[n.jsxs(c.DialogHeader,{children:[n.jsxs(c.DialogTitle,{children:[r?"Edit":"Add New"," "]}),n.jsx(c.DialogDescription,{children:r?"Update your page name":"Enter details to create a new page"})]}),n.jsx(Si,{addEditPage:e,close:()=>t(void 0),additionalPageTypes:s??[]})]})})},wi=()=>{const e=ee(),t=Z();return U.useQuery({queryKey:[L.GET_LIBRARIES],initialData:[],queryFn:async()=>t(e,{action:L.GET_LIBRARIES})})},ji=e=>{const t=ee(),s=Z();return U.useQuery({queryKey:[L.GET_LIBRARY_ITEMS,e],initialData:[],queryFn:async()=>e?s(t,{action:L.GET_LIBRARY_ITEMS,data:{id:e}}):[],enabled:!!e})},Bn=(e,t)=>{const s=g.filter(e,{_parent:t});if(s.length===0)return[];const r=[...s];return s.forEach(a=>{r.push(...Bn(e,a==null?void 0:a._id))}),r},Fs=({block:e,page:t,open:s,setOpen:r})=>{const a=!!t,[i,o]=S.useState("CREATE"),[l,u]=S.useState(""),[d,f]=S.useState(a?(t==null?void 0:t.name)+" template":""),[m,w]=S.useState(""),[E,y]=S.useState(""),[j]=ae.useBlocksStore(),b=Qa({id:l}),{data:D,isLoading:A}=wi(),{data:T,isLoading:v}=ji(l),P=A||v||b.isPending;S.useEffect(()=>{D.length>0&&u(D[0].id)},[D]);const F=()=>{if(a){const C={pageId:t==null?void 0:t.id,libraryId:l,group:m,name:d};E&&(C.id=E),b.mutate(C,{onSuccess:()=>r(!1)})}else if(e){const C=e==null?void 0:e._id,k=g.cloneDeep(e);k==null||delete k._parent;const G={blocks:[k,...Bn(j,C)],libraryId:l,group:m};E&&(G.id=E),G.name=d,b.mutate(G,{onSuccess:()=>r(!1)})}};return n.jsx(c.Dialog,{open:s,onOpenChange:r,children:n.jsxs(c.DialogContent,{children:[n.jsxs(c.DialogHeader,{children:[n.jsx(c.DialogTitle,{children:a?"Save page as template":"Add/Update library block"}),n.jsxs(c.DialogDescription,{className:`py-4 text-slate-500 space-y-1 text-xs ${P?"opacity-75 pointer-events-none":""}`,children:[n.jsx(c.Tabs,{value:i,onValueChange:o,className:"w-full",children:n.jsxs(c.TabsList,{className:"w-full",children:[n.jsxs(c.TabsTrigger,{value:"CREATE",className:"w-full",children:["Create new ",a?"template":""]}),n.jsxs(c.TabsTrigger,{value:"UPDATE",className:"w-full",children:["Update existing ",a?"template":""]})]})}),n.jsx("br",{}),n.jsx(c.Label,{className:"text-xs",children:"Choose Library"}),n.jsxs(c.Select,{disabled:P,value:l,onValueChange:u,children:[n.jsx(c.SelectTrigger,{className:"ring-0 focus:ring-0",onClick:C=>C.preventDefault(),children:n.jsx(c.SelectValue,{})}),n.jsx(c.SelectContent,{className:"z-[9999999]",children:g.map(D,C=>n.jsx(c.SelectItem,{value:C.id,children:C.name},C.id))})]}),n.jsx("br",{}),n.jsx(c.Label,{className:"text-xs",children:"Group"}),n.jsx(c.Input,{value:m,placeholder:"Enter group name",onClick:C=>C.stopPropagation(),onKeyDown:C=>C.stopPropagation(),onChange:C=>{w(C.target.value)}}),n.jsx("br",{}),i==="CREATE"?n.jsxs(n.Fragment,{children:[n.jsxs(c.Label,{className:"text-xs",children:[a?"Template":"Block"," name"]}),n.jsx(c.Input,{value:d,placeholder:`Enter ${a?"template":"block"} name`,onClick:C=>C.stopPropagation(),onKeyDown:C=>C.stopPropagation(),onChange:C=>{f(C.target.value)}})]}):n.jsxs(n.Fragment,{children:[n.jsxs(c.Label,{className:"text-xs",children:["Choose ",a?"template":"block"," to update"]}),n.jsxs(c.Select,{disabled:v,value:E,onValueChange:y,children:[n.jsx(c.SelectTrigger,{className:"ring-0 focus:ring-0",onClick:C=>C.preventDefault(),children:n.jsx(c.SelectValue,{placeholder:`Select ${a?"template":"block"}`})}),n.jsx(c.SelectContent,{className:"z-[9999999]",children:g.map(T,C=>n.jsx(c.SelectItem,{value:C.id,children:C.name},C.id))})]})]})]})]}),n.jsxs(c.DialogFooter,{className:P?"opacity-75 pointer-events-none":"",children:[n.jsx(c.Button,{variant:"outline",onClick:C=>{C.stopPropagation(),r(!1)},children:"Cancel"}),n.jsx(c.Button,{variant:"default",className:"capitalize",disabled:v||P||i==="CREATE"&&((d==null?void 0:d.length)<3||(m==null?void 0:m.length)<3)||i==="UPDATE"&&(l.length<1||E.length<1),onClick:F,children:i.toLowerCase()})]})]})})},Ni=({block:e,page:t,onClose:s=()=>{}})=>{const[r,a]=S.useState(!1),i=(e==null?void 0:e._type)==="PartialBlock";return t?n.jsx(Fs,{page:t,open:!0,setOpen:s}):n.jsxs(n.Fragment,{children:[n.jsxs(c.DropdownMenuItem,{disabled:i,onClick:o=>{o.stopPropagation(),o.preventDefault(),a(l=>!l)},className:"flex items-center gap-x-4 text-xs",children:[n.jsx(I.SquareLibrary,{className:"h-4 w-4"})," Save to library"]}),r&&e&&n.jsx(Fs,{block:e,page:t,open:r,setOpen:()=>{a(!1),s()}})]})},rs=({parentSlug:e,page:t,active:s,changeActivePage:r,setUnpublishPage:a,setDeletePage:i,setAddEditPage:o,setSaveAsTemp:l})=>{const{data:u}=Ee(),{hasPermission:d}=ae.usePermissions(),f=S.useMemo(()=>g.find(u,{key:t.pageType}),[u,t.pageType]),m=g.get(t,"slug").replace(e,"")||"/",w=!d(ce.EDIT_PAGE)&&!d(ce.DELETE_PAGE)&&!d(ce.UNPUBLISH_PAGE);return n.jsxs("div",{onClick:()=>r(g.get(t,"id")),className:`rounded flex p-1.5 items-center justify-between leading-none duration-300 cursor-pointer px-3 py-1.5 ${s?"bg-gray-200":"hover:bg-gray-100"}`,children:[n.jsxs("div",{className:"flex items-center gap-x-2",children:[t.dynamic?n.jsx("div",{className:"w-4 h-4 text-slate-500 stroke-[1]",children:n.jsx(I.StarsIcon,{className:"w-4 h-4 text-yellow-400"})}):f!=null&&f.icon?n.jsx("div",{className:"w-4 h-4 text-slate-500 stroke-[1]",dangerouslySetInnerHTML:{__html:f.icon}}):f!=null&&f.hasSlug?n.jsx(I.File,{className:"w-4 h-4 text-slate-500 stroke-[1]"}):n.jsx(I.Globe,{className:"w-4 h-4 text-slate-500 stroke-[1]"}),n.jsx("div",{className:`w-2.5 h-2.5 rounded-full ${t.online?"bg-green-300":"bg-gray-300"}`}),n.jsx("span",{className:"font-light leading-none truncate text-slate-800",children:g.startCase(t.name)??""}),f!=null&&f.hasSlug?n.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 ${s?"border-gray-300":"border-gray-200"}`,children:[m,t.dynamic&&n.jsx("span",{className:"text-xs font-light leading-none text-slate-500",children:g.endsWith(m,"/")?`${f==null?void 0:f.dynamicSlug}`:`/${f==null?void 0:f.dynamicSlug}`})]}):n.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 ${s?"border-gray-300":"border-gray-200"}`,children:f==null?void 0:f.name})]}),n.jsx("div",{className:"flex items-center space-x-4",children:!w&&n.jsxs(c.DropdownMenu,{children:[n.jsx(c.DropdownMenuTrigger,{asChild:!0,onClick:E=>E.stopPropagation(),children:n.jsx(I.MoreHorizontal,{className:"h-4 w-4 hover:stroke-[3]"})}),n.jsxs(c.DropdownMenuContent,{align:"end",className:"text-sm",children:[d(ce.EDIT_PAGE)&&n.jsxs(c.DropdownMenuItem,{className:"flex items-center gap-2 cursor-pointer",onClick:E=>{E.stopPropagation(),o({...t,global:!(f!=null&&f.hasSlug)})},children:[n.jsx(I.Pencil,{className:"size-3"}),"Edit"]}),(t==null?void 0:t.online)&&d(ce.UNPUBLISH_PAGE)&&n.jsxs(c.DropdownMenuItem,{className:"flex items-center gap-2 cursor-pointer",onClick:E=>{E.stopPropagation(),a(t)},children:[n.jsx(I.Power,{className:"size-3"}),q.UNPUBLISH]}),d(ce.DELETE_PAGE)&&n.jsxs(c.DropdownMenuItem,{className:"flex items-center gap-2 cursor-pointer",onClick:E=>{E.stopPropagation(),i(t)},children:[n.jsx(I.Trash,{className:"size-3"}),q.DELETE]}),d(ce.SAVE_AS_TEMPLATE)&&n.jsxs(c.DropdownMenuItem,{className:"flex items-center gap-2 cursor-pointer",onClick:E=>{E.stopPropagation(),l(t)},children:[n.jsx(I.SquareLibrary,{className:"size-3"}),q.SAVE_AS_TEMPLATE]})]})]})})]})},Ai=({close:e})=>{const[,t]=S.useState([]),[s,r]=S.useState(""),[a,i]=S.useState(null),[o,l]=S.useState(null),[u,d]=S.useState(null),{data:f,isFetching:m}=Gt(),[w,E]=S.useState(""),{hasPermission:y}=ae.usePermissions(),[j,b]=S.useState(null),[D,A]=je(),T=D.get("page"),{data:v}=Ee(),P=S.useCallback(N=>{var G;return(G=g.find(v,{key:N}))==null?void 0:G.hasSlug},[v]);S.useEffect(()=>{if(!g.isEmpty(w))return;const N=sessionStorage.getItem("pageTypeFilter")||"all";!g.isEmpty(v)&&N&&(g.find(v,{key:N})?E(N):E("all"))},[v,w]);const F=N=>{E(N),sessionStorage.setItem("pageTypeFilter",N)},C=S.useCallback(N=>{const H=new URLSearchParams(window.location.search).get("lang"),Y=new URLSearchParams({page:N});H&&Y.set("lang",H),window.history.pushState({},"",`?${Y.toString()}`),A(Y),window.dispatchEvent(new PopStateEvent("popstate")),e()},[A,e]);S.useEffect(()=>{if(T&&!m){const N=g.find(f,{id:T});N&&(N!=null&&N.pageType)?t(G=>[...G,N==null?void 0:N.pageType]):(window.history.replaceState(null,"","/"),A(new URLSearchParams({})),window.dispatchEvent(new PopStateEvent("popstate")))}},[f,T,m,A]);const k=S.useMemo(()=>{const N=g.filter(f,p=>g.isEmpty(s)?!0:g.includes(g.toLower(p==null?void 0:p.name),g.toLower(s))||g.includes(g.toLower(p==null?void 0:p.slug),g.toLower(s)));if(w!=="all")return g.filter(N,{pageType:w});const G=new Map;N.forEach(p=>{G.set(p.id,{...p,children:[]})});const H=[],Y=[];G.forEach(p=>{if(p.parent){const V=G.get(p.parent);V?V.children.push(p):H.push(p)}else Y.push(p)}),H.sort((p,V)=>p.name.localeCompare(V.name)),H.forEach(p=>{p.children.sort((V,be)=>V.name.localeCompare(be.name))});const Le=g.filter(Y,p=>!P(p.pageType)),me=g.filter(Y,p=>P(p.pageType)).sort((p,V)=>p.name.localeCompare(V.name));return g.compact([...me,...Le,...H])},[f,P,s,w]);return n.jsxs("div",{className:"flex flex-col justify-between h-full",children:[n.jsxs("div",{className:"flex flex-col h-full space-y-6",children:[n.jsxs("div",{className:"relative flex item-center gap-x-4",children:[n.jsx(I.Search,{strokeWidth:2.5,className:"absolute left-3 top-2.5 h-4 w-4 text-gray-400"}),n.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:s,onChange:N=>r(N.target.value)}),!g.isEmpty(w)&&n.jsxs(c.Select,{value:w,onValueChange:F,children:[n.jsx(c.SelectTrigger,{className:`${w==="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:n.jsx(c.SelectValue,{placeholder:"Select page type"})}),n.jsx(c.SelectContent,{align:"end",children:g.map(g.concat([{key:"all",name:"All"}],v),N=>n.jsx(c.SelectItem,{value:g.get(N,"key"),children:g.get(N,"name")}))})]})]}),m?n.jsx("div",{className:"space-y-2",children:g.map([...Array(5).keys()],N=>n.jsx("div",{className:"w-full bg-gray-200 rounded h-9 animate-pulse"},N))}):g.isEmpty(k)?n.jsxs("div",{className:"h-[70vh] flex flex-col gap-y-1 items-center justify-center text-slate-500 text-sm font-medium",children:[n.jsx(I.File,{className:"h-6 w-6 stroke-[1]"}),"Empty List!",n.jsx("span",{className:"font-light",children:"Add new page to start"})]}):n.jsx("div",{className:"text-sm text-slate-700 space-y-2 h-[70vh] overflow-y-auto",children:g.map(k,N=>g.isEmpty(N==null?void 0:N.children)?n.jsx(rs,{changeActivePage:C,setUnpublishPage:l,setDeletePage:i,setAddEditPage:d,active:T===N.id,page:N,setSaveAsTemp:b},N.id):n.jsxs("div",{className:"border-0",children:[n.jsx(rs,{changeActivePage:C,setUnpublishPage:l,setDeletePage:i,setAddEditPage:d,active:T===N.id,page:N,setSaveAsTemp:b}),n.jsx("div",{className:"pt-2 pl-6 bg-white",children:g.map(g.get(N,"children",[]),G=>{const H=T===g.get(G,"id");return n.jsx(rs,{parentSlug:N.slug,changeActivePage:C,setUnpublishPage:l,setDeletePage:i,setAddEditPage:d,active:H,page:G,setSaveAsTemp:b},G.id)})})]},N.key))})]}),y(ce.ADD_PAGE)&&n.jsxs(c.Button,{className:"flex text-sm gap-x-2",onClick:()=>{d({slug:"",name:"",pageType:w==="all"?"page":w})},children:[n.jsx(I.Plus,{className:"w-4 h-4"})," Add New"]}),u&&n.jsx(bi,{editPage:C,addEditPage:u,setAddEditPage:d}),a&&n.jsx(On,{page:a,onClose:()=>i(null)}),o&&n.jsx(js,{page:o,onClose:()=>l(null)}),j&&n.jsx(Ni,{page:j,onClose:()=>b(null)})]})},Ti=()=>{const e=Ce("logo",null);return e?n.jsx("div",{className:"w-full max-h-9 overflow-hidden pr-2",children:S.createElement(e,{})}):null},Ci=()=>{const[e]=je(),t=e.get("page"),{data:s,isFetching:r}=Se(),[a,i]=S.useState(!1),o=!!t&&!g.isEmpty(s),l=!t||!r&&g.isEmpty(s)||a;return n.jsxs(n.Fragment,{children:[n.jsxs(c.Button,{variant:"secondary",className:"flex items-center w-full space-x-2 py-1",onClick:()=>i(!0),children:[n.jsx("div",{children:n.jsx(I.Logs,{className:"h-4 w-4"})}),n.jsxs("span",{className:"truncate leading-tight flex items-center max-w-[200px]",children:[n.jsx("span",{className:"text-slate-600 pr-1 font-light",children:"Editing:"}),r?n.jsx(I.Loader,{className:"h-4 w-4 animate-spin text-slate-400 ml-2"}):g.startCase(g.get(s,"name"))??""]})]},"template-viewer"),n.jsx(c.Sheet,{open:l,onOpenChange:u=>!u&&o&&i(!1),children:n.jsxs(c.SheetContent,{side:"left",className:`!max-w-screen-md z-50 border-border w-full ${o?"":"sheet-hide-close-btn"}`,children:[n.jsx(c.SheetHeader,{className:"mb-3",children:n.jsxs(c.SheetTitle,{className:"text-sm flex items-center gap-2 font-semibold",children:[n.jsx("div",{className:"p-2 rounded-md bg-primary text-primary-foreground",children:n.jsx(I.File,{className:"w-6 h-6"})}),n.jsxs("div",{className:"flex flex-col",children:[n.jsx("span",{className:"text-sm font-semibold",children:"Pages"}),n.jsx("span",{className:"text-xs text-muted-foreground",children:"Manage your site structure"})]})]})}),n.jsx("div",{className:"h-[calc(100vh-100px)] overflow-y-auto",children:n.jsx(Ai,{close:()=>i(!1)})})]})})]})},Pi=()=>{const{fallbackLang:e,languages:t,selectedLang:s,setSelectedLang:r}=ae.useLanguages(),a=g.isEmpty(s)?e:s,[,i]=je();S.useEffect(()=>{const y=new URLSearchParams(window.location.search),j=y.get("lang");j&&(t.includes(j)?r(j):(y.delete("lang"),i(y),r("")))},[t,i,r]);const[o,l]=S.useState(null),{data:u}=Se(),{data:d}=ht(),{data:f,isFetching:m}=ft(),w=S.useMemo(()=>{const y=g.compact(g.map(g.get(d,"languages"),j=>{const b=g.find(f,{lang:j});return{key:j,value:g.get(Te,j,j),isLangPageAdded:!!b}})).filter(Boolean);return[{key:e,value:g.get(Te,e),isLangPageAdded:!0},...y]},[e,f,d]),E=y=>{r(y);const j=new URLSearchParams(window.location.search);y===e?j.delete("lang"):j.set("lang",y);const b=j.toString(),D=`${window.location.pathname}${b?`?${b}`:""}`;window.history.pushState({},"",D),i(j),window.dispatchEvent(new PopStateEvent("popstate"))};return g.isEmpty(t)||m?null:n.jsxs(n.Fragment,{children:[n.jsxs(c.DropdownMenu,{children:[n.jsx(c.DropdownMenuTrigger,{asChild:!0,className:"focus:outline-none",children:n.jsxs(c.Button,{variant:"ghost",size:"sm",className:"gap-2",children:[n.jsx(I.Languages,{className:"w-4 h-4"}),g.get(Te,a,a),n.jsx(I.ChevronDown,{className:"w-4 h-4"})]})}),n.jsxs(c.DropdownMenuContent,{className:"border-border space-y-1",children:[g.map(w.filter(y=>y.isLangPageAdded),y=>n.jsxs(c.DropdownMenuItem,{className:ae.mergeClasses("flex cursor-pointer items-center justify-between text-xs font-medium text-gray-800",y.key===a&&"!bg-gray-200 text-gray-700"),onClick:()=>E(y.key),children:[n.jsx("div",{className:"text-slate-600",children:y.value}),y.key===e&&n.jsxs("small",{className:"text-[9px] flex items-center gap-x-1 text-orange-500 leading-none",children:[n.jsx(I.Star,{fill:"orange",className:"w-2 h-2"}),"Primary"]})]},y.value)),!g.isEmpty(w.filter(y=>!y.isLangPageAdded))&&n.jsxs(n.Fragment,{children:[n.jsx(c.Separator,{}),n.jsxs(c.Button,{size:"sm",variant:"ghost",onClick:()=>{l({name:u==null?void 0:u.name,pageType:u==null?void 0:u.pageType,lang:"",slug:"",edit:!1})},className:"hover:bg-slate-300 duration-200 font-normal text-xs hover:text-slate-800",children:[n.jsx(I.Plus,{className:"w-3 h-3 mr-1"})," Add Langauge"]})]})]})]}),o&&n.jsx(Rn,{languages:t,langProps:o,onClose:()=>l(null)})]})};function Ii(){return n.jsxs("div",{className:"flex relative z-10 items-center justify-end gap-1",children:[n.jsx(Ti,{}),n.jsx(Ci,{}),n.jsx(Pi,{})]})}function Fn({children:e,content:t}){return n.jsx(c.TooltipProvider,{children:n.jsxs(c.Tooltip,{children:[n.jsx(c.TooltipTrigger,{asChild:!0,children:e}),n.jsx(c.TooltipContent,{side:"bottom",sideOffset:10,children:n.jsx("p",{children:t})})]})})}function _i(e){const t=ee(),s=Z();return U.useQuery({queryKey:["revisions",e],queryFn:async()=>await s(t,{action:L.GET_PAGE_REVISIONS,data:{pageId:e}}),enabled:!!e,gcTime:0,staleTime:0})}const Li=()=>{const e=ee(),t=Z(),s=U.useQueryClient();return U.useMutation({mutationFn:async r=>await t(e,{action:L.DELETE_PAGE_REVISION,data:{revisionId:r}}),onSuccess:()=>{s.invalidateQueries({queryKey:["revisions"]})}})},Di=()=>{const e=ee(),t=Z(),s=U.useQueryClient();return U.useMutation({mutationFn:async({revisionId:r,discardCurrent:a})=>await t(e,{action:L.RESTORE_PAGE_REVISION,data:{revisionId:r,discardCurrent:a}}),onSuccess:()=>{s.invalidateQueries({queryKey:["revisions"]})}})};function ki(){const{data:e}=Se(),{saveState:t}=ae.useSavePage(),[s]=vs();return e?n.jsx("div",{className:"flex items-start gap-3 rounded-md border p-2 hover:bg-accent/50 bg-primary/5 mb-4",children:n.jsxs("div",{className:"flex-1 space-y-1",children:[n.jsx("div",{className:"flex items-center justify-between",children:n.jsx("p",{className:"text-sm flex items-center gap-1 font-medium leading-none",children:n.jsx("span",{className:"font-bold",children:"Currently editing"})})}),n.jsx("div",{className:"flex items-center text-xs text-muted-foreground",children:!g.isEmpty(s.lastSaved)&&n.jsxs("span",{children:["Last updated"," ",kt.formatDistanceToNow(new Date(s.lastSaved),{addSuffix:!0})]})}),n.jsxs("div",{className:"flex items-center gap-2 pt-0.5",children:[n.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:[n.jsx(I.Edit,{className:"h-3 w-3"}),n.jsx("span",{children:"Draft"})]}),t==="UNSAVED"?n.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:[n.jsx(I.Save,{className:"h-3 w-3"}),n.jsx("span",{children:" Unsaved changes"})]}):null]})]})}):null}function Gi(){const[e,t]=le.useState(!1),[s,r]=le.useState(null),[a,i]=le.useState(!1),[o,l]=le.useState(!1),{data:u}=Se(),{data:d,isFetching:f,error:m,refetch:w}=_i(u==null?void 0:u.id),{mutate:E,isPending:y}=Li(),{mutate:j,isPending:b}=Di(),D=U.useQueryClient(),A=F=>{s&&j({revisionId:s.uid,discardCurrent:F},{onSuccess:()=>{i(!1),r(null),D.invalidateQueries({queryKey:[L.GET_PAGE]})}})},T=F=>{r(F),i(!0)},v=F=>{r(F),l(!0)},P=()=>{s&&E(s.uid,{onSuccess:()=>{l(!1),r(null)}})};return S.useEffect(()=>{e&&w()},[e,w]),n.jsxs(n.Fragment,{children:[n.jsx(c.TooltipProvider,{children:n.jsxs(c.Tooltip,{children:[n.jsxs(c.Sheet,{open:e,onOpenChange:t,children:[n.jsx(c.SheetTrigger,{asChild:!0,children:n.jsx(c.TooltipTrigger,{asChild:!0,children:n.jsxs("span",{className:"flex items-center gap-2",children:[n.jsxs(c.Button,{variant:"ghost",size:"icon",className:"h-8 w-8",children:[n.jsx(I.History,{className:"h-4 w-4"}),n.jsx("span",{className:"sr-only",children:"View revision history"})]}),n.jsx("div",{className:"w-px h-4 bg-gray-200 dark:bg-gray-700"})]})})}),n.jsxs(c.SheetContent,{className:"sm:max-w-md p-4",children:[n.jsxs(c.SheetHeader,{className:"pb-2",children:[n.jsxs(c.SheetTitle,{className:"flex items-center gap-2",children:[n.jsx(I.History,{className:"h-5 w-5"}),"Revision History"]}),(u==null?void 0:u.createdAt)&&n.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:["Page created on"," ",kt.format(new Date(u.createdAt),"MMM d, yyyy 'at' h:mm a")]})]}),n.jsx(c.ScrollArea,{className:"h-[calc(100vh-6rem)] pr-2",children:f?n.jsx(Mi,{}):m?n.jsx("div",{className:"p-4 text-center text-sm text-muted-foreground",children:"Failed to load revisions. Please try again."}):n.jsxs("div",{className:"mt-2 space-y-2",children:[n.jsx(ki,{}),d==null?void 0:d.map(F=>n.jsx(Ui,{revision:F,isLatest:F.uid==="current",onRestore:()=>T(F),onDelete:()=>v(F)},F.uid))]})})]})]}),n.jsx(c.TooltipContent,{side:"bottom",children:n.jsx("p",{children:"Revision history"})})]})}),n.jsx(Ri,{open:a,onOpenChange:i,revision:s,onRestore:A,isRestoring:b}),n.jsx(Bi,{open:o,onOpenChange:l,revision:s,onDelete:P,isDeleting:y})]})}function Mi(){return n.jsx("div",{className:"space-y-2 mt-2",children:Array.from({length:5}).map((e,t)=>n.jsxs("div",{className:"flex items-start gap-3 rounded-md border p-2",children:[n.jsxs("div",{className:"flex-1 space-y-1",children:[n.jsx(c.Skeleton,{className:"h-4 w-3/4"}),n.jsx(c.Skeleton,{className:"h-3 w-1/2"}),n.jsx(c.Skeleton,{className:"h-5 w-20 mt-1"})]}),n.jsx(c.Skeleton,{className:"h-8 w-8 rounded-full"})]},t))})}function Ui({revision:e,isLatest:t,onRestore:s,onDelete:r}){const{data:a}=dt(e.currentEditor),i=(a==null?void 0:a.name)||"Unknown";return n.jsxs("div",{className:"flex items-start gap-3 rounded-md border p-2 hover:bg-accent/50",children:[n.jsxs("div",{className:"flex-1 space-y-1",children:[n.jsx("div",{className:"flex items-center justify-between",children:n.jsxs("p",{className:"text-sm flex items-center gap-1 font-medium leading-none",children:[e.type==="published"?"Published":"Draft"," by ",n.jsx("span",{className:"font-bold",children:i}),t&&n.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:[n.jsxs("span",{className:"mr-1 relative flex h-2 w-2",children:[n.jsx("span",{className:"animate-ping absolute inline-flex h-full w-full rounded-full bg-green-400 opacity-75"}),n.jsx("span",{className:"relative inline-flex rounded-full h-2 w-2 bg-green-500"})]}),"Live"]})]})}),n.jsx("div",{className:"flex items-center text-xs text-muted-foreground",children:n.jsx("span",{children:kt.format(e.createdAt,"MMM d, h:mm a")})}),n.jsx("div",{className:"flex items-center gap-2 pt-0.5",children:e.type==="published"?n.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:[n.jsx(I.ArrowUpRight,{className:"h-3 w-3"}),n.jsx("span",{children:"Published"})]}):n.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:[n.jsx(I.Clock,{className:"h-3 w-3"}),n.jsx("span",{children:"Draft"})]})})]}),n.jsx(we,{permissions:[ce.RESTORE_REVISION,ce.DELETE_REVISION],children:n.jsx(Oi,{revision:e,onRestore:s,onDelete:r})})]})}function Oi({revision:e,onRestore:t,onDelete:s}){return n.jsxs(c.DropdownMenu,{children:[n.jsx(c.DropdownMenuTrigger,{asChild:!0,children:n.jsxs(c.Button,{variant:"ghost",size:"icon",className:"h-7 w-7 -mr-1",children:[n.jsx(I.MoreHorizontal,{className:"h-4 w-4"}),n.jsx("span",{className:"sr-only",children:"More options"})]})}),n.jsxs(c.DropdownMenuContent,{align:"end",className:"text-xs",children:[n.jsx(we,{permission:ce.RESTORE_REVISION,children:n.jsxs(c.DropdownMenuItem,{onClick:t,className:"cursor-pointer",children:[n.jsx(I.Undo2,{className:"mr-2 h-4 w-4"}),n.jsx("span",{children:"Restore this version"})]})}),n.jsx(we,{permission:ce.DELETE_REVISION,children:e.uid!=="current"&&n.jsxs(n.Fragment,{children:[n.jsx(c.DropdownMenuSeparator,{}),n.jsxs(c.DropdownMenuItem,{onClick:s,className:"cursor-pointer text-destructive",children:[n.jsx(I.Trash,{className:"mr-2 h-4 w-4"}),n.jsx("span",{children:"Delete this version"})]})]})})]})]})}function Ri({open:e,onOpenChange:t,revision:s,onRestore:r,isRestoring:a}){const{data:i}=dt((s==null?void 0:s.currentEditor)||""),o=(i==null?void 0:i.name)||"Unknown";return s?n.jsx(c.Dialog,{open:e,onOpenChange:l=>{a||t(l)},children:n.jsxs(c.DialogContent,{className:"sm:max-w-md",children:[n.jsxs(c.DialogHeader,{children:[n.jsx(c.DialogTitle,{children:"Restore Revision"}),n.jsxs(c.DialogDescription,{children:["You are about to restore to revision ",s.uid.substring(0,8)," ","from ",kt.format(s.createdAt,"MMM d, yyyy 'at' h:mm a")," by"," ",o]})]}),n.jsx("div",{className:"py-2",children:n.jsx("p",{className:"text-sm text-muted-foreground",children:"How would you like to handle your current edits?"})}),n.jsxs(c.DialogFooter,{className:"flex flex-col sm:flex-row gap-2",children:[n.jsx(c.Button,{variant:"outline",className:"sm:flex-1",onClick:()=>r(!1),disabled:a,children:a?n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"mr-2 h-4 w-4 animate-spin rounded-full border-2 border-current border-t-transparent"}),"Saving as draft..."]}):n.jsxs(n.Fragment,{children:[n.jsx(I.CloudOff,{className:"mr-2 h-4 w-4"}),"Save as draft"]})}),n.jsx(c.Button,{variant:"default",className:"sm:flex-1",onClick:()=>r(!0),disabled:a,children:a?n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"mr-2 h-4 w-4 animate-spin rounded-full border-2 border-current border-t-transparent"}),"Discarding current..."]}):n.jsxs(n.Fragment,{children:[n.jsx(I.Undo2,{className:"mr-2 h-4 w-4"}),"Discard current"]})})]})]})}):null}function Bi({open:e,onOpenChange:t,revision:s,onDelete:r,isDeleting:a}){const{data:i}=dt((s==null?void 0:s.currentEditor)||""),o=(i==null?void 0:i.name)||"Unknown";return s?n.jsx(c.Dialog,{open:e,onOpenChange:l=>{a||t(l)},children:n.jsxs(c.DialogContent,{className:"sm:max-w-md",children:[n.jsxs(c.DialogHeader,{children:[n.jsx(c.DialogTitle,{children:"Delete Revision"}),n.jsxs(c.DialogDescription,{children:["You are about to delete revision ",s.uid.substring(0,8)," from"," ",kt.format(s.createdAt,"MMM d, yyyy 'at' h:mm a")," by"," ",o]})]}),n.jsx("div",{className:"py-2",children:n.jsx("p",{className:"text-sm text-muted-foreground",children:"This action cannot be undone. Are you sure you want to proceed?"})}),n.jsxs(c.DialogFooter,{className:"flex flex-col sm:flex-row gap-2",children:[n.jsx(c.Button,{variant:"outline",className:"sm:flex-1",onClick:()=>t(!1),disabled:a,children:"Cancel"}),n.jsx(c.Button,{variant:"destructive",className:"sm:flex-1",onClick:r,disabled:a,children:a?n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"mr-2 h-4 w-4 animate-spin rounded-full border-2 border-current border-t-transparent"}),"Deleting..."]}):n.jsxs(n.Fragment,{children:[n.jsx(I.Trash,{className:"mr-2 h-4 w-4"}),"Delete Revision"]})})]})]})}):null}const Fi=()=>{const e=ee(),t=Z();return U.useQuery({queryKey:[L.GET_CHANGES],queryFn:async()=>t(e,{action:L.GET_CHANGES})})},qi=({currentEditor:e})=>{const{data:t}=dt(e);return t==null?void 0:t.name};function Hi({showModal:e=!1,onClose:t=()=>console.log("Cancelled")}){const[s,r]=S.useState([]),{data:a,isFetching:i}=Fi(),{data:o}=Ee(),l=S.useCallback(v=>{var P;return(P=g.find(o,{key:v}))==null?void 0:P.hasSlug},[o]),u=S.useMemo(()=>g.filter(o,v=>!l(v.key)).map(v=>v.key),[l,o]),d=S.useMemo(()=>g.filter(a,v=>!u.includes(v.pageType)),[a,u]),f=S.useMemo(()=>g.filter(a,v=>u.includes(v.pageType)),[a,u]),m=S.useMemo(()=>g.find(a,{pageType:"theme",id:"THEME"}),[a]),{mutate:w,isPending:E}=bs();S.useEffect(()=>{const v=g.map(g.filter(a,{online:!0}),"id");m&&v.push(m==null?void 0:m.id),r(v)},[a,m]);const y=s.length===(a==null?void 0:a.length),j=v=>{r(P=>g.includes(P,v)?g.filter(P,F=>F!==v):g.concat(P,v))},b=()=>{r(y?[]:g.map(a,"id"))},D=()=>{w({ids:g.uniq(s)},{onSuccess:()=>{t(),Qt("CENTER_CENTER")}})},A=v=>{if(v==="theme")return"Theme";const P=g.find(o,{key:v});return P?P==null?void 0:P.name:v},T=S.useMemo(()=>{const v=[{label:"Updated",top:"pt-2"},...g.orderBy(g.filter(d,{online:!0}),"pageType"),...g.orderBy(g.filter(f,{online:!0}),"pageType")].filter(C=>C.pageType!=="theme"),P=[{label:"Offline",top:"pt-6"},...g.orderBy(g.filter(d,{online:!1}),"pageType"),...g.orderBy(g.filter(f,{online:!1}),"pageType")],F=m?[{label:"Theme",top:"pt-6"},m]:[];return[...v,...F,...P]},[d,f,m]);return n.jsx(c.Dialog,{open:e,onOpenChange:E?()=>{}:t,children:n.jsxs(c.DialogContent,{className:"max-w-4xl max-h-[80%] flex flex-col",children:[n.jsxs(c.DialogHeader,{children:[n.jsx(c.DialogTitle,{children:"Publish changes"}),n.jsx(c.DialogDescription,{className:"text-xs",children:"Select the pages you want to publish. Click publish when you're done."})]}),n.jsx("div",{className:"relative h-full max-h-full -mx-4 overflow-y-auto no-scrollbar",children:i?n.jsxs("div",{className:"px-1 space-y-2",children:[n.jsx("div",{className:"w-full h-6 mt-2 bg-gray-200 rounded animate-pulse"}),n.jsx("div",{className:"w-full h-6 bg-gray-200 rounded animate-pulse"}),n.jsx("div",{className:"w-full h-6 bg-gray-200 rounded animate-pulse"}),n.jsx("div",{className:"w-full h-6 bg-gray-200 rounded animate-pulse"})]}):n.jsxs("table",{className:"w-full text-xs text-left text-gray-500 rtl:text-right dark:text-gray-400",children:[n.jsx("thead",{className:"text-gray-700 border-b bg-gray-50 dark:bg-gray-700 dark:text-gray-400",children:n.jsxs("tr",{children:[n.jsxs("th",{scope:"col",className:"px-6 py-3 flex items-center gap-x-2 w-[1 50px]",children:[n.jsx("input",{checked:y,onClick:v=>{v.stopPropagation(),b()},type:"checkbox",className:"mt-1 rounded cursor-pointer focus:outline-none focus:ring-0"}),"Name"]}),n.jsx("th",{scope:"col",className:"px-2 py-3 w-[100px]",children:"Language"}),n.jsx("th",{scope:"col",className:"px-2 py-3 w-[100px]",children:"Type"}),n.jsx("th",{scope:"col",className:"px-4 py-3 w-[150px] text-right",children:"Status"})]})}),n.jsx("tbody",{children:g.map(T,v=>v.label?n.jsx("tr",{children:n.jsxs("td",{colSpan:4,className:`px-6 py-2 text-xs font-medium text-gray-800 relative ${v.top}`,children:[n.jsx("div",{className:"absolute inset-0 flex items-center left-6",children:n.jsx("div",{className:"w-full order-gray-300"})}),n.jsx("div",{className:"relative flex justify-start",children:n.jsx("span",{className:"pr-2 bg-gray-50",children:v.label})})]})},"separator"):n.jsxs("tr",{className:"border-b group hover:bg-gray-50 last:border-b-0",children:[n.jsxs("td",{scope:"row",className:"flex items-center px-6 py-2 text-gray-900 whitespace-nowrap dark:text-white gap-x-1",children:[n.jsx("input",{checked:g.includes(s,v==null?void 0:v.id),onClick:P=>{P.stopPropagation(),j(v==null?void 0:v.id)},type:"checkbox",className:"rounded cursor-pointer focus:outline-none focus:ring-0"})," ",l(v.pageType)?n.jsx(I.File,{className:"w-4 h-4"}):n.jsx(I.GlobeIcon,{className:"w-4 h-4"}),v.name,v.slug&&n.jsxs("span",{className:"text-xs text-gray-500",children:["(",v.slug,")"]}),v.currentEditor&&n.jsx("div",{className:"flex items-center gap-x-1",children:n.jsxs("span",{className:"flex text-xs font-bold text-gray-500",children:[" ","-"," ",n.jsx(qi,{currentEditor:v.currentEditor})," ","is editing"]})})]}),n.jsx("td",{className:"px-2",children:v.lang}),n.jsx("td",{className:"px-2",children:A(v==null?void 0:v.pageType)}),n.jsx("td",{className:"px-4 text-right",children:g.first(v.changes)||""})]},v==null?void 0:v.id))})]})}),n.jsxs(c.DialogFooter,{className:"mt-10",children:[n.jsx(c.Button,{disabled:E,variant:"outline",onClick:t,children:"Cancel"}),n.jsx(c.Button,{disabled:E||i||g.isEmpty(a),onClick:D,children:E?"Publishing...":"Publish"})]})]})})}const Vi=()=>{const e=Z(),t=ee();return U.useQuery({queryKey:[L.GET_WEBSITE_DATA],staleTime:1e3*60*5,queryFn:async()=>e(t,{action:L.GET_WEBSITE_DATA,data:{draft:!0}})})};function $i({onClose:e}){const{data:t,isFetching:s}=Vi(),{mutateAsync:r,isPending:a}=Wa(),i=Ce("settingComponent",null),o=g.debounce(async l=>(await r({data:l}),!0),300);return i?n.jsx(c.Dialog,{open:!0,onOpenChange:e,children:n.jsxs(c.DialogContent,{className:"w-full",children:[n.jsx(c.DialogHeader,{children:n.jsx(c.DialogTitle,{children:"Website Settings"})}),s?n.jsxs("div",{className:"w-full space-y-3 py-4",children:[n.jsx("div",{className:"w-full h-8 rounded bg-gray-300 animate-pulse"}),n.jsx("div",{className:"w-full h-8 rounded bg-gray-300 animate-pulse"}),n.jsx("div",{className:"w-full h-8 rounded bg-gray-300 animate-pulse"}),n.jsx("div",{className:"w-full h-8 rounded bg-gray-300 animate-pulse"}),n.jsx("div",{className:"w-full h-8 rounded bg-gray-300 animate-pulse"}),n.jsx("div",{className:"w-full h-8 rounded bg-gray-300 animate-pulse"})]}):n.jsx("div",{children:S.createElement(i,{data:t||{},onSave:a?()=>{}:o,cancel:a?()=>{}:e})})]})}):null}const Ki=()=>{const{selectedLang:e}=ae.useLanguages(),t=Ce("getPreviewUrl",async f=>f),[s,r]=S.useState(""),{data:a,isFetching:i}=Se(),{data:o}=ft(),{data:l}=Ee(),u=S.useMemo(()=>{var f;return(f=o==null?void 0:o.find(m=>(m==null?void 0:m.lang)===e))==null?void 0:f.slug},[e,o]),d=S.useCallback(f=>{var m;return(m=g.find(l,{key:f}))==null?void 0:m.hasSlug},[l]);return S.useEffect(()=>{(async()=>{if(u&&typeof t=="function"){const f=await t(u||"");r(f)}else r("")})()},[t,u]),!s||!d(a==null?void 0:a.pageType)||i?null:n.jsx(n.Fragment,{children:n.jsx("a",{href:s,target:"_blank",rel:"noopener noreferrer",children:n.jsxs(c.Button,{variant:"ghost",size:"sm",className:"gap-2",children:[n.jsx(I.Eye,{className:"w-4 h-4"})," ",q.PREVIEW]})})})},zi=()=>{const[e,t]=ae.useRightPanel();return n.jsxs(n.Fragment,{children:[n.jsx(Fn,{content:q.THEME,children:n.jsx(c.Button,{variant:e==="theme"?"outline":"ghost",size:"icon",className:"gap-2",onClick:()=>t(e==="theme"?"block":"theme"),children:n.jsx(I.Palette,{className:"w-4 h-4"})})}),n.jsx("div",{className:"w-px h-4 bg-gray-200 dark:bg-gray-700"})]})},Wi=()=>{const[e,t]=S.useState(!1),{isLocked:s}=Mt(),{savePage:r,saveState:a}=ae.useSavePage();S.useEffect(()=>{const f=m=>{a==="UNSAVED"&&(m.preventDefault(),m.returnValue=!1)};return a==="UNSAVED"&&window.addEventListener("beforeunload",f),()=>{window.removeEventListener("beforeunload",f)}},[a]);const i=S.useCallback(async()=>{t(!0),await r(!1)},[r]);S.useEffect(()=>{a==="SAVED"&&t(!1)},[a]);const o=S.useMemo(()=>{if(a==="SAVED"||a==="UNSAVED")return a;if(a==="SAVING")return e?a:"SAVED"},[e,a]),{buttonIcon:l,buttonClass:u,tooltipContent:d}=S.useMemo(()=>{switch(o){case"UNSAVED":return{tooltipContent:q.SAVEDRAFT,buttonIcon:n.jsx(I.Save,{className:"w-4 h-4"}),buttonClass:"flex items-center gap-x-1 leading-tight"};case"SAVING":return{tooltipContent:q.SAVING,buttonIcon:n.jsx(I.Loader,{className:"w-4 h-4 animate-spin"}),buttonClass:"flex items-center gap-x-1 leading-tight"};case"SAVED":return{tooltipContent:q.SAVED,buttonIcon:n.jsx(I.CheckCircle,{className:"w-4 h-4"}),buttonClass:"text-green-500 flex items-center gap-x-1 leading-tight"}}},[o]);return s?null:n.jsxs(c.Button,{size:"sm",variant:"ghost",onClick:i,className:u,children:[l," ",d]})},Qi=()=>{const[e,t]=S.useState(!1),[s,r]=S.useState(!1),[a,i]=S.useState(null),{data:o}=Se(),{mutate:l,isPending:u}=bs(),[d]=ae.useBlocksStore(),{buttonText:f,buttonClassName:m,isPublished:w}=S.useMemo(()=>{const y=o&&(o==null?void 0:o.online);return{buttonClassName:y?"hover:bg-green-600 bg-green-500":"",isPublished:y,buttonText:y?q.PUBLISHED:q.PUBLISH}},[o]),E=async()=>{var j,b;const y=((b=(j=d==null?void 0:d.filter(D=>(D==null?void 0:D._type)==="GlobalBlock"))==null?void 0:j.map(D=>D==null?void 0:D.globalBlock))==null?void 0:b.filter(D=>typeof D=="string"))||[];l({ids:[o==null?void 0:o.id,...y]},{onSuccess:()=>Qt("TOP_RIGHT")})};return n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"flex",children:[n.jsxs(c.Button,{size:"sm",onClick:E,disabled:u||!(o!=null&&o.id),className:`relative overflow-hidden transition-all duration-300 ease-in-out text-white flex items-center gap-1 rounded-r-none ${m}`,onMouseEnter:()=>r(!0),onMouseLeave:()=>r(!1),children:[n.jsx("span",{className:`flex items-center transition-transform duration-300 ease-in-out ${s?"-translate-y-10":""}`,children:w?n.jsx(I.Send,{className:"w-4 h-4"}):n.jsx(I.Rocket,{className:"w-4 h-4"})}),n.jsx("span",{className:`absolute inset-0 flex items-center left-3 transition-transform duration-300 ease-in-out ${s?"":"translate-y-10"}`,children:w?n.jsx(I.Rocket,{className:"w-4 h-4"}):n.jsx(I.Send,{className:"w-4 h-4"})}),n.jsx("span",{children:f})]}),n.jsxs(c.DropdownMenu,{children:[n.jsx(c.DropdownMenuTrigger,{asChild:!0,children:n.jsx(c.Button,{size:"sm",disabled:u||!(o!=null&&o.id),className:`px-2 text-white border-l border-white/50 rounded-l-none ${m}`,children:n.jsx(I.ChevronDown,{className:"w-4 h-4"})})}),n.jsxs(c.DropdownMenuContent,{align:"end",className:"w-36",children:[!w&&n.jsxs(c.DropdownMenuItem,{disabled:u,className:"text-xs cursor-pointer",onClick:()=>l({ids:[o==null?void 0:o.id]},{onSuccess:()=>Qt("TOP_RIGHT")}),children:[q.PUBLISH," page"]}),n.jsxs(c.DropdownMenuItem,{onClick:()=>t(!0),className:"text-xs cursor-pointer",children:[q.OPEN," publish menu"]}),w&&n.jsxs(c.DropdownMenuItem,{onClick:()=>i(o),className:"text-xs cursor-pointer",children:[q.UNPUBLISH," page"]})]})]})]}),n.jsx(Hi,{showModal:e,onClose:()=>t(!1)}),a&&n.jsx(js,{page:a,onClose:()=>i(null)})]})},Yi=()=>{const e=Ce("settingComponent",null),[t,s]=S.useState(!1);return e?n.jsxs(n.Fragment,{children:[n.jsx(Fn,{content:q.WEBSITEDATA,children:n.jsx(c.Button,{variant:"ghost",size:"icon",className:"gap-2",onClick:()=>s(!0),children:n.jsx(I.Settings,{className:"w-4 h-4"})})}),t&&n.jsx($i,{onClose:()=>s(!1)}),n.jsx("div",{className:"w-px h-4 bg-gray-200 dark:bg-gray-700"})]}):null},Xi=()=>{const{data:e}=Se(),t=e&&(e==null?void 0:e.online),{data:s}=Ee();return S.useCallback(a=>{var i;return(i=g.find(s,{key:a}))==null?void 0:i.hasSlug},[s])(e==null?void 0:e.pageType)?n.jsxs(c.Button,{onClick:()=>t&&window.open(`${window.location.origin}${e.slug}`,"_blank"),disabled:!t,variant:"ghost",size:"sm",className:"flex items-center gap-1",children:[n.jsx(I.ExternalLink,{className:"w-4 h-4"}),n.jsx("span",{className:"hidden sm:inline",children:q.OPEN})]}):null};function Zi(){const{isLocked:e}=Mt(),[t]=je(),s=t.get("lang"),r=Mn(s);return e||!r?null:n.jsxs("div",{className:"flex items-center justify-end gap-1",children:[n.jsx(Gi,{}),n.jsx(we,{permission:ce.EDIT_THEME,children:n.jsx(zi,{})}),n.jsx(we,{permission:ce.EDIT_SETTINGS,children:n.jsx(Yi,{})}),n.jsx(Ki,{}),n.jsx(we,{permission:ce.SAVE_PAGE,children:n.jsx(Wi,{})}),n.jsx(we,{permission:ce.PUBLISH_PAGE,children:n.jsx(Qi,{})}),n.jsx(Xi,{})]})}const Ji=()=>n.jsxs("div",{className:"flex h-full items-center justify-between w-full",children:[n.jsx(Ii,{}),n.jsx(Zi,{})]}),qn=()=>{const e=ee(),t=Z(),s=Ce("user"),r=s==null?void 0:s.id;return U.useQuery({queryKey:["permissions",r],queryFn:()=>t(e,{action:L.GET_ROLE_AND_PERMISSIONS,data:{userId:r}}),enabled:!!r})},eo=({isActive:e,show:t})=>{const{data:s}=ht();return!g.has(s,"languages")||!g.get(s,"languages",[]).length?null:n.jsx(c.Button,{size:"sm",onClick:t,variant:e?"default":"ghost",children:n.jsx(I.LanguagesIcon,{className:"w-4 h-4"})})},Hn="lang",to={id:Hn,label:"Languages",position:"top",panel:vi,button:eo},so=()=>{const{selectedLang:e}=ae.useLanguages(),{data:t,isFetching:s}=ft();return{data:S.useMemo(()=>g.find(t,{lang:e||""})||{},[t,e]),isFetching:s}};function ke({data:e,onSelect:t,dataType:s="value",disabled:r=!1}){const[a,i]=le.useState(!1),[o,l]=le.useState([]),[u,d]=le.useState(e);le.useEffect(()=>{a||l([]),d(e)},[e,a]);const f=y=>Array.isArray(y)?"array":typeof y=="object"&&y!==null?"object":"value",m=le.useCallback(y=>{const j=b=>s==="value"?b==="value"||b==="object":s==="array"?b==="array":b===s;y.type==="object"?(l(b=>[...b,y.key]),d(y.value)):j(y.type)&&(t([...o,y.key].join(".")),i(!1))},[o,t,s]),w=le.useCallback(()=>{if(o.length>0){const y=o.slice(0,-1);l(y),d(y.reduce((j,b)=>j[b],e))}},[o,e]),E=le.useMemo(()=>Object.entries(u).map(([y,j])=>({key:y,value:j,type:f(j)})).filter(y=>s==="value"?y.type==="value"||y.type==="object":s==="array"?y.type==="array"||y.type==="object":s==="object"?y.type==="object":!0),[u,s]);return n.jsxs(c.Popover,{open:a,onOpenChange:i,children:[n.jsxs(c.Tooltip,{children:[n.jsx(c.TooltipTrigger,{asChild:!0,children:n.jsx(c.PopoverTrigger,{asChild:!0,children:n.jsx(c.Button,{size:"sm",variant:"outline",className:"h-6 w-6 px-1 py-0 text-[9px] text-muted-foreground",role:"combobox","aria-expanded":a,disabled:r,children:n.jsx(I.DatabaseIcon,{className:"h-3 w-3"})})})}),n.jsx(c.TooltipContent,{children:"Add field"})]}),n.jsx(c.PopoverContent,{className:"w-[200px] p-0",children:n.jsxs(c.Command,{children:[n.jsx(c.CommandInput,{className:"border-none",placeholder:"Search..."}),n.jsxs(c.CommandList,{children:[n.jsx(c.CommandEmpty,{children:"No option found."}),n.jsxs(c.CommandGroup,{children:[o.length>0&&n.jsxs(c.CommandItem,{onSelect:w,className:"flex items-center text-sm",children:[n.jsx(I.ChevronLeft,{className:"w-4 h-4 mr-2"}),"Back"]}),E.map(y=>n.jsxs(c.CommandItem,{onSelect:()=>m(y),className:"flex items-center justify-between",children:[n.jsx("span",{children:y.key}),n.jsxs("div",{className:"flex items-center gap-2",children:[s==="object"&&y.type==="object"&&n.jsx(c.Button,{size:"sm",variant:"ghost",className:"h-6 px-2 hover:bg-primary hover:text-primary-foreground",onClick:j=>{j.stopPropagation(),t([...o,y.key].join(".")),i(!1)},children:"Select"}),(y.type==="object"||y.type==="array")&&n.jsx("div",{className:"p-1 rounded hover:bg-muted cursor-pointer",children:n.jsx(I.ChevronRight,{className:"w-4 h-4 opacity-50"})})]})]},y.key))]})]})]})})]})}const no=(e,t)=>{const s=e.selectionStart||0,r=e.selectionEnd||0,a=e.value,i=a.substring(0,s),o=a.substring(r);let l=!1;if(s>0&&i.length>0){const y=i.charAt(i.length-1);l=!/[\s.,!?;:()[\]{}]/.test(y)&&y!==""}let u=!1;if(o.length>0){const y=o.charAt(0);u=!/[\s.,!?;:()[\]{}]/.test(y)&&y!==""}const d=l?" ":"",f=u?" ":"",m=`{{${t}}}`,w=i+(l?d:"")+m+(u?f:"")+o,E=s+(l?1:0)+m.length;return{value:w,newCursorPos:E}},Vn=()=>{const{t:e}=ae.useTranslation(),{selectedLang:t,fallbackLang:s,languages:r}=ae.useLanguages(),{data:a}=Se(),{data:i}=Gn({lang:t||s,pageType:a==null?void 0:a.pageType}),{data:o,isFetching:l}=so(),u=o==null?void 0:o.seo,d=S.useRef(null),[f,m]=S.useState({title:"",description:"",cononicalUrl:"",noIndex:!1,noFollow:"",ogTitle:"",ogDescription:"",ogImage:"",searchTitle:"",searchDescription:"",jsonLD:"",...u}),w=S.useRef({initial:f,updated:f}),E=t.length?t:s,{mutate:y,isPending:j}=Ss(),b=j,{hasPermission:D}=ae.usePermissions(),A=D(ce.EDIT_SEO);S.useEffect(()=>{!l&&u&&m({title:"",description:"",cononicalUrl:"",noIndex:!1,noFollow:"",ogTitle:"",ogDescription:"",ogImage:"",searchTitle:"",searchDescription:"",jsonLD:"",...u})},[l,u]);const T=async()=>{y({id:o==null?void 0:o.id,seo:f}),w.current.initial=f,w.current.updated=f},v=()=>{m({...f,ogTitle:f.title,ogDescription:f.description})},P=()=>{m({...f,searchTitle:f.ogTitle,searchDescription:f.ogDescription})},F=(k,N)=>{const G=document.getElementById(N);if(G){const{value:H,newCursorPos:Y}=no(G,k);d.current={id:N,position:Y},G.tagName.toLowerCase()==="input"?(G.value=H,m(p=>({...p,[G.name]:H})),G.focus(),G.setSelectionRange(Y,Y),[0,10,50,100,200].forEach(p=>{setTimeout(()=>{const V=document.getElementById(N);V&&(V.focus(),V.setSelectionRange(Y,Y))},p)})):(m(me=>({...me,[G.name]:H})),requestAnimationFrame(()=>{const me=document.getElementById(N);me&&(me.focus(),me.setSelectionRange(Y,Y),setTimeout(()=>{const p=document.getElementById(N);p&&(p.focus(),p.setSelectionRange(Y,Y))},50))}))}},C=k=>{const N={...f,[k.target.name]:k.target.name==="noIndex"||k.target.name==="noFollow"?k.target.checked:k.target.value};m(N),w.current.updated=N};return n.jsxs("div",{className:"relative pb-40",children:[!A&&n.jsx("div",{className:"absolute inset-0 z-10 backdrop-blur-sm flex items-center justify-center",children:n.jsx(c.Alert,{variant:"default",className:"w-[80%] max-w-md text-xs",children:n.jsx(c.AlertDescription,{children:e("You don't have permission to edit SEO settings. Contact your administrator for access.")})})}),n.jsxs("div",{className:"p-2 text-xs text-left bg-gray-100 rounded-md",children:[e("Slug"),": ",o==null?void 0:o.slug,"  ",r.length>0&&n.jsxs("span",{className:"font-semibold text-blue-500",children:["(",g.get(Te,E,E),")"]})]}),n.jsx("form",{className:"space-y-8",children:n.jsxs(c.Accordion,{type:"multiple",defaultValue:["page"],children:[n.jsxs(c.AccordionItem,{value:"page",children:[n.jsx(c.AccordionTrigger,{className:"font-semibold text-slate-700",children:e("SEO")}),n.jsx(c.AccordionContent,{className:"pt-2",children:n.jsxs("div",{className:"space-y-4",children:[n.jsxs("div",{className:"space-y-1",children:[n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsx(c.Label,{className:"text-xs",htmlFor:"title",children:e("SEO Title")}),A&&n.jsx(ke,{dataType:"value",data:i??{},onSelect:k=>F(k,"title")})]}),n.jsx(c.Input,{type:"text",id:"title",name:"title",value:f.title,onChange:C,disabled:b||!A,placeholder:e("Enter SEO title"),readOnly:!A})]}),n.jsxs("div",{className:"space-y-1",children:[n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsx(c.Label,{className:"text-xs",htmlFor:"description",children:e("SEO Description")}),A&&n.jsx(ke,{data:i??{},onSelect:k=>F(k,"description")})]}),n.jsx(c.Textarea,{id:"description",name:"description",rows:5,value:f.description,onChange:C,disabled:b||!A,placeholder:e("Enter SEO description"),readOnly:!A})]}),n.jsxs("div",{className:"space-y-1",children:[n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsx(c.Label,{className:"text-xs",htmlFor:"title",children:e("Canonical URL")}),A&&n.jsx(ke,{dataType:"value",data:i??{},onSelect:k=>F(k,"canonicalUrl")})]}),n.jsx(c.Input,{type:"text",id:"canonicalUrl",name:"canonicalUrl",value:f.canonicalUrl,onChange:C,disabled:b||!A,placeholder:e("Enter Canonical URL"),readOnly:!A})]}),n.jsxs("div",{className:"",children:[n.jsxs("div",{className:"flex items-center gap-x-2",children:[n.jsx(c.Input,{type:"checkbox",id:"noIndex",name:"noIndex",checked:f.noIndex,onChange:C,disabled:b||!A,className:"w-4 h-4"}),n.jsx(c.Label,{className:"pb-1 text-xs",htmlFor:"noIndex",children:e("No Index")})]}),n.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.")})]}),n.jsxs("div",{className:"",children:[n.jsxs("div",{className:"flex items-center gap-x-2",children:[n.jsx(c.Input,{type:"checkbox",id:"noFollow",name:"noFollow",checked:f.noFollow,onChange:C,disabled:b||!A,className:"w-4 h-4"}),n.jsx(c.Label,{className:"pb-1 text-xs",htmlFor:"noIndex",children:e("No Follow")})]}),n.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.")})]})]})})]}),n.jsxs(c.AccordionItem,{value:"og",children:[n.jsx(c.AccordionTrigger,{className:"font-bold text-slate-700",children:e("Open Graph")}),n.jsx(c.AccordionContent,{children:n.jsxs("div",{className:"space-y-4",children:[n.jsx("div",{className:"flex items-center justify-between",children:n.jsx(c.Button,{type:"button",variant:"outline",size:"sm",onClick:v,disabled:!A,children:e("Copy from SEO Settings")})}),n.jsxs("div",{className:"space-y-1",children:[n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsx(c.Label,{className:"text-xs",htmlFor:"ogTitle",children:e("OG Title")}),A&&n.jsx(ke,{dataType:"value",data:i??{},onSelect:k=>F(k,"ogTitle")})]}),n.jsx(c.Input,{type:"text",id:"ogTitle",name:"ogTitle",value:f.ogTitle,onChange:C,disabled:b||!A,placeholder:e("Enter OG title"),readOnly:!A})]}),n.jsxs("div",{className:"space-y-1",children:[n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsx(c.Label,{className:"text-xs",htmlFor:"ogDescription",children:e("OG Description")}),A&&n.jsx(ke,{dataType:"value",data:i??{},onSelect:k=>F(k,"ogDescription")})]}),n.jsx(c.Textarea,{id:"ogDescription",name:"ogDescription",rows:5,value:f.ogDescription,onChange:C,disabled:b||!A,placeholder:e("Enter OG description"),readOnly:!A})]}),n.jsxs("div",{className:"space-y-1",children:[n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsx(c.Label,{className:"text-xs",htmlFor:"ogImage",children:e("OG Image URL")}),A&&n.jsx(ke,{dataType:"value",data:i??{},onSelect:k=>F(k,"ogImage")})]}),n.jsx(c.Input,{type:"text",id:"ogImage",name:"ogImage",value:f.ogImage,onChange:C,disabled:b||!A,placeholder:e("Enter OG image URL"),readOnly:!A})]})]})})]}),n.jsxs(c.AccordionItem,{value:"search",children:[n.jsx(c.AccordionTrigger,{className:"font-bold text-slate-700",children:e("Search")}),n.jsx(c.AccordionContent,{children:n.jsxs("div",{className:"space-y-4",children:[n.jsx("div",{className:"flex items-center justify-between",children:n.jsx(c.Button,{type:"button",variant:"outline",size:"sm",onClick:P,disabled:!A,children:e("Copy from OG Settings")})}),n.jsxs("div",{className:"space-y-1",children:[n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsx(c.Label,{className:"text-xs",htmlFor:"searchTitle",children:e("Search Title")}),A&&n.jsx(ke,{dataType:"value",data:i??{},onSelect:k=>F(k,"searchTitle")})]}),n.jsx(c.Input,{type:"text",id:"searchTitle",name:"searchTitle",value:f.searchTitle,onChange:C,disabled:b||!A,placeholder:e("Enter search title"),readOnly:!A})]}),n.jsxs("div",{className:"space-y-1",children:[n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsx(c.Label,{className:"text-xs",htmlFor:"searchDescription",children:e("Search Description")}),A&&n.jsx(ke,{dataType:"value",data:i??{},onSelect:k=>F(k,"searchDescription")})]}),n.jsx(c.Textarea,{id:"searchDescription",rows:5,name:"searchDescription",value:f.searchDescription,onChange:C,placeholder:e("Enter search description"),disabled:b||!A,readOnly:!A})]})]})})]}),n.jsxs(c.AccordionItem,{value:"jsonLD",children:[n.jsx(c.AccordionTrigger,{className:"font-bold text-slate-700",children:e("JSON-LD")}),n.jsx(c.AccordionContent,{children:n.jsx("div",{className:"space-y-4",children:n.jsxs("div",{className:"space-y-1",children:[n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsx(c.Label,{className:"text-xs",htmlFor:"jsonLD",children:e("JSON-LD")}),A&&n.jsx(ke,{dataType:"value",data:i??{},onSelect:k=>F(k,"jsonLD")})]}),n.jsx(c.Textarea,{id:"jsonLD",name:"jsonLD",rows:6,value:f.jsonLD,onChange:C,placeholder:e("Enter JSON-LD"),disabled:b||!A,readOnly:!A})]})})})]})]})}),A&&n.jsx("div",{className:"flex items-center justify-end w-full mt-4",children:n.jsx(c.Button,{size:"lg",variant:"default",onClick:T,disabled:g.isEqual(w.current.initial,f)||b||!A,children:e(j?"Saving...":"Save")})})]})};Vn.displayName="SeoPanel";const $n="seo",ro=({isActive:e,show:t})=>{const{data:s}=Se(),r=ni(s==null?void 0:s.pageType);return!g.has(r,"hasSlug")||!r.hasSlug?null:n.jsx(c.Button,{size:"sm",className:"my-1",onClick:t,variant:e?"default":"ghost",children:n.jsxs("svg",{className:"w-4 h-4",xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 21 21",fill:"currentColor",children:[n.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"}),n.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"})]})})},ao={id:$n,label:"SEO",panel:Vn,button:ro,position:"top"},io=()=>{ae.registerChaiSidebarPanel($n,ao),ae.registerChaiSidebarPanel(Hn,to)};er.loadWebBlocks();io();ae.registerChaiTopBar(Ji);const oo=e=>{const t=S.useRef([]),[s]=je(),r=s.get("page"),a=s.get("lang"),{data:i}=Se(),{data:o={role:"",permissions:null}}=qn(),{data:l}=ai(),{data:u,isFetching:d}=kn(),{blocks:f}=ti(u),{data:m}=ht(),{data:w}=Ee(),{mutateAsync:E}=Ln(),y=Za(),{getUILibraryBlock:j,getUILibraryBlocks:b,onSave:D}=ii(),{getPartialBlocks:A,getPartialBlockBlocks:T}=oi(),{aiContext:v,setAiContext:P}=Es(),{mutateAsync:F}=ri(),[C,k]=S.useState(!1),N=S.useMemo(()=>(m==null?void 0:m.fallbackLang)||"en",[m]),{data:G}=Gn({pageType:i==null?void 0:i.pageType,lang:a||N});Xa(),S.useEffect(()=>{const p=()=>{document.hidden?k(!0):k(!1)};return window.addEventListener("visibilitychange",p),()=>window.removeEventListener("visibilitychange",p)},[]),t.current=f;const H=S.useMemo(()=>{const p={};return o&&(p.permissions=g.get(o,"permissions",null),p.role=g.get(o,"role","user")),p},[o]),Y=S.useMemo(()=>l,[l]),Le=S.useCallback(async(p,V)=>await F({pageType:p,query:V}),[F]),me=S.useMemo(()=>g.get(m,"theme",{})||{},[m]);return n.jsxs(n.Fragment,{children:[d&&n.jsx("div",{className:"absolute inset-0 z-50 flex items-center justify-center w-screen h-screen bg-white/30",children:n.jsx("div",{className:"flex items-center justify-center bg-white rounded-full size-10",children:n.jsx(I.Loader2,{className:"size-5 animate-spin"})})}),n.jsx(ae.ChaiBuilderEditor,{pageExternalData:G,themePresets:e.themePresets??[],pageId:i==null?void 0:i.id,loading:d,fallbackLang:N,languages:(m==null?void 0:m.languages)||[],brandingOptions:(m==null?void 0:m.theme)||{},translations:e.translations||{},locale:e.locale||"en",htmlDir:e.htmlDir||"ltr",autoSaveSupport:!C&&(e.autoSaveSupport??!0),autoSaveInterval:e.autoSaveInterval??15,onError:e.onError||console.error,getPartialBlockBlocks:T,getPartialBlocks:A,blocks:d?[]:f,theme:g.cloneDeep(me),getUILibraryBlock:j,getUILibraryBlocks:b,uiLibraries:Y,pageTypes:w,searchPageTypeItems:Le,saveAiContextCallback:async p=>{if(!r)return!0;const V=t.current,be={_type:"@chai/ai-context",_value:g.isString(p)?p:""},xe=[...V,be];return await D({page:r,blocks:xe}),P(p),!0},aiContext:v,askAiCallBack:y,onSave:async({blocks:p,theme:V})=>{if(!r)return!0;t.current=p;const be={_type:"@chai/ai-context",_value:g.isString(v)?v:""},xe=[...p,be];return await D({page:r,blocks:xe}),t.current=xe,g.isEqual(V,me)||await E({settings:{theme:V}}),!0},themePanelComponent:yi,...H}),n.jsxs("div",{children:[n.jsx(ci,{}),n.jsx(ui,{})]})]})},lo=new U.QueryClient({defaultOptions:{queries:{refetchOnWindowFocus:!1,refetchOnReconnect:!1}}}),co=e=>{const[,t]=Dn(),[s,r]=S.useState(!1);return S.useEffect(()=>(t(g.pick(e,["apiUrl","getPreviewUrl","logo","settingComponent","user","onSessionExpired","pageLockComponent"])),setTimeout(()=>{r(!0)},200),()=>{r(!1),t({})}),[e,t]),s?n.jsxs(U.QueryClientProvider,{client:lo,children:[n.jsx(oo,{...e}),n.jsx($a,{})]}):n.jsx("div",{})};if(typeof window>"u")throw new Error("@chaibuilder/pages is not available on the server");exports.$TRACK=ms;exports.ChaiBuilderPages=co;exports.Dynamic=Xr;exports.For=jr;exports.Index=Nr;exports.Match=Cr;exports.PermissionChecker=we;exports.Portal=Yr;exports.Show=Ar;exports.Switch=Tr;exports.addEventListener=ln;exports.batch=ir;exports.className=on;exports.clearDelegatedEvents=Br;exports.convertRemToPixels=Ra;exports.createComponent=ps;exports.createComputed=Ws;exports.createContext=hr;exports.createEffect=gs;exports.createMemo=ye;exports.createRenderEffect=Oe;exports.createRoot=Ue;exports.createSignal=he;exports.createUniqueId=wr;exports.delegateEvents=an;exports.deleteNestedDataByPath=xt;exports.displayValue=Da;exports.getMutationStatusColor=_a;exports.getPreferredColorScheme=Ba;exports.getQueryStatusColor=Ia;exports.getQueryStatusColorByLabel=La;exports.getQueryStatusLabel=Ca;exports.getSidedProp=Pa;exports.insert=Wt;exports.mergeProps=ys;exports.mutationSortFns=Oa;exports.on=or;exports.onCleanup=ot;exports.onMount=Qs;exports.serialize=Tn;exports.setAttribute=zt;exports.sortFns=Ma;exports.splitProps=tn;exports.spread=cn;exports.stringify=Ta;exports.template=Rr;exports.untrack=fe;exports.updateNestedDataByPath=gt;exports.use=un;exports.useChaiUserInfo=dt;exports.useContext=fr;exports.useCurrentPage=Se;exports.useFetch=Z;exports.useFetchUpload=za;exports.useLanguagePages=ft;exports.useTransition=dr;exports.useUserRoleAndPermissions=qn;exports.useWebsitePages=Gt;exports.useWebsiteSetting=ht;