@props([
    'noticia',
])

@php
    $slugDate = date('d-m-Y', strtotime($noticia->created_at));
    $noticiaUrl = route('paginas.slug', [$slugDate, $noticia->slug]);
    $titulo = html_entity_decode($noticia->title, ENT_QUOTES, 'UTF-8');
    $resumo = html_entity_decode($noticia->summary, ENT_QUOTES, 'UTF-8');
    $capaPadrao = asset('/pmar/assets/img/angra-default.png');
    $capaPath = ltrim((string) ($noticia->featuredPhoto ?? ''), '/');
    $capa = $capaPath !== '' && file_exists(public_path($capaPath))
        ? asset($noticia->featuredPhoto)
        : $capaPadrao;
@endphp

<article class="ma-news__card h-100">
    <a href="{{ $noticiaUrl }}" class="ma-news__card-link text-reset text-decoration-none d-flex flex-column h-100">
        <div class="ratio ratio-16x9 ma-news__card-media">
            <img src="{{ $capa }}"
                class="object-fit-cover"
                alt="{{ __('Capa da notícia') }}: {{ strip_tags($titulo) }}"
                loading="lazy">
        </div>
        <div class="ma-news__card-body flex-grow-1 d-flex flex-column">
            <h3 class="ma-news__card-title">{{ $titulo }}</h3>
            <p class="ma-news__card-text">{{ Str::limit(strip_tags($resumo), 120) }}</p>
            <time class="ma-news__card-date mt-auto" datetime="{{ $noticia->created_at }}">
                {{ app(App\Http\Controllers\Controller::class)->formatDateToPortuguese($noticia->created_at) }}
            </time>
        </div>
    </a>
</article>
