import { g as et, aa as tt, D as W, C as H } from "./_commonjsHelpers.DgVrNa4W.js";
import "@sinclair/typebox";
import { debounce as rt, isEqual as Ee } from "lodash-es";
import Z, { createContext as je, useContext as We, useEffect as te } from "react";
/*! Upstart.gg - Copyright (C) 2024 Flippable - https://github.com/upstart-gg/upstart/blob/main/LICENSE */
var jt = 24, nt = 24;
/*! Upstart.gg - Copyright (C) 2024 Flippable - https://github.com/upstart-gg/upstart/blob/main/LICENSE */
var Oe = "Invariant failed";
function A(e, t) {
  if (e) return;
  let i = typeof t == "function" ? t() : t, s = i ? `${Oe}: ${i}` : Oe;
  throw new Error(s);
}
var He = Symbol.for("immer-nothing"), Te = Symbol.for("immer-draftable"), x = Symbol.for("immer-state"), it = 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 T(e, ...t) {
  if (process.env.NODE_ENV !== "production") {
    const i = it[e], s = typeof i == "function" ? i.apply(null, t) : i;
    throw new Error(`[Immer] ${s}`);
  }
  throw new Error(
    `[Immer] minified error nr: ${e}. Full error at: https://bit.ly/3cXEKWf`
  );
}
var F = Object.getPrototypeOf;
function V(e) {
  return !!e && !!e[x];
}
function z(e) {
  var t;
  return e ? Ge(e) || Array.isArray(e) || !!e[Te] || !!((t = e.constructor) != null && t[Te]) || ne(e) || ie(e) : !1;
}
var ot = Object.prototype.constructor.toString();
function Ge(e) {
  if (!e || typeof e != "object")
    return !1;
  const t = F(e);
  if (t === null)
    return !0;
  const i = Object.hasOwnProperty.call(t, "constructor") && t.constructor;
  return i === Object ? !0 : typeof i == "function" && Function.toString.call(i) === ot;
}
function G(e, t) {
  re(e) === 0 ? Reflect.ownKeys(e).forEach((i) => {
    t(i, e[i], e);
  }) : e.forEach((i, s) => t(s, i, e));
}
function re(e) {
  const t = e[x];
  return t ? t.type_ : Array.isArray(e) ? 1 : ne(e) ? 2 : ie(e) ? 3 : 0;
}
function _e(e, t) {
  return re(e) === 2 ? e.has(t) : Object.prototype.hasOwnProperty.call(e, t);
}
function Ue(e, t, i) {
  const s = re(e);
  s === 2 ? e.set(t, i) : s === 3 ? e.add(i) : e[t] = i;
}
function st(e, t) {
  return e === t ? e !== 0 || 1 / e === 1 / t : e !== e && t !== t;
}
function ne(e) {
  return e instanceof Map;
}
function ie(e) {
  return e instanceof Set;
}
function M(e) {
  return e.copy_ || e.base_;
}
function ge(e, t) {
  if (ne(e))
    return new Map(e);
  if (ie(e))
    return new Set(e);
  if (Array.isArray(e))
    return Array.prototype.slice.call(e);
  const i = Ge(e);
  if (t === !0 || t === "class_only" && !i) {
    const s = Object.getOwnPropertyDescriptors(e);
    delete s[x];
    let r = Reflect.ownKeys(s);
    for (let n = 0; n < r.length; n++) {
      const u = r[n], 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(F(e), s);
  } else {
    const s = F(e);
    if (s !== null && i)
      return { ...e };
    const r = Object.create(s);
    return Object.assign(r, e);
  }
}
function Pe(e, t = !1) {
  return oe(e) || V(e) || !z(e) || (re(e) > 1 && (e.set = e.add = e.clear = e.delete = ct), Object.freeze(e), t && Object.entries(e).forEach(([i, s]) => Pe(s, !0))), e;
}
function ct() {
  T(2);
}
function oe(e) {
  return Object.isFrozen(e);
}
var ve = {};
function R(e) {
  const t = ve[e];
  return t || T(0, e), t;
}
function at(e, t) {
  ve[e] || (ve[e] = t);
}
var U;
function X() {
  return U;
}
function ut(e, t) {
  return {
    drafts_: [],
    parent_: e,
    immer_: t,
    // 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 Ie(e, t) {
  t && (R("Patches"), e.patches_ = [], e.inversePatches_ = [], e.patchListener_ = t);
}
function be(e) {
  ye(e), e.drafts_.forEach(dt), e.drafts_ = null;
}
function ye(e) {
  e === U && (U = e.parent_);
}
function Be(e) {
  return U = ut(U, e);
}
function dt(e) {
  const t = e[x];
  t.type_ === 0 || t.type_ === 1 ? t.revoke_() : t.revoked_ = !0;
}
function De(e, t) {
  t.unfinalizedDrafts_ = t.drafts_.length;
  const i = t.drafts_[0];
  return e !== void 0 && e !== i ? (i[x].modified_ && (be(t), T(4)), z(e) && (e = Q(t, e), t.parent_ || ee(t, e)), t.patches_ && R("Patches").generateReplacementPatches_(
    i[x].base_,
    e,
    t.patches_,
    t.inversePatches_
  )) : e = Q(t, i, []), be(t), t.patches_ && t.patchListener_(t.patches_, t.inversePatches_), e !== He ? e : void 0;
}
function Q(e, t, i) {
  if (oe(t))
    return t;
  const s = t[x];
  if (!s)
    return G(
      t,
      (r, n) => Ce(e, s, t, r, n, i)
    ), t;
  if (s.scope_ !== e)
    return t;
  if (!s.modified_)
    return ee(e, s.base_, !0), s.base_;
  if (!s.finalized_) {
    s.finalized_ = !0, s.scope_.unfinalizedDrafts_--;
    const r = s.copy_;
    let n = r, u = !1;
    s.type_ === 3 && (n = new Set(r), r.clear(), u = !0), G(
      n,
      (c, o) => Ce(e, s, r, c, o, i, u)
    ), ee(e, r, !1), i && e.patches_ && R("Patches").generatePatches_(
      s,
      i,
      e.patches_,
      e.inversePatches_
    );
  }
  return s.copy_;
}
function Ce(e, t, i, s, r, n, u) {
  if (process.env.NODE_ENV !== "production" && r === i && T(5), V(r)) {
    const c = n && t && t.type_ !== 3 && // Set objects are atomic since they have no keys.
    !_e(t.assigned_, s) ? n.concat(s) : void 0, o = Q(e, r, c);
    if (Ue(i, s, o), V(o))
      e.canAutoFreeze_ = !1;
    else
      return;
  } else u && i.add(r);
  if (z(r) && !oe(r)) {
    if (!e.immer_.autoFreeze_ && e.unfinalizedDrafts_ < 1)
      return;
    Q(e, r), (!t || !t.scope_.parent_) && typeof s != "symbol" && Object.prototype.propertyIsEnumerable.call(i, s) && ee(e, r);
  }
}
function ee(e, t, i = !1) {
  !e.parent_ && e.immer_.autoFreeze_ && e.canAutoFreeze_ && Pe(t, i);
}
function lt(e, t) {
  const i = Array.isArray(e), s = {
    type_: i ? 1 : 0,
    // Track which produce call this is associated with.
    scope_: t ? t.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_: t,
    // 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 r = s, n = we;
  i && (r = [s], n = K);
  const { revoke: u, proxy: c } = Proxy.revocable(r, n);
  return s.draft_ = c, s.revoke_ = u, c;
}
var we = {
  get(e, t) {
    if (t === x)
      return e;
    const i = M(e);
    if (!_e(i, t))
      return ft(e, i, t);
    const s = i[t];
    return e.finalized_ || !z(s) ? s : s === le(e.base_, t) ? (fe(e), e.copy_[t] = q(s, e)) : s;
  },
  has(e, t) {
    return t in M(e);
  },
  ownKeys(e) {
    return Reflect.ownKeys(M(e));
  },
  set(e, t, i) {
    const s = Ke(M(e), t);
    if (s != null && s.set)
      return s.set.call(e.draft_, i), !0;
    if (!e.modified_) {
      const r = le(M(e), t), n = r == null ? void 0 : r[x];
      if (n && n.base_ === i)
        return e.copy_[t] = i, e.assigned_[t] = !1, !0;
      if (st(i, r) && (i !== void 0 || _e(e.base_, t)))
        return !0;
      fe(e), $(e);
    }
    return e.copy_[t] === i && // special case: handle new props with value 'undefined'
    (i !== void 0 || t in e.copy_) || // special case: NaN
    Number.isNaN(i) && Number.isNaN(e.copy_[t]) || (e.copy_[t] = i, e.assigned_[t] = !0), !0;
  },
  deleteProperty(e, t) {
    return le(e.base_, t) !== void 0 || t in e.base_ ? (e.assigned_[t] = !1, fe(e), $(e)) : delete e.assigned_[t], e.copy_ && delete e.copy_[t], !0;
  },
  // Note: We never coerce `desc.value` into an Immer draft, because we can't make
  // the same guarantee in ES5 mode.
  getOwnPropertyDescriptor(e, t) {
    const i = M(e), s = Reflect.getOwnPropertyDescriptor(i, t);
    return s && {
      writable: !0,
      configurable: e.type_ !== 1 || t !== "length",
      enumerable: s.enumerable,
      value: i[t]
    };
  },
  defineProperty() {
    T(11);
  },
  getPrototypeOf(e) {
    return F(e.base_);
  },
  setPrototypeOf() {
    T(12);
  }
}, K = {};
G(we, (e, t) => {
  K[e] = function() {
    return arguments[0] = arguments[0][0], t.apply(this, arguments);
  };
});
K.deleteProperty = function(e, t) {
  return process.env.NODE_ENV !== "production" && isNaN(parseInt(t)) && T(13), K.set.call(this, e, t, void 0);
};
K.set = function(e, t, i) {
  return process.env.NODE_ENV !== "production" && t !== "length" && isNaN(parseInt(t)) && T(14), we.set.call(this, e[0], t, i, e[0]);
};
function le(e, t) {
  const i = e[x];
  return (i ? M(i) : e)[t];
}
function ft(e, t, i) {
  var r;
  const s = Ke(t, i);
  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!
    (r = s.get) == null ? void 0 : r.call(e.draft_)
  ) : void 0;
}
function Ke(e, t) {
  if (!(t in e))
    return;
  let i = F(e);
  for (; i; ) {
    const s = Object.getOwnPropertyDescriptor(i, t);
    if (s)
      return s;
    i = F(i);
  }
}
function $(e) {
  e.modified_ || (e.modified_ = !0, e.parent_ && $(e.parent_));
}
function fe(e) {
  e.copy_ || (e.copy_ = ge(
    e.base_,
    e.scope_.immer_.useStrictShallowCopy_
  ));
}
var pt = class {
  constructor(e) {
    this.autoFreeze_ = !0, this.useStrictShallowCopy_ = !1, this.produce = (t, i, s) => {
      if (typeof t == "function" && typeof i != "function") {
        const n = i;
        i = t;
        const u = this;
        return function(o = n, ...a) {
          return u.produce(o, (d) => i.call(this, d, ...a));
        };
      }
      typeof i != "function" && T(6), s !== void 0 && typeof s != "function" && T(7);
      let r;
      if (z(t)) {
        const n = Be(this), u = q(t, void 0);
        let c = !0;
        try {
          r = i(u), c = !1;
        } finally {
          c ? be(n) : ye(n);
        }
        return Ie(n, s), De(r, n);
      } else if (!t || typeof t != "object") {
        if (r = i(t), r === void 0 && (r = t), r === He && (r = void 0), this.autoFreeze_ && Pe(r, !0), s) {
          const n = [], u = [];
          R("Patches").generateReplacementPatches_(t, r, n, u), s(n, u);
        }
        return r;
      } else
        T(1, t);
    }, this.produceWithPatches = (t, i) => {
      if (typeof t == "function")
        return (u, ...c) => this.produceWithPatches(u, (o) => t(o, ...c));
      let s, r;
      return [this.produce(t, i, (u, c) => {
        s = u, r = c;
      }), s, r];
    }, 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) {
    z(e) || T(8), V(e) && (e = ht(e));
    const t = Be(this), i = q(e, void 0);
    return i[x].isManual_ = !0, ye(t), i;
  }
  finishDraft(e, t) {
    const i = e && e[x];
    (!i || !i.isManual_) && T(9);
    const { scope_: s } = i;
    return Ie(s, t), De(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, t) {
    let i;
    for (i = t.length - 1; i >= 0; i--) {
      const r = t[i];
      if (r.path.length === 0 && r.op === "replace") {
        e = r.value;
        break;
      }
    }
    i > -1 && (t = t.slice(i + 1));
    const s = R("Patches").applyPatches_;
    return V(e) ? s(e, t) : this.produce(
      e,
      (r) => s(r, t)
    );
  }
};
function q(e, t) {
  const i = ne(e) ? R("MapSet").proxyMap_(e, t) : ie(e) ? R("MapSet").proxySet_(e, t) : lt(e, t);
  return (t ? t.scope_ : X()).drafts_.push(i), i;
}
function ht(e) {
  return V(e) || T(10, e), qe(e);
}
function qe(e) {
  if (!z(e) || oe(e))
    return e;
  const t = e[x];
  let i;
  if (t) {
    if (!t.modified_)
      return t.base_;
    t.finalized_ = !0, i = ge(e, t.scope_.immer_.useStrictShallowCopy_);
  } else
    i = ge(e, !0);
  return G(i, (s, r) => {
    Ue(i, s, qe(r));
  }), t && (t.finalized_ = !1), i;
}
function mt() {
  class e extends Map {
    constructor(o, a) {
      super(), this[x] = {
        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 M(this[x]).size;
    }
    has(o) {
      return M(this[x]).has(o);
    }
    set(o, a) {
      const d = this[x];
      return u(d), (!M(d).has(o) || M(d).get(o) !== a) && (i(d), $(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[x];
      return u(a), i(a), $(a), a.base_.has(o) ? a.assigned_.set(o, !1) : a.assigned_.delete(o), a.copy_.delete(o), !0;
    }
    clear() {
      const o = this[x];
      u(o), M(o).size && (i(o), $(o), o.assigned_ = /* @__PURE__ */ new Map(), G(o.base_, (a) => {
        o.assigned_.set(a, !1);
      }), o.copy_.clear());
    }
    forEach(o, a) {
      const d = this[x];
      M(d).forEach((l, f, p) => {
        o.call(a, this.get(f), f, this);
      });
    }
    get(o) {
      const a = this[x];
      u(a);
      const d = M(a).get(o);
      if (a.finalized_ || !z(d) || d !== a.base_.get(o))
        return d;
      const l = q(d, a);
      return i(a), a.copy_.set(o, l), l;
    }
    keys() {
      return M(this[x]).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 t(c, o) {
    return new e(c, o);
  }
  function i(c) {
    c.copy_ || (c.assigned_ = /* @__PURE__ */ new Map(), c.copy_ = new Map(c.base_));
  }
  class s extends Set {
    constructor(o, a) {
      super(), this[x] = {
        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 M(this[x]).size;
    }
    has(o) {
      const a = this[x];
      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[x];
      return u(a), this.has(o) || (n(a), $(a), a.copy_.add(o)), this;
    }
    delete(o) {
      if (!this.has(o))
        return !1;
      const a = this[x];
      return u(a), n(a), $(a), a.copy_.delete(o) || (a.drafts_.has(o) ? a.copy_.delete(a.drafts_.get(o)) : (
        /* istanbul ignore next */
        !1
      ));
    }
    clear() {
      const o = this[x];
      u(o), M(o).size && (n(o), $(o), o.copy_.clear());
    }
    values() {
      const o = this[x];
      return u(o), n(o), o.copy_.values();
    }
    entries() {
      const o = this[x];
      return u(o), n(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 r(c, o) {
    return new s(c, o);
  }
  function n(c) {
    c.copy_ || (c.copy_ = /* @__PURE__ */ new Set(), c.base_.forEach((o) => {
      if (z(o)) {
        const a = q(o, c);
        c.drafts_.set(o, a), c.copy_.add(a);
      } else
        c.copy_.add(o);
    }));
  }
  function u(c) {
    c.revoked_ && T(3, JSON.stringify(M(c)));
  }
  at("MapSet", { proxyMap_: t, proxySet_: r });
}
var B = new pt(), St = B.produce;
B.produceWithPatches.bind(
  B
);
B.setAutoFreeze.bind(B);
B.setUseStrictShallowCopy.bind(B);
B.applyPatches.bind(B);
B.createDraft.bind(B);
B.finishDraft.bind(B);
const _t = {}, $e = (e) => {
  let t;
  const i = /* @__PURE__ */ new Set(), s = (d, l) => {
    const f = typeof d == "function" ? d(t) : d;
    if (!Object.is(f, t)) {
      const p = t;
      t = l ?? (typeof f != "object" || f === null) ? f : Object.assign({}, t, f), i.forEach((m) => m(t, p));
    }
  }, r = () => t, o = { setState: s, getState: r, getInitialState: () => a, subscribe: (d) => (i.add(d), () => i.delete(d)), destroy: () => {
    (_t ? "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."
    ), i.clear();
  } }, a = t = e(s, r, o);
  return o;
}, Me = (e) => e ? $e(e) : $e;
var xe = { exports: {} }, pe = {}, Y = { exports: {} }, he = {};
/**
 * @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 ze;
function gt() {
  if (ze) return he;
  ze = 1;
  var e = Z;
  function t(l, f) {
    return l === f && (l !== 0 || 1 / l === 1 / f) || l !== l && f !== f;
  }
  var i = typeof Object.is == "function" ? Object.is : t, s = e.useState, r = e.useEffect, n = e.useLayoutEffect, u = e.useDebugValue;
  function c(l, f) {
    var p = f(), m = s({ inst: { value: p, getSnapshot: f } }), h = m[0].inst, S = m[1];
    return n(function() {
      h.value = p, h.getSnapshot = f, o(h) && S({ inst: h });
    }, [l, p, f]), r(function() {
      return o(h) && S({ inst: h }), l(function() {
        o(h) && S({ inst: h });
      });
    }, [l]), u(p), p;
  }
  function o(l) {
    var f = l.getSnapshot;
    l = l.value;
    try {
      var p = f();
      return !i(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 he.useSyncExternalStore = e.useSyncExternalStore !== void 0 ? e.useSyncExternalStore : d, he;
}
var me = {};
/**
 * @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 Le;
function vt() {
  return Le || (Le = 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 = Z, t = e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
    function i(v) {
      {
        for (var b = arguments.length, w = new Array(b > 1 ? b - 1 : 0), k = 1; k < b; k++)
          w[k - 1] = arguments[k];
        s("error", v, w);
      }
    }
    function s(v, b, w) {
      {
        var k = t.ReactDebugCurrentFrame, O = k.getStackAddendum();
        O !== "" && (b += "%s", w = w.concat([O]));
        var D = w.map(function(I) {
          return String(I);
        });
        D.unshift("Warning: " + b), Function.prototype.apply.call(console[v], console, D);
      }
    }
    function r(v, b) {
      return v === b && (v !== 0 || 1 / v === 1 / b) || v !== v && b !== b;
    }
    var n = typeof Object.is == "function" ? Object.is : r, u = e.useState, c = e.useEffect, o = e.useLayoutEffect, a = e.useDebugValue, d = !1, l = !1;
    function f(v, b, w) {
      d || e.startTransition !== void 0 && (d = !0, i("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 = b();
      if (!l) {
        var O = b();
        n(k, O) || (i("The result of getSnapshot should be cached to avoid an infinite loop"), l = !0);
      }
      var D = u({
        inst: {
          value: k,
          getSnapshot: b
        }
      }), I = D[0].inst, N = D[1];
      return o(function() {
        I.value = k, I.getSnapshot = b, p(I) && N({
          inst: I
        });
      }, [v, k, b]), c(function() {
        p(I) && N({
          inst: I
        });
        var se = function() {
          p(I) && N({
            inst: I
          });
        };
        return v(se);
      }, [v]), a(k), k;
    }
    function p(v) {
      var b = v.getSnapshot, w = v.value;
      try {
        var k = b();
        return !n(w, k);
      } catch {
        return !0;
      }
    }
    function m(v, b, w) {
      return b();
    }
    var h = typeof window < "u" && typeof window.document < "u" && typeof window.document.createElement < "u", S = !h, y = S ? m : f, _ = e.useSyncExternalStore !== void 0 ? e.useSyncExternalStore : y;
    me.useSyncExternalStore = _, typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ < "u" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop == "function" && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error());
  }()), me;
}
var Ae;
function Je() {
  return Ae || (Ae = 1, process.env.NODE_ENV === "production" ? Y.exports = gt() : Y.exports = vt()), 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 Re;
function bt() {
  if (Re) return pe;
  Re = 1;
  var e = Z, t = Je();
  function i(a, d) {
    return a === d && (a !== 0 || 1 / a === 1 / d) || a !== a && d !== d;
  }
  var s = typeof Object.is == "function" ? Object.is : i, r = t.useSyncExternalStore, n = e.useRef, u = e.useEffect, c = e.useMemo, o = e.useDebugValue;
  return pe.useSyncExternalStoreWithSelector = function(a, d, l, f, p) {
    var m = n(null);
    if (m.current === null) {
      var h = { hasValue: !1, value: null };
      m.current = h;
    } else h = m.current;
    m = c(function() {
      function y(k) {
        if (!_) {
          if (_ = !0, v = k, k = f(k), p !== void 0 && h.hasValue) {
            var O = h.value;
            if (p(O, k)) return b = O;
          }
          return b = k;
        }
        if (O = b, s(v, k)) return O;
        var D = f(k);
        return p !== void 0 && p(O, D) ? O : (v = k, b = D);
      }
      var _ = !1, v, b, w = l === void 0 ? null : l;
      return [function() {
        return y(d());
      }, w === null ? void 0 : function() {
        return y(w());
      }];
    }, [d, l, f, p]);
    var S = r(a, m[0], m[1]);
    return u(function() {
      h.hasValue = !0, h.value = S;
    }, [S]), o(S), S;
  }, pe;
}
var Se = {};
/**
 * @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 Fe;
function yt() {
  return Fe || (Fe = 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 = Z, t = Je();
    function i(d, l) {
      return d === l && (d !== 0 || 1 / d === 1 / l) || d !== d && l !== l;
    }
    var s = typeof Object.is == "function" ? Object.is : i, r = t.useSyncExternalStore, n = e.useRef, u = e.useEffect, c = e.useMemo, o = e.useDebugValue;
    function a(d, l, f, p, m) {
      var h = n(null), S;
      h.current === null ? (S = {
        hasValue: !1,
        value: null
      }, h.current = S) : S = h.current;
      var y = c(function() {
        var w = !1, k, O, D = function(j) {
          if (!w) {
            w = !0, k = j;
            var ce = p(j);
            if (m !== void 0 && S.hasValue) {
              var ae = S.value;
              if (m(ae, ce))
                return O = ae, ae;
            }
            return O = ce, ce;
          }
          var Qe = k, ue = O;
          if (s(Qe, j))
            return ue;
          var de = p(j);
          return m !== void 0 && m(ue, de) ? ue : (k = j, O = de, de);
        }, I = f === void 0 ? null : f, N = function() {
          return D(l());
        }, se = I === null ? void 0 : function() {
          return D(I());
        };
        return [N, se];
      }, [l, f, p, m]), _ = y[0], v = y[1], b = r(d, _, v);
      return u(function() {
        S.hasValue = !0, S.value = b;
      }, [b]), o(b), b;
    }
    Se.useSyncExternalStoreWithSelector = a, typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ < "u" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop == "function" && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error());
  }()), Se;
}
process.env.NODE_ENV === "production" ? xe.exports = bt() : xe.exports = yt();
var xt = xe.exports;
const kt = /* @__PURE__ */ et(xt), { useDebugValue: Et } = Z, { useSyncExternalStoreWithSelector: Pt } = kt, wt = (e) => e;
function g(e, t = wt, i) {
  const s = Pt(
    e.subscribe,
    e.getState,
    e.getServerState || e.getInitialState,
    t,
    i
  );
  return Et(s), s;
}
var Ve = (e, t, i) => (r, n) => ({
  pastStates: (i == null ? void 0 : i.pastStates) || [],
  futureStates: (i == null ? void 0 : i.futureStates) || [],
  undo: (u = 1) => {
    var c, o;
    if (n().pastStates.length) {
      const a = ((c = i == null ? void 0 : i.partialize) == null ? void 0 : c.call(i, t())) || t(), d = n().pastStates.splice(-u, u), l = d.shift();
      e(l), r({
        pastStates: n().pastStates,
        futureStates: n().futureStates.concat(
          ((o = i == null ? void 0 : i.diff) == null ? void 0 : o.call(i, a, l)) || a,
          d.reverse()
        )
      });
    }
  },
  redo: (u = 1) => {
    var c, o;
    if (n().futureStates.length) {
      const a = ((c = i == null ? void 0 : i.partialize) == null ? void 0 : c.call(i, t())) || t(), d = n().futureStates.splice(-u, u), l = d.shift();
      e(l), r({
        pastStates: n().pastStates.concat(
          ((o = i == null ? void 0 : i.diff) == null ? void 0 : o.call(i, a, l)) || a,
          d.reverse()
        ),
        futureStates: n().futureStates
      });
    }
  },
  clear: () => r({ pastStates: [], futureStates: [] }),
  isTracking: !0,
  pause: () => r({ isTracking: !1 }),
  resume: () => r({ isTracking: !0 }),
  setOnSave: (u) => r({ _onSave: u }),
  // Internal properties
  _onSave: i == null ? void 0 : i.onSave,
  _handleSet: (u, c, o, a) => {
    var d, l;
    i != null && i.limit && n().pastStates.length >= (i == null ? void 0 : i.limit) && n().pastStates.shift(), (l = (d = n())._onSave) == null || l.call(d, u, o), r({
      pastStates: n().pastStates.concat(a || u),
      futureStates: []
    });
  }
}), Ze = (e, t) => (s, r, n) => {
  var a, d;
  n.temporal = Me(
    ((a = t == null ? void 0 : t.wrapTemporal) == null ? void 0 : a.call(t, Ve(s, r, t))) || Ve(s, r, t)
  );
  const u = ((d = t == null ? void 0 : t.handleSet) == null ? void 0 : d.call(
    t,
    n.temporal.getState()._handleSet
  )) || n.temporal.getState()._handleSet, c = (l) => {
    var m, h, S;
    if (!n.temporal.getState().isTracking) return;
    const f = ((m = t == null ? void 0 : t.partialize) == null ? void 0 : m.call(t, r())) || r(), p = (h = t == null ? void 0 : t.diff) == null ? void 0 : h.call(t, 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
    (S = t == null ? void 0 : t.equality) != null && S.call(t, l, f) || u(
      l,
      void 0,
      f,
      p
    );
  }, o = n.setState;
  return n.setState = (...l) => {
    var p;
    const f = ((p = t == null ? void 0 : t.partialize) == null ? void 0 : p.call(t, r())) || r();
    o(...l), c(f);
  }, e(
    // Modify the set function to call the userlandSet function
    (...l) => {
      var p;
      const f = ((p = t == null ? void 0 : t.partialize) == null ? void 0 : p.call(t, r())) || r();
      s(...l), c(f);
    },
    r,
    n
  );
};
const Mt = {}, Ot = (e) => (t, i, s) => {
  const r = 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 r(a);
  }, e(t, i, s);
}, Ye = Ot;
function Tt(e, t) {
  let i;
  try {
    i = e();
  } catch {
    return;
  }
  return {
    getItem: (r) => {
      var n;
      const u = (o) => o === null ? null : JSON.parse(o, void 0), c = (n = i.getItem(r)) != null ? n : null;
      return c instanceof Promise ? c.then(u) : u(c);
    },
    setItem: (r, n) => i.setItem(
      r,
      JSON.stringify(n, void 0)
    ),
    removeItem: (r) => i.removeItem(r)
  };
}
const J = (e) => (t) => {
  try {
    const i = e(t);
    return i instanceof Promise ? i : {
      then(s) {
        return J(s)(i);
      },
      catch(s) {
        return this;
      }
    };
  } catch (i) {
    return {
      then(s) {
        return this;
      },
      catch(s) {
        return J(s)(i);
      }
    };
  }
}, It = (e, t) => (i, s, r) => {
  let n = {
    getStorage: () => localStorage,
    serialize: JSON.stringify,
    deserialize: JSON.parse,
    partialize: (S) => S,
    version: 0,
    merge: (S, y) => ({
      ...y,
      ...S
    }),
    ...t
  }, u = !1;
  const c = /* @__PURE__ */ new Set(), o = /* @__PURE__ */ new Set();
  let a;
  try {
    a = n.getStorage();
  } catch {
  }
  if (!a)
    return e(
      (...S) => {
        console.warn(
          `[zustand persist middleware] Unable to update item '${n.name}', the given storage is currently unavailable.`
        ), i(...S);
      },
      s,
      r
    );
  const d = J(n.serialize), l = () => {
    const S = n.partialize({ ...s() });
    let y;
    const _ = d({ state: S, version: n.version }).then(
      (v) => a.setItem(n.name, v)
    ).catch((v) => {
      y = v;
    });
    if (y)
      throw y;
    return _;
  }, f = r.setState;
  r.setState = (S, y) => {
    f(S, y), l();
  };
  const p = e(
    (...S) => {
      i(...S), l();
    },
    s,
    r
  );
  let m;
  const h = () => {
    var S;
    if (!a) return;
    u = !1, c.forEach((_) => _(s()));
    const y = ((S = n.onRehydrateStorage) == null ? void 0 : S.call(n, s())) || void 0;
    return J(a.getItem.bind(a))(n.name).then((_) => {
      if (_)
        return n.deserialize(_);
    }).then((_) => {
      if (_)
        if (typeof _.version == "number" && _.version !== n.version) {
          if (n.migrate)
            return n.migrate(
              _.state,
              _.version
            );
          console.error(
            "State loaded from storage couldn't be migrated since no migrate function was provided"
          );
        } else
          return _.state;
    }).then((_) => {
      var v;
      return m = n.merge(
        _,
        (v = s()) != null ? v : p
      ), i(m, !0), l();
    }).then(() => {
      y == null || y(m, void 0), u = !0, o.forEach((_) => _(m));
    }).catch((_) => {
      y == null || y(void 0, _);
    });
  };
  return r.persist = {
    setOptions: (S) => {
      n = {
        ...n,
        ...S
      }, S.getStorage && (a = S.getStorage());
    },
    clearStorage: () => {
      a == null || a.removeItem(n.name);
    },
    getOptions: () => n,
    rehydrate: () => h(),
    hasHydrated: () => u,
    onHydrate: (S) => (c.add(S), () => {
      c.delete(S);
    }),
    onFinishHydration: (S) => (o.add(S), () => {
      o.delete(S);
    })
  }, h(), m || p;
}, Bt = (e, t) => (i, s, r) => {
  let n = {
    storage: Tt(() => localStorage),
    partialize: (h) => h,
    version: 0,
    merge: (h, S) => ({
      ...S,
      ...h
    }),
    ...t
  }, u = !1;
  const c = /* @__PURE__ */ new Set(), o = /* @__PURE__ */ new Set();
  let a = n.storage;
  if (!a)
    return e(
      (...h) => {
        console.warn(
          `[zustand persist middleware] Unable to update item '${n.name}', the given storage is currently unavailable.`
        ), i(...h);
      },
      s,
      r
    );
  const d = () => {
    const h = n.partialize({ ...s() });
    return a.setItem(n.name, {
      state: h,
      version: n.version
    });
  }, l = r.setState;
  r.setState = (h, S) => {
    l(h, S), d();
  };
  const f = e(
    (...h) => {
      i(...h), d();
    },
    s,
    r
  );
  r.getInitialState = () => f;
  let p;
  const m = () => {
    var h, S;
    if (!a) return;
    u = !1, c.forEach((_) => {
      var v;
      return _((v = s()) != null ? v : f);
    });
    const y = ((S = n.onRehydrateStorage) == null ? void 0 : S.call(n, (h = s()) != null ? h : f)) || void 0;
    return J(a.getItem.bind(a))(n.name).then((_) => {
      if (_)
        if (typeof _.version == "number" && _.version !== n.version) {
          if (n.migrate)
            return [
              !0,
              n.migrate(
                _.state,
                _.version
              )
            ];
          console.error(
            "State loaded from storage couldn't be migrated since no migrate function was provided"
          );
        } else
          return [!1, _.state];
      return [!1, void 0];
    }).then((_) => {
      var v;
      const [b, w] = _;
      if (p = n.merge(
        w,
        (v = s()) != null ? v : f
      ), i(p, !0), b)
        return d();
    }).then(() => {
      y == null || y(p, void 0), p = s(), u = !0, o.forEach((_) => _(p));
    }).catch((_) => {
      y == null || y(void 0, _);
    });
  };
  return r.persist = {
    setOptions: (h) => {
      n = {
        ...n,
        ...h
      }, h.storage && (a = h.storage);
    },
    clearStorage: () => {
      a == null || a.removeItem(n.name);
    },
    getOptions: () => n,
    rehydrate: () => m(),
    hasHydrated: () => u,
    onHydrate: (h) => (c.add(h), () => {
      c.delete(h);
    }),
    onFinishHydration: (h) => (o.add(h), () => {
      o.delete(h);
    })
  }, n.skipHydration || m(), p || f;
}, Dt = (e, t) => "getStorage" in t || "serialize" in t || "deserialize" in t ? ((Mt ? "production" : void 0) !== "production" && console.warn(
  "[DEPRECATED] `getStorage`, `serialize` and `deserialize` options are deprecated. Use `storage` option instead."
), It(e, t)) : Bt(e, t), Ct = Dt, $t = (e) => (t, i, s) => (s.setState = (r, n, ...u) => {
  const c = typeof r == "function" ? St(r) : r;
  return t(c, n, ...u);
}, e(s.setState, i, s)), Xe = $t;
mt();
const Wt = (e) => {
  const t = {
    previewMode: "desktop",
    themesLibrary: [],
    pages: [],
    mode: "anonymous",
    panelPosition: "left",
    logoLink: "/dashboard",
    zoom: 1,
    chatVisible: !0,
    contextMenuVisible: !1,
    planIndex: 0,
    imagesSearchResults: void 0,
    sitePrompt: "",
    onPublish: () => {
      console.warn("onPublish is not implemented");
    },
    onDraftChange: async () => {
      console.warn("onDraftChange is not implemented");
    },
    debugMode: !1
  };
  return Me()(
    Ye(
      Ct(
        Ze(
          Xe((i, s) => ({
            ...t,
            ...e,
            setMouseOverPanel: (r) => i((n) => {
              n.isMouseOverPanel = r;
            }),
            setContextMenuVisible: (r) => i((n) => {
              n.contextMenuVisible = r;
            }),
            setDraggingBrickType: (r) => i((n) => {
              n.draggingBrickType = r ?? void 0;
            }),
            setGridConfig: (r) => i((n) => {
              n.gridConfig = r;
            }),
            toggleEditorEnabled: () => i((r) => {
              r.disabled = !r.disabled;
            }),
            toggleChat: () => i((r) => {
              r.chatVisible = !r.chatVisible, r.chatVisible && (r.panel = void 0, r.panelPosition = "right");
            }),
            toggleDebugMode: () => i((r) => {
              r.debugMode = !r.debugMode;
            }),
            setImagesSearchResults: (r) => i((n) => {
              n.imagesSearchResults = r;
            }),
            setLastTextEditPosition: (r) => i((n) => {
              n.lastTextEditPosition = r;
            }),
            toggleTextEditMode: () => i((r) => {
              r.textEditMode = !r.textEditMode || r.textEditMode === "default" ? "large" : "default";
            }),
            setTextEditMode: (r) => i((n) => {
              n.textEditMode = r;
            }),
            setPreviewMode: (r) => i((n) => {
              n.previewMode = r;
            }),
            setSettingsVisible: (r) => i((n) => {
              n.settingsVisible = r;
            }),
            toggleSettings: () => i((r) => {
              r.settingsVisible = !r.settingsVisible;
            }),
            setIsEditingText: (r) => i((n) => {
              n.isEditingTextForBrickId = r || void 0;
            }),
            setPanel: (r) => i((n) => {
              n.panel = r;
            }),
            togglePanel: (r) => i((n) => {
              n.panel = r && n.panel === r ? void 0 : r;
            }),
            hidePanel: (r) => i((n) => {
              (!r || n.panel === r) && (n.panel = void 0);
            }),
            zoomIn: () => i((r) => {
              r.zoom = Math.min(r.zoom + 0.1, 2);
            }),
            zoomOut: () => i((r) => {
              r.zoom = Math.max(r.zoom - 0.1, 0.5);
            }),
            resetZoom: () => i((r) => {
              r.zoom = 1;
            }),
            setSelectedGroup: (r) => i((n) => {
              n.selectedGroup = r;
            }),
            setSelectedBrickId: (r) => i((n) => {
              n.selectedBrickId = r, r && (n.selectedSectionId = void 0);
            }),
            setSelectedSectionId: (r) => i((n) => {
              n.selectedSectionId = r, r && (n.selectedBrickId = void 0, n.selectedGroup = void 0);
            }),
            deselectBrick: (r) => i((n) => {
              n.selectedBrickId && (!r || n.selectedBrickId === r) && (n.selectedBrickId = void 0);
            }),
            togglePanelPosition: () => i((r) => {
              r.panelPosition = r.panelPosition === "left" ? "right" : "left";
            }),
            showModal: (r) => i((n) => {
              n.modal = r;
            }),
            hideModal: () => i((r) => {
              r.modal = void 0;
            })
          })),
          // limit undo history to 100
          {
            limit: 100,
            equality: (i, s) => Ee(i, s)
          }
        ),
        {
          name: "editor-state",
          partialize: (i) => Object.fromEntries(
            Object.entries(i).filter(([s]) => ["chatVisible", "previewMode"].includes(s))
          )
        }
      )
    )
  );
}, Ht = (e) => {
  const t = {
    data: {},
    mode: "local",
    brickMap: L(e.sections),
    themes: [],
    pages: []
    // themes: [defaultTheme, { ...defaultTheme, id: "t2" }, { ...defaultTheme, id: "t3" }],
  };
  return Me()(
    Ye(
      Ze(
        Xe((i, s) => ({
          ...t,
          ...e,
          detachBrickFromContainer: (r) => i((n) => {
            var p;
            const u = n.brickMap.get(r);
            A(u, `Cannot detach brick ${r}, 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", r);
              return;
            }
            const d = C(a, n);
            if (!d) {
              console.error("Cannot detach brick %s, its parent %s does not exist", r, a);
              return;
            }
            const l = n.sections.find((m) => m.id === o);
            if (!l) {
              console.error("Cannot detach brick %s, its parent section %s does not exist", r, o);
              return;
            }
            d.props.$children = (p = d.props.$children) == null ? void 0 : p.filter(
              (m) => m.id !== r
            );
            const f = l.bricks.findIndex((m) => m.id === a);
            l.bricks.splice(f + 1, 0, {
              ...c
            }), n.brickMap = L(n.sections);
          }),
          createEmptySection: (r, n) => i((u) => {
            var d;
            const c = u.sections.length, o = 1 + (n ? ((d = u.sections.find((l) => l.id === n)) == null ? void 0 : d.order) ?? c : c), a = {
              id: r,
              order: o,
              label: `Section ${c + 1}`,
              bricks: [],
              props: {}
            };
            u.sections.forEach((l) => {
              l.order >= o && (l.order += 1);
            }), u.sections.push(a);
          }),
          addPage: (r) => i((n) => {
            n.pages.push(r), n.id === "_default_" && (n.id = r.id, n.path = r.path, n.label = r.label, n.sections = r.sections, r.attr && (n.attr = r.attr));
          }),
          isFirstSection: (r) => {
            var u;
            return ((u = s().sections.find((c) => c.order === 0)) == null ? void 0 : u.id) === r;
          },
          setSections: (r) => i((n) => {
            n.sections = r, n.brickMap = L(r);
          }),
          pickTheme: (r) => i((n) => {
            const u = n.themes.find((c) => c.id === r);
            if (!u) {
              console.error("Cannot pick theme %s, it does not exist", r);
              return;
            }
            n.theme = u;
          }),
          setThemes: (r) => i((n) => {
            n.themes = r;
          }),
          setSitemap: (r) => i((n) => {
            n.sitemap = r;
          }),
          getPageDataForDuplication: () => {
            const r = s(), n = r.sitemap.length + 1;
            return console.log("state.sitemap", r.sitemap), {
              id: `page-${H()}`,
              label: `${r.label} (page ${n})`,
              path: `${r.path}-${n}`,
              sections: r.sections,
              attr: r.attr,
              attributes: r.attributes,
              datasources: r.datasources,
              datarecords: r.datarecords
            };
          },
          isLastSection: (r) => {
            var u;
            const n = s();
            return ((u = n.sections.find((c) => c.order === n.sections.length - 1)) == null ? void 0 : u.id) === r;
          },
          addDatasource: (r) => i((n) => {
            if (n.datasources || (n.datasources = {}), Object.values(n.datasources).find((c) => c.id === r.id)) {
              console.error("Cannot add datasource %s, it already exists", r.id);
              return;
            }
            n.datasources[r.id] = r;
          }),
          addDatarecord: (r) => i((n) => {
            if (n.datarecords || (n.datarecords = {}), Object.values(n.datarecords).find((c) => c.id === r.id)) {
              console.error("Cannot add datarecord %s, it already exists", r.id);
              return;
            }
            n.datarecords[r.id] = r;
          }),
          addSection: (r) => i((n) => {
            n.sections.push(r);
          }),
          updateSection: (r, n) => i((u) => {
            const c = u.sections.findIndex((o) => o.id === r);
            c !== -1 && (u.sections[c] = {
              ...u.sections[c],
              ...n
            });
          }),
          duplicateSection: (r) => i((n) => {
            const u = n.sections.find((a) => a.id === r);
            if (!u) {
              console.error("Cannot duplicate section %s, it does not exist", r);
              return;
            }
            const c = n.sections.findIndex((a) => a.id === r), 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: W({}, a.props, {
                    $children: (d = a.props.$children) == null ? void 0 : d.map((l) => ({
                      ...l,
                      id: `b_${H()}`
                    }))
                  })
                };
              })
            };
            n.sections.splice(c + 1, 0, o), n.brickMap = L(n.sections);
          }),
          deleteSection: (r) => i((n) => {
            if (!n.sections.find((c) => c.id === r))
              return console.warn("Cannot delete section %s: not found", r), null;
            n.brickMap.forEach((c) => {
              c.sectionId === r && n.brickMap.delete(c.brick.id);
            }), n.sections = n.sections.filter((c) => c.id !== r);
          }),
          getSection: (r) => s().sections.find((n) => n.id === r),
          moveSectionUp: (r) => i((n) => {
            const u = n.sections.find((a) => a.id === r);
            n.sections.findIndex((a) => a.id === r), A(u, "Section not found");
            const c = n.sections.find((a) => a.order === u.order - 1);
            n.sections.findIndex((a) => a.order === u.order - 1), A(c, "Previous section not found");
            const o = u.order;
            u.order = c.order, c.order = o;
          }),
          moveSectionDown: (r) => i((n) => {
            const u = n.sections.find((f) => f.id === r), c = n.sections.findIndex((f) => f.id === r);
            A(u, "Section not found");
            const o = n.sections.find((f) => f.order === u.order + 1), a = n.sections.findIndex((f) => f.order === u.order + 1);
            A(o, "Next section not found");
            const d = u.order, l = o.order;
            n.sections[c].order = l, n.sections[a].order = d;
          }),
          reorderSections: (r) => i((n) => {
            const u = [];
            let c = 0;
            r.forEach((o) => {
              const a = n.sections.find((d) => d.id === o);
              a && u.push({ ...a, order: ++c });
            }), n.sections.forEach((o) => {
              r.includes(o.id) || u.push({ ...o, order: ++c });
            }), n.sections = u, n.brickMap = L(n.sections);
          }),
          setLastLoaded: () => i((r) => {
            r.lastLoaded = /* @__PURE__ */ new Date();
          }),
          deleteBrick: (r) => i((n) => {
            const u = n.brickMap.get(r);
            if (!u) {
              console.error("Cannot delete brick %s, it does not exist", r);
              return;
            }
            const c = [], o = (f) => {
              var m;
              const p = n.brickMap.get(f);
              (m = p == null ? void 0 : p.brick.props) != null && m.$children && p.brick.props.$children.forEach((S) => {
                c.push(S.id), o(S.id);
              });
            };
            o(r);
            const { sectionId: a, parentId: d } = u, l = n.sections.find((f) => f.id === a);
            if (d) {
              const f = C(d, n);
              if (f != null && f.props.$children) {
                const p = f.props.$children.findIndex((m) => m.id === r);
                f.props.$children.splice(p, 1);
              }
            } else l && (l.bricks = l.bricks.filter((f) => f.id !== r));
            n.brickMap.delete(r), c.forEach((f) => {
              n.brickMap.delete(f);
            });
          }),
          duplicateBrick: (r) => i((n) => {
            const u = n.brickMap.get(r);
            if (!u) {
              console.error("Cannot duplicate brick %s, it does not exist", r);
              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((S) => c(S));
              }
              return m;
            }, o = c(u.brick), a = (f, p, m) => {
              n.brickMap.set(f.id, {
                brick: f,
                sectionId: p,
                parentId: m
              }), f.props.$children && f.props.$children.forEach((S) => a(S, p, f.id));
            }, { sectionId: d, parentId: l } = u;
            if (l) {
              const f = C(l, n);
              if (f != null && f.props.$children) {
                const m = f.props.$children.findIndex((h) => h.id === r);
                f.props.$children.splice(m + 1, 0, o);
              }
            } else {
              const f = n.sections.find((p) => p.id === d);
              if (f) {
                const p = f.bricks.findIndex((m) => m.id === r);
                f.bricks.splice(p + 1, 0, o);
              }
            }
            a(o, d, l);
          }),
          updateBrick: (r, n) => i((u) => {
            const c = Ne(r, u);
            c && Object.assign(c, n);
          }),
          updateBrickProps: (r, n, u) => i((c) => {
            const o = C(r, c);
            o ? (u ? o.mobileProps = W({}, o.mobileProps, n, {
              lastTouched: Date.now()
            }) : o.props = W({}, o.props, n, {
              lastTouched: Date.now()
            }), c.brickMap = L(c.sections)) : console.error("Cannot update brick %s, it does not exist in the brick map", r);
          }),
          updateSectionProps: (r, n, u) => i((c) => {
            const o = c.sections.find((a) => a.id === r);
            o ? u ? o.mobileProps = W({}, o.mobileProps, n, {
              lastTouched: Date.now()
            }) : o.props = W({}, o.props, n, {
              lastTouched: Date.now()
            }) : console.warn("Cannot update section %s, it does not exist", r);
          }),
          /**
           * 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: (r, n) => i((u) => {
            let c = [], o = -1;
            const a = u.getParentBrick(r);
            a ? (c = C(a.id, u).props.$children, o = c.findIndex((p) => p.id === r)) : (c = ke(r, u).bricks, o = c.findIndex((p) => p.id === r));
            const d = n === "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 = L(u.sections);
          }),
          /**
           * Reorder a brick within its section using indices
           */
          reorderBrickWithin: (r, n) => i((u) => {
            const c = u.brickMap.get(r);
            if (!c) {
              console.error("Cannot reorder brick %s, brick mapping not found", r);
              return;
            }
            const { sectionId: o, parentId: a } = c;
            if (a) {
              const d = C(a, u);
              if (d != null && d.props.$children) {
                const l = d.props.$children, f = l.findIndex((m) => m.id === r);
                if (f === -1) {
                  console.error("Cannot reorder brick %s, it does not exist in parent's children", r);
                  return;
                }
                const [p] = l.splice(f, 1);
                l.splice(n, 0, p);
              }
            } else {
              const d = u.sections.find((l) => l.id === o);
              if (d) {
                const l = d.bricks.findIndex((p) => p.id === r);
                if (l === -1) {
                  console.error(
                    "Cannot reorder brick %s, it does not exist in section %s",
                    r,
                    o
                  );
                  return;
                }
                const [f] = d.bricks.splice(l, 1);
                d.bricks.splice(n, 0, f);
              }
            }
          }),
          moveBrickToContainerBrick: (r, n, u) => i((c) => {
            const o = c.getBrick(r), a = C(n, c), d = c.brickMap.get(r);
            if (!o || !a || !d) {
              console.error("Cannot move brick %s to new parent, brick or new parent is null", r);
              return;
            }
            if (!("$children" in a.props)) {
              console.error("Cannot move brick %s, parent brick %s is not a container", r, n);
              return;
            }
            const { sectionId: l, parentId: f } = d;
            if (f) {
              const m = C(f, c);
              m != null && m.props.$children && (m.props.$children = m.props.$children.filter(
                (h) => h.id !== r
              ));
            } else {
              const m = c.sections.find((h) => h.id === l);
              m && (m.bricks = m.bricks.filter((h) => h.id !== r));
            }
            a.props.$children || (a.props.$children = []), a.props.$children.splice(u, 0, o);
            const p = c.brickMap.get(n);
            if (p) {
              c.brickMap.set(r, {
                brick: o,
                sectionId: p.sectionId,
                parentId: n
              });
              const m = (h, S) => {
                var _;
                const y = c.brickMap.get(h);
                (_ = y == null ? void 0 : y.brick.props) != null && _.$children && y.brick.props.$children.forEach((b) => {
                  c.brickMap.set(b.id, {
                    brick: b,
                    sectionId: S,
                    parentId: h
                  }), m(b.id, S);
                });
              };
              m(r, p.sectionId);
            }
          }),
          moveBrickToSection: (r, n, u) => i((c) => {
            var m;
            const o = c.getBrick(r);
            n || (n = (m = c.brickMap.get(r)) == null ? void 0 : m.sectionId);
            const a = c.sections.find((h) => h.id === n), d = c.brickMap.get(r);
            if (!o || !a || !d) {
              console.error(
                "Cannot move brick %s to section %s, brick or section not found",
                r,
                n
              );
              return;
            }
            const { sectionId: l, parentId: f } = d;
            if (f) {
              const h = C(f, c);
              h != null && h.props.$children && (h.props.$children = h.props.$children.filter(
                (S) => S.id !== r
              ));
            } else {
              const h = c.sections.find((S) => S.id === l);
              h && (h.bricks = h.bricks.filter((S) => S.id !== r));
            }
            typeof u == "number" ? a.bricks.splice(u, 0, o) : a.bricks.push(o), c.brickMap.set(r, {
              brick: o,
              sectionId: n,
              parentId: null
              // Top level in section
            });
            const p = (h, S, y) => {
              var v;
              const _ = c.brickMap.get(h);
              (v = _ == null ? void 0 : _.brick.props) != null && v.$children && _.brick.props.$children.forEach((w) => {
                c.brickMap.set(w.id, {
                  brick: w,
                  sectionId: S,
                  parentId: h
                }), p(w.id, S);
              });
            };
            p(r, n);
          }),
          /**
           * @deprecated Use getBrickFromDraft instead
           */
          getBrick: (r) => {
            var n;
            return (n = s().brickMap.get(r)) == null ? void 0 : n.brick;
          },
          getParentBrick: (r) => {
            var c;
            const n = s().brickMap, { parentId: u } = n.get(r) ?? {};
            if (u)
              return (c = n.get(u)) == null ? void 0 : c.brick;
          },
          getPositionWithinParent: (r) => {
            const n = s().getParentBrick(r);
            if (n && "$children" in n.props)
              return n.props.$children.findIndex((u) => u.id === r);
          },
          canMoveToWithinParent: (r, n) => {
            const u = s().getParentBrick(r);
            if (u && "$children" in u.props) {
              const a = u.props.$children, d = a.findIndex((l) => l.id === r);
              return n === "previous" ? d > 0 : d < a.length - 1;
            }
            const c = ke(r, s()), o = c.bricks.findIndex((a) => a.id === r);
            return n === "previous" ? o > 0 : o < (c == null ? void 0 : c.bricks.length) - 1;
          },
          setPreviewTheme: (r) => i((n) => {
            n.previewTheme = r;
          }),
          validatePreviewTheme: (r) => i((n) => {
            n.previewTheme && r && (n.theme = n.previewTheme), n.previewTheme = void 0;
          }),
          cancelPreviewTheme: () => i((r) => {
            r.previewTheme = void 0;
          }),
          setTheme: (r) => i((n) => {
            n.theme = r;
          }),
          toggleBrickVisibility: (r, n) => i((u) => {
            var o, a;
            const c = C(r, u);
            c && ((o = c.props).hidden ?? (o.hidden = { desktop: !1, mobile: !1 }), c.props.hidden[n] = !((a = c.props.hidden) != null && a[n]));
          }),
          addBrick: (r, n, u, c) => i((o) => {
            var d;
            const a = o.sections.find((l) => l.id === n);
            if (!a) {
              console.error("Cannot add brick, section %s does not exist", n);
              return;
            }
            if (c) {
              if (console.log("Adding brick to parent container", c), !Ne(c, o)) {
                console.warn("Cannot add brick, parent container %s does not exist", c);
                return;
              }
              const f = o.sections.find((m) => m.id === n);
              if (!f) {
                console.warn("Cannot add brick, parent section %s does not exist", n);
                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,
                  n
                );
                return;
              }
              console.log("PArent BRICK", p), p.props.$children || (console.warn("Brick added to a container without $children, initializing it"), p.props.$children = []), p.props.$children.push(r);
            } else
              a.bricks.splice(u, 0, r);
            if (o.brickMap.set(r.id, {
              brick: r,
              sectionId: n,
              parentId: c
            }), (d = r.props) != null && d.$children) {
              const l = (f, p) => {
                f.forEach((m) => {
                  var h;
                  o.brickMap.set(m.id, {
                    brick: m,
                    sectionId: n,
                    parentId: p
                  }), (h = m.props) != null && h.$children && l(m.props.$children, m.id);
                });
              };
              console.log("Adding children to brick map", r.props.$children), l(r.props.$children, r.id);
            }
          }),
          updateAttributes: (r) => i((n) => {
            n.attr = { ...s().attr, ...r };
          }),
          setVersion: (r) => i((n) => {
            n.version = r;
          }),
          adjustMobileLayout: () => i((r) => {
          }),
          setLastSaved: (r) => i((n) => {
            n.lastSaved = r;
          }),
          setDirty: (r) => i((n) => {
            n.dirty = r;
          })
        })),
        {
          // limit undo history to 100
          limit: 100,
          equality: (i, s) => Ee(i, s),
          partialize: (i) => Object.fromEntries(
            Object.entries(i).filter(([s]) => ["sections", "attr"].includes(s))
          )
          // handleSet: (handleSet) =>
          //   debounce<typeof handleSet>((state) => {
          //     if (state) {
          //       handleSet(state);
          //     }
          //   }, 200),
        }
      )
    )
  );
}, zt = je(null), Lt = je(null), P = () => {
  const e = We(zt);
  return e || console.log("Problem with EditorStoreContext", e), A(e, "useEditorStoreContext must be used within a EditorStoreContext"), e;
}, E = () => {
  const e = We(Lt);
  return A(e, "useDraftStoreContext must be used within a DraftStoreContext"), e;
}, Gt = () => E().temporal.getState(), Ut = () => {
  const e = P();
  return g(e);
}, Kt = () => {
  const e = P();
  return g(e, (t) => t.sitePrompt);
}, qt = () => {
  const e = E();
  return g(e, (t) => t.sitemap);
}, Jt = () => {
  const e = P();
  return g(e, (t) => t.previewMode);
}, Zt = () => {
  const e = E();
  return g(e, (t) => {
    const i = t.sitemap.length > 0, s = t.themes.length > 0, r = i && s && t.sitemap.length > 0, n = new URL(window.location.href).searchParams.get("action") === "generate";
    return {
      hasSitemap: i,
      hasThemesGenerated: s,
      sitemap: t.sitemap,
      pages: t.pages,
      isReady: !n || r || !1
    };
  });
}, Yt = () => {
  const e = P();
  return g(e, (t) => !t.disabled);
}, Xt = () => {
  const e = P();
  return g(e, (t) => t.logoLink);
}, Qt = () => {
  const e = P();
  return g(e, (t) => t.selectedGroup);
}, er = () => {
  const e = P();
  return g(e, (t) => t.selectedBrickId);
};
function tr() {
  const e = P();
  return g(e, (t) => t.selectedSectionId);
}
function rr() {
  const e = P(), t = E();
  return g(e, (i) => {
    const s = t.getState().sections.find((r) => r.id === i.selectedSectionId);
    return s || null;
  });
}
const nr = () => {
  const e = P();
  return g(e, (t) => !!t.debugMode);
}, ir = () => {
  const e = P();
  return g(e, (t) => ({
    panel: t.panel,
    panelPosition: t.panelPosition
  }));
}, or = () => {
  const e = P();
  return g(e, (t) => t.planIndex > 0);
};
function sr(e) {
  const t = P();
  return g(t, (i) => i.planIndex >= e);
}
const cr = () => {
  const e = P();
  return g(e, (t) => t.mode);
}, ar = () => {
  const e = E(), t = g(e, (s) => s.pages);
  return {
    site: At(),
    pages: t
  };
}, ur = () => {
  const e = E();
  return g(e, (t) => t.themes);
}, dr = () => {
  const e = P();
  return g(e, (t) => t.themesLibrary);
}, lr = () => {
  const e = P();
  return g(e, (t) => t.imagesSearchResults);
}, fr = () => {
  const e = P();
  return g(e, (t) => ({
    zoom: t.zoom,
    zoomIn: t.zoomIn,
    zoomOut: t.zoomOut,
    canZoomIn: t.zoom < 2,
    canZoomOut: t.zoom > 0.5,
    resetZoom: t.resetZoom
  }));
}, pr = () => {
  const e = P();
  return g(e, (t) => !!t.chatVisible);
}, hr = () => {
  const e = P();
  return g(e, (t) => t.textEditMode);
}, mr = () => {
  const e = E();
  return g(e);
};
function Sr(e) {
  const t = E(), i = g(t, (r) => r.getParentBrick);
  let s = i(e);
  for (; s; ) {
    if (s.type === "dynamic")
      return !0;
    e = s.id, s = i(e);
  }
  return !1;
}
function _r(e) {
  const t = E(), i = g(t, (r) => r.getParentBrick);
  let s = i(e);
  for (; s; ) {
    if (s.type === "dynamic")
      return s;
    e = s.id, s = i(e);
  }
  return null;
}
const gr = () => {
  const e = E();
  return g(e, (t) => t.getBrick);
};
function vr() {
  const e = E();
  return g(e, (t) => t.version);
}
function br() {
  const e = P();
  return g(e, (t) => t.isEditingTextForBrickId);
}
function yr() {
  const e = E();
  return g(e, (t) => t.lastSaved);
}
const xr = () => {
  const e = E(), t = g(e, (i) => i.sections);
  return tt(t);
}, kr = (e) => {
  const t = E();
  return g(t, (i) => {
    const s = i.sections.find((r) => e && r.id === e);
    return s ? {
      section: s,
      bricks: Array.from(i.brickMap).filter(([, r]) => r.sectionId === e)
    } : null;
  });
}, Er = (e) => {
  const t = E();
  return g(t, (i) => ke(e, i));
}, Pr = () => {
  const e = E();
  return g(e, (t) => t.attr);
}, wr = () => {
  const e = E();
  return g(e, (t) => t.attributes ?? t.siteAttributes);
}, Mr = () => {
  const e = E();
  return g(e, (t) => t.datasources);
}, Or = () => {
  const e = P();
  return g(e, (t) => t.draggingBrickType);
}, Tr = () => {
  const e = P();
  return g(e, (t) => t.contextMenuVisible);
}, Ir = () => {
  const e = P();
  return g(e, (t) => t.isMouseOverPanel);
}, Br = () => {
  const e = P();
  return g(e, (t) => ({
    setMouseOverPanel: t.setMouseOverPanel,
    toggleDebugMode: t.toggleDebugMode,
    setContextMenuVisible: t.setContextMenuVisible,
    setDraggingBrickType: t.setDraggingBrickType,
    setPreviewMode: t.setPreviewMode,
    setSettingsVisible: t.setSettingsVisible,
    setGridConfig: t.setGridConfig,
    toggleSettings: t.toggleSettings,
    toggleTextEditMode: t.toggleTextEditMode,
    setTextEditMode: t.setTextEditMode,
    setIsEditingText: t.setIsEditingText,
    setLastTextEditPosition: t.setLastTextEditPosition,
    setImagesSearchResults: t.setImagesSearchResults,
    setPanel: t.setPanel,
    togglePanel: t.togglePanel,
    hidePanel: t.hidePanel,
    setSelectedGroup: t.setSelectedGroup,
    setSelectedBrickId: t.setSelectedBrickId,
    setSelectedSectionId: t.setSelectedSectionId,
    deselectBrick: t.deselectBrick,
    togglePanelPosition: t.togglePanelPosition,
    showModal: t.showModal,
    hideModal: t.hideModal,
    toggleEditorEnabled: t.toggleEditorEnabled,
    onPublish: t.onPublish,
    onSavePage: t.onSavePage,
    onSaveSite: t.onSaveSite,
    onDraftChange: t.onDraftChange,
    toggleChat: t.toggleChat,
    onShowPopup: t.onShowPopup
  }));
}, Dr = () => {
  const e = E();
  return g(e, (t) => ({
    deleteBrick: t.deleteBrick,
    detachBrickFromContainer: t.detachBrickFromContainer,
    setSections: t.setSections,
    setThemes: t.setThemes,
    setTheme: t.setTheme,
    pickTheme: t.pickTheme,
    setSitemap: t.setSitemap,
    addPage: t.addPage,
    addDatasource: t.addDatasource,
    addDatarecord: t.addDatarecord,
    duplicateBrick: t.duplicateBrick,
    addBrick: t.addBrick,
    getBrick: t.getBrick,
    validatePreviewTheme: t.validatePreviewTheme,
    adjustMobileLayout: t.adjustMobileLayout,
    duplicateSection: t.duplicateSection,
    toggleBrickVisibilityPerBreakpoint: t.toggleBrickVisibility,
    getParentBrick: t.getParentBrick,
    updateBrick: t.updateBrick,
    updateBrickProps: t.updateBrickProps,
    moveBrickWithin: t.moveBrickWithin,
    reorderBrickWithin: t.reorderBrickWithin,
    getPositionWithinParent: t.getPositionWithinParent,
    canMoveToWithinParent: t.canMoveToWithinParent,
    moveBrickToContainerBrick: t.moveBrickToContainerBrick,
    moveBrickToSection: t.moveBrickToSection,
    deleteSection: t.deleteSection,
    moveSectionUp: t.moveSectionUp,
    moveSectionDown: t.moveSectionDown,
    reorderSections: t.reorderSections,
    updateSection: t.updateSection,
    updateSectionProps: t.updateSectionProps,
    addSection: t.addSection,
    createEmptySection: t.createEmptySection,
    isFirstSection: t.isFirstSection,
    isLastSection: t.isLastSection
  }));
}, Cr = () => {
  const e = E();
  return g(e, (t) => t.datarecords);
}, $r = () => {
  const e = E();
  return g(e, (t) => ({
    id: t.id,
    path: t.path,
    label: t.label,
    siteLabel: t.siteLabel,
    siteId: t.siteId,
    hostname: t.hostname
  }));
}, At = () => {
  const e = E(), t = g(
    e,
    (r) => ({
      id: r.siteId,
      label: r.label,
      sitemap: r.sitemap,
      attr: r.attr,
      theme: r.theme,
      themes: r.themes,
      attributes: r.siteAttributes,
      hostname: r.hostname
    })
  ), i = P(), s = g(i, (r) => r.sitePrompt);
  return {
    ...t,
    sitePrompt: s
  };
}, zr = () => {
  const e = E();
  return g(e, (t) => t.theme);
}, Lr = (e) => {
  const t = E();
  te(() => t.subscribe((i) => (i == null ? void 0 : i.sections) ?? [], rt(e, 200), {
    fireImmediately: !1
  }), []);
}, Ar = (e) => {
  const t = E();
  te(() => t.subscribe((i) => i.attr, e, {
    equalityFn: Ee
  }), []);
}, Rr = (e) => {
  const t = E();
  te(() => t.subscribe((i) => i.theme, e), []);
}, Fr = (e) => {
  const t = E();
  te(() => t.subscribe((i) => i.path, e), []);
};
function Vr() {
  const e = P();
  return g(
    e,
    (t) => t.gridConfig ?? {
      colWidth: 20,
      rowHeight: nt
    }
  );
}
function Ne(e, t) {
  const { brick: i } = t.brickMap.get(e) ?? {};
  return i;
}
function ke(e, t) {
  const i = t.brickMap.get(e);
  if (i)
    return t.sections.find((s) => s.id === i.sectionId);
}
function C(e, t) {
  for (const i of t.sections) {
    const s = i.bricks.find((u) => u.id === e);
    if (s)
      return s;
    const r = (u) => {
      var c;
      for (const o of u) {
        if (o.id === e)
          return o;
        if ((c = o.props) != null && c.$children) {
          const a = r(o.props.$children);
          if (a)
            return a;
        }
      }
    }, n = r(i.bricks);
    if (n)
      return n;
  }
  return null;
}
function L(e) {
  const t = /* @__PURE__ */ new Map();
  function i(s, r, n) {
    var u;
    t.set(s.id, { brick: s, sectionId: r, parentId: n }), (u = s.props) != null && u.$children && s.props.$children.forEach((o) => i(o, r, s.id));
  }
  return e.forEach((s) => {
    s.bricks.forEach((r) => i(r, s.id, null));
  }), t;
}
export {
  Qt as $,
  yr as A,
  qt as B,
  fr as C,
  Lt as D,
  zt as E,
  Kt as F,
  ar as G,
  jt as H,
  br as I,
  Or as J,
  Ir as K,
  kr as L,
  A as M,
  Vr as N,
  nt as O,
  Pr as P,
  Ut as Q,
  or as R,
  wr as S,
  gr as T,
  Er as U,
  _r as V,
  rr as W,
  Tr as X,
  Mr as Y,
  P as Z,
  E as _,
  $r as a,
  sr as a0,
  dr as a1,
  hr as a2,
  Sr as a3,
  Cr as a4,
  At as a5,
  Br as b,
  Lr as c,
  Ar as d,
  Fr as e,
  Rr as f,
  Dr as g,
  er as h,
  Gt as i,
  lr as j,
  Zt as k,
  zr as l,
  Yt as m,
  pr as n,
  xr as o,
  ir as p,
  ur as q,
  Jt as r,
  tr as s,
  nr as t,
  mr as u,
  Wt as v,
  Ht as w,
  Xt as x,
  cr as y,
  vr as z
};
//# sourceMappingURL=use-editor.BDnIlF7c.js.map
