---
import '../styles/global.css';

interface Props {
  title: string;
  description: string;
  ogImage?: string;
}

const { title, description, ogImage } = Astro.props;
const siteUrl = import.meta.env.SITE_URL || 'http://localhost:4321';
const ogImageUrl = ogImage || `${siteUrl}/og-default.png`;
---
<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>{title}</title>
  <meta name="description" content={description} />
  <meta name="robots" content="index, follow" />
  <link rel="canonical" href={Astro.url.href} />

  <link rel="preconnect" href="https://fonts.googleapis.com">
  <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
  <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&family=Manrope:wght@400;500;600;700;800&display=swap" rel="stylesheet">
  <link href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:wght,FILL@100..700,0..1&display=swap" rel="stylesheet">

  <meta property="og:type" content="website" />
  <meta property="og:title" content={title} />
  <meta property="og:description" content={description} />
  <meta property="og:url" content={Astro.url.href} />
  <meta property="og:image" content={ogImageUrl} />
  <meta property="og:site_name" content="知习 AI" />

  <meta name="twitter:card" content="summary_large_image" />
  <meta name="twitter:title" content={title} />
  <meta name="twitter:description" content={description} />
  <meta name="twitter:image" content={ogImageUrl} />

  <link rel="icon" type="image/svg+xml" href="/favicon.svg" />
</head>
<body class="antialiased overflow-x-hidden selection:bg-blue-100">
  <div id="global-progress" class="fixed top-0 left-0 h-[3px] bg-gradient-to-r from-primary via-tech-blue to-secondary z-[9999] transition-[width]" style="width: 0%; border-radius: 0 3px 3px 0; box-shadow: 0 0 8px rgba(21, 80, 211, 0.3);"></div>
  <slot />
</body>
<script>
  const bar = document.getElementById('global-progress');
  function updateProgress() {
    const scrollTop = window.scrollY;
    const docHeight = document.documentElement.scrollHeight - window.innerHeight;
    const progress = docHeight > 0 ? Math.min((scrollTop / docHeight) * 100, 100) : 0;
    bar.style.width = progress + '%';
  }
  window.addEventListener('scroll', updateProgress, { passive: true });
  window.addEventListener('resize', updateProgress, { passive: true });
  updateProgress();

  const revealObserver = new IntersectionObserver((entries) => {
    entries.forEach(entry => {
      if (entry.isIntersecting) {
        entry.target.classList.add('revealed');
      }
    });
  }, { threshold: 0.15, rootMargin: '0px 0px -40px 0px' });

  document.querySelectorAll('.animate-reveal-up').forEach(el => revealObserver.observe(el));
</script>
</html>
