import { g as Ke, a3 as qe, m as j, b as H } from "./chunk-RXIM6GTA.C-ABNABt.js";
import "@sinclair/typebox";
import { debounce as Je, isEqual as Re, merge as Ye } from "lodash-es";
import J, { createContext as Xe, useContext as Qe, useEffect as ee } from "react";
/*! Upstart.gg - Copyright (C) 2024 Flippable - https://github.com/upstart-gg/upstart/blob/main/LICENSE */
var we = "Invariant failed";
function L(e, r) {
  if (e) return;
  let n = typeof r == "function" ? r() : r, s = n ? `${we}: ${n}` : we;
  throw new Error(s);
}
var Fe = Symbol.for("immer-nothing"), Pe = Symbol.for("immer-draftable"), g = Symbol.for("immer-state"), Ze = process.env.NODE_ENV !== "production" ? [
  // All error codes, starting by 0:
  function(e) {
    return `The plugin for '${e}' has not been loaded into Immer. To enable the plugin, import and call \`enable${e}()\` when initializing your application.`;
  },
  function(e) {
    return `produce can only be called on things that are draftable: plain objects, arrays, Map, Set or classes that are marked with '[immerable]: true'. Got '${e}'`;
  },
  "This object has been frozen and should not be mutated",
  function(e) {
    return "Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? " + e;
  },
  "An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft.",
  "Immer forbids circular references",
  "The first or second argument to `produce` must be a function",
  "The third argument to `produce` must be a function or undefined",
  "First argument to `createDraft` must be a plain object, an array, or an immerable object",
  "First argument to `finishDraft` must be a draft returned by `createDraft`",
  function(e) {
    return `'current' expects a draft, got: ${e}`;
  },
  "Object.defineProperty() cannot be used on an Immer draft",
  "Object.setPrototypeOf() cannot be used on an Immer draft",
  "Immer only supports deleting array indices",
  "Immer only supports setting array indices and the 'length' property",
  function(e) {
    return `'original' expects a draft, got: ${e}`;
  }
  // Note: if more errors are added, the errorOffset in Patches.ts should be increased
  // See Patches.ts for additional errors
] : [];
function M(e, ...r) {
  if (process.env.NODE_ENV !== "production") {
    const n = Ze[e], s = typeof n == "function" ? n.apply(null, r) : n;
    throw new Error(`[Immer] ${s}`);
  }
  throw new Error(
    `[Immer] minified error nr: ${e}. Full error at: https://bit.ly/3cXEKWf`
  );
}
var R = Object.getPrototypeOf;
function F(e) {
  return !!e && !!e[g];
}
function $(e) {
  var r;
  return e ? Ne(e) || Array.isArray(e) || !!e[Pe] || !!((r = e.constructor) != null && r[Pe]) || te(e) || ne(e) : !1;
}
var er = Object.prototype.constructor.toString();
function Ne(e) {
  if (!e || typeof e != "object")
    return !1;
  const r = R(e);
  if (r === null)
    return !0;
  const n = Object.hasOwnProperty.call(r, "constructor") && r.constructor;
  return n === Object ? !0 : typeof n == "function" && Function.toString.call(n) === er;
}
function U(e, r) {
  re(e) === 0 ? Reflect.ownKeys(e).forEach((n) => {
    r(n, e[n], e);
  }) : e.forEach((n, s) => r(s, n, e));
}
function re(e) {
  const r = e[g];
  return r ? r.type_ : Array.isArray(e) ? 1 : te(e) ? 2 : ne(e) ? 3 : 0;
}
function _e(e, r) {
  return re(e) === 2 ? e.has(r) : Object.prototype.hasOwnProperty.call(e, r);
}
function We(e, r, n) {
  const s = re(e);
  s === 2 ? e.set(r, n) : s === 3 ? e.add(n) : e[r] = n;
}
function rr(e, r) {
  return e === r ? e !== 0 || 1 / e === 1 / r : e !== e && r !== r;
}
function te(e) {
  return e instanceof Map;
}
function ne(e) {
  return e instanceof Set;
}
function P(e) {
  return e.copy_ || e.base_;
}
function Se(e, r) {
  if (te(e))
    return new Map(e);
  if (ne(e))
    return new Set(e);
  if (Array.isArray(e))
    return Array.prototype.slice.call(e);
  const n = Ne(e);
  if (r === !0 || r === "class_only" && !n) {
    const s = Object.getOwnPropertyDescriptors(e);
    delete s[g];
    let t = Reflect.ownKeys(s);
    for (let i = 0; i < t.length; i++) {
      const u = t[i], c = s[u];
      c.writable === !1 && (c.writable = !0, c.configurable = !0), (c.get || c.set) && (s[u] = {
        configurable: !0,
        writable: !0,
        // could live with !!desc.set as well here...
        enumerable: c.enumerable,
        value: e[u]
      });
    }
    return Object.create(R(e), s);
  } else {
    const s = R(e);
    if (s !== null && n)
      return { ...e };
    const t = Object.create(s);
    return Object.assign(t, e);
  }
}
function Ee(e, r = !1) {
  return ie(e) || F(e) || !$(e) || (re(e) > 1 && (e.set = e.add = e.clear = e.delete = tr), Object.freeze(e), r && Object.entries(e).forEach(([n, s]) => Ee(s, !0))), e;
}
function tr() {
  M(2);
}
function ie(e) {
  return Object.isFrozen(e);
}
var ve = {};
function z(e) {
  const r = ve[e];
  return r || M(0, e), r;
}
function nr(e, r) {
  ve[e] || (ve[e] = r);
}
var V;
function X() {
  return V;
}
function ir(e, r) {
  return {
    drafts_: [],
    parent_: e,
    immer_: r,
    // Whenever the modified draft contains a draft from another scope, we
    // need to prevent auto-freezing so the unowned draft can be finalized.
    canAutoFreeze_: !0,
    unfinalizedDrafts_: 0
  };
}
function Oe(e, r) {
  r && (z("Patches"), e.patches_ = [], e.inversePatches_ = [], e.patchListener_ = r);
}
function ye(e) {
  be(e), e.drafts_.forEach(or), e.drafts_ = null;
}
function be(e) {
  e === V && (V = e.parent_);
}
function Me(e) {
  return V = ir(V, e);
}
function or(e) {
  const r = e[g];
  r.type_ === 0 || r.type_ === 1 ? r.revoke_() : r.revoked_ = !0;
}
function Te(e, r) {
  r.unfinalizedDrafts_ = r.drafts_.length;
  const n = r.drafts_[0];
  return e !== void 0 && e !== n ? (n[g].modified_ && (ye(r), M(4)), $(e) && (e = Q(r, e), r.parent_ || Z(r, e)), r.patches_ && z("Patches").generateReplacementPatches_(
    n[g].base_,
    e,
    r.patches_,
    r.inversePatches_
  )) : e = Q(r, n, []), ye(r), r.patches_ && r.patchListener_(r.patches_, r.inversePatches_), e !== Fe ? e : void 0;
}
function Q(e, r, n) {
  if (ie(r))
    return r;
  const s = r[g];
  if (!s)
    return U(
      r,
      (t, i) => De(e, s, r, t, i, n)
    ), r;
  if (s.scope_ !== e)
    return r;
  if (!s.modified_)
    return Z(e, s.base_, !0), s.base_;
  if (!s.finalized_) {
    s.finalized_ = !0, s.scope_.unfinalizedDrafts_--;
    const t = s.copy_;
    let i = t, u = !1;
    s.type_ === 3 && (i = new Set(t), t.clear(), u = !0), U(
      i,
      (c, o) => De(e, s, t, c, o, n, u)
    ), Z(e, t, !1), n && e.patches_ && z("Patches").generatePatches_(
      s,
      n,
      e.patches_,
      e.inversePatches_
    );
  }
  return s.copy_;
}
function De(e, r, n, s, t, i, u) {
  if (process.env.NODE_ENV !== "production" && t === n && M(5), F(t)) {
    const c = i && r && r.type_ !== 3 && // Set objects are atomic since they have no keys.
    !_e(r.assigned_, s) ? i.concat(s) : void 0, o = Q(e, t, c);
    if (We(n, s, o), F(o))
      e.canAutoFreeze_ = !1;
    else
      return;
  } else u && n.add(t);
  if ($(t) && !ie(t)) {
    if (!e.immer_.autoFreeze_ && e.unfinalizedDrafts_ < 1)
      return;
    Q(e, t), (!r || !r.scope_.parent_) && typeof s != "symbol" && Object.prototype.propertyIsEnumerable.call(n, s) && Z(e, t);
  }
}
function Z(e, r, n = !1) {
  !e.parent_ && e.immer_.autoFreeze_ && e.canAutoFreeze_ && Ee(r, n);
}
function cr(e, r) {
  const n = Array.isArray(e), s = {
    type_: n ? 1 : 0,
    // Track which produce call this is associated with.
    scope_: r ? r.scope_ : X(),
    // True for both shallow and deep changes.
    modified_: !1,
    // Used during finalization.
    finalized_: !1,
    // Track which properties have been assigned (true) or deleted (false).
    assigned_: {},
    // The parent draft state.
    parent_: r,
    // The base state.
    base_: e,
    // The base proxy.
    draft_: null,
    // set below
    // The base copy with any updated values.
    copy_: null,
    // Called by the `produce` function.
    revoke_: null,
    isManual_: !1
  };
  let t = s, i = xe;
  n && (t = [s], i = G);
  const { revoke: u, proxy: c } = Proxy.revocable(t, i);
  return s.draft_ = c, s.revoke_ = u, c;
}
var xe = {
  get(e, r) {
    if (r === g)
      return e;
    const n = P(e);
    if (!_e(n, r))
      return sr(e, n, r);
    const s = n[r];
    return e.finalized_ || !$(s) ? s : s === de(e.base_, r) ? (le(e), e.copy_[r] = K(s, e)) : s;
  },
  has(e, r) {
    return r in P(e);
  },
  ownKeys(e) {
    return Reflect.ownKeys(P(e));
  },
  set(e, r, n) {
    const s = je(P(e), r);
    if (s != null && s.set)
      return s.set.call(e.draft_, n), !0;
    if (!e.modified_) {
      const t = de(P(e), r), i = t == null ? void 0 : t[g];
      if (i && i.base_ === n)
        return e.copy_[r] = n, e.assigned_[r] = !1, !0;
      if (rr(n, t) && (n !== void 0 || _e(e.base_, r)))
        return !0;
      le(e), C(e);
    }
    return e.copy_[r] === n && // special case: handle new props with value 'undefined'
    (n !== void 0 || r in e.copy_) || // special case: NaN
    Number.isNaN(n) && Number.isNaN(e.copy_[r]) || (e.copy_[r] = n, e.assigned_[r] = !0), !0;
  },
  deleteProperty(e, r) {
    return de(e.base_, r) !== void 0 || r in e.base_ ? (e.assigned_[r] = !1, le(e), C(e)) : delete e.assigned_[r], e.copy_ && delete e.copy_[r], !0;
  },
  // Note: We never coerce `desc.value` into an Immer draft, because we can't make
  // the same guarantee in ES5 mode.
  getOwnPropertyDescriptor(e, r) {
    const n = P(e), s = Reflect.getOwnPropertyDescriptor(n, r);
    return s && {
      writable: !0,
      configurable: e.type_ !== 1 || r !== "length",
      enumerable: s.enumerable,
      value: n[r]
    };
  },
  defineProperty() {
    M(11);
  },
  getPrototypeOf(e) {
    return R(e.base_);
  },
  setPrototypeOf() {
    M(12);
  }
}, G = {};
U(xe, (e, r) => {
  G[e] = function() {
    return arguments[0] = arguments[0][0], r.apply(this, arguments);
  };
});
G.deleteProperty = function(e, r) {
  return process.env.NODE_ENV !== "production" && isNaN(parseInt(r)) && M(13), G.set.call(this, e, r, void 0);
};
G.set = function(e, r, n) {
  return process.env.NODE_ENV !== "production" && r !== "length" && isNaN(parseInt(r)) && M(14), xe.set.call(this, e[0], r, n, e[0]);
};
function de(e, r) {
  const n = e[g];
  return (n ? P(n) : e)[r];
}
function sr(e, r, n) {
  var t;
  const s = je(r, n);
  return s ? "value" in s ? s.value : (
    // This is a very special case, if the prop is a getter defined by the
    // prototype, we should invoke it with the draft as context!
    (t = s.get) == null ? void 0 : t.call(e.draft_)
  ) : void 0;
}
function je(e, r) {
  if (!(r in e))
    return;
  let n = R(e);
  for (; n; ) {
    const s = Object.getOwnPropertyDescriptor(n, r);
    if (s)
      return s;
    n = R(n);
  }
}
function C(e) {
  e.modified_ || (e.modified_ = !0, e.parent_ && C(e.parent_));
}
function le(e) {
  e.copy_ || (e.copy_ = Se(
    e.base_,
    e.scope_.immer_.useStrictShallowCopy_
  ));
}
var ar = class {
  constructor(e) {
    this.autoFreeze_ = !0, this.useStrictShallowCopy_ = !1, this.produce = (r, n, s) => {
      if (typeof r == "function" && typeof n != "function") {
        const i = n;
        n = r;
        const u = this;
        return function(o = i, ...a) {
          return u.produce(o, (d) => n.call(this, d, ...a));
        };
      }
      typeof n != "function" && M(6), s !== void 0 && typeof s != "function" && M(7);
      let t;
      if ($(r)) {
        const i = Me(this), u = K(r, void 0);
        let c = !0;
        try {
          t = n(u), c = !1;
        } finally {
          c ? ye(i) : be(i);
        }
        return Oe(i, s), Te(t, i);
      } else if (!r || typeof r != "object") {
        if (t = n(r), t === void 0 && (t = r), t === Fe && (t = void 0), this.autoFreeze_ && Ee(t, !0), s) {
          const i = [], u = [];
          z("Patches").generateReplacementPatches_(r, t, i, u), s(i, u);
        }
        return t;
      } else
        M(1, r);
    }, this.produceWithPatches = (r, n) => {
      if (typeof r == "function")
        return (u, ...c) => this.produceWithPatches(u, (o) => r(o, ...c));
      let s, t;
      return [this.produce(r, n, (u, c) => {
        s = u, t = c;
      }), s, t];
    }, typeof (e == null ? void 0 : e.autoFreeze) == "boolean" && this.setAutoFreeze(e.autoFreeze), typeof (e == null ? void 0 : e.useStrictShallowCopy) == "boolean" && this.setUseStrictShallowCopy(e.useStrictShallowCopy);
  }
  createDraft(e) {
    $(e) || M(8), F(e) && (e = ur(e));
    const r = Me(this), n = K(e, void 0);
    return n[g].isManual_ = !0, be(r), n;
  }
  finishDraft(e, r) {
    const n = e && e[g];
    (!n || !n.isManual_) && M(9);
    const { scope_: s } = n;
    return Oe(s, r), Te(void 0, s);
  }
  /**
   * Pass true to automatically freeze all copies created by Immer.
   *
   * By default, auto-freezing is enabled.
   */
  setAutoFreeze(e) {
    this.autoFreeze_ = e;
  }
  /**
   * Pass true to enable strict shallow copy.
   *
   * By default, immer does not copy the object descriptors such as getter, setter and non-enumrable properties.
   */
  setUseStrictShallowCopy(e) {
    this.useStrictShallowCopy_ = e;
  }
  applyPatches(e, r) {
    let n;
    for (n = r.length - 1; n >= 0; n--) {
      const t = r[n];
      if (t.path.length === 0 && t.op === "replace") {
        e = t.value;
        break;
      }
    }
    n > -1 && (r = r.slice(n + 1));
    const s = z("Patches").applyPatches_;
    return F(e) ? s(e, r) : this.produce(
      e,
      (t) => s(t, r)
    );
  }
};
function K(e, r) {
  const n = te(e) ? z("MapSet").proxyMap_(e, r) : ne(e) ? z("MapSet").proxySet_(e, r) : cr(e, r);
  return (r ? r.scope_ : X()).drafts_.push(n), n;
}
function ur(e) {
  return F(e) || M(10, e), He(e);
}
function He(e) {
  if (!$(e) || ie(e))
    return e;
  const r = e[g];
  let n;
  if (r) {
    if (!r.modified_)
      return r.base_;
    r.finalized_ = !0, n = Se(e, r.scope_.immer_.useStrictShallowCopy_);
  } else
    n = Se(e, !0);
  return U(n, (s, t) => {
    We(n, s, He(t));
  }), r && (r.finalized_ = !1), n;
}
function dr() {
  class e extends Map {
    constructor(o, a) {
      super(), this[g] = {
        type_: 2,
        parent_: a,
        scope_: a ? a.scope_ : X(),
        modified_: !1,
        finalized_: !1,
        copy_: void 0,
        assigned_: void 0,
        base_: o,
        draft_: this,
        isManual_: !1,
        revoked_: !1
      };
    }
    get size() {
      return P(this[g]).size;
    }
    has(o) {
      return P(this[g]).has(o);
    }
    set(o, a) {
      const d = this[g];
      return u(d), (!P(d).has(o) || P(d).get(o) !== a) && (n(d), C(d), d.assigned_.set(o, !0), d.copy_.set(o, a), d.assigned_.set(o, !0)), this;
    }
    delete(o) {
      if (!this.has(o))
        return !1;
      const a = this[g];
      return u(a), n(a), C(a), a.base_.has(o) ? a.assigned_.set(o, !1) : a.assigned_.delete(o), a.copy_.delete(o), !0;
    }
    clear() {
      const o = this[g];
      u(o), P(o).size && (n(o), C(o), o.assigned_ = /* @__PURE__ */ new Map(), U(o.base_, (a) => {
        o.assigned_.set(a, !1);
      }), o.copy_.clear());
    }
    forEach(o, a) {
      const d = this[g];
      P(d).forEach((l, f, p) => {
        o.call(a, this.get(f), f, this);
      });
    }
    get(o) {
      const a = this[g];
      u(a);
      const d = P(a).get(o);
      if (a.finalized_ || !$(d) || d !== a.base_.get(o))
        return d;
      const l = K(d, a);
      return n(a), a.copy_.set(o, l), l;
    }
    keys() {
      return P(this[g]).keys();
    }
    values() {
      const o = this.keys();
      return {
        [Symbol.iterator]: () => this.values(),
        next: () => {
          const a = o.next();
          return a.done ? a : {
            done: !1,
            value: this.get(a.value)
          };
        }
      };
    }
    entries() {
      const o = this.keys();
      return {
        [Symbol.iterator]: () => this.entries(),
        next: () => {
          const a = o.next();
          if (a.done)
            return a;
          const d = this.get(a.value);
          return {
            done: !1,
            value: [a.value, d]
          };
        }
      };
    }
    [Symbol.iterator]() {
      return this.entries();
    }
  }
  function r(c, o) {
    return new e(c, o);
  }
  function n(c) {
    c.copy_ || (c.assigned_ = /* @__PURE__ */ new Map(), c.copy_ = new Map(c.base_));
  }
  class s extends Set {
    constructor(o, a) {
      super(), this[g] = {
        type_: 3,
        parent_: a,
        scope_: a ? a.scope_ : X(),
        modified_: !1,
        finalized_: !1,
        copy_: void 0,
        base_: o,
        draft_: this,
        drafts_: /* @__PURE__ */ new Map(),
        revoked_: !1,
        isManual_: !1
      };
    }
    get size() {
      return P(this[g]).size;
    }
    has(o) {
      const a = this[g];
      return u(a), a.copy_ ? !!(a.copy_.has(o) || a.drafts_.has(o) && a.copy_.has(a.drafts_.get(o))) : a.base_.has(o);
    }
    add(o) {
      const a = this[g];
      return u(a), this.has(o) || (i(a), C(a), a.copy_.add(o)), this;
    }
    delete(o) {
      if (!this.has(o))
        return !1;
      const a = this[g];
      return u(a), i(a), C(a), a.copy_.delete(o) || (a.drafts_.has(o) ? a.copy_.delete(a.drafts_.get(o)) : (
        /* istanbul ignore next */
        !1
      ));
    }
    clear() {
      const o = this[g];
      u(o), P(o).size && (i(o), C(o), o.copy_.clear());
    }
    values() {
      const o = this[g];
      return u(o), i(o), o.copy_.values();
    }
    entries() {
      const o = this[g];
      return u(o), i(o), o.copy_.entries();
    }
    keys() {
      return this.values();
    }
    [Symbol.iterator]() {
      return this.values();
    }
    forEach(o, a) {
      const d = this.values();
      let l = d.next();
      for (; !l.done; )
        o.call(a, l.value, l.value, this), l = d.next();
    }
  }
  function t(c, o) {
    return new s(c, o);
  }
  function i(c) {
    c.copy_ || (c.copy_ = /* @__PURE__ */ new Set(), c.base_.forEach((o) => {
      if ($(o)) {
        const a = K(o, c);
        c.drafts_.set(o, a), c.copy_.add(a);
      } else
        c.copy_.add(o);
    }));
  }
  function u(c) {
    c.revoked_ && M(3, JSON.stringify(P(c)));
  }
  nr("MapSet", { proxyMap_: r, proxySet_: t });
}
var D = new ar(), lr = D.produce;
D.produceWithPatches.bind(
  D
);
D.setAutoFreeze.bind(D);
D.setUseStrictShallowCopy.bind(D);
D.applyPatches.bind(D);
D.createDraft.bind(D);
D.finishDraft.bind(D);
const fr = {}, Be = (e) => {
  let r;
  const n = /* @__PURE__ */ new Set(), s = (d, l) => {
    const f = typeof d == "function" ? d(r) : d;
    if (!Object.is(f, r)) {
      const p = r;
      r = l ?? (typeof f != "object" || f === null) ? f : Object.assign({}, r, f), n.forEach((m) => m(r, p));
    }
  }, t = () => r, o = { setState: s, getState: t, getInitialState: () => a, subscribe: (d) => (n.add(d), () => n.delete(d)), destroy: () => {
    (fr ? "production" : void 0) !== "production" && console.warn(
      "[DEPRECATED] The `destroy` method will be unsupported in a future version. Instead use unsubscribe function returned by subscribe. Everything will be garbage-collected if store is garbage-collected."
    ), n.clear();
  } }, a = r = e(s, t, o);
  return o;
}, Ue = (e) => e ? Be(e) : Be;
var ge = { exports: {} }, fe = {}, Y = { exports: {} }, pe = {};
/**
 * @license React
 * use-sync-external-store-shim.production.min.js
 *
 * Copyright (c) Facebook, Inc. and its affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */
var Ie;
function pr() {
  if (Ie) return pe;
  Ie = 1;
  var e = J;
  function r(l, f) {
    return l === f && (l !== 0 || 1 / l === 1 / f) || l !== l && f !== f;
  }
  var n = typeof Object.is == "function" ? Object.is : r, s = e.useState, t = e.useEffect, i = e.useLayoutEffect, u = e.useDebugValue;
  function c(l, f) {
    var p = f(), m = s({ inst: { value: p, getSnapshot: f } }), h = m[0].inst, _ = m[1];
    return i(function() {
      h.value = p, h.getSnapshot = f, o(h) && _({ inst: h });
    }, [l, p, f]), t(function() {
      return o(h) && _({ inst: h }), l(function() {
        o(h) && _({ inst: h });
      });
    }, [l]), u(p), p;
  }
  function o(l) {
    var f = l.getSnapshot;
    l = l.value;
    try {
      var p = f();
      return !n(l, p);
    } catch {
      return !0;
    }
  }
  function a(l, f) {
    return f();
  }
  var d = typeof window > "u" || typeof window.document > "u" || typeof window.document.createElement > "u" ? a : c;
  return pe.useSyncExternalStore = e.useSyncExternalStore !== void 0 ? e.useSyncExternalStore : d, pe;
}
var he = {};
/**
 * @license React
 * use-sync-external-store-shim.development.js
 *
 * Copyright (c) Facebook, Inc. and its affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */
var Ce;
function hr() {
  return Ce || (Ce = 1, process.env.NODE_ENV !== "production" && function() {
    typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ < "u" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart == "function" && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error());
    var e = J, r = e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
    function n(v) {
      {
        for (var y = arguments.length, x = new Array(y > 1 ? y - 1 : 0), k = 1; k < y; k++)
          x[k - 1] = arguments[k];
        s("error", v, x);
      }
    }
    function s(v, y, x) {
      {
        var k = r.ReactDebugCurrentFrame, O = k.getStackAddendum();
        O !== "" && (y += "%s", x = x.concat([O]));
        var I = x.map(function(T) {
          return String(T);
        });
        I.unshift("Warning: " + y), Function.prototype.apply.call(console[v], console, I);
      }
    }
    function t(v, y) {
      return v === y && (v !== 0 || 1 / v === 1 / y) || v !== v && y !== y;
    }
    var i = typeof Object.is == "function" ? Object.is : t, u = e.useState, c = e.useEffect, o = e.useLayoutEffect, a = e.useDebugValue, d = !1, l = !1;
    function f(v, y, x) {
      d || e.startTransition !== void 0 && (d = !0, n("You are using an outdated, pre-release alpha of React 18 that does not support useSyncExternalStore. The use-sync-external-store shim will not work correctly. Upgrade to a newer pre-release."));
      var k = y();
      if (!l) {
        var O = y();
        i(k, O) || (n("The result of getSnapshot should be cached to avoid an infinite loop"), l = !0);
      }
      var I = u({
        inst: {
          value: k,
          getSnapshot: y
        }
      }), T = I[0].inst, N = I[1];
      return o(function() {
        T.value = k, T.getSnapshot = y, p(T) && N({
          inst: T
        });
      }, [v, k, y]), c(function() {
        p(T) && N({
          inst: T
        });
        var oe = function() {
          p(T) && N({
            inst: T
          });
        };
        return v(oe);
      }, [v]), a(k), k;
    }
    function p(v) {
      var y = v.getSnapshot, x = v.value;
      try {
        var k = y();
        return !i(x, k);
      } catch {
        return !0;
      }
    }
    function m(v, y, x) {
      return y();
    }
    var h = typeof window < "u" && typeof window.document < "u" && typeof window.document.createElement < "u", _ = !h, b = _ ? m : f, S = e.useSyncExternalStore !== void 0 ? e.useSyncExternalStore : b;
    he.useSyncExternalStore = S, typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ < "u" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop == "function" && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error());
  }()), he;
}
var $e;
function Ve() {
  return $e || ($e = 1, process.env.NODE_ENV === "production" ? Y.exports = pr() : Y.exports = hr()), Y.exports;
}
/**
 * @license React
 * use-sync-external-store-shim/with-selector.production.min.js
 *
 * Copyright (c) Facebook, Inc. and its affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */
var Ae;
function mr() {
  if (Ae) return fe;
  Ae = 1;
  var e = J, r = Ve();
  function n(a, d) {
    return a === d && (a !== 0 || 1 / a === 1 / d) || a !== a && d !== d;
  }
  var s = typeof Object.is == "function" ? Object.is : n, t = r.useSyncExternalStore, i = e.useRef, u = e.useEffect, c = e.useMemo, o = e.useDebugValue;
  return fe.useSyncExternalStoreWithSelector = function(a, d, l, f, p) {
    var m = i(null);
    if (m.current === null) {
      var h = { hasValue: !1, value: null };
      m.current = h;
    } else h = m.current;
    m = c(function() {
      function b(k) {
        if (!S) {
          if (S = !0, v = k, k = f(k), p !== void 0 && h.hasValue) {
            var O = h.value;
            if (p(O, k)) return y = O;
          }
          return y = k;
        }
        if (O = y, s(v, k)) return O;
        var I = f(k);
        return p !== void 0 && p(O, I) ? O : (v = k, y = I);
      }
      var S = !1, v, y, x = l === void 0 ? null : l;
      return [function() {
        return b(d());
      }, x === null ? void 0 : function() {
        return b(x());
      }];
    }, [d, l, f, p]);
    var _ = t(a, m[0], m[1]);
    return u(function() {
      h.hasValue = !0, h.value = _;
    }, [_]), o(_), _;
  }, fe;
}
var me = {};
/**
 * @license React
 * use-sync-external-store-shim/with-selector.development.js
 *
 * Copyright (c) Facebook, Inc. and its affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */
var ze;
function _r() {
  return ze || (ze = 1, process.env.NODE_ENV !== "production" && function() {
    typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ < "u" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart == "function" && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error());
    var e = J, r = Ve();
    function n(d, l) {
      return d === l && (d !== 0 || 1 / d === 1 / l) || d !== d && l !== l;
    }
    var s = typeof Object.is == "function" ? Object.is : n, t = r.useSyncExternalStore, i = e.useRef, u = e.useEffect, c = e.useMemo, o = e.useDebugValue;
    function a(d, l, f, p, m) {
      var h = i(null), _;
      h.current === null ? (_ = {
        hasValue: !1,
        value: null
      }, h.current = _) : _ = h.current;
      var b = c(function() {
        var x = !1, k, O, I = function(W) {
          if (!x) {
            x = !0, k = W;
            var ce = p(W);
            if (m !== void 0 && _.hasValue) {
              var se = _.value;
              if (m(se, ce))
                return O = se, se;
            }
            return O = ce, ce;
          }
          var Ge = k, ae = O;
          if (s(Ge, W))
            return ae;
          var ue = p(W);
          return m !== void 0 && m(ae, ue) ? ae : (k = W, O = ue, ue);
        }, T = f === void 0 ? null : f, N = function() {
          return I(l());
        }, oe = T === null ? void 0 : function() {
          return I(T());
        };
        return [N, oe];
      }, [l, f, p, m]), S = b[0], v = b[1], y = t(d, S, v);
      return u(function() {
        _.hasValue = !0, _.value = y;
      }, [y]), o(y), y;
    }
    me.useSyncExternalStoreWithSelector = a, typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ < "u" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop == "function" && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error());
  }()), me;
}
process.env.NODE_ENV === "production" ? ge.exports = mr() : ge.exports = _r();
var Sr = ge.exports;
const vr = /* @__PURE__ */ Ke(Sr), { useDebugValue: yr } = J, { useSyncExternalStoreWithSelector: br } = vr, gr = (e) => e;
function w(e, r = gr, n) {
  const s = br(
    e.subscribe,
    e.getState,
    e.getServerState || e.getInitialState,
    r,
    n
  );
  return yr(s), s;
}
var Le = (e, r, n) => (t, i) => ({
  pastStates: (n == null ? void 0 : n.pastStates) || [],
  futureStates: (n == null ? void 0 : n.futureStates) || [],
  undo: (u = 1) => {
    var c, o;
    if (i().pastStates.length) {
      const a = ((c = n == null ? void 0 : n.partialize) == null ? void 0 : c.call(n, r())) || r(), d = i().pastStates.splice(-u, u), l = d.shift();
      e(l), t({
        pastStates: i().pastStates,
        futureStates: i().futureStates.concat(
          ((o = n == null ? void 0 : n.diff) == null ? void 0 : o.call(n, a, l)) || a,
          d.reverse()
        )
      });
    }
  },
  redo: (u = 1) => {
    var c, o;
    if (i().futureStates.length) {
      const a = ((c = n == null ? void 0 : n.partialize) == null ? void 0 : c.call(n, r())) || r(), d = i().futureStates.splice(-u, u), l = d.shift();
      e(l), t({
        pastStates: i().pastStates.concat(
          ((o = n == null ? void 0 : n.diff) == null ? void 0 : o.call(n, a, l)) || a,
          d.reverse()
        ),
        futureStates: i().futureStates
      });
    }
  },
  clear: () => t({ pastStates: [], futureStates: [] }),
  isTracking: !0,
  pause: () => t({ isTracking: !1 }),
  resume: () => t({ isTracking: !0 }),
  setOnSave: (u) => t({ _onSave: u }),
  // Internal properties
  _onSave: n == null ? void 0 : n.onSave,
  _handleSet: (u, c, o, a) => {
    var d, l;
    n != null && n.limit && i().pastStates.length >= (n == null ? void 0 : n.limit) && i().pastStates.shift(), (l = (d = i())._onSave) == null || l.call(d, u, o), t({
      pastStates: i().pastStates.concat(a || u),
      futureStates: []
    });
  }
}), kr = (e, r) => (s, t, i) => {
  var a, d;
  i.temporal = Ue(
    ((a = r == null ? void 0 : r.wrapTemporal) == null ? void 0 : a.call(r, Le(s, t, r))) || Le(s, t, r)
  );
  const u = ((d = r == null ? void 0 : r.handleSet) == null ? void 0 : d.call(
    r,
    i.temporal.getState()._handleSet
  )) || i.temporal.getState()._handleSet, c = (l) => {
    var m, h, _;
    if (!i.temporal.getState().isTracking) return;
    const f = ((m = r == null ? void 0 : r.partialize) == null ? void 0 : m.call(r, t())) || t(), p = (h = r == null ? void 0 : r.diff) == null ? void 0 : h.call(r, l, f);
    // If the user has provided a diff function but nothing has been changed, deltaState will be null
    p === null || // If the user has provided an equality function, use it
    (_ = r == null ? void 0 : r.equality) != null && _.call(r, l, f) || u(
      l,
      void 0,
      f,
      p
    );
  }, o = i.setState;
  return i.setState = (...l) => {
    var p;
    const f = ((p = r == null ? void 0 : r.partialize) == null ? void 0 : p.call(r, t())) || t();
    o(...l), c(f);
  }, e(
    // Modify the set function to call the userlandSet function
    (...l) => {
      var p;
      const f = ((p = r == null ? void 0 : r.partialize) == null ? void 0 : p.call(r, t())) || t();
      s(...l), c(f);
    },
    t,
    i
  );
};
const Er = {}, xr = (e) => (r, n, s) => {
  const t = s.subscribe;
  return s.subscribe = (u, c, o) => {
    let a = u;
    if (c) {
      const d = (o == null ? void 0 : o.equalityFn) || Object.is;
      let l = u(s.getState());
      a = (f) => {
        const p = u(f);
        if (!d(l, p)) {
          const m = l;
          c(l = p, m);
        }
      }, o != null && o.fireImmediately && c(l, l);
    }
    return t(a);
  }, e(r, n, s);
}, wr = xr;
function Pr(e, r) {
  let n;
  try {
    n = e();
  } catch {
    return;
  }
  return {
    getItem: (t) => {
      var i;
      const u = (o) => o === null ? null : JSON.parse(o, void 0), c = (i = n.getItem(t)) != null ? i : null;
      return c instanceof Promise ? c.then(u) : u(c);
    },
    setItem: (t, i) => n.setItem(
      t,
      JSON.stringify(i, void 0)
    ),
    removeItem: (t) => n.removeItem(t)
  };
}
const q = (e) => (r) => {
  try {
    const n = e(r);
    return n instanceof Promise ? n : {
      then(s) {
        return q(s)(n);
      },
      catch(s) {
        return this;
      }
    };
  } catch (n) {
    return {
      then(s) {
        return this;
      },
      catch(s) {
        return q(s)(n);
      }
    };
  }
}, Or = (e, r) => (n, s, t) => {
  let i = {
    getStorage: () => localStorage,
    serialize: JSON.stringify,
    deserialize: JSON.parse,
    partialize: (_) => _,
    version: 0,
    merge: (_, b) => ({
      ...b,
      ..._
    }),
    ...r
  }, u = !1;
  const c = /* @__PURE__ */ new Set(), o = /* @__PURE__ */ new Set();
  let a;
  try {
    a = i.getStorage();
  } catch {
  }
  if (!a)
    return e(
      (..._) => {
        console.warn(
          `[zustand persist middleware] Unable to update item '${i.name}', the given storage is currently unavailable.`
        ), n(..._);
      },
      s,
      t
    );
  const d = q(i.serialize), l = () => {
    const _ = i.partialize({ ...s() });
    let b;
    const S = d({ state: _, version: i.version }).then(
      (v) => a.setItem(i.name, v)
    ).catch((v) => {
      b = v;
    });
    if (b)
      throw b;
    return S;
  }, f = t.setState;
  t.setState = (_, b) => {
    f(_, b), l();
  };
  const p = e(
    (..._) => {
      n(..._), l();
    },
    s,
    t
  );
  let m;
  const h = () => {
    var _;
    if (!a) return;
    u = !1, c.forEach((S) => S(s()));
    const b = ((_ = i.onRehydrateStorage) == null ? void 0 : _.call(i, s())) || void 0;
    return q(a.getItem.bind(a))(i.name).then((S) => {
      if (S)
        return i.deserialize(S);
    }).then((S) => {
      if (S)
        if (typeof S.version == "number" && S.version !== i.version) {
          if (i.migrate)
            return i.migrate(
              S.state,
              S.version
            );
          console.error(
            "State loaded from storage couldn't be migrated since no migrate function was provided"
          );
        } else
          return S.state;
    }).then((S) => {
      var v;
      return m = i.merge(
        S,
        (v = s()) != null ? v : p
      ), n(m, !0), l();
    }).then(() => {
      b == null || b(m, void 0), u = !0, o.forEach((S) => S(m));
    }).catch((S) => {
      b == null || b(void 0, S);
    });
  };
  return t.persist = {
    setOptions: (_) => {
      i = {
        ...i,
        ..._
      }, _.getStorage && (a = _.getStorage());
    },
    clearStorage: () => {
      a == null || a.removeItem(i.name);
    },
    getOptions: () => i,
    rehydrate: () => h(),
    hasHydrated: () => u,
    onHydrate: (_) => (c.add(_), () => {
      c.delete(_);
    }),
    onFinishHydration: (_) => (o.add(_), () => {
      o.delete(_);
    })
  }, h(), m || p;
}, Mr = (e, r) => (n, s, t) => {
  let i = {
    storage: Pr(() => localStorage),
    partialize: (h) => h,
    version: 0,
    merge: (h, _) => ({
      ..._,
      ...h
    }),
    ...r
  }, u = !1;
  const c = /* @__PURE__ */ new Set(), o = /* @__PURE__ */ new Set();
  let a = i.storage;
  if (!a)
    return e(
      (...h) => {
        console.warn(
          `[zustand persist middleware] Unable to update item '${i.name}', the given storage is currently unavailable.`
        ), n(...h);
      },
      s,
      t
    );
  const d = () => {
    const h = i.partialize({ ...s() });
    return a.setItem(i.name, {
      state: h,
      version: i.version
    });
  }, l = t.setState;
  t.setState = (h, _) => {
    l(h, _), d();
  };
  const f = e(
    (...h) => {
      n(...h), d();
    },
    s,
    t
  );
  t.getInitialState = () => f;
  let p;
  const m = () => {
    var h, _;
    if (!a) return;
    u = !1, c.forEach((S) => {
      var v;
      return S((v = s()) != null ? v : f);
    });
    const b = ((_ = i.onRehydrateStorage) == null ? void 0 : _.call(i, (h = s()) != null ? h : f)) || void 0;
    return q(a.getItem.bind(a))(i.name).then((S) => {
      if (S)
        if (typeof S.version == "number" && S.version !== i.version) {
          if (i.migrate)
            return [
              !0,
              i.migrate(
                S.state,
                S.version
              )
            ];
          console.error(
            "State loaded from storage couldn't be migrated since no migrate function was provided"
          );
        } else
          return [!1, S.state];
      return [!1, void 0];
    }).then((S) => {
      var v;
      const [y, x] = S;
      if (p = i.merge(
        x,
        (v = s()) != null ? v : f
      ), n(p, !0), y)
        return d();
    }).then(() => {
      b == null || b(p, void 0), p = s(), u = !0, o.forEach((S) => S(p));
    }).catch((S) => {
      b == null || b(void 0, S);
    });
  };
  return t.persist = {
    setOptions: (h) => {
      i = {
        ...i,
        ...h
      }, h.storage && (a = h.storage);
    },
    clearStorage: () => {
      a == null || a.removeItem(i.name);
    },
    getOptions: () => i,
    rehydrate: () => m(),
    hasHydrated: () => u,
    onHydrate: (h) => (c.add(h), () => {
      c.delete(h);
    }),
    onFinishHydration: (h) => (o.add(h), () => {
      o.delete(h);
    })
  }, i.skipHydration || m(), p || f;
}, Tr = (e, r) => "getStorage" in r || "serialize" in r || "deserialize" in r ? ((Er ? "production" : void 0) !== "production" && console.warn(
  "[DEPRECATED] `getStorage`, `serialize` and `deserialize` options are deprecated. Use `storage` option instead."
), Or(e, r)) : Mr(e, r), Fr = Tr, Dr = (e) => (r, n, s) => (s.setState = (t, i, ...u) => {
  const c = typeof t == "function" ? lr(t) : t;
  return r(c, i, ...u);
}, e(s.setState, n, s)), Br = Dr;
dr();
const Nr = (e) => {
  const r = {
    data: {},
    mode: "local",
    brickMap: A(e.sections),
    themes: [],
    pages: [],
    datasources: [],
    datarecords: [],
    sitePrompt: ""
    // themes: [defaultTheme, { ...defaultTheme, id: "t2" }, { ...defaultTheme, id: "t3" }],
  };
  return Ue()(
    wr(
      kr(
        Br((n, s) => ({
          ...r,
          ...e,
          detachBrickFromContainer: (t) => n((i) => {
            var p;
            const u = i.brickMap.get(t);
            L(u, `Cannot detach brick ${t}, it does not exist in the brickMap`);
            const { brick: c, sectionId: o, parentId: a } = u;
            if (!a) {
              console.warn("Cannot detach brick %s, it is not in a container", t);
              return;
            }
            const d = B(a, i);
            if (!d) {
              console.error("Cannot detach brick %s, its parent %s does not exist", t, a);
              return;
            }
            const l = i.sections.find((m) => m.id === o);
            if (!l) {
              console.error("Cannot detach brick %s, its parent section %s does not exist", t, o);
              return;
            }
            d.props.$children = (p = d.props.$children) == null ? void 0 : p.filter(
              (m) => m.id !== t
            );
            const f = l.bricks.findIndex((m) => m.id === a);
            l.bricks.splice(f + 1, 0, {
              ...c
            }), i.brickMap = A(i.sections);
          }),
          createEmptySection: (t, i) => n((u) => {
            var d;
            const c = u.sections.length, o = 1 + (i ? ((d = u.sections.find((l) => l.id === i)) == null ? void 0 : d.order) ?? c : c), a = {
              id: t,
              order: o,
              label: `Section ${c + 1}`,
              bricks: [],
              props: {}
            };
            u.sections.forEach((l) => {
              l.order >= o && (l.order += 1);
            }), u.sections.push(a);
          }),
          addPage: (t) => n((i) => {
            i.pages.push(t), i.id === "_default_" && (i.id = t.id, i.path = t.path, i.label = t.label, i.sections = t.sections, t.attr && (i.attr = t.attr));
          }),
          isFirstSection: (t) => {
            var u;
            return ((u = s().sections.find((c) => c.order === 0)) == null ? void 0 : u.id) === t;
          },
          setSections: (t) => n((i) => {
            i.sections = t, i.brickMap = A(t);
          }),
          pickTheme: (t) => n((i) => {
            const u = i.themes.find((c) => c.id === t);
            if (!u) {
              console.error("Cannot pick theme %s, it does not exist", t);
              return;
            }
            i.theme = u;
          }),
          setThemes: (t) => n((i) => {
            i.themes = t;
          }),
          setSitemap: (t) => n((i) => {
            i.sitemap = t;
          }),
          getPageDataForDuplication: () => {
            const t = s(), i = t.sitemap.length + 1;
            return console.log("state.sitemap", t.sitemap), {
              id: `page-${H()}`,
              label: `${t.label} (page ${i})`,
              path: `${t.path}-${i}`,
              sections: t.sections,
              attr: t.attr,
              attributes: t.attributes,
              datasources: t.datasources,
              datarecords: t.datarecords
            };
          },
          isLastSection: (t) => {
            var u;
            const i = s();
            return ((u = i.sections.find((c) => c.order === i.sections.length - 1)) == null ? void 0 : u.id) === t;
          },
          addDatasource: (t) => n((i) => {
            if (i.datasources.find((c) => c.id === t.id)) {
              console.error("Cannot add datasource %s, it already exists", t.id);
              return;
            }
            i.datasources.push(t);
          }),
          addDatarecord: (t) => n((i) => {
            if (i.datarecords.find((c) => c.id === t.id)) {
              console.error("Cannot add datarecord %s, it already exists", t.id);
              return;
            }
            i.datarecords.push(t);
          }),
          addSection: (t) => n((i) => {
            i.sections.push(t);
          }),
          updateSection: (t, i) => n((u) => {
            const c = u.sections.findIndex((o) => o.id === t);
            c !== -1 && (u.sections[c] = {
              ...u.sections[c],
              ...i
            });
          }),
          duplicateSection: (t) => n((i) => {
            const u = i.sections.find((a) => a.id === t);
            if (!u) {
              console.error("Cannot duplicate section %s, it does not exist", t);
              return;
            }
            const c = i.sections.findIndex((a) => a.id === t), o = {
              ...u,
              id: `s_${H()}`,
              order: u.order + 1,
              // increment order to place it after the original
              label: `${u.label} (copy)`,
              // generate new bricks with new IDs
              bricks: u.bricks.map((a) => {
                var d;
                return {
                  ...a,
                  id: `b_${H()}`,
                  props: j({}, a.props, {
                    $children: (d = a.props.$children) == null ? void 0 : d.map((l) => ({
                      ...l,
                      id: `b_${H()}`
                    }))
                  })
                };
              })
            };
            i.sections.splice(c + 1, 0, o), i.brickMap = A(i.sections);
          }),
          deleteSection: (t) => n((i) => {
            if (!i.sections.find((c) => c.id === t))
              return console.warn("Cannot delete section %s: not found", t), null;
            i.brickMap.forEach((c) => {
              c.sectionId === t && i.brickMap.delete(c.brick.id);
            }), i.sections = i.sections.filter((c) => c.id !== t);
          }),
          getSection: (t) => s().sections.find((i) => i.id === t),
          moveSectionUp: (t) => n((i) => {
            const u = i.sections.find((a) => a.id === t);
            i.sections.findIndex((a) => a.id === t), L(u, "Section not found");
            const c = i.sections.find((a) => a.order === u.order - 1);
            i.sections.findIndex((a) => a.order === u.order - 1), L(c, "Previous section not found");
            const o = u.order;
            u.order = c.order, c.order = o;
          }),
          moveSectionDown: (t) => n((i) => {
            const u = i.sections.find((f) => f.id === t), c = i.sections.findIndex((f) => f.id === t);
            L(u, "Section not found");
            const o = i.sections.find((f) => f.order === u.order + 1), a = i.sections.findIndex((f) => f.order === u.order + 1);
            L(o, "Next section not found");
            const d = u.order, l = o.order;
            i.sections[c].order = l, i.sections[a].order = d;
          }),
          reorderSections: (t) => n((i) => {
            const u = [];
            let c = 0;
            t.forEach((o) => {
              const a = i.sections.find((d) => d.id === o);
              a && u.push({ ...a, order: ++c });
            }), i.sections.forEach((o) => {
              t.includes(o.id) || u.push({ ...o, order: ++c });
            }), i.sections = u, i.brickMap = A(i.sections);
          }),
          setLastLoaded: () => n((t) => {
            t.lastLoaded = /* @__PURE__ */ new Date();
          }),
          deleteBrick: (t) => n((i) => {
            const u = i.brickMap.get(t);
            if (!u) {
              console.error("Cannot delete brick %s, it does not exist", t);
              return;
            }
            const c = [], o = (f) => {
              var m;
              const p = i.brickMap.get(f);
              (m = p == null ? void 0 : p.brick.props) != null && m.$children && p.brick.props.$children.forEach((_) => {
                c.push(_.id), o(_.id);
              });
            };
            o(t);
            const { sectionId: a, parentId: d } = u, l = i.sections.find((f) => f.id === a);
            if (d) {
              const f = B(d, i);
              if (f != null && f.props.$children) {
                const p = f.props.$children.findIndex((m) => m.id === t);
                f.props.$children.splice(p, 1);
              }
            } else l && (l.bricks = l.bricks.filter((f) => f.id !== t));
            i.brickMap.delete(t), c.forEach((f) => {
              i.brickMap.delete(f);
            });
          }),
          duplicateBrick: (t) => n((i) => {
            const u = i.brickMap.get(t);
            if (!u) {
              console.error("Cannot duplicate brick %s, it does not exist", t);
              return;
            }
            const c = (f) => {
              const p = `brick-${H()}`, m = {
                ...f,
                id: p,
                props: { ...f.props },
                mobileProps: f.mobileProps ? { ...f.mobileProps } : void 0
              };
              if (f.props.$children) {
                const h = f.props.$children;
                m.props.$children = h.map((_) => c(_));
              }
              return m;
            }, o = c(u.brick), a = (f, p, m) => {
              i.brickMap.set(f.id, {
                brick: f,
                sectionId: p,
                parentId: m
              }), f.props.$children && f.props.$children.forEach((_) => a(_, p, f.id));
            }, { sectionId: d, parentId: l } = u;
            if (l) {
              const f = B(l, i);
              if (f != null && f.props.$children) {
                const m = f.props.$children.findIndex((h) => h.id === t);
                f.props.$children.splice(m + 1, 0, o);
              }
            } else {
              const f = i.sections.find((p) => p.id === d);
              if (f) {
                const p = f.bricks.findIndex((m) => m.id === t);
                f.bricks.splice(p + 1, 0, o);
              }
            }
            a(o, d, l);
          }),
          updatePropsMapping: (t, i) => n((u) => {
            const c = B(t, u);
            c ? (c.propsMapping = Ye({}, c.propsMapping, i), c.props.lastTouched = Date.now(), u.brickMap = A(u.sections)) : console.error(
              "Cannot update props mapping for brick %s, it does not exist in the brick map",
              t
            );
          }),
          updateBrickProps: (t, i, u) => n((c) => {
            const o = B(t, c);
            o ? (u ? o.mobileProps = j({}, o.mobileProps, i, {
              lastTouched: Date.now()
            }) : o.props = j({}, o.props, i, {
              lastTouched: Date.now()
            }), c.brickMap = A(c.sections)) : console.error("Cannot update props for brick %s, it does not exist in the brick map", t);
          }),
          updateSectionProps: (t, i, u) => n((c) => {
            const o = c.sections.find((a) => a.id === t);
            o ? u ? o.mobileProps = j({}, o.mobileProps, i, {
              lastTouched: Date.now()
            }) : o.props = j({}, o.props, i, {
              lastTouched: Date.now()
            }) : console.warn("Cannot update section %s, it does not exist", t);
          }),
          /**
           * Move a brick inside its container or its section
           * If the brick does not belong to a container, it will be moved within its section
           */
          moveBrickWithin: (t, i) => n((u) => {
            let c = [], o = -1;
            const a = u.getParentBrick(t);
            a ? (c = B(a.id, u).props.$children, o = c.findIndex((p) => p.id === t)) : (c = ke(t, u).bricks, o = c.findIndex((p) => p.id === t));
            const d = i === "previous" ? Math.max(0, o - 1) : Math.min(c.length - 1, o + 1);
            if (d === o)
              return;
            const [l] = c.splice(o, 1);
            c.splice(d, 0, l), u.brickMap = A(u.sections);
          }),
          /**
           * Reorder a brick within its section using indices
           */
          reorderBrickWithin: (t, i) => n((u) => {
            const c = u.brickMap.get(t);
            if (!c) {
              console.error("Cannot reorder brick %s, brick mapping not found", t);
              return;
            }
            const { sectionId: o, parentId: a } = c;
            if (a) {
              const d = B(a, u);
              if (d != null && d.props.$children) {
                const l = d.props.$children, f = l.findIndex((m) => m.id === t);
                if (f === -1) {
                  console.error("Cannot reorder brick %s, it does not exist in parent's children", t);
                  return;
                }
                const [p] = l.splice(f, 1);
                l.splice(i, 0, p);
              }
            } else {
              const d = u.sections.find((l) => l.id === o);
              if (d) {
                const l = d.bricks.findIndex((p) => p.id === t);
                if (l === -1) {
                  console.error(
                    "Cannot reorder brick %s, it does not exist in section %s",
                    t,
                    o
                  );
                  return;
                }
                const [f] = d.bricks.splice(l, 1);
                d.bricks.splice(i, 0, f);
              }
            }
          }),
          moveBrickToContainerBrick: (t, i, u) => n((c) => {
            const o = c.getBrick(t), a = B(i, c), d = c.brickMap.get(t);
            if (!o || !a || !d) {
              console.error("Cannot move brick %s to new parent, brick or new parent is null", t);
              return;
            }
            if (!("$children" in a.props)) {
              console.error("Cannot move brick %s, parent brick %s is not a container", t, i);
              return;
            }
            const { sectionId: l, parentId: f } = d;
            if (f) {
              const m = B(f, c);
              m != null && m.props.$children && (m.props.$children = m.props.$children.filter(
                (h) => h.id !== t
              ));
            } else {
              const m = c.sections.find((h) => h.id === l);
              m && (m.bricks = m.bricks.filter((h) => h.id !== t));
            }
            a.props.$children || (a.props.$children = []), a.props.$children.splice(u, 0, o);
            const p = c.brickMap.get(i);
            if (p) {
              c.brickMap.set(t, {
                brick: o,
                sectionId: p.sectionId,
                parentId: i
              });
              const m = (h, _) => {
                var S;
                const b = c.brickMap.get(h);
                (S = b == null ? void 0 : b.brick.props) != null && S.$children && b.brick.props.$children.forEach((y) => {
                  c.brickMap.set(y.id, {
                    brick: y,
                    sectionId: _,
                    parentId: h
                  }), m(y.id, _);
                });
              };
              m(t, p.sectionId);
            }
          }),
          moveBrickToSection: (t, i, u) => n((c) => {
            var m;
            const o = c.getBrick(t);
            i || (i = (m = c.brickMap.get(t)) == null ? void 0 : m.sectionId);
            const a = c.sections.find((h) => h.id === i), d = c.brickMap.get(t);
            if (!o || !a || !d) {
              console.error(
                "Cannot move brick %s to section %s, brick or section not found",
                t,
                i
              );
              return;
            }
            const { sectionId: l, parentId: f } = d;
            if (f) {
              const h = B(f, c);
              h != null && h.props.$children && (h.props.$children = h.props.$children.filter(
                (_) => _.id !== t
              ));
            } else {
              const h = c.sections.find((_) => _.id === l);
              h && (h.bricks = h.bricks.filter((_) => _.id !== t));
            }
            typeof u == "number" ? a.bricks.splice(u, 0, o) : a.bricks.push(o), c.brickMap.set(t, {
              brick: o,
              sectionId: i,
              parentId: null
              // Top level in section
            });
            const p = (h, _, b) => {
              var v;
              const S = c.brickMap.get(h);
              (v = S == null ? void 0 : S.brick.props) != null && v.$children && S.brick.props.$children.forEach((x) => {
                c.brickMap.set(x.id, {
                  brick: x,
                  sectionId: _,
                  parentId: h
                }), p(x.id, _);
              });
            };
            p(t, i);
          }),
          /**
           * @deprecated Use getBrickFromDraft instead
           */
          getBrick: (t) => {
            var i;
            return (i = s().brickMap.get(t)) == null ? void 0 : i.brick;
          },
          getParentBrick: (t) => {
            var c;
            const i = s().brickMap, { parentId: u } = i.get(t) ?? {};
            if (u)
              return (c = i.get(u)) == null ? void 0 : c.brick;
          },
          getPositionWithinParent: (t) => {
            const i = s().getParentBrick(t);
            if (i && "$children" in i.props)
              return i.props.$children.findIndex((u) => u.id === t);
          },
          canMoveToWithinParent: (t, i) => {
            const u = s().getParentBrick(t);
            if (u && "$children" in u.props) {
              const a = u.props.$children, d = a.findIndex((l) => l.id === t);
              return i === "previous" ? d > 0 : d < a.length - 1;
            }
            const c = ke(t, s()), o = (c == null ? void 0 : c.bricks.findIndex((a) => a.id === t)) ?? -1;
            return i === "previous" ? o > 0 : o < (c == null ? void 0 : c.bricks.length) - 1;
          },
          setPreviewTheme: (t) => n((i) => {
            i.previewTheme = t;
          }),
          validatePreviewTheme: (t) => n((i) => {
            i.previewTheme && t && (i.theme = i.previewTheme), i.previewTheme = void 0;
          }),
          cancelPreviewTheme: () => n((t) => {
            t.previewTheme = void 0;
          }),
          setTheme: (t) => n((i) => {
            i.theme = t;
          }),
          toggleBrickVisibility: (t, i) => n((u) => {
            var o, a;
            const c = B(t, u);
            c && ((o = c.props).hidden ?? (o.hidden = { desktop: !1, mobile: !1 }), c.props.hidden[i] = !((a = c.props.hidden) != null && a[i]));
          }),
          addBrick: (t, i, u, c) => n((o) => {
            var d;
            const a = o.sections.find((l) => l.id === i);
            if (!a) {
              console.error("Cannot add brick, section %s does not exist", i);
              return;
            }
            if (c) {
              if (console.log("Adding brick to parent container", c), !$r(c, o)) {
                console.warn("Cannot add brick, parent container %s does not exist", c);
                return;
              }
              const f = o.sections.find((m) => m.id === i);
              if (!f) {
                console.warn("Cannot add brick, parent section %s does not exist", i);
                return;
              }
              const p = f.bricks.find((m) => m.id === c);
              if (!p) {
                console.warn(
                  "Cannot add brick, parent brick %s does not exist in section %s",
                  c,
                  i
                );
                return;
              }
              p.props.$children || (console.warn("Brick added to a container without $children, initializing it"), p.props.$children = []), p.props.$children.push(t);
            } else
              a.bricks.splice(u, 0, t);
            if (o.brickMap.set(t.id, {
              brick: t,
              sectionId: i,
              parentId: c
            }), (d = t.props) != null && d.$children) {
              const l = (f, p) => {
                f.forEach((m) => {
                  var h;
                  o.brickMap.set(m.id, {
                    brick: m,
                    sectionId: i,
                    parentId: p
                  }), (h = m.props) != null && h.$children && l(m.props.$children, m.id);
                });
              };
              console.log("Adding children to brick map", t.props.$children), l(t.props.$children, t.id);
            }
          }),
          updateAttributes: (t) => n((i) => {
            i.attr = { ...s().attr, ...t };
          }),
          setVersion: (t) => n((i) => {
            i.version = t;
          }),
          adjustMobileLayout: () => n((t) => {
          }),
          setLastSaved: (t) => n((i) => {
            i.lastSaved = t;
          }),
          setDirty: (t) => n((i) => {
            i.dirty = t;
          })
        })),
        {
          // limit undo history to 100
          limit: 100,
          equality: (n, s) => Re(n, s),
          partialize: (n) => Object.fromEntries(
            Object.entries(n).filter(([s]) => ["sections", "attr"].includes(s))
          )
          // handleSet: (handleSet) =>
          //   debounce<typeof handleSet>((state) => {
          //     if (state) {
          //       handleSet(state);
          //     }
          //   }, 200),
        }
      )
    )
  );
}, Ir = Xe(null), E = () => {
  const e = Qe(Ir);
  return L(e, "useDraftStoreContext must be used within a DraftStoreContext"), e;
}, Wr = () => E().temporal.getState(), jr = () => {
  const e = E();
  return w(e, (r) => r.sitemap);
}, Hr = () => {
  const e = E();
  return w(e, (r) => {
    const n = r.sitemap.length > 0, s = r.themes.length > 0, t = n && s && r.sitemap.length > 0, i = new URL(window.location.href).searchParams.get("action") === "generate";
    return {
      hasSitemap: n,
      hasThemesGenerated: s,
      sitemap: r.sitemap,
      pages: r.pages,
      isReady: !i || t || !1
    };
  });
}, Ur = () => {
  const e = E(), r = w(e, (s) => s.pages);
  return {
    site: Cr(),
    pages: r
  };
}, Vr = () => {
  const e = E();
  return w(e, (r) => r.themes);
}, Gr = () => {
  const e = E();
  return w(e);
};
function Kr(e) {
  const r = E(), n = w(r, (t) => t.getParentBrick);
  let s = n(e);
  for (; s; ) {
    if (s.type === "dynamic")
      return !0;
    e = s.id, s = n(e);
  }
  return !1;
}
function qr(e) {
  const r = E(), n = w(r, (t) => t.getParentBrick);
  let s = n(e);
  for (; s; ) {
    if (s.type === "dynamic")
      return s;
    e = s.id, s = n(e);
  }
  return null;
}
function Jr(e) {
  const r = E();
  return w(r, (s) => s.getParentBrick)(e);
}
function Yr() {
  const e = E();
  return w(e, (r) => r.version);
}
function Xr() {
  const e = E();
  return w(e, (r) => r.lastSaved);
}
const Qr = () => {
  const e = E(), r = w(e, (n) => n.sections);
  return qe(r);
}, Zr = (e) => {
  const r = E();
  return w(r, (n) => {
    const s = n.sections.find((t) => e && t.id === e);
    return s ? {
      section: s,
      bricks: Array.from(n.brickMap).filter(([, t]) => t.sectionId === e)
    } : null;
  });
}, et = (e) => {
  const r = E();
  return w(r, (n) => e ? B(e, n) : null);
}, rt = (e) => {
  const r = E();
  return w(r, (n) => ke(e, n));
}, tt = () => {
  const e = E();
  return w(e, (r) => r.attr);
}, nt = () => {
  const e = E();
  return w(e, (r) => r.attributes ?? r.siteAttributes);
}, it = () => {
  const e = E();
  return w(e, (r) => ({
    deleteBrick: r.deleteBrick,
    detachBrickFromContainer: r.detachBrickFromContainer,
    setSections: r.setSections,
    setThemes: r.setThemes,
    setTheme: r.setTheme,
    pickTheme: r.pickTheme,
    setSitemap: r.setSitemap,
    addPage: r.addPage,
    addDatasource: r.addDatasource,
    addDatarecord: r.addDatarecord,
    duplicateBrick: r.duplicateBrick,
    addBrick: r.addBrick,
    getBrick: r.getBrick,
    validatePreviewTheme: r.validatePreviewTheme,
    adjustMobileLayout: r.adjustMobileLayout,
    duplicateSection: r.duplicateSection,
    toggleBrickVisibilityPerBreakpoint: r.toggleBrickVisibility,
    getParentBrick: r.getParentBrick,
    updateBrickProps: r.updateBrickProps,
    updatePropsMapping: r.updatePropsMapping,
    moveBrickWithin: r.moveBrickWithin,
    reorderBrickWithin: r.reorderBrickWithin,
    getPositionWithinParent: r.getPositionWithinParent,
    canMoveToWithinParent: r.canMoveToWithinParent,
    moveBrickToContainerBrick: r.moveBrickToContainerBrick,
    moveBrickToSection: r.moveBrickToSection,
    deleteSection: r.deleteSection,
    moveSectionUp: r.moveSectionUp,
    moveSectionDown: r.moveSectionDown,
    reorderSections: r.reorderSections,
    updateSection: r.updateSection,
    updateSectionProps: r.updateSectionProps,
    addSection: r.addSection,
    createEmptySection: r.createEmptySection,
    isFirstSection: r.isFirstSection,
    isLastSection: r.isLastSection
  }));
}, ot = () => {
  const e = E();
  return w(e, (r) => ({
    id: r.id,
    path: r.path,
    label: r.label,
    siteLabel: r.siteLabel,
    siteId: r.siteId,
    hostname: r.hostname
  }));
}, Cr = () => {
  const e = E();
  return w(e, (n) => ({
    id: n.siteId,
    label: n.label,
    sitemap: n.sitemap,
    attr: n.attr,
    theme: n.theme,
    themes: n.themes,
    attributes: n.siteAttributes,
    hostname: n.hostname,
    datasources: n.datasources,
    datarecords: n.datarecords,
    sitePrompt: n.sitePrompt
  }));
}, ct = () => {
  const e = E();
  return w(e, (r) => r.theme);
}, st = (e) => {
  const r = E();
  ee(() => r.subscribe((n) => (n == null ? void 0 : n.sections) ?? [], Je(e, 200), {
    fireImmediately: !1
  }), []);
}, at = (e) => {
  const r = E();
  ee(() => r.subscribe((n) => n.attr, e, {
    equalityFn: Re
  }), []);
}, ut = (e) => {
  const r = E();
  ee(() => r.subscribe((n) => n.theme, e), []);
}, dt = (e) => {
  const r = E();
  ee(() => r.subscribe((n) => n.path, e), []);
};
function $r(e, r) {
  const { brick: n } = r.brickMap.get(e) ?? {};
  return n;
}
function ke(e, r) {
  const n = r.brickMap.get(e);
  if (n)
    return r.sections.find((s) => s.id === n.sectionId);
}
function B(e, r) {
  for (const n of r.sections) {
    const s = n.bricks.find((u) => u.id === e);
    if (s)
      return s;
    const t = (u) => {
      var c;
      for (const o of u) {
        if (o.id === e)
          return o;
        if ((c = o.props) != null && c.$children) {
          const a = t(o.props.$children);
          if (a)
            return a;
        }
      }
    }, i = t(n.bricks);
    if (i)
      return i;
  }
  return null;
}
const lt = () => {
  const e = E();
  return w(e, (r) => r.sitePrompt);
};
function A(e) {
  const r = /* @__PURE__ */ new Map();
  function n(s, t, i) {
    var u;
    r.set(s.id, { brick: s, sectionId: t, parentId: i }), (u = s.props) != null && u.$children && s.props.$children.forEach((o) => n(o, t, s.id));
  }
  return e.forEach((s) => {
    s.bricks.forEach((t) => n(t, s.id, null));
  }), r;
}
export {
  dr as A,
  w as B,
  E as C,
  Ir as D,
  Ue as E,
  wr as F,
  Fr as G,
  kr as H,
  Br as I,
  Kr as J,
  Cr as K,
  ot as a,
  st as b,
  at as c,
  dt as d,
  ut as e,
  it as f,
  et as g,
  Wr as h,
  Hr as i,
  ct as j,
  Qr as k,
  Vr as l,
  Nr as m,
  Yr as n,
  Xr as o,
  jr as p,
  lt as q,
  Ur as r,
  Zr as s,
  L as t,
  Gr as u,
  tt as v,
  qr as w,
  rt as x,
  Jr as y,
  nt as z
};
//# sourceMappingURL=use-page-data.ClF2QKbJ.js.map
