import { j as a } from "../../../../../../_virtual/jsx-runtime.js";
import l from "../../../../../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/get.js";
import { IoIosHelpCircleOutline as k } from "../../../../../../node_modules/.pnpm/react-icons@5.3.0_react@18.3.0-canary-3d9b20132-20240124/node_modules/react-icons/io/index.js";
import V from "./fields/array.js";
import v from "./fields/tags.js";
import P from "./fields/background.js";
import S from "./fields/border.js";
import D from "./fields/align-self.js";
import q from "./fields/align-items.js";
import T from "./fields/justify-content.js";
import E from "./fields/color.js";
import z from "./fields/datasource.js";
import B from "./fields/loop.js";
import L from "./fields/page-queries.js";
import Q from "./fields/site-queries.js";
import w from "./fields/enum.js";
import U from "./fields/iconify.js";
import G from "./fields/image.js";
import { NumberField as H, SliderField as J } from "./fields/number.js";
import { PagePaddingField as R } from "./fields/padding.js";
import { StringField as _, UrlOrPageIdField as K, PathField as M, GeoAddressField as W } from "./fields/string.js";
import X from "./fields/switch.js";
import { resolveSchema as F } from "../../../../../sdk/dist/shared/utils/schema-resolver.js";
import "react";
import "../../../../../../node_modules/.pnpm/@formkit_auto-animate@0.8.2/node_modules/@formkit/auto-animate/index.js";
import "../../../../../../node_modules/.pnpm/react-hot-toast@2.5.2_react-dom@18.3.0-canary-3d9b20132-20240124_react@18.3.0-canary-3d_c02c1e17bf76c343fd22d1f22394ecf5/node_modules/react-hot-toast/dist/index.js";
import Y from "./fields/color-preset.js";
import { CssLengthField as Z } from "./fields/css-length.js";
import { DatarecordField as ee } from "./fields/datarecord.js";
import { fieldLabel as b } from "./form-class.js";
import { tx as C } from "../../../../../style-system/dist/twind.js";
import { usePageAttributes as re } from "../../../../../../use-page-data.js";
import { Tooltip as N } from "../../../../../../node_modules/.pnpm/@radix-ui_themes@3.1.4_@types_react-dom@18.3.6_@types_react@18.3.3__@types_react@18.3.3_46b1dabc193c5ff5696ee783983c694e/node_modules/@radix-ui/themes/dist/esm/components/tooltip.js";
function te(u, i) {
  const { brickId: m, fieldName: p, formSchema: h, formData: s } = u;
  return {
    brickId: m,
    schema: i,
    formSchema: h,
    formData: s,
    required: h.properties.required?.includes(p) ?? !1,
    title: i.title ?? i["ui:title"],
    description: i.description ?? i["ui:description"],
    placeholder: i["ui:placeholder"],
    noDynamic: u.noDynamic ?? !1
  };
}
function ne(u) {
  const { brickId: i, fieldName: m, fieldSchema: p, formSchema: h, formData: s, id: e, onChange: o, noDynamic: y } = u, c = F(p), t = te(
    {
      brickId: i,
      fieldName: m,
      formSchema: h,
      formData: s,
      noDynamic: y
    },
    c
  ), j = c["ui:field"] ?? (c.enum ? "enum" : null) ?? c.type ?? (c.anyOf ? "anyOf" : "");
  switch (j) {
    case "hidden":
      return null;
    case "border": {
      const n = l(s, e) ?? t.schema.default;
      return /* @__PURE__ */ a.jsx(
        S,
        {
          currentValue: n,
          onChange: (r) => o({ [e]: r }, e),
          ...t
        },
        `field-${e}`
      );
    }
    case "tags": {
      const n = l(s, e) ?? t.schema.default;
      return /* @__PURE__ */ a.jsx(
        v,
        {
          currentValue: n,
          onChange: (r) => o({ [e]: r }, e),
          ...t
        },
        `field-${e}`
      );
    }
    case "color": {
      const n = l(s, e) ?? t.schema.default;
      return /* @__PURE__ */ a.jsx(
        E,
        {
          currentValue: n,
          onChange: (r) => o({ [e]: r }, e),
          ...t
        },
        `field-${e}`
      );
    }
    case "color-preset": {
      const n = l(s, e) ?? t.schema.default;
      return /* @__PURE__ */ a.jsx(
        Y,
        {
          currentValue: n,
          onChange: (r) => o({ [e]: r }, e),
          ...t
        },
        `field-${e}`
      );
    }
    case "datarecord": {
      const n = l(s, e) ?? t.schema.default;
      return /* @__PURE__ */ a.jsx(
        ee,
        {
          currentValue: n,
          onChange: (r) => o({ [e]: r }, e),
          ...t
        },
        `field-${e}`
      );
    }
    case "geoaddress": {
      const n = l(s, e) ?? t.schema.default;
      return /* @__PURE__ */ a.jsx(
        W,
        {
          currentValue: n,
          onChange: (r) => o({ [e]: r }, e),
          ...t
        },
        `field-${e}`
      );
    }
    case "datasource": {
      const n = l(s, e) ?? t.schema.default;
      return /* @__PURE__ */ a.jsx(
        z,
        {
          currentValue: n,
          onChange: (r) => o({ [e]: r }, e),
          ...t
        },
        `field-${e}`
      );
    }
    case "loop": {
      const n = l(s, e) ?? t.schema.default;
      return /* @__PURE__ */ a.jsx(
        B,
        {
          currentValue: n,
          onChange: (r) => o({ [e]: r }, e),
          ...t
        },
        `field-${e}`
      );
    }
    case "page-queries": {
      const n = l(s, e) ?? t.schema.default;
      return /* @__PURE__ */ a.jsx(
        L,
        {
          currentValue: n,
          onChange: (r) => o({ [e]: r }, e),
          ...t
        },
        `field-${e}`
      );
    }
    case "site-queries": {
      const n = l(s, e) ?? t.schema.default;
      return /* @__PURE__ */ a.jsx(
        Q,
        {
          currentValue: n,
          onChange: (r) => {
          },
          ...t
        },
        `field-${e}`
      );
    }
    case "padding": {
      const n = l(s, e) ?? t.schema.default;
      return /* @__PURE__ */ a.jsx(
        R,
        {
          currentValue: n,
          onChange: (r) => o({ [e]: r }, e),
          ...t
        },
        `field-${e}`
      );
    }
    case "background": {
      const n = l(s, e) ?? t.schema.default;
      return /* @__PURE__ */ a.jsx(
        P,
        {
          currentValue: n,
          onChange: (r) => o({ [e]: r }, e),
          ...t
        },
        `field-${e}`
      );
    }
    case "align-self": {
      const n = l(s, e) ?? t.schema.default;
      return /* @__PURE__ */ a.jsx(
        D,
        {
          currentValue: n,
          onChange: (r) => o({ [e]: r }, e),
          ...t
        },
        `field-${e}`
      );
    }
    case "align-items": {
      const n = l(s, e) ?? t.schema.default;
      return /* @__PURE__ */ a.jsx(
        q,
        {
          currentValue: n,
          onChange: (r) => o({ [e]: r }, e),
          ...t
        },
        `field-${e}`
      );
    }
    case "justify-content": {
      const n = l(s, e) ?? t.schema.default;
      return /* @__PURE__ */ a.jsx(
        T,
        {
          currentValue: n,
          onChange: (r) => o({ [e]: r }, e),
          ...t
        },
        `field-${e}`
      );
    }
    case "enum": {
      const n = l(s, e) ?? t.schema.default;
      return /* @__PURE__ */ a.jsx(
        w,
        {
          currentValue: n,
          onChange: (r) => o({ [e]: r }, e),
          ...t
        },
        `field-${e}`
      );
    }
    case "image": {
      const n = l(s, e) ?? t.schema.default;
      return /* @__PURE__ */ a.jsx(
        G,
        {
          currentValue: n,
          onChange: (r) => o({ [e]: r }, e),
          ...t
        },
        `field-${e}`
      );
    }
    case "path": {
      const n = l(s, e) ?? t.schema.default;
      return /* @__PURE__ */ a.jsx(
        M,
        {
          currentValue: n,
          onChange: (r) => o({ [e]: r }, e),
          ...t
        },
        `field-${e}`
      );
    }
    case "url-page-id": {
      const n = l(s, e) ?? t.schema.default;
      return /* @__PURE__ */ a.jsx(
        K,
        {
          currentValue: n,
          onChange: (r) => o({ [e]: r }, e),
          ...t
        },
        `field-${e}`
      );
    }
    case "css-length": {
      const n = l(s, e) ?? t.schema.default;
      return /* @__PURE__ */ a.jsx(
        Z,
        {
          currentValue: n,
          onChange: (r) => o({ [e]: r }, e),
          ...t
        },
        `field-${e}`
      );
    }
    case "slider": {
      const n = l(s, e) ?? t.schema.default;
      return /* @__PURE__ */ a.jsx(
        J,
        {
          currentValue: n,
          onChange: (r) => o({ [e]: r }, e),
          ...t
        },
        `field-${e}`
      );
    }
    case "boolean":
    case "dynamic-content-switch":
    case "switch": {
      const n = l(s, e) ?? t.schema.default;
      return /* @__PURE__ */ a.jsx(
        X,
        {
          currentValue: n,
          onChange: (r) => o({ [e]: r }, e),
          ...t
        },
        `field-${e}`
      );
    }
    case "string": {
      const n = l(s, e) ?? t.schema.default;
      return /* @__PURE__ */ a.jsx(
        _,
        {
          currentValue: n,
          onChange: (r) => o({ [e]: r }, e),
          ...t
        },
        `field-${e}`
      );
    }
    case "integer":
    case "number": {
      const n = l(s, e) ?? t.schema.default;
      return /* @__PURE__ */ a.jsx(
        H,
        {
          currentValue: n,
          onChange: (r) => o({ [e]: r }, e),
          ...t
        },
        `field-${e}`
      );
    }
    case "anyOf": {
      const n = l(s, e) ?? t.schema.default;
      return /* @__PURE__ */ a.jsx(
        w,
        {
          currentValue: n,
          onChange: (r) => o({ [e]: r }, e),
          ...t,
          options: c.anyOf
        },
        `field-${e}`
      );
    }
    case "array": {
      const n = l(s, e), r = n !== void 0 ? Array.isArray(n) ? n : [] : t.schema.default || [];
      if (c.items) {
        const d = F(c.items);
        if (d.type === "object")
          return /* @__PURE__ */ a.jsx(
            V,
            {
              currentValue: r,
              onChange: (g) => o({ [e]: g || [] }, e),
              itemSchema: d,
              fieldName: m,
              id: e,
              parents: u.parents,
              ...t
            },
            `field-${e}`
          );
        if (d.anyOf || d.oneOf || d.enum || d.union) {
          const g = d.anyOf || d.oneOf || d.enum || d.union || [];
          return /* @__PURE__ */ a.jsxs("div", { className: "space-y-2", children: [
            t.title && /* @__PURE__ */ a.jsx("label", { className: "block text-sm font-medium text-gray-700 mb-1", children: t.title }),
            /* @__PURE__ */ a.jsx("div", { className: "flex flex-wrap gap-1", children: g.map((f) => {
              const x = typeof f == "string" ? f : f.const, O = typeof f == "string" ? x : f.title || f.const, $ = r.includes(x);
              return /* @__PURE__ */ a.jsx(
                "button",
                {
                  type: "button",
                  className: `px-2 py-1 text-xs rounded border transition-colors ${$ ? "bg-upstart-500 text-white border-upstart-500" : "bg-gray-100 text-gray-700 border-gray-300 hover:bg-gray-200"}`,
                  onClick: () => {
                    const I = $ ? r.filter((A) => A !== x) : [...r, x];
                    o({ [e]: I }, e);
                  },
                  children: O
                },
                x
              );
            }) })
          ] }, `field-${e}`);
        }
        return /* @__PURE__ */ a.jsx(
          V,
          {
            currentValue: r,
            onChange: (g) => o({ [e]: g || [] }, e),
            itemSchema: d,
            fieldName: m,
            id: e,
            parents: u.parents,
            ...t
          },
          `field-${e}`
        );
      }
      return console.warn("Array field without items schema:", m, c), null;
    }
    case "iconify": {
      const n = l(s, e) ?? t.schema.default, r = t.schema["ui:default-icon-collection"];
      return /* @__PURE__ */ a.jsx(
        U,
        {
          currentValue: n,
          defaultCollection: r,
          onChange: (d) => o({ [e]: d }, e),
          ...t
        },
        `field-${e}`
      );
    }
    case "Function":
      return null;
    default:
      return console.log("!!! Unknown field type: %s", j), console.log("Field schema", c), null;
  }
}
function Ee({
  schema: u,
  formData: i,
  formSchema: m,
  onChange: p,
  options: h,
  noDynamic: s
}) {
  const e = re(), { brickId: o, filter: y, parents: c = [] } = h, t = [];
  return Object.entries(u.properties).forEach(([j, n]) => {
    const r = F(n);
    if (y && r.type !== "object" && !y(r)) {
      console.warn("ObjectFields: Ignoring field", r);
      return;
    }
    if (r.metadata?.filter) {
      const x = r.metadata.filter;
      if (!x(m, i, e))
        return;
    }
    const g = !(c.length > 0 && c[c.length - 1].includes("[")) && c.length > 0 ? `${c.join(".")}.${j}` : j, f = ne({
      brickId: o,
      fieldName: j,
      fieldSchema: r,
      formSchema: u,
      formData: i,
      id: g,
      onChange: p,
      parents: c,
      noDynamic: s
    });
    f && t.push(f);
  }), t;
}
function ze({
  title: u,
  description: i,
  className: m,
  containerClassName: p,
  withIcon: h = !1
}) {
  return u ? /* @__PURE__ */ a.jsx("div", { className: C("flex items-center text-nowrap basis-[45%]", p), children: i ? h ? /* @__PURE__ */ a.jsx(
    "label",
    {
      className: C(
        m,
        b,
        " underline-offset-4 no-underline decoration-upstart-300 decoration-dotted cursor-default"
      ),
      children: /* @__PURE__ */ a.jsx(
        N,
        {
          content: /* @__PURE__ */ a.jsx("span", { className: "block text-sm p-1", children: i }),
          className: "!z-[10000]",
          align: "start",
          children: /* @__PURE__ */ a.jsxs("span", { className: "cursor-help flex items-center", children: [
            u,
            /* @__PURE__ */ a.jsx(k, { className: "ml-1 text-[110%] opacity-50" })
          ] })
        }
      )
    }
  ) : /* @__PURE__ */ a.jsx(
    N,
    {
      content: /* @__PURE__ */ a.jsx("span", { className: "block text-sm p-1", children: i }),
      className: "!z-[10000]",
      align: "start",
      children: /* @__PURE__ */ a.jsx(
        "label",
        {
          className: C(
            m,
            b,
            "underline-offset-4 no-underline hover:underline decoration-upstart-300 decoration-dotted cursor-default"
          ),
          children: u
        }
      )
    }
  ) : /* @__PURE__ */ a.jsx("label", { className: C(m, b), children: u }) }) : null;
}
export {
  ze as FieldTitle,
  Ee as default
};
//# sourceMappingURL=field-factory.js.map
