@extends('layouts.app')

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

@section('content')

<div class="container-fluid">

    {{-- Header --}}
    <div class="d-flex justify-content-between align-items-center mb-4">

        <div>

            <h3 class="font-weight-bold mb-1">
                Data Staff
            </h3>

            <p class="text-muted mb-0">
                Kelola seluruh data staff dan tenaga kependidikan.
            </p>

        </div>

        <a href="{{ route('staff.create') }}"
           class="btn btn-primary btn-modern">

            <i class="bi bi-plus-circle"></i>

            Tambah Staff

        </a>

    </div>

    @if(session('success'))

        <div class="alert alert-success alert-dismissible fade show">

            <i class="bi bi-check-circle-fill"></i>

            {{ session('success') }}

            <button
                type="button"
                class="close"
                data-dismiss="alert">

                <span>&times;</span>

            </button>

        </div>

    @endif

    {{-- Statistik --}}
    <div class="row mb-4">

        <div class="col-md-4">

            <div class="small-card">

                <div>

                    <small>Total Staff</small>

                    <h3>

                        {{ $staff->count() }}

                    </h3>

                </div>

                <div class="small-icon bg-primary">

                    <i class="bi bi-people-fill"></i>

                </div>

            </div>

        </div>

        <div class="col-md-4">

            <div class="small-card">

                <div>

                    <small>Total Gaji</small>

                    <h4>

                        Rp {{ number_format($staff->sum('gaji_pokok'),0,',','.') }}

                    </h4>

                </div>

                <div class="small-icon bg-success">

                    <i class="bi bi-cash-stack"></i>

                </div>

            </div>

        </div>

        <div class="col-md-4">

            <div class="small-card">

                <div>

                    <small>Rata-rata Gaji</small>

                    <h4>

                        Rp {{ number_format($staff->avg('gaji_pokok'),0,',','.') }}

                    </h4>

                </div>

                <div class="small-icon bg-warning">

                    <i class="bi bi-graph-up"></i>

                </div>

            </div>

        </div>

    </div>

    {{-- Card --}}
    <div class="card card-modern">

        <div class="card-header bg-white border-0">

            <h5 class="mb-0">

                <i class="bi bi-table text-primary mr-2"></i>

                Daftar Staff

            </h5>

        </div>

        <div class="card-body">

            <div class="table-responsive">

                <table class="table table-modern datatable">

                    <thead>

                        <tr>

                            <th>NIP</th>

                            <th>Nama</th>

                            <th>Jabatan</th>

                            <th>Gaji Pokok</th>

                            <th width="150" class="text-center">

                                Aksi

                            </th>

                        </tr>

                    </thead>

                    <tbody>

                    @foreach($staff as $s)

                        <tr>

                            <td>

                                <strong>

                                    {{ $s->nip }}

                                </strong>

                            </td>

                            <td>

                                {{ $s->nama }}

                            </td>

                            <td>

                                <span class="badge badge-info badge-pill px-3 py-2">

                                    {{ $s->jabatan }}

                                </span>

                            </td>

                            <td>

                                <strong>

                                    Rp {{ number_format($s->gaji_pokok,0,',','.') }}

                                </strong>

                            </td>

                            <td class="text-center">

                                <a href="{{ route('staff.edit',$s->id) }}"
                                   class="btn btn-warning btn-sm rounded-circle">

                                    <i class="bi bi-pencil"></i>

                                </a>

                                <form
                                    action="{{ route('staff.destroy',$s->id) }}"
                                    method="POST"
                                    class="d-inline">

                                    @csrf
                                    @method('DELETE')

                                    <button
                                        class="btn btn-danger btn-sm rounded-circle"
                                        onclick="return confirm('Yakin menghapus data staff ini?')">

                                        <i class="bi bi-trash"></i>

                                    </button>

                                </form>

                            </td>

                        </tr>

                    @endforeach

                    </tbody>

                </table>

            </div>

        </div>

    </div>

</div>

@endsection