<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<% request.setAttribute("title", "Bootcamp List "); %>
<%@ include file="head.jsp" %>

<c:if test="${empty requestScope[Attributes.BOOTCAMPS]}">
    <p>There are no bootcamps registered.</p>
</c:if>
<c:if test="${not empty requestScope[Attributes.BOOTCAMPS]}">
    <h2>Bootcamp List (${requestScope[Attributes.COUNT]})</h2>

    <c:if test="${empty requestScope[Attributes.BOOTCAMP].id}">
        <form:form method="post" modelAttribute="${Attributes.BOOTCAMP}" action="${pageContext.request.contextPath}${Routes.BOOTCAMPS}${Routes.ADD}">
            <form:input path="id" placeholder="id"/>
            <form:input path="location" placeholder="location"/>
            <form:input path="start" placeholder="start" />
            <form:input path="end" placeholder="end"/>
            <br>
            <input type="submit" value="Add"/>
        </form:form>
    </c:if>

    <c:if test="${not empty requestScope[Attributes.BOOTCAMP].id}">
        <form:form method="post" modelAttribute="${Attributes.BOOTCAMP}" action="${pageContext.request.contextPath}${Routes.BOOTCAMPS}${Routes.EDIT}">
            <form:input path="id" value="${requestScope[Attributes.BOOTCAMP].id}"/>
            <form:input path="location" value="${requestScope[Attributes.BOOTCAMP].location}"/>
            <form:input path="start" value="${requestScope[Attributes.BOOTCAMP].startString}"/>
            <form:input path="end" value="${requestScope[Attributes.BOOTCAMP].endString}"/>
            <br>
            <input type="submit" value="Edit"/>
        </form:form>
    </c:if>
    <table>
        <thead>
        <td>Id</td>
        <td>Location</td>
        <td>Start</td>
        <td>End</td>
        <td></td>
        <td></td>
        </thead>
        <c:forEach var="bootcamp" items="${requestScope[Attributes.BOOTCAMPS]}">
            <tr>
                <td>${bootcamp.id}</td>
                <td>${bootcamp.location}</td>
                <td>${bootcamp.start}</td>
                <td>${bootcamp.end}</td>
                <td><a href="<c:url value="${Routes.BOOTCAMPS}${Routes.EDIT}/${bootcamp.id}"/>">Edit</a></td>
                <td><a href="<c:url value="${Routes.BOOTCAMPS}${Routes.DELETE}/${bootcamp.id}"/>">Delete</a></td>
            </tr>
        </c:forEach>
    </table>
</c:if>
<%@ include file="foot.jsp" %>

