@using System.Globalization;
@using Kreta.BusinessLogic.Security;
@using Kreta.Web.Utils
@using Kreta.Web.Configuration
@using Kreta.Web.Helpers
@using Kreta.Core.Configuratiaton.Interface
@using Kreta.Web.Security

@{
    var culture = new CultureInfo(ClaimData.LCID);
    bool hideTips = ProfileUtils.HideTips;
    bool successFeedBackWindowNeeded = Kreta.Web.Controllers.LayoutController.SuccessFeedBackWindowNeeded;
    var idpConfiguration = DependencyResolver.Current.GetService<IIdpConfiguration>();
    string logOutPath = idpConfiguration.LoginEnabled ? Url.Action("LogOut", "Home", new { area = string.Empty }) : Url.Action("LogOut", "Layout", new { area = string.Empty });
    string ajaxError401Redirect = idpConfiguration.LoginEnabled ? Url.Action("Index", "Home", new { area = string.Empty }) : Url.Action("Index", "Login", new { area = "Adminisztracio" });
    var firebaseConfiguration = DependencyResolver.Current.GetService<IFirebaseConfiguration>();
}

<!DOCTYPE html>
<html lang="hu">
<head>
    <meta charset="utf-8" />
    <meta name="format-detection" content="telephone=no" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="IE=Edge" />
    <title>@{ Write(string.IsNullOrWhiteSpace(ViewBag.Title) ? LoginResource.KretaIskolaiAlaprendszer : ViewBag.Title); }</title>
    <link rel="preconnect" href="https://fonts.googleapis.com" crossorigin>
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=Open+Sans:ital,wght@0,300;0,400;0,600;0,700;1,300;1,400;1,600&family=Roboto+Condensed:wght@300;400;700&display=swap" rel="stylesheet">
    <link rel="preconnect" href="https://www.google-analytics.com/" crossorigin>
    <link rel="icon" href="~/favicon.ico" type="image/x-icon" />
    
    <!-- Iskolaőr üzenetküldéshez kell -->
    <script src="https://www.gstatic.com/firebasejs/8.2.6/firebase-app.js"></script>
    <!-- <script src="https://www.gstatic.com/firebasejs/8.2.6/firebase-analytics.js"></script> -->
    <script src="https://www.gstatic.com/firebasejs/8.2.6/firebase-firestore.js"></script>

    @Styles.Render("~/App_Themes/css", "~/Content/css", "~/Content/kretaControls")
    @Styles.Render(Request.Browser.IsMobileDevice ? "~/Content/kretaMobileCss" : "~/Content/kretaCss")
    @Scripts.Render("~/bundles/jquery")
    @Scripts.Render("~/bundles/bootstrap")
    @Scripts.Render("~/bundles/ErrorHandler")
    @Scripts.Render("~/bundles/js")
    @Scripts.Render("~/bundles/moment")
    @Scripts.Render("~/bundles/document-register-element")

    @Html.Raw(Kreta.Core.Analytics.Client.Factory.GetInstance())

    <style>
        .usermenu ul.dropdown-menu i {
            width: 15px;
            height: 15px;
        }
    </style>

    <script type="text/javascript">
        var UrlHelper = {
            AppPath: '@Url.Content("~/")',
            CurrentArea: '@ViewContext.RouteData.DataTokens["area"]',
            CurrentControl: '@(ViewContext.RouteData.Values["controller"])',
            CurrentControlPath: '@Url.Action(string.Empty, ViewContext.RouteData.Values["controller"].ToString())',
            GetLayoutInformationPath: '@Url.Action("GetLayoutInformation", "Layout", new { area = string.Empty })',
            RemainingTime: '@Url.Action("GetRemainingTime", "Layout", new { area = string.Empty })',
            ExtendTime: '@Url.Action("ExtendSessionTime", "Layout", new { area = string.Empty })',
            LogOutPath: '@logOutPath',
            SajatAdatlapPopUp: '@Url.Action("SajatAdatlapPopUp", "Profil", new { area = "Adminisztracio" })',
            DashboardPopup: '@Url.Action("DashboardUzenetPopup", "Layout", new { area = string.Empty })',
            IskolaorUzenetKuldesPopup : '@Url.Action("OpenIskolaorUzenetKuldesPopup", "Layout", new { area = string.Empty })'
        };

        $(document).ready(function () {
            JiraRestHelper.urls = {
                UgyfelSzolgalatPopUp: '@Url.Action("UgyfelSzolgalatPopUp", "UgyfelSzolgalat", new { area = "UgyfelSzolgalat" })',
                BejelentesPopUp: '@Url.Action("BejelentesPopUp", "UgyfelSzolgalat", new { area = "UgyfelSzolgalat" })',
                KommunikaciosPopUp: '@Url.Action("KommunikaciosPopUp", "UgyfelSzolgalat", new { area = "UgyfelSzolgalat" })',
                CreateCommentToBejegyzes: "@Url.HttpRouteUrl(Constants.RouteKey.ActionApi, new { controller = "UgyfelSzolgalatApi", action = "CreateCommentToBejegyzes" })",
                CreateBejelentes: "@Url.HttpRouteUrl(Constants.RouteKey.ActionApi, new { controller = "UgyfelSzolgalatApi", action = "CreateBejelentes" })",
                CreateDbVisszaallitas: "@Url.HttpRouteUrl(Constants.RouteKey.ActionApi, new { controller = "UgyfelszolgalatApi", action = "CreateDbVisszaallitas" })",
                CreateUjUrlIgenyles: "@Url.HttpRouteUrl(Constants.RouteKey.ActionApi, new { controller = "UgyfelszolgalatApi", action = "CreateUjUrlIgenyles" })",
                CreateKonferenciaJelentkezes: "@Url.HttpRouteUrl(Constants.RouteKey.ActionApi, new { controller = "UgyfelszolgalatApi", action = "CreateKonferenciaJelentkezes" })"
            };

            JiraRestHelper.popUpTitles =
            {
                UgyfelSzolgalat: { title: "UgyfelSzolgalatWindow", text: "UgyfelSzolgalat" },
                Bejelentes: { title: "BejelentesWindow", text: "Bejelentes" },
                Kommunikacios: { title: "KommunikaciosWindow", text: "Kommunikacios" }
            };
        });

        GlobalErrorHandler('@Url.Action("ClientError", "Layout", new { area = string.Empty })');
    </script>

    <script type="text/javascript">
        $(document).ready(function () {
            $(document).keydown(function (e) {
                if ($("#KretaProgressBar").hasClass("isOverlayActiv")) {
                    e.preventDefault();
                    return false;
                }
            });
            var ajaxError401RedirectInProgress = false;
            var ajaxCallCount = 0;

            $.ajaxSetup({
                async: true,
                cache: false
            });

            $(document).ajaxSend(function () {
                if (AjaxHelper) {
                    ajaxCallCount++;
                    AjaxHelper.ShowIndicator();
                }
            });

            $(document).ajaxComplete(function () {
                if (AjaxHelper && !ajaxError401RedirectInProgress) {
                    ajaxCallCount--;
                    if (ajaxCallCount === 0) {
                        AjaxHelper.HideIndicator();
                    }
                }
            });

            $(document).ajaxError(function (event, jqxhr, settings, thrownError) {
                if (jqxhr.status == '401') {
                    ajaxError401RedirectInProgress = true;
                    window.location = '@ajaxError401Redirect';
                }
            });

            kendo.culture("@culture.Name");

            $.validator.addMethod(
                "date",
                function (value, element) {
                    return this.optional(element) || (kendo.parseDate(value) != null);
                }
            );

            $.validator.addMethod(
                "min",
                function (value, element, param) {
                    var floatValue = kendo.parseFloat(value);
                    return this.optional(element) || floatValue >= param;
                }
            );

            $.validator.addMethod(
                "max",
                function (value, element, param) {
                    var floatValue = kendo.parseFloat(value);
                    return this.optional(element) || floatValue <= param;
                }
            );

            if ("@ClaimData.SelectedTanevID" !== "@ClaimData.AktivTanevID") {
                setTimeout(function () {
                    $(".main-header, .selectTanev *").addClass("kovTanevBackgound");
                }, 0);
            }

            $.validator.addMethod(
                "requireddropdown",
                function (value, element, param) {
                    var numberRegex = /^\d+$/;
                    return numberRegex.test(value);
                }
            );

            $.validator.addMethod(
                "daterange",
                function (value, element, param) {
                    try {
                        var parts = value.split('.');
                        var date = new Date(Date.UTC(parts[0], parts[1] - 1, parts[2]));
                        var minParts = ("@Kreta.Core.Constants.MinMaxValues.MinDate").split('/');
                        var maxPatrs = ("@Kreta.Core.Constants.MinMaxValues.MaxDate").split('/');
                        if (date >= new Date(Date.UTC(minParts[2], minParts[1] - 1, minParts[0]))
                            && date <= new Date(Date.UTC(maxPatrs[2], maxPatrs[1] - 1, maxPatrs[0]))) {
                            return true;
                        }
                    } catch (e) { }
                    return this.optional(element) || false;
                }
            );
        });

        var MasterLayoutHelper = (function () {
            var masterLayoutHelper = function () { };
            masterLayoutHelper.changeSelectedTanev = function () {
                AjaxHelper.DoPostQuery("@Url.Action("ChangeSelectedTanev", "Layout", new { area = "" })", null, { selectedTanevId: parseInt($("#selectTanevCombo").val()) }, responeOk);
            }

            masterLayoutHelper.popUpSajatAdatlapWindow = function () { AjaxHelper.DoPost(UrlHelper.SajatAdatlapPopUp, null, function (data) { openPopUp('@LayoutResource.SzemelyesAdatlap', data) }) };

            masterLayoutHelper.checkNeedDashboardPopup = function () { checkNeedDashboardPopup(); };

            function openPopUp(title, data) {
                var config = KretaWindowHelper.getWindowConfigContainer();
                config.title = title;
                config.content = data;
                config.width = "85%";
                config.height = "85%";

                var modal = KretaWindowHelper.createWindow("SzemelyesAdatlapWindow", config);
                KretaWindowHelper.openWindow(modal, true);
            }

            function responeOk(data) {
                if (CommonUtils.parseBool(data)) {
                    location.reload();
                } else {
                    location.href = "@Url.Action("Index", "RendszerHibaErtesites", new { area = "Adminisztracio" })";
                }
            }

            function checkNeedDashboardPopup() {
                var needId = $('#popupId').val();
                var needField = $('#popupAzonosito').val();

                if (typeof (needId) !== 'undefined' && needId > 0
                    && typeof (needField) !== 'undefined' && needField.length > 0) {
                    var postData = { popupId: needId, egyediAzonosito: needField };
                    AjaxHelper.DoPost(UrlHelper.DashboardPopup, postData, function (data) { openDashboardPopup($('#Name', data).val(), data); })
                }
            }

            function openDashboardPopup(title, data, actions = []) {
                var config = KretaWindowHelper.getWindowConfigContainer();
                config.title = title;
                config.content = data;
                config.width = "auto";
                config.height = "auto";
                config.maxWidth = "50%";
                config.actions = actions;

                var modal = KretaWindowHelper.createWindow("popupId", config);
                KretaWindowHelper.openWindow(modal, true);
            }

            masterLayoutHelper.popUpIskolaorUzenetKuldesWindow = function () {
                AjaxHelper.DoPost(UrlHelper.IskolaorUzenetKuldesPopup, null, function (data) {
                    openDashboardPopup("@Html.Raw(IskolaorResource.IskolaorErtesitese)", data, ["Close"]);
                });
            };

            return masterLayoutHelper;
        })();
    </script>

    @Scripts.Render("~/bundles/modernizr")
    @Scripts.Render("~/bundles/js")
    @Scripts.Render("~/bundles/kendo")
    @Scripts.Render("~/bundles/KendoGrid")
    @Scripts.Render("~/bundles/KretaImportGridHelper")
    @Scripts.Render("~/bundles/KretaWindowHelper")
    @Scripts.Render("~/bundles/KretaDateTimeHelper")
    @Scripts.Render("~/bundles/KretaComboBoxHelper")
    @Scripts.Render("~/bundles/KretaMultiSelectHelper")
    @Scripts.Render("~/bundles/KretaCheckBoxHelper")
    @Scripts.Render("~/bundles/KretaTooltipHelper")
    @Scripts.Render("~/bundles/KretaDropDownListHelper")
    @Scripts.Render("~/bundles/KretaPanelBarHelper")
    @Scripts.Render("~/bundles/KretaRadioButtonListHelper")
    @Scripts.Render("~/bundles/KretaOsztalybaSorolasHelper")
    @Scripts.Render("~/bundles/KretaWizard")
    @Scripts.Render("~/bundles/KretaNumericHelper")

    @if (IsSectionDefined("AddCss"))
    {
        @RenderSection("AddCss", false) 
    }
    
    @* NOTE: A CommonUtils miatt, a bundle után kell! *@
    <script type="text/javascript">
        var GlobalSystemParams = {};
        GlobalSystemParams.SuccessFeedBackWindowNeeded = CommonUtils.parseBool("@(successFeedBackWindowNeeded.ToString())");
        GlobalSystemParams.IdpLoginEnabled = CommonUtils.parseBool("@(idpConfiguration.LoginEnabled.ToString())");
    </script>
</head>
<body>
    @Html.AntiForgeryToken()

    <script>
        // Iskolaőr üzenetküldéséhez kell
        var firebaseConfig = {
            apiKey: "@firebaseConfiguration.ApiKey",
            authDomain: "@firebaseConfiguration.AuthDomain",
            databaseURL: "@firebaseConfiguration.DatabaseURL",
            projectId: "@firebaseConfiguration.ProjectId",
            storageBucket: "@firebaseConfiguration.StorageBucket",
            messagingSenderId: "@firebaseConfiguration.MessagingSenderId",
            appId: "@firebaseConfiguration.AppId",
            //measurementId: "@firebaseConfiguration.MeasurementId",
        };
        firebase.initializeApp(firebaseConfig);
        //firebase.analytics();
    </script>

    <div id="KretaProgressBar" class="modalBckgroundMain" style="display: block;">
        <img id="bodyOverLayImg" src="~/App_Themes/New_Common_Images/loading2.gif" alt="Folyamatban">
    </div>

    @Html.KretaTooltipTemplate("kendoTooltip-defaultTemplate",
        @"<div class='kendoTooltip defaultKendoTooltip'>
            <table>
                <tr>
                    <td style=""max-width: 600px;word-break:break-all"">#:target.data('tooltiptext')#</td>
                </tr>
            </table>
        </div>")

    @{ Html.RenderPartial("JavascriptTemplates/UserMenu"); }

    @{ Html.RenderPartial("Globalization"); }

    <div class="page-wrapper">
        <div class="clearfix container-fluid" id="frissitesDatumDiv" style="display: none;">
            <div class="row">
                <div class="col-xs-12 col-sm-12" style="font-weight: bold; font-size: 16px;">
                    <div style="text-align:center;">
                        <span style="font-size: 13px;">@AdminisztracioResource.RendszerFrissitesHamarosan</span>
                        <span class="frissitesDatumText"></span>
                    </div>
                </div>
            </div>
        </div>
        <div class="main-header clearfix container-fluid main-header">
            <div class="row">
                <div class="col-xs-6 col-sm-6">
                    <div class="school-title pull-left">
                        <a>
                            <h3 class="brand-title ng-binding">
                                <span id="layout_organizationName"></span>
                                @if (ClaimData.FelhasznaloSzerepCsomagok.Contains(KretaClaimPackages.CsokkentettGondviselo.ClaimValue))
                                {
                                    <span> - @OrarendResource.CsokkentettJogosultsag.ToUpper()</span>
                                }
                            </h3>
                            <div style="clear: both;" class="selectTanev">
                                @if (ClaimData.IsAdministrator || ClaimData.IsArchivIntezmeny)
                                {
                                    @Html.KretaDropdownList("selectTanevCombo", Url.HttpRouteUrl(Constants.RouteKey.ActionApi, new { controller = "ComboBoxHelperApi", action = "GetTanevek" })).Events(e => e.Change("MasterLayoutHelper.changeSelectedTanev")).Value(ClaimData.SelectedTanevID.HasValue ? ClaimData.SelectedTanevID.Value.ToString() : ClaimData.AktivTanevID.Value.ToString())
                                }
                                else if (ClaimData.FelhasznaloSzerepkor == Kreta.Enums.SzerepkorTipusEnum.Naplo)
                                {
                                    @Html.KretaDropdownList("selectTanevCombo", Url.HttpRouteUrl(Constants.RouteKey.ActionApi, new { controller = "ComboBoxHelperApi", action = "GetFelhasznaloTanevek" })).Events(e => e.Change("MasterLayoutHelper.changeSelectedTanev")).Value(ClaimData.SelectedTanevID.HasValue ? ClaimData.SelectedTanevID.Value.ToString() : ClaimData.AktivTanevID.Value.ToString())
                                }
                                else
                                {
                                    @ClaimData.AktivTanevNev
                                }
                            </div>
                        </a>
                    </div>
                </div>
                <div id="layout_userMenu" class="col-xs-6 col-sm-6">
                </div>
            </div>
        </div>
        <div id="layout_navigationBar" class="main-menu clearfix">
            @{ Html.RenderAction("Menu", "Layout", new { SzerepkorId = ClaimData.PackageCacheHash, FelhasznaloId = ClaimData.FelhasznaloId.ToString(), SelectedTanevId = ClaimData.SelectedTanevID.Value, area = "" }); }
        </div>

        <div class="main-wrapper">
            <div class="main-sidebar">
                <div class="row">
                    <div class="sidepanel-wrapper">
                        <ul id="sidepanel_tabs">
                            <li class="sidebar-tab-item">
                                <span id="menucaption" class="head-sidebar-tab-item">@Html.MvcSiteMap(Constants.General.FullKretaSiteMap).SiteMapTitle()</span>
                            </li>
                            <li id="searchPanelFul" class="sidebar-tab-item @{ Write(IsSectionDefined("AddSearchPanel") ? "closed" : "disabled"); } ">
                                <span @if (IsSectionDefined("AddSearchPanel")) { Write("onclick=MasterLayout.OpenCloseSideBar($(this));"); }>Szűrés</span>
                            </li>
                            <li id="tippekFul" class="sidebar-tab-item @if (hideTips || !IsSectionDefined("AddTip")) { Write("disabled"); }" style="cursor: pointer;"
                                @if (!hideTips && IsSectionDefined("AddTip")) { Write("onclick=showTip();"); }><span>Tipp</span></li>
                            @if (!string.IsNullOrWhiteSpace(ViewBag.HelpPageUrl))
                            {
                                <li id='sablonFul1' class='sidebar-tab-item sablonFul' style='cursor: pointer;'>
                                    <a href="@Url.Content(string.Format("~\\Resources\\{0}", ViewBag.HelpPageUrl))" target="_blank">@CommonResource.Help</a>
                                </li>
                            }
                        </ul>
                    </div>
                </div>
            </div>
            <div class="main-content">
                <div class="content-header">
                    <div class="favoriteIconContainer">
                    </div>
                </div>

                <div id="layout_slidePanel" class="content-content" @if (IsSectionDefined("AddSearchPanel")) { Write("data-open=true"); }>
                    <div class="sidebar-container">

                        @if (IsSectionDefined("AddSearchPanel"))
                        {
                            @RenderSection("AddSearchPanel", false)
                            @Html.KretaNotification("popupNotification")
                        }
                        @if (IsSectionDefined("AddTip"))
                        {
                            @RenderSection("AddTip", false)
                            @Html.Partial("_TipsNotification")
                        }
                    </div>
                    <div class="content-container">
                        <div class="k-content">
                            @RenderBody()
                        </div>
                    </div>
                </div>
            </div>
            <script>
                window.onload = function () {
                    var panelWidth = document.getElementById('sidepanel_tabs').offsetWidth;
                    $('#sidepanel_tabs').css('top', panelWidth + "px");
                    $('.content-content').css('min-height', panelWidth + "px");
                };
            </script>
        </div>

        <div class="main-footer1">
        </div>
        <div class="main-footer2">
            eKRÉTA Informatikai Zrt.
            - @Kreta.Core.KretaVersion.Instance.MainVersion
            - @Kreta.Core.KretaVersion.Instance.CommitNumber
            <div style="float: right;">
                <a href="https://tudasbazis.ekreta.hu/pages/viewpage.action?pageId=4064926" target="_blank">@LayoutResource.JogiNyilatkozat</a>
            </div>
        </div>
    </div>

    @Scripts.Render("~/bundles/kreta")
    @Scripts.Render("~/bundles/KretaFileUpload")
    @Scripts.Render("~/bundles/IskolaorUzenetKuldes")

    @if (IsSectionDefined("AddJs"))
    {
        @RenderSection("AddJs", false)
    }

    <!--
        branchName: @Kreta.Core.KretaVersion.Instance.BranchName
        commitNumber: @Kreta.Core.KretaVersion.Instance.CommitNumber
    -->
</body>

</html>