const { useState } = React;

// WEVM Logo SVG Component
const WevmLogo = () => (
  <svg width="80" height="16" viewBox="0 0 311 63" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" className="block text-white">
    <path d="M17.24 61.12C16.52 53.28 15.68 45.8 14.72 38.68C13.84 31.48 12.96 24.48 12.08 17.68C11.84 16 11.48 14.96 11 14.56C10.52 14.08 9.92 13.84 9.2 13.84C7.68 13.84 5.8 15.24 3.56 18.04L0.8 14.8C4.08 10.32 7.2 6.92 10.16 4.6C13.12 2.28 16.08 1.12 19.04 1.12C22.16 1.12 24.48 2.04 26 3.88C27.52 5.72 28.48 8.56 28.88 12.4C29.44 17.2 29.92 22.24 30.32 27.52C30.72 32.8 31.08 38.08 31.4 43.36C34.68 37.04 37.92 30.6 41.12 24.04C44.4 17.48 47.6 10.76 50.72 3.88H61.16C61.56 6.52 61.96 9.68 62.36 13.36C62.76 16.96 63.16 20.8 63.56 24.88C64.04 28.88 64.48 32.8 64.88 36.64C65.28 40.48 65.68 43.96 66.08 47.08C68.8 43.4 71.32 39.76 73.64 36.16C75.96 32.56 78.24 28.76 80.48 24.76L79.04 20.56C78.48 18.96 77.92 17.32 77.36 15.64C76.8 13.96 76.52 12.36 76.52 10.84C76.52 7.4 77.52 4.88 79.52 3.28C81.52 1.6 83.92 0.76 86.72 0.76C87.84 0.76 88.88 0.96 89.84 1.36C90.8 1.68 91.56 2.04 92.12 2.44C92.76 3.4 93.2 4.4 93.44 5.44C93.68 6.48 93.8 7.92 93.8 9.76C93.8 11.52 93.44 13.48 92.72 15.64C92.08 17.8 90.72 20.8 88.64 24.64C85.68 30 81.8 35.88 77 42.28C72.28 48.6 66.92 54.88 60.92 61.12L52.16 62.08L50.96 61.12C50.56 58.08 50.12 54.56 49.64 50.56C49.16 46.48 48.68 42.4 48.2 38.32C47.72 34.16 47.24 30.44 46.76 27.16C44.04 32.52 41.08 38.16 37.88 44.08C34.76 50 31.56 55.68 28.28 61.12L18.56 62.08L17.24 61.12Z" fill="currentColor"/>
    <path d="M125.84 7.72C124.16 7.72 122.36 8.44 120.44 9.88C118.6 11.24 116.84 13.16 115.16 15.64C113.48 18.12 112.04 20.96 110.84 24.16C109.72 27.36 109.08 30.72 108.92 34.24C114.36 32.32 118.64 30.2 121.76 27.88C124.88 25.48 127.08 23.04 128.36 20.56C129.64 18.08 130.28 15.76 130.28 13.6C130.28 11.6 129.84 10.12 128.96 9.16C128.08 8.2 127.04 7.72 125.84 7.72ZM113 62.8C106.76 62.8 101.68 60.8 97.76 56.8C93.92 52.8 92 47.28 92 40.24C92 35.04 92.88 30.12 94.64 25.48C96.48 20.76 99 16.6 102.2 13C105.4 9.32 109.16 6.44 113.48 4.36C117.8 2.2 122.48 1.12 127.52 1.12C132.96 1.12 137.08 2.32 139.88 4.72C142.76 7.12 144.2 10.24 144.2 14.08C144.2 19.12 141.32 23.84 135.56 28.24C129.88 32.56 121.08 36.2 109.16 39.16C109.56 43 110.8 45.84 112.88 47.68C114.96 49.52 117.64 50.44 120.92 50.44C124.44 50.44 127.56 49.56 130.28 47.8C133 46.04 135.28 44 137.12 41.68L140.48 44.08C138.88 47.12 136.72 50.08 134 52.96C131.36 55.84 128.28 58.2 124.76 60.04C121.24 61.88 117.32 62.8 113 62.8Z" fill="currentColor"/>
    <path d="M164.24 61.12C163.44 53.28 162.6 45.84 161.72 38.8C160.92 31.68 160.04 24.68 159.08 17.8C158.84 16.04 158.44 14.96 157.88 14.56C157.4 14.08 156.84 13.84 156.2 13.84C155.48 13.84 154.64 14.16 153.68 14.8C152.8 15.44 151.76 16.52 150.56 18.04L147.8 14.8C151.08 10.32 154.2 6.92 157.16 4.6C160.12 2.28 163.12 1.12 166.16 1.12C169.2 1.12 171.48 2.08 173 4C174.52 5.92 175.52 8.84 176 12.76C176.64 18.36 177.2 24.16 177.68 30.16C178.16 36.08 178.6 42.04 179 48.04C184.84 40.44 190 32.56 194.48 24.4L193.28 20.44C192.72 18.84 192.16 17.24 191.6 15.64C191.12 13.96 190.88 12.36 190.88 10.84C190.88 7.4 191.8 4.88 193.64 3.28C195.56 1.6 197.96 0.76 200.84 0.76C201.96 0.76 203 0.96 203.96 1.36C205 1.68 205.8 2.04 206.36 2.44C207 3.4 207.44 4.4 207.68 5.44C207.92 6.48 208.04 7.92 208.04 9.76C208.04 11.44 207.72 13.36 207.08 15.52C206.44 17.68 205.04 20.72 202.88 24.64C199.92 29.92 195.92 35.8 190.88 42.28C185.84 48.68 180.24 54.96 174.08 61.12L165.44 62.08L164.24 61.12Z" fill="currentColor"/>
    <path d="M228.4 61L212.8 61.96L211.12 60.52L220.96 13.6L212.56 12.28L213.4 7.84L237.88 1L240.16 2.92L238.12 13.48C242.12 9.64 246.16 6.64 250.24 4.48C254.4 2.24 258.32 1.12 262 1.12C264.64 1.12 266.84 1.96 268.6 3.64C270.36 5.32 271.24 7.84 271.24 11.2C271.24 11.6 271.24 12.04 271.24 12.52C271.24 12.92 271.2 13.32 271.12 13.72C275.12 9.72 279.16 6.64 283.24 4.48C287.4 2.24 291.32 1.12 295 1.12C297.56 1.12 299.72 1.96 301.48 3.64C303.24 5.32 304.12 7.84 304.12 11.2C304.12 12.8 303.96 14.48 303.64 16.24C303.4 18 303.04 19.8 302.56 21.64L296.92 44.32C296.6 45.44 296.32 46.44 296.08 47.32C295.92 48.12 295.84 48.84 295.84 49.48C295.84 51.08 296.48 51.88 297.76 51.88C299.76 51.88 302.72 49.4 306.64 44.44L310.24 46.84C308.64 49.56 306.68 52.16 304.36 54.64C302.12 57.04 299.52 59 296.56 60.52C293.68 62.04 290.48 62.8 286.96 62.8C284.16 62.8 281.96 62.16 280.36 60.88C278.84 59.52 278.08 57.64 278.08 55.24C278.08 53.4 278.28 51.52 278.68 49.6C279.16 47.68 279.64 45.84 280.12 44.08L284.56 26.08C285.04 24.24 285.4 22.56 285.64 21.04C285.96 19.44 286.12 18.16 286.12 17.2C286.12 15.84 285.8 14.88 285.16 14.32C284.6 13.76 283.88 13.48 283 13.48C281.32 13.48 279.36 14.04 277.12 15.16C274.96 16.28 272.56 18.04 269.92 20.44L266.8 35.32C265.92 39.56 265.04 43.84 264.16 48.16C263.36 52.4 262.56 56.68 261.76 61L246.16 61.96L244.48 60.52L251.92 24.76C252.32 23.16 252.64 21.72 252.88 20.44C253.12 19.08 253.24 17.92 253.24 16.96C253.24 15.76 252.92 14.88 252.28 14.32C251.72 13.76 251 13.48 250.12 13.48C248.36 13.48 246.36 14.04 244.12 15.16C241.88 16.28 239.4 18 236.68 20.32L233.44 35.32C232.56 39.56 231.72 43.84 230.92 48.16C230.12 52.4 229.28 56.68 228.4 61Z" fill="currentColor"/>
  </svg>
);

// Projects Data List
const projectsList = [
  {
    name: 'viem',
    desc: 'TypeScript interface for Ethereum that provides low-level primitives for interacting with Ethereum.',
    stars: '6.4k',
    downloads: '14.2m/mo',
    url: 'https://viem.sh',
    github: 'https://github.com/wevm/viem',
    badge: 'Core Primitive',
    snippet: `import { createPublicClient, http } from 'viem'
import { mainnet } from 'viem/chains'

const client = createPublicClient({
  chain: mainnet,
  transport: http(),
})

const blockNumber = await client.getBlockNumber()
console.log('Latest Mainnet Block:', blockNumber)`
  },
  {
    name: 'wagmi',
    desc: 'React Hooks for Ethereum. Used by Uniswap, OpenSea, Stripe, and Coinbase.',
    stars: '5.8k',
    downloads: '8.6m/mo',
    url: 'https://wagmi.sh',
    github: 'https://github.com/wevm/wagmi',
    badge: 'React Library',
    snippet: `import { useAccount, useConnect, useDisconnect } from 'wagmi'

function App() {
  const { address, isConnected } = useAccount()
  const { connect, connectors } = useConnect()

  if (isConnected) return <div>Connected: {address}</div>
  return <button onClick={() => connect({ connector: connectors[0] })}>Connect Wallet</button>
}`
  },
  {
    name: 'vocs',
    desc: 'Minimal, fast static site generator built for developer documentation powered by React & Vite.',
    stars: '1.2k',
    downloads: '420k/mo',
    url: 'https://vocs.dev',
    github: 'https://github.com/wevm/vocs',
    badge: 'Documentation',
    snippet: `// vocs.config.ts
import { defineConfig } from 'vocs'

export default defineConfig({
  title: 'Wevm Docs',
  sidebar: [
    { text: 'Getting Started', link: '/docs/getting-started' },
    { text: 'API Reference', link: '/docs/api' },
  ],
})`
  },
  {
    name: 'curl.md',
    desc: 'Convert any web page or documentation URL to clean Markdown instantly for AI agents.',
    stars: '840',
    downloads: '180k/mo',
    url: 'https://curl.md',
    github: 'https://github.com/wevm/curl.md',
    badge: 'AI Utility',
    snippet: `$ curl https://curl.md/https://viem.sh
# Viem Documentation
TypeScript Interface for Ethereum...`
  },
  {
    name: 'abitype',
    desc: 'Strict TypeScript types for Ethereum ABIs with ultra-fast type inference.',
    stars: '890',
    downloads: '18.4m/mo',
    url: 'https://abitype.dev',
    github: 'https://github.com/wevm/abitype',
    badge: 'TypeScript Core',
    snippet: `import { parseAbi } from 'abitype'

const abi = parseAbi([
  'function balanceOf(address owner) view returns (uint256)',
  'event Transfer(address indexed from, address indexed to, uint256 value)',
])`
  },
  {
    name: 'incur',
    desc: 'Command-line tool suite & micro-utility runners for open-source TypeScript workflows.',
    stars: '310',
    downloads: '95k/mo',
    url: 'https://github.com/wevm/incur',
    github: 'https://github.com/wevm/incur',
    badge: 'CLI Tool',
    snippet: `$ npx incur@latest init
✓ Created incur config for workspace`
  },
  {
    name: 'mppx',
    desc: 'Micropayments protocol for instant low-friction developer api monetization.',
    stars: '260',
    downloads: '40k/mo',
    url: 'https://github.com/wevm/mppx',
    github: 'https://github.com/wevm/mppx',
    badge: 'Protocol',
    snippet: `import { mppx } from 'mppx'

const payment = await mppx.requestPayment({
  amount: '0.001',
  recipient: '0x123...'
})`
  }
];

// Sponsors / Enterprise Logos
const sponsors = [
  'Paradigm', 'Tempo', 'Coinbase', 'Stripe', 'Brave', 'Cloudflare', 'Shopify', 'Vercel', 'MetaMask', 'Polymarket', 'Uniswap', 'Zora', 'ENS', 'OpenSea'
];

function App() {
  const [activeTab, setActiveTab] = useState('viem');
  const [outputConsole, setOutputConsole] = useState('');
  const [isRunning, setIsRunning] = useState(false);

  const selectedProject = projectsList.find(p => p.name === activeTab) || projectsList[0];

  const handleRunSnippet = () => {
    setIsRunning(true);
    setOutputConsole('Executing TypeScript snippet...');
    setTimeout(() => {
      if (activeTab === 'viem') {
        setOutputConsole(`✓ Connected to Ethereum Mainnet RPC\n> Latest Block: #20,481,932\n> Gas Price: 12.4 Gwei\n> Chain ID: 1`);
      } else if (activeTab === 'wagmi') {
        setOutputConsole(`✓ Injected Connector Ready (MetaMask / Coinbase Wallet)\n> Account Status: Disconnected\n> Available Connectors: [Injected, WalletConnect, CoinbaseWallet]`);
      } else if (activeTab === 'vocs') {
        setOutputConsole(`✓ Vocs Documentation Server Started\n> Local: http://localhost:5173/\n> Pages compiled: 14 pages in 180ms`);
      } else if (activeTab === 'abitype') {
        setOutputConsole(`✓ Inferred ABI Types cleanly\n> Types extracted: 2 functions, 1 event\n> Zero type errors.`);
      } else {
        setOutputConsole(`✓ Code compiled & executed cleanly.`);
      }
      setIsRunning(false);
    }, 600);
  };

  return (
    <div className="p-4 sm:p-8 md:p-14 min-h-screen">
      <div className="mx-auto max-w-[880px]">
        {/* Main Panel Box */}
        <div className="border border-[#262626] bg-[#111111] p-6 sm:p-10 md:p-12 shadow-2xl">
          
          {/* Header */}
          <header className="mb-10 flex flex-col sm:flex-row sm:items-center justify-between gap-4 border-b border-dashed border-[#262626] pb-6">
            <div className="flex items-center gap-3">
              <WevmLogo />
            </div>

            {/* Stats Badges */}
            <div className="flex flex-wrap gap-2.5 font-mono">
              <a
                href="https://www.npmjs.com/org/wevm"
                target="_blank"
                rel="noopener noreferrer"
                className="inline-flex h-7 items-center gap-2 border border-dashed border-[#333333] bg-[#0c0c0c] px-2.5 text-[11px] uppercase tracking-wider text-white hover:bg-white hover:text-black transition-colors"
              >
                <span className="text-[#888888]">NPM</span>
                <span className="font-bold">81,986,738</span>
                <span className="text-[#888888]">DL/MO</span>
              </a>

              <a
                href="https://github.com/wevm"
                target="_blank"
                rel="noopener noreferrer"
                className="inline-flex h-7 items-center gap-2 border border-dashed border-[#333333] bg-[#0c0c0c] px-2.5 text-[11px] uppercase tracking-wider text-white hover:bg-white hover:text-black transition-colors"
              >
                <span className="text-[#888888]">GH</span>
                <span className="font-bold">13,560</span>
                <span className="text-[#888888]">STARS</span>
              </a>
            </div>
          </header>

          {/* Hero Section */}
          <section className="mb-12">
            <h1 className="text-4xl sm:text-6xl font-bold leading-none tracking-tight mb-4">
              TypeScript tools<br />
              for the <span className="font-serif font-normal italic pr-1">frontier</span>
            </h1>

            <p className="max-w-[56ch] text-base sm:text-lg text-[#888888] leading-relaxed mb-6 font-sans">
              <strong className="text-white font-semibold">Wevm</strong> is an open-source collective building TypeScript software used by hundreds of enterprise organizations and millions of developers worldwide.
            </p>

            <div className="flex flex-wrap gap-3 mb-8">
              <a
                href="https://github.com/wevm"
                target="_blank"
                rel="noopener noreferrer"
                className="inline-flex items-center gap-2 border border-white bg-white text-black px-4 py-2 text-xs font-mono font-medium hover:bg-transparent hover:text-white transition-colors"
              >
                GitHub →
              </a>
              <a
                href="https://github.com/sponsors/wevm"
                target="_blank"
                rel="noopener noreferrer"
                className="inline-flex items-center gap-2 border border-[#333333] bg-[#0c0c0c] text-white px-4 py-2 text-xs font-mono font-medium hover:border-white transition-colors"
              >
                Sponsor →
              </a>
              <a
                href="mailto:dev@wevm.dev"
                className="inline-flex items-center gap-2 border border-[#333333] bg-[#0c0c0c] text-white px-4 py-2 text-xs font-mono font-medium hover:border-white transition-colors"
              >
                dev@wevm.dev
              </a>
            </div>

            {/* Enterprise Marquee Ticker */}
            <div className="border-y border-dashed border-[#262626] py-3 overflow-hidden">
              <span className="text-[10px] uppercase font-mono text-[#888888] tracking-widest block mb-2">
                Trusted in production by
              </span>
              <div className="flex w-max animate-marquee space-x-8 text-xs font-mono text-white/80">
                {sponsors.concat(sponsors).map((s, idx) => (
                  <span key={idx} className="flex items-center gap-2 opacity-75 hover:opacity-100 transition-opacity">
                    <span>◈</span>
                    <span>{s}</span>
                  </span>
                ))}
              </div>
            </div>
          </section>

          {/* Interactive Library Playground Section */}
          <section className="mb-14 p-6 border border-[#262626] bg-[#0c0c0c] rounded-none">
            <div className="flex flex-col sm:flex-row justify-between items-start sm:items-center gap-4 mb-4 pb-3 border-b border-[#262626]">
              <div>
                <span className="text-[10px] uppercase tracking-widest font-mono text-white/50 block">Interactive Sandbox</span>
                <h3 className="text-xl font-bold font-sans text-white">Live Code Tester</h3>
              </div>

              {/* Selector Tabs */}
              <div className="flex flex-wrap gap-1 font-mono text-xs">
                {['viem', 'wagmi', 'vocs', 'abitype'].map(key => (
                  <button
                    key={key}
                    onClick={() => { setActiveTab(key); setOutputConsole(''); }}
                    className={`px-3 py-1 border ${activeTab === key ? 'border-white bg-white text-black font-bold' : 'border-[#262626] text-[#888888] hover:text-white'}`}
                  >
                    {key}
                  </button>
                ))}
              </div>
            </div>

            {/* Code Block */}
            <div className="bg-[#111111] p-4 font-mono text-xs text-emerald-400 border border-[#262626] mb-4 overflow-x-auto custom-scrollbar">
              <pre className="whitespace-pre-wrap leading-relaxed">{selectedProject.snippet}</pre>
            </div>

            <div className="flex justify-between items-center">
              <button
                onClick={handleRunSnippet}
                disabled={isRunning}
                className="inline-flex items-center gap-2 border border-white bg-white text-black px-4 py-2 text-xs font-mono font-bold hover:bg-[#111111] hover:text-white transition-colors"
              >
                {isRunning ? 'Running...' : 'Run Snippet →'}
              </button>

              <a
                href={selectedProject.url}
                target="_blank"
                rel="noopener noreferrer"
                className="text-xs font-mono text-[#888888] hover:text-white underline"
              >
                Visit {selectedProject.name} docs ↗
              </a>
            </div>

            {/* Console Output */}
            {outputConsole && (
              <div className="mt-4 p-3 bg-black border border-dashed border-[#333333] font-mono text-xs text-white/90 animate-fade-up">
                <span className="text-white/40 block text-[10px] uppercase mb-1">Terminal Output</span>
                <pre className="whitespace-pre-wrap">{outputConsole}</pre>
              </div>
            )}
          </section>

          {/* Projects Grid */}
          <section className="mb-14">
            <div className="mb-6 flex justify-between items-center border-b border-dashed border-[#262626] pb-3">
              <h2 className="text-2xl font-bold font-sans text-white">Open Source Projects</h2>
              <span className="text-xs font-mono text-[#888888]">{projectsList.length} Active Libraries</span>
            </div>

            <div className="grid grid-cols-1 gap-6">
              {projectsList.map((p, idx) => (
                <div
                  key={idx}
                  className="border border-[#262626] bg-[#0c0c0c] p-6 hover:border-white transition-colors group"
                >
                  <div className="flex flex-col sm:flex-row sm:items-center justify-between gap-2 mb-3">
                    <div className="flex items-center gap-3">
                      <a
                        href={p.url}
                        target="_blank"
                        rel="noopener noreferrer"
                        className="text-2xl font-bold font-mono text-white group-hover:underline flex items-center gap-2"
                      >
                        {p.name}
                        <span className="text-xs font-mono text-[#888888] group-hover:translate-x-1 transition-transform">↗</span>
                      </a>
                      <span className="text-[10px] uppercase font-mono px-2 py-0.5 border border-[#333333] text-[#888888]">
                        {p.badge}
                      </span>
                    </div>

                    <div className="flex items-center gap-3 text-xs font-mono text-[#888888]">
                      <span>★ {p.stars}</span>
                      <span>↓ {p.downloads}</span>
                    </div>
                  </div>

                  <p className="text-sm text-[#888888] font-sans leading-relaxed mb-4">
                    {p.desc}
                  </p>

                  <div className="flex gap-4 text-xs font-mono">
                    <a
                      href={p.url}
                      target="_blank"
                      rel="noopener noreferrer"
                      className="text-white hover:underline"
                    >
                      Website
                    </a>
                    <a
                      href={p.github}
                      target="_blank"
                      rel="noopener noreferrer"
                      className="text-[#888888] hover:text-white hover:underline"
                    >
                      GitHub Repo
                    </a>
                  </div>
                </div>
              ))}
            </div>
          </section>

          {/* Team / Maintainers Section */}
          <section className="mb-10 pt-6 border-t border-dashed border-[#262626]">
            <h2 className="text-xl font-bold font-sans text-white mb-4">Maintainers</h2>
            
            <div className="grid grid-cols-1 sm:grid-cols-2 gap-4">
              {/* tmm */}
              <a
                href="https://github.com/tmm"
                target="_blank"
                rel="noopener noreferrer"
                className="flex items-center gap-3 border border-[#262626] bg-[#0c0c0c] p-4 hover:border-white transition-colors"
              >
                <img
                  src="https://github.com/tmm.png?size=84"
                  alt="tmm avatar"
                  className="w-10 h-10 rounded-full border border-[#333333]"
                />
                <div>
                  <span className="font-mono text-sm font-bold text-white block">tmm</span>
                  <span className="text-xs font-sans text-[#888888]">@awkweb · Co-founder</span>
                </div>
              </a>

              {/* jxom */}
              <a
                href="https://github.com/jxom"
                target="_blank"
                rel="noopener noreferrer"
                className="flex items-center gap-3 border border-[#262626] bg-[#0c0c0c] p-4 hover:border-white transition-colors"
              >
                <img
                  src="https://github.com/jxom.png?size=84"
                  alt="jxom avatar"
                  className="w-10 h-10 rounded-full border border-[#333333]"
                />
                <div>
                  <span className="font-mono text-sm font-bold text-white block">jxom</span>
                  <span className="text-xs font-sans text-[#888888]">@_jxom · Co-founder</span>
                </div>
              </a>
            </div>
          </section>

          {/* Footer */}
          <footer className="pt-8 border-t border-dashed border-[#262626] flex flex-col sm:flex-row justify-between items-center gap-4 text-xs font-mono text-[#888888]">
            <div>© 2026 Wevm (weth, LLC). Open source software.</div>
            <div className="flex gap-4">
              <a href="https://github.com/wevm" target="_blank" rel="noopener noreferrer" className="hover:text-white">GitHub</a>
              <a href="https://x.com/wevm_devv" target="_blank" rel="noopener noreferrer" className="hover:text-white">X / Twitter</a>
              <a href="mailto:dev@wevm.dev" className="hover:text-white">Email</a>
            </div>
          </footer>

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

// Render Application to Root DOM
ReactDOM.render(<App />, document.getElementById('root'));
