@extends('front.include.app')
@section('content')
    <style>
        .error {
            color: red;
        }
    </style>
    <section class="container">
        <div class="row">
            <div class="col-md-12 col-sm-12" align="center">
                <img src="{{ asset('assets/images/logo.png') }}" class="logo" width="50%">
            </div>
            <div class="col-md-12 col-sm-12" align="center">
                <h2>Akshar Ganesh Campaign</h2>
                <p class="red paddin-20">Please Update You profile here</p>
                <form action="{{ route('employee-info-update', auth()->guard('employee')->user()['id']) }}" method="POST"
                    enctype="multipart/form-data" id="addForm">
                    @csrf
                    {{-- New password --}}
                    <input name="password" type="password" id="password"
                        class="form-control blueinput mt-4 @error('password') is-invalid @enderror"
                        value="{{ old('password') }}" placeholder="New Password" autocomplete="password" autofocus required>
                    @error('password')
                        <span class="invalid-feedback" role="alert">
                            <strong>{{ $message }}</strong>
                        </span>
                    @enderror
                    {{-- confirm password --}}
                    <input name="password_confirmation" type="password" id="password"
                        class="form-control blueinput mt-4 @error('password') is-invalid @enderror"
                        value="{{ old('password_confirmation') }}" placeholder="confirm password"
                        autocomplete="password_confirmation" autofocus>
                    @error('password')
                        <span class="invalid-feedback" role="alert">
                            <strong>{{ $message }}</strong>
                        </span>
                    @enderror
                    {{-- WhatsApp Number --}}
                    <input name="whatsapp_number" type="text" id="whatsapp_number"
                        class="form-control blueinput mt-4 @error('whatsapp_number') is-invalid @enderror"
                        value="{{ !empty($data->whatsapp_number) ? $data->whatsapp_number : old('email') }}"
                        placeholder="WhatsApp Number" autocomplete="whatsapp_number	" autofocus
                        oninput="this.value = this.value.replace(/[^0-9.]/g, ''); this.value = this.value.replace(/(\..*)\./g, '$1');">
                    @error('whatsapp_number')
                        <span class="invalid-feedback" role="alert">
                            <strong>{{ $message }}</strong>
                        </span>
                    @enderror
                    {{-- Email --}}
                    <input name="email" type="email" id="email"
                        class="form-control blueinput mt-4 @error('email') is-invalid @enderror"
                        value="{{ !empty($data->email) ? $data->email : old('email') }}" required placeholder="Email ID"
                        autocomplete="email" autofocus>
                    @error('email')
                        <span class="invalid-feedback" role="alert">
                            <strong>{{ $message }}</strong>
                        </span>
                    @enderror
                    <input type="submit" class="form-control redbutton mt-4" value="Next">
                </form>

            </div>


        </div>

    </section>
@endsection
@section('script')
    <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"
        integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous">
    </script>
    <!-- JQuery -->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.19.2/jquery.validate.min.js"></script>
    <script>
        $(function() {
            $(document).ready(function() {
                // alert();
                $.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: {
                        password: {
                            required: true,
                            minlength: 6,
                        },
                        password_confirmation: {
                            required: true,
                            equalTo: "#password"
                        },
                        whatsapp_number: {
                            required: true,
                            minlength: 10,
                            maxlength: 10,
                            matches: "([0-9]{10})|(\([0-9]{3}\)\s+[0-9]{3}\-[0-9]{4})",


                        },
                        email: {
                            required: true,
                            email: true,
                        },

                    },
                    messages: {
                        password: {
                            required: "Please enter password"
                        },
                        email: {
                            required: "Please enter Email",
                            email: "Enter Valid email",
                        },
                    },
                    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
