import { useLocation, matchPath } from 'react-router-dom';

export const usePaths = (paths: string[], strict: boolean = false) => {
  const location = useLocation();

  const matches = paths.reduce(
    (matchesAcc, path) => {
      const match = !!matchPath({ path, end: false }, location.pathname);

      return strict ? matchesAcc && match : matchesAcc || match;
    },
    strict ? true : false,
  );

  return matches;
};

export default usePaths;
