@extends('layouts.app')
@section('title',$employee->name.' - Employee')
@section('page_title',$employee->name)
@section('page_subtitle','Employee profile, HR records and account details.')
@section('content')
<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</span><strong>₦{{ 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(['active','probation','suspended','terminated','resigned'] as $s)<option value="{{ $s }}" @selected($employee->employment_status===$s)>{{ ucfirst($s) }}</option>@endforeach</select></div>
            <div class="field"><label>Basic Salary</label><input class="input" type="number" step="0.01" name="basic_salary" value="{{ $employee->basic_salary }}"></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>Bank Name</label><input class="input" name="bank_name" value="{{ $employee->bank_name }}"></div><div class="field"><label>Bank Account</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>₦{{ number_format($payroll->net_pay,2) }}</td><td>{{ ucfirst($payroll->status) }}</td></tr>@endforeach</table></div>
</div>
@endsection
