@extends('layouts.app')
@section('title','Employees - Movex Canada HR')
@section('page_title','Employees')
@section('page_subtitle','Create, search and manage Canadian staff records. Role changes remain database-only.')
@section('content')
@php($provinces = config('hr_canada.provinces'))
@php($statuses = config('hr_canada.employment_statuses'))
@php($payrollFrequencies = config('hr_canada.payroll_frequencies'))
<div class="card">
    <form method="GET" class="form-row">
        <div class="field"><label>Search</label><input class="input" name="search" value="{{ request('search') }}" placeholder="Name, email, staff ID"></div>
        <div class="field"><label>Status</label><select name="employment_status"><option value="">All</option>@foreach($statuses as $s)<option value="{{ $s }}" @selected(request('employment_status')===$s)>{{ ucfirst(str_replace('_',' ', $s)) }}</option>@endforeach</select></div>
        <div class="field"><button class="btn">Filter</button></div>
    </form>
</div>
<div class="card">
    <h3>Add Employee</h3>
    <form method="POST" action="{{ route('admin.employees.store') }}">@csrf
        <div class="form-row">
            <div class="field"><label>Name</label><input class="input" name="name" required></div>
            <div class="field"><label>Email</label><input class="input" type="email" name="email" required></div>
            <div class="field"><label>Phone</label><input class="input" name="phone" placeholder="+1 204 555 0101"></div>
            <div class="field"><label>Password</label><input class="input" type="password" name="password" value="password123" required></div>
            <div class="field"><label>Department</label><select name="department_id"><option value="">None</option>@foreach($departments as $department)<option value="{{ $department->id }}">{{ $department->name }}</option>@endforeach</select></div>
            <div class="field"><label>Designation</label><select name="designation_id"><option value="">None</option>@foreach($designations as $designation)<option value="{{ $designation->id }}">{{ $designation->name }}</option>@endforeach</select></div>
            <div class="field"><label>Job Title</label><input class="input" name="job_title"></div>
            <div class="field"><label>Employment Date</label><input class="input" type="date" name="employment_date"></div>
            <div class="field"><label>Status</label><select name="employment_status">@foreach($statuses as $s)<option value="{{ $s }}">{{ ucfirst(str_replace('_',' ', $s)) }}</option>@endforeach</select></div>
            <div class="field"><label>Basic Salary / Pay Amount (CAD)</label><input class="input" type="number" step="0.01" name="basic_salary" value="0"></div>
            <div class="field"><label>Payroll Frequency</label><select name="payroll_frequency">@foreach($payrollFrequencies as $frequency)<option value="{{ $frequency }}" @selected($frequency==='biweekly')>{{ ucfirst(str_replace('_',' ', $frequency)) }}</option>@endforeach</select></div>
            <div class="field"><label>Tax Province/Territory</label><select name="tax_province"><option value="">Select</option>@foreach($provinces as $code => $province)<option value="{{ $code }}">{{ $code }} - {{ $province }}</option>@endforeach</select></div>
            <div class="field"><label>Gender</label><select name="gender"><option value="">Select</option><option>Male</option><option>Female</option><option>Other</option><option>Prefer not to say</option></select></div>
            <div class="field"><label>Date of Birth</label><input class="input" type="date" name="date_of_birth"></div>
            <div class="field"><label>SIN Last 4 Digits</label><input class="input" name="sin_last4" maxlength="4" placeholder="1234"></div>
            <div class="field"><label>Work Authorization</label><select name="work_authorization_status"><option value="">Select</option><option>Canadian citizen</option><option>Permanent resident</option><option>Work permit</option><option>Study permit with work authorization</option><option>Other authorized worker</option></select></div>
            <div class="field"><label>Province/Territory</label><select name="province"><option value="">Select</option>@foreach($provinces as $code => $province)<option value="{{ $code }}">{{ $code }} - {{ $province }}</option>@endforeach</select></div>
            <div class="field"><label>Postal Code</label><input class="input" name="postal_code" placeholder="R3C 4T3"></div>
            <div class="field"><label>Bank Name</label><input class="input" name="bank_name" placeholder="RBC, TD, Scotiabank..."></div>
            <div class="field"><label>Institution Number</label><input class="input" name="bank_institution_number" placeholder="003"></div>
            <div class="field"><label>Transit Number</label><input class="input" name="bank_transit_number" placeholder="00001"></div>
            <div class="field"><label>Account Number</label><input class="input" name="bank_account"></div>
        </div>
        <div class="field"><label>Address</label><input class="input" name="address" placeholder="Street, city, province, Canada"></div>
        <div class="field"><label>Emergency Contact</label><input class="input" name="emergency_contact" placeholder="Name and Canadian phone number"></div>
        <button class="btn">Save Employee</button>
    </form>
</div>
<div class="card">
    <div class="section-title"><h3>Employee List</h3><span class="muted">{{ $employees->total() }} records</span></div>
    <div class="table-wrap"><table class="table"><tr><th>Staff ID</th><th>Name</th><th>Dept</th><th>Province</th><th>Designation</th><th>Role</th><th>Status</th><th></th></tr>
        @forelse($employees as $employee)<tr><td class="mono">{{ $employee->staff_id }}</td><td><strong>{{ $employee->name }}</strong><br><span class="muted small">{{ $employee->email }}</span></td><td>{{ $employee->department?->name ?? '-' }}</td><td>{{ $employee->province ?? '-' }}</td><td>{{ $employee->designation?->name ?? '-' }}</td><td><span class="badge">{{ strtoupper($employee->role) }}</span></td><td><span class="badge {{ $employee->employment_status === 'active' ? 'green' : 'yellow' }}">{{ ucfirst(str_replace('_',' ', $employee->employment_status)) }}</span></td><td><a class="btn secondary" href="{{ route('admin.employees.show',$employee) }}">View</a></td></tr>@empty<tr><td colspan="8"><div class="empty">No employees found.</div></td></tr>@endforelse
    </table></div><div class="pagination">{{ $employees->links() }}</div>
</div>
@endsection
