@extends('Admin.include.app')
@section('content')

<style>
	.input-group .fas {
		color: black;
	}
</style>
<!-- Main content -->
<section class="content">
	<div class="container-fluid">
		<div class="row">
				@if(\Request::route()->getName() === $c_page.'.create')
			<form name="addForm" id="addForm" class="col-md-12" method="POST" action="{{ route($c_page.'.store') }}" enctype="multipart/form-data">
				@csrf
				@else
			<form name="addForm" id="addForm" class="col-md-12" method="POST" action="{{ route($c_page.'.update',$data->id) }}" enctype="multipart/form-data">
				@csrf
				@method("PATCH")
				@endif
				<div class="col-md-12">
					<div class="card card-success">
						<div class="card-header">
							<h3 class="card-title"><i class="fas fa-user"></i>&nbsp; {{ $pageTitle }} Info</h3>
						</div>
						<div class="card-body">
							<div class="row">
								
								<div class="form-group col-md-4">
									<label>Role Name*</label>
									<input id='name' class="form-control @error('name') is-invalid @enderror" value="{{ !empty($data->name)?$data->name:old('name') }}" autocomplete="name" autofocus name="name" style='width:100%;' required>
                                    
									@error('name')
									<span class="invalid-feedback" role="alert">
										<strong>{{ $message }}</strong>
									</span>
									@enderror
								</div>
							</div>	
						</div>
					</div>
				</div>

				<div class="form-group col-lg-12 text-center">
					<input type="submit" value="Submit" class="btn btn-success btn-sm">
				</div>
			</form>
		</div>
		<!-- /.row -->
	</div>
	<!-- /.container-fluid -->
</section>
<!-- /.content -->


@endsection
@section('script')

<script>
	$(function() {
        $(document).ready(function() {
            $.validator.methods.isJSON = function(value, element) {
                if (typeof(value) !== 'string') {
                    return false;
                }
                try {
                    JSON.parse(value);
                    return true;
                } catch (e) {
                    return false;
                }
            }
			
            $("#addForm").validate({
                rules: {
                    name: {
                        required: true
                    },
                    
                    
                },
                messages: {
                    name_default: {
                        required: "Please select"
                    },
                },
                errorElement: "em",
                errorPlacement: function(error, element) {
                    // Add the `help-block` class to the error element
                    error.addClass("help-block");

                    if (element.prop("type") === "checkbox") {
                        error.insertAfter(element.parent("label"));
                    } else {
                        error.insertAfter(element);
                    }
                },
                highlight: function(element, errorClass, validClass) {
                    $(element).parents(".col-sm-5").addClass("has-error").removeClass("has-success");
                },
                unhighlight: function(element, errorClass, validClass) {
                    $(element).parents(".col-sm-5").addClass("has-success").removeClass("has-error");
                }
            });
        });
    });
</script>
@endsection