<div class="col-md-12 col-sm-12">
    <div class="col-sm-12 col-md-12">
        <div class="form-group fg-line">
            {!! Form::label('persona', 'Persona', ['class' => '']) !!}
            <select name="persona" class="form-control input-sm select-user" id="persona" disabled="disabled"></select>
            {{ Form::hidden('persona_id', (isset($userpersona) ? $userpersona->persona->persona_id : null), ['id' => 'persona_id']) }}
        </div>
    </div>
</div>
<div class="col-md-12 col-sm-12">
    <div class="col-sm-6 col-md-4">
        <div class="form-group fg-line">
            {!! Form::label('username', 'Usuario', ['class' => '']) !!}
            {!! Form::text('username',(isset($userpersona) ? $userpersona->user->username : null),['class'=>'form-control input-sm', 'id'=>'username', 'readonly'=>true ,'placeholder'=>'Usuario']) !!}
        </div>
    </div>
    <div class="col-sm-6 col-md-8">
        <div class="form-group fg-line">
            {!! Form::label('last_first_name', 'Apellidos y Nombres', ['class' => '']) !!}
            {!! Form::text('last_first_name',(isset($userpersona) ? $userpersona->user->last_first_name : null),['class'=>'form-control input-sm', 'id'=>'last_first_name', 'readonly'=>true, 'placeholder'=>'Apellidos y Nombres']) !!}
        </div>
    </div>
</div>
<div class="col-md-12 col-sm-12">
    <div class="col-sm-6 col-md-4">
        <div class="form-group fg-line">
            {!! Form::label('email', 'E-mail', ['class' => '']) !!}
            {!! Form::email('email',(isset($userpersona) ? $userpersona->user->email : null),['class'=>'form-control input-sm','id'=>'email','placeholder'=>'E-mail','readonly'=>true]) !!}
        </div>
    </div>
    @if(!isset($userpersona))
        {{--<div class="col-sm-6 col-md-4">--}}
        {{--<div class="form-group fg-line">--}}
        {{--{!! Form::label('password', 'Contraseña', ['class' => '']) !!}--}}
        {{--{!! Form::password('password',['class'=>'form-control input-sm','id'=>'password','placeholder'=>'**********']) !!}--}}
        {{--</div>--}}
        {{--</div>--}}
    @endif
    <div class="col-sm-6 col-md-4">
        <div class="form-group fg-line">
            {!! Form::label('role_id', 'Rol', ['class' => '']) !!}
            {!! Form::select('role_id', $roles, (isset($userpersona) ? $userpersona->user->role_id : null), ['id'=>'role_id', 'class'=>'form-control input-sm selectRol', 'placeholder' => 'Seleccione']) !!}
        </div>
    </div>
    <div class="col-sm-6 col-md-4">
        <div class="form-group fg-line">
            {!! Form::label('admin_label', 'Acceso Superadmin', ['class' => '']) !!}
            <div class="checkbox">
                <label>
                    {!! Form::checkbox('admin', 1 ,((isset($userpersona) && $userpersona->user->admin == 1) ? true : false)) !!}
                    <span class="text">Acceso</span>
                </label>
            </div>
        </div>
    </div>
</div>
{{--<div class="col-md-12 col-sm-12">--}}
{{--<div class="col-sm-6 col-md-4">--}}
{{--<div class="form-group fg-line">--}}
{{--<div class="checkbox">--}}
{{--<label>--}}
{{--{!! Form::checkbox('admin', 1 ,((isset($userpersona) && $userpersona->user->admin == 1) ? true : false)) !!}--}}
{{--<span class="text">Acceso Backend</span>--}}
{{--</label>--}}
{{--</div>--}}
{{--</div>--}}
{{--</div>--}}
{{--</div>--}}
<script>
    $(function () {
        // $('.selectRol').select2();
        $(".select-user").select2({
            ajax: {
                url: function (params) {
                    return LA.base_url + 'superadmin/ajax/persona/' + params.term;
                },
                type: 'POST',
                headers: {'X-CSRF-Token': $("input[name=_token]").val()},
                dataType: 'json',
                delay: 100,
                processResults: function (data) {
                    var arr = [];
//                    console.log("data---::: ", data);
                    if (data.length > 0) {
                        $.each(data, function (index, value) {
                            arr.push({
                                id: value.id,
                                text: value.apellidos_nombres + ' - ' + value.sede.nombre + ' - ' + value.area.nombre + ' - ' + value.cargo.nombre,
                                last_first_name: value.apellidos_nombres,
                                email: value.email
                            });
                        });
                    }
                    return {
                        results: arr
                    };
                },
                cache: true
            },
            placeholder: "Ingrese nombre de la persona",
            minimumInputLength: 1,
            language: "es"
        });

            <?php if(isset($userpersona)):?>
        var select = "";
        select += '<option value="{{ $userpersona->user->id }}">{{ $userpersona->user->last_first_name. " - ". $userpersona->persona->sedeAreaCargo }}</option>';
        $("#persona").html(select).trigger('change.select2');
            <?php endif;?>

        var $eventSelect = $(".select-user");
        $eventSelect.on("select2:select", function (evt) {
            var args = JSON.stringify(evt.params, function (key, value) {
                if (value && value.nodeName) return "[DOM node]";
                if (value instanceof $.Event) return "[$.Event]";
                $("#persona_id").val(value.data.id);
                $("#last_first_name").val((value.data.last_first_name).trim());
                $("#email").val(value.data.email);
            });
        });
    });
</script>