<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Detail</title>
    </head>
    <body>
        <%@include file="header.jsp" %>
        
        <form name="detail" method="POST">
            <c:choose>
                <c:when test="${type == 'customer'}">
                    <p>
                        <label for="numero">Numero</label>
                        <input type="text" name="numero" value="${result.customerId}" size="30" id="numero" />
                    </p>
                    <p>
                        <label for="nom">Nom</label>
                        <input type="text" name="nom" value="${result.name}" size="30" id="nom" />
                    </p>
                    <p>
                        <label for="adresse">Adresse</label>
                        <input type="text" name="adresse" value="${result.addressline1}" size="30" id="adresse" />
                    </p>
                    <p>
                        <label for="telephone">Téléphone</label>
                        <input type="text" name="telephone" value="${result.phone}" size="30" id="tel" />
                    </p>
                    <p>
                        <label for="email">E-mail</label>
                        <input type="text" name="email" value="${result.email}" size="30" id="email"/>
                    </p>
                    <p>
                        <label for="discountCode">Remise</label>
                        <select name="discountCode" id="discountCode">
                            <c:forEach items="${code}" var="dc">
                                <option <c:if test="${dc.discountCode==result.discountCode}"> selected </c:if> value="${dc.discountCode}}">${dc.discountCode} - ${dc.rate}%</option>
                            </c:forEach>
                        </select>
                    </p>
                    <p>
                        <label for="cp">Code Postal</label>
                        <select name="CP" id="cp">
                            <c:forEach items="${cpostaux}" var="cp">
                                <option <c:if test="${cp==result.zip}"> selected </c:if>>${cp}</option>
                            </c:forEach>
                        </select>
                    </p>
                </c:when>
                <c:when test="${type == 'product'}">
                    <p>
                        <label for="productId">ID</label>
                        <input type="number" name="productId" value="${result.productId}" size="30" id="productId" />
                    </p>
                    <p>
                        <label for="manufacturerId">Manufacturer</label>
                        <select name="manufacturerId" id="manufacturerId">
                            <c:forEach items="${manufacturers}" var="manufacturer">
                                <option <c:if test="${manufacturer.manufacturerId == result.manufacturerId}">selected </c:if>value="${manufacturer.manufacturerId}">${manufacturer.name}</option>
                            </c:forEach>
                        </select>
                    </p>
                    <p>
                        <label for="productCode">Product Code</label>
                        <select name="productCode" id="productCode">
                            <c:forEach items="${productCodes}" var="productCode">
                                <option <c:if test="${productCode.prodCode == result.productCode}">selected </c:if>value="${productCode.prodCode}">${productCode.prodCode} - ${productCode.description}</option>
                            </c:forEach>
                        </select>
                    </p>
                    <p>
                        <label for="purchaseCost">Purchase cost</label>
                        <input type="number" step="0.000000000001" name="purchaseCost" value="${result.purchaseCost}" id="purchaseCost" />
                    </p>
                    <p>
                        <label for="quantityOnHand">Quantity on hand</label>
                        <input type="number" name="quantityOnHand" value="${result.quantityOnHand}" id="quantityOnHand" />
                    </p>
                    <p>
                        <label for="markup">Markup</label>
                        <input type="number" step="0.0001" name="markup" value="${result.markup}" id="markup" />
                    </p>
                    <p>
                        <label for="markup">Available</label>
                        <input type="checkbox" name="available" <c:if test="${result.available == 'TRUE'}">checked</c:if> id="available" />
                    </p>
                    <p>
                        <label for="description">Description</label>
                        <input type="text" name="description" value="${result.description}" id="description" size="50" />
                    </p>
                </c:when>
                <c:when test="${type == 'purchase'}">
                    <p>
                        <label for="orderNum">Order number</label>
                        <input type="number" name="orderNum" value="${result.orderNum}" id="orderNum" />
                    </p>
                    <p>
                        <label for="customerId">Customer</label>
                        <select name="customerId" id="customerId">
                            <c:forEach items="${customers}" var="customer">
                                <option <c:if test="${customer.customerId == result.customerId}">selected </c:if>value="${customer.customerId}">${customer.name}</option>
                            </c:forEach>
                        </select>
                    </p>
                    <p>
                        <label for="productId">Product</label>
                        <select name="productId" id="productId">
                            <c:forEach items="${products}" var="product">
                                <option <c:if test="${product.productId == result.productId}">selected </c:if>value="${product.productId}">${product.description}</option>
                            </c:forEach>
                        </select>
                    </p>
                    <p>
                        <label for="quantity">Quantity</label>
                        <input type="number" name="quantity" value="${result.quantity}" id="quantity" />
                    </p>
                    <p>
                        <label for="shippingCost">Shipping cost</label>
                        <input type="number" name="shippingCost" value="${result.shippingCost}" id="shippingCost" />
                    </p>
                    <p>
                        <label for="salesDate">Sales date</label>
                        <input type="date" name="salesDate" value="${result.salesDate}" id="salesDate" />
                    </p>
                    <p>
                        <label for="shippingDate">Shipping date</label>
                        <input type="date" name="shippingDate" value="${result.shippingDate}" id="shippingDate" />
                    </p>
                    <p>
                        <label for="freightCompany">Freight company</label>
                        <input type="text" name="freightCompany" value="${result.freightCompany}" id="freightCompany" />
                    </p>
                </c:when>
                <c:when test="${type == 'discount'}">
                    <p>
                        <label for="discountCode">Discount code</label>
                        <input type="text" name="discountCode" value="${result.discountCode}" id="discountCode" size="1" />
                    </p>
                    <p>
                        <label for="rate">Rate</label>
                        <input type="number" name="rate" value="${result.rate}" id="rate" />
                    </p>
                </c:when>
                <c:when test="${type == 'prodCode'}">
                    <p>
                        <label for="prodCode">Product Code</label>
                        <input type="text" name="prodCode" value="${result.prodCode}" id="prodCode" size="2" />
                    </p>
                    <p>
                        <label for="discountCode">Remise</label>
                        <select name="discountCode" id="discountCode">
                            <c:forEach items="${code}" var="dc">
                                <option <c:if test="${dc.discountCode==result.discountCode}"> selected </c:if> value="${dc.discountCode}}">${dc.discountCode} - ${dc.rate}%</option>
                            </c:forEach>
                        </select>
                    </p>
                    <p>
                        <label for="description">Description</label>
                        <input type="text" name="description" value="${result.description}" id="description" size="10" />
                    </p>
                </c:when>
            </c:choose>
           
            <input hidden type="text" name="type"  value="${type}" />
            <input type="submit" value="Modifier" formaction="update.htm" />
            <input type="submit" value="Supprimer" formaction="delete.htm" />
            <c:if test="${type == 'customer'}">
                <input type="submit" value="Afficher les achats" formaction="achats.htm" />
            </c:if>
            
        </form>
    </body>
</html>