import dayjs from "../../util/day";
import React from "react";
import { connect } from "react-redux";
import { createStructuredSelector } from "reselect";
import { selectBodyshop } from "../../redux/user/user.selectors";
import { Alert } from "antd";

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

function FeatureWrapper({ bodyshop, featureName, noauth, children, ...restProps }) {
  if (HasFeatureAccess({ featureName, bodyshop })) return children;

  return (
    noauth || (
      <Alert
        message={
          "You do not currently have access to this feature. Please reach out to support at support@thinkimex.com or 604-839-3431 to subscribe."
        }
        type="warning"
      />
    )
  );
}

export function HasFeatureAccess({ featureName, bodyshop }) {
  return bodyshop?.features?.allAccess || dayjs(bodyshop?.features[featureName]).isAfter(dayjs());
}

export default connect(mapStateToProps, null)(FeatureWrapper);

/* 
dashboard
production-board
scoreboard
csi
tech-console
mobile-imaging
*/
