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/table/Table/fields/oldRangePicker/Edit/index.tsx
var Edit_exports = {};
__export(Edit_exports, {
  default: () => Edit_default
});
module.exports = __toCommonJS(Edit_exports);
var import_utils = require("@pisell/utils");
var import_dayjs = __toESM(require("dayjs"));
var import_react = __toESM(require("react"));
var import_date_picker = __toESM(require("../../../../../date-picker"));
var import_locales = require("../../../../../../locales");
var { OldRangePicker: RangePicker } = import_date_picker.default;
var defaultFormat = "YYYY-MM-DD HH:mm:ss";
var Edit = (props, ref) => {
  const {
    value,
    onChange,
    onPressEnter,
    onBlur,
    style,
    bordered,
    presets,
    showTime,
    format,
    ...others
  } = props;
  const dayjsVal = (0, import_react.useMemo)(() => {
    if ((0, import_utils.isString)(value)) {
      return (0, import_dayjs.default)(value);
    }
    if ((0, import_utils.isArr)(value)) {
      if (value.some((item) => !item)) {
        return [];
      }
      return value.map((item) => (0, import_dayjs.default)(item));
    }
    return value;
  }, [value]);
  const rangePresets = [
    { label: (0, import_locales.getText)("table-action-range-picker-presets-today"), value: [(0, import_dayjs.default)().startOf("day"), (0, import_dayjs.default)().endOf("day")] },
    {
      label: (0, import_locales.getText)("table-action-range-picker-presets-yesterday"),
      value: [
        (0, import_dayjs.default)().add(-1, "d").startOf("day"),
        (0, import_dayjs.default)().add(-1, "d").endOf("day")
      ]
    },
    {
      label: (0, import_locales.getText)("table-action-range-picker-presets-last-3-day"),
      value: [(0, import_dayjs.default)().add(-3, "d").startOf("day"), (0, import_dayjs.default)().endOf("day")]
    },
    {
      label: (0, import_locales.getText)("table-action-range-picker-presets-last-7-day"),
      value: [(0, import_dayjs.default)().add(-7, "d").startOf("day"), (0, import_dayjs.default)().endOf("day")]
    },
    {
      label: (0, import_locales.getText)("table-action-range-picker-presets-last-14-day"),
      value: [(0, import_dayjs.default)().add(-14, "d").startOf("day"), (0, import_dayjs.default)().endOf("day")]
    },
    {
      label: (0, import_locales.getText)("table-action-range-picker-presets-last-30-day"),
      value: [(0, import_dayjs.default)().add(-30, "d").startOf("day"), (0, import_dayjs.default)().endOf("day")]
    },
    {
      label: (0, import_locales.getText)("table-action-range-picker-presets-last-90-day"),
      value: [(0, import_dayjs.default)().add(-90, "d").startOf("day"), (0, import_dayjs.default)().endOf("day")]
    }
  ];
  const _showTime = (0, import_react.useMemo)(() => {
    if ((0, import_utils.isBoolean)(showTime)) {
      return showTime;
    } else if (typeof showTime === "object") {
      return showTime;
    }
    return true;
  }, [showTime]);
  return /* @__PURE__ */ import_react.default.createElement(
    RangePicker,
    {
      ...others,
      format,
      showTime: _showTime,
      presets: presets || rangePresets,
      ref,
      value: dayjsVal,
      onChange: (date) => {
        onChange == null ? void 0 : onChange(date == null ? void 0 : date.map((item) => {
          var _a;
          return ((_a = item == null ? void 0 : item.format) == null ? void 0 : _a.call(item, defaultFormat)) || null;
        }));
      },
      onPressEnter,
      onBlur,
      style: { width: "220px", ...style },
      bordered,
      onClick: (e) => e.stopPropagation(),
      panelRender: (dom) => {
        return /* @__PURE__ */ import_react.default.createElement("div", { onClick: (e) => e.stopPropagation() }, dom);
      }
    }
  );
};
var Edit_default = (0, import_react.forwardRef)(Edit);
