@extends('layouts.app')

@section('title', 'Search results for "' . e($query) . '" - ' . config('app.name'))
@section('description', 'Ditemukan ' . $total_results . ' hasil drama yang relevan untuk pencarian "' . e($query) . '" di ' . config('app.name'))
@section('image', env('FAVICON_URL', '/images/logo-s.png'))
@section('type', 'website')

@section('meta_extra')
    <meta name="robots" content="noindex, follow">
@endsection

@section('content')
<main class="container my-4">

    <h2 class="search-header">
        Ditemukan <strong>{{ $total_results }}</strong> hasil yang relevan dengan <span class="query-highlight">"{{ e($query) }}"</span>
    </h2>

    <div class="search-results-list">
        
        @foreach ($data as $item)
        <div class="card search-item-card mb-3">
            <div class="row g-3">
                
                <div class="col-md-2 col-3">
                    <img src="{{ $item['Poster'] }}" class="search-item-image" alt="{{ $item['Title'] }}">
                </div>
                
                <div class="col-md-7 col-9 search-detail">
                    <div class="card-body p-0">
                        @php
                        $permalink = ltrim($item['Permalink'], '/');
                        if (str_starts_with($permalink, $lang . '/')) {
                            $finalUrl = $permalink;
                        } else {
                            $finalUrl = $lang . '/' . $permalink;
                        }
                        @endphp
                        <a href="{{ url($finalUrl) }}" class="text-decoration-none" alt="{{ $item['Title'] }}">
                            <h3 class="search-item-title">{{ $item['Title'] }}</h3>
                        </a>
                        <p class="search-item-episodes">{{ $item['Total_Episode'] }}</p>
                        
                        <p class="search-item-synopsis">{{ $item['Sinopsis'] }}</p>
                        
                        <a href="#" class="genre-tag">{{ implode(',', $item['Genre']) }}</a>
                    </div>
                </div>
                
                <div class="col-md-3 d-none d-md-flex align-items-center justify-content-end">
                    @php
                    $permalink = ltrim($item['Permalink'], '/');
                    if (str_starts_with($permalink, $lang . '/')) {
                        $finalUrl = $permalink;
                    } else {
                        $finalUrl = $lang . '/' . $permalink;
                    }
                    @endphp
                    <a href="{{ url($finalUrl) }}" class="btn-putar">
                        <i class="bi bi-play-fill me-1"></i> Putar
                    </a>
                </div>
                
            </div>
        </div>
        @endforeach
        
    </div> 
    
    <x-pagination :current-page="$current_page"
    :total-pages="$total_pages"
    :base-url="$base_url"
    :query-params="request()->query()" />
</main>
@endsection