import { Link } from "react-router";
import Logo from "/MAV.svg";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import {
  faGear,
  faHome,
  faListCheck,
  faMaximize,
  faMinimize,
  faRotate,
} from "@fortawesome/free-solid-svg-icons";
import { useState } from "react";
import SoundBtn from "./SoundBtn";
import { useNPEDContext } from "../../context/NPEDUserContext";

export default function Header() {
  const [isFullscreen, setIsFullscreen] = useState(false);
  const { sessionStarted } = useNPEDContext();

  const toggleFullscreen = () => {
    if (!document.fullscreenElement) {
      document.documentElement.requestFullscreen();
      setIsFullscreen(true);
    } else {
      document.exitFullscreen();
      setIsFullscreen(false);
    }
  };

  const refreshBrowser = () => {
    window.location.reload();
  };

  return (
    <div className="relative bg-[#253445] border-b border-gray-500 items-center mx-auto px-2 sm:px-6 lg:px-8 p-4 flex flex-col md:flex-row justify-between mb-7">
      <div className="w-30">
        <Link to={"/"}>
          <img src={Logo} alt="Logo" width={150} height={150} />
        </Link>
      </div>
      <div className="flex flex-col lg:flex-row items-center space-x-24 justify-items-center">
        {sessionStarted && (
          <div className="text-green-400 font-bold">Session Active</div>
        )}

        <div className="flex flex-row space-x-8">
          <Link to={"/"}>
            <FontAwesomeIcon className="text-white" icon={faHome} size="2x" />
          </Link>
          <div onClick={toggleFullscreen} className="flex flex-col">
            {isFullscreen ? (
              <FontAwesomeIcon icon={faMinimize} size="2x" />
            ) : (
              <FontAwesomeIcon icon={faMaximize} size="2x" />
            )}
          </div>
          <div onClick={refreshBrowser}>
            <FontAwesomeIcon icon={faRotate} size="2x" />
          </div>
          <SoundBtn />
          <Link to={"/session-settings"}>
            <FontAwesomeIcon
              className="text-white"
              icon={faListCheck}
              size="2x"
            />
          </Link>

          <Link to={"/system-settings"}>
            <FontAwesomeIcon className="text-white" icon={faGear} size="2x" />
          </Link>
        </div>
      </div>
    </div>
  );
}
