@extends('theme::layouts.web')

{{--
    News article — Protera theme override (task-4 v17.85).

    Replaces the standalone Modules/News/Resources/views/web/default.blade.php
    fallback. Inherits topbar + site-header + site-footer + Vite-built CSS
    from theme::layouts.web — same parity Pages already has at
    themes/Web/Protera/Resources/views/pages/web/default.blade.php.

    Vars (passed by NewsSlugResolver::resolve()):
      - $news           News (the resolved article)
      - $currentLocale  string (slug locale tag)
      - $defaultLocale  string
      - $locales        Collection<Locale>
      - $relatedNews    Collection<News> (already filtered to published)

    Test markers preserved verbatim from the legacy standalone view so the
    existing news-crud / news-submodules specs keep passing:
      [data-news-title], [data-news-published-at], [data-news-author],
      [data-news-reading-time], [data-news-excerpt], [data-news-content],
      [data-news-related], [data-news-related-card],
      [data-news-primary-category], [data-news-title-breadcrumb].
--}}

@section('title', $news->getTranslation('title', $currentLocale))
@section('description', $news->getTranslation('excerpt', $currentLocale) ?: '')

@section('content')
<main class="container py-5">
    @php
        $primary = $news->primaryCategory;
        $primaryUrl = $primary?->getUrl($currentLocale);
        $primaryTitle = $primary
            ? ($primary->getTranslation('title', $currentLocale) ?: $primary->getTranslation('title', $defaultLocale))
            : null;
    @endphp

    <nav aria-label="breadcrumb" class="mb-3">
        <ol class="breadcrumb">
            <li class="breadcrumb-item"><a href="/">{{ __('news::messages.home') }}</a></li>
            @if ($primary && $primaryUrl)
                <li class="breadcrumb-item">
                    <a href="{{ $primaryUrl }}" data-news-primary-category>{{ $primaryTitle }}</a>
                </li>
            @endif
            <li class="breadcrumb-item active" aria-current="page" data-news-title-breadcrumb>
                {{ $news->getTranslation('title', $currentLocale) }}
            </li>
        </ol>
    </nav>

    <x-microdata::attributes :for="$news" tag="article" class="cms-news">
        <header class="mb-4">
            <h1 class="mb-2" data-news-title>
                <x-microdata::property
                    name="headline"
                    :for="$news"
                    :value="$news->getTranslation('title', $currentLocale)" />
            </h1>

            <div class="text-muted small mb-3 d-flex flex-wrap gap-3">
                @if ($news->published_at)
                    <span data-news-published-at>
                        <i class="bi bi-calendar"></i>
                        {{ $news->published_at->format('Y-m-d H:i') }}
                    </span>
                    <x-microdata::property
                        name="datePublished"
                        :for="$news"
                        :value="$news->published_at->toIso8601String()"
                        tag="meta"
                        content-attr="content" />
                @endif
                <span data-news-author>
                    <i class="bi bi-person"></i>
                    {{ $news->displayedAuthor() }}
                </span>
                @if ($news->reading_time_minutes > 0)
                    <span data-news-reading-time>
                        <i class="bi bi-clock"></i>
                        {{ $news->reading_time_minutes }} {{ __('news::messages.minutes_short') }}
                    </span>
                @endif
            </div>

            @if ($news->getTranslation('excerpt', $currentLocale))
                <p class="lead text-muted mb-0" data-news-excerpt>
                    <x-microdata::property
                        name="description"
                        :for="$news"
                        :value="$news->getTranslation('excerpt', $currentLocale)" />
                </p>
            @endif
        </header>

        @if ($news->getTranslation('content', $currentLocale))
            <x-microdata::property
                name="articleBody"
                :for="$news"
                tag="div"
                class="cms-news-content mb-5"
                data-news-content>
                {!! $news->getTranslation('content', $currentLocale) !!}
            </x-microdata::property>
        @endif
    </x-microdata::attributes>

    @if ($relatedNews->isNotEmpty())
        <hr>
        <section class="related-news mt-5" data-news-related>
            <h2 class="h4 mb-3">{{ __('news::messages.related_news_heading') }}</h2>
            <div class="row g-3">
                @foreach ($relatedNews as $related)
                    @php
                        $relatedUrl = $related->getUrl($currentLocale);
                        $relatedTitle = $related->getTranslation('title', $currentLocale)
                            ?: $related->getTranslation('title', $defaultLocale);
                        $relatedExcerpt = $related->getTranslation('excerpt', $currentLocale);
                    @endphp
                    @if ($relatedUrl)
                        <div class="col-md-4" data-news-related-card>
                            <a href="{{ $relatedUrl }}" class="card text-decoration-none h-100">
                                <div class="card-body">
                                    <h3 class="h6 card-title">{{ $relatedTitle }}</h3>
                                    @if ($relatedExcerpt)
                                        <p class="card-text small text-muted">{{ \Illuminate\Support\Str::limit($relatedExcerpt, 100) }}</p>
                                    @endif
                                </div>
                            </a>
                        </div>
                    @endif
                @endforeach
            </div>
        </section>
    @endif
</main>
@endsection
