@extends('backend.admin.layouts.app')
@section('content')
    <div class="pagetitle">
        <h1>Dashboard</h1>
        <nav>
            <ol class="breadcrumb">
                <li class="breadcrumb-item"><a href="index.html">Home</a></li>
                <li class="breadcrumb-item">Dashboard</li>
                <li class="breadcrumb-item active">{{ $PageTitle }}</li>
            </ol>
        </nav>
    </div>

    <section class="section dashboard">
        <div class="row">
            <div class="col-lg-12">
                <div class="card">
                    <div class="card-body mt-3">
                        <a href="{{ route('admin.create-slider') }}">
                            <button type="button" class="btn btn-primary">Add Slider</button>
                        </a>

                        <div class="table-responsive">
                            <table class="table table-striped mt-4 align-middle">
                                <thead>
                                    <tr>
                                        <th scope="col">#</th>
                                        <th scope="col">Preview</th>
                                        <th scope="col">Type</th>
                                        <th scope="col">Title</th>
                                        <th scope="col">YouTube</th>
                                        <th scope="col">Alternative Info</th>
                                        <th scope="col">Action</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    @forelse ($sliders as $slider)
                                        <tr>
                                            <th scope="row">{{ $loop->iteration }}</th>
                                            <td>
                                                @if($slider->image)
                                                    <img src="{{ asset('storage/' . $slider->image) }}"
                                                         alt="{{ $slider->alt ?? 'Slider image' }}"
                                                         width="100"
                                                         height="70"
                                                         style="object-fit: cover; border-radius: 8px;">
                                                @else
                                                    <span class="badge bg-secondary">No Image</span>
                                                @endif
                                            </td>
                                            <td>{{ ucfirst($slider->type) }}</td>
                                            <td>
                                                <div>{{ $slider->title ?: '—' }}</div>
                                                @if($slider->description)
                                                    <small class="text-muted">{{ \Illuminate\Support\Str::limit($slider->description, 70) }}</small>
                                                @endif
                                            </td>
                                            <td>
                                                @if($slider->youtube_url)
                                                    <a href="{{ $slider->youtube_url }}" target="_blank">Open Video</a>
                                                @else
                                                    —
                                                @endif
                                            </td>
                                            <td>{{ $slider->alt ?: '—' }}</td>
                                            <td>
                                                <a href="{{ route('admin.slider.edit', $slider->id) }}" class="mr-1" title="Edit">
                                                    <img src="{{ asset('assets/img/edit.png') }}" alt="">
                                                </a>

                                                <a href="#" class="ms-2 deleteItem" data-formid="delete_row_form_{{ $slider->id }}">
                                                    <img src="{{ asset('assets/img/trash.png') }}" alt="">
                                                </a>
                                                <form action="{{ route('admin.slider.destroy', $slider->id) }}" method="post" id="delete_row_form_{{ $slider->id }}">
                                                    @csrf
                                                    {{ method_field('DELETE') }}
                                                    <input type="hidden" name="_token" value="{{ csrf_token() }}">
                                                </form>
                                            </td>
                                        </tr>
                                    @empty
                                        <tr>
                                            <td colspan="7" class="text-center py-4">No slider found.</td>
                                        </tr>
                                    @endforelse
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>
@endsection
