import React from 'react';
import { X, Terminal, Cpu, Palette, Layout, Layers, Box, Code } from 'lucide-react';

interface BriefOverlayProps {
  isOpen: boolean;
  onClose: () => void;
}

export default function BriefOverlay({ isOpen, onClose }: BriefOverlayProps) {
  if (!isOpen) return null;

  return (
    <div className="fixed inset-0 bg-black/40 backdrop-blur-sm z-[200] flex justify-end transition-opacity duration-300">
      <div className="w-full max-w-2xl bg-white h-screen shadow-2xl flex flex-col overflow-hidden animate-slide-in">
        {/* Header */}
        <div className="px-6 py-5 bg-primary text-white flex items-center justify-between">
          <div className="flex items-center gap-3">
            <Terminal className="w-6 h-6 animate-pulse" />
            <div>
              <h2 className="text-xl font-bold tracking-tight">AI & Developer Brief</h2>
              <p className="text-xs text-primary-fixed opacity-90">Design System & Blueprint for HostKeeper</p>
            </div>
          </div>
          <button 
            onClick={onClose}
            className="p-1.5 hover:bg-white/10 rounded-lg transition-colors cursor-pointer text-white"
            title="Close brief"
          >
            <X className="w-6 h-6" />
          </button>
        </div>

        {/* Content */}
        <div className="flex-1 overflow-y-auto p-6 space-y-8 custom-scrollbar">
          {/* Intro Guidance */}
          <div className="bg-primary-container/10 border border-primary/20 rounded-xl p-4 text-sm text-on-surface">
            <span className="font-bold text-primary block mb-1">🤖 AI-to-AI / Developer System Instructions</span>
            This documentation is built directly into the codebase to guide downstream development agents. 
            Maintain the <strong className="text-primary">Bright-Tech / Lumina Terminal</strong> aesthetic. Avoid dark-mode-by-default stereotypes unless requested; focus on high-clarity slate cards, interactive neon accents, and crisp typography.
          </div>

          {/* Section: Palette */}
          <section className="space-y-3">
            <h3 className="font-bold text-on-background flex items-center gap-2 text-base">
              <Palette className="w-5 h-5 text-primary" />
              Colors (Lumina System)
            </h3>
            <div className="grid grid-cols-2 sm:grid-cols-3 gap-3">
              <div className="p-3 border border-outline-variant rounded-lg bg-surface-container-low text-xs">
                <div className="w-full h-8 rounded bg-[#0050cb] mb-1.5"></div>
                <p className="font-bold">Primary (Blue)</p>
                <code className="text-[10px] text-outline">#0050cb</code>
              </div>
              <div className="p-3 border border-outline-variant rounded-lg bg-surface-container-low text-xs">
                <div className="w-full h-8 rounded bg-[#006e2f] mb-1.5"></div>
                <p className="font-bold">Secondary (Green)</p>
                <code className="text-[10px] text-outline">#006e2f</code>
              </div>
              <div className="p-3 border border-outline-variant rounded-lg bg-surface-container-low text-xs">
                <div className="w-full h-8 rounded bg-[#7e23cc] mb-1.5"></div>
                <p className="font-bold">Tertiary (Purple)</p>
                <code className="text-[10px] text-outline">#7e23cc</code>
              </div>
              <div className="p-3 border border-outline-variant rounded-lg bg-surface-container-low text-xs">
                <div className="w-full h-8 rounded bg-[#f7f9fb] mb-1.5 border border-outline-variant/50"></div>
                <p className="font-bold">Surface Base</p>
                <code className="text-[10px] text-outline">#f7f9fb</code>
              </div>
              <div className="p-3 border border-outline-variant rounded-lg bg-surface-container-low text-xs">
                <div className="w-full h-8 rounded bg-white mb-1.5 border border-outline-variant/50"></div>
                <p className="font-bold">Container Lowest</p>
                <code className="text-[10px] text-outline">#ffffff</code>
              </div>
              <div className="p-3 border border-outline-variant rounded-lg bg-surface-container-low text-xs">
                <div className="w-full h-8 rounded bg-[#191c1e] mb-1.5"></div>
                <p className="font-bold">On Surface</p>
                <code className="text-[10px] text-outline">#191c1e</code>
              </div>
            </div>
          </section>

          {/* Section: Typography */}
          <section className="space-y-3">
            <h3 className="font-bold text-on-background flex items-center gap-2 text-base">
              <Code className="w-5 h-5 text-primary" />
              Typography Specifications
            </h3>
            <div className="border border-outline-variant rounded-xl divide-y divide-outline-variant/50 overflow-hidden text-sm">
              <div className="p-4 bg-surface-container-lowest">
                <p className="font-bold text-xs text-outline mb-1 uppercase tracking-wider">UI Font Pairing (Inter)</p>
                <p className="font-sans text-lg font-bold">Inter Sans-Serif</p>
                <p className="text-xs text-on-surface-variant">Used for all lists, forms, dashboard metrics, setting menus, and high-contrast labels.</p>
              </div>
              <div className="p-4 bg-surface-container-lowest font-mono">
                <p className="font-bold text-xs text-outline mb-1 uppercase tracking-wider font-sans">Technical Font (JetBrains Mono)</p>
                <p className="text-base font-medium">JetBrains Mono</p>
                <p className="text-xs text-on-surface-variant font-sans mt-1">Used for terminal outputs, commands, snippets, directory paths, and code metadata.</p>
              </div>
            </div>
          </section>

          {/* Section: Layout & Spacing */}
          <section className="space-y-3">
            <h3 className="font-bold text-on-background flex items-center gap-2 text-base">
              <Layout className="w-5 h-5 text-primary" />
              Layout & Spacing Architecture
            </h3>
            <ul className="list-disc pl-5 space-y-2 text-sm text-on-surface-variant">
              <li>
                <strong className="text-on-background">The Dot Grid Texture:</strong> A 16px background repeating dot grid system (<code className="text-xs bg-surface-container px-1 rounded">radial-gradient(#E2E8F0 1.5px, transparent 1.5px)</code>) anchors the content, providing depth and mimicking physical engineering logs.
              </li>
              <li>
                <strong className="text-on-background">Asymmetric Bento Sizing:</strong> Balance large focus modules (such as the active Terminal Session or SFTP local-remote streams) alongside secondary narrow utility sheets.
              </li>
              <li>
                <strong className="text-on-background">Standardized Metrics:</strong> Sidebar width is exactly <code className="text-xs bg-surface-container px-1 rounded">260px</code>. Terminal containers use <code className="text-xs bg-surface-container px-1 rounded">20px</code> internal padding.
              </li>
            </ul>
          </section>

          {/* Section: Elevation & Glassmorphism */}
          <section className="space-y-3">
            <h3 className="font-bold text-on-background flex items-center gap-2 text-base">
              <Layers className="w-5 h-5 text-primary" />
              Depth & Glassmorphism Rules
            </h3>
            <div className="grid grid-cols-1 sm:grid-cols-2 gap-4 text-xs">
              <div className="p-4 border border-outline-variant/60 rounded-xl space-y-1">
                <span className="font-bold text-primary text-xs uppercase tracking-wider block">Level 1: Translucency</span>
                <p className="text-on-surface-variant">Sidebars, Top App Bars, and overlay cards use <code className="text-[11px] bg-surface-container px-1 rounded">backdrop-blur-md</code> and semi-transparent backgrounds to overlay smoothly on background grid lines.</p>
              </div>
              <div className="p-4 border border-outline-variant/60 rounded-xl space-y-1">
                <span className="font-bold text-primary text-xs uppercase tracking-wider block">Level 2: Glowing States</span>
                <p className="text-on-surface-variant">Active focus objects should never look heavy. Apply accent borders (<code className="text-[11px] bg-surface-container px-1 rounded">border-primary</code>) and soft drop shadow glows of the accent color.</p>
              </div>
            </div>
          </section>

          {/* Section: Future Enhancements Blueprint */}
          <section className="space-y-3">
            <h3 className="font-bold text-on-background flex items-center gap-2 text-base">
              <Box className="w-5 h-5 text-primary" />
              AI Implementation Guidelines
            </h3>
            <div className="p-4 bg-surface-container-low rounded-xl text-xs space-y-2">
              <p>When modifying this code or adding database handlers:</p>
              <ol className="list-decimal pl-4 space-y-1.5 text-on-surface-variant">
                <li>Always maintain class structures using state routers instead of traditional pages for fluid interactions.</li>
                <li>Import standard icons only from <code className="text-xs font-mono text-primary font-bold">lucide-react</code>. Do not write custom inline SVG structures.</li>
                <li>Ensure interactive switches use the custom <code className="text-xs font-mono">checked</code> properties with transition toggles.</li>
                <li>For terminal commands, enhance the custom parser inside <code className="text-xs font-mono">TerminalView.tsx</code> to handle rich multi-line logs.</li>
              </ol>
            </div>
          </section>
        </div>

        {/* Footer */}
        <div className="p-4 border-t border-outline-variant bg-surface-container-low flex justify-between items-center text-xs text-outline font-medium">
          <span>Lumina Technical Blueprint v1.0</span>
          <span>Google AI Studio Build</span>
        </div>
      </div>
    </div>
  );
}
