import { ElementType } from 'react';
import { To, useNavigate } from 'react-router-dom';
import { IndexSignature } from '../../utils';

export const WithHocNavigate = (Component: ElementType) => {
  return function WithHocNavigateComponent({ ...props }: IndexSignature) {
    const navigate = useNavigate();

    return (
      <Component
        handleNavigate={(path: To = '/') => navigate(path)}
        {...props}
      />
    );
  };
};

export type HandleNavigateType = (path?: To) => void;
