@extends('layouts.app')
@section('title',$employee->name.' - Employee')
@section('page_title',$employee->name)
@section('page_subtitle','Employee profile, Canadian payroll fields, HR records and account details.')
@section('content')
@php($provinces = config('hr_canada.provinces'))
@php($statuses = config('hr_canada.employment_statuses'))
@php($payrollFrequencies = config('hr_canada.payroll_frequencies'))
<div class="grid grid-3">
    <div class="stat"><span class="muted">Staff ID</span><strong class="mono">{{ $employee->staff_id }}</strong></div>
    <div class="stat"><span class="muted">Department</span><strong>{{ $employee->department?->name ?? '-' }}</strong></div>
    <div class="stat"><span class="muted">Salary / Pay Amount</span><strong>C${{ number_format($employee->basic_salary,2) }}</strong></div>
</div>
<div class="card">
    <h3>Edit Employee</h3>
    <form method="POST" action="{{ route('admin.employees.update',$employee) }}">@csrf @method('PUT')
        <div class="form-row">
            <div class="field"><label>Name</label><input class="input" name="name" value="{{ old('name',$employee->name) }}" required></div>
            <div class="field"><label>Email</label><input class="input" type="email" name="email" value="{{ old('email',$employee->email) }}" required></div>
            <div class="field"><label>Phone</label><input class="input" name="phone" value="{{ old('phone',$employee->phone) }}"></div>
            <div class="field"><label>New Password</label><input class="input" type="password" name="password" placeholder="Leave blank to keep old password"></div>
            <div class="field"><label>Department</label><select name="department_id"><option value="">None</option>@foreach($departments as $department)<option value="{{ $department->id }}" @selected($employee->department_id==$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 }}" @selected($employee->designation_id==$designation->id)>{{ $designation->name }}</option>@endforeach</select></div>
            <div class="field"><label>Job Title</label><input class="input" name="job_title" value="{{ old('job_title',$employee->job_title) }}"></div>
            <div class="field"><label>Employment Date</label><input class="input" type="date" name="employment_date" value="{{ optional($employee->employment_date)->format('Y-m-d') }}"></div>
            <div class="field"><label>Status</label><select name="employment_status">@foreach($statuses as $s)<option value="{{ $s }}" @selected($employee->employment_status===$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="{{ $employee->basic_salary }}"></div>
            <div class="field"><label>Payroll Frequency</label><select name="payroll_frequency">@foreach($payrollFrequencies as $frequency)<option value="{{ $frequency }}" @selected(($employee->payroll_frequency ?? 'biweekly')===$frequency)>{{ 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 }}" @selected($employee->tax_province===$code)>{{ $code }} - {{ $province }}</option>@endforeach</select></div>
            <div class="field"><label>Gender</label><input class="input" name="gender" value="{{ $employee->gender }}"></div>
            <div class="field"><label>Date of Birth</label><input class="input" type="date" name="date_of_birth" value="{{ optional($employee->date_of_birth)->format('Y-m-d') }}"></div>
            <div class="field"><label>SIN Last 4 Digits</label><input class="input" name="sin_last4" maxlength="4" value="{{ $employee->sin_last4 }}"></div>
            <div class="field"><label>Work Authorization</label><input class="input" name="work_authorization_status" value="{{ $employee->work_authorization_status }}"></div>
            <div class="field"><label>Province/Territory</label><select name="province"><option value="">Select</option>@foreach($provinces as $code => $province)<option value="{{ $code }}" @selected($employee->province===$code)>{{ $code }} - {{ $province }}</option>@endforeach</select></div>
            <div class="field"><label>Postal Code</label><input class="input" name="postal_code" value="{{ $employee->postal_code }}"></div>
            <div class="field"><label>Bank Name</label><input class="input" name="bank_name" value="{{ $employee->bank_name }}"></div>
            <div class="field"><label>Institution Number</label><input class="input" name="bank_institution_number" value="{{ $employee->bank_institution_number }}"></div>
            <div class="field"><label>Transit Number</label><input class="input" name="bank_transit_number" value="{{ $employee->bank_transit_number }}"></div>
            <div class="field"><label>Account Number</label><input class="input" name="bank_account" value="{{ $employee->bank_account }}"></div>
        </div>
        <div class="field"><label>Address</label><input class="input" name="address" value="{{ $employee->address }}"></div>
        <div class="field"><label>Emergency Contact</label><input class="input" name="emergency_contact" value="{{ $employee->emergency_contact }}"></div>
        <div class="help small"><strong>Role:</strong> {{ strtoupper($employee->role) }}. This screen does not change role. Update role manually in the database as requested.</div>
        <button class="btn">Update Employee</button>
    </form>
</div>
<div class="grid grid-2">
    <div class="card"><h3>Recent Leave</h3><table class="table"><tr><th>Type</th><th>Dates</th><th>Status</th></tr>@foreach($employee->leaveRequests->take(5) as $leave)<tr><td>{{ $leave->leaveType?->name }}</td><td>{{ $leave->start_date?->format('d M Y') }} - {{ $leave->end_date?->format('d M Y') }}</td><td>{{ ucfirst($leave->status) }}</td></tr>@endforeach</table></div>
    <div class="card"><h3>Recent Payroll</h3><table class="table"><tr><th>Period</th><th>Net Pay</th><th>Status</th></tr>@foreach($employee->payrolls->take(5) as $payroll)<tr><td>{{ $payroll->pay_period_start?->format('M Y') }}</td><td>C${{ number_format($payroll->net_pay,2) }}</td><td>{{ ucfirst($payroll->status) }}</td></tr>@endforeach</table></div>
</div>
@endsection
