import { j as e } from "../../node_modules/react/jsx-runtime.mjs";
import { useState as M, useMemo as z, createElement as J } from "react";
import "./index.less.mjs";
import { useImmer as A } from "../../node_modules/use-immer/dist/use-immer.module.mjs";
import { isMobile as E } from "../../node_modules/react-device-detect/dist/lib.mjs";
import d from "../../node_modules/antd/es/form/index.mjs";
import K from "../../node_modules/antd/es/divider/index.mjs";
import c from "../../node_modules/antd/es/grid/col.mjs";
import I from "../../node_modules/antd/es/grid/row.mjs";
import W from "../../node_modules/antd/es/tag/index.mjs";
import S from "../../node_modules/antd/es/select/index.mjs";
import X from "../../node_modules/antd/es/tooltip/index.mjs";
import x from "../../node_modules/antd/es/button/button.mjs";
import Q from "../../node_modules/antd/es/input/index.mjs";
import Y from "../../node_modules/@ant-design/icons/es/icons/SettingOutlined.mjs";
import Z from "../../node_modules/@ant-design/icons/es/icons/MinusCircleOutlined.mjs";
import $ from "../../node_modules/@ant-design/icons/es/icons/PlusOutlined.mjs";
const L = {
  input: Q,
  select: S
}, fe = (t) => {
  const [j] = d.useForm(), [o, g] = A([]), [b, y] = A([]), [v, T] = M(!1), [C, B] = M(!1), [f, V] = M(!1), D = {
    xs: 24,
    sm: 24,
    md: 24,
    lg: 8,
    xl: 8
  }, k = z(() => {
    var n, i;
    return C ? t == null ? void 0 : t.items : E ? (n = t == null ? void 0 : t.items) == null ? void 0 : n.slice(0, 1) : (i = t == null ? void 0 : t.items) == null ? void 0 : i.slice(0, 3);
  }, [C, t == null ? void 0 : t.items, E]), N = (n) => {
    var i, l;
    console.log("onFinish", n), f ? (i = t == null ? void 0 : t.onFinish) == null || i.call(t, n == null ? void 0 : n.advanced) : (n == null || delete n.advanced, (l = t == null ? void 0 : t.onFinish) == null || l.call(t, n), g(() => b));
  }, P = (n, i, l, m) => {
    var h;
    const a = b == null ? void 0 : b.findIndex((r) => r.name === i);
    m === "input" && (n = n[0].target.value), m === "select" && (n = (h = n[1]) == null ? void 0 : h.label), y((r) => {
      a !== -1 ? (r[a].value = n, r[a].label = l) : r.push({
        name: i,
        label: l,
        value: n
      });
    });
  }, U = () => {
    V(!f), B(!1), T(!1), j.resetFields([]), g(() => []), y(() => []);
  }, _ = z(() => {
    const n = (i) => {
      j.resetFields([i]), g((l) => l == null ? void 0 : l.filter((m) => m.name !== i)), y((l) => l == null ? void 0 : l.filter((m) => m.name !== i)), j.submit();
    };
    return o != null && o.length ? [
      /* @__PURE__ */ e.jsx(K, {}, "1"),
      /* @__PURE__ */ e.jsx(I, { gutter: [8, 8], children: o == null ? void 0 : o.map(
        (i) => /* @__PURE__ */ e.jsx(c, { children: /* @__PURE__ */ e.jsxs(
          W,
          {
            onClose: () => n(i.name),
            closeIcon: !0,
            children: [
              i.label,
              ": ",
              i.value
            ]
          }
        ) }, i.name)
      ) }, "2")
    ] : null;
  }, [o]), q = () => {
    j.resetFields(), g(() => []), y(() => []);
  };
  return /* @__PURE__ */ e.jsxs("div", { className: "BitzQueryFilter2Block", children: [
    /* @__PURE__ */ e.jsx(
      d,
      {
        form: j,
        onFinish: N,
        children: f ? /* @__PURE__ */ e.jsx(d.List, { name: "advanced", children: (n, { add: i, remove: l }) => {
          var m;
          return /* @__PURE__ */ e.jsxs(e.Fragment, { children: [
            n.map(({ key: a, name: h, ...r }) => {
              var R;
              return /* @__PURE__ */ e.jsxs(I, { gutter: [8, 0], children: [
                /* @__PURE__ */ e.jsx(c, { sm: 12, xs: 12, md: 4, children: /* @__PURE__ */ e.jsx(
                  d.Item,
                  {
                    ...r,
                    name: [h, "field"],
                    children: /* @__PURE__ */ e.jsx(
                      S,
                      {
                        style: { width: "100%" },
                        options: (R = t == null ? void 0 : t.items) == null ? void 0 : R.map((u) => ({
                          value: u.name,
                          label: u.label
                        }))
                      }
                    )
                  }
                ) }),
                /* @__PURE__ */ e.jsx(c, { sm: 12, xs: 12, md: 4, children: /* @__PURE__ */ e.jsx(
                  d.Item,
                  {
                    ...r,
                    name: [h, "state"],
                    children: /* @__PURE__ */ e.jsx(
                      S,
                      {
                        defaultValue: "1",
                        style: { width: "100%" },
                        options: [
                          { value: "1", label: "包含" },
                          { value: "2", label: "不包含" },
                          { value: "3", label: "等于" }
                        ]
                      }
                    )
                  }
                ) }),
                /* @__PURE__ */ e.jsx(c, { sm: 20, xs: 20, md: 4, children: /* @__PURE__ */ e.jsx(
                  d.Item,
                  {
                    style: { margin: 0, padding: 0 },
                    shouldUpdate: (u, w) => {
                      var s, F;
                      return ((s = u.advanced[a]) == null ? void 0 : s.field) !== ((F = w.advanced[a]) == null ? void 0 : F.field);
                    },
                    children: ({ getFieldValue: u }) => {
                      var O;
                      const w = u(["advanced", a, "field"]), s = (O = t == null ? void 0 : t.items) == null ? void 0 : O.find((H) => H.name === w), F = L[(s == null ? void 0 : s.type) ?? "input"], G = (s == null ? void 0 : s.props) ?? {};
                      return /* @__PURE__ */ e.jsx(d.Item, { name: [h, "value"], children: /* @__PURE__ */ e.jsx(F, { style: { width: "100%" }, ...G }) });
                    }
                  }
                ) }),
                /* @__PURE__ */ e.jsx(c, { sm: 4, xs: 4, children: /* @__PURE__ */ e.jsx(X, { placement: "top", title: "移除此项", children: /* @__PURE__ */ e.jsx(
                  x,
                  {
                    type: "text",
                    disabled: (n == null ? void 0 : n.length) <= 1,
                    onClick: () => l(h),
                    icon: /* @__PURE__ */ e.jsx(Z, {})
                  }
                ) }) })
              ] }, a);
            }),
            /* @__PURE__ */ e.jsx(d.Item, { children: /* @__PURE__ */ e.jsx(
              x,
              {
                type: "dashed",
                onClick: () => i(),
                block: !0,
                icon: /* @__PURE__ */ e.jsx($, {}),
                disabled: (n == null ? void 0 : n.length) >= ((m = t == null ? void 0 : t.items) == null ? void 0 : m.length),
                children: "添加条件"
              }
            ) })
          ] });
        } }) : /* @__PURE__ */ e.jsx(I, { gutter: [8, 0], children: k == null ? void 0 : k.map((n) => {
          const i = L[n.type] || Q, l = (n == null ? void 0 : n.props) ?? {};
          return /* @__PURE__ */ J(c, { ...D, key: n.name }, /* @__PURE__ */ e.jsx(
            d.Item,
            {
              label: n.label,
              name: n.name,
              children: /* @__PURE__ */ e.jsx(
                i,
                {
                  ...l,
                  onChange: (...m) => P(m, n.name, n.label, n.type)
                }
              )
            }
          ));
        }) })
      }
    ),
    /* @__PURE__ */ e.jsxs(I, { gutter: [8, 8], children: [
      /* @__PURE__ */ e.jsx(c, { children: /* @__PURE__ */ e.jsx(
        S,
        {
          defaultValue: "1",
          options: [
            { value: "1", label: "符合以上条件" },
            { value: "2", label: "Lucy" },
            { value: "3", label: "yiminghe" }
          ]
        }
      ) }),
      /* @__PURE__ */ e.jsx(c, { children: /* @__PURE__ */ e.jsx(x, { onClick: j.submit, type: "primary", children: "搜素" }) }),
      /* @__PURE__ */ e.jsx(c, { children: /* @__PURE__ */ e.jsx(x, { onClick: q, children: "重置" }) }),
      f ? null : /* @__PURE__ */ e.jsx(c, { children: /* @__PURE__ */ e.jsxs(x, { onClick: () => B(!C), children: [
        C ? "收起" : "展开",
        "筛选"
      ] }) }),
      /* @__PURE__ */ e.jsx(c, { children: /* @__PURE__ */ e.jsxs(x, { onClick: () => U(), children: [
        f ? "普通" : "高级",
        "筛选"
      ] }) }),
      /* @__PURE__ */ e.jsx(c, { children: /* @__PURE__ */ e.jsx(x, { type: "primary", icon: /* @__PURE__ */ e.jsx(Y, {}) }) })
    ] }),
    _
  ] });
};
export {
  fe as default
};
