import { b9 as h, a0 as n, c9 as x, c1 as k, fw as z, ea as M, gb as P, V as l, fG as y, P as w, fR as W, gc as G, gd as X, ge as _, fA as J, fB as Q, bE as I, co as U, gf as Y, fs as j, gg as N, gh as T, gi as Z, fW as ee, fX as te, gj as D, gk as A, bv as v, a as oe, bb as le, g0 as B, gl as ne, gm as ae, gn as re, ft as ie } from "./684d2f28.js";
import { useState as F, useMemo as se, useContext as ce, useEffect as ue, useRef as q } from "react";
import "react-dom";
const pe = h.div`
  display: flex;
  align-items: center;
  gap: 8px;
`, de = (e, t, o, c, u) => U`
    background-color: ${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;

    ${u && "z-index: 99;"};
    ${u && c === "below" && "bottom: 0;"};
    ${u && c === "above" && "top: 0;"};

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

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

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

      .filter {
        cursor: pointer;

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

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

      .column-setting {
        cursor: pointer;

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

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

    .ant-pagination-prev,
    .ant-pagination-next {
      path {
        ${e.toolbarText !== y.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)};
    }
  `, be = h.div`
  // overflow: auto;
  ${(e) => e.$style && de(e.$style, e.$filtered, e.$theme, e.$position, e.$fixedToolbar)}
`, fe = h.div`
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-width: max-content;
  height: 21px;
  width: 100%;
`, ge = h.div`
  display: flex;
  align-items: center;
  gap: 8px;
`, he = h(Y)`
  height: 16px;
  width: 16px;

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

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

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

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