<%- include('./partials/header_head.ejs') -%>
    <link rel="stylesheet" href="/register/register.css">
    <div id="top-menu">
        <a href="/"> <img id="logo" src="/images/futuretech.png" alt=""> </a>
    </div>
    <div class="container register-form" style="background-color: white;padding: 1%;">
        <div class="form">
            <div class="note">
                <p>Register for best offers in futureTech Store.</p>
            </div>

            <form class="form-content" method="POST" action="/register" onsubmit="return verification()">
                <div class="row">
                    <div class="col-md-6">
                        <div class="form-group row">
                            <div class="col-md-6">
                                <input type="text" class="form-control" placeholder="First name *" value="" name="fname" required />
                            </div>
                            <div class="col-md-6">
                                <input type="text" class="form-control" placeholder="Last name *" value="" name="lname" required />
                            </div>
                        </div><br>
                        <div class="form-group">
                            <input type="text" class="form-control" placeholder="Phone number *" name="phone" value=""
                                required />
                        </div><br>
                        <div class="form-group">
                            <input type="text" class="form-control" placeholder="Address *" value="" name="adress"
                                required />
                        </div>
                        <br>
                        <div class="form-group row">
                            <div class="col-md-5 mb-3">
                                <input type="text" class="form-control" placeholder="Country *" value="" name="country" required />
                            </div>
                            <div class="col-md-4 mb-3">
                                <input type="text" class="form-control" placeholder="City *" value="" name="city" required />
                            </div>
                            <div class="col-md-3 mb-3">
                                <input type="text" class="form-control" placeholder="Zib code *" value="" name="zip" required />
                            </div>
                        </div>
                    </div>
                    <div class="col-md-6">
                        <div class="form-group">
                            <input id="email_input" type="email" class="form-control" placeholder="email adress *" value="" name="email"
                                required />
                        </div><br>
                        <div class="form-group">
                            <input type="password" id="pass" class="form-control" placeholder="Password *"
                                name="password" value="" required />
                        </div><br>
                        <div class="form-group">
                            <input type="password" id="confirm_pass" class="form-control"
                                placeholder="Confirm Password *" name="password_confirmation" value="" required />
                        </div>
                    </div>
                </div>
                <br>
                <button type="submit" class="btnSubmit">Register</button>
                <div id="sigin">
                    already registered? <a href="/login">Sign In</a>
                </div>
            </form>
        </div>
    </div>

    <% if(locals.fail){ %>
    <div id="failed_msg" class="alert alert-danger" role="alert">
        <%= desc %>
      </div>
<%}%>
    <script>
        function verification() {
            if ($("#pass").val() != $("#confirm_pass").val()) {
                alert("password confirmation doesn't match");
                return false;
            }
         fetch("/user/email/"+$("#email_input").val())
            .then(data => { return data.json(); }).then(function (res) {
if(res.message=="success"){
    $("#failed_msg").text("email already exists");
    $("#failed_msg").show("1000");
    return false }
else{ return true; }
            });
        }
    </script>


    <%- include('./partials/footer.ejs') -%>
