const require_runtime = require("../../../../_virtual/_rolldown/runtime.js");
const require_objectSpread2 = require("../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js");
const require_utils = require("../../utils.js");
const require_model = require("../model.js");
let dayjs = require("dayjs");
dayjs = require_runtime.__toESM(dayjs);
let react = require("react");
react = require_runtime.__toESM(react);
let antd = require("antd");
let _pisell_icon_es_ChevronDown = require("@pisell/icon/es/ChevronDown");
_pisell_icon_es_ChevronDown = require_runtime.__toESM(_pisell_icon_es_ChevronDown);
require("./index.less");
//#region src/components/booking/info/date/index.tsx
const getLastService = (list, index) => {
	if (index === 0) return null;
	return list[index - 1];
};
const updateServiceDate = (services, date, isTime) => {
	let _list = [];
	for (let i = 0; i < services.length; i++) {
		let d = services[i];
		let _extend = require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, d._extend), {}, { start_date: date });
		if (isTime) {
			let newDate = date;
			let newTime = date.format("HH:mm");
			let lastService = getLastService(_list, i);
			if (lastService) {
				newDate = lastService._extend.endDate;
				newTime = lastService._extend.endDate.format("HH:mm");
			}
			_extend = require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, _extend), {}, {
				start_date: newDate,
				start_time: newTime
			});
		}
		const { startDate, endDate } = require_utils.getServiceTimes({ _extend });
		_list.push(require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, d), {}, { _extend: require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, _extend), {}, {
			startDate,
			endDate
		}) }));
	}
	return _list;
};
const DateCom = () => {
	const modal = (0, react.useContext)(require_model.Context);
	const disabledDate = (current) => {
		return current && current < (0, dayjs.default)().startOf("day");
	};
	const dateChange = (e) => {
		if (modal.state.disabledEdit) return;
		modal.dispatch({
			type: "setDate",
			payload: {
				value: e,
				edit: true
			}
		});
		setTimeout(() => {
			var _modal$state$service;
			if ((_modal$state$service = modal.state.service) === null || _modal$state$service === void 0 || (_modal$state$service = _modal$state$service.value) === null || _modal$state$service === void 0 ? void 0 : _modal$state$service.length) {
				var _modal$state$service2;
				let _list = updateServiceDate((_modal$state$service2 = modal.state.service) === null || _modal$state$service2 === void 0 ? void 0 : _modal$state$service2.value, e, false);
				modal.dispatch({
					type: "setService",
					payload: {
						value: _list,
						edit: true
					}
				});
			}
		}, 100);
	};
	return /* @__PURE__ */ react.default.createElement(react.default.Fragment, null, /* @__PURE__ */ react.default.createElement("div", { className: "pisell-lowcode__booking-body-select-date" }, /* @__PURE__ */ react.default.createElement(antd.DatePicker, {
		inputReadOnly: true,
		allowClear: false,
		size: "large",
		style: {
			width: "100%",
			padding: 0
		},
		bordered: false,
		suffixIcon: !modal.state.disabledEdit ? /* @__PURE__ */ react.default.createElement(_pisell_icon_es_ChevronDown.default, null) : null,
		disabledDate,
		format: modal.state.locale === "en" ? "dddd, DD MMM YYYY" : "YYYY年MM月DD日",
		value: modal.state.date.value,
		onChange: dateChange,
		disabled: modal.state.disabledEdit
	})));
};
//#endregion
exports.default = DateCom;
exports.updateServiceDate = updateServiceDate;
