@extends('frontend.layouts.app')
@php
    $__canon    = rtrim(\App\Models\Setting::get('seo_canonical_domain', config('app.url')), '/') . route('blog.show', $post->slug, false);
    $__ogImg    = $post->coverUrl;
    $__pubDate  = $post->published_at?->toIso8601String();
    $__modDate  = $post->updated_at?->toIso8601String();
    $__faqItems = $post->faq ?? [];
@endphp
@section('title', ($post->meta_title ?: $post->title) . ' — Animexe Blog')
@section('meta_description', $post->meta_description ?: $post->excerpt)
@section('meta_keywords', $post->meta_keywords)
@section('og_type', 'article')
@section('og_title', $post->title)
@section('og_description', $post->excerpt)
@if($__ogImg)@section('og_image', $__ogImg)@endif
@section('canonical', $__canon)
@section('robots', 'index, follow')

@section('schema')
<script type="application/ld+json">
{
  "@@context":"https://schema.org",
  "@@type":"BlogPosting",
  "headline":"{{ addslashes($post->title) }}",
  "description":"{{ addslashes($post->excerpt ?? '') }}",
  "url":"{{ $__canon }}",
  "datePublished":"{{ $__pubDate }}",
  "dateModified":"{{ $__modDate }}",
  "author":{"@@type":"Organization","name":"Animexe","url":"{{ rtrim(\App\Models\Setting::get('seo_canonical_domain',config('app.url')),'/') }}"},
  "publisher":{"@@type":"Organization","name":"Animexe","logo":{"@@type":"ImageObject","url":"{{ url('/logo.jpg') }}"}},
  "image":"{{ $__ogImg ?: url('/logo.jpg') }}",
  "inLanguage":"tr-TR",
  "keywords":"{{ addslashes($post->meta_keywords ?? '') }}"
}
</script>
@if(count($__faqItems) > 0)
<script type="application/ld+json">
{
  "@@context":"https://schema.org",
  "@@type":"FAQPage",
  "mainEntity":[
    @foreach($__faqItems as $i => $faq)
    {"@@type":"Question","name":"{{ addslashes($faq['q'] ?? '') }}","acceptedAnswer":{"@@type":"Answer","text":"{{ addslashes($faq['a'] ?? '') }}"}}{{ $i < count($__faqItems)-1 ? ',' : '' }}
    @endforeach
  ]
}
</script>
@endif
<script type="application/ld+json">
{
  "@@context":"https://schema.org",
  "@@type":"BreadcrumbList",
  "itemListElement":[
    {"@@type":"ListItem","position":1,"name":"Ana Sayfa","item":"{{ rtrim(\App\Models\Setting::get('seo_canonical_domain',config('app.url')),'/') }}/"},
    {"@@type":"ListItem","position":2,"name":"Blog","item":"{{ rtrim(\App\Models\Setting::get('seo_canonical_domain',config('app.url')),'/') }}/blog"},
    {"@@type":"ListItem","position":3,"name":"{{ addslashes($post->title) }}","item":"{{ $__canon }}"}
  ]
}
</script>
@endsection

@push('styles')
<style>
.blog-layout{display:grid;grid-template-columns:1fr 300px;gap:40px;max-width:1160px;margin:0 auto}
.blog-article{}
.blog-hero-img{width:100%;aspect-ratio:16/9;object-fit:cover;border-radius:var(--r2);margin-bottom:28px;
  box-shadow:0 8px 32px rgba(0,0,0,.5)}
.blog-meta-bar{display:flex;align-items:center;gap:16px;flex-wrap:wrap;margin-bottom:20px;padding-bottom:16px;border-bottom:1px solid rgba(0,245,255,.1)}
.blog-meta-item{display:flex;align-items:center;gap:6px;font-size:.78rem;color:var(--text3)}
.blog-meta-item i{font-size:.75rem;color:var(--accent2)}
.blog-ai-badge-lg{display:inline-flex;align-items:center;gap:6px;padding:4px 12px;border-radius:999px;
  background:linear-gradient(135deg,rgba(124,58,237,.2),rgba(232,67,147,.1));
  border:1px solid rgba(124,58,237,.3);color:#a78bfa;font-size:.78rem;font-weight:700;margin-bottom:16px}
.blog-h1{font-family:var(--font-display);font-size:1.55rem;font-weight:800;letter-spacing:.04em;
  line-height:1.35;color:var(--text);margin-bottom:20px}
.blog-content{color:var(--text2);line-height:1.85;font-size:.95rem}
.blog-content h2{font-family:var(--font-display);font-size:1.1rem;font-weight:700;color:var(--text);
  margin:32px 0 14px;letter-spacing:.04em;text-transform:uppercase;
  border-left:3px solid var(--accent2);padding-left:12px}
.blog-content h3{font-size:.95rem;font-weight:700;color:var(--text);margin:22px 0 10px}
.blog-content p{margin-bottom:16px}
.blog-content ul,.blog-content ol{padding-left:24px;margin-bottom:16px}
.blog-content li{margin-bottom:8px}
.blog-content strong{color:var(--text);font-weight:700}
.blog-content a{color:var(--accent2);text-decoration:underline;text-decoration-color:rgba(0,245,255,.4)}
.blog-content a:hover{color:var(--accent);text-decoration-color:rgba(255,45,125,.6)}
.faq-section{margin-top:40px;padding-top:28px;border-top:1px solid rgba(0,245,255,.1)}
.faq-section h2{font-family:var(--font-display);font-size:1rem;font-weight:800;text-transform:uppercase;
  letter-spacing:.06em;color:var(--accent2);margin-bottom:20px}
.faq-item{background:rgba(17,17,31,.8);border:1px solid rgba(0,245,255,.1);border-radius:var(--r2);
  padding:18px;margin-bottom:12px}
.faq-item h3{font-size:.9rem;font-weight:700;color:var(--text);margin-bottom:10px;line-height:1.4}
.faq-item p{font-size:.85rem;color:var(--text2);line-height:1.65;margin:0}
.cta-box{margin-top:36px;padding:28px;background:linear-gradient(135deg,rgba(255,45,125,.12),rgba(0,245,255,.08));
  border:1px solid rgba(255,45,125,.3);border-radius:var(--r2);text-align:center}
.cta-box h3{font-family:var(--font-display);font-size:1rem;font-weight:800;text-transform:uppercase;
  letter-spacing:.06em;color:var(--text);margin-bottom:12px}
.cta-btn{display:inline-flex;align-items:center;gap:8px;padding:12px 28px;border-radius:999px;
  background:linear-gradient(135deg,var(--accent),var(--accent3));color:#fff;
  font-weight:700;font-size:.9rem;text-decoration:none;transition:transform .16s,box-shadow .18s;
  box-shadow:0 0 24px rgba(255,45,125,.4)}
.cta-btn:hover{transform:translateY(-2px);box-shadow:0 0 36px rgba(255,45,125,.55);color:#fff}
.related-card{
  background:rgba(17,17,31,.8);border:1px solid rgba(0,245,255,.1);border-radius:var(--r);
  overflow:hidden;transition:border-color .2s;display:flex;gap:12px;align-items:flex-start;padding:12px;
}
.related-card:hover{border-color:rgba(255,45,125,.3)}
.related-thumb{width:64px;height:64px;border-radius:6px;overflow:hidden;flex-shrink:0;background:var(--surface2)}
.related-thumb img{width:100%;height:100%;object-fit:cover}
.linked-animes{margin-top:28px;padding:20px;background:rgba(0,245,255,.04);border:1px solid rgba(0,245,255,.12);border-radius:var(--r2)}
.linked-animes h3{font-size:.82rem;font-weight:700;text-transform:uppercase;letter-spacing:.08em;color:var(--accent2);margin-bottom:14px}
.la-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(120px,1fr));gap:10px}
@media(max-width:900px){
  .blog-layout{grid-template-columns:1fr}
  .blog-sidebar-wrap{display:none}
}
</style>
@endpush

@section('content')
<div class="section" style="padding-top:calc(var(--nav-h) + 28px)">
  <div class="blog-layout">
    <article class="blog-article" itemscope itemtype="https://schema.org/BlogPosting">

      @if($post->coverUrl)
      <img src="{{ $post->coverUrl }}" alt="{{ $post->title }}"
           class="blog-hero-img" itemprop="image" fetchpriority="high">
      @endif

      @if($post->ai_generated)
      <div class="blog-ai-badge-lg"><i class="bi bi-stars"></i> AI Destekli İçerik</div>
      @endif

      <h1 class="blog-h1" itemprop="headline">{{ $post->title }}</h1>

      <div class="blog-meta-bar">
        @if($post->published_at)
        <span class="blog-meta-item">
          <i class="bi bi-calendar3"></i>
          <time itemprop="datePublished" datetime="{{ $post->published_at->toIso8601String() }}">
            {{ $post->published_at->format('d F Y') }}
          </time>
        </span>
        @endif
        <span class="blog-meta-item"><i class="bi bi-clock"></i> {{ $post->reading_time }} dk okuma</span>
        @if($post->anime)
        <span class="blog-meta-item">
          <i class="bi bi-play-circle"></i>
          <a href="{{ $post->anime?->detailUrl ?? '#' }}" style="color:var(--accent2)">{{ $post->anime->title }}</a>
        </span>
        @endif
        @if($post->focus_keyword)
        <span class="blog-meta-item"><i class="bi bi-tag"></i> {{ $post->focus_keyword }}</span>
        @endif
      </div>

      <div class="blog-content" itemprop="articleBody">
        {!! $post->content !!}
      </div>

      {{-- FAQ Bölümü --}}
      @if(count($__faqItems) > 0)
      <div class="faq-section">
        <h2>Sıkça Sorulan Sorular</h2>
        @foreach($__faqItems as $faq)
        <div class="faq-item">
          <h3>{{ $faq['q'] ?? '' }}</h3>
          <p>{{ $faq['a'] ?? '' }}</p>
        </div>
        @endforeach
      </div>
      @endif

      {{-- İlgili Anime Linkleri --}}
      @if($linkedAnimes->count())
      <div class="linked-animes">
        <h3><i class="bi bi-collection-play me-1"></i>Bu Yazıda Bahsedilen Animeler</h3>
        <div class="la-grid">
          @foreach($linkedAnimes as $la)
          <a href="{{ $la->detailUrl }}" class="a-card">
            <div class="a-poster">
              @if($la->coverUrl)<img src="{{ $la->coverUrl }}" alt="{{ $la->title }}" loading="lazy">
              @else<div class="a-no-img"><i class="bi bi-image"></i></div>@endif
              @if($la->rating)<span class="a-rating"><i class="bi bi-star-fill" style="font-size:.6rem"></i>{{ number_format($la->rating,1) }}</span>@endif
            </div>
            <div class="a-info">
              <div class="a-title">{{ $la->title }}</div>
              <div class="a-meta">{{ $la->release_year }}</div>
            </div>
          </a>
          @endforeach
        </div>
      </div>
      @endif

      {{-- CTA --}}
      @if($post->anime)
      <div class="cta-box">
        <h3>{{ $post->anime->title }} İzle</h3>
        <p style="color:var(--text2);font-size:.88rem;margin-bottom:18px">
          Animexe'de Türkçe altyazılı veya dublajlı ücretsiz izle.
        </p>
        <a href="{{ $post->anime?->detailUrl ?? '#' }}" class="cta-btn">
          <i class="bi bi-play-fill"></i> Hemen İzle
        </a>
      </div>
      @endif
    </article>

    {{-- Sidebar --}}
    <aside class="blog-sidebar-wrap">
      @if($related->count())
      <div style="background:rgba(17,17,31,.8);border:1px solid rgba(0,245,255,.1);border-radius:var(--r2);padding:18px">
        <div style="font-family:var(--font-display);font-size:.72rem;text-transform:uppercase;letter-spacing:.1em;color:var(--accent2);margin-bottom:14px;font-weight:700">İlgili Yazılar</div>
        <div style="display:flex;flex-direction:column;gap:10px">
          @foreach($related as $rp)
          <a href="{{ route('blog.show', $rp->slug) }}" class="related-card" style="text-decoration:none">
            <div class="related-thumb">
              @if($rp->coverUrl)<img src="{{ $rp->coverUrl }}" alt="" loading="lazy">
              @else<div style="width:100%;height:100%;display:flex;align-items:center;justify-content:center;color:var(--text3)"><i class="bi bi-journal-text"></i></div>@endif
            </div>
            <div>
              <div style="font-size:.8rem;font-weight:600;color:var(--text);line-height:1.4;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden">{{ $rp->title }}</div>
              <div style="font-size:.68rem;color:var(--text3);margin-top:4px">{{ $rp->published_at?->format('d.m.Y') }}</div>
            </div>
          </a>
          @endforeach
        </div>
      </div>
      @endif
    </aside>
  </div>
</div>
@endsection
