import { j as i } from "../../../../../../../_virtual/jsx-runtime.js";
import { useState as y } from "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 { FieldTitle as c } from "../field-factory.js";
import { usePageQueries as b } from "../../../../../../../use-page-data.js";
import { Switch as C } 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/switch.js";
import { Root as N, Trigger as I, Content as O, Item as u } 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/select.js";
import { Root as L } 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/text-field.js";
const o = "$NOLOOP$", D = (d) => {
  const { currentValue: t, onChange: r, schema: f, title: p, description: h } = d, { over: a = o } = t ?? {}, [l, v] = y(!!t?.overrideLimit), s = b(), n = s.find((e) => e.alias === a), m = f["ui:placeholder"] ?? "Do not repeat", x = (e) => {
    r(e === o ? null : {
      ...t ?? {},
      over: e
    });
  };
  if (s.length === 0)
    return null;
  const g = s.filter((e) => !e.queryInfo?.limit || e.queryInfo?.limit > 1);
  return /* @__PURE__ */ i.jsxs("div", { className: "layout-field w-full flex flex-col gap-3", children: [
    /* @__PURE__ */ i.jsxs("div", { className: "flex items-center justify-between pr-1", children: [
      /* @__PURE__ */ i.jsx(
        c,
        {
          title: p ?? "Repeat over",
          description: h ?? "repeat the brick for each item returned by the query. If no query is selected, the brick will not repeat.",
          containerClassName: "!basis-1/4"
        }
      ),
      /* @__PURE__ */ i.jsxs(N, { defaultValue: a, size: "2", onValueChange: x, children: [
        /* @__PURE__ */ i.jsx(
          I,
          {
            radius: "medium",
            variant: "ghost",
            className: "!basis-2/3 !text-[92%] !max-w-fit",
            placeholder: m
          }
        ),
        /* @__PURE__ */ i.jsxs(O, { position: "popper", children: [
          /* @__PURE__ */ i.jsx(u, { value: o, children: m }),
          g.map((e) => /* @__PURE__ */ i.jsxs(u, { value: e.alias, children: [
            e.alias,
            " - ",
            e.queryInfo?.label
          ] }, e.alias))
        ] })
      ] })
    ] }),
    typeof t?.over == "string" && /* @__PURE__ */ i.jsxs("div", { className: "flex items-center justify-between", children: [
      /* @__PURE__ */ i.jsx(
        c,
        {
          title: "Override limit",
          description: "Override the number of items to repeat over. It can only be inferior to the number of items (limit) set by the query."
        }
      ),
      /* @__PURE__ */ i.jsxs("div", { className: "flex items-center gap-1.5", children: [
        /* @__PURE__ */ i.jsx(
          C,
          {
            size: "2",
            defaultChecked: l,
            onCheckedChange: (e) => {
              v(e), e || r({
                ...t ?? {},
                overrideLimit: void 0
              });
            },
            className: "mr-2"
          }
        ),
        /* @__PURE__ */ i.jsx(
          L,
          {
            disabled: !l,
            size: "2",
            type: "number",
            min: "1",
            max: n?.queryInfo?.limit ?? 50,
            defaultValue: t?.overrideLimit ?? n?.queryInfo?.limit ?? 10,
            onChange: (e) => {
              const j = e.target.value ? parseInt(e.target.value, 10) : void 0;
              r({
                ...t ?? {},
                overrideLimit: j
              });
            },
            className: "w-[34px]"
          }
        )
      ] })
    ] })
  ] });
};
export {
  D as default
};
//# sourceMappingURL=loop.js.map
