import React from "react";
import Button from "./Button";
import robotLogo from "../../assets/images/robot-logo.png";
import { BsNewspaper, BsGithub } from "react-icons/bs";
import Whitepaper from "../../assets/Whitepaper.pdf";
type Props = {};

const menuItems = [
  {
    name: "Home",
    path: "/",
    id: "home",
  },
  {
    name: "About",
    path: "",
    id: "about",
  },
  {
    name: "Tokenomics",
    path: "",
    id: "tokenomics",
  },
  {
    name: "Roadmap",
    path: "",
    id: "roadmap",
  },
];

const Header = (props: Props) => {
  const [isScrolled, setIsScrolled] = React.useState(false);

  React.useEffect(() => {
    window.addEventListener("scroll", () => {
      if (window.scrollY > 0) {
        setIsScrolled(true);
      } else {
        setIsScrolled(false);
      }
    });
  }, []);

  const jumpToSection = (section: string) => {
    console.log("section", section);
    const element = document.getElementById(section);
    if (element) {
      element.scrollIntoView({ behavior: "smooth" });
    }
  };

  const openLocalPdf = () => {
    const pdf = Whitepaper;
    window.open(pdf);
  };

  return (
    <>
      {isScrolled ? (
        <div className="fixed w-full z-30 p-1 transition-all duration-150 bg-gray-800">
          <div className="container mx-auto flex justify-between items-center">
            <div className="flex gap-2 items-center">
              <div className="bg-white w-8 rounded-full overflow-hidden p-1">
                <img
                  src={robotLogo}
                  className="w-full transition-all duration-150 rounded-full"
                  alt=""
                />
              </div>
              <h4 className="text-xl transition-all duration-150 text-white uppercase font-bold">
                SGPT
              </h4>
            </div>

            <div className="flex gap-10 items-center">
              <ul className="flex gap-10">
                {menuItems.map((item) => (
                  <li
                    className="inline-block"
                    key={item.path}
                    onClick={() => jumpToSection(item.id)}
                  >
                    <p className="text-white text-md transition-all duration-150 cursor-pointer">
                      {item.name}
                    </p>
                  </li>
                ))}
              </ul>

              <div className="flex gap-4">
                <Button size="sm" onClick={() => openLocalPdf()}>
                  <div className="flex items-center gap-2">
                    <BsNewspaper />
                    Whitepaper
                  </div>
                </Button>
                <Button size="sm">
                  <div className="flex items-center gap-2">
                    <BsGithub />
                    Audit
                  </div>
                </Button>
              </div>
            </div>
          </div>
        </div>
      ) : (
        <div className="fixed z-30 w-full p-5 transition-all duration-150">
          <div className="container mx-auto flex justify-between items-center">
            <div className="flex gap-2 items-center">
              <div className="bg-white w-12 rounded-full overflow-hidden p-1">
                <img
                  src={robotLogo}
                  className="w-full transition-all duration-150 rounded-full"
                  alt=""
                />
              </div>
              <h4 className="text-4xl transition-all duration-150 text-white uppercase font-bold">
                SGPT
              </h4>
            </div>

            <div className="flex gap-10 items-center">
              <ul className="flex gap-10">
                {menuItems.map((item) => (
                  <li
                    className="inline-block"
                    key={item.path}
                    onClick={() => jumpToSection(item.id)}
                  >
                    <p className="text-white text-md transition-all duration-150 cursor-pointer">
                      {item.name}
                    </p>
                  </li>
                ))}
              </ul>

              <div className="flex gap-4">
                <Button size="md" onClick={() => openLocalPdf()}>
                  <div className="flex items-center gap-2">
                    <BsNewspaper />
                    Whitepaper
                  </div>
                </Button>
                <Button size="md">
                  <div className="flex items-center gap-2">
                    <BsGithub />
                    Audit
                  </div>
                </Button>
              </div>
            </div>
          </div>
        </div>
      )}
    </>
  );
};

export default Header;
