@extends('layouts.admin') @section('content')
<div class="row mb-3">
    <div class="col-10">
        <div class="card mb-3">
            <div class="card-header">
                <div class="row flex-between-end">
                    <div class="col-auto align-self-center">
                        <h5 class="mb-0" data-anchor="data-anchor">Add new user</h5>
                    </div>
                </div>
            </div>
            <div class="card-body bg-light">
                <form class="form-material" method="POST" action="{{ url ('/user')}}">
                    @csrf
                  
                    @if(count($errors->all()))
                    @foreach ($errors->all() as $error)
                    <div class="alert alert-danger alert-dismissable"> <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a> <strong>Alert!</strong> {{ $error }} </div> @endforeach @endif
                    <div class="row">
                        <div class="col-sm-6">
                            <input type="text" required class="form-control" id="name" name="name" value="" placeholder="Name">
                        </div>
                        <div class="col-sm-6">
                            <input type="text" required class="form-control" id="surname" name="surname" value="" placeholder="Surname">
                            <br>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-sm-4">  
                        <select name="role" class="form-control"> 
                                <option disabled selected> -- Select role -- </option> 
                                @foreach ($roles as $role)
                                <option value="{{$role->id}}">{{$role->name}}</option> 
                                @endforeach
                        </select>                           
                        </div>
                        <div class="col-sm-4">
                            <input type="number" required class="form-control" id="national_id" name="national_id" value="" placeholder="National ID">
                        </div>
                        <div class="col-sm-4">
                            <input type="date" onmouseover="myFunctions()" required class="form-control" id="dob" name="dob" value=""><br>
                        </div>

                        <script>
                                
                                function myFunctions() {
                                    var options = {
                                        weekday: 'long',
                                        year: 'numeric',
                                        month: 'long',
                                        day: 'numeric'
                                    };                                    
                                    var date = document.getElementById("national_id").value;
                                    var year = +date.substring(0, 2);
                                    var month = +date.substring(2, 4);
                                    var day = +date.substring(4, 6);

                                    //var yyyy = (+year == 00) ? '20' + year : '19' + year;                                    
                                    document.getElementById("dob").value = ( "19" +year + "-" + month + "-" + day);
                               }
                            </script>
                    </div>
                    <div class="row">
                        <div class="col-sm-6">
                        <select name="gender" class="form-control"> 
                                <option disabled selected> -- select Gender--</option> 
                                <option>Female</option>
                                <option>Male</option>
                        </select>
                        </div>
                        <div class="col-sm-6">
                            <input type="email" required class="form-control" id="email" name="email" value="" placeholder="Email">
                            <br>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-sm-6">
                        <input type="text" required class="form-control" id="cell" name="cell" value="" placeholder="Cell Number">
                            
                        </div>
                        <div class="col-sm-6">
                            <input type="text" required class="form-control" id="position" name="position" value="" placeholder="Position">
                            <br>
                        </div>
                    </div>
                    
                    <div class="text-center">
                        <br><button type="submit" class="btn btn-primary btn-sm"><i class="far fa-save"></i>Save</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
@endsection