<%@ page buffer="8kb" autoFlush="true" %>
<%@ page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8" %>
<%@ taglib prefix="zm" uri="com.zimbra.zm" %>
<%@ taglib prefix="app" uri="com.zimbra.htmlclient" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

<fmt:setBundle basename="/msgs/ZhMsg" scope="session"/>
<app:handleError>
    <c:choose>
        <c:when test="${zm:actionSet(param, 'actionNew')}">
            <c:set var="contactId" value=""/>
            <fmt:message var="title" key="newContact"/>
        </c:when>
        <c:when test="${zm:actionSet(param, 'actionNewGroup')}">
            <c:set var="contactId" value=""/>
            <fmt:message var="title" key="newGroup"/>
            <!--- yeah -->
        </c:when>
        <c:when test="${zm:actionSet(param, 'actionEdit') and not empty param.actionEditId}">
            <c:set var="contactId" value="${not empty param.id ? param.id : param.actionEditId}"/>
        </c:when>
        <c:otherwise>
            <c:set var="contactId" value="${param.id}"/>            
        </c:otherwise>
    </c:choose>
    
    <zm:computeSearchContext var="context" types="contact" usecache="true"/>
    <c:set var="isCreate" value="${empty contactId}"/>

    <c:choose>
        <c:when test="${isCreate}">
            <c:set var="contact" value="${null}"/>
        </c:when>
        <c:otherwise>
            <zm:getContact id="${contactId}" var="contact"/>
            <c:set var="messageKey" value="${contact.isGroup ? 'editGroup': 'editContact'}"/>
            <fmt:message var="title" key="${messageKey}">
                <fmt:param>${contact.displayFileAs}</fmt:param>
            </fmt:message>
        </c:otherwise>
    </c:choose>
</app:handleError>

<app:view title="${title}" context="${context}" selected="contacts" contacts="true" tags="true" keys="false">
    <zm:currentResultUrl var="currentUrl" disp="${isCreate ? 0 : 1}" value="" action="${param.action}" context="${context}"/>
    <form action="${currentUrl}" method="post">
        <table width=100% cellpadding="0" cellspacing="0">
            <tr>
                <td class='TbTop'>
                    <app:editContactToolbar create="${isCreate}"context="${context}" keys="true"/>
                </td>
            </tr>
            <tr>
                <td class='ZhAppContent'>
                        <app:editContact title="${title}" contact="${contact}" context="${context}" isgroup="${zm:actionSet(param, 'actionNewGroup')}"/>
                </td>
            </tr>
            <tr>
                <td class='TbBottom'>
                    <app:editContactToolbar create="${isCreate}" context="${context}" keys="false"/>
                </td>
            </tr>
            </table>
        <input type="hidden" name="doContactListViewAction" value="1"/>
        <input type="hidden" name="id" value="${contact.id}"/>
    </form>

</app:view>
