@extends('layouts.sash')

@section('title', 'Staff')

@section('content')
<div class="row mt-4">
<div class="col-12">
    <div class="page-header">
        <div>
            <h1 class="page-title">Staff</h1>
            <p class="page-subtitle">Manage your team, roles, and availability.</p>
        </div>
        <div class="page-actions">
            <a href="{{ route('staff.create') }}" class="btn btn-primary"><i class="fe fe-plus me-1"></i>Add Staff</a>
        </div>
    </div>

    <div class="card mb-4">
        <div class="card-body">
            <form method="get" action="{{ route('staff.index') }}" class="row g-3 align-items-end">
                <div class="col-12 col-md-6 col-lg-4">
                    <label class="form-label">Search</label>
                    <input type="text" name="search" value="{{ request('search') }}" placeholder="Name, mobile, email..." class="form-control">
                </div>
                <div class="col-12 col-md-6 col-lg-3">
                    <label class="form-label">Branch</label>
                    <select name="branch_id" class="form-control form-select">
                        <option value="">All</option>
                        @foreach($branches as $b)
                            <option value="{{ $b->id }}" {{ (string)request('branch_id') === (string)$b->id ? 'selected' : '' }}>{{ $b->name }}</option>
                        @endforeach
                    </select>
                </div>
                <div class="col-12 col-md-6 col-lg-2">
                    <label class="form-label">Status</label>
                    <select name="status" class="form-control form-select">
                        <option value="">All</option>
                        <option value="active" {{ request('status') === 'active' ? 'selected' : '' }}>Active</option>
                        <option value="inactive" {{ request('status') === 'inactive' ? 'selected' : '' }}>Inactive</option>
                        <option value="on_leave" {{ request('status') === 'on_leave' ? 'selected' : '' }}>On Leave</option>
                    </select>
                </div>
                <div class="col-12 col-lg-auto">
                    <button type="submit" class="btn btn-primary"><i class="fe fe-filter me-1"></i>Filter</button>
                </div>
            </form>
        </div>
    </div>

    <div class="card">
        <div class="card-body">
            <div class="table-responsive">
                <table class="table border text-nowrap text-md-nowrap table-hover mb-0">
                    <thead>
                        <tr>
                            <th>Code</th>
                            <th>Name</th>
                            <th>Branch</th>
                            <th>Designation</th>
                            <th>Status</th>
                            <th class="text-end">Actions</th>
                        </tr>
                    </thead>
                    <tbody>
                        @forelse($staff as $member)
                        <tr>
                            <td>{{ $member->employee_code }}</td>
                            <td>{{ $member->full_name }}</td>
                            <td>{{ $member->branch?->name ?? '—' }}</td>
                            <td>{{ $member->designation ?? '—' }}</td>
                            <td>
                                @php
                                    $badgeClass = match($member->status) {
                                        'active' => 'badge-success',
                                        'on_leave' => 'badge-warning',
                                        default => 'badge-muted',
                                    };
                                @endphp
                                <span class="badge {{ $badgeClass }}">
                                    {{ $member->status }}
                                </span>
                            </td>
                            <td class="text-end table-actions">
                        <a href="{{ route('staff.show', $member) }}" class="btn btn-icon btn-sm btn-light" title="View"><i class="fe fe-eye"></i></a>
                        <a href="{{ route('staff.edit', $member) }}" class="btn btn-icon btn-sm btn-light" title="Edit"><i class="fe fe-edit"></i></a>
                        <form action="{{ route('staff.destroy', $member) }}" method="POST" class="d-inline" onsubmit="return confirm('Delete this staff member?');">
                            @csrf
                            @method('DELETE')
                            <button type="submit" class="btn btn-icon btn-sm btn-light text-danger" title="Delete"><i class="fe fe-trash-2"></i></button>
                        </form>
                    </td>
                </tr>
                        @empty
                        <tr>
                            <td colspan="6" class="text-center text-muted py-4">No staff found.</td>
                        </tr>
                        @endforelse
                    </tbody>
                </table>
            </div>
        </div>
    </div>

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