import React, { PropsWithChildren } from "react";
import { useNavigate, useLocation } from "react-router-dom";

export  const Link = ({
    to,
    children,
    colorEnd,
  }: { to: string; colorEnd: string } & PropsWithChildren) => {
    const navigate = useNavigate();
    const location = useLocation();
  
    const handleClicked = () => {

      setTimeout(() => navigate(to), 1000);
    };
  
    return (
      <a
        className={
          location.pathname.includes(children?.toString().toLowerCase()!)
            ? "active"
            : " cursor-pointer"
        }
        onClick={handleClicked}
      >
        {children}
      </a>
    );
  };