<?php
if (Auth('admin')->User()->dashboard_style == 'light') {
    $text = 'dark';
} else {
    $text = 'light';
}
?>
@extends('layouts.app')
@section('content')
    @include('admin.topmenu')
    @include('admin.sidebar')
    <div class="main-panel">
        <div class="content ">
            <div class="page-inner">
                <div class="mt-2 mb-4">
                    <h1 class="title1 ">{{ $title }}</h1>
                </div>
                <x-danger-alert />

                @if (session('success'))
                    <div class="alert alert-success">
                        {{ session('success') }}
                    </div>
                @endif

                <div class="mb-3">
                    <a href="{{ route('admin.personnel.create') }}" class="btn btn-primary">
                        <i class="fa fa-plus"></i> Add New Personnel
                    </a>
                </div>

                <div class="mb-5 row">
                    <div class="col card p-3 shadow ">
                        <div class="bs-example widget-shadow table-responsive" data-example-id="hoverable-table">
                            <span style="margin:3px;">
                                <table id="ShipTable" class="table table-hover ">
                                    <thead>
                                        <tr>
                                            <th>Service Number</th>
                                            <th>Full Name</th>
                                            <th>Email</th>
                                            <th>Rank</th>
                                            <th>Unit</th>
                                            <th>MOS</th>
                                            <th>Status</th>
                                            <th>Date Created</th>
                                            <th>View</th>
                                            <th>Edit</th>
                                            <th>Delete</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        @forelse ($personnel as $person)
                                            <tr>
                                                <td>{{ $person->service_number }}</td>
                                                <td>{{ $person->full_name }}</td>
                                                <td>{{ $person->email }}</td>
                                                <td>{{ $person->rank }}</td>
                                                <td>{{ $person->unit }}</td>
                                                <td>{{ $person->mos }}</td>
                                                <td>
                                                    @if($person->status === 'Active Duty')
                                                        <span class="badge badge-success">{{ $person->status }}</span>
                                                    @elseif($person->status === 'Reserve' || $person->status === 'National Guard')
                                                        <span class="badge badge-warning">{{ $person->status }}</span>
                                                    @elseif($person->status === 'Retired')
                                                        <span class="badge badge-info">{{ $person->status }}</span>
                                                    @else
                                                        <span class="badge badge-secondary">{{ $person->status }}</span>
                                                    @endif
                                                </td>
                                                <td>{{ \Carbon\Carbon::parse($person->created_at)->toDayDateTimeString() }}</td>
                                                <td>
                                                    <a href="{{ route('admin.personnel.show', $person->id) }}"
                                                        class="m-1 btn btn-info btn-sm"><i class="fa fa-eye"></i> View</a>
                                                </td>
                                                <td>
                                                    <a href="{{ route('admin.personnel.edit', $person->id) }}"
                                                        class="m-1 btn btn-warning btn-sm"><i class="fa fa-edit"></i> Edit</a>
                                                </td>
                                                <td>
                                                    <form action="{{ route('admin.personnel.destroy', $person->id) }}" method="POST" style="display: inline-block;">
                                                        @csrf
                                                        @method('DELETE')
                                                        <button type="submit" class="m-1 btn btn-danger btn-sm"
                                                                onclick="return confirm('Are you sure you want to delete this personnel record?')">
                                                            <i class="fa fa-trash"></i> Delete
                                                        </button>
                                                    </form>
                                                </td>
                                            </tr>
                                        @empty
                                            <tr>
                                                <td colspan="11" class="text-center">
                                                    <div class="alert alert-info">
                                                        No personnel records found.
                                                        <a href="{{ route('admin.personnel.create') }}" class="btn btn-primary btn-sm">
                                                            Add the first personnel record
                                                        </a>
                                                    </div>
                                                </td>
                                            </tr>
                                        @endforelse
                                    </tbody>
                                </table>
                            </span>
                        </div>

                        @if($personnel->hasPages())
                            <div class="mt-3">
                                {{ $personnel->links() }}
                            </div>
                        @endif
                    </div>
                </div>
            </div>
        </div>
    </div>
@endsection
