@extends('layouts.admin')

@section('title', 'Staff')

@section('content')
<div class="fundi-page-header">
    <div>
        <h1>Staff</h1>
        <p class="fundi-page-header__desc">Internal users and role assignments.</p>
    </div>
</div>

<form method="GET" class="fundi-filters">
    <div class="fundi-form-group">
        <label for="search">Search</label>
        <input type="text" id="search" name="search" class="fundi-input" value="{{ request('search') }}" placeholder="Name, email, staff code">
    </div>
    <div class="fundi-form-group">
        <label for="department">Department</label>
        <select id="department" name="department" class="fundi-select">
            <option value="">All departments</option>
            @foreach($departments as $dept)
                <option value="{{ $dept }}" @selected(request('department') === $dept)>{{ $dept }}</option>
            @endforeach
        </select>
    </div>
    <div class="fundi-form-group">
        <label for="status">Status</label>
        <select id="status" name="status" class="fundi-select">
            <option value="">All</option>
            @foreach(['active','inactive','suspended'] as $s)
                <option value="{{ $s }}" @selected(request('status') === $s)>{{ ucfirst($s) }}</option>
            @endforeach
        </select>
    </div>
    <button type="submit" class="fundi-btn fundi-btn--secondary">Filter</button>
</form>

<div class="fundi-card">
    <div class="fundi-card__body">
        <div class="fundi-table-wrap">
            <table class="fundi-table">
                <thead>
                    <tr>
                        <th>Staff Code</th>
                        <th>Name</th>
                        <th>Email</th>
                        <th>Role</th>
                        <th>Department</th>
                        <th>Designation</th>
                        <th>Flags</th>
                        <th>Status</th>
                    </tr>
                </thead>
                <tbody>
                    @forelse($staff as $member)
                        <tr>
                            <td>{{ $member->staff_code ?? '—' }}</td>
                            <td>{{ $member->name }}</td>
                            <td>{{ $member->email }}</td>
                            <td>{{ $member->role->name ?? '—' }}</td>
                            <td>{{ $member->department ?? '—' }}</td>
                            <td>{{ $member->designation ?? '—' }}</td>
                            <td>
                                @if($member->is_inputer)<span class="fundi-badge fundi-badge--info">Inputer</span>@endif
                                @if($member->is_authorizer)<span class="fundi-badge fundi-badge--navy">Authorizer</span>@endif
                            </td>
                            <td><x-status-badge :status="$member->status" /></td>
                        </tr>
                    @empty
                        <tr><td colspan="8" class="fundi-empty">No staff found.</td></tr>
                    @endforelse
                </tbody>
            </table>
        </div>
        @if($staff->hasPages())
            <div class="fundi-pagination">{{ $staff->links() }}</div>
        @endif
    </div>
</div>
@endsection
