@extends('layouts.app')

@section('title', 'Employee Directory')

@section('content')
<div class="space-y-6">
    <div class="flex flex-col sm:flex-row sm:items-center justify-between gap-4">
        <div>
            <h1 class="text-xl font-bold text-slate-900 dark:text-white">Employee Directory</h1>
            <p class="text-xs text-slate-500 dark:text-slate-400">Master record of all typing center employees and staff.</p>
        </div>
        <a href="{{ route('app.employees.create') }}" class="inline-flex items-center px-4 py-2 bg-sky-600 hover:bg-sky-700 text-white font-semibold text-xs rounded-xl shadow-sm transition-all">
            + Create New Employee
        </a>
    </div>

    <!-- Search Bar -->
    <div class="bg-white dark:bg-slate-800 rounded-3xl p-4 border border-slate-200 dark:border-slate-700/60 shadow-sm">
        <form action="{{ route('app.employees.index') }}" method="GET" class="flex gap-3 text-xs">
            <input type="text" name="search" value="{{ request('search') }}" placeholder="Search by name, employee code, mobile, email..." class="flex-1 px-3 py-2 bg-slate-50 dark:bg-slate-900 border border-slate-300 dark:border-slate-700 rounded-xl text-slate-900 dark:text-white">
            <button type="submit" class="px-4 py-2 bg-sky-600 text-white font-bold rounded-xl hover:bg-sky-700">Search</button>
        </form>
    </div>

    <!-- Employee Table (Requirement 3) -->
    <div class="bg-white dark:bg-slate-800 rounded-3xl border border-slate-200 dark:border-slate-700/60 shadow-sm overflow-hidden">
        <div class="overflow-x-auto">
            <table class="w-full text-left rtl:text-right text-xs">
                <thead class="bg-slate-50 dark:bg-slate-900/60 border-b border-slate-200 dark:border-slate-700 text-slate-500 uppercase tracking-wider font-bold">
                    <tr>
                        <th class="px-6 py-4">Employee Code</th>
                        <th class="px-6 py-4">Full Name</th>
                        <th class="px-6 py-4">Designation</th>
                        <th class="px-6 py-4">Branch</th>
                        <th class="px-6 py-4">ERP Access</th>
                        <th class="px-6 py-4">Status</th>
                        <th class="px-6 py-4 text-right rtl:text-left">Actions</th>
                    </tr>
                </thead>
                <tbody class="divide-y divide-slate-200 dark:divide-slate-700/60 font-medium">
                    @foreach($employees as $emp)
                        <tr class="hover:bg-slate-50 dark:hover:bg-slate-700/30">
                            <td class="px-6 py-4 font-mono font-bold text-sky-600 dark:text-sky-400">{{ $emp->employee_code }}</td>
                            <td class="px-6 py-4">
                                <div class="font-bold text-slate-900 dark:text-white">{{ $emp->full_name }}</div>
                                <div class="text-[11px] text-slate-400 font-normal">{{ $emp->email }} • {{ $emp->mobile }}</div>
                            </td>
                            <td class="px-6 py-4 text-slate-700 dark:text-slate-300 font-medium">{{ $emp->designation ?? 'N/A' }}</td>
                            <td class="px-6 py-4 text-slate-700 dark:text-slate-300">{{ $emp->branch ? $emp->branch->name : 'N/A' }}</td>
                            <td class="px-6 py-4">
                                @if($emp->user)
                                    <span class="px-2.5 py-0.5 rounded-full bg-emerald-100 dark:bg-emerald-950 text-emerald-700 dark:text-emerald-300 text-[10px] font-bold">Has ERP Access</span>
                                @else
                                    <span class="px-2.5 py-0.5 rounded-full bg-slate-100 dark:bg-slate-700 text-slate-500 text-[10px] font-bold">No Login Account</span>
                                @endif
                            </td>
                            <td class="px-6 py-4">
                                <span class="px-2.5 py-0.5 rounded-full bg-emerald-100 dark:bg-emerald-950 text-emerald-700 dark:text-emerald-300 text-[10px] font-bold">Active</span>
                            </td>
                            <td class="px-6 py-4 text-right rtl:text-left">
                                @if(!$emp->user)
                                    <a href="{{ route('app.employees.give_access', $emp->id) }}" class="px-3 py-1 bg-sky-600 hover:bg-sky-700 text-white rounded-lg text-[11px] font-bold shadow-sm">
                                        Give ERP Access
                                    </a>
                                @else
                                    <a href="{{ route('app.users.edit', $emp->user->id) }}" class="text-sky-600 hover:text-sky-800 font-bold">Edit Account</a>
                                @endif
                            </td>
                        </tr>
                    @endforeach
                </tbody>
            </table>
        </div>
        <div class="p-4 border-t border-slate-200 dark:border-slate-700">
            {{ $employees->links() }}
        </div>
    </div>
</div>
@endsection
