@extends('layouts.app')

@section('title', 'Departments')
@section('heading', 'Departments')

@section('content')
@include('settings.partials.back-to-home')
    <x-card>
        <div class="mb-4 flex justify-between items-center">
            <p class="text-slate-600">Manage company departments.</p>
            <a href="{{ route('departments.create') }}" class="inline-flex items-center rounded-lg bg-slate-800 px-4 py-2 text-sm font-medium text-white hover:bg-slate-700"><i class="bi bi-plus-lg me-1"></i>Add Department</a>
        </div>
        <x-table>
            <x-slot name="head">
                <tr>
                    <th class="px-4 py-3 text-left text-xs font-medium uppercase text-slate-500">Name</th>
                    <th class="px-4 py-3 text-left text-xs font-medium uppercase text-slate-500">Employee (Auto Calculated)</th>
                    <th class="px-4 py-3 text-right text-xs font-medium uppercase text-slate-500">Actions</th>
                </tr>
            </x-slot>
            @forelse($departments as $dept)
                <tr>
                    <td class="whitespace-nowrap px-4 py-3 text-sm text-slate-900">{{ $dept->name }}</td>
                    <td class="px-4 py-3 text-sm text-slate-700">{{ $dept->users()?->count() ?? 0 }}</td>
                    <td class="whitespace-nowrap px-4 py-3 text-right text-sm">
                        <a href="{{ route('departments.edit', $dept) }}" class="btn-icon-action btn-icon-action--edit" title="Edit" aria-label="Edit"><i class="bi bi-pencil-square"></i></a> <form action="{{ route('departments.destroy', $dept) }}" method="POST" class="inline" onsubmit="return confirm('Delete this department?');">
                            @csrf
                            @method('DELETE')
                            <button type="submit" class="btn-icon-action btn-icon-action--delete" title="Delete" aria-label="Delete"><i class="bi bi-trash3"></i></button>
                        </form>
                    </td>
                </tr>
            @empty
                <tr><td colspan="2" class="px-4 py-8 text-center text-sm text-slate-500">No departments yet.</td></tr>
            @endforelse
        </x-table>
        @if($departments->hasPages())<div class="mt-4">{{ $departments->links() }}</div>@endif
    </x-card>
@endsection
