@extends('dashboard.app')

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

@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 Kurikulum</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 Kurikulum</h1>
                        <a href="{{ route('kurikulum.create') }}" class="btn btn-primary">
                            <i class="fa fa-plus fa-fw"></i> Tambah Kurikulum
                        </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>Jurusan</th>
                                        <th>File</th>
                                        <th>Aksi</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    @forelse ($kurikulums as $index => $item)
                                        <tr>
                                            <td>{{ ($kurikulums->currentPage() - 1) * $kurikulums->perPage() + $index + 1 }}</td>
                                            <td>{{ $item->jurusan }}</td>
                                            <td>
                                                @if ($item->file)
                                                    <a href="{{ asset('storage/kurikulumFiles/' . $item->file) }}" target="_blank">
                                                        {{ $item->file }}
                                                    </a>
                                                @else
                                                    <span class="text-muted">Tidak Ada</span>
                                                @endif
                                            </td>
                                            <td>
                                                <div class="d-flex flex-wrap gap-2">
                                                    <a href="{{ route('kurikulum.edit', $item->id_kurikulum) }}"
                                                        class="btn btn-warning btn-sm">Edit</a>
                                                    <form action="{{ route('kurikulum.delete', $item->id_kurikulum) }}"
                                                        method="POST" style="display:inline-block;">
                                                        @csrf
                                                        @method('DELETE')
                                                        <button type="submit" class="btn btn-danger btn-sm"
                                                            onclick="return confirm('Yakin ingin menghapus data ini?')">Hapus</button>
                                                    </form>
                                                </div>
                                            </td>
                                        </tr>
                                    @empty
                                        <tr>
                                            <td colspan="4" class="text-center">Tidak ada data kurikulum</td>
                                        </tr>
                                    @endforelse
                                </tbody>
                            </table>
                        </div>
                    </div>
                    <div class="mt-3">
                        {{ $kurikulums->links('vendor.pagination.simple-bootstrap-5') }}
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection
