import { ElementType } from 'react';
import { Navigate, To } from 'react-router-dom';
import { useAppSelector } from '../../hooks';
import {} from '../../store';
import { IndexSignature } from '../../utils';

export const WithHocAuth = (Component: ElementType, redirectUrl?: To) => {
  return function WithHocAuthComponent({ ...props }: IndexSignature) {
    const auth = false; // useAppSelector();

    if (redirectUrl) {
      return auth ? (
        <Component
          {...props}
        />
      ) : (<Navigate to={redirectUrl} />);
    }

    return (
      <Component
        auth={auth}
        {...props}
      />
    );
  };
};

export type AuthType = any;
