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