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