import { p as $, s as q } from "./attributes.C0ljq_Tf.js";
import { a5 as U, a6 as G, a7 as R, u as J, w as K, x as j, r as Q, a8 as X, G as Y, a9 as w } from "./use-page-data.BYLN5MSa.js";
import { Type as i } from "typebox";
import { d as Z } from "./types.DnmGKJXU.js";
import { t as C, u as v } from "./use-brick-manifest.CKrAfjO8.js";
import { c as m, a as x } from "./twind.Cg2g8xBZ.js";
import { g as O } from "./get.D6Ij4kC_.js";
import { useEffect as _, Suspense as V, lazy as tt } from "react";
import { jsx as I } from "react/jsx-runtime";
import { merge as T, get as b } from "lodash-es";
import { p as P, a as E } from "./color-system.DmbQ-PqB.js";
const H = i.Object({
  id: i.String({
    description: "The unique ID of the page. Use a human readable url-safe slug",
    examples: [
      "home",
      "about-us",
      "products-list"
    ],
    pattern: "^[a-z0-9-_]+$"
  }),
  label: i.String({
    description: "The label (name) of the page",
    examples: [
      "Home",
      "About us",
      "Products"
    ]
  }),
  sections: i.Array(U, { description: "The sections of the page. See the Section schema" }),
  attributes: $
});
i.Evaluate(i.Intersect([H, i.Object({ version: i.String() })]));
const et = i.Evaluate(i.Intersect([
  i.Pick(H, ["id", "label"]),
  i.Pick($, ["path", "tags"]),
  i.Object({
    status: i.Optional(i.Enum(["draft", "published"], {
      title: "Page status",
      enumNames: ["Draft", "Published"],
      default: "draft",
      "ai:hidden": !0,
      type: "string",
      description: "The status of the page. Can be draft or published. [AI instructions: Dont generate this.]"
    })),
    isInitialPage: i.Optional(i.Boolean({
      title: "Is initial page",
      "ai:hidden": !0
    }))
  })
], {
  description: "Pages map. The complete list of site pages & their metadata",
  additionalProperties: !0
})), st = i.Array(et), it = i.String({
  minLength: 30,
  maxLength: 1e3,
  description: "User prompt for the site, describing the purpose and main features of the site."
}), rt = i.Object({
  id: i.String({
    description: "The unique identifier for the site.",
    readOnly: !0
  }),
  label: i.String({ description: "The label (name) of the site, only displayed to the site owner" }),
  hostname: i.String({
    description: "The hostname of the site, e.g. example.com",
    readOnly: !0
  }),
  attributes: q,
  datasources: G,
  datarecords: Z,
  themes: i.Array(C),
  theme: C,
  sitemap: st,
  sitePrompt: it
});
i.Object({
  site: rt,
  pages: i.Array(H)
});
i.Enum(["mobile", "desktop"], { type: "string" });
i.Object({
  id: i.Optional(i.String({
    title: "Template ID",
    description: "A unique identifier for the template. Can be any string, but should be unique."
  })),
  name: i.String({ title: "Template Name" }),
  description: i.Optional(i.String({ title: "Show template description" })),
  readme: i.Optional(i.String()),
  tags: i.Optional(i.Array(i.String(), { title: "Tags" })),
  author: i.Optional(i.String({ title: "Author name" })),
  thumbnail: i.Optional(i.String({
    title: "Thumbnail",
    description: "A URL to the thumbnail image for the template."
  })),
  homepage: i.Optional(i.String({
    title: "Homepage",
    description: "A URL to the homepage of the template."
  }))
});
function k(t, e = "", s = {}) {
  if (i.IsObject(t))
    for (const r in t.properties) {
      const n = t.properties[r];
      n["ui:styleId"] && (s[`${e}${r}`] = n["ui:styleId"]), k(n, `${e}${r}.`, s);
    }
  else i.IsArray(t) && k(t.items, `${e}[].`, s);
  return s;
}
function ot(t) {
  return t?.image ? [
    m({
      backgroundImage: `url(${t.image})`,
      backgroundSize: t.size ?? "auto",
      backgroundRepeat: t.repeat ?? "no-repeat"
    })
  ] : null;
}
function B(t) {
  return function(e, s) {
    return e ? s ? `@desktop:(${m({ [t]: e })}) @mobile:(${m({ [t]: s })})` : m({
      [t]: e
    }) : null;
  };
}
function nt(t, e) {
  return e ? `@desktop:(${m({ gap: t })}) @mobile:(${m({ gap: e })})` : m({
    gap: t
  });
}
function at(t, e) {
  return e ? `@desktop:(${P(t, "bg-color")}) @mobile:(${P(e, "bg-color")})` : P(t, "bg");
}
function lt(t, e) {
  return E(t, "color");
}
function pt(t) {
  return E(t, "opacity");
}
function c(t, e, s) {
  if (s?.["ui:desktop-only"])
    return `@desktop:(${t})`;
  if (!e)
    return t;
  if (t && e)
    return `@desktop:(${t}) @mobile:(${e})`;
  if (e)
    return `@mobile:(${e})`;
}
function ct(t, e, s) {
  if (s?.["ui:desktop-only"])
    return `@desktop:(${Object.values(t).join(" ")})`;
  if (t && !e)
    return Object.values(t);
  if (t && e)
    return `@desktop:(${Object.values(t).join(" ")}) @mobile:(${Object.values(e).join(" ")})`;
  if (e)
    return `@mobile:(${Object.values(e).join(" ")})`;
}
function ut(t) {
  return t ? "sticky top-0 left-0 right-0 self-start w-fill z-[99999] isolate" : null;
}
function dt(t, e, s) {
  if (s?.["ui:desktop-only"])
    return "@desktop:(flex-grow)";
  if (t && e)
    return "flex-grow";
  if (!e)
    return t ? "@desktop:(flex-grow)" : null;
  if (e)
    return "@mobile:(flex-grow) @desktop:(grow-0)";
}
function mt(t, e, s) {
  if (s?.["ui:desktop-only"])
    return `@desktop:(${t ? "flex-wrap" : "flex-nowrap"})`;
  if (!e)
    return t ? "flex-wrap" : "flex-nowrap";
  if (t && e)
    return "@desktop:(flex-wrap) @mobile:(flex-wrap)";
  if (e)
    return "@mobile:(flex-wrap) @desktop:(flex-nowrap)";
}
function F(t, e, s) {
  const r = s?.["ui:presets"] ?? R;
  if (s?.["ui:desktop-only"])
    return `@desktop:(${r[t]?.className})`;
  if (!e)
    return r[t]?.className;
  if (t && e)
    return `@desktop:(${r[t]?.className}) @mobile:(${r[e]?.className})`;
  if (e)
    return `@mobile:(${r[e]?.className})`;
}
const ft = {
  "presets:color": F,
  "styles:gradientDirection": c
}, W = {
  "styles:color": lt,
  "styles:textShadow": c,
  "styles:opacity": pt,
  "styles:objectFit": c,
  "styles:objectPosition": c,
  "styles:heroSize": c,
  "styles:fontSize": c,
  "styles:wrap": mt,
  "styles:padding": B("padding"),
  // test
  "styles:verticalMargin": B("margin-block"),
  // test
  "styles:gap": nt,
  "styles:gradientDirection": c,
  "styles:backgroundColor": at,
  "styles:background": ot,
  "presets:color": F,
  "styles:borderColor": c,
  "styles:rounding": c,
  "styles:direction": c,
  // test putting here
  "styles:alignItems": c,
  "styles:justifyContent": c,
  "styles:border": ct,
  // "styles:rounding": simpleClassHandler,
  "styles:shadow": c
}, z = {
  "styles:direction": c,
  "styles:rounding": c,
  "styles:justifyContent": c,
  "styles:alignItems": c,
  "styles:fixedPositioned": ut,
  "styles:alignSelf": c,
  "styles:grow": dt
};
function A(t) {
  return t.includes(".") ? t.split(".").slice(0, -1).join(".") : t;
}
function gt() {
  const t = J(), e = t.previewTheme ?? t.site.theme;
  return _(() => {
    bt(), ht(e.typography);
  }, [e.typography]), e.typography;
}
function ht(t) {
  for (const e of ["body", "heading"])
    if (t[e].type === "google") {
      const s = document.getElementById(`stylesheet-font-${e}`);
      s.href = `https://fonts.googleapis.com/css2?family=${t[e].family.replace(
        / /g,
        "+"
      )}&display=swap`;
    }
}
function bt() {
  for (const t of ["body", "heading"]) {
    const e = `stylesheet-font-${t}`;
    document.getElementById(e) && document.getElementById(e)?.remove();
    const s = document.createElement("link");
    s.rel = "stylesheet", s.id = e, document.head.appendChild(s);
  }
}
function zt({ editable: t, showIntro: e } = {}) {
  const s = k($), r = yt(s), n = gt();
  return x(
    "flex flex-col group/page mx-auto relative max-w-full w-full p-0 antialiased",
    t && "overflow-hidden min-h-[100cqh]",
    // pageAttributes.colorPreset?.color ?? siteAttributes.colorPreset?.color,
    Object.values(r),
    kt(n),
    // Animate all bricks when the page is loading
    t && e && "[&>.brick-wrapper]:(opacity-0 animate-elastic-pop)"
  );
}
function yt(t) {
  const e = K(), s = j();
  return Object.entries(t).reduce(
    (n, [o, f]) => {
      const a = ft[f];
      if (!a)
        return n;
      const p = A(o);
      n[p] = n[p] ?? [];
      const d = O(s, o) ?? O(e, o), g = O($.properties, o);
      return n[p].push(x(a?.(d, void 0, g))), n;
    },
    {}
  );
}
function kt(t) {
  function e(s) {
    return s.type === "stack" ? `var(--font-${s.family})` : `"${s.family}"`;
  }
  return m({
    fontFamily: e(t.body),
    fontSize: `${t.base}px`,
    "& h1, & h2, & h3, & h4, & h5, & h6, & h7": {
      fontFamily: e(t.heading)
    }
  });
}
const xt = /* @__PURE__ */ Object.assign({ "../bricks/accordion.tsx": () => import("./accordion.Bcrw5Tnn.js"), "../bricks/box.tsx": () => import("./box.DjPojJU8.js"), "../bricks/button.tsx": () => import("./button.Dg4W-m12.js"), "../bricks/card.tsx": () => import("./card.Cr4bJWiH.js"), "../bricks/carousel.tsx": () => import("./carousel.D2YHmSzO.js"), "../bricks/footer.tsx": () => import("./footer.DMmZGJsG.js"), "../bricks/form.tsx": () => import("./form.5OXYuOf0.js"), "../bricks/hero.tsx": () => import("./hero.B-6aW9U3.js"), "../bricks/html.tsx": () => import("./html.xE3G6rs2.js"), "../bricks/icon.tsx": () => import("./icon.CfNzowQs.js"), "../bricks/image.tsx": () => import("./image.1pxjf39b.js"), "../bricks/images-gallery.tsx": () => import("./images-gallery.Dwavh_VY.js"), "../bricks/map.tsx": () => import("./map.DaL2TOD8.js"), "../bricks/navbar.tsx": () => import("./navbar.Bqc_nHKW.js"), "../bricks/sidebar.tsx": () => import("./sidebar.MJosowP4.js"), "../bricks/social-links.tsx": () => import("./social-links.yqdLNAFR.js"), "../bricks/spacer.tsx": () => import("./spacer.BlpHpwor.js"), "../bricks/table.tsx": () => import("./table.LdVSBmxT.js"), "../bricks/tabs.tsx": () => import("./tabs.BqhZXUaq.js"), "../bricks/testimonials.tsx": () => import("./testimonials.Bm1Cpxyu.js"), "../bricks/text.tsx": () => import("./text.BdACOJ_T.js"), "../bricks/timeline.tsx": () => import("./timeline.DmSZTvYm.js"), "../bricks/video.tsx": () => import("./video.Ctm1aA2_.js").then((t) => t.v) }), St = Object.entries(xt).reduce(
  (t, [e, s]) => {
    const r = e.match(/\.\/bricks\/(.*)\.(j|t)sx?$/)[1];
    return t[r] = tt(s), t;
  },
  // biome-ignore lint/suspicious/noExplicitAny: <explanation>
  {}
), Nt = ({
  brick: t,
  editable: e,
  isDynamicPreview: s,
  iterationIndex: r,
  selected: n
}) => {
  const o = St[t.type];
  return o ? /* @__PURE__ */ I(V, { children: /* @__PURE__ */ I(o, { ...{
    brick: t,
    editable: e,
    isDynamicPreview: s,
    selected: n,
    iterationIndex: r
  } }) }) : (console.warn("Brick not found", t.type), null);
};
function N(t, e, s) {
  const { props: r, mobileProps: n } = e, o = j(), f = T({}, X[e.type].props, r), a = v(e.type), p = Object.entries(t).reduce((l, [u, S]) => {
    const h = b(a.props.properties, u);
    if (h && h.metadata?.filter) {
      const y = h.metadata.filter;
      y(h, f, o) || l.push(u);
    }
    return l;
  }, []), d = s === "brick" ? W : z;
  return Object.entries(t).reduce(
    (l, [u, S]) => {
      const h = d[S];
      if (!h || p.includes(u))
        return l;
      const y = A(u);
      l[y] = l[y] ?? [];
      const M = b(f, u), D = b(n, u), L = b(a.props.properties, u);
      return l[y].push(x(h?.(M, D, L))), l;
    },
    {}
  );
}
function Mt(t) {
  const e = v(t.type), s = k(e.props);
  return N(s, t, "brick");
}
function Dt(t) {
  const { brick: e, editable: s, selected: r, isContainerChild: n = !1 } = t, { props: o, mobileProps: f } = e, a = v(e.type), p = k(a.props), d = Object.values(p), g = N(p, e, "wrapper"), l = !!a.isContainer, { isSetup: u } = Q();
  return x(
    a.staticClasses,
    o.className,
    o.preset,
    "brick-wrapper group/brick flex max-w-full",
    l ? "@desktop:min-w-min min-h-fit h-auto flex-wrap" : (
      // ? "@desktop:min-w-min min-h-fit shrink-0 h-auto @mobile:flex-wrap @desktop:flex-nowrap"
      "min-w-min min-h-min"
    ),
    a.maxHeight?.mobile && `@mobile:max-h-[${a.maxHeight.mobile}px]`,
    a.maxHeight?.desktop && `@desktop:max-h-[${a.maxHeight.desktop}px]`,
    // !isContainerChild &&
    o.grow ? "@desktop:w-auto" : typeof o.width < "u" ? `@desktop:w-[${o.width}]` : `@desktop:w-[${a.defaultWidth.desktop}]`,
    !n && (typeof f?.width < "u" ? `@mobile:min-w-[${f.width}]` : `@mobile:w-[${a.defaultWidth.mobile}]`),
    // Max width
    a.maxWidth?.mobile && `@mobile:max-w-[${a.maxWidth.mobile}px]`,
    a.maxWidth?.desktop && `@desktop:max-w-[${a.maxWidth.desktop}px]`,
    typeof o.height < "u" ? m({
      minHeight: `${o.height}`
    }) : `@mobile:min-h-[${a.defaultHeight.mobile}] @desktop:min-h-[${a.defaultHeight.desktop}]`,
    d.includes("styles:fixedPositioned") === !1 && "relative",
    // container children expand to fill the space
    n && "container-child",
    // When a brick is hidden on mobile, hide the wrapper as well
    "@mobile:[&:has([data-mobile-hidden])]:hidden @desktop:[&:has([data-mobile-hidden])]:flex",
    u && "animate animate-reveal-brick",
    wt(t),
    ...Object.values(g).flat()
  );
}
function wt({
  brick: t,
  editable: e,
  isContainerChild: s,
  selected: r
}) {
  const o = !!v(t.type).isContainer;
  return e ? [
    "select-none",
    // "select-none transition-[outline] duration-[200ms]",
    e && "transition-all duration-300",
    "outline outline-2 outline-transparent outline-dashed",
    {
      "outline-offset-2": !o && !s,
      "outline-offset-4": o,
      "outline-offset-0": s
    },
    r && !o && "!outline-upstart-400",
    r && o && "!outline-orange-300",
    !r && !s && !o && "hover:(outline-upstart-400/60)",
    !r && !s && o && "hover:(outline-orange-300/20)",
    !r && s && "hover:(outline-upstart-400/60) group-hover/brick:(outline-upstart-400/60)",
    m({
      "&.selected-group": {
        outlineColor: "var(--violet-8) !important"
      },
      "&.moving": {
        outlineColor: "var(--violet-8)"
      },
      "&.resizing": {
        outlineColor: "var(--violet-8)",
        minHeight: "min-content"
      },
      "& [data-brick-group]:hover": {
        outline: "1px dashed var(--violet-8)"
      },
      // Hide any UI children elements when dragging
      "&.moving [data-ui]": {
        display: "none"
      }
    })
  ] : null;
}
function Lt({
  section: t,
  selected: e,
  editable: s,
  previewMode: r,
  isDropTarget: n
}) {
  const o = k(w), f = Ot(o, t);
  return x(
    // @mobile:flex-col @desktop:flex-row
    "flex flex-wrap w-full @container/section group/section overflow-visible relative mx-auto max-sm:max-w-dvw",
    [
      Object.values(f),
      t.props.maxWidth,
      typeof t.props.minHeight == "string" && t.props.minHeight !== "full" && `min-h-[${t.props.minHeight}]`,
      // full height
      t.props.minHeight === "full" && (s ? "min-h-[calc(100dvh-60px)]" : "min-h-dvh"),
      m({
        "&:has([data-no-section-padding])": {
          // This is a hack to ensure that the navbar is not affected by the section's padding
          paddingInline: "0px !important",
          paddingBlock: "0px !important"
        }
      }),
      // Section editor styles
      $t({ editable: s, previewMode: r, selected: e, isDropTarget: n }),
      // Manage the section order using css "order" (flex) property
      m({
        order: t.order
      })
    ]
  );
}
function $t({ editable: t, selected: e, previewMode: s, isDropTarget: r }) {
  return t ? [
    "select-none relative outline-dashed outline-2 -outline-offset-2",
    !r && !e && "outline-transparent",
    e || r ? "outline-upstart-500/40" : "hover:outline-upstart-500/40",
    // this is the grid overlay shown when dragging
    s && m`
      &:has(.moving), &:has(.moving) ~ section {
        & [data-floating-ui-portal] {
          display: none;
        }
        & .resizable-handle {
          display: none;
        }
      }`
  ] : null;
}
const vt = Y(w);
function Ot(t, e) {
  const { props: s, mobileProps: r } = e, n = j(), o = T({}, vt, s), f = Object.entries(t).reduce((p, [d, g]) => {
    const l = b(w.properties, d);
    if (l && l.metadata?.filter) {
      const u = l.metadata.filter;
      u(l, o, n) || p.push(d);
    }
    return p;
  }, []);
  return Object.entries(t).reduce(
    (p, [d, g]) => {
      const l = W[g] ?? z[g];
      if (!l)
        return console.warn("No helper found for styleId", g), p;
      if (f.includes(d))
        return console.warn("Filtered out section path", d), p;
      const u = A(d);
      p[u] = p[u] ?? [];
      const S = b(o, d), h = b(r, d), y = b(w.properties, d);
      return p[u].push(
        // @ts-expect-error
        x(l?.(S, h, y))
      ), p;
    },
    {}
  );
}
export {
  Nt as B,
  zt as a,
  Mt as b,
  Dt as c,
  Lt as u
};
