const require_runtime = require("../../../../_virtual/_rolldown/runtime.js");
const require_objectSpread2 = require("../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js");
const require_usePisellConfig = require("../../../pisell-config-provider/hooks/usePisellConfig.js");
const require_utils = require("../../dataSourceForm/utils.js");
const require_utils$1 = require("../../../table/Table/utils.js");
const require_index = require("../../../select-time/index.js");
const require_ReadPretty = require("./ReadPretty.js");
let react = require("react");
react = require_runtime.__toESM(react);
let _pisell_utils = require("@pisell/utils");
let antd = require("antd");
let _ant_design_icons = require("@ant-design/icons");
let classnames = require("classnames");
classnames = require_runtime.__toESM(classnames);
let dayjs = require("dayjs");
dayjs = require_runtime.__toESM(dayjs);
require("./style.less");
//#region src/components/dataSourceComponents/fields/TimePicker/WithMode.tsx
const TimePicker = (props) => {
	const config = require_usePisellConfig.default();
	const { format = "HH:mm", className, size = "middle", value, onChange, disabled, placeholder, defaultValue: propsDefaultValue } = props;
	const normalizedValue = (0, react.useMemo)(() => {
		if (!value) return void 0;
		if (dayjs.default.isDayjs(value)) return value;
		try {
			return (0, dayjs.default)(String(value), format);
		} catch (_unused) {
			return;
		}
	}, [value, format]);
	const defaultValue = (0, react.useMemo)(() => {
		if (!propsDefaultValue) return void 0;
		if (dayjs.default.isDayjs(propsDefaultValue)) return propsDefaultValue;
		try {
			return (0, dayjs.default)(String(propsDefaultValue), format);
		} catch (_unused2) {
			return;
		}
	}, [propsDefaultValue, format]);
	if (config.platform === "h5") {
		const sizeClassMap = {
			large: "pisell-h5-time-picker-lg",
			middle: "",
			small: "pisell-h5-time-picker-sm"
		};
		const timeFormat = (0, _pisell_utils.isString)(format) ? format : "HH:mm:ss";
		const stepValue = timeFormat.includes("ss") ? 1 : 60;
		return /* @__PURE__ */ react.default.createElement("div", { className: "pisell-h5-time-picker-wrapper" }, /* @__PURE__ */ react.default.createElement("input", {
			type: "time",
			step: stepValue,
			value: (normalizedValue === null || normalizedValue === void 0 ? void 0 : normalizedValue.format(timeFormat)) || "",
			onChange: (e) => {
				const timeString = e.target.value;
				if (onChange && timeString) {
					const timeValue = (0, dayjs.default)(`${(0, dayjs.default)().format("YYYY-MM-DD")} ${timeString}`);
					onChange(timeValue, timeValue.format(timeFormat));
				}
			},
			disabled,
			placeholder,
			className: (0, classnames.default)("pisell-h5-time-picker", sizeClassMap[size], className)
		}), /* @__PURE__ */ react.default.createElement(_ant_design_icons.ClockCircleOutlined, { className: "pisell-h5-time-picker-suffix" }));
	}
	if (format === "HH:mm") return /* @__PURE__ */ react.default.createElement(require_index.default, {
		value: normalizedValue === null || normalizedValue === void 0 ? void 0 : normalizedValue.format("HH:mm"),
		onChange: (timeString) => {
			if (onChange) onChange(timeString ? (0, dayjs.default)(`${(0, dayjs.default)().format("YYYY-MM-DD")} ${timeString}`) : null, timeString || "");
		},
		timePickerProps: require_objectSpread2._objectSpread2({ format }, require_utils$1.omit(props, ["value", "defaultValue"]) || {}),
		popoverProps: {},
		timeProps: {},
		slice: 15
	});
	return /* @__PURE__ */ react.default.createElement(antd.TimePicker, require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, props), {}, {
		value: normalizedValue,
		defaultValue
	}));
};
const TimePickerWithMode = require_utils.withMode(TimePicker, require_ReadPretty.default);
//#endregion
exports.default = TimePickerWithMode;
