<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html-el" %>
<%@ taglib uri="/tags/struts-bean-el" prefix="bean-el" %>
<%@ taglib uri="/tags/displaytag" prefix="display" %>
<%@ taglib uri="/tags/esr-core" prefix="esrcore" %>								 							 
<%@ taglib uri="/tags/valuelist" prefix="vlh" %>
<%@ taglib uri="/tags/fw" prefix="fw" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="/tags/authz" prefix="auth" %>
<%@ page import='gov.va.med.esr.common.model.lookup.Capability' %>
<%@ page import="gov.va.med.esr.common.model.comms.CommsLogEntry"%>
<%@ page import="gov.va.med.esr.common.model.lookup.ComMailingStatusType" %>

<c:set var="updateAddress" value="false"/>
<auth:authorize ifAnyGranted="<%=Capability.EDIT_ADDRESS.getName()%>">
  <c:set var="updateAddress" value="true"/>
</auth:authorize>

<table width="100%" border="0" cellpadding="0" cellspacing="0" class="moduleShell" role="presentation">
<html-el:form action="/commslogDetail" method="post">
  <%@ include file="/admin/csrfgentoken.jsp" %>
<html-el:hidden property="selectedCommsLogId" />
  <tr>
    <td>
      <table width="100%" border="0" cellpadding="0" cellspacing="0" class="moduleShellTable" role="presentation">
        <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: 7">Add Comments</td>
                <td width="100%"><img alt=""  src="../images/spacer.gif"></td>
              </tr>
            </table>
          </td>
        </tr>
        <tr>
          <td>
            <table align="center" width="100%" border="0" cellspacing="0" cellpadding="0" class="moduleShellTableBody" role="presentation">

              <c:set var="Send_to_AAC"><%= ComMailingStatusType.SEND_TO_AAC.getName() %></c:set>
              <c:set var="MAILED_BY_AAC"><%= ComMailingStatusType.MAILED_BY_AAC.getName() %></c:set>
              <c:set var="MAILED_BY_HEC"><%= ComMailingStatusType.MAILED_BY_HEC.getName() %></c:set>
              <c:set var="REJECT_BY_AAC"><%= ComMailingStatusType.REJECT_BY_AAC.getName() %></c:set>
              <c:set var="ERROR_BY_AAC"><%= ComMailingStatusType.ERROR_BY_AAC.getName() %></c:set>
              <c:set var="REJECT_AT_HEC"><%= ComMailingStatusType.REJECT_AT_HEC.getName() %></c:set>
              
              <c:set var="SEND_TO_CMS"><%= ComMailingStatusType.SEND_TO_CMS.getName() %></c:set>
              <c:set var="MAILED_BY_CMS"><%= ComMailingStatusType.MAILED_BY_CMS.getName() %></c:set>
              <c:set var="REJECT_BY_CMS"><%= ComMailingStatusType.REJECT_BY_CMS.getName() %></c:set>
              <c:set var="ERROR_BY_CMS"><%= ComMailingStatusType.ERROR_BY_CMS.getName() %></c:set>              

              <c:set var="currentStatus" value="${commsLogForm.selectedCommsLog.latestMailingStatus.mailingStatus.code }" />

              <tr><td colspan="2"><img alt="" src="../images/spacer.gif" width="1" height="10"></td></tr>
              <c:if test="${commsLogForm.selectedCommsLog.latestMailingStatus.mailingStatus.code == Send_to_AAC || commsLogForm.selectedCommsLog.latestMailingStatus.mailingStatus.code == SEND_TO_CMS}">
              <tr>                
                <td class="moduleLabel"><fw:label forId="cancelMailingId" property="cancelMailing">Cancel Mailing:</fw:label></td>
                <td class="moduleValue"><html-el:checkbox title="Cancel Mailing" property="cancelMailing" styleId="cancelMailingId"/>Cancel</td>
              </tr>
              </c:if>

              <c:if test="${currentStatus == MAILED_BY_AAC || currentStatus == MAILED_BY_HEC || currentStatus == MAILED_BY_CMS}">
              <tr>
                <td class="moduleLabel"><fw:label forId="undeliverableMailId" property="undeliverableMail">Undeliverable Mail:</fw:label></td>                
                <td class="moduleValue"><html-el:checkbox title="Returned by Post Office" property="returnedByPostOffice" styleId="undeliverableMailId"/>Returned by Post Office</td>
              </tr>
              </c:if>

              <tr>
                <td width="10%" class="moduleLabel" valign="top"><fw:label property="newComment" forId="txtNewComment">Comments:</fw:label></td>
                <td width="90%" class="moduleValue"><textarea title="Comments" wrap="hard" name="newComment" id="txtNewComment" cols="90" rows="8"/><c:out value="${commsLogForm.newComment}"/></textarea></td>
              </tr>
              <tr><td colspan="2">&nbsp;</td></tr>
              <tr>
                <td colspan="2" class="moduleValueButton">
                  <table width="100%" border="0" align="center" cellspacing="0" cellpadding="0" role="presentation">
                    <tr>
                      <td width="45%"><img alt=""  src="../images/spacer.gif"/></td>
                      <td><img alt=""  src="../images/buttonEndLeft.gif"/></td>
                      <td><html-el:submit property="methodName" style="width:50; vertical-align: top;" styleClass="buttonText"><bean-el:message key="button.update"/></html-el:submit></td>
                      <td><img alt=""  src="../images/buttonEndRight.gif"/></td>
                      <td width="1%"><img alt=""  src="../images/spacer.gif"/></td>
                      <td><img alt=""  src="../images/buttonEndLeft.gif"/></td>
                      <td><html-el:submit property="methodName" style="width:50; vertical-align: top;" styleClass="buttonText"><bean-el:message key="button.cancel"/></html-el:submit></td>
                      <td><img alt=""  src="../images/buttonEndRight.gif"/></td>
                      <td width="45%"><img alt=""  src="../images/spacer.gif"/></td>
                    </tr>
                  </table>
                </td>
              </tr>
            </table>
          </td>
        </tr>
      </table>
    </td>
  </tr>
</html-el:form>
</table>

<br>

<table width="100%" border="0" cellpadding="0" cellspacing="0" class="moduleShell" role="presentation">
<tr>
 <td>
   <table width="100%" border="0" cellpadding="0" cellspacing="0" class="moduleShellTable" role="presentation">
    <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="15"/></td>
         <td  nowrap style="padding-left: 7">
         <esrcore:displayValue name="commsLogForm" property="selectedFormNumber" nullText=""/> -
         <esrcore:displayValue name="commsLogForm" property="selectedFormName" nullText=""/></td>
         <td width="100%"><img alt=""  src="../images/spacer.gif"></td>
       <c:if test="${updateAddress == true}">
           <td nowrap class="moduleBlueLink" style="padding: 1 8 1 8">
         <fw:link forward="updateAddr"><bean-el:message key="button.updateVeteranAddress"/></fw:link>
         </td>
       </c:if>
       </tr>
      </table>
     </td>
    </tr>
    <tr>
     <td>
      <table width="100%" border="0" cellspacing="0" cellpadding="0" class="moduleShellTableBody" role="presentation">

<tr valign="top">
  <td class="moduleLabel"><div align="left">Case Number:</div></td>
  <td class="moduleValue"><div align="left"><esrcore:displayValue name="commsLogForm" property="selectedCommsLog.workflowCaseId" nullText=""/></div></td>
  <td class="moduleLabel"><div align="left">Bar Code ID:</div></td>
  <td class="moduleValue"><esrcore:displayValue name="commsLogForm" property="selectedCommsLog.barcode" nullText=""/></td>
</tr>
<tr valign="top">
  <td width="172" class="moduleLabel"><div align="left">Communication Status:</div></td>
  <td width="178" class="moduleValue"><div align="left"><esrcore:displayValue name="commsLogForm" property="selectedCommsLog.latestMailingStatus.mailingStatus.description" nullText=""/></div></td>
  <td width="171" class="moduleLabel"><div align="left">Status Date/Time:</div></td>
  <td class="moduleValue"><div align="left"><esrcore:displayDate name="commsLogForm" dateProperty="selectedCommsLog.latestMailingStatus.modifiedOn" format="MM/dd/yyyy h:mm:ssa"/></div></td>
</tr>
<tr valign="top">
  <td class="moduleLabel"><div align="left">Date Mailed:</div></td>
  <td class="moduleValue"><div align="left"><esrcore:displayDate name="commsLogForm" dateProperty="selectedCommsLog.mailingDate" format="MM/dd/yyyy"/></div></td>
  <td class="moduleLabel"><div align="left">Remail Indicator:</div></td>
  <td class="moduleValue"><div align="left"><esrcore:displayValue name="commsLogForm" property="selectedCommsLog.remailIndicator" nullText=""/></div></td>
</tr>

<c:if test="${commsLogForm.selectedCommsLog.latestMailingStatus.mailingStatus.code == REJECT_BY_AAC}">
  <tr valign="top">
    <td class="moduleLabel"><div align="left">AAC Reject Reason:</div></td>
    <td class="moduleValue"><div align="left">
    <esrcore:displayValue name="commsLogForm" property="selectedCommsLog.code1RejectReason"/>
    </div></td>
    <td class="moduleLabel"><div align="left">&nbsp;</div></td>
    <td class="moduleValue"><div align="left">&nbsp;</div></td>
  </tr>
</c:if>

<c:if test="${commsLogForm.selectedCommsLog.latestMailingStatus.mailingStatus.code == REJECT_BY_CMS}">
  <tr valign="top">
    <td class="moduleLabel"><div align="left">CMS Reject Reason:</div></td>
    <td class="moduleValue"><div align="left">
    <esrcore:displayValue name="commsLogForm" property="selectedCommsLog.code1RejectReason"/>
    </div></td>
    <td class="moduleLabel"><div align="left">&nbsp;</div></td>
    <td class="moduleValue"><div align="left">&nbsp;</div></td>
  </tr>
</c:if>

<c:if test="${commsLogForm.selectedCommsLog.latestMailingStatus.mailingStatus.code == ERROR_BY_AAC}">
  <tr valign="top">
    <td class="moduleLabel"><div align="left">AAC Error Reason(s):</div></td>
    <td class="moduleValue"><div align="left">
    <c:forEach var="item" items="${commsLogForm.selectedCommsLog.aacErrorReasonLinks}">
      <esrcore:displayValue name="item" property="aacErrorType" nullText=""/><br>
    </c:forEach>
    </div></td>
    <td class="moduleLabel"><div align="left">&nbsp;</div></td>
    <td class="moduleValue"><div align="left">&nbsp;</div></td>
  </tr>
</c:if>
<c:if test="${commsLogForm.selectedCommsLog.latestMailingStatus.mailingStatus.code == ERROR_BY_CMS}">
  <tr valign="top">
    <td class="moduleLabel"><div align="left">CMS Error Reason(s):</div></td>
    <td class="moduleValue"><div align="left">
    <c:forEach var="item" items="${commsLogForm.selectedCommsLog.aacErrorReasonLinks}">
      <esrcore:displayValue name="item" property="aacErrorType" nullText=""/><br>
    </c:forEach>
    </div></td>
    <td class="moduleLabel"><div align="left">&nbsp;</div></td>
    <td class="moduleValue"><div align="left">&nbsp;</div></td>
  </tr>
</c:if>

<tr valign="top">
  <td class="moduleLabel"><div align="left">Recipient Type:</div></td>
  <td class="moduleValue"><div align="left"><esrcore:displayValue name="commsLogForm" property="selectedCommsLog.recipient" nullText=""/></div></td>
  <td class="moduleLabel"><div align="left">Mailing Address:</div></td>
  <td class="moduleValue"><div align="left"><esrcore:displayValue name="commsLogForm" property="selectedCommsLog.address"/></div></td>  
</tr>

<c:if test="${commsLogForm.selectedCommsLog.latestMailingStatus.mailingStatus.code == REJECT_AT_HEC}">
  <tr valign="top">
    <td class="moduleLabel"><div align="left">HEC Reject Reason:</div></td>
    <td class="moduleValue"><div align="left"><fw:messages id="error"><c:out value="${error}" /><br></fw:messages></div></td>
    <td class="moduleLabel"><div align="left">&nbsp;</div></td>
    <td class="moduleValue"><div align="left">&nbsp;</div></td>
  </tr>
</c:if>

<c:set var="POA"><%= CommsLogEntry.RECIPIENT_POA %></c:set>
<c:if test="${commsLogForm.selectedCommsLog.recipient == POA}">
<tr valign="top">
  <td class="moduleLabel"><div align="left">Name:</div></td>
  <td class="moduleValue"><div align="left"><esrcore:displayValue name="commsLogForm" property="selectedCommsLog.name" nullText=""/></div></td>
  <td class="moduleLabel"><div align="left">&nbsp;</div></td>
  <td class="moduleValue"><div align="left">&nbsp;</div></td>
</tr>
</c:if>
</table>
<!-- module shell table body-->
</td>
</tr>

</table>
<!-- module shell table  -->
</td>
</tr>
</table>
<!-- module shell -->

<br>

<c:if test="${commsLogForm.selectedCommsLog.actionComment != null}">
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="moduleShell" role="presentation">
<tr>
 <td>
   <table width="100%" border="0" cellpadding="0" cellspacing="0" class="moduleShellTable" role="presentation">
    <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: 7">Comments</td>
         <td width="100%"><img alt=""  src="../images/spacer.gif"></td>
       </tr>
      </table>
     </td>
    </tr>
    <tr>
     <td>
      <table width="100%" border="0" cellspacing="0" cellpadding="0" class="moduleShellTableBody" role="presentation">
     <tr><td>&nbsp;<td></tr>

        <tr>
        <td> <esrcore:displayValue name="commsLogForm" property="fomattedActionComment" nullText=""/>
       </td>
       </TR>

     <tr><td>&nbsp;<td></tr>
     </table>
<!-- module shell table body-->
</td>
</tr>

</table>
<!-- module shell table  -->
</td>
</tr>
</table>
<!-- module shell -->

<br>
</c:if>

<table width="100%" border="0" cellpadding="0" cellspacing="0" class="moduleShell" role="presentation">
<tr>
 <td>
   <table width="100%" border="0" cellpadding="0" cellspacing="0" class="moduleShellTable" role="presentation">
    <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: 7">Status History</td>
         <td width="100%"><img alt=""  src="../images/spacer.gif"></td>
       </tr>
      </table>
     </td>
    </tr>
    <tr>
     <td>
       <table width="100%" border="0" cellspacing="0" cellpadding="0" class="moduleShellTableBody" role="presentation">
       <c:choose>
        <c:when test="${vlhlist==null ||vlhlist.valueListInfo==null ||vlhlist.valueListInfo.totalNumberOfEntries == 0}">
          <tr>
            <td class="darkValue" style="padding:10 0 10 10; text-align: left"><bean-el:message key="label.noDataAvailable"/></td>
          </tr>
        </c:when>
        <c:otherwise>
          <tr valign="top" width="100%">
            <td vAlign="top" align="center">
              <div id="mailingStatusLink" style="border-width:0px;">
                <table id="mailStatusResult" align="center" width="100%" border="0" cellpadding="0" cellspacing="0" class="moduleTable" role="presentation">
                  <vlh:root id="mailStatusTableId" value="vlhlist" url="?" includeParameters="*" configName="valueListConfigBeanLookAndFeel">
                    <tr>
                      <td colspan="5">
                        <table class="pagelinks">
                          <tr>
                            <td width="45%"><img alt=""  src="../images/spacer.gif"></td>
                            <td width="5%" nowrap="true">
				                          <span class="pagebanner"><c:out value="${vlhlist.valueListInfo.totalNumberOfEntries}"/> Total
				                          - Page (<c:out value="${vlhlist.valueListInfo.pagingPage}"/> of <c:out value="${vlhlist.valueListInfo.totalNumberOfPages}"/>).
				                          &nbsp;</span>
                            </td>
                            <td width="5%">
                              <c:choose>
                                <c:when test="${vlhlist.valueListInfo.totalNumberOfPages > 1}">
                                  <vlh:paging attributes="class=\"pagelinks\"" pages="10"><c:out value="${pagefutureEGTSettingsTableId}"/>&nbsp;</vlh:paging>
                                </c:when>
                                <c:otherwise>
                                  &nbsp;
                                </c:otherwise>
                              </c:choose>
                            </td>
                            <td width="45%"><img alt=""  src="../images/spacer.gif"></td>
                          </tr>
                        </table>
                      </td>
                    </tr>
                    <tr vAlign="top">
                      <td vAlign="top" align="center">
        <tr>
        <td>
 			<table summary="List of Status History for this Communication" rules="all" class="TableDisplay" role="presentation">
                <tr>
                  <vlh:row bean="mailingStatusLink">					  
                	<vlh:column title="Status Date/Time" property="createdOn"  sortable="asc" attributes="align=\"left\" scope='col'" default="">
                    	<vlh:attribute name="scope">row</vlh:attribute>
                      	<esrcore:displayValue name="mailingStatusLink" property="createdOn" nullText="" format="MM/dd/yyyy h:mm:ssa"/>
                    </vlh:column>
             		<vlh:column title="Status" property="mailingStatus.description" sortable="asc" attributes="align=\"left\" scope='col'" default="">
                      <esrcore:displayValue name="mailingStatusLink" property="mailingStatus.description" nullText=""/>
                    </vlh:column>
                  </vlh:row>
                </tr>
        	</table>
        	</td>
       </tr>
		</vlh:root>
       </table>
<!-- module shell table body-->
</td>
</tr>
        </c:otherwise>
      </c:choose>
</table>
<!-- module shell table  -->
</td>
</tr>
</table>
<!-- module shell -->
