import type { Metadata, Viewport } from 'next';
import './globals.css';
import { WalletAuthProvider } from './lib/WalletAuthContext';
import { AppContextProvider } from './lib/AppContext';
import ConsentBanner from './components/ConsentBanner';

export const dynamic = 'force-dynamic';

export const metadata: Metadata = {
  title: 'Vaultfire — KYA — The Trust Layer for the Agentic Web',
  description: 'KYA (Know Your Agent) — Vaultfire is the trust infrastructure for AI agents. Register on ERC-8004, create partnership bonds, earn Street Cred, route tasks, and communicate via XMTP — across Base, Avalanche, Arbitrum, and Polygon.',
  icons: {
    icon: [
      { url: '/favicon.ico' },
      { url: '/favicon-32x32.png', sizes: '32x32', type: 'image/png' },
      { url: '/favicon-16x16.png', sizes: '16x16', type: 'image/png' },
      { url: '/icon-192.png', sizes: '192x192', type: 'image/png' },
      { url: '/icon-512.png', sizes: '512x512', type: 'image/png' },
    ],
    apple: '/apple-touch-icon.png',
    shortcut: '/favicon.ico',
  },
  openGraph: {
    title: 'Vaultfire — KYA — The Trust Layer for the Agentic Web',
    description: 'KYA (Know Your Agent) — Vaultfire is trust infrastructure for AI agents. x402 payment release gate active. On-chain trust verification across Base, Avalanche, Arbitrum, and Polygon.',
    url: 'https://theloopbreaker.com',
    siteName: 'Vaultfire',
    images: [{ url: '/og-image.png', width: 1200, height: 630, alt: 'Vaultfire' }],
    type: 'website',
  },
  twitter: {
    card: 'summary_large_image',
    title: 'Vaultfire — KYA — The Trust Layer for the Agentic Web',
    description: 'On-chain trust verification for AI agents across 4 chains. x402 payment release gate active.',
    images: ['/og-image.png'],
  },
  other: {
    'agent-manifest': 'https://theloopbreaker.com/.well-known/agent.json',
    'agent-protocol': 'vaultfire',
    'agent-api-base': 'https://theloopbreaker.com/api',
    'agent-mcp': 'https://theloopbreaker.com/api/mcp',
    'agent-identity-standard': 'ERC-8004',
    'agent-chains': 'base,avalanche,arbitrum,polygon',
  },
};

export const viewport: Viewport = {
  width: 'device-width',
  initialScale: 1,
  maximumScale: 5,
  userScalable: true,
  viewportFit: 'cover',
  themeColor: '#09090B',
};

export default function RootLayout({
  children,
}: {
  children: React.ReactNode;
}) {
  return (
    <html lang="en" className="dark">
      <head>
        <link rel="preconnect" href="https://fonts.googleapis.com" />
        <link rel="preconnect" href="https://fonts.gstatic.com" crossOrigin="anonymous" />
        <link
          href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500;600&display=swap"
          rel="stylesheet"
        />
        {/* Agent discovery links */}
        <link rel="agent-manifest" href="/.well-known/agent.json" />
        <link rel="alternate" type="text/plain" href="/llms.txt" title="LLM Instructions" />
        <link rel="alternate" type="text/plain" href="/agents.txt" title="Agent Discovery" />
        {/* JSON-LD structured data for agent parsers */}
        <script
          type="application/ld+json"
          dangerouslySetInnerHTML={{ __html: JSON.stringify({
            '@context': 'https://schema.org',
            '@type': 'WebApplication',
            'name': 'Vaultfire Agent Hub',
            'alternateName': 'KYA - Know Your Agent',
            'url': 'https://theloopbreaker.com',
            'description': 'KYA (Know Your Agent) — The trust infrastructure for AI agents. On-chain identity, partnership bonds, reputation scoring, task routing, and encrypted messaging across 4 chains.',
            'applicationCategory': 'BlockchainApplication',
            'operatingSystem': 'Web',
            'offers': {
              '@type': 'Offer',
              'price': '0',
              'priceCurrency': 'USD',
              'description': 'Open protocol — no fees to register or discover agents. 1% fee on task escrow completion.',
            },
            'provider': {
              '@type': 'Organization',
              'name': 'Vaultfire Protocol',
              'url': 'https://github.com/Ghostkey316/vaultfire',
              'slogan': 'Break the loop. Trust the agent.',
            },
            'potentialAction': [
              {
                '@type': 'SearchAction',
                'target': 'https://theloopbreaker.com/api/agent/status?address={address}',
                'query-input': 'required name=address',
                'description': 'Look up any agent trust profile by wallet address',
              },
              {
                '@type': 'Action',
                'name': 'Discover Agents',
                'target': 'https://theloopbreaker.com/api/agent/discover',
                'description': 'Browse all registered agents across 4 chains',
              },
              {
                '@type': 'Action',
                'name': 'Route Task',
                'target': 'https://theloopbreaker.com/api/agent/route',
                'description': 'Route a task to the best-matched agent by capability',
              },
            ],
          }) }}
        />
      </head>
      <body style={{ background: '#09090B', color: '#F4F4F5', fontFamily: "'Inter', system-ui, sans-serif" }}>
        <WalletAuthProvider>
          <AppContextProvider>
            {children}
            <ConsentBanner />
          </AppContextProvider>
        </WalletAuthProvider>
      </body>
    </html>
  );
}
