@extends('layouts.app')
@section('title', 'Manajemen Master')
@section('content')
<div class="row">
    <div class="col-lg-12 d-flex align-items-stretch">
        <div class="card w-100">
            <div class="card-body p-4">
                <div class="d-flex align-items-stretch">
                    <h5 class="card-title fw-semibold mb-4">Manajemen Master</h5>
                    @role(['Admin'])
                    <div class="d-inline ms-auto">
                        @method('GET')
                        <a href="{{ URL::to('master/management-master/create') }}" class="btn btn-sm btn-success">
                            <i class="ti ti-circle-plus"></i>&nbsp; Tambah
                        </a>
                    </div>
                    @endrole
                </div>
                <div class="table-responsive">
                    <table class="table table-responsive table-bordered text-nowrap mb-0 align-middle">
                        <thead class="text-dark fs-4">
                            <tr>
                                <th class="border-bottom-0" width="45px">
                                    <h6 class="fw-semibold mb-0 text-center">No.</h6>
                                </th>
                                <th class="border-bottom-0">
                                    <h6 class="fw-semibold mb-0">Kode Master</h6>
                                </th>
                                <th class="border-bottom-0">
                                    <h6 class="fw-semibold mb-0">Keterangan</h6>
                                </th>
                                <th class="border-bottom-0" width="100px">
                                    <h6 class="fw-semibold mb-0 text-center">Aksi</h6>
                                </th>
                            </tr>
                        </thead>
                        <tbody>
                            @forelse ($management_master as $_mana)
                            <tr>
                                <td class="border-bottom-0 text-center">
                                    <span class="fw-normal mb-0">{{ ($management_master->currentPage()-1) * $management_master->perPage() + $loop->index + 1 }}</span>
                                </td>
                                <td class="border-bottom-0 text-truncate" style="max-width: 100px;">
                                    <span class="fw-normal mb-1">{{ $_mana->master_code }}</span>
                                </td>
                                <td class="border-bottom-0">
                                    <span class="fw-normal mb-1 badge text-bg-light">{{ $_mana->master_value }}</span>
                                </td>
                                <td class="border-bottom-0">
                                    <div class="d-flex align-items-center gap-2">
                                        @role(['Admin'])
                                        <a href="{{ URL::to('master/management-master/edit/' . $_mana->id) }}" class="btn btn-sm bg-warning-subtle text-warning mx-auto" data-bs-toggle="tooltip" title="Edit data"><i class="ti ti-edit"></i></a>
                                        @endrole
                                    </div>
                                </td>
                            </tr>
                            @empty
                            <div class="alert alert-danger">
                                Data master belum Tersedia.
                            </div>
                            @endforelse
                        </tbody>
                    </table>
                    {{-- Pagination --}}
                    <div class="d-flex justify-content-center">
                        {!! $management_master->links('includes.custom-pagination') !!}
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
@if (Session::has('management_masters-message'))
<script>
    Swal.fire({
        text: "{{ Session::get('management_masters-message')['msg'] }}",
        icon: "{{ Session::get('management_masters-message')['type'] }}",
        timer: 2500
    });
</script>
@endif
@stop