@extends('admin.layouts.app')
@section('title', 'Bannerlar')
@section('page-title', 'Bannerlar')

@section('content')

<div class="page-header">
    <div>
        <h5 style="font-size:18px;font-weight:700;color:var(--text);margin:0">Bannerlar</h5>
        <div style="font-size:13px;color:var(--text2);margin-top:2px">Ana sayfa slider bannerleri</div>
    </div>
</div>

<div class="row g-4">

    {{-- Ekle --}}
    <div class="col-lg-4">
        <div class="card">
            <div class="card-header">
                <i class="bi bi-plus-circle" style="color:var(--accent-lt)"></i>
                <h6>Yeni Banner Ekle</h6>
            </div>
            <div class="card-body">
                <form method="POST" action="{{ route('admin.banners.store') }}" enctype="multipart/form-data">
                    @csrf
                    <div class="mb-3">
                        <label class="form-label">Başlık <span style="color:var(--danger)">*</span></label>
                        <input type="text" name="title" class="form-control" placeholder="Banner adı" required>
                    </div>
                    <div class="mb-3">
                        <label class="form-label">Görsel <span style="color:var(--danger)">*</span></label>
                        <input type="file" name="image" class="form-control" accept="image/*" required>
                        <div class="form-text">Önerilen: 1920×900px</div>
                    </div>
                    <div class="mb-3">
                        <label class="form-label">Link</label>
                        <input type="url" name="link" class="form-control" placeholder="https://...">
                    </div>
                    <div class="mb-3">
                        <label class="form-label">Sıra</label>
                        <input type="number" name="sort_order" class="form-control" value="0" min="0">
                        <div class="form-text">Küçük sayı önce gösterilir</div>
                    </div>
                    <div class="d-flex align-items-center justify-content-between p-3 rounded mb-4"
                         style="background:var(--surface2);border:1px solid var(--border)">
                        <div>
                            <div style="font-size:13.5px;font-weight:600;color:var(--text)">Aktif</div>
                            <div style="font-size:12px;color:var(--text2)">Sitede göster</div>
                        </div>
                        <div class="form-check form-switch mb-0">
                            <input class="form-check-input" type="checkbox" name="is_active" value="1"
                                   id="ba" role="switch" checked>
                        </div>
                    </div>
                    <button type="submit" class="btn btn-primary w-100">
                        <i class="bi bi-plus-lg"></i> Banner Ekle
                    </button>
                </form>
            </div>
        </div>
    </div>

    {{-- Liste --}}
    <div class="col-lg-8">
        <div class="card">
            <div class="card-header">
                <i class="bi bi-images" style="color:var(--info)"></i>
                <h6>Mevcut Bannerlar</h6>
                <span style="font-size:12px;color:var(--text2);margin-left:4px">{{ $banners->count() }} adet</span>
            </div>
            <div class="card-body p-0">
                @forelse($banners as $banner)
                <div style="display:flex;align-items:center;gap:16px;padding:14px 20px;border-bottom:1px solid var(--border)">
                    {{-- Görsel --}}
                    <div style="flex-shrink:0;width:96px;height:54px;border-radius:8px;overflow:hidden;background:var(--surface)">
                        @if($banner->imageUrl)
                            <img src="{{ $banner->imageUrl }}" alt="{{ $banner->title }}"
                                 style="width:100%;height:100%;object-fit:cover">
                        @else
                            <div style="width:100%;height:100%;display:flex;align-items:center;justify-content:center;color:var(--text3)">
                                <i class="bi bi-image"></i>
                            </div>
                        @endif
                    </div>

                    {{-- Bilgi --}}
                    <div style="flex:1;min-width:0">
                        <div style="font-size:13.5px;font-weight:700;color:var(--text)" class="text-truncate">{{ $banner->title }}</div>
                        @if($banner->link)
                            <div style="font-size:11.5px;color:var(--text2)" class="text-truncate">{{ $banner->link }}</div>
                        @endif
                        <div style="font-size:11.5px;color:var(--text3);margin-top:2px">Sıra: {{ $banner->sort_order }}</div>
                    </div>

                    {{-- Durum + Sil --}}
                    <div style="flex-shrink:0;display:flex;align-items:center;gap:10px">
                        @if($banner->is_active)
                            <span class="badge bg-success">Aktif</span>
                        @else
                            <span class="badge bg-secondary">Pasif</span>
                        @endif
                        <form method="POST" action="{{ route('admin.banners.destroy', $banner) }}"
                              onsubmit="return confirm('Bu banner silinsin mi?')">
                            @csrf @method('DELETE')
                            <button type="submit" class="btn btn-sm btn-outline-danger">
                                <i class="bi bi-trash3"></i>
                            </button>
                        </form>
                    </div>
                </div>
                @empty
                <div class="empty-state">
                    <i class="bi bi-images"></i>
                    <h6>Henüz banner eklenmemiş</h6>
                    <p>Sol panelden ilk bannerınızı ekleyebilirsiniz.</p>
                </div>
                @endforelse
            </div>
        </div>
    </div>

</div>
@endsection
