var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/components/filter/components/Dropdown/index.tsx
var Dropdown_exports = {};
__export(Dropdown_exports, {
  default: () => Dropdown_default
});
module.exports = __toCommonJS(Dropdown_exports);
var import_react = __toESM(require("react"));
var import_DotsSix = __toESM(require("@pisell/icon/es/DotsSix"));
var import_HelpCircle = __toESM(require("@pisell/icon/es/HelpCircle"));
var import_classnames = __toESM(require("classnames"));
var import_index = require("./index.less");
var import_FilterItem = __toESM(require("../FilterItem"));
var import_antd = require("antd");
var import_MultipleContainersSortList = __toESM(require("../../../MultipleContainersSortList"));
var import_locales = require("../../../../locales");
var DragItem = import_react.default.forwardRef((props, ref) => {
  const { attributes, listeners, setActivatorNodeRef, style } = props;
  return /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      ref,
      ...attributes,
      style,
      className: "filter-dropdown-drag-item"
    },
    /* @__PURE__ */ import_react.default.createElement("div", null, /* @__PURE__ */ import_react.default.createElement(
      import_DotsSix.default,
      {
        ref: setActivatorNodeRef,
        ...listeners,
        style: {
          ...listeners.style || {},
          touchAction: "none"
        },
        className: "dots-six-icon"
      }
    )),
    /* @__PURE__ */ import_react.default.createElement("div", { className: "filter-dropdown-drag-item-right" }, props.children)
  );
});
var Dropdown = (props) => {
  const {
    quickFilter,
    hiddenQuickFilter,
    hiddenOtherFilter,
    otherFilter,
    onChange,
    quickFilterMaxLength,
    formFiltersPrefix,
    onOpen,
    onClose,
    renderItem,
    phoneLayout,
    className
  } = props;
  const list = (0, import_react.useMemo)(() => {
    const _list = {};
    if (!hiddenQuickFilter) {
      _list.quickFilter = quickFilter || [];
    }
    if (!hiddenOtherFilter) {
      _list.otherFilter = otherFilter || [];
    }
    return _list;
  }, [quickFilter, otherFilter, hiddenQuickFilter, hiddenOtherFilter]);
  const handleSortChange = (list2) => {
    onChange == null ? void 0 : onChange(list2);
  };
  const titleMap = {
    quickFilter: (0, import_locales.getText)("table-action-filter-quick-filter"),
    otherFilter: (0, import_locales.getText)("table-action-filter-other-filter")
  };
  const tooltipMap = {
    quickFilter: (0, import_locales.getText)("table-action-filter-quick-filter-tip"),
    otherFilter: (0, import_locales.getText)("table-action-filter-other-filter-tip")
  };
  const getTooltipTitle = (0, import_react.useCallback)(
    (id) => {
      const fn = tooltipMap[id];
      return typeof fn === "function" ? fn(quickFilterMaxLength) : fn;
    },
    [quickFilterMaxLength]
  );
  const renderContainer = (0, import_react.useCallback)(
    ({ children, ref, id }) => {
      return /* @__PURE__ */ import_react.default.createElement("div", { className: "filter-dropdown-container-wrap" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "filter-dropdown-container-title-wrap" }, /* @__PURE__ */ import_react.default.createElement("span", { className: "filter-dropdown-container-title" }, titleMap[id]), /* @__PURE__ */ import_react.default.createElement(import_antd.Tooltip, { title: getTooltipTitle(id) }, /* @__PURE__ */ import_react.default.createElement(import_HelpCircle.default, { className: "filter-dropdown-container-icon-help" }))), /* @__PURE__ */ import_react.default.createElement("div", { ref, className: "filter-dropdown-container-filter-wrap" }, children));
    },
    [quickFilterMaxLength, getTooltipTitle]
  );
  return /* @__PURE__ */ import_react.default.createElement("div", { className: (0, import_classnames.default)("filter-dropdown-wrap", className) }, /* @__PURE__ */ import_react.default.createElement("div", { className: "filter-dropdown-wrap-content" }, /* @__PURE__ */ import_react.default.createElement(
    import_MultipleContainersSortList.default,
    {
      list,
      rowKey: "name",
      renderContainer,
      onChange: handleSortChange,
      quickFilterMaxLength
    },
    ({
      item,
      index,
      style,
      props: props2,
      attributes,
      setActivatorNodeRef,
      listeners
    }) => {
      var _a, _b;
      const name = [formFiltersPrefix, (_a = item.name) == null ? void 0 : _a.toString()].filter(
        Boolean
      );
      return /* @__PURE__ */ import_react.default.createElement(
        DragItem,
        {
          ...props2,
          index,
          attributes,
          setActivatorNodeRef,
          listeners,
          style
        },
        renderItem ? renderItem(item, {
          onOpen,
          onClose
        }) : /* @__PURE__ */ import_react.default.createElement(
          import_FilterItem.default,
          {
            key: name.join("-"),
            phoneLayout,
            name,
            label: item.label,
            type: item.type,
            other: {
              ...item.other,
              onOpen: () => {
                var _a2, _b2;
                (_b2 = (_a2 = item.other) == null ? void 0 : _a2.onOpen) == null ? void 0 : _b2.call(_a2);
                onOpen == null ? void 0 : onOpen();
              },
              onClose: () => {
                var _a2, _b2;
                (_b2 = (_a2 = item.other) == null ? void 0 : _a2.onClose) == null ? void 0 : _b2.call(_a2);
                onClose == null ? void 0 : onClose();
              },
              style: {
                ...((_b = item.other) == null ? void 0 : _b.style) || {},
                width: "100%"
              }
            },
            props: item.props
          }
        )
      );
    }
  )));
};
var Dropdown_default = Dropdown;
