const require_runtime = require("../../../../_virtual/_rolldown/runtime.js");
const require_objectSpread2 = require("../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.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_model = require("../../model.js");
const require_utils = require("../../utils.js");
const require_serve = require("../serve.js");
const require_detailContent = require("./detailContent.js");
let react = require("react");
react = require_runtime.__toESM(react);
let ahooks = require("ahooks");
require("./index.less");
//#region src/components/schedules/resources/detail/index.tsx
const ResourcesDetail = (props, refs) => {
	const { onSuccess } = props;
	const { state, dispatch } = (0, react.useContext)(require_model.Context);
	const { resources } = state;
	const cacheResource = resources === null || resources === void 0 ? void 0 : resources.cacheResource;
	const tabKey = state === null || state === void 0 ? void 0 : state.tabKey;
	const detailContentRef = (0, react.useRef)(null);
	const [open, setOpen] = (0, react.useState)(false);
	const [currentResource, setCurrentResource] = (0, react.useState)({});
	const [detail, setDetail] = (0, react.useState)({});
	const onClose = function() {
		var _ref = require_asyncToGenerator._asyncToGenerator(function* (isSuccess) {
			if (isSuccess) onSuccess === null || onSuccess === void 0 || onSuccess(isSuccess);
			if (!isSuccess && detailContentRef.current.getIsEdit()) {
				if (!(yield require_utils.saveConfirm())) return;
			}
			setOpen(false);
			if (cacheResource) dispatch({
				type: "setState",
				payload: {
					tabKey: "products",
					resources: require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, state.resources), {}, { cacheResource: null })
				}
			});
		});
		return function onClose(_x) {
			return _ref.apply(this, arguments);
		};
	}();
	(0, react.useEffect)(() => {
		if (tabKey !== "resources" && tabKey !== "openHours" || tabKey === "resources" && !open) dispatch({
			type: "setCalendar",
			payload: { isEdit: false }
		});
	}, [tabKey, open]);
	const onOpen = () => {
		setOpen(true);
	};
	const _getResourceRelation = (0, ahooks.useRequest)(require_serve.getResourceRelation, {
		manual: true,
		onSuccess: (res) => {
			var _detailContentRef$cur, _detailContentRef$cur2;
			const data = (res === null || res === void 0 ? void 0 : res.data) || {};
			setDetail(data);
			detailContentRef === null || detailContentRef === void 0 || (_detailContentRef$cur = detailContentRef.current) === null || _detailContentRef$cur === void 0 || (_detailContentRef$cur2 = _detailContentRef$cur.setFieldsValue) === null || _detailContentRef$cur2 === void 0 || _detailContentRef$cur2.call(_detailContentRef$cur, data);
		}
	});
	(0, react.useImperativeHandle)(refs, () => {
		return { open: (item) => {
			onOpen();
			setCurrentResource(item);
			_getResourceRelation.run({
				item_id: item.id,
				item_type: "form"
			});
		} };
	});
	return /* @__PURE__ */ react.default.createElement(require_index.default, {
		width: "100%",
		placement: "right",
		open,
		getContainer: document.querySelector(".pisell-lowcode__schedules-component-resources") || document.body,
		titleNoWrap: true,
		headerStyle: { display: "none" },
		onClose: () => {
			onClose(false);
		},
		bodyStyle: { padding: 0 },
		title: currentResource === null || currentResource === void 0 ? void 0 : currentResource.title,
		rootStyle: { position: "absolute" },
		contentWrapperStyle: { boxShadow: "none" },
		destroyOnClose: true
	}, /* @__PURE__ */ react.default.createElement("div", { className: "pisell-lowcode__schedules-component-resources-detail" }, /* @__PURE__ */ react.default.createElement(require_detailContent.default, {
		tabKey,
		isAutoSetCalendarData: tabKey === "resources" && open,
		ref: detailContentRef,
		loading: _getResourceRelation.loading,
		onClose,
		drawerContainer: document.querySelector(".pisell-lowcode__schedules-component-resources")
	})));
};
var detail_default = (0, react.forwardRef)(ResourcesDetail);
//#endregion
exports.default = detail_default;
