@extends('layouts.app')

@section('title', 'Home')

@section('content')
<div class="container">
    <!-- Hero Section -->
    <div class="row mb-4">
        <div class="col-12">
            <div class="hero-section bg-primary text-white p-5 rounded">
                <h1 class="display-4">Welcome to Sports Portal</h1>
                <p class="lead">Your ultimate destination for the latest sports news, updates, and analysis.</p>
            </div>
        </div>
    </div>

    <!-- Featured Posts -->
    <div class="row mb-5">
        <div class="col-12">
            <h2 class="mb-4">Featured Sports News</h2>
        </div>
        @foreach($featuredPosts as $post)
        <div class="col-md-4 mb-4">
            <div class="card h-100">
                @if($post->image)
                <img src="{{ $post->image }}" class="card-img-top" alt="{{ $post->title }}">
                @endif
                <div class="card-body">
                    <h5 class="card-title">{{ $post->title }}</h5>
                    <p class="card-text">{{ $post->excerpt ?? Str::limit($post->content, 150) }}</p>
                    <a href="{{ url('/post/' . $post->slug) }}" class="btn btn-primary">Read More</a>
                </div>
                <div class="card-footer text-muted">
                    <small>{{ $post->published_at->diffForHumans() }}</small>
                </div>
            </div>
        </div>
        @endforeach
    </div>

    <!-- Latest Posts -->
    <div class="row">
        <div class="col-md-8">
            <h2 class="mb-4">Latest News</h2>
            @foreach($latestPosts as $post)
            <article class="mb-4">
                <div class="card">
                    <div class="card-body">
                        <h3 class="card-title">{{ $post->title }}</h3>
                        <p class="card-text">{{ $post->excerpt ?? Str::limit($post->content, 200) }}</p>
                        <div class="d-flex justify-content-between align-items-center">
                            <a href="{{ url('/post/' . $post->slug) }}" class="btn btn-outline-primary">Read More</a>
                            <small class="text-muted">{{ $post->published_at->diffForHumans() }}</small>
                        </div>
                    </div>
                </div>
            </article>
            @endforeach
            
            {{ $latestPosts->links() }}
        </div>
        
        <!-- Sidebar -->
        <div class="col-md-4">
            <!-- Categories -->
            <div class="card mb-4">
                <div class="card-header">
                    <h5>Categories</h5>
                </div>
                <div class="card-body">
                    <ul class="list-unstyled">
                        @foreach($categories as $category)
                        <li class="mb-2">
                            <a href="{{ url('/category/' . $category->slug) }}" class="text-decoration-none">
                                {{ $category->name }}
                            </a>
                        </li>
                        @endforeach
                    </ul>
                </div>
            </div>
            
            <!-- Popular Posts -->
            <div class="card">
                <div class="card-header">
                    <h5>Popular Posts</h5>
                </div>
                <div class="card-body">
                    @foreach($popularPosts as $post)
                    <div class="mb-3">
                        <h6 class="mb-1">
                            <a href="{{ url('/post/' . $post->slug) }}" class="text-decoration-none">
                                {{ $post->title }}
                            </a>
                        </h6>
                        <small class="text-muted">{{ $post->published_at->diffForHumans() }}</small>
                    </div>
                    @endforeach
                </div>
            </div>
        </div>
    </div>
</div>
@endsection