import { j as e } from "../../../../../_virtual/jsx-runtime.js";
import { useState as A, useCallback as W, Fragment as H } 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 { PiListNumbersLight as G } from "../../../../../node_modules/.pnpm/react-icons@5.3.0_react@18.3.0-canary-3d9b20132-20240124/node_modules/react-icons/pi/index.js";
import { useModal as _, useEditorHelpers as O } from "../../../../../use-editor.js";
import { BsDatabaseDown as U, BsDatabase as Y, BsCrosshair as J } from "../../../../../node_modules/.pnpm/react-icons@5.3.0_react@18.3.0-canary-3d9b20132-20240124/node_modules/react-icons/bs/index.js";
import { e as I } from "../../../../sdk/dist/shared/chunk-5N6MBJJ4.js";
import "@sinclair/typebox";
import { getDatasourceIndexedFieldsWithTitles as K } from "../../../../sdk/dist/shared/datasources.js";
import { a as z } from "../../../../sdk/dist/shared/chunk-ZTDUXSWH.js";
import "../../../../sdk/dist/shared/chunk-T3LIA4YB.js";
import "../../../../sdk/dist/shared/chunk-YBGPPF7T.js";
import "../../../../sdk/dist/shared/chunk-UMHXXXVP.js";
import { useSiteQueries as X, useDraftHelpers as Z } from "../../../../../use-page-data.js";
import { useDatasources as $, useDatasource as ee } from "../hooks/use-datasource.js";
import { FieldTitle as x } from "./json-form/field-factory.js";
import { TbPlus as ae } from "../../../../../node_modules/.pnpm/react-icons@5.3.0_react@18.3.0-canary-3d9b20132-20240124/node_modules/react-icons/tb/index.js";
import { RxCross2 as se } from "../../../../../node_modules/.pnpm/react-icons@5.3.0_react@18.3.0-canary-3d9b20132-20240124/node_modules/react-icons/rx/index.js";
import { tx as g } from "../../../../style-system/dist/twind.js";
import te from "../../../../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/debounce.js";
import { nanoid as le } from "../../../../../node_modules/.pnpm/nanoid@5.1.5/node_modules/nanoid/index.browser.js";
import { LuPlus as re } from "../../../../../node_modules/.pnpm/react-icons@5.3.0_react@18.3.0-canary-3d9b20132-20240124/node_modules/react-icons/lu/index.js";
import ie, { TagsSelect as ne } from "./TagsInput.js";
import { FiEdit as oe } from "../../../../../node_modules/.pnpm/react-icons@5.3.0_react@18.3.0-canary-3d9b20132-20240124/node_modules/react-icons/fi/index.js";
import { Root as de, Content as ce, Title as ue, Description as me } 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/dialog.js";
import { Button as S } 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/button.js";
import { Tooltip as T } 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";
import { IconButton as M } 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/icon-button.js";
import { Root as v } 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";
import { Root as y, Trigger as N, Content as w, Item as h, Group as C, Separator as pe } 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 fe, Item 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/segmented-control.js";
function Ye() {
  const n = _(), { hideModal: c } = O();
  return /* @__PURE__ */ e.jsx(
    de,
    {
      open: !!n,
      onOpenChange: (l) => {
        l || c();
      },
      children: n === "queries" && /* @__PURE__ */ e.jsx(xe, {})
    }
  );
}
function xe() {
  const [n, c] = A(!1), [l, o] = A(null), q = O(), b = X(), D = $(), { hideModal: m } = O();
  return /* @__PURE__ */ e.jsxs(
    ce,
    {
      "aria-describedby": "Queries managament",
      maxWidth: "760px",
      minHeight: "80dvh",
      className: "overflow-y-clip flex flex-col gap-y-2",
      children: [
        /* @__PURE__ */ e.jsxs(ue, { className: "flex items-center gap-3 pl-0 -ml-3", children: [
          /* @__PURE__ */ e.jsx(U, { className: "h-6 w-6 text-upstart-600" }),
          "Manage site queries",
          /* @__PURE__ */ e.jsxs(
            S,
            {
              size: "2",
              disabled: !D.length || n,
              variant: "outline",
              radius: "medium",
              className: g("!ml-auto", n && "!opacity-0"),
              onClick: () => {
                o(null), c(!0);
              },
              children: [
                /* @__PURE__ */ e.jsx(re, { className: "w-4 h-4" }),
                "Create Query"
              ]
            }
          )
        ] }),
        /* @__PURE__ */ e.jsxs(me, { children: [
          "Queries are used to fetch data from your databases. Once defined you can use them in your",
          " ",
          /* @__PURE__ */ e.jsx(
            "button",
            {
              type: "button",
              className: g("text-upstart-600 hover:underline underline-offset-4"),
              onClick: () => {
                m(), q.setPanel("settings");
              },
              children: "page settings"
            }
          ),
          " ",
          "and reference them to loop over or use their fields in bricks to display dynamic data."
        ] }),
        n && /* @__PURE__ */ e.jsx(he, { query: l, onClose: () => c(!1) }),
        !n && b.length === 0 && /* @__PURE__ */ e.jsx("div", { className: "flex flex-col gap-2 justify-center items-center flex-1 text-center", children: /* @__PURE__ */ e.jsxs("span", { className: "text-base text-gray-500", children: [
          "You currently have no queries defined.",
          /* @__PURE__ */ e.jsx("br", {}),
          "Create a new query to get started."
        ] }) }),
        b.length > 0 && /* @__PURE__ */ e.jsx("div", { className: "flex flex-col border border-gray-200 rounded-lg overflow-hidden -mx-1 mt-3 shadow-sm", children: b.map((r) => /* @__PURE__ */ e.jsxs(
          "div",
          {
            className: "flex items-center justify-between p-4 [&:not(:last-child)]:border-b border-gray-200 ",
            children: [
              /* @__PURE__ */ e.jsxs("div", { className: "flex flex-col gap-2", children: [
                /* @__PURE__ */ e.jsx("div", { className: "font-medium", children: r.label }),
                /* @__PURE__ */ e.jsxs("div", { className: "flex gap-6 items-center justify-start text-sm  text-gray-500", children: [
                  /* @__PURE__ */ e.jsx(T, { content: "Database", children: /* @__PURE__ */ e.jsxs("span", { className: "inline-flex gap-1 items-center cursor-help", children: [
                    /* @__PURE__ */ e.jsx(Y, { className: "text-upstart-500" }),
                    r.datasourceId
                  ] }) }),
                  /* @__PURE__ */ e.jsx(T, { content: "Number of items", children: /* @__PURE__ */ e.jsxs("span", { className: "inline-flex gap-1 items-center cursor-help", children: [
                    /* @__PURE__ */ e.jsx(G, { className: "text-upstart-500" }),
                    r.limit
                  ] }) }),
                  (r.parameters?.length ?? 0) > 0 && /* @__PURE__ */ e.jsx(T, { content: "Parameters", children: /* @__PURE__ */ e.jsxs("span", { className: "inline-flex gap-1 items-center cursor-help", children: [
                    /* @__PURE__ */ e.jsx(J, { className: "text-upstart-500" }),
                    r.parameters.join(", ")
                  ] }) })
                ] })
              ] }),
              /* @__PURE__ */ e.jsx(
                M,
                {
                  size: "2",
                  variant: "soft",
                  color: "violet",
                  onClick: () => {
                    o(r), c(!0);
                  },
                  children: /* @__PURE__ */ e.jsx(oe, { className: "w-4 h-4" })
                }
              )
            ]
          },
          r.id
        )) })
      ]
    }
  );
}
function Q() {
  return {
    id: le(7),
    filters: {
      op: "and",
      fields: []
    },
    sortField: "$publicationDate",
    sortDirection: "desc",
    limit: 10
  };
}
function he({ query: n, onClose: c }) {
  const [l, o] = A(n ?? Q()), q = () => {
    o(Q());
  }, { upsertQuery: b } = Z(), D = $(), m = ee(l?.datasourceId), r = m ? K(m) : [], k = r.filter((a) => ["$id", "$slug"].includes(a.value) === !1), V = l?.filters?.fields?.filter((a) => "field" in a) ?? [], F = (a, t) => {
    o(
      (s) => ({
        ...s,
        sortDirection: a === "sortField" && t === "random()" ? null : s?.sortDirection,
        [a]: t
      })
    );
  }, E = (a) => {
    if (!m) return [];
    const t = u(a), s = [
      { value: "eq", label: "Equals" },
      { value: "ne", label: "Not equals" }
    ], d = [
      { value: "contains", label: "Contains" },
      { value: "notContains", label: "Not contains" },
      { value: "startsWith", label: "Starts with" },
      { value: "notStartsWith", label: "Not starts with" },
      { value: "endsWith", label: "Ends with" },
      { value: "notEndsWith", label: "Not ends with" }
    ], i = [
      { value: "contains", label: "Contains" },
      { value: "notContains", label: "Not contains" },
      { value: "containsAll", label: "Contains all" },
      { value: "containsAny", label: "Contains any" },
      { value: "notContainsAny", label: "Not contains any" }
    ], f = [
      { value: "lt", label: "Less than" },
      { value: "lte", label: "Less than or equal" },
      { value: "gt", label: "Greater than" },
      { value: "gte", label: "Greater than or equal" }
    ], j = [
      { value: "before", label: "Before Date" },
      { value: "after", label: "After Date" },
      { value: "beforeNow", label: "Before Now" },
      { value: "afterNow", label: "After Now" }
    ];
    switch (t) {
      case "array":
        return i;
      case "string":
        return [...s, ...d];
      case "number":
      case "integer":
        return [...s, ...f];
      case "boolean":
        return [{ value: "eq", label: "Equals" }];
      case "date":
      case "datetime":
        return [...j, s[0]];
      default:
        return [...s, ...d, ...f, ...j];
    }
  }, B = () => {
    const a = {
      field: "",
      op: "eq",
      value: ""
    };
    o((t) => {
      const s = t?.filters?.fields?.filter((d) => "field" in d) ?? [];
      return {
        ...t,
        filters: {
          op: "and",
          fields: [...s, a]
        }
      };
    });
  }, P = (a) => {
    o((t) => {
      const d = (t?.filters?.fields?.filter((i) => "field" in i) ?? []).filter((i, f) => f !== a);
      return {
        ...t,
        filters: {
          op: "and",
          fields: d
        }
      };
    });
  }, p = (a, t, s) => {
    o((d) => {
      const i = [...d?.filters?.fields?.filter((j) => "field" in j) ?? []], f = { ...i[a] };
      if (t === "field") {
        const j = s ? E(s)[0]?.value ?? "eq" : "eq";
        i[a] = { field: s, op: j, value: "" };
      } else t === "op" ? i[a] = { ...f, op: s, value: "" } : i[a] = { ...f, [t]: s };
      return console.log("Updated filters:", i), {
        ...d,
        filters: {
          op: "and",
          fields: i
        }
      };
    });
  }, u = (a) => {
    if (!m) return "string";
    const t = m.schema?.items?.properties?.[a];
    return t?.type === "string" && t.format === "date" ? "date" : t?.type === "string" && t.format === "date-time" ? "datetime" : t?.type ?? "string";
  }, R = W(
    (a) => {
      a.preventDefault(), a.stopPropagation(), console.log("Submitting query:", l), z.validate(I, l) ? (b(l), c?.()) : console.error("Query validation failed:", z.errors, l);
    },
    [l]
  );
  return /* @__PURE__ */ e.jsxs(
    "form",
    {
      onSubmit: R,
      className: "text-sm border border-gray-300 bg-gray-50 p-4 rounded-lg -mx-1 mt-3 shadow-sm",
      children: [
        /* @__PURE__ */ e.jsx("h3", { className: "font-bold text-base mb-3", children: n ? "Edit query" : "Create a new query" }),
        /* @__PURE__ */ e.jsxs("div", { className: "flex flex-col text-sm gap-4 flex-1 -mx-2.5 divide-y divide-gray-200", children: [
          /* @__PURE__ */ e.jsxs("div", { className: "flex justify-between gap-4 flex-1 items-center py-0.5 px-2.5", children: [
            /* @__PURE__ */ e.jsxs("div", { className: "flex flex-col gap-1 flex-1", children: [
              /* @__PURE__ */ e.jsx(
                x,
                {
                  withIcon: !0,
                  className: "font-medium",
                  title: "Label",
                  description: "Label displayed in the Editor"
                }
              ),
              /* @__PURE__ */ e.jsx(
                v,
                {
                  onInput: (a) => F("label", a.currentTarget.value),
                  defaultValue: l?.label,
                  maxLength: I.properties.label.maxLength,
                  "aria-required": !0,
                  placeholder: "Ex: Latest blog posts"
                }
              )
            ] }),
            /* @__PURE__ */ e.jsxs("div", { className: "flex flex-col gap-1 flex-1", children: [
              /* @__PURE__ */ e.jsx(x, { withIcon: !0, className: "font-medium", title: "Database", description: "Database to query" }),
              /* @__PURE__ */ e.jsxs(
                y,
                {
                  "aria-required": !0,
                  defaultValue: l?.datasourceId,
                  size: "2",
                  onValueChange: (a) => o(
                    (t) => ({
                      ...t ?? {},
                      datasourceId: a,
                      filters: {
                        op: "and",
                        fields: []
                      }
                    })
                  ),
                  children: [
                    /* @__PURE__ */ e.jsx(
                      N,
                      {
                        radius: "medium",
                        variant: "surface",
                        placeholder: "Select a database",
                        className: "!max-w-2/3 !mr-[1px]"
                      }
                    ),
                    /* @__PURE__ */ e.jsx(w, { position: "popper", children: D.map((a) => /* @__PURE__ */ e.jsx(h, { value: a.id, children: a.label }, a.id)) })
                  ]
                }
              )
            ] })
          ] }),
          r.length > 0 && /* @__PURE__ */ e.jsxs("div", { className: "flex flex-col gap-2 flex-1 justify-between pt-3 px-2.5", children: [
            /* @__PURE__ */ e.jsxs("div", { className: "flex flex-1 w-full justify-between items-center", children: [
              /* @__PURE__ */ e.jsx(
                x,
                {
                  withIcon: !0,
                  title: "Filters",
                  className: "font-medium",
                  description: "Add filters to narrow down your query"
                }
              ),
              /* @__PURE__ */ e.jsxs(S, { type: "button", radius: "full", variant: "solid", size: "1", onClick: B, children: [
                /* @__PURE__ */ e.jsx(ae, { className: "w-3 h-3" }),
                "Add Filter"
              ] })
            ] }),
            V.length > 0 && /* @__PURE__ */ e.jsx("div", { className: "flex flex-col gap-3 mt-1", children: V.map((a, t) => /* @__PURE__ */ e.jsxs(H, { children: [
              /* @__PURE__ */ e.jsxs("div", { className: "flex gap-x-3 gap-y-0.5 items-center", children: [
                /* @__PURE__ */ e.jsx("div", { className: "w-[200px] flex items-center gap-3 pr-1", children: /* @__PURE__ */ e.jsxs(
                  y,
                  {
                    defaultValue: a.field,
                    onValueChange: (s) => p(t, "field", s),
                    children: [
                      /* @__PURE__ */ e.jsx(
                        N,
                        {
                          className: "!w-full",
                          radius: "medium",
                          variant: "surface",
                          placeholder: "Select a field"
                        }
                      ),
                      /* @__PURE__ */ e.jsx(w, { position: "popper", children: /* @__PURE__ */ e.jsx(C, { children: r.map((s) => /* @__PURE__ */ e.jsx(h, { value: s.value, children: s.title }, s.value)) }) })
                    ]
                  }
                ) }),
                /* @__PURE__ */ e.jsx("div", { className: g("flex gap-2 items-center w-[120px]", !a.field && "hidden"), children: /* @__PURE__ */ e.jsxs(
                  y,
                  {
                    defaultValue: a.op,
                    size: "2",
                    onValueChange: (s) => p(t, "op", s),
                    disabled: !a.field,
                    children: [
                      /* @__PURE__ */ e.jsx(
                        N,
                        {
                          radius: "medium",
                          variant: "ghost",
                          placeholder: "Select operator",
                          className: "!flex-1 !mr-1"
                        }
                      ),
                      /* @__PURE__ */ e.jsx(w, { position: "popper", children: /* @__PURE__ */ e.jsx(C, { children: E(a.field).map((s) => /* @__PURE__ */ e.jsx(h, { value: s.value, children: s.label }, s.value)) }) })
                    ]
                  },
                  `operator-${t}-${a.field}`
                ) }),
                u(a.field) === "date" || u(a.field) === "datetime" ? (a.op === "before" || a.op === "after" || a.op === "eq") && // Absolute date: span both columns
                /* @__PURE__ */ e.jsx("div", { className: g("grow flex justify-end", !a.field && "hidden"), children: /* @__PURE__ */ e.jsx(
                  v,
                  {
                    size: "2",
                    type: u(a.field) === "datetime" ? "datetime-local" : "date",
                    defaultValue: String(a.value || ""),
                    onChange: (s) => p(t, "value", s.target.value),
                    disabled: !a.field,
                    className: "!w-full"
                  }
                ) }) : (
                  // Non-date fields: span both columns
                  /* @__PURE__ */ e.jsx("div", { className: g("grow flex justify-end", !a.field && "hidden"), children: u(a.field) === "number" || u(a.field) === "integer" ? /* @__PURE__ */ e.jsx(
                    v,
                    {
                      type: "number",
                      size: "2",
                      defaultValue: String(a.value || ""),
                      onChange: (s) => p(t, "value", Number(s.target.value)),
                      placeholder: "Value",
                      min: "1",
                      disabled: !a.field,
                      className: "!w-full"
                    }
                  ) : u(a.field) === "boolean" ? /* @__PURE__ */ e.jsxs(
                    fe,
                    {
                      size: "1",
                      defaultValue: String(a.value || "true"),
                      onValueChange: (s) => p(t, "value", s === "true"),
                      className: g("!mt-0.5 [&_.rt-SegmentedControlItemLabel]:(px-3)"),
                      children: [
                        /* @__PURE__ */ e.jsx(L, { value: "true", children: "True" }),
                        /* @__PURE__ */ e.jsx(L, { value: "false", children: "False" })
                      ]
                    }
                  ) : u(a.field) === "array" ? /* @__PURE__ */ e.jsx(
                    ie,
                    {
                      initialValue: Array.isArray(a.value) ? a.value : [],
                      onChange: (s) => p(t, "value", s),
                      className: "!w-full",
                      placeholder: "Add tags"
                    }
                  ) : /* @__PURE__ */ e.jsx(
                    v,
                    {
                      disabled: !a.field,
                      defaultValue: String(a.value || ""),
                      onChange: te((s) => p(t, "value", s.target.value), 400),
                      placeholder: "Value",
                      size: "2",
                      className: "!w-full max-w-full"
                    }
                  ) })
                ),
                /* @__PURE__ */ e.jsx(
                  M,
                  {
                    size: "1",
                    type: "button",
                    variant: "ghost",
                    className: "hover:(bg-red-100 text-red-800) !shrink-0 !ml-auto",
                    onClick: () => P(t),
                    children: /* @__PURE__ */ e.jsx(se, { size: 14 })
                  }
                )
              ] }),
              t < V.length - 1 && /* @__PURE__ */ e.jsx("div", { className: "border-t border-dotted mx-auto w-2/3 border-gray-200 my-2 relative", children: /* @__PURE__ */ e.jsx("span", { className: "absolute left-1/2 -translate-x-1/2 -top-3 bg-gray-50 rounded-full px-2 py-1 inline-block text-xs text-gray-500", children: "And" }) })
            ] }, t)) })
          ] }),
          r.length > 0 && /* @__PURE__ */ e.jsx("div", { className: "flex flex-col gap-2 flex-1 justify-between pt-3 px-2.5", children: /* @__PURE__ */ e.jsxs("div", { className: "flex flex-1 w-full justify-between items-center", children: [
            /* @__PURE__ */ e.jsx(
              x,
              {
                title: "Parameters",
                className: "font-medium",
                withIcon: !0,
                description: "Optional fields that will be used as parameters when using the query. Only indexed fields can be used as parameters. Usually only one parameter is needed, but you can add multiple parameters if necessary. When specifying parameters, you will need to set a value for each parameter every time you use it."
              }
            ),
            /* @__PURE__ */ e.jsx(
              ne,
              {
                options: r.map((a) => ({ value: a.value, label: a.title })),
                initialValue: l?.parameters ?? [],
                isMulti: !0,
                onChange: (a) => o((t) => ({ ...t, parameters: a })),
                className: "!w-full min-w-fit max-w-[340px]",
                placeholder: "Add parameters (e.g. Slug, Id)"
              }
            )
          ] }) }),
          l?.datasourceId && /* @__PURE__ */ e.jsxs("div", { className: "flex flex-1 gap-6 justify-between items-center pt-2.5 pb-1 px-2.5", children: [
            /* @__PURE__ */ e.jsxs("div", { className: "flex flex-col gap-1 flex-1 ", children: [
              /* @__PURE__ */ e.jsx(
                x,
                {
                  className: "font-medium",
                  title: "Order by",
                  description: "Select a field to sort the results"
                }
              ),
              /* @__PURE__ */ e.jsxs(
                y,
                {
                  defaultValue: l?.sortField,
                  size: "2",
                  onValueChange: (a) => F("sortField", a),
                  children: [
                    /* @__PURE__ */ e.jsx(
                      N,
                      {
                        radius: "medium",
                        variant: "surface",
                        className: "!mr-[1px] !mt-0.5",
                        placeholder: "Select a field"
                      }
                    ),
                    /* @__PURE__ */ e.jsxs(w, { position: "popper", children: [
                      /* @__PURE__ */ e.jsx(C, { children: k.map((a) => /* @__PURE__ */ e.jsx(h, { value: a.value, children: a.title }, a.value)) }),
                      /* @__PURE__ */ e.jsx(pe, {}),
                      /* @__PURE__ */ e.jsx(C, { children: /* @__PURE__ */ e.jsx(h, { value: "random()", children: "Random" }) })
                    ] })
                  ]
                }
              )
            ] }),
            /* @__PURE__ */ e.jsxs(
              "div",
              {
                className: g("flex flex-col gap-1 flex-1", l?.sortField === "random()" && "opacity-40"),
                children: [
                  /* @__PURE__ */ e.jsx(
                    x,
                    {
                      className: "font-medium",
                      title: "Direction",
                      description: "Select the direction to sort the results"
                    }
                  ),
                  /* @__PURE__ */ e.jsxs(
                    y,
                    {
                      disabled: l?.sortField === "random()",
                      defaultValue: l?.sortDirection || "asc",
                      size: "2",
                      onValueChange: (a) => F("sortDirection", a),
                      children: [
                        /* @__PURE__ */ e.jsx(
                          N,
                          {
                            radius: "medium",
                            variant: "surface",
                            placeholder: "Select direction",
                            className: "!mr-[1px] !mt-0.5"
                          }
                        ),
                        /* @__PURE__ */ e.jsx(w, { position: "popper", children: /* @__PURE__ */ e.jsxs(C, { children: [
                          /* @__PURE__ */ e.jsx(h, { value: "asc", children: "Ascending" }),
                          /* @__PURE__ */ e.jsx(h, { value: "desc", children: "Descending" })
                        ] }) })
                      ]
                    }
                  )
                ]
              }
            )
          ] }),
          l?.datasourceId && r.length > 0 && /* @__PURE__ */ e.jsx("div", { className: "flex flex-1 gap-6 justify-between items-center pt-2.5 pb-1 px-2.5", children: /* @__PURE__ */ e.jsxs("div", { className: "flex flex-col flex-1 gap-2", children: [
            /* @__PURE__ */ e.jsx(
              x,
              {
                className: "font-medium",
                title: "Max number of items to fetch",
                containerClassName: "!basis-0"
              }
            ),
            /* @__PURE__ */ e.jsx(
              v,
              {
                type: "number",
                defaultValue: l?.limit?.toString() ?? "10",
                onChange: (a) => F("limit", parseInt(a.target.value) || 10),
                min: "1",
                max: "30",
                className: "!w-[40px]"
              }
            )
          ] }) })
        ] }),
        /* @__PURE__ */ e.jsxs("div", { className: "flex justify-end gap-2 mt-10", children: [
          /* @__PURE__ */ e.jsx(
            S,
            {
              type: "button",
              size: "2",
              color: "gray",
              variant: "soft",
              onClick: () => {
                q(), c?.();
              },
              children: "Cancel"
            }
          ),
          /* @__PURE__ */ e.jsx(S, { disabled: z.validate(I, l) === !1, type: "submit", size: "2", children: "Save query" })
        ] })
      ]
    }
  );
}
export {
  Ye as default
};
//# sourceMappingURL=Modal.js.map
