// Shared layout for individual GEOKlar blog post pages

const POST_DARK_BG =
  "linear-gradient(to right, rgba(255,255,255,0.03) 1px, transparent 1px) 0 0 / 20px 20px," +
  "linear-gradient(to bottom, rgba(255,255,255,0.03) 1px, transparent 1px) 0 0 / 20px 20px," +
  "radial-gradient(circle at 30% 50%, #0f2654 0%, #050f22 100%)";

function BlogPostLayout({ title, category, date, readTime, imgBg, children }) {
  const heroBg = imgBg
    ? imgBg.replace(/linear-gradient\(135deg/, "linear-gradient(160deg")
    : POST_DARK_BG;
  return (
    <>
      {/* Prose styles — scoped to .geo-prose */}
      <style>{`
        .geo-prose { font-size: 16px; line-height: 1.78; color: #3a4a6b; }
        .geo-prose .lead { font-size: 18px; line-height: 1.65; color: #3a4a6b; margin-bottom: 36px; }
        .geo-prose h2 {
          font-family: 'DM Sans', sans-serif; font-size: 22px; font-weight: 600;
          color: #0a1f44; letter-spacing: -0.01em; line-height: 1.25;
          margin: 44px 0 16px;
        }
        .geo-prose h3 {
          font-family: 'DM Sans', sans-serif; font-size: 17px; font-weight: 600;
          color: #0a1f44; margin: 32px 0 12px; line-height: 1.3;
        }
        .geo-prose p { margin-bottom: 20px; }
        .geo-prose ul, .geo-prose ol { margin: 0 0 20px 22px; }
        .geo-prose li { margin-bottom: 9px; }
        .geo-prose strong { color: #0a1f44; font-weight: 600; }
        .geo-prose a { color: #8a6f2d; text-decoration: underline; }
        .geo-prose a:hover { color: #0a1f44; }
        .geo-prose blockquote {
          border-left: 3px solid #b8944a; padding: 14px 20px;
          background: #faf7f0; border-radius: 0 8px 8px 0; margin: 28px 0;
        }
        .geo-prose blockquote p { color: #3a4a6b; margin-bottom: 0; font-style: italic; }
        .geo-prose hr { border: none; border-top: 1px solid #e8e4d8; margin: 40px 0; }
        .geo-prose .callout {
          background: #faf7f0; border: 1px solid #e8e4d8; border-radius: 10px;
          padding: 20px 24px; margin: 28px 0;
        }
        .geo-prose .callout p { margin-bottom: 0; }
        .geo-prose ol.numbered { list-style: none; margin-left: 0; counter-reset: steps; }
        .geo-prose ol.numbered li {
          counter-increment: steps;
          padding-left: 40px; position: relative; margin-bottom: 16px;
        }
        .geo-prose ol.numbered li::before {
          content: counter(steps);
          position: absolute; left: 0; top: 1px;
          width: 26px; height: 26px; border-radius: 50%;
          background: #0a1f44; color: white;
          font-size: 12px; font-weight: 600; font-family: 'DM Sans', sans-serif;
          display: flex; align-items: center; justify-content: center;
        }
      `}</style>

      {/* ── Article hero ──────────────────────────────────────────── */}
      <section style={{
        background: heroBg,
        color: 'white',
        padding: '60px 0 56px',
        position: 'relative',
        overflow: 'hidden',
      }}>
        <div style={{
          position: 'absolute', inset: 0, pointerEvents: 'none',
          backgroundImage: 'linear-gradient(rgba(255,255,255,0.03) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,0.03) 1px, transparent 1px)',
          backgroundSize: '20px 20px',
        }}/>
        <div className="wrap-narrow" style={{ position: 'relative', zIndex: 1 }}>
          <a href="blog.html" style={{
            display: 'inline-flex', alignItems: 'center', gap: 6,
            fontSize: 13, color: 'rgba(255,255,255,0.55)', marginBottom: 28,
            textDecoration: 'none', transition: 'color .15s ease',
            fontWeight: 500,
          }}
            onMouseEnter={e => e.currentTarget.style.color = 'rgba(255,255,255,0.9)'}
            onMouseLeave={e => e.currentTarget.style.color = 'rgba(255,255,255,0.55)'}
          >← Tilbage til blog</a>

          <div style={{ marginBottom: 18 }}>
            <span style={{
              fontSize: 11, fontWeight: 600, letterSpacing: '0.10em',
              textTransform: 'uppercase', color: 'rgba(255,255,255,0.9)',
              background: 'rgba(184,148,74,0.25)', padding: '4px 12px',
              borderRadius: 100, border: '1px solid rgba(184,148,74,0.4)',
            }}>{category}</span>
          </div>

          <h1 style={{
            fontFamily: "'DM Sans', sans-serif", fontWeight: 600, color: 'white',
            fontSize: 'clamp(26px, 3.8vw, 42px)', lineHeight: 1.15,
            letterSpacing: '-0.02em', marginBottom: 24,
            maxWidth: '22ch', textWrap: 'balance',
          }}>{title}</h1>

          <div style={{ display: 'flex', alignItems: 'center', gap: 14, fontSize: 13, color: 'rgba(255,255,255,0.48)' }}>
            <span>{date}</span>
            <span>·</span>
            <span>{readTime} læsning</span>
          </div>
        </div>
      </section>

      {/* ── Article body ──────────────────────────────────────────── */}
      <section style={{ padding: '60px 0 88px', background: 'white' }}>
        <div className="geo-prose" style={{ maxWidth: 680, margin: '0 auto', padding: '0 32px' }}>
          {children}
        </div>
      </section>

      {/* ── Bottom CTA ────────────────────────────────────────────── */}
      <section style={{
        padding: '72px 0',
        background: 'var(--bg-warm)',
        borderTop: '1px solid var(--line)',
      }}>
        <div className="wrap-narrow" style={{ textAlign: 'center' }}>
          <span className="eyebrow" style={{ marginBottom: 16, display: 'inline-block' }}>Gratis analyse</span>
          <h2 className="h2" style={{ marginBottom: 16, fontSize: 'clamp(24px, 3vw, 36px)' }}>
            Er din virksomhed synlig i AI?
          </h2>
          <p style={{ fontSize: 16, color: 'var(--ink-2)', marginBottom: 32, maxWidth: '48ch', margin: '0 auto 32px', lineHeight: 1.6 }}>
            Find ud af det på 5 minutter med vores gratis GEO-analyse — 100 prompts på tværs af ChatGPT, Claude, Perplexity og Gemini.
          </p>
          <div style={{ display: 'inline-flex', gap: 12, flexWrap: 'wrap', justifyContent: 'center' }}>
            <a href="index.html#audit" className="btn btn-gold btn-lg">
              Få gratis analyse <Icon.arrow/>
            </a>
            <a href="blog.html" className="btn btn-outline">
              ← Alle indlæg
            </a>
          </div>
        </div>
      </section>
    </>
  );
}

Object.assign(window, { BlogPostLayout });
