<%@ page import="ro.emid.common.constants.AppConstants" %>
<%@ page import="ro.emid.common.utils.*" %>
<%@ taglib prefix="emid" tagdir="/WEB-INF/tags" %>

<%! private static boolean in(String value, String... values) {
    if (value == null) return false;
    if (values == null || value.length() == 0) return false;
    for (String s : values) {
        if (s != null && s.equals(value)) return true;
    }
    return false;
}%>

<%
    String jsp = (String) request.getAttribute("__jsp");
    if( jsp == null){
        response.sendRedirect( request.getContextPath() + request.getContextPath() +  ".default");
        return;
    }

    String selectedSubTab = "";
    String action = request.getParameter("action");

    if(in(action, "showSucursale", "showCentre", "showEvenimente")) {
        selectedSubTab = MenuConstants.INCIDENTE.LINK_HOME;
    }else if(in(action, "rapoarte", "raport-evenimente", "raport-incidente", "raport-echipamente", "raport-indicatori",
            "raport-indicatori-simplu1", "raport-indicatori-simplu2", "raport-indicatori-simplu3", "raport-indici-specifici",
            "raport-top10-fi", "raport-top10-fe", "raport-top10-fi-fe", "raport-intreruperi",
            "raport-monitorizare-intreruperi", "raport-lucrari-accidentale-incidente"
    )) {
        selectedSubTab = MenuConstants.INCIDENTE.LINK_RAPOARTE;
    }
%>
<%@include file="incidente/declaratii.jsp"%>

<!DOCTYPE html>
<html>
<head>
    <title>EMID / Incidente - [<%=AppProperties.getInstance().getVersion()%>]</title>
    <meta http-equiv="content-type" content="text/html;charset=utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />

    <%@include file="layout/includes-emid.jspf"%>

    <link rel="stylesheet" type="text/css" href="<%=AppConstants.WEB_RESOURCE_PATH%>/styles/incidente.css?<%=AppProperties.getInstance().getVersion()%>">

    <script type="text/javascript">
        var filtruIncidenteWindow = null;
        function showFiltruIncidente(){
            if( filtruIncidenteWindow != null) filtruIncidenteWindow.close();
            filtruIncidenteWindow = window.open('<%=AppConstants.APP_NAME%>?action=editFiltruIncidente&type=incidente','filtruIncidente', 'top=50,left=50,width=850, height=570, status=yes,resizable=yes,dependent=yes,alwaysRaised=yes, scrollbars=yes');
        }

        var filtruEchipamenteWindow = null;
        function showFiltruEchipamente(){
            if( filtruEchipamenteWindow != null) filtruEchipamenteWindow.close();
            filtruEchipamenteWindow = window.open('<%=AppConstants.APP_NAME%>?action=editFiltruIncidente&type=echipamente','filtruEchipamente', 'top=50,left=50,width=850, height=550, status=yes,resizable=yes,dependent=yes,alwaysRaised=yes, scrollbars=yes');
        }

        var filtruRapoarteWindow = null;
        function openConfigurareFiltruRapoarte(){
            if( filtruRapoarteWindow) filtruRapoarteWindow.close();
            filtruRapoarteWindow = window.open('<%=AppConstants.APP_NAME%>?action=showFiltru','filtru', 'width=800 height=620, scrollbars=yes,status=yes,resizable=yes,top=10,left=50,dependent=yes,alwaysRaised=yes');
        }
    </script>
</head>
<body>

<div class="header">
    <%@include file="layout/header-emid.jspf"%>
	
    <div class="subTabsWrapper">
        <span class="subTab">
            <a class="clean subitem <%=selectedSubTab.equals(MenuConstants.INCIDENTE.LINK_HOME)?"selected":""%>" href="<%=AppConstants.APP_NAME%>?action=<%=user.getProfile().getHomePageAction()%>">Home</a>
        </span>
        <span class="divider"></span>
        <%if(UserUtils.hasIeRightRapoarteIncidente(user)){%>
            <span class="subTab">
                <a class="clean subitem <%=selectedSubTab.equals(MenuConstants.INCIDENTE.LINK_RAPOARTE)?"selected":""%>" href="<%=AppConstants.APP_NAME%>?action=rapoarte">Rapoarte</a>
            </span>
            <span class="divider"></span>
        <%}%>
		<span class="subTab">
            <a class="clean subitem" href="http://10.30.1.60:8080/emid-rapoarte?userId=<%=user.getId()%>">Rapoarte 2020</a>
        </span>
        <span class="divider"></span>
    </div>
</div>

<emid:messages/>
<div class="content">
    <jsp:include page="<%=jsp%>"/>
</div>

</body>
</html>
