"use client";

import Link from "next/link";
import { usePathname } from "next/navigation";
import { Home, Compass, MessageSquare, Folder, Users, Tag, Smartphone, Radio } from "lucide-react";

// Official Discord Logo SVG
function DiscordLogo({ className = "w-4 h-4" }: { className?: string }) {
  return (
    <svg className={className} viewBox="0 0 127.14 96.36" fill="currentColor">
      <path d="M107.7,8.07A105.15,105.15,0,0,0,81.47,0a72.06,72.06,0,0,0-3.36,6.83A97.68,97.68,0,0,0,49,6.83,72.37,72.37,0,0,0,45.64,0,105.89,105.89,0,0,0,19.39,8.09C2.79,32.65-1.71,56.6.54,80.21h0A105.73,105.73,0,0,0,32.71,96.36,77.7,77.7,0,0,0,39.6,85.25a68.42,68.42,0,0,1-10.85-5.18c.91-.66,1.8-1.34,2.66-2a75.57,75.57,0,0,0,64.32,0c.87.71,1.76,1.39,2.66,2a68.68,68.68,0,0,1-10.87,5.19,77,77,0,0,0,6.89,11.1,105.25,105.25,0,0,0,32.19-16.14c2.64-27.38-4.51-51.11-18.91-72.15ZM42.45,65.69C36.18,65.69,31,60,31,53s5-12.74,11.43-12.74S54,45.92,53.87,53,48.74,65.69,42.45,65.69Zm42.24,0C78.41,65.69,73.25,60,73.25,53s5-12.74,11.44-12.74S96.23,45.92,96.1,53,91,65.69,84.69,65.69Z"/>
    </svg>
  );
}

export function Sidebar() {
  const pathname = usePathname();

  return (
    <aside
      style={{ 
        width: "var(--custom-sidebar-width, 220px)",
        top: "var(--custom-sidebar-top, 105px)"
      }}
      className="hidden lg:flex flex-col justify-between shrink-0 select-none text-xs fixed bottom-6 left-4 z-40 py-1 pr-3 transition-all duration-150"
    >
      
      {/* 📌 HAUT : NAVIGATION + EXPLORER */}
      <div className="flex flex-col gap-4 overflow-y-auto scrollbar-hide">
        {/* SECTION 1 : NAVIGATION PRINCIPALE */}
        <nav className="flex flex-col gap-1.5">
          {[
            { name: "Accueil", href: "/", icon: Home },
            { name: "Shorts", href: "/shorts", icon: Smartphone, badge: "TikTok", badgeColor: "bg-pink-500/20 text-pink-300 border-pink-500/40" },
            { name: "Live Cams", href: "/live", icon: Radio, badge: "LIVE", badgeColor: "bg-red-500/20 text-red-300 border-red-500/40" },
            { name: "Vidéos", href: "/videos", icon: Compass },
            { name: "Messages", href: "/dashboard/messages", icon: MessageSquare },
          ].map((item) => {
            const isActive = pathname === item.href;
            const Icon = item.icon;
            return (
              <Link
                key={item.name}
                href={item.href}
                prefetch={true}
                style={{ 
                  height: "var(--custom-sidebar-item-height, 44px)",
                  fontSize: "var(--custom-sidebar-font, 14px)",
                  borderRadius: "var(--custom-sidebar-item-radius, 12px)"
                }}
                className={`px-3.5 flex items-center justify-between font-extrabold transition-all duration-150 ${
                  isActive
                    ? "bg-[#240e13] text-[#e05a68] font-black border-l-4 border-[#e05a68] pl-3 shadow-[0_0_15px_rgba(224,90,104,0.25)]"
                    : "text-[#e2c0c5] hover:text-white hover:bg-white/5"
                }`}
              >
                <div className="flex items-center gap-3.5">
                  <Icon size={19} className={isActive ? "text-[#e05a68]" : "text-[#9e737a]"} />
                  <span>{item.name}</span>
                </div>
                {item.badge && (
                  <span className={`text-[8.5px] font-black uppercase px-2 py-0.5 rounded-full border ${item.badgeColor}`}>
                    {item.badge}
                  </span>
                )}
              </Link>
            );
          })}
        </nav>

        {/* SECTION 2 : EXPLORER / CATÉGORIES */}
        <div className="flex flex-col gap-1.5 pt-2 border-t border-white/10">
          <span className="text-[10px] font-black uppercase text-[#9e737a] tracking-wider px-3 pb-1">
            Explorer
          </span>
          {[
            { name: "Catégories", href: "/categories", icon: Folder },
            { name: "Chaînes", href: "/channels", icon: Users },
            { name: "Tags", href: "/tags", icon: Tag },
          ].map((item) => {
            const isActive = pathname === item.href;
            const Icon = item.icon;
            return (
              <Link
                key={item.name}
                href={item.href}
                prefetch={true}
                style={{ 
                  height: "var(--custom-sidebar-item-height, 42px)",
                  fontSize: "var(--custom-sidebar-font, 13.5px)",
                  borderRadius: "var(--custom-sidebar-item-radius, 12px)"
                }}
                className={`px-3.5 flex items-center gap-3.5 font-bold transition-all duration-150 ${
                  isActive
                    ? "bg-[#240e13] text-[#e05a68] font-black border-l-4 border-[#e05a68] pl-3"
                    : "text-[#e2c0c5] hover:text-white hover:bg-white/5"
                }`}
              >
                <Icon size={18} className={isActive ? "text-[#e05a68]" : "text-[#9e737a]"} />
                <span>{item.name}</span>
              </Link>
            );
          })}
        </div>
      </div>

      {/* 📌 BAS : DISCORD COLLÉ TOUT EN BAS DE L'ÉCRAN */}
      <div className="pt-3 border-t border-white/10">
        <a
          href="https://discord.gg/mtbr"
          target="_blank"
          rel="noreferrer"
          style={{ 
            height: "var(--custom-sidebar-item-height, 44px)",
            borderRadius: "var(--custom-sidebar-item-radius, 12px)"
          }}
          className="flex items-center justify-between px-3.5 bg-[#5865F2]/15 hover:bg-[#5865F2]/25 border border-[#5865F2]/40 hover:border-[#5865F2] text-[#818cf8] hover:text-white transition-all text-xs font-black shadow-lg group"
        >
          <div className="flex items-center gap-2.5">
            <DiscordLogo className="w-4 h-4 text-[#5865F2] group-hover:scale-110 transition-transform" />
            <span>DISCORD</span>
          </div>
          <span className="text-[10px] opacity-70 group-hover:opacity-100 font-bold">REJOINDRE ➔</span>
        </a>
      </div>

    </aside>
  );
}
