import { _asyncToGenerator } from "../../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js";
import { useConfig } from "../../../hooks.js";
import React, { useEffect, useState } from "react";
import { Spin } from "antd";
import { locales } from "@pisell/utils";
import { Button as Button$1, Checkbox as Checkbox$1, PisellEmpty, PisellModal } from "@pisell/materials";
import "./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] = useState(null);
	const [loading, setLoading] = useState(false);
	const [disabled, setDisabled] = useState(false);
	const { platform } = useConfig();
	useEffect(() => {
		setDisabled(!isHideCheckout);
	}, [isHideCheckout]);
	/**
	* @title: 获取协议内容
	* @description:
	* @param {string} id
	* @return {*}
	* @Author: WangHan
	* @Date: 2025-04-24 15:16
	*/
	const getPolicy = function() {
		var _ref = _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);
		};
	}();
	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.createElement(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: locales.getText("pisell2.appointment.deposit.close"),
		footer: [/* @__PURE__ */ React.createElement("div", { className: "policy-modal-footer" }, !isHideCheckout ? /* @__PURE__ */ React.createElement(Checkbox$1, {
			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));
			}
		}, locales.getText("pisell2.appointment.policy")) : null, /* @__PURE__ */ React.createElement(Button$1, {
			type: "primary",
			size: "large",
			onClick: isHideCheckout ? onCancel : onConfirm,
			disabled
		}, locales.getText(isHideCheckout ? "pisell2.appointment.deposit.close" : "pisell2.appointment.policy.confirm")))]
	}, /* @__PURE__ */ React.createElement(Spin, {
		style: { minHeight: "200px" },
		spinning: loading
	}, (policy === null || policy === void 0 ? void 0 : policy.content) ? /* @__PURE__ */ React.createElement("div", {
		className: "policy-content",
		dangerouslySetInnerHTML: { __html: policy === null || policy === void 0 ? void 0 : policy.content }
	}) : !loading ? /* @__PURE__ */ React.createElement(PisellEmpty, { description: locales.getText("pisell2.appointment.booking.empty.data") }) : null));
};
//#endregion
export { DepositModal as default };
