import { getText } from "../../../../../../locales/index.js";
import { _objectSpread2 } from "../../../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js";
import { _objectWithoutProperties } from "../../../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectWithoutProperties.js";
import DatePicker from "../../../../../date-picker/index.js";
import React, { forwardRef, useMemo } from "react";
import { isArr, isBoolean, isString } from "@pisell/utils";
import dayjs from "dayjs";
//#region src/components/table/Table/fields/oldRangePicker/Edit/index.tsx
const _excluded = [
	"value",
	"onChange",
	"onPressEnter",
	"onBlur",
	"style",
	"bordered",
	"presets",
	"showTime",
	"format"
];
const { OldRangePicker: RangePicker } = DatePicker;
const defaultFormat = "YYYY-MM-DD HH:mm:ss";
const Edit = (props, ref) => {
	const { value, onChange, onPressEnter, onBlur, style, bordered, presets, showTime, format } = props, others = _objectWithoutProperties(props, _excluded);
	const dayjsVal = useMemo(() => {
		if (isString(value)) return dayjs(value);
		if (isArr(value)) {
			if (value.some((item) => !item)) return [];
			return value.map((item) => dayjs(item));
		}
		return value;
	}, [value]);
	const rangePresets = [
		{
			label: getText("table-action-range-picker-presets-today"),
			value: [dayjs().startOf("day"), dayjs().endOf("day")]
		},
		{
			label: getText("table-action-range-picker-presets-yesterday"),
			value: [dayjs().add(-1, "d").startOf("day"), dayjs().add(-1, "d").endOf("day")]
		},
		{
			label: getText("table-action-range-picker-presets-last-3-day"),
			value: [dayjs().add(-3, "d").startOf("day"), dayjs().endOf("day")]
		},
		{
			label: getText("table-action-range-picker-presets-last-7-day"),
			value: [dayjs().add(-7, "d").startOf("day"), dayjs().endOf("day")]
		},
		{
			label: getText("table-action-range-picker-presets-last-14-day"),
			value: [dayjs().add(-14, "d").startOf("day"), dayjs().endOf("day")]
		},
		{
			label: getText("table-action-range-picker-presets-last-30-day"),
			value: [dayjs().add(-30, "d").startOf("day"), dayjs().endOf("day")]
		},
		{
			label: getText("table-action-range-picker-presets-last-90-day"),
			value: [dayjs().add(-90, "d").startOf("day"), dayjs().endOf("day")]
		}
	];
	const _showTime = useMemo(() => {
		if (isBoolean(showTime)) return showTime;
		else if (typeof showTime === "object") return showTime;
		return true;
	}, [showTime]);
	return /* @__PURE__ */ React.createElement(RangePicker, _objectSpread2(_objectSpread2({}, others), {}, {
		format,
		showTime: _showTime,
		presets: presets || rangePresets,
		ref,
		value: dayjsVal,
		onChange: (date) => {
			onChange === null || onChange === void 0 || onChange(date === null || date === void 0 ? void 0 : date.map((item) => {
				var _item$format;
				return (item === null || item === void 0 || (_item$format = item.format) === null || _item$format === void 0 ? void 0 : _item$format.call(item, defaultFormat)) || null;
			}));
		},
		onPressEnter,
		onBlur,
		style: _objectSpread2({ width: "220px" }, style),
		bordered,
		onClick: (e) => e.stopPropagation(),
		panelRender: (dom) => {
			return /* @__PURE__ */ React.createElement("div", { onClick: (e) => e.stopPropagation() }, dom);
		}
	}));
};
var Edit_default = forwardRef(Edit);
//#endregion
export { Edit_default as default };
