<%@ taglib uri="/tags/struts-bean-el" prefix="bean-el" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html-el" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="/tags/fw" prefix="fw" %>

<c:set var="dataChanged" scope="page"><bean-el:message key="label.dataChanged"/></c:set>

<table width="100%" border="0" cellpadding="0" cellspacing="0" class="moduleShell" role="presentation">
  <html-el:form action="/${historyForm.actionName}" method="post">
    <%@ include file="/admin/csrfgentoken.jsp" %>
  <tr>
    <td>
      <table width="100%" border="0" cellpadding="0" cellspacing="0" class="moduleShellTable" role="presentation">

        <%-- Main screen header --%>
        <tr>
          <td>
            <table width="100%" border="0" cellpadding="0" cellspacing="0" class="moduleShellTableHead" role="presentation">
              <tr>
                <td class="moduleBlueBox"><img alt=""  src="../images/spacer.gif" width="25" height="17"/></td>
                <td nowrap style="padding-left: 7px"> <c:out value="${historyForm.title}"/></td>
                <td width="100%"><img alt=""  src="../images/spacer.gif"></td>
                <td nowrap class="moduleBlueLink" style="padding: 1px 8px 1px 8px"><html-el:link action="${historyForm.actionName}?methodName=RETURN"><bean-el:message key="${historyForm.returnLinkMessageKey}"/></html-el:link></td>
              </tr>
            </table>
          </td>
        </tr>

        <%-- List of Change Times --%>
        <tr>
          <td>
            <table width="100%" border="0" cellspacing="0" cellpadding="0" class="moduleShellTableBody" role="presentation">
              <tr style="padding:20px 0 20px 0">
                <c:choose>
                <c:when test="${History_Change_Event_Keys == null}">
                <td style="text-align:left; padding: 10px 0 10px 10px" nowrap class="moduleLabel"><bean-el:message key="label.noHistoryDataAvailable"/></td>
                </c:when>
                <c:otherwise>
                <c:set var="changeTimesLabel" scope="page"><bean-el:message key="label.changeTimes"/></c:set>                
                <td style="padding:0 5px 0 10px" nowrap class="moduleLabel"><fw:label property="changeEventKey" forId="changeEventId"><bean-el:message key="label.changeTimes"/>:</fw:label></td>
                <td class="moduleValue">
                  <html-el:select title="${changeTimesLabel}" styleClass="moduleEdit" styleId="changeEventId" property="changeEventKey">
                  <html-el:option value=""><bean-el:message key="label.select" /></html-el:option>
                  <html-el:options name="History_Change_Event_Keys"/>
                  </html-el:select>
                </td>
                <td style="padding:0 0 0 15px"><img alt=""  src="../images/buttonEndLeft.gif"/></td>
                <td><html-el:submit property="methodName" style="width:70; vertical-align: top;" styleClass="buttonText"><bean-el:message key="button.viewData"/></html-el:submit></td>
                <td><img alt=""  src="../images/buttonEndRight.gif"/></td>
                <td width="100%"><img alt=""  src="../images/spacer.gif"></td>
                </c:otherwise>
                </c:choose>
              </tr>
            </table>
          </td>
        </tr>

        <c:if test="${History_Change_Event_Keys != null}">
        <%-- History Change Details --%>
        <tr>
          <td>
            <table width="100%" border="0" cellpadding="0" cellspacing="0" class="moduleShellLowTableHead" style="padding-top: 4px; padding-bottom: 4px;">
              <tr>
                <td class="moduleBrownBox"><img alt=""  src="../images/spacer.gif" width="25" height="17"/></td>
                <td nowrap style="padding-left: 7px"><bean-el:message key="title.historyChangeDetails"/></td>
                <td align="left" nowrap>&nbsp;(<c:out value="${historyForm.changeEventKey}"/>)
                  <input name="finAssessHiddenId" id="finAssessHiddenId" type="hidden" value="false"/>
                </td>
                <td width="100%"><img alt=""  src="../images/spacer.gif"></td>
              </tr>
            </table>
          </td>
        </tr>

        <tr>
          <td>
            <table summary="List of Historical Changes" width="100%" border="0" cellspacing="0" cellpadding="0" class="moduleShellTableBody">
              <tr>
                <td>
                  <%-- Historical Change Details Content --%>
                  <table summary="List of Historical Changes" width="100%"  cellspacing="0" cellpadding="0">

                    <thead>
                    <%-- Column Headings --%>
                    <!-- <tr><td colspan="3"><img alt=""  src="../images/spacer.gif" width="1" height="15"/></td></tr>-->
                    <tr>
                      <th scope="col" width="25%" id = "category" class="moduleLabel" style="text-align:left; padding-left: 10px" valign="bottom"><bean-el:message key="label.category"/></th>
                      <th scope="col" width="35%" id = "oldvalue" class="moduleLabel" style="text-align:left; padding-left: 10px" valign="bottom"><bean-el:message key="label.oldValue"/></th>
                      <th scope="col" width="35%" id = "newvalue" class="moduleLabel" style="text-align:left; padding-left: 10px" valign="bottom"><bean-el:message key="label.newValue"/></th>
                      <th scope="col" width="5%" id = "datachanged" class="moduleLabel" style="text-align:left; padding-left: 10px" valign="bottom"><bean-el:message key="label.dataChanged"/></th>
                    </tr>
                   </thead>

                    <c:if test="${historyForm.historicalInfo != null}">
                      <c:set var="rowLabelColor" value="darkLabel" />
                      <c:set var="rowValueColor" value="darkValue" />

                      <%-- Initialize disable color change to false --%>
                      <c:set var="disableColorChange" value="false" />

                      <%-- Iterate through every field in the history information --%>
                      <c:forEach var="fieldHistory" items="${historyForm.historicalInfo}" varStatus="loop">

                      <c:choose>
                      <c:when test="${fieldHistory.formattingChange == 'true'}">

                        <%-- Disable color change flag --%>
                        <c:if test="${fieldHistory.disableColorChange != null}">
                          <c:choose>
                          <c:when test="${fieldHistory.disableColorChange == 'true'}">
                            <c:set var="disableColorChange" value="true" />
                          </c:when>
                          <c:otherwise>
                            <c:set var="disableColorChange" value="false" />
                          </c:otherwise>
                          </c:choose>
                        </c:if>

                        <%-- Force a color change --%>
                        <c:if test="${fieldHistory.forceColorChange == 'true'}">
                          <c:choose>
                          <c:when test="${rowLabelColor == 'darkLabel'}">
                            <c:set var="rowLabelColor" value="label" />
                            <c:set var="rowValueColor" value="value" />
                          </c:when>
                          <c:otherwise>
                            <c:set var="rowLabelColor" value="darkLabel" />
                            <c:set var="rowValueColor" value="darkValue" />
                          </c:otherwise>
                          </c:choose>
                        </c:if>

                        <%-- Section header --%>
                        <c:if test="${fieldHistory.title != null}">
                        <c:set var="thId" value="subtitle${loop.index}" />
                          <tr>
                            <th scope = "col" id = "${thId}" colspan="4" nowrap style="padding-left: 10px" class="moduleShellLowTableHead" >
                              <c:choose>
                              <c:when test="${fieldHistory.subTitle == 'true'}">
                              <bean-el:message key="${fieldHistory.title}"/><!--
                              <table width="100%" border="0" cellpadding="0" cellspacing="0" class="moduleShellLowTableHead">
                                <tr>
                                  <td nowrap style="padding-left: 10px"><bean-el:message key="${fieldHistory.title}"/></td>
                                  <td width="100%"><img alt=""  src="../images/spacer.gif"></td>
                                </tr>
                              </table>
                              --></c:when>
                              <c:otherwise>
                              <!-- defaults to regular title -->
                              <bean-el:message key="${fieldHistory.title}"/>
                              <!--<table width="100%" border="0" cellpadding="0" cellspacing="0" class="moduleShellLowTableHead">
                                <tr>
                                  <td scope="row" nowrap style="padding-left: 10px"><bean-el:message key="${fieldHistory.title}"/></td>
                                  <td width="100%"><img alt=""  src="../images/spacer.gif"></td>
                                </tr>
                              </table>
                              --></c:otherwise>
                              </c:choose>
                            </th>
                          </tr>

                          <%-- After section header, reset the color to light --%>
                          <c:set var="rowLabelColor" value="label" />
                          <c:set var="rowValueColor" value="value" />
                        </c:if>

                      </c:when>
                      <c:otherwise>

                        <%-- Perform a color change if it's not disabled --%>
                        <c:if test="${disableColorChange == 'false'}">
                          <c:choose>
                          <c:when test="${rowLabelColor == 'darkLabel'}">
                            <c:set var="rowLabelColor" value="label" />
                            <c:set var="rowValueColor" value="value" />
                          </c:when>
                          <c:otherwise>
                            <c:set var="rowLabelColor" value="darkLabel" />
                            <c:set var="rowValueColor" value="darkValue" />
                          </c:otherwise>
                          </c:choose>
                        </c:if>

                        <tr>
                         
                        <c:choose>
                        <c:when test="${fieldHistory.previousValue != fieldHistory.currentValue}">
                         <td scope="row" headers = "${thId} category" class="<c:out value="${rowLabelColor}"/>" style="text-align: left; padding-left: 10px" valign="top" nowrap>
                            <c:if test="${ ! empty fieldHistory.labelKey}">
                              <bean-el:message key="${fieldHistory.labelKey}"/>:
                            </c:if>
                          </td>
                          <td headers = "${thId} oldvalue" class="<c:out value="${rowValueColor}"/>" style="color:red; text-align: left; padding-left: 10px" valign="top"><c:out escapeXml="false" value="${fieldHistory.previousValue}"/></td>
                          <td headers = "${thId} newvalue" class="<c:out value="${rowValueColor}"/>" style="color:red; text-align: left; padding-left: 10px" valign="top"><c:out escapeXml="false" value="${fieldHistory.currentValue}"/></td>
                          <td headers = "${thId} datachanged" class="<c:out value="${rowValueColor}"/>" style="text-align: left; padding-left: 10px" valign="top"><html-el:img alt="${dataChanged}" align="center" border="0" styleId="rdImage" src="../images/data_changed.gif"/></td>
                        </c:when>
                        <c:otherwise>
                         <td scope="row" headers = "${thId} category" class="<c:out value="${rowLabelColor}"/>" style="text-align: left; padding-left: 10px" valign="top" nowrap>
                            <c:if test="${ ! empty fieldHistory.labelKey}">
                              <bean-el:message key="${fieldHistory.labelKey}"/>:
                            </c:if>
                          </td>
                          <td headers = "${thId} oldvalue" class="<c:out value="${rowValueColor}"/>" style="text-align: left; padding-left: 10px" valign="top"><c:out escapeXml="false" value="${fieldHistory.previousValue}"/></td>
                          <td headers = "${thId} newvalue" class="<c:out value="${rowValueColor}"/>" style="text-align: left; padding-left: 10px" valign="top"><c:out escapeXml="false" value="${fieldHistory.currentValue}"/></td>
                          <td headers = "${thId} datachanged" class="<c:out value="${rowValueColor}"/>" >&nbsp;</td>
                        </c:otherwise>
                        </c:choose>
                        </tr>

                      </c:otherwise>
                      </c:choose>

                      </c:forEach>
                    </c:if>
                  </table>
                </td>
              </tr>
            </table>
          </td>
        </tr>
        </c:if>
      </table>
    </td>
  </tr>
  </html-el:form>
</table>
