"use client";

import Link from "next/link";
import { Smartphone, Flame, Crown, Radio, Sparkles } from "lucide-react";

interface StoryItem {
  id: string;
  name: string;
  image?: string;
  icon?: any;
  href: string;
  badge?: string;
  isLive?: boolean;
  borderGradient: string;
}

export function MobileStoriesBar({ creators = [] }: { creators?: any[] }) {
  const staticStories: StoryItem[] = [
    {
      id: "shorts",
      name: "Shorts",
      icon: Smartphone,
      href: "/shorts",
      badge: "HOT",
      borderGradient: "from-[#e05a68] via-[#c93f52] to-[#5c1922]",
    },
    {
      id: "vip",
      name: "VIP Club",
      icon: Crown,
      href: "/premium",
      badge: "0.99€",
      borderGradient: "from-amber-400 via-yellow-500 to-amber-600",
    },
    {
      id: "trending",
      name: "Tendances",
      icon: Flame,
      href: "/?tab=trending",
      badge: "TOP",
      borderGradient: "from-orange-500 via-red-500 to-[#e05a68]",
    },
    {
      id: "live",
      name: "Live Cams",
      icon: Radio,
      href: "/live",
      isLive: true,
      borderGradient: "from-red-500 via-[#c93f52] to-[#e05a68]",
    },
  ];

  const creatorStories: StoryItem[] = (creators || []).slice(0, 8).map((c, i) => ({
    id: `creator-${c.id || i}`,
    name: c.name || `Modèle #${i + 1}`,
    image: c.image || `https://images.unsplash.com/photo-${1534528741775 + i}?w=150&q=80`,
    href: `/channel/${c.id || ''}`,
    isLive: Boolean(c.isOnline),
    borderGradient: "from-[#e05a68] via-[#c93f52] to-[#5c1922]",
  }));

  const allStories = [...staticStories, ...creatorStories];

  return (
    <div className="md:hidden w-full pt-1 pb-3 px-2 select-none">
      <div className="flex items-center gap-3 overflow-x-auto scrollbar-hide py-1 px-1 -mx-1">
        {allStories.map((story) => {
          const Icon = story.icon;
          return (
            <Link
              key={story.id}
              href={story.href}
              className="flex flex-col items-center gap-1.5 flex-shrink-0 group active:scale-95 transition-transform"
            >
              {/* Cercle avec bordure dégradée lumineuse (Style Instagram/TikTok Story) */}
              <div className="relative p-[2.5px] rounded-full bg-gradient-to-tr shadow-md group-hover:scale-105 transition-transform"
                style={{
                  backgroundImage: `linear-gradient(to top right, var(--tw-gradient-stops))`,
                }}
              >
                <div className={`p-[2px] rounded-full bg-gradient-to-tr ${story.borderGradient}`}>
                  <div className="w-14 h-14 rounded-full bg-[#12080b] p-0.5 overflow-hidden flex items-center justify-center border border-black/40">
                    {story.image ? (
                      <img
                        src={story.image}
                        alt={story.name}
                        className="w-full h-full object-cover rounded-full"
                        loading="lazy"
                      />
                    ) : Icon ? (
                      <div className="w-full h-full rounded-full bg-[#1a0a0f] flex items-center justify-center text-white">
                        <Icon size={22} className="text-[#f08592] drop-shadow-[0_0_8px_rgba(224,90,104,0.8)]" />
                      </div>
                    ) : null}
                  </div>
                </div>

                {/* Badge Flottant (HOT / VIP / LIVE) */}
                {story.isLive ? (
                  <span className="absolute -bottom-1 left-1/2 -translate-x-1/2 bg-red-600 text-white text-[8px] font-black px-1.5 py-0.2 rounded-full border border-black shadow flex items-center gap-0.5 uppercase tracking-wider">
                    <span className="w-1.5 h-1.5 rounded-full bg-white animate-pulse" />
                    LIVE
                  </span>
                ) : story.badge ? (
                  <span className="absolute -bottom-1 left-1/2 -translate-x-1/2 bg-gradient-to-r from-[#c93f52] to-[#e05a68] text-white text-[7.5px] font-black px-1.5 py-0.2 rounded-full border border-black shadow uppercase tracking-wider">
                    {story.badge}
                  </span>
                ) : null}
              </div>

              {/* Nom de la Story */}
              <span className="text-[11px] font-bold text-[#d4b09a] group-hover:text-white truncate max-w-[62px] text-center leading-tight">
                {story.name}
              </span>
            </Link>
          );
        })}
      </div>
    </div>
  );
}
