const require_runtime = require("../../../../_virtual/_rolldown/runtime.js");
const require_index = require("../../products/ProductDetailDrawer/ProductDetail/SchedulesModule/index.js");
const require_index$1 = require("../../products/ProductDetailDrawer/ProductDetail/MaxParticipantsModule/index.js");
const require_serve = require("../serve.js");
const require_index$2 = require("../relationProduct/index.js");
let react = require("react");
react = require_runtime.__toESM(react);
let antd = require("antd");
let _pisell_utils = require("@pisell/utils");
let ahooks = require("ahooks");
require("./index.less");
//#region src/components/schedules/resources/detail/detailContent.tsx
const ResourcesDetailContent = (props, refs) => {
	const [form] = antd.Form.useForm();
	const useSchedule = antd.Form.useWatch("schedule", form);
	const { loading, onClose, drawerContainer, isAutoSetCalendarData, tabKey } = props;
	const [detail, setDetail] = (0, react.useState)({});
	const [isChangeData, setIsChangeData] = (0, react.useState)(false);
	const [canChange, setCanChange] = (0, react.useState)(false);
	(0, react.useImperativeHandle)(refs, () => {
		return {
			setFieldsValue: (data) => {
				setDetail(data);
				form.setFieldsValue(data);
			},
			getIsEdit: () => isChangeData
		};
	});
	const _setResourceRelation = (0, ahooks.useRequest)(require_serve.setResourceRelation, {
		manual: true,
		onSuccess: (res) => {
			if ((res === null || res === void 0 ? void 0 : res.code) === 200) {
				onClose === null || onClose === void 0 || onClose(true);
				antd.message.success(_pisell_utils.locales.getText("pisell2.text.schedules.save-success"));
				setIsChangeData(false);
			}
		}
	});
	const onFinish = (params) => {
		_setResourceRelation.run({
			item_id: detail.form_record_id,
			item_type: "form",
			schedules: params
		});
	};
	return /* @__PURE__ */ react.default.createElement(react.default.Fragment, null, /* @__PURE__ */ react.default.createElement("div", { className: "resources-detail-card product-detail-card" }, /* @__PURE__ */ react.default.createElement(antd.Skeleton, {
		round: true,
		active: true,
		loading
	}, /* @__PURE__ */ react.default.createElement(antd.Form, {
		form,
		onFinish,
		onValuesChange: () => {
			if (canChange) setIsChangeData(true);
		}
	}, /* @__PURE__ */ react.default.createElement(antd.Form.Item, {
		noStyle: true,
		name: "schedule"
	}, /* @__PURE__ */ react.default.createElement(require_index.default, {
		drawerContainer,
		ruleFn: () => isAutoSetCalendarData,
		tabKey
	})), /* @__PURE__ */ react.default.createElement(antd.Form.Item, {
		noStyle: true,
		name: "max_participants"
	}, /* @__PURE__ */ react.default.createElement(require_index$1.default, {
		form,
		useSchedule,
		onData: () => {
			setTimeout(() => {
				setCanChange(true);
			}, 500);
		}
	})), /* @__PURE__ */ react.default.createElement(antd.Form.Item, {
		noStyle: true,
		name: "products"
	}, /* @__PURE__ */ react.default.createElement(require_index$2.default, null))))), /* @__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: form.submit,
		loading: _setResourceRelation.loading,
		disabled: !isChangeData
	}, _pisell_utils.locales.getText("pisell2.text.schedules.save"))));
};
var detailContent_default = (0, react.forwardRef)(ResourcesDetailContent);
//#endregion
exports.default = detailContent_default;
