@extends('layout')

@section('title', __('store.announcements_title'))

@section('content')
<div class="container py-5">
    <h1 class="mb-4">{{ __('store.announcements_title') }}</h1>

    @if ($tags->isNotEmpty())
        <div class="mb-4">
            <a href="{{ lroute('announcements.index') }}"
               class="badge bg-secondary text-decoration-none {{ ! $tagSlug ? 'fw-bold' : '' }}">
                {{ __('store.posts_all_tags') }}
            </a>
            @foreach ($tags as $tag)
                <a href="{{ lroute('announcements.index', ['tag' => $tag->slug]) }}"
                   class="badge text-decoration-none {{ $tagSlug === $tag->slug ? 'fw-bold border border-2 border-dark' : '' }}"
                   style="background-color: {{ $tag->color ?? '#6c757d' }}">
                    @if ($tag->icon)<i class="fas {{ $tag->icon }}"></i> @endif
                    {{ $tag->getFirstNonEmptyTranslation('name') }}
                </a>
            @endforeach
        </div>
    @endif

    @forelse ($announcements as $announcement)
        @php $badge = $announcement->subtypeBadge(); @endphp
        <div class="card mb-3 border-0 shadow-sm">
            <div class="card-body">
                <div class="d-flex align-items-start">
                    <span class="badge bg-{{ $badge['color'] }} me-3 align-self-start">
                        <i class="fas {{ $badge['icon'] }}"></i>
                    </span>
                    <div class="flex-grow-1">
                        <h5 class="card-title mb-1">
                            <a href="{{ lroute('announcements.show', $announcement->getLocaleSlug(app()->getLocale())) }}">
                                {{ $announcement->getFirstNonEmptyTranslation('title') }}
                            </a>
                        </h5>
                        <small class="text-muted">{{ $announcement->published_at?->diffForHumans() }}</small>
                        <p class="mt-2 mb-0">{{ \Illuminate\Support\Str::limit(
                            $announcement->getFirstNonEmptyTranslation('excerpt')
                                ?: strip_tags(app(\App\Services\Content\EditorJsRenderer::class)->render(
                                    $announcement->getTranslation('content', app()->getLocale())
                                )),
                            200
                        ) }}</p>
                    </div>
                </div>
            </div>
        </div>
    @empty
        <p class="text-muted">{{ __('store.announcements_empty') }}</p>
    @endforelse

    {{ $announcements->withQueryString()->links() }}
</div>
@endsection
