@extends('layouts.app')

@section('title', 'Search Results')

@section('content')
<div class="container">
    <div class="row">
        <div class="col-12">
            <h1 class="mb-4">Search Results</h1>
            
            <!-- Search Form -->
            <form action="{{ url('/search') }}" method="GET" class="mb-4">
                <div class="input-group">
                    <input type="text" name="q" class="form-control" placeholder="Search for sports news..." value="{{ request('q') }}" required>
                    <button class="btn btn-primary" type="submit">Search</button>
                </div>
            </form>
            
            @if(request('q'))
                <p class="text-muted mb-4">Search results for: "<strong>{{ request('q') }}</strong>" ({{ $posts->total() }} results found)</p>
                
                @if($posts->count() > 0)
                    <div class="row">
                        @foreach($posts as $post)
                        <div class="col-md-6 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>
                                    <div class="d-flex justify-content-between align-items-center">
                                        <a href="{{ url('/post/' . $post->slug) }}" class="btn btn-primary">Read More</a>
                                        <small class="text-muted">{{ $post->published_at->diffForHumans() }}</small>
                                    </div>
                                </div>
                            </div>
                        </div>
                        @endforeach
                    </div>
                    
                    {{ $posts->links() }}
                @else
                    <div class="alert alert-info">
                        <h4>No results found</h4>
                        <p>Try searching with different keywords or browse our categories:</p>
                        <div class="row">
                            @foreach($categories as $category)
                            <div class="col-md-3 mb-2">
                                <a href="{{ url('/category/' . $category->slug) }}" class="btn btn-outline-primary w-100">{{ $category->name }}</a>
                            </div>
                            @endforeach
                        </div>
                    </div>
                @endif
            @else
                <div class="alert alert-info">
                    <h4>Start Searching</h4>
                    <p>Enter a search term above to find sports news articles.</p>
                </div>
            @endif
        </div>
    </div>
</div>
@endsection