import { X as h, Y as a, cm as x, _ as k, fp as A, at as P, g8 as U, F as l, g9 as C, a6 as w, fB as W, ga as G, gb as X, gc as Y, fu as _, fv as J, bV as E, av as Q, gd as L, ge as N, gf as V, gg as Z, fG as ee, fH as te, gh as B, gi as M, O as y, a as oe, a3 as le, w as D, S as ae, fM as q, gj as ne, gk as re, gl as ie, gm as se, gn as ce } from "./603b75d9.js";
import { useState as F, useMemo as pe, useContext as ue, useEffect as de, useRef as O } from "react";
import "react-dom";
const be = h.div`
  display: flex;
  align-items: center;
  gap: 8px;
`, fe = (e, t, o, c, u) => Q`
    background: ${e.background};
    // Implement horizontal scrollbar and vertical page number selection is not blocked
    padding: 13px 12px;
    position: sticky;
    postion: -webkit-sticky;
    left: 0px !important;
    margin: ${e.margin} !important;
    z-index: 999;

    ${u && c === "below" && "bottom: 0;"};
    ${u && c === "above" && "top: 0;"};

    .toolbar-icons {
      .refresh,
      .download {
        cursor: pointer;

        * {
          ${e.toolbarText !== C.textDark ? `stroke: ${e.toolbarText}` : null};
        }

        &:hover * {
          stroke: ${o == null ? void 0 : o.primary};
        }
      }

      .filter {
        cursor: pointer;

        * {
          ${t ? `stroke: ${C.primary}` : e.toolbarText !== C.textDark ? `stroke: ${e.toolbarText}` : null}
        }

        &:hover * {
          stroke: ${o == null ? void 0 : o.primary};
        }
      }

      .column-setting {
        width: 20px;
        cursor: pointer;

        * {
          ${e.toolbarText && e.toolbarText !== C.textDark ? `fill: ${e.toolbarText}` : "fill: #8b8fa3"} 
        }

        &:hover * {
          fill: ${o == null ? void 0 : o.primary};
        }
      }
    }

    .ant-pagination-prev,
    .ant-pagination-next {
      path {
        ${e.toolbarText !== C.textDark ? `fill: ${e.toolbarText}` : null};
      }

      svg:hover {
        path {
          fill: ${o == null ? void 0 : o.primary};
        }
      }
    }

    .ant-pagination {
      color: ${e.toolbarText};
    }

    .ant-pagination-item-active {
      border-color: ${e.border || (o == null ? void 0 : o.primary)};

      a {
        color: ${o == null ? void 0 : o.textDark};
      }
    }

    .ant-pagination-item:not(.ant-pagination-item-active) a {
      color: ${e.toolbarText};

      &:hover {
        color: ${o == null ? void 0 : o.primary};
      }
    }

    .ant-select:not(.ant-select-disabled):hover .ant-select-selector,
    .ant-select-focused:not(.ant-select-disabled).ant-select:not(.ant-select-customize-input)
      .ant-select-selector,
    .ant-pagination-options-quick-jumper input:hover,
    .ant-pagination-options-quick-jumper input:focus {
      border-color: ${e.border || (o == null ? void 0 : o.primary)};
    }
  `, ge = h.div`
  // overflow: auto;
  ${(e) => e.$style && fe(e.$style, e.$filtered, e.$theme, e.$position, e.$fixedToolbar)}
`, he = h.div`
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-width: max-content;
  height: 21px;
  width: 100%;
`, me = h.div`
  display: flex;
  align-items: center;
  gap: 8px;
`, we = h(re)`
  height: 16px;
  width: 16px;

  ${(e) => e.disabled && `
      cursor: not-allowed;
      g g {
      stroke: #D7D9E0;
    }
  `}
  :hover:not([disabled]) {
    cursor: pointer;

    g g {
      stroke: #315efb;
    }
  }
`, xe = h.div`
  display: flex;
  align-items: center;
  gap: 8px;
`, ye = h.div`
  min-height: 92px;
  overflow: auto;

  > div {
    margin-top: 4px;
  }
`, Ce = h.div`
  display: flex;
  align-items: end;
  height: 44px;
  justify-content: end;
  gap: 4px;

  > button {
    width: 76px;
    height: 28px;
  }
`, H = h.div`
  display: flex;
  gap: 4px;
`, K = [{
  label: a("table.and"),
  value: "and"
}, {
  label: a("table.or"),
  value: "or"
}], ve = [{
  label: /* @__PURE__ */ l(ie, {}),
  value: "below"
}, {
  label: /* @__PURE__ */ l(se, {}),
  value: "above"
}, {
  label: /* @__PURE__ */ l(ce, {}),
  value: "close"
}], ke = ["contain", "notContain", "equal", "notEqual", "isEmpty", "isNotEmpty", "gt", "gte", "lt", "lte"], z = ["isEmpty", "isNotEmpty"], Te = {
  contain: {
    label: a("table.contains"),
    filter: (e, t) => x.isNil(t) ? !1 : t.toString().toLowerCase().includes(e.toLowerCase())
  },
  notContain: {
    label: a("table.notContain"),
    filter: (e, t) => x.isNil(t) ? !0 : !t.toString().toLowerCase().includes(e.toLowerCase())
  },
  equal: {
    label: a("table.equals"),
    filter: (e, t) => x.isNil(t) ? !1 : t.toString() === e
  },
  notEqual: {
    label: a("table.isNotEqual"),
    filter: (e, t) => x.isNil(t) ? !0 : t.toString() !== e
  },
  isEmpty: {
    label: a("table.isEmpty"),
    filter: (e, t) => t === "" || x.isNil(t)
  },
  isNotEmpty: {
    label: a("table.isNotEmpty"),
    filter: (e, t) => t !== "" && !x.isNil(t)
  },
  gt: {
    label: a("table.greater"),
    filter: (e, t) => k.gt(t, e)
  },
  gte: {
    label: a("table.greaterThanOrEquals"),
    filter: (e, t) => k.gte(t, e)
  },
  lt: {
    label: a("table.lessThan"),
    filter: (e, t) => k.gt(e, t)
  },
  lte: {
    label: a("table.lessThanOrEquals"),
    filter: (e, t) => k.gte(e, t)
  }
}, $ = (e = "", t = "", o) => ({
  key: L(),
  columnKey: e,
  filterValue: t,
  operator: o
});
function Ve(e) {
  return e.columnKey && e.operator && (e.filterValue !== "" || z.includes(e.operator));
}
function $e(e) {
  return !e.columnKey && !e.operator && e.filterValue === "";
}
function Fe(e) {
  const {
    columnKeyNames: t,
    tableFilter: o,
    onFilterChange: c,
    setVisible: u
  } = e, [d, p] = F(o.stackType), [i, s] = F(() => o.filters.length <= 0 ? [$()] : o.filters.map((n) => ({
    key: L(),
    ...n
  }))), f = (n) => {
    s(i.map((g) => g.key === n.key ? {
      ...n
    } : g));
  };
  de(() => {
    c(i.filter((n) => Ve(n)).map((n) => ({
      filterValue: n.filterValue,
      operator: n.operator,
      columnKey: n.columnKey
    })), d);
  }, [d, i]);
  const S = /* @__PURE__ */ l(ye, {
    children: i && i.map((n, g) => {
      var v;
      return /* @__PURE__ */ w(xe, {
        children: [g === 0 && /* @__PURE__ */ l(N, {
          style: {
            width: "65px"
          },
          children: a("table.filterRule")
        }), g >= 1 && /* @__PURE__ */ l(V, {
          style: {
            width: "65px"
          },
          border: !0,
          defaultValue: d,
          value: (v = K.find((r) => r.value === d)) == null ? void 0 : v.value,
          disabled: g > 1,
          onChange: (r) => p(r),
          children: K.map((r, R) => /* @__PURE__ */ l(V.Option, {
            value: r.value,
            children: /* @__PURE__ */ l("div", {
              style: {
                width: "72px",
                fontSize: "13px",
                lineHeight: "13px"
              },
              children: r.label
            })
          }, r.value))
        }), /* @__PURE__ */ l(V, {
          options: t.map((r) => ({
            label: r[1],
            value: r[0]
          })),
          style: {
            width: "160px"
          },
          value: n.columnKey,
          placeholder: a("table.chooseColumnName"),
          allowClear: !0,
          onChange: (r) => {
            f({
              ...n,
              columnKey: r
            });
          }
        }), /* @__PURE__ */ l(V, {
          defaultValue: n.operator,
          placeholder: a("table.chooseCondition"),
          style: {
            width: "160px"
          },
          allowClear: !0,
          options: ke.map((r) => ({
            label: Te[r].label,
            value: r
          })),
          onChange: (r) => {
            f({
              ...n,
              operator: r
            });
          }
        }), /* @__PURE__ */ l(Z, {
          style: {
            width: "136px"
          },
          disabled: n.operator && z.includes(n.operator),
          defaultValue: n.filterValue,
          onChange: (r) => {
            f({
              ...n,
              filterValue: r.target.value
            });
          }
        }), /* @__PURE__ */ l(we, {
          disabled: i.length === 1 && $e(i[0]),
          onClick: () => {
            i.length === 1 ? s([$()]) : s(i.filter((r) => r.key !== n.key));
          }
        })]
      }, n.key);
    })
  }), T = /* @__PURE__ */ w(Ce, {
    children: [/* @__PURE__ */ l(ee, {
      style: {
        marginRight: "auto"
      },
      text: a("addItem"),
      icon: /* @__PURE__ */ l(te, {}),
      onClick: () => {
        s(i.concat($()));
      }
    }), /* @__PURE__ */ l(B, {
      onClick: () => {
        s([$()]);
      },
      buttonType: "delete",
      children: a("table.clear")
    }), /* @__PURE__ */ l(B, {
      buttonType: "primary",
      onClick: () => u(!1),
      children: a("ok")
    })]
  });
  return /* @__PURE__ */ l(M, {
    title: a("table.filter"),
    onClose: () => u(!1),
    width: 600,
    scrollable: !0,
    contentMaxHeight: 292,
    content: S,
    footer: T
  });
}
const Ee = function() {
  const e = {
    showRefresh: y,
    showDownload: y,
    showFilter: y,
    columnSetting: y,
    fixedToolbar: y,
    // searchText: StringControl,
    filter: oe({
      stackType: "and",
      filters: []
    }),
    position: le(ve, "below"),
    columnSeparator: D(ae, ","),
    showUpdateButtons: D(y, !0)
  };
  return new A(e, (t, o) => ({
    ...t,
    onFilterChange: (c, u) => {
      o(P("filter", {
        stackType: u,
        filters: c
      }, !1));
    }
  })).setPropertyViewFn((t) => [
    t.position.propertyView({
      label: a("table.position"),
      radioButton: !0
    }),
    t.fixedToolbar.propertyView({
      label: a("table.fixedToolbar"),
      tooltip: a("table.fixedToolbarTooltip")
    }),
    t.showUpdateButtons.propertyView({
      label: a("table.showUpdateButtons")
    }),
    t.showFilter.propertyView({
      label: a("table.showFilter")
    }),
    t.showRefresh.propertyView({
      label: a("table.showRefresh")
    }),
    t.showDownload.propertyView({
      label: a("table.showDownload")
    }),
    t.showDownload.getView() && t.columnSeparator.propertyView({
      label: a("table.columnSeparator"),
      tooltip: a("table.columnSeparatorTooltip")
    }),
    t.columnSetting.propertyView({
      label: a("table.columnSetting")
    })
    /* children.searchText.propertyView({
      label: trans("table.searchText"),
      tooltip: trans("table.searchTextTooltip"),
      placeholder: "{{input1.value}}",
    }), */
  ]).build();
}();
function Se(e) {
  const {
    columns: t,
    setVisible: o
  } = e;
  let c = !0;
  const u = t.map((d) => {
    const p = d.getView(), i = !p.tempHide;
    return i || (c = !1), /* @__PURE__ */ w(H, {
      children: [/* @__PURE__ */ l(q, {
        checked: i,
        onChange: (s) => {
          d.children.tempHide.dispatchChangeValueAction(!s.target.checked);
        }
      }), /* @__PURE__ */ l(N, {
        children: p.title || p.dataIndex
      })]
    }, p.dataIndex);
  });
  return /* @__PURE__ */ l(M, {
    title: a("table.columnShows"),
    onClose: () => o(!1),
    width: 160,
    contentMaxHeight: 150,
    scrollable: !0,
    content: /* @__PURE__ */ l("div", {
      style: {
        display: "flex",
        flexDirection: "column",
        gap: "8px"
      },
      children: u
    }),
    footer: /* @__PURE__ */ l("div", {
      style: {
        display: "flex",
        alignItems: "flex-end",
        justifyContent: "space-between",
        height: "32px"
      },
      children: /* @__PURE__ */ w(H, {
        children: [/* @__PURE__ */ l(q, {
          checked: c,
          onChange: (d) => {
            const p = d.target.checked;
            t.forEach((i) => {
              const s = i.children.tempHide.getView();
              p && s ? i.children.tempHide.dispatchChangeValueAction(!1) : !p && !s && i.children.tempHide.dispatchChangeValueAction(!0);
            });
          }
        }), /* @__PURE__ */ l(N, {
          children: a("table.selectAll")
        })]
      })
    })
  });
}
function j(e) {
  const {
    visible: t,
    setVisible: o,
    Icon: c,
    iconClassName: u,
    content: d
  } = e, p = O(null), i = O(null);
  return /* @__PURE__ */ l(ne, {
    open: t,
    overlayStyle: {
      pointerEvents: "auto"
    },
    overlayInnerStyle: {
      padding: "0"
    },
    content: /* @__PURE__ */ l("div", {
      ref: i,
      tabIndex: -1,
      onBlur: (s) => {
        !s.currentTarget.contains(s.relatedTarget) && p.current !== s.relatedTarget && o(!1);
      },
      children: d
    }),
    children: /* @__PURE__ */ l(c, {
      className: u,
      tabIndex: -1,
      ref: p,
      onBlur: (s) => {
        var f;
        (f = i.current) != null && f.contains(s.relatedTarget) || o(!1);
      },
      onClick: () => o(!t)
    })
  });
}
function Be(e) {
  var I;
  const {
    toolbar: t,
    pagination: o,
    columns: c,
    onRefresh: u,
    onDownload: d,
    hasChange: p,
    onSaveChanges: i,
    onCancelChanges: s,
    onEvent: f
  } = e, [S, T] = F(!1), [n, g] = F(!1), v = c.filter((b) => !b.children.hide.getView()), r = pe(() => v.map((b) => {
    const m = b.getView();
    return [m.dataIndex, m.title || m.dataIndex];
  }), [c]), R = (I = ue(U)) == null ? void 0 : I.theme;
  return /* @__PURE__ */ l(ge, {
    $style: e.$style,
    $theme: R || C,
    $filtered: t.filter.filters.length > 0,
    $position: t.position,
    $fixedToolbar: t.fixedToolbar,
    children: /* @__PURE__ */ w(he, {
      children: [/* @__PURE__ */ w(me, {
        className: "toolbar-icons",
        children: [t.showRefresh && /* @__PURE__ */ l(W, {
          className: "refresh",
          onClick: () => {
            u(), f("refresh");
          }
        }), t.showFilter && /* @__PURE__ */ l(j, {
          visible: S,
          setVisible: T,
          content: /* @__PURE__ */ l(Fe, {
            columnKeyNames: r,
            tableFilter: t.filter,
            onFilterChange: (b, m) => {
              (!k.isEqual(b, t.filter.filters) || m !== t.filter.stackType) && (t.onFilterChange(b, m), f("filterChange"));
            },
            setVisible: (b) => T(b)
          }),
          Icon: G,
          iconClassName: "filter"
        }), t.showDownload && /* @__PURE__ */ l(X, {
          className: "download",
          onClick: d
        }), t.columnSetting && /* @__PURE__ */ l(j, {
          visible: n,
          setVisible: g,
          content: /* @__PURE__ */ l(Se, {
            columns: v,
            setVisible: g
          }),
          Icon: Y,
          iconClassName: "column-setting"
        })]
      }), /* @__PURE__ */ l(_, {
        size: "small",
        itemRender: J,
        ...o,
        onChange: (b, m) => {
          o.onChange && o.onChange(b, m), b !== o.current && f("pageChange");
        }
      }), p && t.showUpdateButtons && /* @__PURE__ */ w(be, {
        children: [/* @__PURE__ */ l(E, {
          onClick: s,
          children: a("cancel")
        }), /* @__PURE__ */ l(E, {
          type: "primary",
          onClick: i,
          children: a("table.saveChanges")
        })]
      })]
    })
  });
}
export {
  Be as TableToolbar,
  Ee as TableToolbarComp,
  Te as tableFilterOperatorMap
};
