@extends('dashboard.app')

@section('title', 'Data Biaya Kuliah')

@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 Biaya Kuliah</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 Biaya Kuliah</h1>
                        <a href="{{ route('biaya.create') }}" class="btn btn-primary">
                            <i class="fa fa-plus fa-fw"></i> Tambah Biaya
                        </a>
                    </div>
                    <form method="GET" action="{{ route('biaya.index') }}" class="mb-3">
                            
                            <div class="d-flex flex-wrap align-items-center gap-2">
                                <input type="text" name="search" class="form-control w-auto" placeholder="Cari Jurusan" value="{{ request('search') }}">
                                <button type="submit" class="btn btn-primary btn-sm mt-2 mt-md-0">
                                    <i class="fa fa-search"></i> Cari
                                </button>
                            </div>
                    </form>

                    @if (session('message'))
                        <div class="alert alert-{{ session('alert-type', '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>Jurusan</th>
                                    <th>Biaya Awal</th>
                                    <th>Biaya SPP</th>
                                    <th>Biaya Semester</th>
                                    <th>Deskripsi</th>
                                    <th>Aksi</th>
                                </tr>
                            </thead>
                            <tbody>
                                @forelse($biayas as $index => $biaya)
                                    <tr>
                                        <td>{{ ($biayas->currentPage() - 1) * $biayas->perPage() + $index + 1 }}</td>
                                        <td>{{ $biaya->kategori }}</td>
                                        <td>{{ $biaya->jurusan }}</td>
                                        <td>Rp {{ number_format($biaya->biaya_awal, 0, ',', '.') }}</td>
                                        <td>Rp {{ number_format($biaya->biaya_spp, 0, ',', '.') }}</td>
                                        <td>Rp {{ number_format($biaya->biaya_semester, 0, ',', '.') }}</td>
                                        <td>{!! \Illuminate\Support\Str::limit(strip_tags($biaya->deskripsi), 100, '...') !!}</td>
                                        <td>
                                            <div class="d-flex flex-wrap gap-2">
                                                <a href="{{ route('biaya.edit', $biaya->biaya_id) }}" class="btn btn-warning btn-sm">Edit</a>
                                                <form action="{{ route('biaya.destroy', $biaya->biaya_id) }}" method="POST" onsubmit="return confirm('Yakin ingin menghapus data ini?')" style="display:inline-block;">
                                                    @csrf
                                                    @method('DELETE')
                                                    <button type="submit" class="btn btn-danger btn-sm">Hapus</button>
                                                </form>
                                            </div>
                                        </td>
                                    </tr>
                                @empty
                                    <tr>
                                        <td colspan="7" class="text-center">Tidak ada data biaya</td>
                                    </tr>
                                @endforelse
                            </tbody>
                        </table>
                    </div>

                    @if ($biayas instanceof \Illuminate\Pagination\LengthAwarePaginator)
                        <div class="mt-3">
                            {{ $biayas->links('vendor.pagination.simple-bootstrap-5') }}
                        </div>
                    @endif

                </div>
            </div>
        </div>
    </div>
</div>
@endsection