import { createFileRoute, Link } from "@tanstack/react-router";
import { useEffect, useState } from "react";
import { Flame, Play } from "lucide-react";
import { LobbyShell } from "@/components/lotus/LobbyShell";
import { ProfitRanking } from "@/components/lotus/ProfitRanking";
import { GAMES } from "@/lib/games";
import vipBanner from "@/assets/lobby/vip-wheel-banner.png";
import slideAviator from "@/assets/lobby/slide-aviator.png";
import slideChicken from "@/assets/lobby/slide-chicken.png";
import slideJet from "@/assets/lobby/slide-luckyjet.png";

export const Route = createFileRoute("/")({
  head: () => ({
    meta: [
      { title: "Lotus365 – Top Games: Aviator, Chicken Road, Lucky Jet" },
      { name: "description", content: "Play Aviator, Chicken Road, Lucky Jet, Mines, Tower Rush and Wingo in the Lotus365 demo lobby." },
      { property: "og:title", content: "Lotus365 – Top Games" },
      { property: "og:description", content: "Six popular instant games in one demo lobby." },
      { property: "og:type", content: "website" },
      { name: "twitter:card", content: "summary_large_image" },
    ],
  }),
  component: Lobby,
});

const BANNERS = [
  { tag: "REGAL VIP WHEEL", line1: "WIN UP TO", line2: "₹50,000 CASH", bg: vipBanner, baked: true },
  { tag: "HIGH ROLLER PACK", line1: "DEPOSIT ₹10,000", line2: "GET ₹5,000 BONUS", bg: slideAviator, baked: false },
  { tag: "NOBLE WHEEL", line1: "WIN UP TO", line2: "₹25,000 CASH", bg: slideJet, baked: false },
  { tag: "WELCOME OFFER", line1: "DEPOSIT ₹5,000", line2: "GET ₹2,000 BONUS", bg: slideChicken, baked: false },
];

function Lobby() {
  const [slide, setSlide] = useState(0);
  useEffect(() => {
    const t = setInterval(() => setSlide((s) => (s + 1) % BANNERS.length), 3500);
    return () => clearInterval(t);
  }, []);

  return (
    <LobbyShell>
      <section className="mt-4 px-3">
        <div className="overflow-hidden rounded-xl">
        <div className="flex transition-transform duration-700" style={{ transform: `translateX(-${slide * 100}%)` }}>
          {BANNERS.map((b) => (
            <div key={b.tag} className="relative aspect-[427/171] w-full shrink-0 overflow-hidden rounded-xl border border-border">
              <img src={b.bg} alt={`${b.tag} — ${b.line1} ${b.line2}`} className="absolute inset-0 h-full w-full object-cover" />
              {b.baked ? (
                <Link to="/deposit" aria-label="Deposit" className="absolute bottom-[12%] left-[6%] h-[25%] w-[24%] rounded-md" />
              ) : (
                <div className="relative flex h-full flex-col justify-center pl-[7%]">
                  <span className="w-fit rounded-md bg-lobby-deep/80 px-2 py-1 text-[10px] font-bold tracking-wider text-muted-foreground">{b.tag}</span>
                  <p className="mt-2.5 text-lg font-extrabold leading-tight">{b.line1}<br />{b.line2}</p>
                  <Link to="/deposit" className="mt-3 w-fit rounded-md bg-gold px-4 py-2 text-[11px] font-bold text-gold-foreground">DEPOSIT</Link>
                </div>
              )}
            </div>
          ))}
        </div>
        </div>
      </section>

      <h2 className="mt-6 flex items-center gap-1.5 px-3 text-sm font-extrabold"><Flame className="size-4 text-pill-blue" /> TOP GAMES</h2>
      <div className="mt-3 grid grid-cols-3 gap-2.5 px-3">
        {GAMES.map((g, i) => (
          <Link key={g.to} to={g.to} className="group animate-pop" style={{ animationDelay: `${i * 70}ms` }}>
            <div className="relative aspect-[4/5] overflow-hidden rounded-lg">
              <img src={g.img} alt={g.name} width={768} height={960} className="h-full w-full object-cover transition-transform duration-300 group-hover:scale-110" />
              {i < 3 && <span className="absolute left-1.5 top-1.5 rounded-sm bg-hot px-1 text-[8px] font-bold">HOT</span>}
            </div>
            <p className="mt-1.5 text-center text-xs font-semibold">{g.name}</p>
            <span className="mt-1.5 flex items-center justify-center gap-1 rounded-md bg-gold py-1.5 text-[10px] font-extrabold text-gold-foreground transition active:scale-95">
              <Play className="size-2.5 fill-current" /> PLAY NOW
            </span>
          </Link>
        ))}
      </div>

      <ProfitRanking />

      <section className="mt-8 border-t border-border px-3 pt-5 text-xs leading-relaxed text-muted-foreground">
        <span className="rounded bg-gold/20 px-1.5 py-0.5 text-[10px] font-bold text-gold">18+</span>
        <h3 className="mt-3 text-base font-extrabold text-brand-red">WELCOME TO LOTUS</h3>
        <p className="mt-2">Welcome to <b className="text-foreground">LOTUS</b>, the most trusted and premier online gaming destination. We provide a safe, secure, and highly entertaining platform for individuals who are 18 years of age and older.</p>
        <h4 className="mt-3 font-bold text-foreground">Responsible Gaming at LOTUS</h4>
        <p className="mt-1">At LOTUS, we prioritize the well-being of our users above all else. This is a demo — no real money is used.</p>
      </section>

    </LobbyShell>
  );
}
