const require_runtime = require("../../../../_virtual/_rolldown/runtime.js");
const require_asyncToGenerator = require("../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js");
const require_index = require("../../../booking/components/drawer/index.js");
const require_useComponents = require("../../../../hooks/useComponents.js");
const require_utils = require("../../utils.js");
const require_utils$1 = require("../utils.js");
let react = require("react");
react = require_runtime.__toESM(react);
let antd = require("antd");
let _pisell_utils = require("@pisell/utils");
let ahooks = require("ahooks");
let _pisell_icon_es_Delete_wght300_24px = require("@pisell/icon/es/Delete_wght300_24px");
_pisell_icon_es_Delete_wght300_24px = require_runtime.__toESM(_pisell_icon_es_Delete_wght300_24px);
require("./index.less");
//#region src/components/schedules/schedules/ScheduleDetailDrawer/index.tsx
/**
* 日程详情抽屉
* @param props
* @constructor
*/
const ScheduleDetailDrawer = (props) => {
	const { onClose, open, getContainer, onDelete, scheduleId, type, onCalendarDataChange } = props;
	const [title, setTitle] = (0, react.useState)("");
	const [isEdit, setEdit] = (0, react.useState)(false);
	const [AllCreateScheduleRefReady, setAllCreateScheduleRefReady] = (0, react.useState)(false);
	const AllCreateScheduleRef = (0, react.useRef)(null);
	const [AllCreateSchedule] = require_useComponents.default({ components: ["AllCreateSchedule"] });
	const edit = (0, ahooks.useMemoizedFn)(require_asyncToGenerator._asyncToGenerator(function* () {
		var _AllCreateScheduleRef, _AllCreateScheduleRef2;
		yield (_AllCreateScheduleRef = AllCreateScheduleRef.current) === null || _AllCreateScheduleRef === void 0 || (_AllCreateScheduleRef2 = _AllCreateScheduleRef.open) === null || _AllCreateScheduleRef2 === void 0 ? void 0 : _AllCreateScheduleRef2.call(_AllCreateScheduleRef, { id: scheduleId });
		const { formValues, depend } = AllCreateScheduleRef.current.getCurrentSetting();
		handleValueChange({}, formValues, depend);
	}));
	(0, react.useEffect)(() => {
		if (open) if (scheduleId) edit();
		else {
			var _AllCreateScheduleRef3, _AllCreateScheduleRef4;
			(_AllCreateScheduleRef3 = AllCreateScheduleRef.current) === null || _AllCreateScheduleRef3 === void 0 || (_AllCreateScheduleRef4 = _AllCreateScheduleRef3.open) === null || _AllCreateScheduleRef4 === void 0 || _AllCreateScheduleRef4.call(_AllCreateScheduleRef3, { type });
		}
		else setTitle("");
	}, [
		open,
		scheduleId,
		edit,
		type
	]);
	const handleValueChange = (0, ahooks.useMemoizedFn)((changedValues, value, others) => {
		var _value$name, _value$name2;
		if (AllCreateScheduleRefReady) setEdit(true);
		setTitle(((_value$name = value.name) === null || _value$name === void 0 ? void 0 : _value$name[_pisell_utils.locales.locale]) || ((_value$name2 = value.name) === null || _value$name2 === void 0 ? void 0 : _value$name2["original"]));
		const data = require_utils$1.calcCalendarDataBySchedule(value, others, type || others.type);
		onCalendarDataChange === null || onCalendarDataChange === void 0 || onCalendarDataChange(data);
	});
	const resetState = () => {
		setEdit(false);
		setAllCreateScheduleRefReady(false);
	};
	const handleClose = function() {
		var _ref = require_asyncToGenerator._asyncToGenerator(function* (data) {
			if (isEdit && !data) {
				if (!(yield require_utils.saveConfirm())) return;
			}
			resetState();
			onClose === null || onClose === void 0 || onClose(data);
		});
		return function handleClose(_x) {
			return _ref.apply(this, arguments);
		};
	}();
	const handleChangeResData = (data) => {
		handleClose(data);
	};
	return /* @__PURE__ */ react.default.createElement(require_index.default, {
		width: "100%",
		placement: "right",
		closable: false,
		titleNoWrap: true,
		onClose: () => {
			handleClose();
		},
		open,
		getContainer: getContainer !== null && getContainer !== void 0 ? getContainer : false,
		title,
		contentWrapperStyle: { boxShadow: "none" },
		destroyOnClose: true
	}, /* @__PURE__ */ react.default.createElement("div", { className: "pisell-lowcode__schedules-detail-wrap" }, /* @__PURE__ */ react.default.createElement("div", { className: "pisell-lowcode__schedules-detail-content" }, AllCreateSchedule && /* @__PURE__ */ react.default.createElement(AllCreateSchedule, {
		showMode: "content",
		ref: AllCreateScheduleRef,
		onSettingChange: handleValueChange,
		onChange: handleChangeResData,
		onData: () => {
			setTimeout(() => {
				setAllCreateScheduleRefReady(true);
			}, 500);
		}
	})), /* @__PURE__ */ react.default.createElement("div", { className: "pisell-lowcode__schedules-detail-footer" }, scheduleId && /* @__PURE__ */ react.default.createElement("div", {
		className: "pisell-lowcode__schedules-detail-footer-delete-wrap",
		onClick: () => {
			var _AllCreateScheduleRef5;
			return onDelete === null || onDelete === void 0 ? void 0 : onDelete((_AllCreateScheduleRef5 = AllCreateScheduleRef.current) === null || _AllCreateScheduleRef5 === void 0 ? void 0 : _AllCreateScheduleRef5.getCurrentDetail());
		}
	}, /* @__PURE__ */ react.default.createElement(_pisell_icon_es_Delete_wght300_24px.default, { className: "pisell-lowcode__schedules-detail-footer-delete-icon" })), /* @__PURE__ */ react.default.createElement(antd.Button, {
		type: "primary",
		className: "pisell-lowcode__schedules-detail-footer-save",
		onClick: () => {
			var _AllCreateScheduleRef6;
			(_AllCreateScheduleRef6 = AllCreateScheduleRef.current) === null || _AllCreateScheduleRef6 === void 0 || _AllCreateScheduleRef6.submit();
		},
		disabled: !isEdit
	}, _pisell_utils.locales.getText("pisell2.text.schedules.save")))));
};
//#endregion
exports.default = ScheduleDetailDrawer;
