<%@ page language="java" contentType="text/html; charset=utf-8" errorPage="/errorRedesigned.action" %>
<%@ taglib prefix="emm" uri="https://emm.agnitas.de/jsp/jsp/common" %>
<%@ taglib prefix="mvc" uri="https://emm.agnitas.de/jsp/jsp/spring" %>
<%@ taglib prefix="c"   uri="http://java.sun.com/jsp/jstl/core"%>

<%--@elvariable id="isTemplate" type="java.lang.Boolean"--%>
<%--@elvariable id="gridTemplateId" type="java.lang.Boolean"--%>
<%--@elvariable id="isMailingUndoAvailable" type="java.lang.Boolean"--%>
<%--@elvariable id="limitedRecipientOverview" type="java.lang.Boolean"--%>
<%--@elvariable id="mailingId" type="java.lang.Integer"--%>
<%--@elvariable id="workflowId" type="java.lang.Integer"--%>
<%--@elvariable id="mailingShortname" type="java.lang.String"--%>
<%--@elvariable id="isSettingsReadonly" type="java.lang.Boolean"--%>

<c:set var="isMailingGrid" value="${not empty gridTemplateId and gridTemplateId gt 0}" scope="request"/>

<emm:CheckLogon/>
<emm:Permission token="mailing.content.show"/>

<c:url var="templatesOverviewLink" value="/mailing/list.action">
    <c:param name="forTemplates" value="true"/>
</c:url>

<c:url var="templateViewLink" value="/mailing/${mailingId}/settings.action"/>

<c:url var="mailingsOverviewLink" value="/mailing/list.action"/>

<c:url var="mailingViewLink" value="/mailing/${mailingId}/settings.action">
    <c:param name="keepForward" value="true"/>
</c:url>

<c:set var="agnHighlightKey" 		value="mailing.Trackable_Links"     scope="request" />
<c:set var="isBreadcrumbsShown" 	value="true" 					    scope="request" />
<c:set var="agnBreadcrumbsRootKey" 	value="Mailings" 				    scope="request" />
<c:set var="agnBreadcrumbsRootUrl"	value="${mailingsOverviewLink}"	    scope="request" />
<c:set var="agnHelpKey" 			value="mailingLinks" 			    scope="request" />
<c:set var="agnEditViewKey"         value="mailing-links-overview"      scope="request" />

<c:choose>
    <c:when test="${isTemplate}">
        <c:set var="agnNavigationKey" 	 value="templateView" scope="request" />
        <c:set var="agnTitleKey" 		 value="Template" 	  scope="request" />
        <c:set var="agnSubtitleKey" 	 value="Template" 	  scope="request" />
        <c:set var="sidemenu_active" 	 value="Mailings" 	  scope="request" />
        <c:set var="sidemenu_sub_active" value="Templates" 	  scope="request" />

        <emm:instantiate var="agnNavHrefParams" type="java.util.LinkedHashMap" scope="request">
            <c:set target="${agnNavHrefParams}" property="mailingID" value="${mailingId}"/>
            <c:set target="${agnNavHrefParams}" property="init" value="true"/>
        </emm:instantiate>
        
        <emm:instantiate var="agnBreadcrumbs" type="java.util.LinkedHashMap" scope="request">
            <emm:instantiate var="agnBreadcrumb" type="java.util.LinkedHashMap">
                <c:set target="${agnBreadcrumbs}" property="0" value="${agnBreadcrumb}"/>
                <c:set target="${agnBreadcrumb}" property="textKey" value="Templates"/>
                <c:set target="${agnBreadcrumb}" property="url" value="${templatesOverviewLink}"/>
            </emm:instantiate>

            <emm:instantiate var="agnBreadcrumb" type="java.util.LinkedHashMap">
                <c:set target="${agnBreadcrumbs}" property="1" value="${agnBreadcrumb}"/>
                <c:set target="${agnBreadcrumb}" property="text" value="${mailingShortname}"/>
                <c:set target="${agnBreadcrumb}" property="url" value="${templateViewLink}"/>
            </emm:instantiate>
        </emm:instantiate>
    </c:when>
    <c:otherwise>
        <c:set var="agnTitleKey" 			value="Mailing" 				scope="request" />
        <c:set var="agnSubtitleKey" 		value="Mailing" 				scope="request" />
        <c:set var="sidemenu_active" 		value="Mailings" 				scope="request" />
        <c:set var="sidemenu_sub_active"	value="none" 					scope="request" />

        <c:choose>
            <c:when test="${isMailingGrid}">
                <%@ include file="../fragments/mailing-grid-navigation.jspf" %>

                <emm:instantiate var="agnNavHrefParams" type="java.util.LinkedHashMap" scope="request">
                    <c:set target="${agnNavHrefParams}" property="templateID" value="${gridTemplateId}"/>
                    <c:set target="${agnNavHrefParams}" property="mailingID" value="${mailingId}"/>
                </emm:instantiate>
            </c:when>
            <c:otherwise>
                <c:choose>
                    <c:when test="${limitedRecipientOverview}">
                        <c:set var="agnNavigationKey" value="mailingView_DisabledMailinglist" scope="request" />
                    </c:when>
                    <c:otherwise>
                        <c:set var="agnNavigationKey" value="mailingView" scope="request" />
                    </c:otherwise>
                </c:choose>
                <emm:instantiate var="agnNavHrefParams" type="java.util.LinkedHashMap" scope="request">
                    <c:set target="${agnNavHrefParams}" property="mailingID" value="${mailingId}"/>
                    <c:set target="${agnNavHrefParams}" property="init" value="true"/>
                </emm:instantiate>
            </c:otherwise>
        </c:choose>

        <emm:instantiate var="agnBreadcrumbs" type="java.util.LinkedHashMap" scope="request">
            <emm:instantiate var="agnBreadcrumb" type="java.util.LinkedHashMap">
                <c:set target="${agnBreadcrumbs}" property="0" value="${agnBreadcrumb}"/>
                <c:set target="${agnBreadcrumb}" property="text" value="${mailingShortname}"/>
                <c:set target="${agnBreadcrumb}" property="url" value="${mailingViewLink}"/>
            </emm:instantiate>
        </emm:instantiate>
    </c:otherwise>
</c:choose>

<c:if test="${not isSettingsReadonly}">
    <emm:instantiate var="itemActionsSettings" type="java.util.LinkedHashMap" scope="request">
        <%-- Actions dropdown --%>
        <emm:ShowByPermission token="mailing.extend_trackable_links">
            <emm:instantiate var="element" type="java.util.LinkedHashMap">
                <c:set target="${itemActionsSettings}" property="0" value="${element}"/>
                <c:set target="${element}" property="btnCls" value="btn dropdown-toggle"/>
                <c:set target="${element}" property="extraAttributes" value="data-bs-toggle='dropdown'"/>
                <c:set target="${element}" property="iconBefore" value="icon-wrench"/>
                <c:set target="${element}" property="name"><mvc:message code="action.Action"/></c:set>

                <emm:instantiate var="optionList" type="java.util.LinkedHashMap">
                    <c:set target="${element}" property="dropDownItems" value="${optionList}"/>
                </emm:instantiate>

                <%-- Items for dropdown --%>
                <c:url var="bulkClearExtensionsUrl" value='/mailing/${mailingId}/trackablelink/confirmBulkClearExtensions.action'/>
                <emm:instantiate var="option" type="java.util.LinkedHashMap">
                    <c:set target="${optionList}" property="0" value="${option}"/>
                    <c:set target="${option}" property="extraAttributes" value="data-form-url='${bulkClearExtensionsUrl}' data-form-confirm data-form-target='#trackableLinksForm'"/>
                    <c:set target="${option}" property="url">#</c:set>
                    <c:set target="${option}" property="name"><mvc:message code="ClearAllProperties" /></c:set>
                </emm:instantiate>

                <c:url var="bulkActionsViewUrl" value='/mailing/${mailingId}/trackablelink/bulkActionsView.action'/>
                <emm:instantiate var="option" type="java.util.LinkedHashMap">
                    <c:set target="${optionList}" property="1" value="${option}"/>
                    <c:set target="${option}" property="extraAttributes" value="data-form-url='${bulkActionsViewUrl}' data-form-confirm data-form-target='#trackableLinksForm'"/>
                    <c:set target="${option}" property="url">#</c:set>
                    <c:set target="${option}" property="name"><mvc:message code="TrackableLink.edit" /></c:set>
                </emm:instantiate>
            </emm:instantiate>
        </emm:ShowByPermission>

        <emm:instantiate var="element" type="java.util.LinkedHashMap">
            <c:set target="${itemActionsSettings}" property="2" value="${element}"/>

            <c:set target="${element}" property="btnCls" value="btn"/>
            <c:set target="${element}" property="extraAttributes" value="data-form-target='#trackableLinkForm' data-form-set='everyPositionLink: false' data-action='save-all'"/>
            <c:set target="${element}" property="iconBefore" value="icon-save"/>
            <c:set target="${element}" property="name"><mvc:message code="button.Save"/></c:set>
        </emm:instantiate>
    </emm:instantiate>
</c:if>
