@extends('layouts/contentNavbarLayout')

@section('title', 'Tables - Sertifikat')

@section('content')
<h4 class="fw-bold py-3 mb-4">
    <span class="text-muted fw-light">Tables Sertifikat</span>
</h4>

<!-- Responsive Table -->
<div class="card">
    <h5 class="card-header">Sertifikat</h5>
    @if ($user->role == "Admin")
        <div class="mx-3 text-start">
            <a href="{{ route('sertifikat.create') }}">
                <button type="submit" class="btn btn-sm btn-primary">
                    <i class='bx bx-plus'></i>
                    Add
                </button>
            </a>
        </div>
        <div class="table-responsive text-nowrap p-3">
            <table class="table" id="table">
                <thead>
                    <tr class="text-nowrap">
                        <th>No</th>
                        <th>Nama</th>
                        <th>Sertifikat</th>
                        <th>Actions</th>
                    </tr>
                </thead>
                <tbody>
                    @foreach ($sertifikat as $record)
                        <tr>
                            <th scope="row">{{$loop->index + 1}}</th>
                            <td>{{$record->nama}}</td>
                            @if ($record->sertifikat)
                                <td><a href="/file/sertifikat/{{$record->sertifikat}}" class="btn btn-primary btn-sm">Lihat</a></td>
                            @else
                                <td><a href="/file/sertifikat/{{$record->sertifikat}}"
                                        class="btn btn-secondary btn-sm disabled">Lihat</a>
                                </td>
                            @endif
                            <td>
                                <div class="btn-group" role="group" aria-label="Actions">
                                    <a href="{{route('sertifikat.edit', $record->sid)}}" class="btn btn-blue"><i
                                            class="bx bx-upload"></i> Upload</a>
                                    <form action="{{route('sertifikat.delete', $record->sid)}}" method="POST">
                                        @csrf
                                        @method("DELETE")
                                        <button type="submit" class="btn btn-white"
                                            onclick="return confirm('Are you sure you want to delete this classification?')">
                                            <i class="bx bx-trash"></i> Delete
                                        </button>
                                    </form>
                                </div>
                            </td>
                        </tr>
                    @endforeach
                </tbody>
            </table>
        </div>
    @else
        <div class="row mb-3 px-3">
            <div class="col-md-6 col-lg-12 mb-3">
                <div class="card text-center">
                    <div class="card-body">
                        <h3 class="card-title">Sertifikat Keahlian</h3>
                        @if ($sertifikat[0]->sertifikat)
                            <a href="/file/sertifikat/{{$sertifikat[0]->sertifikat}}" class="btn btn-primary">Download
                                Sertifikat</a>
                        @else
                            <a href="/file/sertifikat/{{$sertifikat[0]->sertifikat}}" class="btn btn-primary disabled">Download
                                Sertifikat</a>
                        @endif
                    </div>
                </div>
            </div>
        </div>
    @endif
</div>
<!--/ Responsive Table -->
@endsection