@extends('layouts.app')
@section('content')
<div class="main-header">
    <div class="admin-header">
        <div class="uk-grid">
            <div class="uk-width-1-2">
                <h1 class="uk-margin-small-top main-heading">{{$title}}</h1>
            </div>
            <div class="uk-width-1-2 uk-text-right">
                <a class="uk-button uk-button-default" href="{{url('admin/admins')}}"> Back</a>
            </div>
        </div>
    </div>
</div>
<div class="uk-margin uk-width-1-1 uk-margin-auto uk-card uk-card-default uk-card-body small-padding">
	@include('partials.messages')
	{{ Form::open(array('route' => ['admin.admins.update',$data->id],'method' => 'PUT', 'class' => 'uk-form-stacked','id' => 'edit_form')) }}
    @csrf
	<div uk-grid>
    	<div class="uk-width-2-3@m">  
            <div class="uk-margin-small">
                <label for="name" class="uk-form-label">Name <span class="uk-text-danger">*</span></label>
                <div class="uk-form-controls">
                    {{Form::text('name',$data->name,['class' => 'uk-input','autocomplete' => 'off'])}}
                </div>    
            </div>
            <div class="uk-margin-small">
                <label for="phone_number" class="uk-form-label">Phone Number</label>
                <div class="uk-form-controls">
                    {{Form::text('phone_number', $data->phone_number,['class' => 'uk-input','autocomplete' => 'off'])}}
                </div>    
            </div>
            <div class="uk-margin-small">
                <label for="email" class="uk-form-label">Email <span class="uk-text-danger">*</span></label>
                <div class="uk-form-controls">
                    {{Form::email('email',$data->email,['class' => 'uk-input','autocomplete' => 'off'])}}
                </div>    
            </div>
            <div class="uk-margin-small">
               <label for="password" class="uk-form-label">Password</label>
               <div class="uk-form-controls">
                    {{Form::password('password',['class' => 'uk-input password','autocomplete' => 'off','id' => 'password'])}}
                </div>    
            </div>
            <div class="uk-margin-small">
                <div class="uk-form-controls">
                {{ Form::submit('Update', array('class' => 'uk-button uk-button-primary','name' => 'save', 'id' => 'edit_submit')) }}
                <a class="uk-button uk-button-default" href="{{ url('admin/admins') }}">Cancel</a>
                </div>
            </div> 
        </div>
        {{ Form::close() }}
    </div>
</div>                   
@endsection
@section('footer-script')
<script>
    $("#edit_form").validate({
        errorClass: "uk-text-danger",
        rules:{
            name:"required",
            email: {
				required: true,
				email:true,
				remote:{
                    url: '{{url("check-email")}}',
                    type: "post",
                    data:{'userId': {{$data->id}}}
                }
              },
			password: {
				minlength: 6,
			}
        },
        messages: {
            name: {
                required: "Complete this required field."
            },
            email: {
                required: "Complete this required field.",
                remote:"This email is already exist."
            }
        },
        submitHandler: function(form) {
            $('#edit_submit').attr('disabled',true);
            form.submit();
        }
    });
    
</script>
@endsection