<%@ page buffer="8kb" autoFlush="true" %>
<%@ page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8" %>
<%@ taglib prefix="zm" uri="com.zimbra.zm" %>
<%@ taglib prefix="mo" uri="com.zimbra.mobileclient" %>
<%@ 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="com.zimbra.i18n" %>
<mo:handleError>
    <zm:getMailbox var="mailbox"/>
    <c:choose>
        <c:when test="${not empty mailbox.prefs.locale}">
            <fmt:setLocale value='${mailbox.prefs.locale}' scope='request'/>
        </c:when>
        <c:otherwise>
            <fmt:setLocale value='${pageContext.request.locale}' scope='request'/>
        </c:otherwise>
    </c:choose>
    <fmt:setBundle basename="/messages/ZhMsg" scope="request"/>
    <c:set var="action" value="${zm:cook(empty param.paction ? param.action : param.paction)}" scope="request"/>
    <c:choose>
        <c:when test="${not empty param.actionSearch}">
            <c:if test="${not empty param.sq_size}"><c:set var="sq_size"
                                                           value=" ${param.sq_size_comp}:${fn:trim(param.sq_size)}${param.sq_size_units}"/></c:if>
            <c:if test="${not empty param.sq_from}"><c:set var="sq_from" value=' from:(${param.sq_from})'/></c:if>
            <c:if test="${not empty param.sq_subject}"><c:set var="sq_subject" value=' subject:(${param.sq_subject})'/></c:if>
            <c:if test="${not empty param.sq_tocc}"><c:set var="sq_tocc"
                                                           value=' (to:(${param.sq_tocc}) or cc:(${param.sq_tocc}))'/></c:if>
            <c:set var="sq">${param.sq}${param.sq_folder}${param.sq_tag}${param.sq_unread}${param.sq_flagged}${sq_subject}${sq_tocc}${sq_from}${sq_size}</c:set>
        </c:when>
        <c:otherwise>
            <c:set var="sq" value="${param.sq}"/>
        </c:otherwise>
    </c:choose>


    <%-- switch based on context search types --%>

        <c:choose>
            <c:when test="${not empty param.actionSearch && empty sq}">
                 <c:set var="context" value="${pcontext}"/>
                 <%--<div class="StatusWarning"><fmt:message key="actionNoSearchQuerySpecified"/></div>--%>
                <mo:status style="Warning">
                     <fmt:message key="actionNoSearchQuerySpecified"/>
                </mo:status>
            </c:when>
            <c:otherwise><zm:computeSearchContext  var="context" usecache="true" query="${sq}" limit="${param.st eq 'contact' ? mailbox.prefs.contactsPerPage : mailbox.prefs.mailItemsPerPage}"/>
            </c:otherwise>
        </c:choose>
    <c:set var="pcontext" value="${context}" scope="session"/>
</mo:handleError>
<%-- switch based on context search types --%>
<c:choose>

    <c:when test="${requestScope.contactAddError != null}">
        <mo:contactEdit context="${context}"/>
    </c:when>
    <c:when test="${requestScope.currentContactId != null}">
        <mo:contactView context="${context}" id="${requestScope.currentContactId}"/>
    </c:when>
    <c:when test="${context.isConversationSearch and action eq 'view'}">
        <c:choose>
            <c:when test="${!empty requestScope.op && requestScope.op eq 'x'}">
                <mo:convListView context="${context}"/>                
            </c:when>    
            <c:otherwise>
                <mo:convView context="${context}"/>
            </c:otherwise>
        </c:choose>
    </c:when>
    <c:when test="${context.isConversationSearch}">
        <mo:convListView context="${context}"/>
    </c:when>
    <c:when test="${context.isMessageSearch and action eq 'view'}">
        <c:choose>
            <c:when test="${!empty requestScope.op && requestScope.op eq 'x'}">
                <mo:messageListView context="${context}"/>
            </c:when>
            <c:otherwise>
                <mo:messageView context="${context}"/>
            </c:otherwise>
       </c:choose>
    </c:when>
    <c:when test="${context.isMessageSearch}">
        <mo:messageListView context="${context}"/>
    </c:when>
    <c:when test="${context.isContactSearch and action eq'view'}">
        <c:choose>
        <c:when test="${!empty requestScope.op && requestScope.op eq 'x'}">
            <mo:contactListView context="${context}"/>
        </c:when>
        <c:otherwise>
            <mo:contactView context="${context}"/>             
        </c:otherwise>
        </c:choose>
    </c:when>
    <c:when test="${context.isGALSearch and action eq'view'}">
            <mo:galContactView email="${param.email}" id="${param.id}" context="${context}"/>
    </c:when>
    <c:when test="${context.isContactSearch and action eq'edit'}">
        <mo:contactEdit context="${context}"/>
    </c:when>
    <c:when test="${context.isContactSearch or context.isGALSearch}">
        <mo:contactListView context="${context}"/>
    </c:when>
    <c:when test="${context.isTaskSearch}">
        <mo:taskListView context="${context}"/>
    </c:when>
    <%-- bug:56196
    <c:when test="${context.isWikiSearch && (empty sessionScope.l_view || sessionScope.l_view eq 'explorer' || param.view eq 'explorer')}">
        <mo:wikiExplorerView context="${context}"/>
    </c:when>
    <c:when test="${context.isWikiSearch && ( sessionScope.l_view eq 'list' || param.view eq 'list')}">
            <mo:wikiListView context="${context}"/>
    </c:when>
    --%>
     <c:when test="${context.isBriefcaseSearch && (empty sessionScope.l_view || sessionScope.l_view eq 'explorer' || param.view eq 'explorer')}">
        <mo:briefcaseExplorerView context="${context}"/>
    </c:when>
    <c:when test="${context.isBriefcaseSearch && ( sessionScope.l_view eq 'list' || param.view eq 'list')}">
        <mo:briefcaseListView context="${context}"/>
    </c:when>
    <c:otherwise>
        <fmt:message key="error" var="title"/>
        <mo:view mailbox="${mailbox}" title="${title}" context="${context}">
            <fmt:message key="ztaglib.TAG_EXCEPTION"/>
        </mo:view>
    </c:otherwise>
</c:choose>
