@extends('layouts.appmin')

@section('content')
<div class="container">
    <h3 class="mb-4">Senarai Gambar Carousel</h3>

    @if(session('success'))
        <div class="alert alert-success">{{ session('success') }}</div>
    @endif

    <div class="mb-3">
        <a href="{{ route('carousel.create') }}" class="btn btn-success">+ Tambah Gambar</a>
    </div>

    <table class="table table-bordered table-hover">
        <thead class="table-light">
            <tr>
                <th>Gambar</th>
                <th>Tajuk</th>
                <th>Keterangan</th>
                <th>Tarikh Siar</th>
                <th>Admin</th>
                <th>Tindakan</th>
            </tr>
        </thead>
        <tbody>
            @foreach ($carousels as $item)
                <tr>
                    <td style="width: 180px">
                        <img src="{{ asset('storage/' . $item->fail_path) }}" class="img-thumbnail" width="160">
                    </td>
                    <td>{{ $item->tajuk }}</td>
                    <td>{{ $item->keterangan }}</td>
                    <td>{{ $item->tarikh_mula }} hingga {{ $item->tarikh_tamat }}</td>
                    <td>{{ $item->admin->name ?? 'N/A' }}</td>
                    <td>
                        <form action="{{ route('carousel.destroy', $item->id) }}" method="POST" onsubmit="return confirm('Padam gambar ini?')">
                            @csrf
                            @method('DELETE')
                            <button class="btn btn-danger btn-sm">Padam</button>
                        </form>
                    </td>
                </tr>
            @endforeach
        </tbody>
    </table>
</div>
@endsection