import { Button, Modal } from "antd";
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 CardPaymentModalComponent from "./card-payment-modal.component";

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

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

function CardPaymentModalContainer({ cardPaymentModal, toggleModalVisible }) {
  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%"
      destroyOnHidden
    >
      <CardPaymentModalComponent />
    </Modal>
  );
}

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