<%- include('../partials/header'); %>
    <div class="container" align="center">
        <div class="jumbotron" >
            <h1>Edit Part</h1>    
                <div class="card-body">
                    <%  if (foundPart) { %>
                        <% var partID = foundPart._id; %>
                        <% var partName = foundPart.nameID; %>
                        <% var partQuant = foundPart.data.slice(-1)[0].quantity %>
                        <% var partWeight = foundPart.weight; %>
                        <% var partZO = foundPart.zero_offset; %>
                        <% var partCF = foundPart.calibration_factor; %>
                        <% var formURL = "?_method=PUT"; %>
                        <% var buttonText  = 'Update'; %> 
                        <% var display  = 'block'; %> 
                    <% } else { %>
                        <% var partID = ""; %>
                        <% var partName = ""; %>
                        <% var partQuant= ""; %>
                        <% var partWeight = ""; %>
                        <% var partZO = ""; %>
                        <% var partCF = ""; %>
                        <% var formURL = ""; %>
                        <% var buttonText  = 'Create'; %>  
                        <% var display  = 'none'; %> 
                    <% } %>
                    <form id="part-form" action="../<%=partID%><%=formURL%>" class ="form"  method="POST">
                        <div class="form-group row align-items-center">
                            <label class="col-lg-4 col-form-label form-control-label">Part name</label>
                            <div class="col-lg-8">
                                <input class="form-control" type="text" name="part[nameID]" value="<%=partName%>">
                            </div>
                        </div>
                        <div class="form-group row align-items-center">
                            <label class="col-lg-4 col-form-label form-control-label">Quantity</label>
                            <div class="col-lg-8">
                                <input class="form-control" type="number" name="part[quantity]" value="<%=partQuant%>">
                            </div>
                        </div>
                        <div class="form-group row align-items-center">
                            <label class="col-lg-4 col-form-label form-control-label">Weight</label>
                            <div class="col-lg-8">
                                <input class="form-control" type="number" step="0.0001" name="part[weight]" value="<%=partWeight%>">
                            </div>
                        </div>
                        <div class="form-group row align-items-center">
                            <label class="col-lg-4 col-form-label form-control-label">Zero Offset</label>
                            <div class="col-lg-8">
                                <input class="form-control" type="number" step="0.0001" name="part[zero_offset]" value="<%=partZO%>">
                            </div>
                        </div>
                        <div class="form-group row align-items-center">
                            <label class="col-lg-4 col-form-label form-control-label">Calibration Factor</label>
                            <div class="col-lg-8">
                                <input class="form-control" type="number" step="0.0001" name="part[calibration_factor]" value="<%=partCF%>">
                            </div>
                        </div>
                    <div class="form-group row">
                        <label class="col-lg-4 col-form-label form-control-label"></label>
                        <div class="col-lg-4">
                            <button id="create-update" class="btn btn-dark mt-3"><%=buttonText%></button>                  
                        </div>
                    </form>
                        <div class="col-lg-4">
                            <form style="display: <%=display%>" action="../<%=partID%>?_method=DELETE" method="POST">
                                <button class="btn btn-dark mt-3 ml-3">Delete</button>
                            </form>                                    
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
<%- include('../partials/footer'); %>