@extends('layouts.admin')

@section('content')
<div class="container-fluid">
    <div class="row">
        <div class="col-12">
            <div class="page-title-box">
                <div class="page-title-right">
                    <a href="{{ route('admin.banners.create') }}" class="btn btn-primary">
                        <i class="fas fa-plus"></i> Create New Banner
                    </a>
                </div>
                <h4 class="page-title">Banners</h4>
            </div>
        </div>
    </div>

    <div class="row">
        <div class="col-12">
            <div class="card">
                <div class="card-body">
                    <div class="table-responsive">
                        <table class="table table-centered table-striped dt-responsive nowrap w-100">
                            <thead>
                                <tr>
                                    <th>Image</th>
                                    <th>Title</th>
                                    <th>Position</th>
                                    <th>Status</th>
                                    <th>Duration</th>
                                    <th>Actions</th>
                                </tr>
                            </thead>
                            <tbody>
                                @foreach($banners as $banner)
                                <tr>
                                    <td>
                                        <img src="{{ Storage::url($banner->image) }}" 
                                             alt="{{ $banner->title }}" 
                                             class="img-thumbnail" 
                                             style="max-width: 100px;">
                                    </td>
                                    <td>
                                        {{ $banner->title }}
                                        @if($banner->subtitle)
                                            <br><small class="text-muted">{{ $banner->subtitle }}</small>
                                        @endif
                                    </td>
                                    <td>{{ ucfirst($banner->position) }}</td>
                                    <td>
                                        <span class="badge bg-{{ $banner->status ? 'success' : 'danger' }}">
                                            {{ $banner->status ? 'Active' : 'Inactive' }}
                                        </span>
                                    </td>
                                    <td>
                                        @if($banner->start_date && $banner->end_date)
                                            {{ $banner->start_date->format('M d') }} - {{ $banner->end_date->format('M d, Y') }}
                                        @else
                                            Permanent
                                        @endif
                                    </td>
                                    <td>
                                        <a href="{{ route('admin.banners.edit', $banner) }}" 
                                           class="btn btn-sm btn-info">
                                            <i class="fas fa-edit"></i>
                                        </a>
                                        <form action="{{ route('admin.banners.destroy', $banner) }}" 
                                              method="POST" 
                                              class="d-inline">
                                            @csrf
                                            @method('DELETE')
                                            <button type="submit" 
                                                    class="btn btn-sm btn-danger" 
                                                    onclick="return confirm('Are you sure?')">
                                                <i class="fas fa-trash"></i>
                                            </button>
                                        </form>
                                    </td>
                                </tr>
                                @endforeach
                            </tbody>
                        </table>
                    </div>
                    {{ $banners->links('pagination::bootstrap-5') }}
                </div>
            </div>
        </div>
    </div>
</div>
@endsection