import { Button, Modal } from "antd";
import React from "react";
import { useTranslation } from "react-i18next";
import { connect } from "react-redux";
import { createStructuredSelector } from "reselect";
import { toggleModalVisible } from "../../redux/modals/modals.actions";
import { selectCardPayment } from "../../redux/modals/modals.selectors";
import { selectBodyshop } from "../../redux/user/user.selectors";
import CardPaymentModalComponent from "./card-payment-modal.component.";

const mapStateToProps = createStructuredSelector({
  cardPaymentModal: selectCardPayment,
  bodyshop: selectBodyshop
});

const mapDispatchToProps = (dispatch) => ({
  toggleModalVisible: () => dispatch(toggleModalVisible("cardPayment"))
});

function CardPaymentModalContainer({ cardPaymentModal, toggleModalVisible, bodyshop }) {
  const { open } = cardPaymentModal;
  const { t } = useTranslation();

  const handleCancel = () => {
    toggleModalVisible();
  };

  const handleOK = () => {
    toggleModalVisible();
  };

  return (
    <Modal
      open={open}
      onOk={handleOK}
      onCancel={handleCancel}
      footer={[
        <Button key="back" onClick={handleCancel}>
          {t("job_payments.buttons.goback")}
        </Button>
      ]}
      width="80%"
      destroyOnClose
    >
      <CardPaymentModalComponent />
    </Modal>
  );
}

export default connect(mapStateToProps, mapDispatchToProps)(CardPaymentModalContainer);
