@extends('dashboard.app')

@section('title', 'Data Brosur')

@section('content')
    <div class="page-content">
        <nav class="page-breadcrumb">
            <ol class="breadcrumb">
                <li class="breadcrumb-item"><a href="{{ route('dashboard') }}">Dashboard</a></li>
                <li class="breadcrumb-item active" aria-current="page">Data Brosur</li>
            </ol>
        </nav>
        <div class="row">
            <div class="col-md-12 grid-margin stretch-card">
                <div class="card">
                    <div class="card-body">
                        <div class="panel-heading mb-3 d-flex justify-content-between align-items-center">
                            <h1 class="card-title">Data Brosur</h1>
                            <a href="{{ route('brosur.create') }}" class="btn btn-primary">
                                <i class="fa fa-plus fa-fw"></i> Tambah Brosur
                            </a>
                        </div>
                        <div class="panel-body">
                            @if (session('message'))
                                <div class="alert alert-success alert-dismissible fade show" role="alert">
                                    {{ session('message') }}
                                    <button type="button" class="btn-close" data-bs-dismiss="alert"
                                        aria-label="Close"></button>
                                </div>
                            @endif
                            <div class="table-responsive">
                                <table class="table table-bordered table-striped">
                                    <thead>
                                        <tr>
                                            <th>No</th>
                                            <th>Kategori</th>
                                            <th>File</th>
                                            <th>Aksi</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        @forelse ($brosurs as $index => $item)
                                            <tr>
                                                <td>{{ ($brosurs->currentPage() - 1) * $brosurs->perPage() + $index + 1 }}</td>
                                                <td>{{ $item->kategori }}</td>
                                                <td>
                                                    @if ($item->file)
                                                        <a href="{{ asset('storage/brosurFiles/' . $item->file) }}" target="_blank">
                                                            <img src="{{ asset('storage/brosurFiles/' . $item->file) }}"
                                                                 alt="gambar"
                                                                 style="width: 50px; height: 50px; object-fit: cover;">
                                                        </a>
                                                    @else
                                                        <span class="text-muted">Tidak Ada</span>
                                                    @endif
                                                </td>
                                                <td>
                                                    <div class="d-flex flex-wrap gap-2">
                                                        <a href="{{ route('brosur.edit', $item->brosur_id) }}"
                                                            class="btn btn-warning btn-sm">Edit</a>
                                                        <form action="{{ route('brosur.delete', $item->brosur_id) }}"
                                                            method="POST" style="display:inline-block;">
                                                            @csrf
                                                            @method('DELETE')
                                                            <button type="submit" class="btn btn-danger btn-sm"
                                                                onclick="return confirm('Yakin ingin menghapus brosur ini?')">Hapus</button>
                                                        </form>
                                                    </div>
                                                </td>
                                            </tr>
                                        @empty
                                            <tr>
                                                <td colspan="4" class="text-center">Tidak ada data brosur</td>
                                            </tr>
                                        @endforelse
                                    </tbody>
                                </table>
                            </div>
                        </div>
                        <div class="mt-3">
                            {{ $brosurs->links('vendor.pagination.simple-bootstrap-5') }}
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
@endsection
