import { g as et, ak as tt, O as Z, C as W } from "./_commonjsHelpers.BCwc0xb5.js";
import "@sinclair/typebox";
import { debounce as rt, isEqual as Ee, merge as nt } from "lodash-es";
import J, { 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 Wt = 24, it = 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, c = i ? `${Oe}: ${i}` : Oe;
  throw new Error(c);
}
var He = Symbol.for("immer-nothing"), Ie = Symbol.for("immer-draftable"), k = Symbol.for("immer-state"), ot = 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 I(e, ...t) {
  if (process.env.NODE_ENV !== "production") {
    const i = ot[e], c = typeof i == "function" ? i.apply(null, t) : i;
    throw new Error(`[Immer] ${c}`);
  }
  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[k];
}
function z(e) {
  var t;
  return e ? Ge(e) || Array.isArray(e) || !!e[Ie] || !!((t = e.constructor) != null && t[Ie]) || ne(e) || ie(e) : !1;
}
var st = 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) === st;
}
function H(e, t) {
  re(e) === 0 ? Reflect.ownKeys(e).forEach((i) => {
    t(i, e[i], e);
  }) : e.forEach((i, c) => t(c, i, e));
}
function re(e) {
  const t = e[k];
  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 c = re(e);
  c === 2 ? e.set(t, i) : c === 3 ? e.add(i) : e[t] = i;
}
function ct(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 c = Object.getOwnPropertyDescriptors(e);
    delete c[k];
    let r = Reflect.ownKeys(c);
    for (let n = 0; n < r.length; n++) {
      const u = r[n], s = c[u];
      s.writable === !1 && (s.writable = !0, s.configurable = !0), (s.get || s.set) && (c[u] = {
        configurable: !0,
        writable: !0,
        // could live with !!desc.set as well here...
        enumerable: s.enumerable,
        value: e[u]
      });
    }
    return Object.create(F(e), c);
  } else {
    const c = F(e);
    if (c !== null && i)
      return { ...e };
    const r = Object.create(c);
    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 = at), Object.freeze(e), t && Object.entries(e).forEach(([i, c]) => Pe(c, !0))), e;
}
function at() {
  I(2);
}
function oe(e) {
  return Object.isFrozen(e);
}
var ve = {};
function R(e) {
  const t = ve[e];
  return t || I(0, e), t;
}
function ut(e, t) {
  ve[e] || (ve[e] = t);
}
var G;
function X() {
  return G;
}
function dt(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 Te(e, t) {
  t && (R("Patches"), e.patches_ = [], e.inversePatches_ = [], e.patchListener_ = t);
}
function be(e) {
  ye(e), e.drafts_.forEach(lt), e.drafts_ = null;
}
function ye(e) {
  e === G && (G = e.parent_);
}
function Be(e) {
  return G = dt(G, e);
}
function lt(e) {
  const t = e[k];
  t.type_ === 0 || t.type_ === 1 ? t.revoke_() : t.revoked_ = !0;
}
function Ce(e, t) {
  t.unfinalizedDrafts_ = t.drafts_.length;
  const i = t.drafts_[0];
  return e !== void 0 && e !== i ? (i[k].modified_ && (be(t), I(4)), z(e) && (e = Q(t, e), t.parent_ || ee(t, e)), t.patches_ && R("Patches").generateReplacementPatches_(
    i[k].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 c = t[k];
  if (!c)
    return H(
      t,
      (r, n) => De(e, c, t, r, n, i)
    ), t;
  if (c.scope_ !== e)
    return t;
  if (!c.modified_)
    return ee(e, c.base_, !0), c.base_;
  if (!c.finalized_) {
    c.finalized_ = !0, c.scope_.unfinalizedDrafts_--;
    const r = c.copy_;
    let n = r, u = !1;
    c.type_ === 3 && (n = new Set(r), r.clear(), u = !0), H(
      n,
      (s, o) => De(e, c, r, s, o, i, u)
    ), ee(e, r, !1), i && e.patches_ && R("Patches").generatePatches_(
      c,
      i,
      e.patches_,
      e.inversePatches_
    );
  }
  return c.copy_;
}
function De(e, t, i, c, r, n, u) {
  if (process.env.NODE_ENV !== "production" && r === i && I(5), V(r)) {
    const s = n && t && t.type_ !== 3 && // Set objects are atomic since they have no keys.
    !_e(t.assigned_, c) ? n.concat(c) : void 0, o = Q(e, r, s);
    if (Ue(i, c, 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 c != "symbol" && Object.prototype.propertyIsEnumerable.call(i, c) && ee(e, r);
  }
}
function ee(e, t, i = !1) {
  !e.parent_ && e.immer_.autoFreeze_ && e.canAutoFreeze_ && Pe(t, i);
}
function ft(e, t) {
  const i = Array.isArray(e), c = {
    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 = c, n = we;
  i && (r = [c], n = U);
  const { revoke: u, proxy: s } = Proxy.revocable(r, n);
  return c.draft_ = s, c.revoke_ = u, s;
}
var we = {
  get(e, t) {
    if (t === k)
      return e;
    const i = M(e);
    if (!_e(i, t))
      return pt(e, i, t);
    const c = i[t];
    return e.finalized_ || !z(c) ? c : c === le(e.base_, t) ? (fe(e), e.copy_[t] = K(c, e)) : c;
  },
  has(e, t) {
    return t in M(e);
  },
  ownKeys(e) {
    return Reflect.ownKeys(M(e));
  },
  set(e, t, i) {
    const c = Ke(M(e), t);
    if (c != null && c.set)
      return c.set.call(e.draft_, i), !0;
    if (!e.modified_) {
      const r = le(M(e), t), n = r == null ? void 0 : r[k];
      if (n && n.base_ === i)
        return e.copy_[t] = i, e.assigned_[t] = !1, !0;
      if (ct(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), c = Reflect.getOwnPropertyDescriptor(i, t);
    return c && {
      writable: !0,
      configurable: e.type_ !== 1 || t !== "length",
      enumerable: c.enumerable,
      value: i[t]
    };
  },
  defineProperty() {
    I(11);
  },
  getPrototypeOf(e) {
    return F(e.base_);
  },
  setPrototypeOf() {
    I(12);
  }
}, U = {};
H(we, (e, t) => {
  U[e] = function() {
    return arguments[0] = arguments[0][0], t.apply(this, arguments);
  };
});
U.deleteProperty = function(e, t) {
  return process.env.NODE_ENV !== "production" && isNaN(parseInt(t)) && I(13), U.set.call(this, e, t, void 0);
};
U.set = function(e, t, i) {
  return process.env.NODE_ENV !== "production" && t !== "length" && isNaN(parseInt(t)) && I(14), we.set.call(this, e[0], t, i, e[0]);
};
function le(e, t) {
  const i = e[k];
  return (i ? M(i) : e)[t];
}
function pt(e, t, i) {
  var r;
  const c = Ke(t, i);
  return c ? "value" in c ? c.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 = c.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 c = Object.getOwnPropertyDescriptor(i, t);
    if (c)
      return c;
    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 ht = class {
  constructor(e) {
    this.autoFreeze_ = !0, this.useStrictShallowCopy_ = !1, this.produce = (t, i, c) => {
      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" && I(6), c !== void 0 && typeof c != "function" && I(7);
      let r;
      if (z(t)) {
        const n = Be(this), u = K(t, void 0);
        let s = !0;
        try {
          r = i(u), s = !1;
        } finally {
          s ? be(n) : ye(n);
        }
        return Te(n, c), Ce(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), c) {
          const n = [], u = [];
          R("Patches").generateReplacementPatches_(t, r, n, u), c(n, u);
        }
        return r;
      } else
        I(1, t);
    }, this.produceWithPatches = (t, i) => {
      if (typeof t == "function")
        return (u, ...s) => this.produceWithPatches(u, (o) => t(o, ...s));
      let c, r;
      return [this.produce(t, i, (u, s) => {
        c = u, r = s;
      }), c, 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) || I(8), V(e) && (e = mt(e));
    const t = Be(this), i = K(e, void 0);
    return i[k].isManual_ = !0, ye(t), i;
  }
  finishDraft(e, t) {
    const i = e && e[k];
    (!i || !i.isManual_) && I(9);
    const { scope_: c } = i;
    return Te(c, t), Ce(void 0, c);
  }
  /**
   * 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 c = R("Patches").applyPatches_;
    return V(e) ? c(e, t) : this.produce(
      e,
      (r) => c(r, t)
    );
  }
};
function K(e, t) {
  const i = ne(e) ? R("MapSet").proxyMap_(e, t) : ie(e) ? R("MapSet").proxySet_(e, t) : ft(e, t);
  return (t ? t.scope_ : X()).drafts_.push(i), i;
}
function mt(e) {
  return V(e) || I(10, e), qe(e);
}
function qe(e) {
  if (!z(e) || oe(e))
    return e;
  const t = e[k];
  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 H(i, (c, r) => {
    Ue(i, c, qe(r));
  }), t && (t.finalized_ = !1), i;
}
function St() {
  class e extends Map {
    constructor(o, a) {
      super(), this[k] = {
        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[k]).size;
    }
    has(o) {
      return M(this[k]).has(o);
    }
    set(o, a) {
      const d = this[k];
      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[k];
      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[k];
      u(o), M(o).size && (i(o), $(o), o.assigned_ = /* @__PURE__ */ new Map(), H(o.base_, (a) => {
        o.assigned_.set(a, !1);
      }), o.copy_.clear());
    }
    forEach(o, a) {
      const d = this[k];
      M(d).forEach((l, f, p) => {
        o.call(a, this.get(f), f, this);
      });
    }
    get(o) {
      const a = this[k];
      u(a);
      const d = M(a).get(o);
      if (a.finalized_ || !z(d) || d !== a.base_.get(o))
        return d;
      const l = K(d, a);
      return i(a), a.copy_.set(o, l), l;
    }
    keys() {
      return M(this[k]).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(s, o) {
    return new e(s, o);
  }
  function i(s) {
    s.copy_ || (s.assigned_ = /* @__PURE__ */ new Map(), s.copy_ = new Map(s.base_));
  }
  class c extends Set {
    constructor(o, a) {
      super(), this[k] = {
        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[k]).size;
    }
    has(o) {
      const a = this[k];
      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[k];
      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[k];
      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[k];
      u(o), M(o).size && (n(o), $(o), o.copy_.clear());
    }
    values() {
      const o = this[k];
      return u(o), n(o), o.copy_.values();
    }
    entries() {
      const o = this[k];
      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(s, o) {
    return new c(s, o);
  }
  function n(s) {
    s.copy_ || (s.copy_ = /* @__PURE__ */ new Set(), s.base_.forEach((o) => {
      if (z(o)) {
        const a = K(o, s);
        s.drafts_.set(o, a), s.copy_.add(a);
      } else
        s.copy_.add(o);
    }));
  }
  function u(s) {
    s.revoked_ && I(3, JSON.stringify(M(s)));
  }
  ut("MapSet", { proxyMap_: t, proxySet_: r });
}
var B = new ht(), _t = 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 gt = {}, $e = (e) => {
  let t;
  const i = /* @__PURE__ */ new Set(), c = (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: c, getState: r, getInitialState: () => a, subscribe: (d) => (i.add(d), () => i.delete(d)), destroy: () => {
    (gt ? "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(c, r, o);
  return o;
}, Me = (e) => e ? $e(e) : $e;
var ke = { 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 vt() {
  if (ze) return he;
  ze = 1;
  var e = J;
  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, c = e.useState, r = e.useEffect, n = e.useLayoutEffect, u = e.useDebugValue;
  function s(l, f) {
    var p = f(), m = c({ 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 : s;
  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 bt() {
  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 = J, 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), x = 1; x < b; x++)
          w[x - 1] = arguments[x];
        c("error", v, w);
      }
    }
    function c(v, b, w) {
      {
        var x = t.ReactDebugCurrentFrame, O = x.getStackAddendum();
        O !== "" && (b += "%s", w = w.concat([O]));
        var C = w.map(function(T) {
          return String(T);
        });
        C.unshift("Warning: " + b), Function.prototype.apply.call(console[v], console, C);
      }
    }
    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, s = 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 x = b();
      if (!l) {
        var O = b();
        n(x, O) || (i("The result of getSnapshot should be cached to avoid an infinite loop"), l = !0);
      }
      var C = u({
        inst: {
          value: x,
          getSnapshot: b
        }
      }), T = C[0].inst, N = C[1];
      return o(function() {
        T.value = x, T.getSnapshot = b, p(T) && N({
          inst: T
        });
      }, [v, x, b]), s(function() {
        p(T) && N({
          inst: T
        });
        var se = function() {
          p(T) && N({
            inst: T
          });
        };
        return v(se);
      }, [v]), a(x), x;
    }
    function p(v) {
      var b = v.getSnapshot, w = v.value;
      try {
        var x = b();
        return !n(w, x);
      } 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 = vt() : Y.exports = bt()), 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 yt() {
  if (Re) return pe;
  Re = 1;
  var e = J, t = Je();
  function i(a, d) {
    return a === d && (a !== 0 || 1 / a === 1 / d) || a !== a && d !== d;
  }
  var c = typeof Object.is == "function" ? Object.is : i, r = t.useSyncExternalStore, n = e.useRef, u = e.useEffect, s = 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 = s(function() {
      function y(x) {
        if (!_) {
          if (_ = !0, v = x, x = f(x), p !== void 0 && h.hasValue) {
            var O = h.value;
            if (p(O, x)) return b = O;
          }
          return b = x;
        }
        if (O = b, c(v, x)) return O;
        var C = f(x);
        return p !== void 0 && p(O, C) ? O : (v = x, b = C);
      }
      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 kt() {
  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 = J, t = Je();
    function i(d, l) {
      return d === l && (d !== 0 || 1 / d === 1 / l) || d !== d && l !== l;
    }
    var c = typeof Object.is == "function" ? Object.is : i, r = t.useSyncExternalStore, n = e.useRef, u = e.useEffect, s = 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 = s(function() {
        var w = !1, x, O, C = function(j) {
          if (!w) {
            w = !0, x = 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 = x, ue = O;
          if (c(Qe, j))
            return ue;
          var de = p(j);
          return m !== void 0 && m(ue, de) ? ue : (x = j, O = de, de);
        }, T = f === void 0 ? null : f, N = function() {
          return C(l());
        }, se = T === null ? void 0 : function() {
          return C(T());
        };
        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" ? ke.exports = yt() : ke.exports = kt();
var xt = ke.exports;
const Et = /* @__PURE__ */ et(xt), { useDebugValue: Pt } = J, { useSyncExternalStoreWithSelector: wt } = Et, Mt = (e) => e;
function g(e, t = Mt, i) {
  const c = wt(
    e.subscribe,
    e.getState,
    e.getServerState || e.getInitialState,
    t,
    i
  );
  return Pt(c), c;
}
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 s, o;
    if (n().pastStates.length) {
      const a = ((s = i == null ? void 0 : i.partialize) == null ? void 0 : s.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 s, o;
    if (n().futureStates.length) {
      const a = ((s = i == null ? void 0 : i.partialize) == null ? void 0 : s.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, s, 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) => (c, r, n) => {
  var a, d;
  n.temporal = Me(
    ((a = t == null ? void 0 : t.wrapTemporal) == null ? void 0 : a.call(t, Ve(c, r, t))) || Ve(c, 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, s = (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), s(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();
      c(...l), s(f);
    },
    r,
    n
  );
};
const Ot = {}, It = (e) => (t, i, c) => {
  const r = c.subscribe;
  return c.subscribe = (u, s, o) => {
    let a = u;
    if (s) {
      const d = (o == null ? void 0 : o.equalityFn) || Object.is;
      let l = u(c.getState());
      a = (f) => {
        const p = u(f);
        if (!d(l, p)) {
          const m = l;
          s(l = p, m);
        }
      }, o != null && o.fireImmediately && s(l, l);
    }
    return r(a);
  }, e(t, i, c);
}, Ye = It;
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), s = (n = i.getItem(r)) != null ? n : null;
      return s instanceof Promise ? s.then(u) : u(s);
    },
    setItem: (r, n) => i.setItem(
      r,
      JSON.stringify(n, void 0)
    ),
    removeItem: (r) => i.removeItem(r)
  };
}
const q = (e) => (t) => {
  try {
    const i = e(t);
    return i instanceof Promise ? i : {
      then(c) {
        return q(c)(i);
      },
      catch(c) {
        return this;
      }
    };
  } catch (i) {
    return {
      then(c) {
        return this;
      },
      catch(c) {
        return q(c)(i);
      }
    };
  }
}, Bt = (e, t) => (i, c, 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 s = /* @__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);
      },
      c,
      r
    );
  const d = q(n.serialize), l = () => {
    const S = n.partialize({ ...c() });
    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();
    },
    c,
    r
  );
  let m;
  const h = () => {
    var S;
    if (!a) return;
    u = !1, s.forEach((_) => _(c()));
    const y = ((S = n.onRehydrateStorage) == null ? void 0 : S.call(n, c())) || void 0;
    return q(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 = c()) != 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) => (s.add(S), () => {
      s.delete(S);
    }),
    onFinishHydration: (S) => (o.add(S), () => {
      o.delete(S);
    })
  }, h(), m || p;
}, Ct = (e, t) => (i, c, r) => {
  let n = {
    storage: Tt(() => localStorage),
    partialize: (h) => h,
    version: 0,
    merge: (h, S) => ({
      ...S,
      ...h
    }),
    ...t
  }, u = !1;
  const s = /* @__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);
      },
      c,
      r
    );
  const d = () => {
    const h = n.partialize({ ...c() });
    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();
    },
    c,
    r
  );
  r.getInitialState = () => f;
  let p;
  const m = () => {
    var h, S;
    if (!a) return;
    u = !1, s.forEach((_) => {
      var v;
      return _((v = c()) != null ? v : f);
    });
    const y = ((S = n.onRehydrateStorage) == null ? void 0 : S.call(n, (h = c()) != null ? h : f)) || void 0;
    return q(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 = c()) != null ? v : f
      ), i(p, !0), b)
        return d();
    }).then(() => {
      y == null || y(p, void 0), p = c(), 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) => (s.add(h), () => {
      s.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 ? ((Ot ? "production" : void 0) !== "production" && console.warn(
  "[DEPRECATED] `getStorage`, `serialize` and `deserialize` options are deprecated. Use `storage` option instead."
), Bt(e, t)) : Ct(e, t), $t = Dt, zt = (e) => (t, i, c) => (c.setState = (r, n, ...u) => {
  const s = typeof r == "function" ? _t(r) : r;
  return t(s, n, ...u);
}, e(c.setState, i, c)), Xe = zt;
St();
const Ht = (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(
      $t(
        Ze(
          Xe((i, c) => ({
            ...t,
            ...e,
            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, c) => Ee(i, c)
          }
        ),
        {
          name: "editor-state",
          partialize: (i) => Object.fromEntries(
            Object.entries(i).filter(([c]) => ["chatVisible", "previewMode"].includes(c))
          )
        }
      )
    )
  );
}, Gt = (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, c) => ({
          ...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: s, sectionId: o, parentId: a } = u;
            if (!a) {
              console.warn("Cannot detach brick %s, it is not in a container", r);
              return;
            }
            const d = D(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, {
              ...s
            }), n.brickMap = L(n.sections);
          }),
          createEmptySection: (r, n) => i((u) => {
            var d;
            const s = u.sections.length, o = 1 + (n ? ((d = u.sections.find((l) => l.id === n)) == null ? void 0 : d.order) ?? s : s), a = {
              id: r,
              order: o,
              label: `Section ${s + 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 = c().sections.find((s) => s.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((s) => s.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 = c(), n = r.sitemap.length + 1;
            return console.log("state.sitemap", r.sitemap), {
              id: `page-${W()}`,
              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 = c();
            return ((u = n.sections.find((s) => s.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((s) => s.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((s) => s.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 s = u.sections.findIndex((o) => o.id === r);
            s !== -1 && (u.sections[s] = {
              ...u.sections[s],
              ...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 s = n.sections.findIndex((a) => a.id === r), o = {
              ...u,
              id: `s_${W()}`,
              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_${W()}`,
                  props: Z({}, a.props, {
                    $children: (d = a.props.$children) == null ? void 0 : d.map((l) => ({
                      ...l,
                      id: `b_${W()}`
                    }))
                  })
                };
              })
            };
            n.sections.splice(s + 1, 0, o), n.brickMap = L(n.sections);
          }),
          deleteSection: (r) => i((n) => {
            if (!n.sections.find((s) => s.id === r))
              return console.warn("Cannot delete section %s: not found", r), null;
            n.brickMap.forEach((s) => {
              s.sectionId === r && n.brickMap.delete(s.brick.id);
            }), n.sections = n.sections.filter((s) => s.id !== r);
          }),
          getSection: (r) => c().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 s = n.sections.find((a) => a.order === u.order - 1);
            n.sections.findIndex((a) => a.order === u.order - 1), A(s, "Previous section not found");
            const o = u.order;
            u.order = s.order, s.order = o;
          }),
          moveSectionDown: (r) => i((n) => {
            const u = n.sections.find((f) => f.id === r), s = 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[s].order = l, n.sections[a].order = d;
          }),
          reorderSections: (r) => i((n) => {
            const u = [];
            let s = 0;
            r.forEach((o) => {
              const a = n.sections.find((d) => d.id === o);
              a && u.push({ ...a, order: ++s });
            }), n.sections.forEach((o) => {
              r.includes(o.id) || u.push({ ...o, order: ++s });
            }), 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 s = [], 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) => {
                s.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 = D(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), s.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 s = (f) => {
              const p = `brick-${W()}`, 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) => s(S));
              }
              return m;
            }, o = s(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 = D(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 s = Ne(r, u);
            s && Object.assign(s, n);
          }),
          updateBrickProps: (r, n, u) => i((s) => {
            const o = D(r, s);
            if (o) {
              u ? o.mobileProps = Z({}, o.mobileProps, n, {
                lastTouched: Date.now()
              }) : o.props = Z({}, o.props, n, {
                lastTouched: Date.now()
              });
              const a = D(r, s);
              if (!a) {
                console.error("Cannot update brick %s, it does not exist in the draft", r);
                return;
              }
              a.props = o.props, a.mobileProps = o.mobileProps, s.brickMap = L(s.sections);
            } else
              console.error("Cannot update brick %s, it does not exist in the brick map", r);
          }),
          updateSectionProps: (r, n, u) => i((s) => {
            const o = s.sections.find((a) => a.id === r);
            o ? u ? o.mobileProps = Z({}, o.mobileProps, n, {
              lastTouched: Date.now()
            }) : o.props = nt({}, 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 s = [], o = -1;
            const a = u.getParentBrick(r);
            a ? (s = D(a.id, u).props.$children, o = s.findIndex((p) => p.id === r)) : (s = xe(r, u).bricks, o = s.findIndex((p) => p.id === r));
            const d = n === "previous" ? Math.max(0, o - 1) : Math.min(s.length - 1, o + 1);
            if (d === o)
              return;
            const [l] = s.splice(o, 1);
            s.splice(d, 0, l), u.brickMap = L(u.sections);
          }),
          /**
           * Reorder a brick within its section using indices
           */
          reorderBrickWithin: (r, n) => i((u) => {
            const s = u.brickMap.get(r);
            if (!s) {
              console.error("Cannot reorder brick %s, brick mapping not found", r);
              return;
            }
            const { sectionId: o, parentId: a } = s;
            if (a) {
              const d = D(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((s) => {
            const o = s.getBrick(r), a = D(n, s), d = s.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 = D(f, s);
              m != null && m.props.$children && (m.props.$children = m.props.$children.filter(
                (h) => h.id !== r
              ));
            } else {
              const m = s.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 = s.brickMap.get(n);
            if (p) {
              s.brickMap.set(r, {
                brick: o,
                sectionId: p.sectionId,
                parentId: n
              });
              const m = (h, S) => {
                var _;
                const y = s.brickMap.get(h);
                (_ = y == null ? void 0 : y.brick.props) != null && _.$children && y.brick.props.$children.forEach((b) => {
                  s.brickMap.set(b.id, {
                    brick: b,
                    sectionId: S,
                    parentId: h
                  }), m(b.id, S);
                });
              };
              m(r, p.sectionId);
            }
          }),
          moveBrickToSection: (r, n, u) => i((s) => {
            var m;
            const o = s.getBrick(r);
            n || (n = (m = s.brickMap.get(r)) == null ? void 0 : m.sectionId);
            const a = s.sections.find((h) => h.id === n), d = s.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 = D(f, s);
              h != null && h.props.$children && (h.props.$children = h.props.$children.filter(
                (S) => S.id !== r
              ));
            } else {
              const h = s.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), s.brickMap.set(r, {
              brick: o,
              sectionId: n,
              parentId: null
              // Top level in section
            });
            const p = (h, S, y) => {
              var v;
              const _ = s.brickMap.get(h);
              (v = _ == null ? void 0 : _.brick.props) != null && v.$children && _.brick.props.$children.forEach((w) => {
                s.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 = c().brickMap.get(r)) == null ? void 0 : n.brick;
          },
          getParentBrick: (r) => {
            var s;
            const n = c().brickMap, { parentId: u } = n.get(r) ?? {};
            if (u)
              return (s = n.get(u)) == null ? void 0 : s.brick;
          },
          getPositionWithinParent: (r) => {
            const n = c().getParentBrick(r);
            if (n && "$children" in n.props)
              return n.props.$children.findIndex((u) => u.id === r);
          },
          canMoveToWithinParent: (r, n) => {
            const u = c().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 s = xe(r, c()), o = s.bricks.findIndex((a) => a.id === r);
            return n === "previous" ? o > 0 : o < (s == null ? void 0 : s.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 s = D(r, u);
            s && ((o = s.props).hidden ?? (o.hidden = { desktop: !1, mobile: !1 }), s.props.hidden[n] = !((a = s.props.hidden) != null && a[n]));
          }),
          addBrick: (r, n, u, s) => 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 (s) {
              if (console.log("Adding brick to parent container", s), !Ne(s, o)) {
                console.warn("Cannot add brick, parent container %s does not exist", s);
                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 === s);
              if (!p) {
                console.warn(
                  "Cannot add brick, parent brick %s does not exist in section %s",
                  s,
                  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: s
            }), (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 = { ...c().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, c) => Ee(i, c),
          partialize: (i) => Object.fromEntries(
            Object.entries(i).filter(([c]) => ["sections", "attr"].includes(c))
          )
          // handleSet: (handleSet) =>
          //   debounce<typeof handleSet>((state) => {
          //     if (state) {
          //       handleSet(state);
          //     }
          //   }, 200),
        }
      )
    )
  );
}, Lt = je(null), At = je(null), E = () => {
  const e = We(Lt);
  return e || console.log("Problem with EditorStoreContext", e), A(e, "useEditorStoreContext must be used within a EditorStoreContext"), e;
}, P = () => {
  const e = We(At);
  return A(e, "useDraftStoreContext must be used within a DraftStoreContext"), e;
}, Ut = () => P().temporal.getState(), Kt = () => {
  const e = E();
  return g(e);
}, qt = () => {
  const e = E();
  return g(e, (t) => t.sitePrompt);
}, Jt = () => {
  const e = P();
  return g(e, (t) => t.sitemap);
}, Zt = () => {
  const e = E();
  return g(e, (t) => t.previewMode);
}, Yt = () => {
  const e = P();
  return g(e, (t) => {
    const i = t.sitemap.length > 0, c = t.themes.length > 0, r = i && c && t.sitemap.length > 0, n = new URL(window.location.href).searchParams.get("action") === "generate";
    return {
      hasSitemap: i,
      hasThemesGenerated: c,
      sitemap: t.sitemap,
      pages: t.pages,
      isReady: !n || r || !1
    };
  });
}, Xt = () => {
  const e = E();
  return g(e, (t) => !t.disabled);
}, Qt = () => {
  const e = E();
  return g(e, (t) => t.logoLink);
}, er = () => {
  const e = E();
  return g(e, (t) => t.selectedGroup);
}, tr = () => {
  const e = E();
  return g(e, (t) => t.selectedBrickId);
};
function rr() {
  const e = E();
  return g(e, (t) => t.selectedSectionId);
}
function nr() {
  const e = E(), t = P();
  return g(e, (i) => {
    const c = t.getState().sections.find((r) => r.id === i.selectedSectionId);
    return c || null;
  });
}
const ir = () => {
  const e = E();
  return g(e, (t) => !!t.debugMode);
}, or = () => {
  const e = E();
  return g(e, (t) => ({
    panel: t.panel,
    panelPosition: t.panelPosition
  }));
}, sr = () => {
  const e = E();
  return g(e, (t) => t.planIndex > 0);
};
function cr(e) {
  const t = E();
  return g(t, (i) => i.planIndex >= e);
}
const ar = () => {
  const e = E();
  return g(e, (t) => t.mode);
}, ur = () => {
  const e = P(), t = g(e, (c) => c.pages);
  return {
    site: Rt(),
    pages: t
  };
}, dr = () => {
  const e = P();
  return g(e, (t) => t.themes);
}, lr = () => {
  const e = E();
  return g(e, (t) => t.themesLibrary);
}, fr = () => {
  const e = E();
  return g(e, (t) => t.imagesSearchResults);
}, pr = () => {
  const e = E();
  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
  }));
}, hr = () => {
  const e = E();
  return g(e, (t) => !!t.chatVisible);
}, mr = () => {
  const e = E();
  return g(e, (t) => t.textEditMode);
}, Sr = () => {
  const e = P();
  return g(e);
}, _r = () => {
  const e = P();
  return g(e, (t) => t.getBrick);
};
function gr() {
  const e = P();
  return g(e, (t) => t.version);
}
function vr() {
  const e = E();
  return g(e, (t) => t.isEditingTextForBrickId);
}
function br() {
  const e = P();
  return g(e, (t) => t.lastSaved);
}
const yr = () => {
  const e = P(), t = g(e, (i) => i.sections);
  return tt(t);
}, kr = (e) => {
  const t = P();
  return g(t, (i) => {
    const c = i.sections.find((r) => e && r.id === e);
    return c ? {
      section: c,
      bricks: Array.from(i.brickMap).filter(([, r]) => r.sectionId === e)
    } : null;
  });
}, xr = (e) => {
  const t = P();
  return g(t, (i) => xe(e, i));
}, Er = () => {
  const e = P();
  return g(e, (t) => t.attr);
}, Pr = () => {
  const e = P();
  return g(e, (t) => t.attributes ?? t.siteAttributes);
}, wr = () => {
  const e = P();
  return g(e, (t) => t.datasources);
}, Mr = () => {
  const e = E();
  return g(e, (t) => t.draggingBrickType);
}, Or = () => {
  const e = E();
  return g(e, (t) => t.contextMenuVisible);
}, Ir = () => {
  const e = E();
  return g(e, (t) => ({
    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
  }));
}, Tr = () => {
  const e = P();
  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
  }));
}, Br = () => {
  const e = P();
  return g(e, (t) => t.datarecords);
}, Cr = () => {
  const e = P();
  return g(e, (t) => ({
    id: t.id,
    path: t.path,
    label: t.label,
    siteLabel: t.siteLabel,
    siteId: t.siteId,
    hostname: t.hostname
  }));
}, Rt = () => {
  const e = P(), 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 = E(), c = g(i, (r) => r.sitePrompt);
  return {
    ...t,
    sitePrompt: c
  };
}, Dr = () => {
  const e = P();
  return g(e, (t) => t.theme);
}, $r = (e) => {
  const t = P();
  te(() => t.subscribe((i) => (i == null ? void 0 : i.sections) ?? [], rt(e, 200), {
    fireImmediately: !1
  }), []);
}, zr = (e) => {
  const t = P();
  te(() => t.subscribe((i) => i.attr, e, {
    equalityFn: Ee
  }), []);
}, Lr = (e) => {
  const t = P();
  te(() => t.subscribe((i) => i.theme, e), []);
}, Ar = (e) => {
  const t = P();
  te(() => t.subscribe((i) => i.path, e), []);
};
function Rr() {
  const e = E();
  return g(
    e,
    (t) => t.gridConfig ?? {
      colWidth: 20,
      rowHeight: it
    }
  );
}
function Ne(e, t) {
  const { brick: i } = t.brickMap.get(e) ?? {};
  return i;
}
function xe(e, t) {
  const i = t.brickMap.get(e);
  if (i)
    return t.sections.find((c) => c.id === i.sectionId);
}
function D(e, t) {
  for (const i of t.sections) {
    const c = i.bricks.find((u) => u.id === e);
    if (c)
      return c;
    const r = (u) => {
      var s;
      for (const o of u) {
        if (o.id === e)
          return o;
        if ((s = o.props) != null && s.$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(c, r, n) {
    var u;
    t.set(c.id, { brick: c, sectionId: r, parentId: n }), (u = c.props) != null && u.$children && c.props.$children.forEach((o) => i(o, r, c.id));
  }
  return e.forEach((c) => {
    c.bricks.forEach((r) => i(r, c.id, null));
  }), t;
}
export {
  lr as $,
  br as A,
  Jt as B,
  pr as C,
  At as D,
  Lt as E,
  qt as F,
  ur as G,
  Wt as H,
  vr as I,
  Mr as J,
  kr as K,
  A as L,
  Rr as M,
  Er as N,
  it as O,
  Kt as P,
  sr as Q,
  _r as R,
  Pr as S,
  xr as T,
  nr as U,
  Or as V,
  wr as W,
  E as X,
  P as Y,
  er as Z,
  cr as _,
  Cr as a,
  mr as a0,
  Br as a1,
  Rt as a2,
  Ir as b,
  $r as c,
  zr as d,
  Ar as e,
  Lr as f,
  Tr as g,
  tr as h,
  Ut as i,
  fr as j,
  Yt as k,
  Dr as l,
  Xt as m,
  hr as n,
  yr as o,
  or as p,
  dr as q,
  Zt as r,
  rr as s,
  ir as t,
  Sr as u,
  Ht as v,
  Gt as w,
  Qt as x,
  ar as y,
  gr as z
};
//# sourceMappingURL=use-editor.CHZsl_Yo.js.map
