import SchedulesModule from "../../products/ProductDetailDrawer/ProductDetail/SchedulesModule/index.js";
import MaxParticipantsModule from "../../products/ProductDetailDrawer/ProductDetail/MaxParticipantsModule/index.js";
import { setResourceRelation } from "../serve.js";
import RelationProduct from "../relationProduct/index.js";
import React, { forwardRef, useImperativeHandle, useState } from "react";
import { Button, Form, Skeleton, message } from "antd";
import { locales } from "@pisell/utils";
import { useRequest } from "ahooks";
import "./index.less";
//#region src/components/schedules/resources/detail/detailContent.tsx
const ResourcesDetailContent = (props, refs) => {
	const [form] = Form.useForm();
	const useSchedule = Form.useWatch("schedule", form);
	const { loading, onClose, drawerContainer, isAutoSetCalendarData, tabKey } = props;
	const [detail, setDetail] = useState({});
	const [isChangeData, setIsChangeData] = useState(false);
	const [canChange, setCanChange] = useState(false);
	useImperativeHandle(refs, () => {
		return {
			setFieldsValue: (data) => {
				setDetail(data);
				form.setFieldsValue(data);
			},
			getIsEdit: () => isChangeData
		};
	});
	const _setResourceRelation = useRequest(setResourceRelation, {
		manual: true,
		onSuccess: (res) => {
			if ((res === null || res === void 0 ? void 0 : res.code) === 200) {
				onClose === null || onClose === void 0 || onClose(true);
				message.success(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.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("div", { className: "resources-detail-card product-detail-card" }, /* @__PURE__ */ React.createElement(Skeleton, {
		round: true,
		active: true,
		loading
	}, /* @__PURE__ */ React.createElement(Form, {
		form,
		onFinish,
		onValuesChange: () => {
			if (canChange) setIsChangeData(true);
		}
	}, /* @__PURE__ */ React.createElement(Form.Item, {
		noStyle: true,
		name: "schedule"
	}, /* @__PURE__ */ React.createElement(SchedulesModule, {
		drawerContainer,
		ruleFn: () => isAutoSetCalendarData,
		tabKey
	})), /* @__PURE__ */ React.createElement(Form.Item, {
		noStyle: true,
		name: "max_participants"
	}, /* @__PURE__ */ React.createElement(MaxParticipantsModule, {
		form,
		useSchedule,
		onData: () => {
			setTimeout(() => {
				setCanChange(true);
			}, 500);
		}
	})), /* @__PURE__ */ React.createElement(Form.Item, {
		noStyle: true,
		name: "products"
	}, /* @__PURE__ */ React.createElement(RelationProduct, null))))), /* @__PURE__ */ React.createElement("div", { className: "pisell-lowcode__schedules-component-resources-detail-footer" }, /* @__PURE__ */ React.createElement(Button, {
		className: "footer-btn",
		type: "primary",
		onClick: form.submit,
		loading: _setResourceRelation.loading,
		disabled: !isChangeData
	}, locales.getText("pisell2.text.schedules.save"))));
};
var detailContent_default = forwardRef(ResourcesDetailContent);
//#endregion
export { detailContent_default as default };
