const require_runtime = require("../../../../_virtual/_rolldown/runtime.js");
const require_index = require("../../../booking/components/drawer/index.js");
const require_useComponents = require("../../../../hooks/useComponents.js");
let react = require("react");
react = require_runtime.__toESM(react);
let antd = require("antd");
let _pisell_utils = require("@pisell/utils");
require("./index.less");
//#region src/components/schedules/resources/edit/index.tsx
const filterList = [
	"schedule",
	"max_participants",
	"partyroom_package",
	"products",
	"capacity"
];
const ResourcesDetail = ({ onSuccess }, refs) => {
	const formDataEditRef = (0, react.useRef)();
	const [FormDataEdit] = require_useComponents.default({ components: ["FormDataEdit"] });
	const [open, setOpen] = (0, react.useState)(false);
	const [currentResource, setCurrentResource] = (0, react.useState)({});
	const [formId, setFormId] = (0, react.useState)(0);
	const [formRecordId, setFormRecordId] = (0, react.useState)(0);
	const onClose = () => {
		setOpen(false);
	};
	const onOpen = () => {
		setOpen(true);
	};
	(0, react.useImperativeHandle)(refs, () => {
		return { open: (item) => {
			onOpen();
			setCurrentResource(item);
			setFormId(item.form_id);
			setFormRecordId(item.id);
		} };
	});
	const onSubmit = () => {
		var _formDataEditRef$curr;
		console.log("formDataEditRef", formDataEditRef);
		(_formDataEditRef$curr = formDataEditRef.current) === null || _formDataEditRef$curr === void 0 || _formDataEditRef$curr.submit();
	};
	(0, react.useEffect)(() => {
		console.log("formDataEditRef?.current", formDataEditRef === null || formDataEditRef === void 0 ? void 0 : formDataEditRef.current);
	}, [formDataEditRef === null || formDataEditRef === void 0 ? void 0 : formDataEditRef.current]);
	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
	}, FormDataEdit && /* @__PURE__ */ react.default.createElement(react.default.Fragment, null, /* @__PURE__ */ react.default.createElement(FormDataEdit, {
		formId,
		formRecordId,
		filterList,
		onReady: (ref) => {
			formDataEditRef.current = ref;
		},
		formChange: (isSuccess, params) => {
			if (isSuccess) {
				onSuccess === null || onSuccess === void 0 || onSuccess(params);
				onClose();
			}
		}
	}), /* @__PURE__ */ react.default.createElement("div", { className: "pisell-lowcode__schedules-component-resources-detail-footer" }, /* @__PURE__ */ react.default.createElement(antd.Button, {
		className: "footer-btn",
		type: "primary",
		onClick: onSubmit
	}, _pisell_utils.locales.getText("pisell2.text.schedules.save")))));
};
var edit_default = (0, react.forwardRef)(ResourcesDetail);
//#endregion
exports.default = edit_default;
