<%@ page contentType="text/html; charset=UTF-8"%><%@ include file="/WEB-INF/jspf/include/taglibs.jsp"%>

<%--
<c:if test="${not empty dashboardPaths}">
	<div class="dashboardPaths" >
		<c:forEach var="item" varStatus="status" items="${dashboardPaths}">
			<c:choose>
				<c:when test="${status.last}"><span style="font-size: 15pt;">${item.title}</span></c:when>
				<c:otherwise><a onclick="showBlock( 'dashboardRoot', 'list', { ...dashboardQuery, key: '${item.key}' } ); return false;">${item.title}</a> / </c:otherwise>
			</c:choose>
		</c:forEach>
	</div>
</c:if>
--%>

<div class="d-flex flex-row justify-content-between align-items-stretch mb-2">
</div>
<ul class="dashboard">
	<li class="tile mb-5">
	<div class="flex-fill" style="height: 15rem;">
		<div class="d-flex flex-row justify-content-between align-items-center m-2">
			<div class="fs-4 fw-medium mx-4 my-2">Договор</div>
			<div class="fs-6 fw-bold mx-3 text-info"><a href="${pageContext.request.contextPath}/webexecuter/b/Contracts">Другие договора</a></div>
		</div>
		<div class="fw-bold fs-1 mx-4">${sessionScope.contract_current.title}</div>
		<bg:textTrim textClass="fs-5 mx-4 text-info" maxLength="100" text="${sessionScope.contract_current.comment}"/>
	</div>
	</li>
	<li class="tile mb-5">
	<div class="flex-fill" style="height: 15rem;">
		<div class="d-flex flex-row justify-content-between align-items-center m-2">
			<div class="fs-4 fw-medium mx-4 my-2">Баланс</div>
			<div class="fs-6 fw-bold mx-3 text-info"><%-- Бонусы --%></div>
		</div>
		<div class="fw-bold fs-1 mx-4">${balanceSum} <span class="CUR fw-bold fs-1"/></div>
		<div class="fs-5 mx-4 text-info"><c:choose><c:when test="${ammountToBePaid gt 0}"> К оплате: <fmt:formatNumber value="${ammountToBePaid}" maxFractionDigits="2"/> <span class="CUR fs-5"/></c:when><c:otherwise>&nbsp;</c:otherwise></c:choose></div>
		<div class="d-flex flex-row justify-content-between align-items-center">
			<c:set var="paymentUrl">window.location.href='<c:choose><c:when test="${not empty extPaymentUrl}">${extPaymentUrl}</c:when><c:otherwise>${pageContext.request.contextPath}/webexecuter/b/Payment</c:otherwise></c:choose>'</c:set>
			<div class="fs-5 mx-4 text-info"><button type="button" class="btn btn-primary fs-4 mt-3 px-5" onclick="${paymentUrl}">Оплатить</button></div>
		</div>
	</div>
	</li>
<c:forEach var="item" items="${dashboardItems}">
	<c:set var="dashboardOnClick">
		<c:choose>
		<c:when test="${item.itemType == 'FOLDER'}">showDashboardBlock( { ...dashboardQuery, key: '${item.key}' } );</c:when>
		<c:when test="${item.itemType == 'LINK'}">window.location.href = '${item.url}'</c:when>
		<c:when test="${item.itemType == 'ASSISTANT_MASTER'}">window.location.href='${pageContext.request.contextPath}/webexecuter/p${item.moduleId}/Assistant?masterId=${item.assistantMasterId}'</c:when>
		<c:when test="${fn:startsWith( item.module, 'ru.bitel.bgbilling.plugins' )}">window.location.href ='${pageContext.request.contextPath}/webexecuter/p${item.moduleId}/${item.action}'</c:when>
		<c:when test="${item.moduleId > 0 }">window.location.href ='${pageContext.request.contextPath}/webexecuter/m${item.moduleId}/${item.action}'</c:when>
		<c:otherwise>window.location.href = '${pageContext.request.contextPath}/webexecuter?action=${item.action}&mid=${item.moduleId}&module=${item.module}&contractId=${contract.id}'</c:otherwise>
		<%--
		<c:otherwise>return showBlock( 'contentRoot', '', { action: '${item.action}', mid: '${item.moduleId}', module: '${item.module}', contractId: '${contract.id}', getBody: true } );</c:otherwise>
		<c:otherwise>window.location.href = '${pageContext.request.contextPath}/webexecuter?action=${item.action}&mid=${item.moduleId}&module=${item.module}&contractId=${contract.id}'</c:otherwise>
		 --%>
		</c:choose>
	</c:set>
	<c:if test="${item.itemType ne 'FOLDER'}">
	<c:set var="bg"><c:if test="${not empty item.icon}">background-attachment: fixed; background-image: url(${pageContext.request.contextPath}/${item.icon}); background-position: 30% 2rem; background-repeat: no-repeat;</c:if></c:set>
	<li class="tile tileHeight tilewMiddle" onclick="${dashboardOnClick}">
		<c:set var="bg"><c:if test="${not empty item.icon}">background-attachment: fixed; background-image: url(${pageContext.request.contextPath}/${item.icon}); background-position: 30% 2rem; background-repeat: no-repeat;</c:if></c:set>
		<div class="header bd-highlight">${item.title}</div>
		<div class="d-flex flex-row">
			<c:set var="iconSrc"><c:if test="${not empty item.icon}">${pageContext.request.contextPath}/${item.icon}</c:if></c:set>
			<div class="px-3 py-2"><img src="${iconSrc}" class="icon-color"></div>
			<c:set var="bodyText"><c:choose><c:when test="${not empty item.description}">${item.description}</c:when><c:otherwise><c:forEach var="subItems" varStatus="subStatus" items="${item.subItems}"><c:if test="${subStatus.index > 0}">, </c:if>${subItems.title}</c:forEach></c:otherwise></c:choose></c:set>
			<div class="body flex-fill"><c:choose><c:when test="${fn:length(bodyText) > 100}">${fn:substring(bodyText, 0, 100)}...</c:when><c:otherwise>${fn:substring(bodyText, 0, -1)}</c:otherwise></c:choose></div>
		</div>
	</li>
	</c:if>
</c:forEach>
</ul>

<script>

function showDashboardBlock( query )
{
	showBlock( 'contentRoot', 'list', query );
}

jQuery("#pageTitle").hide();

</script>
