import * as React from "react";

interface Props {
  roles: string[];
  userRoles: string[];
  permissions: string[];
  userPermissions: string[];
  children: any;
}

export default class MagaProtect extends React.Component<Props> {
  static defaultProps = {
    roles: [],
    permissions: []
  };

  render() {
    const {
      roles,
      userRoles,
      permissions,
      userPermissions,
      children
    } = this.props;
    return (
      roles.some((role: string) => userRoles.includes(role)) &&
      permissions.some((permission: string) =>
        userPermissions.includes(permission)
      ) && <React.Fragment>{children}</React.Fragment>
    );
  }
}
