import { 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 { selectReportCenter } from "../../redux/modals/modals.selectors";
import RbacWrapperComponent from "../rbac-wrapper/rbac-wrapper.component";
import ReportCenterModalComponent from "./report-center-modal.component";

const mapStateToProps = createStructuredSelector({
  reportCenterModal: selectReportCenter
});

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

export function ReportCenterModalContainer({ reportCenterModal, toggleModalVisible }) {
  const { t } = useTranslation();

  const { open } = reportCenterModal;

  return (
    <Modal
      open={open}
      title={t("printcenter.labels.reportcentermodal")}
      onOk={() => toggleModalVisible()}
      onCancel={() => toggleModalVisible()}
      cancelButtonProps={{ style: { display: "none" } }}
      destroyOnHidden
      width="80%"
    >
      <RbacWrapperComponent action="shop:reportcenter">
        <ReportCenterModalComponent />
      </RbacWrapperComponent>
    </Modal>
  );
}

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