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/FilterItem/index.tsx
var FilterItem_exports = {};
__export(FilterItem_exports, {
  default: () => FilterItem_default
});
module.exports = __toCommonJS(FilterItem_exports);
var import_react = __toESM(require("react"));
var import_antd = require("antd");
var import_dayjs = __toESM(require("dayjs"));
var import_fields = require("../../../table/Table/fields");
var import_pisellSingleLineText = require("../../../pisellSingleLineText");
var import_pisellLongText = require("../../../pisellLongText");
var import_pisellEmail = require("../../../pisellEmail");
var import_pisellPhone = require("../../../pisellPhone");
var import_pisellUrl = require("../../../pisellUrl");
var import_pisellNumber = require("../../../pisellNumber");
var import_pisellCurrency = require("../../../pisellCurrency");
var import_pisellPercent = require("../../../pisellPercent");
var import_pisellRating = require("../../../pisellRating");
var import_pisellSingleSelect = require("../../../pisellSingleSelect");
var import_pisellMultipleSelect = require("../../../pisellMultipleSelect");
var import_locales = require("../../../../locales");
var import_AsyncOptionsSelectWrapper = __toESM(require("./AsyncOptionsSelectWrapper"));
var import_index = require("./index.less");
var { RangePicker } = import_antd.DatePicker;
var PISELL_FIELD_TYPE_MAP = {
  singleLineText: import_pisellSingleLineText.PisellSingleLineText,
  longText: import_pisellLongText.PisellLongText,
  email: import_pisellEmail.PisellEmail,
  phone: import_pisellPhone.PisellPhone,
  url: import_pisellUrl.PisellUrl,
  number: import_pisellNumber.PisellNumber,
  currency: import_pisellCurrency.PisellCurrency,
  percent: import_pisellPercent.PisellPercent,
  rating: import_pisellRating.PisellRating,
  singleSelect: import_pisellSingleSelect.PisellSingleSelect,
  multipleSelect: import_pisellMultipleSelect.PisellMultipleSelect
};
var FILTER_TYPE_TO_FIELD = {
  single: "select",
  input: "text",
  datePicker: "date",
  rangePicker: "rangePicker",
  search: "search"
};
function toRangePickerValue(val) {
  if (val == null) return null;
  if (Array.isArray(val) && val.length >= 2) {
    const start = val[0] ? import_dayjs.default.isDayjs(val[0]) ? val[0] : (0, import_dayjs.default)(val[0]) : null;
    const end = val[1] ? import_dayjs.default.isDayjs(val[1]) ? val[1] : (0, import_dayjs.default)(val[1]) : null;
    if (start && end) return [start, end];
  }
  return null;
}
var AntdRangePickerWithValue = import_react.default.forwardRef(function AntdRangePickerWithValue2({ value, onChange, ...rest }, ref) {
  const normalized = toRangePickerValue(value);
  return /* @__PURE__ */ import_react.default.createElement(
    RangePicker,
    {
      ...rest,
      ref,
      placeholder: [
        (0, import_locales.getText)("table-action-range-picker-placeholder-start"),
        (0, import_locales.getText)("table-action-range-picker-placeholder-end")
      ],
      value: normalized,
      onChange: (dates) => onChange == null ? void 0 : onChange(dates ?? void 0)
    }
  );
});
var FilterItem = (props) => {
  const { label, type, name, other, isHidden, props: itemProps } = props;
  const fieldTypeFromColumn = other == null ? void 0 : other.fieldType;
  const PisellCom = fieldTypeFromColumn ? PISELL_FIELD_TYPE_MAP[fieldTypeFromColumn] : void 0;
  if (type === "custom") {
    const CustomComponent = other == null ? void 0 : other.component;
    if (!CustomComponent) return null;
    const componentProps2 = { ...itemProps || {}, ...other || {} };
    delete componentProps2.component;
    return /* @__PURE__ */ import_react.default.createElement(
      import_antd.Form.Item,
      {
        label,
        name,
        hidden: isHidden,
        ...(other == null ? void 0 : other.formItemProps) || {}
      },
      /* @__PURE__ */ import_react.default.createElement(CustomComponent, { ...componentProps2 })
    );
  }
  if (type === "rangePickerNew") {
    const componentProps2 = {
      ...itemProps || {},
      ...other || {},
      prefixCls: "pisell-lowcode"
    };
    return /* @__PURE__ */ import_react.default.createElement(
      import_antd.Form.Item,
      {
        label,
        name,
        ...(other == null ? void 0 : other.formItemProps) || {},
        hidden: isHidden,
        className: "pisell-lowcode-range-picker-wrap"
      },
      /* @__PURE__ */ import_react.default.createElement(AntdRangePickerWithValue, { ...componentProps2 })
    );
  }
  const Com = (0, import_react.useMemo)(() => {
    var _a;
    if (PisellCom) return PisellCom;
    const fieldType = FILTER_TYPE_TO_FIELD[type] ?? type;
    return (_a = import_fields.fieldMaps[fieldType]) == null ? void 0 : _a.edit;
  }, [type, PisellCom]);
  if (!Com) {
    return null;
  }
  const isPisell = Boolean(PisellCom);
  const componentProps = {
    ...itemProps || {},
    ...other || {},
    ...isPisell ? { mode: "edit" } : {}
  };
  const getOptions = componentProps.getOptions ?? (other == null ? void 0 : other.getOptions);
  const useAsyncOptions = isPisell && typeof getOptions === "function" && (fieldTypeFromColumn === "singleSelect" || fieldTypeFromColumn === "multipleSelect");
  if (useAsyncOptions && fieldTypeFromColumn) {
    const { getOptions: _go, ...restProps } = componentProps;
    return /* @__PURE__ */ import_react.default.createElement(
      import_antd.Form.Item,
      {
        label,
        name,
        ...(other == null ? void 0 : other.formItemProps) || {},
        hidden: isHidden
      },
      /* @__PURE__ */ import_react.default.createElement(
        import_AsyncOptionsSelectWrapper.default,
        {
          getOptions,
          fieldType: fieldTypeFromColumn,
          ...restProps
        }
      )
    );
  }
  return /* @__PURE__ */ import_react.default.createElement(
    import_antd.Form.Item,
    {
      label,
      name,
      ...(other == null ? void 0 : other.formItemProps) || {},
      hidden: isHidden
    },
    /* @__PURE__ */ import_react.default.createElement(Com, { ...componentProps })
  );
};
var FilterItem_default = FilterItem;
