@extends('layouts.app')

@section('title', $article->title)

@section('content')
<div class="container">
    <div class="row justify-content-center">
        <div class="col-lg-8">
            <a href="{{ route('articles.index') }}" class="btn btn-outline-secondary btn-sm rounded-pill mb-3">
                &larr; Kembali ke Daftar Artikel
            </a>

            <div class="card card-eco p-4 p-md-5 mb-5">
                <span class="badge bg-success font-heading px-3 py-2 rounded-pill align-self-start mb-3">{{ $article->category }}</span>
                <h1 class="fw-bold font-heading text-dark mb-3">{{ $article->title }}</h1>
                
                <div class="d-flex align-items-center gap-3 text-muted small mb-4 pb-3 border-bottom">
                    <span><i class="fa-solid fa-user me-1"></i> Tim KKN Edukasi</span>
                    <span><i class="fa-regular fa-calendar me-1"></i> {{ $article->created_at->format('d F Y') }}</span>
                </div>

                @if($article->image)
                    <img src="{{ $article->image }}" class="img-fluid rounded-4 mb-4 shadow-sm mx-auto d-block" style="max-height: 550px; object-fit: contain;" alt="{{ $article->title }}">
                @endif

                <div class="article-content fs-5 text-secondary mb-4" style="line-height: 1.8;">
                    {!! nl2br(e($article->content)) !!}
                </div>

                @if($article->source_url)
                    <div class="mt-4 pt-4 border-top d-flex justify-content-center justify-content-md-start">
                        <a href="{{ $article->source_url }}" target="_blank" class="btn btn-outline-success rounded-pill px-4 fw-bold">
                            <i class="fa-solid fa-arrow-up-right-from-square me-2"></i> Baca Artikel Aslinya 🔗
                        </a>
                    </div>
                @endif
            </div>

            <!-- RELATED ARTICLES -->
            @if(count($relatedArticles) > 0)
            <div class="mb-5">
                <h5 class="fw-bold font-heading text-dark mb-3">Artikel Lainnya</h5>
                <div class="row gy-3">
                    @foreach($relatedArticles as $rel)
                    <div class="col-md-4">
                        <div class="card card-eco h-100 p-3">
                            <h6 class="fw-bold text-dark mb-2">{{ Str::limit($rel->title, 45) }}</h6>
                            <a href="{{ route('articles.show', $rel->slug) }}" class="btn btn-link text-success p-0 small fw-bold">Baca &rarr;</a>
                        </div>
                    </div>
                    @endforeach
                </div>
            </div>
            @endif
        </div>
    </div>
</div>
@endsection
