import { jsxs as E, jsx as f } from "react/jsx-runtime";
import { u as le, a as je, b as ce, c as Ke, d as _e, e as Oe, f as Fe, g as ue, h as ye, i as We, j as Ve, k as be, l as qe, m as Ue, n as Ge, o as Xe, p as Ye, q as Je, r as Qe, s as Ze, t as et } from "./use-editor.CHZsl_Yo.js";
import * as d from "react";
import { useState as oe, useRef as O, useCallback as tt, useLayoutEffect as rt, useEffect as X, useContext as ke, createContext as we, lazy as z, Suspense as K, startTransition as nt } from "react";
import { _ as I, B as _, r as st } from "./twind.BLUk_ZzT.js";
import { c as ot, O as at } from "./index.Bxix3KXR.js";
import { u as me } from "./index.BsxM-ToU.js";
import { getThemeCss as it } from "../get-theme-css.js";
import { D as lt } from "./dnd.esm.ByOls-Fs.js";
import { f as Z, C as U, r as G } from "./_commonjsHelpers.BCwc0xb5.js";
import "@sinclair/typebox";
import "lodash-es";
import { S as xe, y as F, V as ct, u as ut, a as dt, c as pt, P as Se, b as ft, d as mt } from "./index.DaRbhbpm.js";
import { e as gt, t as vt, o as ht, p as yt, u as bt } from "./index.ChhKNKNO.js";
import { r as Ne, o as Ee, s as kt, a as Ce, v as J, b as Q, c as wt } from "./radius.prop.B549yVS5.js";
const T = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"], xt = { p: { type: "enum | string", className: "rt-r-p", customProperties: ["--p"], values: T, responsive: !0 }, px: { type: "enum | string", className: "rt-r-px", customProperties: ["--pl", "--pr"], values: T, responsive: !0 }, py: { type: "enum | string", className: "rt-r-py", customProperties: ["--pt", "--pb"], values: T, responsive: !0 }, pt: { type: "enum | string", className: "rt-r-pt", customProperties: ["--pt"], values: T, responsive: !0 }, pr: { type: "enum | string", className: "rt-r-pr", customProperties: ["--pr"], values: T, responsive: !0 }, pb: { type: "enum | string", className: "rt-r-pb", customProperties: ["--pb"], values: T, responsive: !0 }, pl: { type: "enum | string", className: "rt-r-pl", customProperties: ["--pl"], values: T, responsive: !0 } }, ee = ["visible", "hidden", "clip", "scroll", "auto"], St = ["static", "relative", "absolute", "fixed", "sticky"], q = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "-1", "-2", "-3", "-4", "-5", "-6", "-7", "-8", "-9"], Nt = ["0", "1"], Et = ["0", "1"], Ct = { ...xt, ...vt, ...gt, position: { type: "enum", className: "rt-r-position", values: St, responsive: !0 }, inset: { type: "enum | string", className: "rt-r-inset", customProperties: ["--inset"], values: q, responsive: !0 }, top: { type: "enum | string", className: "rt-r-top", customProperties: ["--top"], values: q, responsive: !0 }, right: { type: "enum | string", className: "rt-r-right", customProperties: ["--right"], values: q, responsive: !0 }, bottom: { type: "enum | string", className: "rt-r-bottom", customProperties: ["--bottom"], values: q, responsive: !0 }, left: { type: "enum | string", className: "rt-r-left", customProperties: ["--left"], values: q, responsive: !0 }, overflow: { type: "enum", className: "rt-r-overflow", values: ee, responsive: !0 }, overflowX: { type: "enum", className: "rt-r-ox", values: ee, responsive: !0 }, overflowY: { type: "enum", className: "rt-r-oy", values: ee, responsive: !0 }, flexBasis: { type: "string", className: "rt-r-fb", customProperties: ["--flex-basis"], responsive: !0 }, flexShrink: { type: "enum | string", className: "rt-r-fs", customProperties: ["--flex-shrink"], values: Nt, responsive: !0 }, flexGrow: { type: "enum | string", className: "rt-r-fg", customProperties: ["--flex-grow"], values: Et, responsive: !0 }, gridArea: { type: "string", className: "rt-r-ga", customProperties: ["--grid-area"], responsive: !0 }, gridColumn: { type: "string", className: "rt-r-gc", customProperties: ["--grid-column"], responsive: !0 }, gridColumnStart: { type: "string", className: "rt-r-gcs", customProperties: ["--grid-column-start"], responsive: !0 }, gridColumnEnd: { type: "string", className: "rt-r-gce", customProperties: ["--grid-column-end"], responsive: !0 }, gridRow: { type: "string", className: "rt-r-gr", customProperties: ["--grid-row"], responsive: !0 }, gridRowStart: { type: "string", className: "rt-r-grs", customProperties: ["--grid-row-start"], responsive: !0 }, gridRowEnd: { type: "string", className: "rt-r-gre", customProperties: ["--grid-row-end"], responsive: !0 } }, Pt = ["1", "2", "3", "4"], $t = ["classic", "solid", "soft", "surface", "outline", "ghost"], ge = { ...Ce, size: { type: "enum", className: "rt-r-size", values: Pt, default: "2", responsive: !0 }, variant: { type: "enum", className: "rt-variant", values: $t, default: "solid" }, ...kt, ...Ee, ...Ne, loading: { type: "boolean", className: "rt-loading", default: !1 } }, te = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"], It = { gap: { type: "enum | string", className: "rt-r-gap", customProperties: ["--gap"], values: te, responsive: !0 }, gapX: { type: "enum | string", className: "rt-r-cg", customProperties: ["--column-gap"], values: te, responsive: !0 }, gapY: { type: "enum | string", className: "rt-r-rg", customProperties: ["--row-gap"], values: te, responsive: !0 } }, Bt = ["div", "span"], Dt = ["none", "inline-flex", "flex"], Rt = ["row", "column", "row-reverse", "column-reverse"], Lt = ["start", "center", "end", "baseline", "stretch"], At = ["start", "center", "end", "between"], Ht = ["nowrap", "wrap", "wrap-reverse"], Tt = { as: { type: "enum", values: Bt, default: "div" }, ...Ce, display: { type: "enum", className: "rt-r-display", values: Dt, responsive: !0 }, direction: { type: "enum", className: "rt-r-fd", values: Rt, responsive: !0 }, align: { type: "enum", className: "rt-r-ai", values: Lt, responsive: !0 }, justify: { type: "enum", className: "rt-r-jc", values: At, parseValue: zt, responsive: !0 }, wrap: { type: "enum", className: "rt-r-fw", values: Ht, responsive: !0 }, ...It };
function zt(e) {
  return e === "between" ? "space-between" : e;
}
const Y = d.forwardRef((e, t) => {
  const { className: r, asChild: n, as: u = "div", ...l } = J(e, Tt, Ct, Q);
  return d.createElement(n ? xe : u, { ...l, ref: t, className: F("rt-Flex", r) });
});
Y.displayName = "Flex";
const Mt = ["1", "2", "3"], jt = { size: { type: "enum", className: "rt-r-size", values: Mt, default: "2", responsive: !0 }, loading: { type: "boolean", default: !0 } }, Pe = d.forwardRef((e, t) => {
  const { className: r, children: n, loading: u, ...l } = J(e, jt, Q);
  if (!u) return n;
  const s = d.createElement("span", { ...l, ref: t, className: F("rt-Spinner", r) }, d.createElement("span", { className: "rt-SpinnerLeaf" }), d.createElement("span", { className: "rt-SpinnerLeaf" }), d.createElement("span", { className: "rt-SpinnerLeaf" }), d.createElement("span", { className: "rt-SpinnerLeaf" }), d.createElement("span", { className: "rt-SpinnerLeaf" }), d.createElement("span", { className: "rt-SpinnerLeaf" }), d.createElement("span", { className: "rt-SpinnerLeaf" }), d.createElement("span", { className: "rt-SpinnerLeaf" }));
  return n === void 0 ? s : d.createElement(Y, { asChild: !0, position: "relative", align: "center", justify: "center" }, d.createElement("span", null, d.createElement("span", { "aria-hidden": !0, style: { display: "contents", visibility: "hidden" }, inert: void 0 }, n), d.createElement(Y, { asChild: !0, align: "center", justify: "center", position: "absolute", inset: "0" }, d.createElement("span", null, s))));
});
Pe.displayName = "Spinner";
const $e = d.forwardRef((e, t) => {
  const { size: r = ge.size.default } = e, { className: n, children: u, asChild: l, color: s, radius: i, disabled: p = e.loading, ...c } = J(e, ge, Q);
  return d.createElement(l ? xe : "button", { "data-disabled": p || void 0, "data-accent-color": s, "data-radius": i, ...c, ref: t, className: F("rt-reset", "rt-BaseButton", n), disabled: p }, e.loading ? d.createElement(d.Fragment, null, d.createElement("span", { style: { display: "contents", visibility: "hidden" }, "aria-hidden": !0 }, u), d.createElement(ct, null, u), d.createElement(Y, { asChild: !0, align: "center", justify: "center", position: "absolute", inset: "0" }, d.createElement("span", null, d.createElement(Pe, { size: ht(r, yt) })))) : u);
});
$e.displayName = "BaseButton";
const ae = d.forwardRef(({ className: e, ...t }, r) => d.createElement($e, { ...t, ref: r, className: F("rt-Button", e) }));
ae.displayName = "Button";
var de = "Switch", [Kt, zr] = pt(de), [_t, Ot] = Kt(de), Ie = d.forwardRef(
  (e, t) => {
    const {
      __scopeSwitch: r,
      name: n,
      checked: u,
      defaultChecked: l,
      required: s,
      disabled: i,
      value: p = "on",
      onCheckedChange: c,
      ...y
    } = e, [m, b] = d.useState(null), o = ut(t, (R) => b(R)), B = d.useRef(!1), D = m ? !!m.closest("form") : !0, [w = !1, k] = dt({
      prop: u,
      defaultProp: l,
      onChange: c
    });
    return /* @__PURE__ */ E(_t, { scope: r, checked: w, disabled: i, children: [
      /* @__PURE__ */ f(
        Se.button,
        {
          type: "button",
          role: "switch",
          "aria-checked": w,
          "aria-required": s,
          "data-state": Re(w),
          "data-disabled": i ? "" : void 0,
          disabled: i,
          value: p,
          ...y,
          ref: o,
          onClick: ft(e.onClick, (R) => {
            k((M) => !M), D && (B.current = R.isPropagationStopped(), B.current || R.stopPropagation());
          })
        }
      ),
      D && /* @__PURE__ */ f(
        Ft,
        {
          control: m,
          bubbles: !B.current,
          name: n,
          value: p,
          checked: w,
          required: s,
          disabled: i,
          style: { transform: "translateX(-100%)" }
        }
      )
    ] });
  }
);
Ie.displayName = de;
var Be = "SwitchThumb", De = d.forwardRef(
  (e, t) => {
    const { __scopeSwitch: r, ...n } = e, u = Ot(Be, r);
    return /* @__PURE__ */ f(
      Se.span,
      {
        "data-state": Re(u.checked),
        "data-disabled": u.disabled ? "" : void 0,
        ...n,
        ref: t
      }
    );
  }
);
De.displayName = Be;
var Ft = (e) => {
  const { control: t, checked: r, bubbles: n = !0, ...u } = e, l = d.useRef(null), s = bt(r), i = mt(t);
  return d.useEffect(() => {
    const p = l.current, c = window.HTMLInputElement.prototype, m = Object.getOwnPropertyDescriptor(c, "checked").set;
    if (s !== r && m) {
      const b = new Event("click", { bubbles: n });
      m.call(p, r), p.dispatchEvent(b);
    }
  }, [s, r, n]), /* @__PURE__ */ f(
    "input",
    {
      type: "checkbox",
      "aria-hidden": !0,
      defaultChecked: r,
      ...u,
      tabIndex: -1,
      ref: l,
      style: {
        ...e.style,
        ...i,
        position: "absolute",
        pointerEvents: "none",
        opacity: 0,
        margin: 0
      }
    }
  );
};
function Re(e) {
  return e ? "checked" : "unchecked";
}
var Wt = Ie, Vt = De;
const qt = ["1", "2", "3"], Ut = ["classic", "surface", "soft"], Gt = { size: { type: "enum", className: "rt-r-size", values: qt, default: "2", responsive: !0 }, variant: { type: "enum", className: "rt-variant", values: Ut, default: "surface" }, ...wt, ...Ee, ...Ne }, Le = d.forwardRef((e, t) => {
  const { className: r, color: n, radius: u, ...l } = J(e, Gt, Q);
  return d.createElement(Wt, { "data-accent-color": n, "data-radius": u, ...l, asChild: !1, ref: t, className: F("rt-reset", "rt-SwitchRoot", r) }, d.createElement(Vt, { className: F("rt-SwitchThumb", { "rt-high-contrast": e.highContrast }) }));
});
Le.displayName = "Switch";
const ve = 1e3;
function Xt() {
  const e = le(), t = je(), { onSavePage: r, onSaveSite: n, onDraftChange: u } = ce(), l = me(async (i) => {
    await (r == null ? void 0 : r({
      pageId: t.id,
      pageVersionId: "latest",
      siteId: t.siteId,
      data: i
    })), e.setDirty(!1);
  }, ve), s = me(async (i) => {
    await (n == null ? void 0 : n({
      siteId: t.siteId,
      data: i
    })), e.setDirty(!1);
  }, ve);
  Ke((i) => {
    console.debug("Sections have changed, updating page version", i), e.setDirty(!0), l({ sections: i });
  }), _e((i) => {
    console.debug("Attributes have changed:", i), e.setDirty(!0), l({ attr: i });
  }), Oe((i) => {
    console.debug("pagePath has changed, updating page version"), e.setDirty(!0), l({ path: i });
  }), Fe((i) => {
    console.debug("theme has changed, updating page version"), e.setDirty(!0), s({ theme: i });
  });
}
function ie() {
  return ie = Object.assign ? Object.assign.bind() : function(e) {
    for (var t = 1; t < arguments.length; t++) {
      var r = arguments[t];
      for (var n in r) ({}).hasOwnProperty.call(r, n) && (e[n] = r[n]);
    }
    return e;
  }, ie.apply(null, arguments);
}
var Ae = ["shift", "alt", "meta", "mod", "ctrl"], Yt = {
  esc: "escape",
  return: "enter",
  ".": "period",
  ",": "comma",
  "-": "slash",
  " ": "space",
  "`": "backquote",
  "#": "backslash",
  "+": "bracketright",
  ShiftLeft: "shift",
  ShiftRight: "shift",
  AltLeft: "alt",
  AltRight: "alt",
  MetaLeft: "meta",
  MetaRight: "meta",
  OSLeft: "meta",
  OSRight: "meta",
  ControlLeft: "ctrl",
  ControlRight: "ctrl"
};
function A(e) {
  return (e && Yt[e] || e || "").trim().toLowerCase().replace(/key|digit|numpad|arrow/, "");
}
function Jt(e) {
  return Ae.includes(e);
}
function re(e, t) {
  return t === void 0 && (t = ","), e.split(t);
}
function ne(e, t, r) {
  t === void 0 && (t = "+");
  var n = e.toLocaleLowerCase().split(t).map(function(s) {
    return A(s);
  }), u = {
    alt: n.includes("alt"),
    ctrl: n.includes("ctrl") || n.includes("control"),
    shift: n.includes("shift"),
    meta: n.includes("meta"),
    mod: n.includes("mod")
  }, l = n.filter(function(s) {
    return !Ae.includes(s);
  });
  return ie({}, u, {
    keys: l,
    description: r,
    hotkey: e
  });
}
(function() {
  typeof document < "u" && (document.addEventListener("keydown", function(e) {
    e.key !== void 0 && He([A(e.key), A(e.code)]);
  }), document.addEventListener("keyup", function(e) {
    e.key !== void 0 && Te([A(e.key), A(e.code)]);
  })), typeof window < "u" && window.addEventListener("blur", function() {
    H.clear();
  });
})();
var H = /* @__PURE__ */ new Set();
function pe(e) {
  return Array.isArray(e);
}
function Qt(e, t) {
  t === void 0 && (t = ",");
  var r = pe(e) ? e : e.split(t);
  return r.every(function(n) {
    return H.has(n.trim().toLowerCase());
  });
}
function He(e) {
  var t = Array.isArray(e) ? e : [e];
  H.has("meta") && H.forEach(function(r) {
    return !Jt(r) && H.delete(r.toLowerCase());
  }), t.forEach(function(r) {
    return H.add(r.toLowerCase());
  });
}
function Te(e) {
  var t = Array.isArray(e) ? e : [e];
  e === "meta" ? H.clear() : t.forEach(function(r) {
    return H.delete(r.toLowerCase());
  });
}
function Zt(e, t, r) {
  (typeof r == "function" && r(e, t) || r === !0) && e.preventDefault();
}
function er(e, t, r) {
  return typeof r == "function" ? r(e, t) : r === !0 || r === void 0;
}
function tr(e) {
  return ze(e, ["input", "textarea", "select"]);
}
function ze(e, t) {
  t === void 0 && (t = !1);
  var r = e.target, n = e.composed, u = null;
  return rr(r) && n ? u = e.composedPath()[0] && e.composedPath()[0].tagName : u = r && r.tagName, pe(t) ? !!(u && t && t.some(function(l) {
    var s;
    return l.toLowerCase() === ((s = u) == null ? void 0 : s.toLowerCase());
  })) : !!(u && t && t);
}
function rr(e) {
  return !!e.tagName && !e.tagName.startsWith("-") && e.tagName.includes("-");
}
function nr(e, t) {
  return e.length === 0 && t ? (console.warn('A hotkey has the "scopes" option set, however no active scopes were found. If you want to use the global scopes feature, you need to wrap your app in a <HotkeysProvider>'), !0) : t ? e.some(function(r) {
    return t.includes(r);
  }) || e.includes("*") : !0;
}
var sr = function(t, r, n) {
  n === void 0 && (n = !1);
  var u = r.alt, l = r.meta, s = r.mod, i = r.shift, p = r.ctrl, c = r.keys, y = t.key, m = t.code, b = t.ctrlKey, o = t.metaKey, B = t.shiftKey, D = t.altKey, w = A(m), k = y.toLowerCase();
  if (!(c != null && c.includes(w)) && !(c != null && c.includes(k)) && !["ctrl", "control", "unknown", "meta", "alt", "shift", "os"].includes(w))
    return !1;
  if (!n) {
    if (u === !D && k !== "alt" || i === !B && k !== "shift")
      return !1;
    if (s) {
      if (!o && !b)
        return !1;
    } else if (l === !o && k !== "meta" && k !== "os" || p === !b && k !== "ctrl" && k !== "control")
      return !1;
  }
  return c && c.length === 1 && (c.includes(k) || c.includes(w)) ? !0 : c ? Qt(c) : !c;
}, or = /* @__PURE__ */ we(void 0), ar = function() {
  return ke(or);
};
function Me(e, t) {
  return e && t && typeof e == "object" && typeof t == "object" ? Object.keys(e).length === Object.keys(t).length && //@ts-ignore
  Object.keys(e).reduce(function(r, n) {
    return r && Me(e[n], t[n]);
  }, !0) : e === t;
}
var ir = /* @__PURE__ */ we({
  hotkeys: [],
  enabledScopes: [],
  toggleScope: function() {
  },
  enableScope: function() {
  },
  disableScope: function() {
  }
}), lr = function() {
  return ke(ir);
};
function cr(e) {
  var t = O(void 0);
  return Me(t.current, e) || (t.current = e), t.current;
}
var he = function(t) {
  t.stopPropagation(), t.preventDefault(), t.stopImmediatePropagation();
}, ur = typeof window < "u" ? rt : X;
function S(e, t, r, n) {
  var u = oe(null), l = u[0], s = u[1], i = O(!1), p = r instanceof Array ? n instanceof Array ? void 0 : n : r, c = pe(e) ? e.join(p == null ? void 0 : p.splitKey) : e, y = r instanceof Array ? r : n instanceof Array ? n : void 0, m = tt(t, y ?? []), b = O(m);
  y ? b.current = m : b.current = t;
  var o = cr(p), B = lr(), D = B.enabledScopes, w = ar();
  return ur(function() {
    if (!((o == null ? void 0 : o.enabled) === !1 || !nr(D, o == null ? void 0 : o.scopes))) {
      var k = function(a, x) {
        var v;
        if (x === void 0 && (x = !1), !(tr(a) && !ze(a, o == null ? void 0 : o.enableOnFormTags))) {
          if (l !== null) {
            var C = l.getRootNode();
            if ((C instanceof Document || C instanceof ShadowRoot) && C.activeElement !== l && !l.contains(C.activeElement)) {
              he(a);
              return;
            }
          }
          (v = a.target) != null && v.isContentEditable && !(o != null && o.enableOnContentEditable) || re(c, o == null ? void 0 : o.splitKey).forEach(function(fe) {
            var W, L = ne(fe, o == null ? void 0 : o.combinationKey);
            if (sr(a, L, o == null ? void 0 : o.ignoreModifiers) || (W = L.keys) != null && W.includes("*")) {
              if (o != null && o.ignoreEventWhen != null && o.ignoreEventWhen(a) || x && i.current)
                return;
              if (Zt(a, L, o == null ? void 0 : o.preventDefault), !er(a, L, o == null ? void 0 : o.enabled)) {
                he(a);
                return;
              }
              b.current(a, L), x || (i.current = !0);
            }
          });
        }
      }, R = function(a) {
        a.key !== void 0 && (He(A(a.code)), ((o == null ? void 0 : o.keydown) === void 0 && (o == null ? void 0 : o.keyup) !== !0 || o != null && o.keydown) && k(a));
      }, M = function(a) {
        a.key !== void 0 && (Te(A(a.code)), i.current = !1, o != null && o.keyup && k(a, !0));
      }, j = l || (p == null ? void 0 : p.document) || document;
      return j.addEventListener("keyup", M), j.addEventListener("keydown", R), w && re(c, o == null ? void 0 : o.splitKey).forEach(function(g) {
        return w.addHotkey(ne(g, o == null ? void 0 : o.combinationKey, o == null ? void 0 : o.description));
      }), function() {
        j.removeEventListener("keyup", M), j.removeEventListener("keydown", R), w && re(c, o == null ? void 0 : o.splitKey).forEach(function(g) {
          return w.removeHotkey(ne(g, o == null ? void 0 : o.combinationKey, o == null ? void 0 : o.description));
        });
      };
    }
  }, [l, c, o, D]), s;
}
function dr() {
  const e = ce(), t = ue(), r = le(), n = ye(), { undo: u, redo: l } = We();
  S("esc", () => {
    e.deselectBrick(), e.setSelectedSectionId(), e.hidePanel();
  }), S("mod+c", () => {
    const s = window.getSelection();
    s != null && s.rangeCount || console.debug("mod+c pressed");
  }), S(["backspace", "del"], (s) => {
    n && (s.preventDefault(), t.deleteBrick(n), e.deselectBrick(n), e.hidePanel("inspector"));
  }), S("s", (s) => {
    s.preventDefault(), e.togglePanel("settings");
  }), S("l", (s) => {
    s.preventDefault(), e.togglePanel("library");
  }), S("t", (s) => {
    s.preventDefault(), e.togglePanel("theme");
  }), S("p", (s) => {
    s.preventDefault(), e.togglePanel();
  }), S(
    ["mod+up", "mod+left"],
    (s) => {
      s.preventDefault(), n && (console.log("Moving %s up", n), t.moveBrickWithin(n, "previous"));
    },
    {
      enableOnContentEditable: !0
    }
  ), S(["mod+z", "ctrl+z"], (s) => {
    s.preventDefault(), u();
  }), S(["mod+shift+z", "ctrl+shift+z"], (s) => {
    s.preventDefault(), l();
  }), S(
    ["mod+down", "mod+right"],
    (s) => {
      s.preventDefault(), n && (console.log("Moving %s to right", n), t.moveBrickWithin(n, "next"));
    },
    {
      enableOnContentEditable: !0
    }
  ), S("mod+d", (s) => {
    s.preventDefault(), n && (t.duplicateBrick(n), ot("Brick duplicated"));
  }), S("mod+j", (s) => {
    s.preventDefault(), e.toggleEditorEnabled();
  }), S("mod+g", (s) => {
    s.preventDefault(), console.log("Debugging draft:");
    const { sections: i, themes: p, siteAttr: c, sitemap: y, attr: m, brickMap: b } = r;
    console.log({ sections: i, themes: p, siteAttr: c, sitemap: y, attr: m, brickMap: b });
  });
}
function pr({ themes: e }) {
  var c;
  const [t, r] = oe(0), [n, u] = oe(0), l = O(null), s = O(null), i = Ve(), p = e[t];
  return X(() => {
    const y = setInterval(() => {
      r((m) => (m + 1) % e.length), i != null && i.length && u((m) => (m + 1) % i.length);
    }, 1e4);
    return () => clearInterval(y);
  }, [e, i]), X(() => {
    var y, m, b;
    (y = s.current) == null || y.style.setProperty("background-color", p.colors.base200), (m = s.current) == null || m.style.setProperty("color", p.colors.baseContent), (b = l.current) == null || b.style.setProperty(
      "background-image",
      `conic-gradient(from 0deg, ${p.colors.primary}, ${p.colors.secondary}, ${p.colors.accent}, ${p.colors.primary})`
    );
  }, [p]), /* @__PURE__ */ E(
    "div",
    {
      ref: s,
      className: I(
        "w-full flex justify-center items-center h-full relative overflow-hidden animate-background bg-size[400%] opacity-50",
        _({
          backgroundImage: i ? `url(${(c = i[n]) == null ? void 0 : c.url})` : "none",
          backgroundSize: "cover"
        })
      ),
      children: [
        /* @__PURE__ */ f("div", { ref: l, className: I("absolute w-[100vh] h-[100vh] inset-0 animate-spin-blob z-20") }),
        /* @__PURE__ */ f(
          "div",
          {
            className: I(
              "rounded-full absolute backdrop-blur-3xl inset-0 scale-150 bg-white/40 z-50 flex items-center justify-center",
              _({
                textShadow: "0 0 3px rgba(0, 0, 0, 0.3)",
                color: "#FFFFFF",
                fontSize: "1.2rem",
                fontWeight: "bold",
                transition: "color 0.3s ease, background-color 0.3s ease"
              })
            ),
            children: p.name
          }
        )
      ]
    }
  );
}
function fr() {
  return be(), qe(), /* @__PURE__ */ f(
    "div",
    {
      className: I("absolute bg-gray-200 top-0 bottom-0 left-0 right-0 flex items-center justify-center"),
      children: /* @__PURE__ */ E("h2", { className: I("text-gray-400 leading-relaxed text-xl font-semibold flex-1 text-center !font-sans"), children: [
        "Welcome!",
        /* @__PURE__ */ f("br", {}),
        "To get started, please answer a few questions from our beloved Bot, Upsie.",
        /* @__PURE__ */ f("br", {}),
        "Your site will then appear here... 🤩"
      ] })
    }
  );
}
function mr() {
  var e;
  return ((e = globalThis.location) == null ? void 0 : e.hostname) === "localhost";
}
const gr = z(() => import("./Tour.Bmkx45AP.js")), vr = z(() => import("./NavBar.d0qQ2PNc.js")), hr = z(() => import("./Chat.CDF6l9Nr.js")), yr = z(() => import("./EditablePage.CCREfg7L.js")), br = z(() => import("../Page.js")), se = z(() => import("./DeviceFrame.ClJKcmg2.js")), kr = z(() => import("./Panel.CGCxOv5O.js"));
function Mr(e) {
  const t = O(null), r = le(), n = Ue(), u = Ge(), l = Xe(), { panelPosition: s } = Ye(), i = Je(), p = be(), c = ue(), y = Qe(), { setDraggingBrickType: m, toggleDebugMode: b, hidePanel: o } = ce(), B = ye(), D = Ze(), w = mr(), k = et();
  Xt(), dr(), X(() => {
    const g = r.previewTheme ?? r.theme;
    g && st(_(it(g)));
  }, [r.previewTheme, r.theme]);
  const R = (g) => {
    const { draggableId: a, type: x, source: v } = g;
    console.log("DragStart result:", g);
    const C = document.getElementById(a);
    C == null || C.classList.add(I("moving")), v.droppableId !== "bricks-library" && v.droppableId;
  }, M = (g) => {
    m(g.draggableId), console.log("BeforeCapture result:", g);
    const a = document.getElementById(g.draggableId);
    a && window.getComputedStyle(a).getPropertyValue("background-color") === "rgba(0, 0, 0, 0)" && a.classList.add(I("!bg-upstart-100"));
  }, j = (g) => {
    var W, L;
    const { destination: a, source: x, draggableId: v, type: C, combine: fe } = g;
    if (m(null), console.log("DragEnd result:", g), !a) {
      console.warn("Dropped outside a valid droppable area, no action taken.");
      return;
    }
    if (a.droppableId === x.droppableId && a.index === x.index) {
      console.log("Dropped in the same position, no action taken.");
      return;
    }
    if (x.droppableId === "bricks-library" || x.droppableId === "widgets-library") {
      const P = l.find(($) => $.id === a.droppableId);
      if (P) {
        const $ = document.getElementById(P.id).clientHeight, h = { ...Z[v].props };
        h.height = `${$ * 0.9}px`;
        const V = {
          type: v,
          props: h,
          id: `brick-${U()}`
        };
        console.log("Brick object created:", V), c.addBrick(V, P.id, a.index, null), console.log(
          `Added new brick ${v} to section ${P.id} at index ${a.index}`
        );
      }
      const N = c.getBrick(a.droppableId);
      if (N && G[N.type] && G[N.type].isContainer) {
        const $ = {
          ...Z[v],
          id: `b_${U()}`
        }, h = (W = r.brickMap.get(N.id)) == null ? void 0 : W.sectionId;
        if (!h) {
          console.warn(`No section found for container ${N.id}`);
          return;
        }
        c.addBrick($, h, a.index, N.id), console.log(
          `Added new brick ${v} to container ${N.id} at index ${a.index} in section ${h}`
        );
      }
      if (a.droppableId === "page") {
        console.log("Brick has been dropped on page!");
        const $ = `s_${U()}`;
        c.createEmptySection($);
        const h = {
          ...Z[v],
          id: `b_${U()}`
        };
        c.addBrick(h, $, 0, null);
      }
    } else if (C === "section") {
      const P = Array.from(l), [N] = P.splice(x.index, 1);
      P.splice(a.index, 0, N), c.reorderSections(P.map(($) => $.id));
    } else if (C === "brick") {
      const P = x.droppableId, N = a.droppableId;
      if (l.find((h) => h.id === a.droppableId))
        P === N ? (console.log(
          `Moving brick ${v} within section from ${x.index} to ${a.index}`
        ), c.reorderBrickWithin(v, a.index)) : (console.log(
          `Moving brick ${v} from section ${P} to ${N}`
        ), c.moveBrickToSection(v, N, a.index));
      else {
        const h = c.getBrick(a.droppableId);
        if (h && G[h.type] && G[h.type].isContainer) {
          const V = (L = r.brickMap.get(h.id)) == null ? void 0 : L.sectionId;
          if (!V) {
            console.warn(`No section found for container ${h.id}`);
            return;
          }
          if (v === h.id) {
            console.warn("Cannot move a container into itself");
            return;
          }
          console.log(
            `Moving brick ${v} to container ${h.id} at index ${a.index} in section ${V}`
          ), c.moveBrickToContainerBrick(v, h.id, a.index);
        }
      }
      y === "desktop" && nt(() => {
        c.adjustMobileLayout();
      });
    }
  };
  return n ? /* @__PURE__ */ f(
    lt,
    {
      onDragEnd: j,
      onDragStart: R,
      onBeforeCapture: M,
      children: /* @__PURE__ */ E(
        "div",
        {
          id: "editor",
          className: I(
            "grid relative transition-all mx-auto w-full",
            wr(p, u),
            "min-h-[100dvh] max-h-[100dvh]",
            p.isReady === !1 && _({
              background: `linear-gradient(120deg,
              oklab(from #9291e7 l a b / 0.65),
              oklab(from #7270c6 l a b / 0.65),
              oklab(from #c050c2 l a b / 0.65),
              oklab(from #ef50a2 l a b / 0.65),
              oklab(from #ff6285 l a b / 0.65),
              oklab(from #ff806b l a b / 0.65),
              oklab(from #ffa25a l a b / 0.65),
              oklab(from #ffc358 l a b / 0.65)
          )`
            }),
            p.isReady === !1 && "transition-all duration-500 ease-in-out"
          ),
          ...e,
          ref: t,
          children: [
            l.length > 0 && p.isReady && /* @__PURE__ */ f(K, { children: /* @__PURE__ */ f(gr, {}) }),
            /* @__PURE__ */ f(K, { children: /* @__PURE__ */ f(vr, {}) }),
            u && /* @__PURE__ */ f(K, { children: /* @__PURE__ */ f(hr, {}) }),
            /* @__PURE__ */ f(K, { children: /* @__PURE__ */ f(kr, {}) }),
            /* @__PURE__ */ E(
              "main",
              {
                className: I(
                  "flex-1 flex place-content-center z-40 overscroll-none ",
                  "overflow-x-auto overflow-y-visible ",
                  p.isReady === !1 && "!hidden",
                  _({
                    gridArea: "main",
                    scrollbarColor: "var(--violet-4) var(--violet-2)",
                    scrollBehavior: "smooth",
                    scrollbarGutter: "stable",
                    scrollbarWidth: s === "left" ? "thin" : "none",
                    "&:hover": {
                      scrollbarColor: "var(--violet-7) var(--violet-3)"
                    }
                  })
                ),
                children: [
                  p.isReady && /* @__PURE__ */ f(K, { children: /* @__PURE__ */ E(se, { children: [
                    /* @__PURE__ */ f(yr, {}),
                    r.previewTheme && /* @__PURE__ */ f(xr, {})
                  ] }) }),
                  !p.isReady && (i.length > 0 ? /* @__PURE__ */ f(se, { children: /* @__PURE__ */ f(pr, { themes: i }) }) : /* @__PURE__ */ f(se, { children: /* @__PURE__ */ f(fr, {}) })),
                  /* @__PURE__ */ f(
                    at,
                    {
                      toastOptions: {
                        position: "bottom-center",
                        style: {
                          background: "rgba(0, 0, 0, 0.85)",
                          color: "white",
                          fontSize: "0.85rem",
                          fontWeight: "500"
                          // marginBottom: "1rem",
                        },
                        className: I("last:mb-1 px-1 py-1 rounded-lg"),
                        error: {
                          style: {
                            background: "#880808"
                          }
                        }
                      }
                    }
                  ),
                  w && /* @__PURE__ */ E(
                    "div",
                    {
                      className: "fixed flex max-w-[548px] items-center divide-x divide-gray-300 bottom-0 right-6 p-2 text-xs text-gray-500 bg-gray-100 dark:bg-dark-800 z-[19999] rounded-t-md",
                      style: {
                        // Shadow to the top left corner
                        boxShadow: "0 -2px 4px rgba(0, 0, 0, 0.1), -2px 0 4px rgba(0, 0, 0, 0.1)"
                      },
                      children: [
                        /* @__PURE__ */ E("div", { className: "px-2", children: [
                          "Selected brick: ",
                          B ?? "none"
                        ] }),
                        /* @__PURE__ */ E("div", { className: "px-2", children: [
                          "Selected section: ",
                          D ?? "none"
                        ] }),
                        /* @__PURE__ */ E("div", { className: "flex items-center gap-1 px-2", children: [
                          /* @__PURE__ */ f(Le, { defaultChecked: k, onCheckedChange: b, size: "1", id: "debug-mode" }),
                          /* @__PURE__ */ E("label", { htmlFor: "debug-mode", className: "cursor-pointer select-none", children: [
                            "Debug mode",
                            " ",
                            /* @__PURE__ */ f("b", { className: I("font-semibold", k ? "text-upstart-600" : "text-gray-500"), children: k ? "on" : "off" })
                          ] })
                        ] })
                      ]
                    }
                  )
                ]
              }
            )
          ]
        }
      )
    }
  ) : /* @__PURE__ */ f("div", { className: "@container", children: /* @__PURE__ */ f(K, { children: /* @__PURE__ */ f(
    br,
    {
      page: {
        ...r,
        tags: []
      }
    }
  ) }) });
}
function wr(e, t) {
  return _({
    gridTemplateAreas: t ? '"navbar navbar" "chat main"' : '"navbar" "main"',
    gridTemplateRows: "64px 1fr",
    gridTemplateColumns: e.isReady === !1 ? "1fr 0px" : t ? "360px 1fr" : "1fr"
    // maxWidth: generationState.isReady === false ? "clamp(500px, 40dvw, 650px)" : "none",
  });
}
function xr() {
  const { validatePreviewTheme: e } = ue();
  return /* @__PURE__ */ f("div", { className: "sticky bottom-4 left-0 right-0 flex justify-center items-center z-[9999]", children: /* @__PURE__ */ E("div", { className: "p-3 bg-black/70 backdrop-blur-md rounded-lg max-w-fit flex gap-2 shadow-xl", children: [
    /* @__PURE__ */ f(ae, { variant: "solid", color: "gray", onClick: () => e(!1), children: "Revert" }),
    /* @__PURE__ */ f(ae, { onClick: () => e(!0), variant: "solid", children: "Accept theme" })
  ] }) });
}
export {
  Mr as E,
  Le as i,
  $e as n,
  ae as o,
  xt as p,
  Pe as s,
  Tt as u
};
//# sourceMappingURL=Editor.CaEIuXmU.js.map
