"use client";

import Link from "next/link";
import Image from "next/image";
import { FaTelegram, FaXTwitter } from "react-icons/fa6";
import { useState } from "react";

export default function Header() {
  const [isDrawerOpen, setIsDrawerOpen] = useState(false);

  // Toggle the nav drawer
  const toggleDrawer = () => {
    setIsDrawerOpen(!isDrawerOpen);
  };

  return (
    <header className="w-full bg-[rgb(22,22,22)] shadow-md">
      <div className="container mx-auto flex items-center justify-between p-12 max-w-screen-xl w-full">
        {/* Logo */}
        <div className="flex items-center w-40 mr-20">
          <Image src="/duelfiassets/logo.png" alt="Logo" width={100} height={40} />
        </div>

        {/* Navigation Links (hidden on mobile, visible on md+) */}
        <nav className="hidden md:flex gap-6 ml-6">
          <Link
            href="/whitepaper"
            className="text-white transition-colors duration-[500ms] hover:text-[rgb(248,144,22)]"
          >
            Whitepaper
          </Link>
          <Link
            href="/support"
            className="text-white transition-colors duration-[500ms] hover:text-[rgb(248,144,22)]"
          >
            Support
          </Link>
        </nav>

        {/* Spacer (for centering) */}
        <div className="flex-grow"></div>

        {/* Socials & Login (hidden on mobile, visible on md+) */}
        <div className="hidden md:flex items-center gap-6">
        <a
          href="https://t.me/yourchannel"
          target="_blank"
          rel="noopener noreferrer"
          className="transition-transform duration-300 hover:scale-120"
        >
          <Image
            src="/duelfiassets/telegram (1).png"
            alt="Telegram"
            width={40}
            height={40}
          />
        </a>
        <a
          href="https://twitter.com/yourhandle"
          target="_blank"
          rel="noopener noreferrer"
          className="transition-transform duration-300 hover:scale-120"
        >
          <Image
            src="/duelfiassets/xlogo.png"
            alt="X (Twitter)"
            width={40}
            height={40}
          />
        </a>

          {/* Login Button */}
          <button className="px-15 py-3 bg-[rgb(248,144,22)] text-black font-bold rounded-lg transition-transform duration-300 hover:scale-115 hover:bg-white hover:text-[rgb(248,144,22)]">
            Connected
          </button>
        </div>

        {/* Mobile-only view (Logo & Login) */}
        <div className="flex md:hidden items-center gap-4">
          {/* Hamburger Button */}
          <button className="px-4 py-2 bg-[rgb(248,144,22)] text-white rounded-lg transition-colors duration-300 hover:bg-white hover:text-[rgb(248,144,22)]">
            Login
          </button>
          <button
            onClick={toggleDrawer}
            className="text-white"
            aria-label="Open Menu"
          >
            <svg
              className="w-6 h-6"
              xmlns="http://www.w3.org/2000/svg"
              fill="none"
              viewBox="0 0 24 24"
              stroke="currentColor"
            >
              <path
                strokeLinecap="round"
                strokeLinejoin="round"
                strokeWidth="2"
                d="M4 6h16M4 12h16M4 18h16"
              />
            </svg>
          </button>
        </div>
      </div>

      {/* Mobile Drawer */}
      {isDrawerOpen && (
        <div className="fixed inset-0 bg-black bg-opacity-50 z-50">
          <div className="absolute top-0 right-0 bg-[rgb(22,22,22)] w-64 h-full p-6">
            {/* Close button */}
            <button
              onClick={toggleDrawer}
              className="text-white mb-4"
              aria-label="Close Menu"
            >
              <svg
                className="w-6 h-6"
                xmlns="http://www.w3.org/2000/svg"
                fill="none"
                viewBox="0 0 24 24"
                stroke="currentColor"
              >
                <path
                  strokeLinecap="round"
                  strokeLinejoin="round"
                  strokeWidth="2"
                  d="M6 18L18 6M6 6l12 12"
                />
              </svg>
            </button>

            {/* Mobile Navigation Links */}
            <div className="flex flex-col gap-6">
              <Link
                href="/whitepaper"
                className="text-white transition-colors duration-[500ms] hover:text-[rgb(248,144,22)]"
                onClick={() => setIsDrawerOpen(false)} // Close drawer on link click
              >
                Whitepaper
              </Link>
              <Link
                href="/support"
                className="text-white transition-colors duration-[500ms] hover:text-[rgb(248,144,22)]"
                onClick={() => setIsDrawerOpen(false)} // Close drawer on link click
              >
                Support
              </Link>

              {/* Socials */}
              <a
                href="https://t.me/yourchannel"
                target="_blank"
                rel="noopener noreferrer"
                className="text-white transition-colors duration-[500ms] hover:text-[rgb(248,144,22)]"
                onClick={() => setIsDrawerOpen(false)}
              >
                <FaTelegram size={24} />
              </a>
              <a
                href="https://twitter.com/yourhandle"
                target="_blank"
                rel="noopener noreferrer"
                className="text-white transition-colors duration-[500ms] hover:text-[rgb(248,144,22)]"
                onClick={() => setIsDrawerOpen(false)}
              >
                <FaXTwitter size={24} />
              </a>
            </div>
          </div>
        </div>
      )}
    </header>
  );
}
