"use client";

import { useState } from "react";
import {
  ExternalLink,
  ShieldCheck,
  Gamepad2,
  Code2,
  Lock,
  ArrowUpRight,
  ChevronDown,
  ChevronUp,
} from "lucide-react";

interface GameItem {
  title: string;
  url: string;
  category: string;
  highlight?: boolean;
}

const ALL_GAMES: GameItem[] = [
  {
    title: "BloxStrike",
    url: "https://www.roblox.com/games/114234929420007/BloxStrike",
    category: "Tactical FPS • Core Systems & Security",
    highlight: true,
  },
  {
    title: "Basketball Zero",
    url: "https://www.roblox.com/games/130739873848552/Basketball-Zero",
    category: "Competitive Sports",
    highlight: true,
  },
  {
    title: "Track & Field: Infinite",
    url: "https://www.roblox.com/games/16426795556/Track-Field-Infinite",
    category: "Athletics & Physics",
    highlight: true,
  },
  {
    title: "Musical Chairs",
    url: "https://www.roblox.com/games/113323927469374/Musical-Chairs",
    category: "Multiplayer Party",
    highlight: true,
  },
  {
    title: "Soccer Zero",
    url: "https://www.roblox.com/games/75462869229229/Soccer-Zero",
    category: "Competitive Sports",
  },
  {
    title: "Scream City 2",
    url: "https://www.roblox.com/games/76427445314955/Scream-City-2",
    category: "Atmospheric Adventure",
  },
  {
    title: "Oakdale Arena",
    url: "https://www.roblox.com/games/104493944461140/Oakdale-Arena",
    category: "Combat Arena",
  },
  {
    title: "Knife Tag",
    url: "https://www.roblox.com/games/132669595086376/Knife-Tag",
    category: "Action & PvP",
  },
  {
    title: "OPPS",
    url: "https://www.roblox.com/games/114939661069378/OPPS",
    category: "Action Shooter",
  },
  {
    title: "Rodeo Simulator",
    url: "https://www.roblox.com/games/122965903518728/Rodeo-Simulator",
    category: "Simulator",
  },
  {
    title: "Lift the Largest Rock",
    url: "https://www.roblox.com/games/74413399427694/Lift-the-Largest-Rock",
    category: "Incremental Simulator",
  },
  {
    title: "UGC Math Race",
    url: "https://www.roblox.com/games/14656843302/UGC-Math-Race",
    category: "UGC Arcade",
  },
  {
    title: "UGC Steal Points",
    url: "https://www.roblox.com/games/15998144390/UGC-Steal-Points",
    category: "Competitive UGC",
  },
  {
    title: "Free UGC Cart Ride",
    url: "https://www.roblox.com/games/14508327597/Free-UGC-Cart-Ride",
    category: "UGC Cart Ride",
  },
  {
    title: "Escape Brainrots for Lucky Blocks",
    url: "https://www.roblox.com/games/117145281772407/Escape-Brainrots-for-Lucky-Blocks",
    category: "Arcade Minigame",
  },
  {
    title: "Shot Put Showdown",
    url: "https://www.roblox.com/games/14863511622/Shot-Put-Showdown",
    category: "Sports",
  },
  {
    title: "Pole Vault Playground",
    url: "https://www.roblox.com/games/14244290386/Pole-Vault-Playground",
    category: "Physics & Sports",
  },
];

export default function CusDeveloperSection({ accent = "#ffffff" }: { accent?: string }) {
  const [expanded, setExpanded] = useState(false);
  const themeColor = accent || "#ffffff";

  const featuredGames = ALL_GAMES.filter((g) => g.highlight);
  const remainingGames = ALL_GAMES.filter((g) => !g.highlight);

  return (
    <div
      suppressHydrationWarning
      style={{
        marginTop: 20,
        textAlign: "left",
        display: "flex",
        flexDirection: "column",
        gap: 12,
        fontFamily: "inherit",
      }}
    >
      {/* Hairline Divider */}
      <div
        style={{
          width: "100%",
          height: 1,
          background: "linear-gradient(90deg, transparent, rgba(0, 0, 0, 0.12), transparent)",
        }}
      />

      {/* Main Container */}
      <div
        style={{
          background: "rgba(10, 13, 18, 0.72)",
          border: "1px solid rgba(0, 0, 0, 0.08)",
          borderRadius: 14,
          padding: 16,
          display: "flex",
          flexDirection: "column",
          gap: 14,
          backdropFilter: "blur(14px)",
        }}
      >
        {/* Top Header: Roblox Verified Badge */}
        <div
          style={{
            display: "flex",
            alignItems: "center",
            justifyContent: "space-between",
            flexWrap: "wrap",
            gap: 8,
          }}
        >
          <div style={{ display: "flex", alignItems: "center", gap: 7 }}>
            {/* Roblox Verified Square with Checkmark */}
            <span
              style={{
                width: 18,
                height: 18,
                background: "#ffffff",
                borderRadius: 4,
                display: "grid",
                placeItems: "center",
                flexShrink: 0,
              }}
              title="Roblox Verified Creator"
            >
              <svg width="11" height="9" viewBox="0 0 11 9" fill="none">
                <path
                  d="M1 4.5L4 7.5L10 1.5"
                  stroke="#000000"
                  strokeWidth="2"
                  strokeLinecap="round"
                  strokeLinejoin="round"
                />
              </svg>
            </span>
            <span
              style={{
                fontSize: 12,
                fontWeight: 700,
                color: "#c80404",
                letterSpacing: "0.02em",
                textTransform: "uppercase",
              }}
            >
              Roblox Verified Developer
            </span>
          </div>

          <span
            style={{
              fontSize: 11,
              fontFamily: "monospace",
              color: themeColor,
              background: `${themeColor}14`,
              border: `1px solid ${themeColor}33`,
              padding: "2px 7px",
              borderRadius: 6,
            }}
          >
            Security & Systems
          </span>
        </div>

        {/* 2.4B+ Metric Callout */}
        <div
          style={{
            background: "rgba(0, 0, 0, 0.025)",
            border: "1px solid rgba(0, 0, 0, 0.05)",
            borderRadius: 10,
            padding: "12px 14px",
            display: "flex",
            alignItems: "baseline",
            justifyContent: "space-between",
          }}
        >
          <div>
            <div
              style={{
                fontSize: 26,
                fontWeight: 800,
                lineHeight: 1,
                color: "#000000",
                letterSpacing: "-0.03em",
              }}
            >
              2.4B<span style={{ color: themeColor }}>+</span>
            </div>
            <div
              style={{
                fontSize: 11,
                color: "#551212",
                marginTop: 4,
                fontWeight: 500,
              }}
            >
              Total Game Visits Contributed Across 17 Titles
            </div>
          </div>

          <div
            style={{
              textAlign: "right",
              fontSize: 11,
              color: "#3d1616",
              lineHeight: 1.4,
            }}
          >
            <div>Lua • Luau</div>
            <div>Game Security</div>
          </div>
        </div>

        {/* Technical Specialization Tags */}
        <div style={{ display: "flex", flexWrap: "wrap", gap: 6 }}>
          {[
            { label: "Anti-Cheat Systems", icon: ShieldCheck },
            { label: "Lua / Luau Architecture", icon: Code2 },
            { label: "Exploit Mitigation", icon: Lock },
          ].map((tag) => {
            const Icon = tag.icon;
            return (
              <span
                key={tag.label}
                style={{
                  display: "inline-flex",
                  alignItems: "center",
                  gap: 5,
                  fontSize: 11,
                  color: "#7e0b0b",
                  background: "rgba(0, 0, 0, 0.04)",
                  border: "1px solid rgba(0, 0, 0, 0.06)",
                  padding: "4px 8px",
                  borderRadius: 6,
                }}
              >
                <Icon size={12} color={themeColor} />
                {tag.label}
              </span>
            );
          })}
        </div>

        {/* Section Header: Featured Titles */}
        <div
          style={{
            display: "flex",
            alignItems: "center",
            justifyContent: "space-between",
            marginTop: 4,
          }}
        >
          <span
            style={{
              fontSize: 11,
              fontWeight: 700,
              color: "#551212",
              textTransform: "uppercase",
              letterSpacing: "0.06em",
            }}
          >
            Featured Roblox Titles
          </span>
          <span style={{ fontSize: 11, color: "#3d1616" }}>
            17 Contributed Games
          </span>
        </div>

        {/* Top 4 Featured Games */}
        <div style={{ display: "flex", flexDirection: "column", gap: 6 }}>
          {featuredGames.map((game) => (
            <a
              key={game.title}
              href={game.url}
              target="_blank"
              rel="noopener noreferrer"
              style={{
                textDecoration: "none",
                display: "flex",
                alignItems: "center",
                justifyContent: "space-between",
                background: "rgba(0, 0, 0, 0.025)",
                border: "1px solid rgba(0, 0, 0, 0.06)",
                borderRadius: 8,
                padding: "8px 11px",
                transition: "all 0.15s ease",
                color: "inherit",
              }}
              onMouseEnter={(e) => {
                e.currentTarget.style.borderColor = "rgba(255, 255, 255, 0.35)";
                e.currentTarget.style.background = "rgba(255, 255, 255, 0.05)";
              }}
              onMouseLeave={(e) => {
                e.currentTarget.style.borderColor = "rgba(0, 0, 0, 0.06)";
                e.currentTarget.style.background = "rgba(0, 0, 0, 0.025)";
              }}
            >
              <div style={{ display: "flex", alignItems: "center", gap: 9 }}>
                <div
                  style={{
                    width: 26,
                    height: 26,
                    borderRadius: 6,
                    background: "rgba(255, 255, 255, 0.1)",
                    display: "grid",
                    placeItems: "center",
                    flexShrink: 0,
                  }}
                >
                  <Gamepad2 size={14} color="#ffffff" />
                </div>
                <div>
                  <div style={{ fontSize: 12, fontWeight: 700, color: "#ca0202" }}>
                    {game.title}
                  </div>
                  <div style={{ fontSize: 10, color: "#3d1616" }}>
                    {game.category}
                  </div>
                </div>
              </div>

              <div
                style={{
                  display: "flex",
                  alignItems: "center",
                  gap: 3,
                  fontSize: 11,
                  fontWeight: 600,
                  color: "#ffffff",
                }}
              >
                Play <ArrowUpRight size={12} />
              </div>
            </a>
          ))}
        </div>

        {/* Expandable Roster for the Remaining 13 Games */}
        {expanded && (
          <div
            style={{
              display: "flex",
              flexDirection: "column",
              gap: 5,
              paddingTop: 4,
              borderTop: "1px solid rgba(0, 0, 0, 0.06)",
            }}
          >
            {remainingGames.map((game) => (
              <a
                key={game.title}
                href={game.url}
                target="_blank"
                rel="noopener noreferrer"
                style={{
                  textDecoration: "none",
                  display: "flex",
                  alignItems: "center",
                  justifyContent: "space-between",
                  background: "rgba(0, 0, 0, 0.015)",
                  border: "1px solid rgba(0, 0, 0, 0.04)",
                  borderRadius: 6,
                  padding: "6px 10px",
                  fontSize: 11,
                  color: "#7e0b0b",
                  transition: "all 0.15s ease",
                }}
                onMouseEnter={(e) => {
                  e.currentTarget.style.borderColor = "rgba(255, 255, 255, 0.25)";
                  e.currentTarget.style.color = "#000000";
                }}
                onMouseLeave={(e) => {
                  e.currentTarget.style.borderColor = "rgba(0, 0, 0, 0.04)";
                  e.currentTarget.style.color = "#7e0b0b";
                }}
              >
                <div>
                  <strong style={{ color: "#9b0707" }}>{game.title}</strong>
                  <span style={{ color: "#3d1616", marginLeft: 7 }}>
                    • {game.category}
                  </span>
                </div>
                <ArrowUpRight size={11} color="#ffffff" />
              </a>
            ))}
          </div>
        )}

        {/* Expand / Collapse Button */}
        <button
          type="button"
          onClick={() => setExpanded(!expanded)}
          style={{
            background: "rgba(0, 0, 0, 0.03)",
            border: "1px solid rgba(0, 0, 0, 0.06)",
            borderRadius: 7,
            padding: "7px 10px",
            fontSize: 11,
            fontWeight: 600,
            color: "#551212",
            cursor: "pointer",
            display: "flex",
            alignItems: "center",
            justifyContent: "center",
            gap: 5,
            transition: "all 0.15s ease",
          }}
          onMouseEnter={(e) => {
            e.currentTarget.style.background = "rgba(0, 0, 0, 0.06)";
            e.currentTarget.style.color = "#000000";
          }}
          onMouseLeave={(e) => {
            e.currentTarget.style.background = "rgba(0, 0, 0, 0.03)";
            e.currentTarget.style.color = "#551212";
          }}
        >
          {expanded ? (
            <>
              Show Less <ChevronUp size={13} />
            </>
          ) : (
            <>
              View All 17 Games ({remainingGames.length} more) <ChevronDown size={13} />
            </>
          )}
        </button>

        {/* Verified Roblox Profile Link */}
        <a
          href="https://www.roblox.com/users/1528545277/profile"
          target="_blank"
          rel="noopener noreferrer"
          style={{
            textDecoration: "none",
            display: "flex",
            alignItems: "center",
            justifyContent: "space-between",
            background: "rgba(255, 255, 255, 0.06)",
            border: "1px solid rgba(255, 255, 255, 0.2)",
            borderRadius: 8,
            padding: "8px 12px",
            fontSize: 12,
            color: "#c80404",
            transition: "all 0.15s ease",
          }}
          onMouseEnter={(e) => {
            e.currentTarget.style.borderColor = "rgba(255, 255, 255, 0.4)";
            e.currentTarget.style.background = "rgba(255, 255, 255, 0.1)";
          }}
          onMouseLeave={(e) => {
            e.currentTarget.style.borderColor = "rgba(255, 255, 255, 0.2)";
            e.currentTarget.style.background = "rgba(255, 255, 255, 0.06)";
          }}
        >
          <span style={{ display: "inline-flex", alignItems: "center", gap: 7 }}>
            <span style={{ color: "#551212" }}>Roblox Profile:</span>
            <strong>@Ihaveash0rtname</strong>
          </span>
          <span
            style={{
              fontSize: 11,
              fontWeight: 600,
              color: "#f8e3e3",
              display: "inline-flex",
              alignItems: "center",
              gap: 3,
            }}
          >
            Verified Developer <ExternalLink size={11} />
          </span>
        </a>
      </div>
    </div>
  );
}
