import React, { useMemo } from 'react';

import { Result } from 'antd';

import check from './CheckPermissions';

const Authorized =  ({
  children,
  authority,
  flatMenu,
  noMatch = (
    <Result
      status="403"
      title="403"
      subTitle="Sorry, you are not authorized to access this page."
    />
  ),
}) => {
  const childrenRender = typeof children === 'undefined' ? null : children;
  const dom = useMemo( () =>  check(authority, flatMenu, childrenRender, noMatch), []);
  return <>{dom}</>;
};

export default Authorized;