@extends('layouts.public')

@section('meta_title', 'Arama - Kütüphane - Askeri Platform')
@section('meta_description', 'Kütüphane içinde içerik arayın.')

@section('content')
<style>
    .search-header {
        background: white;
        border: 1px solid #e5e7eb;
        border-radius: 14px;
        padding: 32px;
        margin-bottom: 24px;
        box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    }
    .search-title { font-size: 24px; font-weight: 800; color: #111827; margin-bottom: 16px; }
    .search-form { display: flex; gap: 10px; }
    .search-input {
        flex: 1;
        padding: 12px 16px;
        border: 2px solid #e5e7eb;
        border-radius: 8px;
        font-size: 15px;
        font-family: inherit;
        outline: none;
        transition: border-color 0.2s;
    }
    .search-input:focus { border-color: #059669; }
    .search-btn {
        padding: 12px 24px;
        background: #059669;
        color: white;
        border: none;
        border-radius: 8px;
        font-weight: 600;
        cursor: pointer;
        font-size: 15px;
        transition: background 0.2s;
    }
    .search-btn:hover { background: #047857; }

    .results-info { font-size: 14px; color: #6b7280; margin-bottom: 16px; }
    .results-info strong { color: #059669; font-weight: 700; }

    .content-list { display: flex; flex-direction: column; gap: 12px; }
    .content-item {
        background: white;
        border: 1px solid #e5e7eb;
        border-radius: 10px;
        padding: 20px 24px;
        text-decoration: none;
        color: inherit;
        display: flex;
        align-items: center;
        gap: 16px;
        transition: all 0.2s;
        box-shadow: 0 1px 2px rgba(0,0,0,0.04);
    }
    .content-item:hover {
        border-color: #059669;
        box-shadow: 0 4px 12px rgba(5, 150, 105, 0.1);
        background: #f0fdf4;
    }
    .content-item-icon { font-size: 28px; flex-shrink: 0; }
    .content-item-body { flex: 1; min-width: 0; }
    .content-item-title { font-size: 16px; font-weight: 700; color: #111827; margin-bottom: 4px; }
    .content-item-meta { font-size: 13px; color: #9ca3af; display: flex; gap: 12px; }

    .type-badge {
        padding: 4px 12px;
        border-radius: 20px;
        font-size: 12px;
        font-weight: 600;
        white-space: nowrap;
        flex-shrink: 0;
    }
    .type-article { background: #dbeafe; color: #1e40af; }
    .type-table   { background: #fce7f3; color: #9d174d; }
    .type-list    { background: #fef3c7; color: #92400e; }
    .type-pdf     { background: #fee2e2; color: #991b1b; }
    .type-mixed   { background: #ede9fe; color: #5b21b6; }

    .empty-state { text-align: center; padding: 60px 24px; background: white; border: 1px dashed #e5e7eb; border-radius: 12px; }
    .empty-state-icon { font-size: 48px; margin-bottom: 16px; }
    .empty-state-text { font-size: 16px; color: #6b7280; }
</style>

{{-- Search Header --}}
<div class="search-header">
    <div class="search-title">🔍 Kütüphane Arama</div>
    <form action="{{ route('library.search') }}" method="GET" class="search-form">
        <input type="text" name="q" class="search-input" placeholder="İçerik başlığı ara..." value="{{ $q }}">
        <button type="submit" class="search-btn">Ara</button>
    </form>
</div>

{{-- Results --}}
@if(strlen($q) >= 2)
    <div class="results-info">
        @if($contents->count() > 0)
            <strong>"{{ $q }}"</strong> için <strong>{{ $contents->total() }}</strong> sonuç bulundu.
        @else
            <strong>"{{ $q }}"</strong> için sonuç bulunamadı.
        @endif
    </div>

    @forelse($contents as $content)
        <div class="content-list">
            <a href="{{ route('library.show', [$content->category->slug, $content->slug]) }}" class="content-item">
                <div class="content-item-icon">
                    {{ match($content->type) {
                        'article' => '📄',
                        'table'   => '📊',
                        'list'    => '📋',
                        'pdf'     => '📕',
                        'mixed'   => '🗂️',
                        default   => '📄'
                    } }}
                </div>
                <div class="content-item-body">
                    <div class="content-item-title">{{ $content->title }}</div>
                    <div class="content-item-meta">
                        <span>📂 {{ $content->category->name }}</span>
                        <span>👁️ {{ number_format($content->views) }}</span>
                        <span>{{ $content->created_at->format('d.m.Y') }}</span>
                    </div>
                </div>
                <span class="type-badge type-{{ $content->type }}">
                    {{ match($content->type) {
                        'article' => 'Makale',
                        'table'   => 'Tablo',
                        'list'    => 'Liste',
                        'pdf'     => 'PDF',
                        'mixed'   => 'Karma',
                        default   => $content->type
                    } }}
                </span>
            </a>
        </div>
    @empty
        <div class="empty-state">
            <div class="empty-state-icon">🔍</div>
            <div class="empty-state-text">Arama kriterlerinize uygun içerik bulunamadı.</div>
        </div>
    @endforelse

    {{-- Pagination --}}
    @if($contents->hasPages())
        <div style="margin-top:32px;display:flex;justify-content:center;">
            {{ $contents->links() }}
        </div>
    @endif
@else
    <div class="empty-state">
        <div class="empty-state-icon">🔍</div>
        <div class="empty-state-text">Arama yapmak için en az 2 karakter girin.</div>
    </div>
@endif

@endsection
