import Drawer$1 from "../../../booking/components/drawer/index.js";
import useComponents from "../../../../hooks/useComponents.js";
import React, { forwardRef, useEffect, useImperativeHandle, useRef, useState } from "react";
import { Button } from "antd";
import { locales } from "@pisell/utils";
import "./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 = useRef();
	const [FormDataEdit] = useComponents({ components: ["FormDataEdit"] });
	const [open, setOpen] = useState(false);
	const [currentResource, setCurrentResource] = useState({});
	const [formId, setFormId] = useState(0);
	const [formRecordId, setFormRecordId] = useState(0);
	const onClose = () => {
		setOpen(false);
	};
	const onOpen = () => {
		setOpen(true);
	};
	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();
	};
	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.createElement(Drawer$1, {
		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.createElement(React.Fragment, null, /* @__PURE__ */ React.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.createElement("div", { className: "pisell-lowcode__schedules-component-resources-detail-footer" }, /* @__PURE__ */ React.createElement(Button, {
		className: "footer-btn",
		type: "primary",
		onClick: onSubmit
	}, locales.getText("pisell2.text.schedules.save")))));
};
var edit_default = forwardRef(ResourcesDetail);
//#endregion
export { edit_default as default };
