<form action="{{route('factory.reciever.post.edit.user')}}" method="post" class="mb-5">
    {{csrf_field()}}
    <div class="row mt-3">
        <input type="hidden" name="userid" id="userid" value=" {{$user_selected->id}}">
        <div class="col-12 col-lg-6">
            <div class="form-group">
                <label for="first_name" class="mb-2">نام</label>
                <input type="text" class=" form-control" name="first_name" id="first_name" placeholder="نام" value=" {{$user_selected->first_name}}">
            </div>
        </div>
        <div class="col-12 col-lg-6 mt-3 mt-lg-0">
            <div class="form-group">
                <label for="last_name" class="mb-2">نام خانوادگی</label>
                <input type="text" class=" form-control" name="last_name" id="last_name" placeholder="نام خانوادگی" value=" {{$user_selected->last_name}}">
            </div>
        </div>
    </div>
    @php
        $subusers = json_decode($user_selected->sub_users, true);
    @endphp
    @if ($user_selected->role == 'chief_worker')
    <div class="row mt-3">
        <div class="col-12 col-lg-6">
            <div class="form-group">
                <label for="subusers" class="mb-2">زیرمجموعه ها</label>
                <select name="subusers" id="subusers" class="form-control" data-placeholder="انتخاب زیرمجموعه" multiple="multiple" data-multi-select>
                    @foreach ($user_worker as $userInfo)
                    <option value="{{ $userInfo->id }}"
                        {{!empty($subusers) && in_array($userInfo->id, $subusers) ? 'selected' : '' }}>
                        {{ $userInfo->first_name }} {{ $userInfo->last_name }}
                    </option>
                    @endforeach
                </select>
            </div>
        </div>
    </div>
    @endif
    <div class="row mt-3">
        <div class="col-12 col-lg-6">
            <div class="form-group">
                <label for="role" class="mb-2">نقش کاربر</label>
                <select class=" form-control" name="role" id="role">
                    <option value="chief_worker" {{($user_selected->role == 'chief_worker') ? 'selected' : ''}} >سرتیم</option>
                    <option value="worker" {{($user_selected->role == 'worker') ? 'selected' : ''}} >کارگر</option>
                </select>
            </div>
        </div>
        <div class="col-12 col-lg-6 mt-3 mt-lg-0 d-flex align-items-end">
            <div class="form-group w-100">
                <button type="submit" class=" btn btn-success w-100">ویرایش کاربر</button>
            </div>
        </div>
    </div>
</form>