import React, { useState } from 'react';
import { Copy, Check, ShieldCheck, Flame, Layers, Award, Sparkles, Cpu, Lock, ArrowUpRight } from 'lucide-react';
import { CONTRACT_ADDRESS, TOKEN_INFO, TOKENOMICS_VERSION, YOUR_BUY_LINK } from '../config';
import { triggerBirthdayConfetti } from '../utils/confetti';
import { TokenomicsDashboard } from './TokenomicsDashboard';
import coinImg from '../assets/images/bm_connect_coin_1787085516443.jpg';

export const TokenSection: React.FC = () => {
  const [copied, setCopied] = useState(false);

  const handleCopy = () => {
    navigator.clipboard.writeText(CONTRACT_ADDRESS);
    setCopied(true);
    triggerBirthdayConfetti();
    setTimeout(() => setCopied(false), 3000);
  };

  const specs = [
    { label: 'Ticker', value: TOKEN_INFO.ticker, sub: 'Symbol', icon: Sparkles, color: 'text-[#FF8C32]' },
    { label: 'Network', value: TOKEN_INFO.network, sub: 'Solana SPL Token', icon: Cpu, color: 'text-[#00D7FF]' },
    { label: 'Launch', value: TOKEN_INFO.launchDateString, sub: 'Official Pool Launch', icon: Flame, color: 'text-[#FFA843]' },
    { label: 'Total Supply', value: TOKEN_INFO.totalSupply, sub: '10 Billion Fixed', icon: Layers, color: 'text-white' },
    { label: 'Buy / Sell Tax', value: TOKEN_INFO.buySellTax, sub: 'Zero Slippage Tax', icon: ShieldCheck, color: 'text-emerald-400' },
    { label: 'Liquidity', value: TOKEN_INFO.liquidity, sub: 'Fair Launch Raydium', icon: Award, color: 'text-[#00D7FF]' },
  ];

  return (
    <section id="token" className="py-24 relative overflow-hidden">
      {/* Background Glows */}
      <div className="absolute top-1/3 right-1/4 w-96 h-96 bg-[#FF8C32]/10 rounded-full blur-[130px] pointer-events-none -z-10" />
      <div className="absolute bottom-1/4 left-1/4 w-96 h-96 bg-[#00D7FF]/10 rounded-full blur-[130px] pointer-events-none -z-10" />

      <div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
        
        {/* Section Header */}
        <div className="text-center max-w-3xl mx-auto mb-16">
          <div className="inline-flex items-center gap-2 px-3.5 py-1.5 rounded-full bg-white dark:bg-white/5 border border-slate-200 dark:border-white/10 text-xs font-bold text-[#00A6DB] dark:text-[#00D7FF] mb-3 shadow-sm">
            <span className="w-2 h-2 rounded-full bg-[#00D7FF] animate-pulse" />
            TOKENOMICS & SPECIFICATIONS • {TOKENOMICS_VERSION}
          </div>

          <h2
            id="token-section-heading"
            className="font-display text-4xl sm:text-5xl font-black text-slate-900 dark:text-white tracking-tight flex items-center justify-center flex-wrap gap-2 sm:gap-3"
          >
            <span><span className="text-gradient-brand">BM ALPHA</span> TOKENOMICS</span>
            <span className="text-xs sm:text-sm font-mono font-bold px-3 py-1 rounded-full bg-[#FF8C32]/15 text-[#FF8C32] border border-[#FF8C32]/30 align-middle">
              {TOKENOMICS_VERSION}
            </span>
          </h2>
          <p className="mt-4 text-slate-600 dark:text-gray-400 text-base sm:text-lg font-medium">
            Transparent, community-focused, and 100% fixed 10 Billion token distribution built on Solana.
          </p>
        </div>

        {/* Main Token Hub Card */}
        <div className="relative rounded-3xl bg-white/90 dark:bg-[#161b2b]/90 border border-slate-200 dark:border-white/10 p-6 sm:p-10 shadow-xl dark:shadow-2xl backdrop-blur-xl mb-12">
          
          {/* Top Token Overview Bar */}
          <div className="flex flex-col lg:flex-row items-center justify-between gap-8 pb-10 border-b border-slate-200 dark:border-white/5">
            <div className="flex items-center gap-5">
              <div className="relative w-16 h-16 sm:w-20 sm:h-20 rounded-full p-1 bg-gradient-to-tr from-[#FF8C32] to-[#00D7FF] shrink-0 shadow-[0_0_25px_rgba(255,140,50,0.4)]">
                <div className="w-full h-full rounded-full overflow-hidden bg-slate-100 dark:bg-[#0a0c14]">
                  <img src={coinImg} alt="BM Alpha" className="w-full h-full object-cover" />
                </div>
              </div>
              <div>
                <div className="flex items-center gap-3">
                  <h3 className="font-display text-2xl sm:text-3xl font-black text-slate-900 dark:text-white">
                    BM ALPHA
                  </h3>
                  <span className="px-2.5 py-0.5 rounded-full bg-[#FF8C32]/15 text-[#FF8C32] border border-[#FF8C32]/30 font-mono text-xs font-bold">
                    $BMALPHA
                  </span>
                </div>
                <p className="text-slate-500 dark:text-gray-400 text-xs sm:text-sm mt-1">
                  Solana Program Library (SPL) Token • BirthdayMessaging Ecosystem
                </p>
              </div>
            </div>

            {/* Contract Address Box & Copy Action */}
            <div className="w-full lg:w-auto flex flex-col sm:flex-row items-stretch sm:items-center gap-3">
              <div className="flex flex-col px-4 py-2.5 rounded-xl bg-slate-50 dark:bg-white/5 border border-slate-200 dark:border-white/10 min-w-[260px]">
                <span className="text-[9px] font-bold text-slate-500 dark:text-gray-400 uppercase tracking-widest">
                  Contract Address
                </span>
                <span className="font-mono text-xs sm:text-sm font-semibold text-slate-800 dark:text-gray-200 truncate">
                  {CONTRACT_ADDRESS}
                </span>
              </div>

              <button
                id="copy-contract-btn"
                type="button"
                onClick={handleCopy}
                className="flex items-center justify-center gap-2 px-6 py-3.5 rounded-full font-display font-extrabold text-xs sm:text-sm text-black bg-[#FF8C32] hover:bg-[#E6761D] shadow-[0_0_20px_rgba(255,140,50,0.35)] transition-all active:scale-95 whitespace-nowrap cursor-pointer"
              >
                {copied ? (
                  <>
                    <Check className="w-4 h-4 text-black" />
                    <span>COPIED TO CLIPBOARD!</span>
                  </>
                ) : (
                  <>
                    <Copy className="w-4 h-4 text-black" />
                    <span>COPY CONTRACT ADDRESS</span>
                  </>
                )}
              </button>
            </div>
          </div>

          {/* 6 Metric Specs Cards */}
          <div className="grid grid-cols-2 lg:grid-cols-3 gap-4 sm:gap-6 my-10">
            {specs.map((item, index) => {
              const Icon = item.icon;
              return (
                <div
                  key={index}
                  className="p-5 rounded-2xl bg-slate-50 dark:bg-white/5 border border-slate-200 dark:border-white/10 hover:border-[#00D7FF]/40 transition-all hover:bg-slate-100 dark:hover:bg-white/[0.08] group"
                >
                  <div className="flex items-center justify-between mb-3">
                    <span className="text-xs font-bold uppercase tracking-wider text-slate-500 dark:text-gray-400">
                      {item.label}
                    </span>
                    <Icon className={`w-4 h-4 ${item.color} group-hover:scale-110 transition-transform`} />
                  </div>
                  <div className={`font-display text-lg sm:text-2xl font-black ${item.label === 'Total Supply' ? 'text-slate-900 dark:text-white' : item.color}`}>
                    {item.value}
                  </div>
                  <div className="text-[11px] font-medium text-slate-500 dark:text-gray-400 mt-1">
                    {item.sub}
                  </div>
                </div>
              );
            })}
          </div>

          {/* Interactive Tokenomics Dashboard Component */}
          <TokenomicsDashboard />

        </div>

      </div>
    </section>
  );
};
