<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

<%--@elvariable id="adminDateTimeFormat" type="java.lang.String"--%>
<%--@elvariable id="recipientReports" type="java.util.List<com.agnitas.emm.core.dashboard.bean.DashboardRecipientReport>"--%>

<script id="dashboard-tile-imports-exports" type="text/x-mustache-template">
    <div class="tile draggable-tile scheduled-items">
        <div class="tile-header">
            <h1 class="tile-title">{{- tileName }}</h1>
        </div>
        <div class="tile-body grid js-scrollable" style="--bs-columns: 1">
            <c:choose>
                <c:when test="${recipientReports.isEmpty()}">
                    <div class="notification-simple">
                        <i class="icon icon-info-circle"></i>
                        <span><mvc:message code="noResultsFound" /></span>
                    </div>
                </c:when>
                <c:otherwise>
                    <c:forEach var="report" items="${recipientReports}">
                        <a class="list-item overflow-hidden" href="<c:url value="/recipientsreport/${report.id}/view.action"/>" ${emm:permissionAllowed('recipientsreport.ui.migration', pageContext.request) ? 'data-confirm' : ''}>
                            <div class="item__info-container">
                                <span class="multi-icon-badge" data-tooltip="<mvc:message code="${report.type.messageKey}" />">
                                    <i class="icon icon-file-${report.hasImportType() ? 'import' : 'export'}"></i>
                                     <c:if test="${report.automatic}">
                                         <i class="icon icon-cogs"></i>
                                     </c:if>
                                </span>

                                <c:choose>
                                    <c:when test="${report.successful}">
                                        <span class="status-badge small status.success" data-tooltip="<mvc:message code="default.Success" />"></span>
                                    </c:when>
                                    <c:otherwise>
                                        <span class="status-badge small status.error" data-tooltip="<mvc:message code="Error" />"></span>
                                    </c:otherwise>
                                </c:choose>
                                <span class="item__name-label text-truncate">
                                    <c:choose>
                                        <c:when test="${report.name ne null}">
                                            ${report.name}
                                        </c:when>
                                        <c:otherwise>
                                            <mvc:message code="default.unknown.source" />
                                        </c:otherwise>
                                    </c:choose>
                                </span>
                            </div>

                            <div class="item__schedule-container">
                                <i class="icon icon-calendar-alt"></i>
                                <span class="text-truncate">
                                    <fmt:formatDate var="executionDate" value="${report.lastExecutionDate}" pattern="${adminDateTimeFormat}" timeZone="${adminTimeZone}"/>
                                    <mvc:message code="GWUA.last.execution" />: ${executionDate}
                                </span>
                            </div>
                        </a>
                    </c:forEach>
                </c:otherwise>
            </c:choose>
        </div>
        {{= overlay }}
    </div>
</script>
