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