@extends('layouts.app')

@section('title', 'Department Management')

@section('content')
<div class="space-y-6" x-data="{ modal: false }">
    <div class="flex items-center justify-between">
        <div>
            <h1 class="text-xl font-bold text-slate-900 dark:text-white">Departments Directory</h1>
            <p class="text-xs text-slate-500">Default and custom operational departments (Reception, Typing, PRO, Cashier, Accounts, HR).</p>
        </div>
        <button @click="modal = true" class="px-4 py-2 bg-sky-600 hover:bg-sky-700 text-white font-bold text-xs rounded-xl shadow-sm">+ Add Department</button>
    </div>

    <!-- Departments Grid (Requirement 14, 15) -->
    <div class="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-4 text-xs font-medium">
        @foreach($departments as $dept)
            <div class="p-4 rounded-2xl bg-white dark:bg-slate-800 border border-slate-200 dark:border-slate-700 shadow-sm space-y-2">
                <div class="flex items-center justify-between">
                    <span class="font-bold text-slate-900 dark:text-white text-sm">{{ $dept->name }}</span>
                    <span class="px-2 py-0.5 rounded bg-slate-100 dark:bg-slate-700 font-mono text-[10px]">{{ $dept->code }}</span>
                </div>
                <p class="text-slate-500 text-[11px]">Branch: {{ $dept->branch ? $dept->branch->name : 'All Branches' }}</p>
            </div>
        @endforeach
    </div>

    <div x-show="modal" class="fixed inset-0 bg-slate-950/80 backdrop-blur-sm z-50 flex items-center justify-center p-4" x-cloak>
        <div class="bg-white dark:bg-slate-800 rounded-3xl max-w-md w-full p-6 border border-slate-200 dark:border-slate-700 shadow-2xl space-y-4 text-xs">
            <h3 class="text-sm font-bold text-slate-900 dark:text-white uppercase tracking-wider">Add Department</h3>
            <form action="{{ route('app.settings.departments.store') }}" method="POST" class="space-y-3">
                @csrf
                <div>
                    <label class="block font-semibold mb-1">Department Name *</label>
                    <input type="text" name="name" required placeholder="Document Processing & Clearances" class="w-full px-3 py-2 bg-slate-50 dark:bg-slate-900 border border-slate-300 dark:border-slate-700 rounded-xl">
                </div>
                <div class="flex justify-end space-x-2 rtl:space-x-reverse pt-2">
                    <button type="button" @click="modal = false" class="px-4 py-2 bg-slate-200 dark:bg-slate-700 text-slate-700 dark:text-slate-200 font-bold rounded-xl">Cancel</button>
                    <button type="submit" class="px-5 py-2 bg-sky-600 text-white font-bold rounded-xl">Add Department</button>
                </div>
            </form>
        </div>
    </div>
</div>
@endsection
