function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
import React, { useCallback, useMemo, useState } from 'react';
import { Checkbox } from 'antd';
import { PisellText } from '@pisell/materials';
import { locales } from '@pisell/utils';
import { getPunctuationMark } from "../utils";
import useEngineContext from "../../../hooks/useEngineContext";
import PolicyModal from "./components/PolicyModal";
import "./index.less";
var Deposit = function Deposit(props) {
  var _context$engine2;
  var protocols = props.protocols,
    total = props.total,
    title = props.title,
    _props$isAgreePolicy = props.isAgreePolicy,
    isAgreePolicy = _props$isAgreePolicy === void 0 ? true : _props$isAgreePolicy,
    _props$isShowTitle = props.isShowTitle,
    isShowTitle = _props$isShowTitle === void 0 ? true : _props$isShowTitle,
    onChange = props.onChange,
    depositProtocolRequest = props.depositProtocolRequest;
  var context = useEngineContext();
  // 打开协议弹窗
  var _useState = useState(false),
    _useState2 = _slicedToArray(_useState, 2),
    visible = _useState2[0],
    setVisible = _useState2[1];
  var _useState3 = useState(),
    _useState4 = _slicedToArray(_useState3, 2),
    policyItem = _useState4[0],
    setPolicyItem = _useState4[1];
  var isEn = useMemo(function () {
    var _context$engine;
    var _locale = (context === null || context === void 0 || (_context$engine = context.engine) === null || _context$engine === void 0 || (_context$engine = _context$engine.props) === null || _context$engine === void 0 ? void 0 : _context$engine.locale) || 'en';
    return _locale === 'en';
  }, [context === null || context === void 0 || (_context$engine2 = context.engine) === null || _context$engine2 === void 0 || (_context$engine2 = _context$engine2.props) === null || _context$engine2 === void 0 ? void 0 : _context$engine2.locale]);

  /**
   * @title: 协议文案
   * @description: 根据中英文不同显示文案不同
   * @param {*} useMemo
   * @return {*}
   * @Author: wh
   * @Date: 2023-01-30 16:25
   */
  var _policyText = useCallback(function (item, index) {
    if (!item || !(protocols !== null && protocols !== void 0 && protocols.length)) return '';
    return getPunctuationMark(index, protocols.length, isEn);
  }, [protocols]);
  var handleAgreed = function handleAgreed() {
    onChange && onChange(!isAgreePolicy);
  };
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
    className: "appointment-deposit-bottom"
  }, isShowTitle ? /*#__PURE__*/React.createElement("span", {
    className: "title"
  }, title) : null, /*#__PURE__*/React.createElement("div", {
    className: "tip"
  }, isEn ? /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(PisellText.Amount, {
    value: total,
    showCurrencySymbol: true,
    className: "amount"
  }), /*#__PURE__*/React.createElement("span", null, locales.getText('pisell2.appointment.deposit.amount.tip1'))) : /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("span", null, locales.getText('pisell2.appointment.deposit.amount.tip1')), /*#__PURE__*/React.createElement(PisellText.Amount, {
    value: total,
    showCurrencySymbol: true,
    className: "amount"
  }), /*#__PURE__*/React.createElement("span", null, locales.getText('pisell2.appointment.deposit.amount.tip2')))), (protocols === null || protocols === void 0 ? void 0 : protocols.length) > 0 ? /*#__PURE__*/React.createElement("div", {
    className: "checkbox-wrap",
    onClick: function onClick() {
      return handleAgreed();
    }
  }, /*#__PURE__*/React.createElement(Checkbox, {
    checked: isAgreePolicy
  }), /*#__PURE__*/React.createElement("div", {
    className: "policy-box"
  }, /*#__PURE__*/React.createElement("span", null, locales.getText('pisell2.appointment.deposit.agreed')), /*#__PURE__*/React.createElement("div", {
    className: "policy-wrap"
  }, protocols === null || protocols === void 0 ? void 0 : protocols.map(function (item, index) {
    return /*#__PURE__*/React.createElement("span", {
      key: item === null || item === void 0 ? void 0 : item.id,
      onClick: function onClick(e) {
        e.stopPropagation();
        e.preventDefault();
        setPolicyItem(item);
        setVisible(true);
      }
    }, item === null || item === void 0 ? void 0 : item.title, /*#__PURE__*/React.createElement("span", {
      className: "symbol"
    }, _policyText(item, index)));
  })))) : null), /*#__PURE__*/React.createElement(PolicyModal, {
    open: visible,
    onCancel: function onCancel() {
      return setVisible(false);
    },
    item: policyItem,
    depositProtocolRequest: depositProtocolRequest
  }));
};
export default Deposit;