<div class="tab d-none py-5">
    <div class="row form-group mb-3">
        <label class="col-md-4 col-lg-2 d-flex align-items-center justify-content-end gap-1 form-label">
            {{ _trans('common.Employee ID') }}
        </label>
        <div class="col-md-8 col-lg-10">
            <input type="text" name="employee_id" class="form-control ot-form-control ot-input"
                value="{{ old('employee_id', @$user->employee_id) }}" placeholder="{{ _trans('common.Employee ID') }}">
            @if ($errors->has('employee_id'))
                <div class="error text-danger">{{ $errors->first('employee_id') }}</div>
            @endif
        </div>
    </div>
    <div class="row form-group mb-3">
        <label class="col-md-4 col-lg-2 d-flex align-items-center justify-content-end gap-1 form-label">
            {{ _trans('common.Joining Date') }} <span class="text-danger">*</span>
        </label>
        <div class="col-md-8 col-lg-10">
            <input type="date" name="joining_date" autocomplete="off" class="form-control ot-form-control ot-input"
                value="{{ old('joining_date', @$user->joining_date) }}">
            @if ($errors->has('joining_date'))
                <div class="error text-danger">{{ $errors->first('joining_date') }}</div>
            @endif
        </div>
    </div>
    <div class="row form-group mb-3">
        <label class="col-md-4 col-lg-2 d-flex align-items-center justify-content-end gap-1 form-label">
            {{ _trans('common.Department') }} <span class="text-danger">*</span>
        </label>
        <div class="col-md-8 col-lg-10">
            <select name="department_id" class="form-select select2"
                data-placeholder="{{ _trans('common.Choose One') }}">
                <option value="" selected disabled></option>
                @foreach ($data['departments'] as $department)
                    <option value="{{ $department->id }}"
                        {{ old('department_id', @$user->department_id) == $department->id ? 'selected' : '' }}>
                        {{ $department->title }}
                    </option>
                @endforeach
            </select>
            @if ($errors->has('department_id'))
                <span class="error text-danger">
                    {{ $errors->first('department_id') }}
                </span>
            @endif
        </div>
    </div>
    <div class="row form-group mb-3">
        <label class="col-md-4 col-lg-2 d-flex align-items-center justify-content-end gap-1 form-label">
            {{ _trans('common.Designation') }} <span class="text-danger">*</span>
        </label>
        <div class="col-md-8 col-lg-10">
            <select name="designation_id" class="form-select select2"
                data-placeholder="{{ _trans('common.Choose One') }}">
                <option value="" selected disabled></option>
                @foreach ($data['designations'] as $designation)
                    <option value="{{ $designation->id }}"
                        {{ old('designation_id', @$user->designation_id) == $designation->id ? 'selected' : '' }}>
                        {{ $designation->title }}
                    </option>
                @endforeach
            </select>
            @if ($errors->has('designation_id'))
                <span class="error text-danger">
                    {{ $errors->first('designation_id') }}
                </span>
            @endif
        </div>
    </div>
    <div class="row form-group mb-3">
        <label class="col-md-4 col-lg-2 d-flex align-items-center justify-content-end gap-1 form-label">
            {{ _trans('common.Duty Schedule') }} <span class="text-danger">*</span>
        </label>
        <div class="col-md-8 col-lg-10">
            <select name="duty_schedule_id" class="form-select select2" required>
                <option disabled selected value="">{{ _trans('common.Choose One') }}</option>
                @foreach ($data['dutySchedules'] as $dutySchedule)
                    <option value="{{ $dutySchedule->id }}"
                        {{ old('duty_schedule_id', @$user->duty_schedule_id) == $dutySchedule->id ? 'selected' : '' }}>
                        {{ $dutySchedule->shift }}
                    </option>
                @endforeach
            </select>
            @if ($errors->has('duty_schedule_id'))
                <span class="error text-danger">
                    {{ $errors->first('duty_schedule_id') }}
                </span>
            @endif
        </div>
    </div>
    <div class="row form-group mb-3">
        <label class="col-md-4 col-lg-2 d-flex align-items-center justify-content-end gap-1 form-label">
            {{ _trans('user.Manager') }}
        </label>
        <div class="col-md-8 col-lg-10">
            <select name="manager_id" class="form-select select2">
                <option disabled selected value="">{{ _trans('common.Choose One') }}</option>
                @foreach ($data['managers'] as $manager)
                    <option value="{{ $manager->id }}"
                        {{ old('manager_id', @$user->manager_id) == $manager->id ? 'selected' : '' }}>
                        {{ $manager->name }} [{{ @$manager->designation->title }}]
                    </option>
                @endforeach
            </select>
            @if ($errors->has('manager_id'))
                <small class="error">{{ $errors->first('manager_id') }}</small>
            @endif
        </div>
    </div>
    @if (@$user->role->slug == 'superadmin')
        <input type="hidden" name="role_id" value="{{ $user->role_id }}">
    @else
        <div class="row form-group mb-3">
            <label class="col-md-4 col-lg-2 d-flex align-items-center justify-content-end gap-1 form-label">
                {{ _trans('common.Role') }} <span class="text-danger">*</span>
            </label>
            <div class="col-md-8 col-lg-10">
                <select name="role_id" class="form-select select2"
                    data-placeholder="{{ _trans('common.Choose One') }}">
                    <option value="" selected disabled></option>
                    @foreach ($data['roles'] as $role)
                        <option value="{{ $role->id }}"
                            {{ old('role_id', @$user->role_id) == $role->id ? 'selected' : '' }}>
                            {{ $role->name }}
                        </option>
                    @endforeach
                </select>
                @if ($errors->has('role_id'))
                    <span class="error text-danger">
                        {{ $errors->first('role_id') }}
                    </span>
                @endif
            </div>
        </div>
    @endif
    <div class="row form-group mb-3">
        <label class="col-md-4 col-lg-2 d-flex align-items-center justify-content-end gap-1 form-label">
            {{ _trans('common.Time Zone') }}
        </label>
        <div class="col-md-8 col-lg-10">
            <select id="time_zone" name="time_zone" class="form-select select2"
                data-placeholder="{{ _trans('common.Choose One') }}">
                <option value="" selected disabled></option>
                @foreach ($data['timezones'] ?? [] as $timezone)
                    <option value="{{ $timezone->time_zone }}"
                        {{ old('time_zone', @$user->time_zone) == $timezone->time_zone ? 'selected' : '' }}>
                        {{ $timezone->time_zone }}
                    </option>
                @endforeach
            </select>
            @if ($errors->has('time_zone'))
                <div class="error">{{ $errors->first('time_zone') }}</div>
            @endif
        </div>
    </div>

    <div class="row form-group mb-3">
        <label class="col-md-4 col-lg-2 d-flex align-items-center justify-content-end gap-1 form-label">
            {{ _trans('common.Status') }}
        </label>
        <div class="col-md-8 col-lg-10">
            <select id="status_id" name="status_id" class="form-select select2"
                data-placeholder="{{ _trans('common.Choose One') }}">
                <option value="" selected disabled></option>

                @foreach ($data['statuses'] ?? [] as $status)
                    <option value="{{ $status->id }}"
                        {{ old('status_id', @$user->status_id) == $status->id ? 'selected' : '' }}>
                        {{ $status->name }}
                    </option>
                @endforeach
            </select>
            @if ($errors->has('status_id'))
                <div class="error">{{ $errors->first('status_id') }}</div>
            @endif
        </div>
    </div>

    <div class="row form-group mb-3">
        <label class="col-md-4 col-lg-2 d-flex align-items-center justify-content-end gap-1 form-label">
            {{ _trans('common.Attendance Method') }} <span class="text-danger">*</span>
        </label>
        <div class="col-md-8 col-lg-10">
            <select name="attendance_method[]" class="form-control" id="attendance_method" multiple>
                @if (@$user && @$user->attendance_method)
                    @foreach ($user->attendance_method as $key => $method)
                        <option value="{{ $key }}" {{ $method === 1 ? 'selected' : '' }}>
                            {{ ucwords(str_replace('_', ' ', $key)) }}</option>
                    @endforeach
                @else
                    <option value="normal_attendance" selected>{{ _trans('common.Normal Attendance') }}</option>
                @endif
            </select>
            @if ($errors->has('attendance_method'))
                <div class="error">{{ $errors->first('attendance_method') }}</div>
            @endif
        </div>
    </div>

    <div class="row form-group mb-3">
        <label class="col-md-4 col-lg-2 d-flex align-items-center justify-content-end gap-1 form-label">
            {{ _trans('common.Password') }}</span>
        </label>
        <div class="col-md-8 col-lg-10">
            <div class="form-group">
                <input type="text" name="password" placeholder="{{ _trans('common.Password') }}"
                    class="form-control ot-form-control ot-input mt-1" value="{{ old('password') }}" id="password">
                @if ($errors->has('password'))
                    <div class="error text-danger">{{ $errors->first('password') }}</div>
                @endif
            </div>
            <span
                class="text-warning">{{ _trans('common.If no password is provided, set the default password to 12345678 when creating a user.') }}</span>

            @if ($errors->has('password'))
                <div class="error">{{ $errors->first('password') }}</div>
            @endif
        </div>
    </div>

    @if (isModuleActive('IpBasedAttendance'))
        <div class="row form-group mb-3">
            <label class="col-md-4 col-lg-2 d-flex align-items-center justify-content-end gap-1 form-label">
                {{ _trans('common.Is Free IP') }}
            </label>
            <div class="col-md-8 col-lg-10">
                <select name="is_free_ip" id="is_free_ip" class="form-select select2"
                    data-placeholder="{{ _trans('common.Choose One') }}">
                    <option value="1" {{ old('is_free_ip', @$user->is_free_ip) == '1' ? 'selected' : '' }}>
                        {{ _trans('common.Yes') }}
                    </option>
                    <option value="0" {{ old('is_free_ip', @$user->is_free_ip) == '0' ? 'selected' : '' }}>
                        {{ _trans('common.No') }}
                    </option>
                </select>
                @if ($errors->has('is_free_ip'))
                    <div class="error">{{ $errors->first('is_free_ip') }}</div>
                @endif
            </div>
        </div>

        <div class="row form-group mb-3" id="ip_address_div">
            <label class="col-md-4 col-lg-2 d-flex align-items-center justify-content-end gap-1 form-label">
                {{ _trans('common.IP Addresses') }} <span class="text-danger">*</span>
            </label>
            <div class="col-md-8 col-lg-10">
                @php
                    if (@$user->ipBind->ip_addresses) {
                        $ipAddresses = implode(', ', @$user->ipBind->ip_addresses);
                    } else {
                        $ipAddresses = '';
                    }
                @endphp

                <input type="text" name="ip_addresses" class="form-control ot-form-control ot-input"
                    value="{{ old('ip_addresses', $ipAddresses) }}" placeholder="127.0.0.1, 127.0.0.2" required>

                @if ($errors->has('ip_addresses'))
                    <div class="error text-danger">{{ $errors->first('ip_addresses') }}</div>
                @endif
            </div>
        </div>
    @endif

    @if (isModuleActive('AreaBasedAttendance'))
        <div class="row form-group mb-3 align-items-start">
            <label class="col-md-4 col-lg-2 d-flex align-items-center justify-content-end gap-1 form-label mt-4">
                {{ _trans('common.Is Free Location') }}
            </label>
            <div class="col-md-8 col-lg-10">
                <select name="is_free_location" id="is_free_location" class="form-select select2"
                    data-placeholder="{{ _trans('common.Choose One') }}">
                    <option value="1"
                        {{ old('is_free_location', @$user->is_free_location) == '1' ? 'selected' : '' }}>
                        {{ _trans('common.Yes') }}
                    </option>
                    <option value="0"
                        {{ old('is_free_location', @$user->is_free_location) == '0' ? 'selected' : '' }}>
                        {{ _trans('common.No') }}
                    </option>
                </select>
                @if ($errors->has('is_free_location'))
                    <div class="error">{{ $errors->first('is_free_location') }}</div>
                @endif

                <div class="mt-3" id="location_div">
                    <div class="location_heading mb-10 d-flex align-items-center justify-content-between gap-4">
                        <h4>{{ _trans('common.Allow Location') }}</h4>
                        <button type="button" class="button btn btn-primary bg-gradient" data-bs-toggle="modal"
                            href="#exampleModalToggle">
                            {{ _trans('common.Add Location') }}
                        </button>
                    </div>
                    <div class="location_list">
                        <div class="table-content table-basic">
                            <div class="table-responsive  min-height-500">
                                <table class="table table-bordered">
                                    <thead class="thead">
                                        <tr>
                                            <th>{{ _trans('common.ID') }}</th>
                                            <th>{{ _trans('common.Location') }}</th>
                                            <th>{{ _trans('common.Action') }}</th>
                                        </tr>
                                    </thead>
                                    <tbody class="tbody">
                                        @foreach (@$user->locationBinds ?? [] as $key => $locationBind)
                                            <tr>
                                                <td>{{ ++$key }}</td>
                                                <td id="location-{{ $locationBind->id }}">
                                                    {{ $locationBind->address }}</td>
                                                <td>
                                                    <button type="button"
                                                        class="btn btn-sm btn-success location-edit-btn"
                                                        data-id="{{ $locationBind->id }}"
                                                        data-latitude="{{ $locationBind->latitude }}"
                                                        data-longitude="{{ $locationBind->longitude }}"
                                                        data-address="{{ $locationBind->address }}"
                                                        data-distance="{{ $locationBind->distance }}"
                                                        data-bs-toggle="modal" href="#locationEditModal">

                                                        <i class="fa fa-edit"></i>
                                                    </button>

                                                    <button type="button" class="btn btn-sm btn-danger"
                                                        onclick="deleteLocation('{{ $locationBind->id }}')">
                                                        <i class="fa fa-trash"></i>
                                                    </button>
                                                </td>
                                            </tr>
                                        @endforeach
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    @endif
</div>
