<div class="row g-4"><div class="col-md-8"><label class="form-label fw-semibold">Connected User *</label><div class="input-group"><span class="input-group-text"><i class="feather-user"></i></span><select id="employeeUserSelect" name="user_id" required class="form-select @error('user_id') is-invalid @enderror"><option value="">Select User</option>@foreach($users as $user)<option value="{{ $user->id }}" data-name="{{ $user->name }}" data-email="{{ $user->email }}" data-team="{{ $user->team_name ?: 'No Team' }}" @selected((int)old('user_id',$employee->user_id??0)===$user->id)>{{ $user->name }} · {{ $user->email }}{{ $user->team_name?' · '.$user->team_name:'' }}</option>@endforeach</select></div>@error('user_id')<div class="invalid-feedback d-block">{{ $message }}</div>@enderror<small class="text-muted">One Employee record can connect to one User account.</small></div><div class="col-md-4"><label class="form-label fw-semibold">Employee Code *</label><div class="input-group"><span class="input-group-text"><i class="feather-hash"></i></span><input name="employee_code" required maxlength="50" value="{{ old('employee_code',$employee->employee_code??'') }}" class="form-control" placeholder="EMP-001"></div></div>
<div class="col-12"><div id="employeeUserPreview" class="alert alert-primary d-none mb-0"><strong id="employeeUserName"></strong><span id="employeeUserEmail" class="ms-2"></span><span id="employeeUserTeam" class="badge bg-primary ms-2"></span></div></div>
<div class="col-md-6"><label class="form-label fw-semibold">Department</label><div class="input-group"><span class="input-group-text"><i class="feather-grid"></i></span><select name="department_id" class="form-select"><option value="">Select Department</option>@foreach($departments as $department)<option value="{{ $department->id }}" @selected((int)old('department_id',$employee->department_id??0)===$department->id)>{{ $department->name }}{{ $department->code?' · '.$department->code:'' }}</option>@endforeach</select></div></div><div class="col-md-6"><label class="form-label fw-semibold">Reporting Employee</label><div class="input-group"><span class="input-group-text"><i class="feather-user-check"></i></span><select name="manager_id" class="form-select"><option value="">Select manager</option>@foreach($managers as $manager)<option value="{{ $manager->id }}" @selected((int)old('manager_id',$employee->manager_id??0)===$manager->id)>{{ $manager->user?->name }} · {{ $manager->employee_code }}</option>@endforeach</select></div></div>
<div class="col-md-6"><label class="form-label fw-semibold">Job Title</label><div class="input-group"><span class="input-group-text"><i class="feather-briefcase"></i></span><input name="job_title" maxlength="255" value="{{ old('job_title',$employee->job_title??'') }}" class="form-control"></div></div><div class="col-md-6"><label class="form-label fw-semibold">Employment Type *</label><div class="input-group"><span class="input-group-text"><i class="feather-clock"></i></span><select name="employment_type" required class="form-select">@foreach(['full_time'=>'Full Time','part_time'=>'Part Time','contract'=>'Contract','intern'=>'Intern'] as $v=>$l)<option value="{{ $v }}" @selected(old('employment_type',$employee->employment_type??'full_time')===$v)>{{ $l }}</option>@endforeach</select></div></div>
<div class="col-md-4"><label class="form-label fw-semibold">Hire Date</label><input type="date" name="hire_date" value="{{ old('hire_date',isset($employee)&&$employee->hire_date?$employee->hire_date->toDateString():'') }}" class="form-control"></div><div class="col-md-4"><label class="form-label fw-semibold">Work Phone</label><div class="input-group"><span class="input-group-text"><i class="feather-phone"></i></span><input name="phone" maxlength="50" value="{{ old('phone',$employee->phone??'') }}" class="form-control"></div></div><div class="col-md-4"><label class="form-label fw-semibold">Work Location</label><div class="input-group"><span class="input-group-text"><i class="feather-map-pin"></i></span><input name="work_location" maxlength="255" value="{{ old('work_location',$employee->work_location??'') }}" class="form-control"></div></div><div class="col-md-6"><label class="form-label fw-semibold">Status *</label><div class="input-group"><span class="input-group-text"><i class="feather-toggle-right"></i></span><select name="status" required class="form-select">@foreach(['active'=>'Active','inactive'=>'Inactive','on_leave'=>'On Leave','terminated'=>'Terminated'] as $v=>$l)<option value="{{ $v }}" @selected(old('status',$employee->status??'active')===$v)>{{ $l }}</option>@endforeach</select></div></div></div>
@push('scripts')<script>document.addEventListener('DOMContentLoaded',function(){const select=document.getElementById('employeeUserSelect'),preview=document.getElementById('employeeUserPreview');function showUser(){const option=select.options[select.selectedIndex];if(!option?.value){preview.classList.add('d-none');return}document.getElementById('employeeUserName').textContent=option.dataset.name;document.getElementById('employeeUserEmail').textContent=option.dataset.email;document.getElementById('employeeUserTeam').textContent=option.dataset.team;preview.classList.remove('d-none')}select?.addEventListener('change',showUser);showUser()});</script>@endpush
