import React from "react";
import { useSelector } from "react-redux";
import { Navigate } from "react-router-dom";
import { CLINIC_STATUS } from "../constants";
// import { isBSPortal } from "../utils/share";

// eslint-disable-next-line
const withPermission = (Component) => (props) => {
  const companyStatus = useSelector(
    (state) => state?.login?.user?.company?.status
  );
  const { isSuperAdmin } = false;
  // const { isSuperAdmin } = isBSPortal();

  // If the user is a BS Admin, render the component without any checks
  if (isSuperAdmin === true) {
    return <Component {...props} />;
  }

  if (companyStatus !== CLINIC_STATUS.APPROVED) {
    return <Navigate to="/" />;
  }

  return <Component {...props} />;
};

export default withPermission;
