var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/components/appointmentBooking/deposit/components/PolicyModal/index.tsx
var PolicyModal_exports = {};
__export(PolicyModal_exports, {
  default: () => PolicyModal_default
});
module.exports = __toCommonJS(PolicyModal_exports);
var import_react = __toESM(require("react"));
var import_antd = require("antd");
var import_materials = require("@pisell/materials");
var import_utils = require("@pisell/utils");
var import_index = require("./index.less");
var DepositModal = (props) => {
  const {
    open,
    onCancel,
    item,
    onChange,
    onConfirm,
    isHideCheckout = true,
    depositProtocolRequest
    // 定金协议请求
  } = props;
  const [policy, setPolicy] = (0, import_react.useState)(null);
  const [loading, setLoading] = (0, import_react.useState)(false);
  const [disabled, setDisabled] = (0, import_react.useState)(false);
  (0, import_react.useEffect)(() => {
    setDisabled(!isHideCheckout);
  }, [isHideCheckout]);
  const getPolicy = async (id) => {
    if (!depositProtocolRequest) {
      console.error("depositProtocolRequest is not defined");
      return;
    }
    setLoading(true);
    try {
      const { data } = await (depositProtocolRequest == null ? void 0 : depositProtocolRequest(id));
      setPolicy(data);
      onChange && onChange(data);
    } catch (error) {
      console.log(error);
      onChange && onChange(error);
    } finally {
      setLoading(false);
    }
  };
  (0, import_react.useEffect)(() => {
    if (!open || !(item == null ? void 0 : item.id)) return setPolicy(null);
    getPolicy(item == null ? void 0 : item.id);
  }, [open]);
  return /* @__PURE__ */ import_react.default.createElement(
    import_materials.PisellModal,
    {
      open,
      platform: (0, import_utils.isMobile)() ? "h5" : "pc",
      closable: true,
      bodyStyle: { padding: "24px", minHeight: "300px" },
      destroyOnClose: true,
      title: (item == null ? void 0 : item.title) || (policy == null ? void 0 : policy.title) || void 0,
      onCancel,
      mobileModalHeight: "auto",
      className: "policy-modal-wrap",
      cancelVisible: false,
      okText: import_utils.locales.getText("pisell2.appointment.deposit.close"),
      footer: [
        /* @__PURE__ */ import_react.default.createElement("div", { className: "policy-modal-footer" }, !isHideCheckout ? /* @__PURE__ */ import_react.default.createElement(
          import_materials.Checkbox,
          {
            className: "policy-modal-checkbox",
            onChange: (e) => {
              var _a;
              return setDisabled(!((_a = e.target) == null ? void 0 : _a.checked));
            }
          },
          import_utils.locales.getText("pisell2.appointment.policy")
        ) : null, /* @__PURE__ */ import_react.default.createElement(
          import_materials.Button,
          {
            type: "primary",
            size: "large",
            onClick: isHideCheckout ? onCancel : onConfirm,
            disabled
          },
          import_utils.locales.getText(
            isHideCheckout ? "pisell2.appointment.deposit.close" : "pisell2.appointment.policy.confirm"
          )
        ))
      ]
    },
    /* @__PURE__ */ import_react.default.createElement(import_antd.Spin, { style: { minHeight: "200px" }, spinning: loading }, (policy == null ? void 0 : policy.content) ? /* @__PURE__ */ import_react.default.createElement(
      "div",
      {
        className: "policy-content",
        dangerouslySetInnerHTML: {
          __html: policy == null ? void 0 : policy.content
        }
      }
    ) : !loading ? /* @__PURE__ */ import_react.default.createElement(
      import_materials.PisellEmpty,
      {
        description: import_utils.locales.getText(
          "pisell2.appointment.booking.empty.data"
        )
      }
    ) : null)
  );
};
var PolicyModal_default = DepositModal;
