<% layout('layouts/customer-boilerplate')  -%>


    <div class="row ">
        <div class="col-md-6 offset-md-3 col-xl-4 offset-xl-4">
            <div class="card shadow">
                <!-- <img src="https://images.unsplash.com/photo-1488459716781-31db52582fe9?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=800&q=80" alt="" class="card-img-top" /> -->

                <div class="card-body">
                    <h5 class="card-title">Add product: </h5>
                    <form action="/admin/products/<%= product._id %>/edit?_method=PUT" method="POST">

                        <div class="mb-3">
                            <label class="form-label" for="name">Product name: </label>
                            <input class="form-control" type="text" id="name" name="name" value="<%= product.name %>" required autofocus>
                        </div>

                        <div class="mb-3">
                            <label for="category" class="form-label mt-4">Select category: </label>
                            <select class="form-select" id="category" name="category" required>
                                <option selected><%= product.category %></option>
                                <option>fruits</option>
                                <option>vegetables</option>
                                <option>meat</option>
                                <option>spices</option>          
                            </select>
                        </div>

                        <div class="mb-3">
                            <label class="form-label" for="price">Price: </label>
                            <div class="input-group">
                                <div class="input-group-text">zl</div>
                                <input type="number" class="form-control" id="price" name="price" value="<%= product.price %>" required>
                            </div>
                        </div>

                        <div class="mb-3">
                            <div class="form-check form-switch">
                                <input class="form-check-input" type="checkbox" name="tags" value="Available" id="tags" <% if(product.tags.includes( 'Available')) { %> checked
                                <% } %> >
                                    <label class="form-check-label" for="tags">Available</label>
                            </div>
                            <div class="form-check form-switch">
                                <input class="form-check-input" type="checkbox" name="tags" value="OnSale" id="tags" <% if(product.tags.includes( 'OnSale')) { %> checked
                                <% } %>>
                                    <label class="form-check-label" for="tags">OnSale</label>
                            </div>
                            <div class="form-check form-switch">
                                <input class="form-check-input" type="checkbox" name="tags" value="Out-of-Stock" id="tags" <% if(product.tags.includes( 'Out-of-Stock')) { %> checked
                                <% } %>>
                                    <label class="form-check-label" for="tags">Out-of-Stock</label>
                            </div>
                        </div>


                        <div class="mb-3">
                            <label class="form-label" for="quantity">Quantity: </label>
                            <input class="form-control" type="number" id="quantity" name="quantity" value="<%= product.quantity %>" required>

                            <label for="quantity_type" class="form-label mt-4">Quantity type: </label>
                            <select class="form-select" id="quantity_type" name="quantity_type" required>
                               <% if (product.quantity_type == 'kg') { %>
                                <option selected>kg</option>
                                <option>piece</option>  
                               <% } else { %>
                                <option>kg</option>
                                <option selected>piece</option>  
                                <% } %> 
                                                   
                            </select>
                        </div>
                        <div class="mb-3">
                            <label for="description" class="form-label mt-4">Product description: </label>
                            <textarea class="form-control" id="description" name="description" rows="2" required><%= product.description %></textarea>
                        </div>

                        <div>
                            <button class="btn btn-primary btn-block ">Save</button>
                            <a href="/admin/products/<%= product._id %>/edit/photos" class="btn btn-info btn-block">Manage photos</a>
                            <a href="/products/<%= product._id %>" class="btn btn-secondary btn-block">Back</a>
                        </div>

                    </form>
                </div>
            </div>
        </div>
    </div>