import React from 'react';
import { PisellText } from '@pisell/materials';
import AppointmentDeposit from "../../deposit";
import { useAppointmentBookingContext } from "../../context";
import { locales } from '@pisell/utils';
import "./index.less";
export var DepositContent = function DepositContent(props) {
  var isAgreeDepositPolicy = props.isAgreeDepositPolicy,
    setIsAgreeDepositPolicy = props.setIsAgreeDepositPolicy,
    deposit = props.deposit,
    depositProtocolRequest = props.depositProtocolRequest;
  return /*#__PURE__*/React.createElement("div", {
    className: "appointment-deposit-wrap"
  }, /*#__PURE__*/React.createElement("div", {
    className: "appointment-deposit-top"
  }, /*#__PURE__*/React.createElement("span", null, locales.getText('pisell2.appointment.deposit')), /*#__PURE__*/React.createElement(PisellText.Amount, {
    value: deposit === null || deposit === void 0 ? void 0 : deposit.total,
    showCurrencySymbol: true,
    className: "amount"
  })), /*#__PURE__*/React.createElement(AppointmentDeposit, {
    total: deposit === null || deposit === void 0 ? void 0 : deposit.total,
    protocols: deposit === null || deposit === void 0 ? void 0 : deposit.protocols,
    isAgreePolicy: isAgreeDepositPolicy,
    onChange: function onChange(value) {
      return setIsAgreeDepositPolicy(value);
    },
    depositProtocolRequest: depositProtocolRequest
  }));
};
var Deposit = function Deposit() {
  var _ref = useAppointmentBookingContext(),
    setIsAgreeDepositPolicy = _ref.setIsAgreeDepositPolicy,
    isAgreeDepositPolicy = _ref.isAgreeDepositPolicy,
    summary = _ref.summary,
    appointmentBooking = _ref.appointmentBooking;
  var deposit = summary.deposit;

  // 获取协议方法需要在组件中定义才能传递给子组件，子组件无法获取到context中的方法
  var depositProtocolRequest = function depositProtocolRequest(id) {
    var _appointmentBooking$g;
    return appointmentBooking === null || appointmentBooking === void 0 || (_appointmentBooking$g = appointmentBooking.getProtocol) === null || _appointmentBooking$g === void 0 ? void 0 : _appointmentBooking$g.call(appointmentBooking, id);
  };
  return /*#__PURE__*/React.createElement(DepositContent, {
    isAgreeDepositPolicy: !!isAgreeDepositPolicy,
    setIsAgreeDepositPolicy: setIsAgreeDepositPolicy,
    deposit: deposit,
    depositProtocolRequest: depositProtocolRequest
  });
};
export default Deposit;