import React from "react";
import { useNavigate } from "react-router-dom";
import { Box } from "@mui/material";
import logoText from "../../assets/logo-text.svg";
import gradient from "../../assets/gradient.svg";
import { useUrlState } from "../../hooks/useUrlState";
import { useLeaderboard } from "../../context/LeaderboardContext";

const Logo = () => {
  const { resetParams } = useUrlState();
  const { resetState } = useLeaderboard();
  const navigate = useNavigate();

  const handleClick = (e) => {
    e.preventDefault();
    resetState();
    resetParams();
    navigate("/");
  };

  return (
    <Box
      component="a"
      onClick={handleClick}
      sx={{
        textDecoration: "none",
        position: "relative",
        cursor: "pointer",
      }}
    >
      <Box
        component="img"
        src={gradient}
        alt=""
        sx={{
          position: "absolute",
          width: "150%",
          height: "auto",
          top: "50%",
          left: "50%",
          transform: "translate(-50%, -50%)",
          zIndex: 0,
          opacity: 1,
        }}
      />
      <Box
        component="img"
        src={logoText}
        alt="Leaderboards on the Hub"
        sx={{
          height: 110,
          width: "auto",
          display: "block",
          margin: "0 auto",
          position: "relative",
          zIndex: 1,
          opacity: (theme) => (theme.palette.mode === "dark" ? 0.8 : 1),
        }}
      />
    </Box>
  );
};

export default Logo;
