@extends('layouts.app')

@section('title', $author->name . ' — ' . config('app.name'))
@section('meta_description', Str::limit($author->bio ?: 'Articles by ' . $author->name . ' on The Hindu.', 155))
@section('canonical', $author->url)

@section('content')
<div class="author-page">
  <div class="author-header">
    <img src="{{ $author->photo_url }}" alt="{{ $author->name }}" class="author-hero-img" width="120" height="120">
    <div class="author-header-info">
      <h1 class="author-name">{{ $author->name }}</h1>
      @if($author->designation)<p class="author-title">{{ $author->designation }}</p>@endif
      @if($author->location)<p class="author-location"><i class="fa-solid fa-location-dot"></i> {{ $author->location }}</p>@endif
      @if($author->bio)<p class="author-bio">{{ $author->bio }}</p>@endif
      <div class="author-social">
        @if($author->twitter_url)<a href="{{ $author->twitter_url }}" target="_blank" rel="noopener" aria-label="Twitter"><i class="fa-brands fa-x-twitter"></i></a>@endif
        @if($author->facebook_url)<a href="{{ $author->facebook_url }}" target="_blank" rel="noopener" aria-label="Facebook"><i class="fa-brands fa-facebook-f"></i></a>@endif
        @if($author->linkedin_url)<a href="{{ $author->linkedin_url }}" target="_blank" rel="noopener" aria-label="LinkedIn"><i class="fa-brands fa-linkedin-in"></i></a>@endif
      </div>
      <p class="author-stats">{{ number_format($totalArticles) }} {{ Str::plural('article', $totalArticles) }}</p>
    </div>
  </div>

  <div class="cat-layout">
    <div class="cat-main">
      <div class="cat-list">
        @forelse($articles as $art)
        <article class="cat-item">
          <a href="{{ $art->canonical_url }}" class="cat-item-img">
            <img src="{{ $art->photo_url }}" alt="{{ $art->news_title }}" loading="lazy" width="200" height="130">
          </a>
          <div class="cat-item-body">
            <span class="cat-item-tag">{{ strtoupper($art->category->category_name ?? 'NEWS') }}</span>
            <h3 class="cat-item-title"><a href="{{ $art->canonical_url }}" title="{{ $art->news_title }}">{{ $art->news_title }}</a></h3>
            <p class="cat-item-summary">{{ Str::limit(strip_tags($art->news_content_short), 130) }}</p>
            <div class="cat-item-meta">
              @if($art->published_at)<span>{{ $art->published_at->format('M j, Y') }}</span>@endif
            </div>
          </div>
        </article>
        @empty
        <p>No articles found.</p>
        @endforelse
      </div>
      @if($articles->hasPages())
      <div class="hindu-pagination">{{ $articles->links('partials.pagination') }}</div>
      @endif
    </div>
    <aside class="cat-sidebar">
      <div class="sidebar-block">
        <div class="sidebar-title">Latest News</div>
        @foreach($latestSidebar as $ls)
        <div class="sidebar-item">
          <img src="{{ $ls->photo_url }}" alt="{{ $ls->news_title }}" loading="lazy" width="70" height="52">
          <div>
            <span class="sidebar-cat">{{ strtoupper($ls->category->category_name ?? '') }}</span>
            <p class="sidebar-text"><a href="{{ $ls->canonical_url }}">{{ Str::limit($ls->news_title, 80) }}</a></p>
          </div>
        </div>
        @endforeach
      </div>
    </aside>
  </div>
</div>
@endsection
