const require_runtime = require("../../../../../_virtual/_rolldown/runtime.js");
const require_asyncToGenerator = require("../../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js");
const require_hooks = require("../../../hooks.js");
let react = require("react");
react = require_runtime.__toESM(react);
let antd = require("antd");
let _pisell_utils = require("@pisell/utils");
let _pisell_materials = require("@pisell/materials");
require("./index.less");
//#region src/components/appointmentBooking/deposit/components/PolicyModal/index.tsx
const DepositModal = (props) => {
	const { open, onCancel, item, onChange, onConfirm, isHideCheckout = true, depositProtocolRequest } = props;
	const [policy, setPolicy] = (0, react.useState)(null);
	const [loading, setLoading] = (0, react.useState)(false);
	const [disabled, setDisabled] = (0, react.useState)(false);
	const { platform } = require_hooks.useConfig();
	(0, react.useEffect)(() => {
		setDisabled(!isHideCheckout);
	}, [isHideCheckout]);
	/**
	* @title: 获取协议内容
	* @description:
	* @param {string} id
	* @return {*}
	* @Author: WangHan
	* @Date: 2025-04-24 15:16
	*/
	const getPolicy = function() {
		var _ref = require_asyncToGenerator._asyncToGenerator(function* (id) {
			if (!depositProtocolRequest) {
				console.error("depositProtocolRequest is not defined");
				return;
			}
			setLoading(true);
			try {
				const { data } = yield depositProtocolRequest === null || depositProtocolRequest === void 0 ? void 0 : depositProtocolRequest(id);
				setPolicy(data);
				onChange && onChange(data);
			} catch (error) {
				console.log(error);
				onChange && onChange(error);
			} finally {
				setLoading(false);
			}
		});
		return function getPolicy(_x) {
			return _ref.apply(this, arguments);
		};
	}();
	(0, react.useEffect)(() => {
		if (!open || !(item === null || item === void 0 ? void 0 : item.id)) return setPolicy(null);
		getPolicy(item === null || item === void 0 ? void 0 : item.id);
	}, [open]);
	return /* @__PURE__ */ react.default.createElement(_pisell_materials.PisellModal, {
		open,
		platform,
		closable: true,
		bodyStyle: {
			padding: "24px",
			minHeight: "300px"
		},
		destroyOnClose: true,
		title: (item === null || item === void 0 ? void 0 : item.title) || (policy === null || policy === void 0 ? void 0 : policy.title) || void 0,
		onCancel,
		mobileModalHeight: "auto",
		className: "policy-modal-wrap",
		cancelVisible: false,
		okText: _pisell_utils.locales.getText("pisell2.appointment.deposit.close"),
		footer: [/* @__PURE__ */ react.default.createElement("div", { className: "policy-modal-footer" }, !isHideCheckout ? /* @__PURE__ */ react.default.createElement(_pisell_materials.Checkbox, {
			className: "policy-modal-checkbox",
			onChange: (e) => {
				var _e$target;
				return setDisabled(!((_e$target = e.target) === null || _e$target === void 0 ? void 0 : _e$target.checked));
			}
		}, _pisell_utils.locales.getText("pisell2.appointment.policy")) : null, /* @__PURE__ */ react.default.createElement(_pisell_materials.Button, {
			type: "primary",
			size: "large",
			onClick: isHideCheckout ? onCancel : onConfirm,
			disabled
		}, _pisell_utils.locales.getText(isHideCheckout ? "pisell2.appointment.deposit.close" : "pisell2.appointment.policy.confirm")))]
	}, /* @__PURE__ */ react.default.createElement(antd.Spin, {
		style: { minHeight: "200px" },
		spinning: loading
	}, (policy === null || policy === void 0 ? void 0 : policy.content) ? /* @__PURE__ */ react.default.createElement("div", {
		className: "policy-content",
		dangerouslySetInnerHTML: { __html: policy === null || policy === void 0 ? void 0 : policy.content }
	}) : !loading ? /* @__PURE__ */ react.default.createElement(_pisell_materials.PisellEmpty, { description: _pisell_utils.locales.getText("pisell2.appointment.booking.empty.data") }) : null));
};
//#endregion
exports.default = DepositModal;
