@extends('front-end.layouts.apps')

@section('title', 'لټون')

@section('page_title', 'د شعرونو لټون')

@section('main_container')
<div class="container" dir="rtl">
    {{-- Search Header --}}
    <div class="section-header" style="margin-top: 20px;">
        <i class="fas fa-search"></i>
        <h3>د شعرونو لټون</h3>
    </div>

    {{-- Search Form --}}
    <div class="search-elegant mb-4">
        <form action="{{ route('public.poetry_search') }}" method="GET">
            <div class="row g-3">
                <div class="col-md-3">
                    <label class="fw-bold mb-2">کټګورۍ</label>
                    <div class="input-icon-group">
                        <i class="fas fa-tag"></i>
                        <select name="category_id" class="form-select">
                            <option value="any">ټولې کټګورۍ</option>
                            @foreach($categories as $cat)
                                <option value="{{ $cat->id }}" {{ request('category_id') == $cat->id ? 'selected' : '' }}>
                                    {{ $cat->title_ps ?? $cat->title }}
                                </option>
                            @endforeach
                        </select>
                    </div>
                </div>
                <div class="col-md-3">
                    <label class="fw-bold mb-2">شاعر</label>
                    <div class="input-icon-group">
                        <i class="fas fa-user"></i>
                        <select name="poet_id" class="form-select">
                            <option value="any">ټول شاعران</option>
                            @foreach($poets as $p)
                                <option value="{{ $p->id }}" {{ request('poet_id') == $p->id ? 'selected' : '' }}>
                                    {{ $p->name }}
                                </option>
                            @endforeach
                        </select>
                    </div>
                </div>
                <div class="col-md-4">
                    <label class="fw-bold mb-2">کلیمه</label>
                    <div class="input-icon-group">
                        <i class="fas fa-search"></i>
                        <input type="text" name="keyword" class="form-control"
                               placeholder="د شعر یا کلمې په اساس..."
                               value="{{ request('keyword') }}">
                    </div>
                </div>
                <div class="col-md-2 d-flex align-items-end">
                    <button type="submit" class="btn-gradient w-100">
                        <i class="fas fa-filter"></i> فلتر
                    </button>
                </div>
            </div>
        </form>
    </div>

    {{-- Results Count --}}
    <div class="d-flex justify-content-between align-items-center mb-3">
        <p class="text-muted">
            <i class="fas fa-feather-alt"></i> ټولې پایلې: {{ $poetries->total() }}
        </p>
        @if(request()->anyFilled(['category_id', 'poet_id', 'keyword']))
            <a href="{{ route('public.poetry_search') }}" class="btn btn-sm btn-outline-secondary rounded-pill">
                <i class="fas fa-times"></i> لیرې کول
            </a>
        @endif
    </div>

    {{-- Results Grid --}}
    @if($poetries->count() > 0)
        <div class="row">
            @foreach($poetries as $poetry)
                <div class="col-12 col-md-6 col-lg-4 mb-3">
                    <div class="folk-item poetry-result">
                        <a href="{{ route('public.poet_poetry_details_single', $poetry->id) }}" class="folk-link" style="flex-direction: column; align-items: start;">
                            <div class="d-flex w-100 align-items-center">
                                <i class="fas fa-star folk-icon" style="font-size: 1.5rem;"></i>
                                <span class="fw-bold">{{ Str::limit($poetry->title ?? 'بې نوم', 40) }}</span>
                                <i class="fas fa-arrow-left folk-arrow"></i>
                            </div>
                            <div class="d-flex w-100 text-muted small gap-3 mt-1">
                                <span><i class="fas fa-user ms-1"></i> {{ $poetry->poet->name ?? 'نامعلوم' }}</span>
                                <span><i class="fas fa-tag ms-1"></i> {{ $poetry->category->title_ps ?? $poetry->category->title ?? 'نور' }}</span>
                            </div>
                            @if($poetry->description)
                                <p class="text-muted mt-2 mb-0 small">{{ Str::limit($poetry->description, 60) }}</p>
                            @endif
                        </a>
                    </div>
                </div>
            @endforeach
        </div>

        {{-- Pagination --}}
        <div class="d-flex justify-content-center mt-4">
            {{ $poetries->links('pagination::bootstrap-4') }}
        </div>
    @else
        <div class="alert alert-info text-center">
            <i class="fas fa-info-circle"></i> د یادو شرطونو سره هېڅ شعر ونه موندل شو.
        </div>
    @endif

    {{-- spacer --}}
    <div style="height: 30px;"></div>
</div>

{{-- Bottom Navigation --}}
<nav class="bottom-nav">
    <a href="{{ url('/') }}" class="nav-item {{ request()->is('/') ? 'active' : '' }}">
        <i class="fas fa-home"></i>
        <span>کور</span>
    </a>
    <a href="{{ route('public.categories') }}" class="nav-item {{ request()->is('categories') || request()->is('categories*') ? 'active' : '' }}">
        <i class="fas fa-list-ul"></i>
        <span>کټګورۍ</span>
    </a>
    <a href="{{ route('public.poetry_search') }}" class="nav-item {{ request()->is('poetry/search') ? 'active' : '' }}">
        <i class="fas fa-search"></i>
        <span>لټون</span>
    </a>
</nav>
@endsection

