@using CarCareTracker.Helper
@inject IConfigHelper config
@inject ITranslationHelper translator
@{
    var userConfig = config.GetUserConfig(User);
    var enableAuth = userConfig.EnableAuth;
    var userLanguage = userConfig.UserLanguage;
}
@model string
@{
    ViewData["Title"] = "Garage";
}
@section Scripts {
    <script src="~/js/garage.js?v=@StaticHelper.VersionNumber"></script>
    <script src="~/js/settings.js?v=@StaticHelper.VersionNumber"></script>
    <script src="~/js/supplyrecord.js?v=@StaticHelper.VersionNumber"></script>
    <script src="~/lib/drawdown/drawdown.js"></script>
}
<div class="lubelogger-mobile-nav" onclick="hideMobileNav()">
    <ul class="navbar-nav" id="homeTab" role="tablist">
        <li class="nav-item" role="presentation">
            <button class="nav-link user-select-none @(Model == "garage" ? "active" : "")" ontouchstart="detectLongTouch(this)" ontouchend="detectTouchEndPremature(this)" id="garage-tab" data-bs-toggle="tab" data-bs-target="#garage-tab-pane" type="button" role="tab"><span class="ms-2 display-3"><i class="bi bi-car-front me-2"></i>@translator.Translate(userLanguage,"Garage")</span></button>
        </li>
        @if(config.GetServerEnableShopSupplies())
        {
            <li class="nav-item" role="presentation">
                <button class="nav-link" id="supply-tab" data-bs-toggle="tab" data-bs-target="#supply-tab-pane" type="button" role="tab"><span class="ms-2 display-3"><i class="bi bi-shop me-2"></i>@translator.Translate(userLanguage, "Supplies")</span></button>
            </li>
        }
        @if(userConfig.ShowCalendar){
            <li class="nav-item" role="presentation">
                <button class="nav-link" id="calendar-tab" data-bs-toggle="tab" data-bs-target="#calendar-tab-pane" type="button" role="tab"><span class="ms-2 display-3"><i class="bi bi-calendar-week me-2"></i>@translator.Translate(userLanguage, "Calendar")</span></button>
            </li>
        }
        <li class="nav-item" role="presentation">
            <button class="nav-link @(Model == "settings" ? "active" : "")" id="settings-tab" data-bs-toggle="tab" data-bs-target="#settings-tab-pane" type="button" role="tab"><span class="ms-2 display-3"><i class="bi bi-gear me-2"></i>@translator.Translate(userLanguage,"Settings")</span></button>
        </li>
        @if (User.IsInRole("CookieAuth") || User.IsInRole("APIAuth"))
        {
            @if (User.IsInRole(nameof(UserData.IsAdmin)))
            {
                <li class="nav-item" role="presentation">
                    <a class="dropdown-item" href="/Admin"><span class="display-3 ms-2"><i class="bi bi-people me-2"></i>@translator.Translate(userLanguage,"Admin Panel")</span></a>
                </li>
            }
            @if (User.IsInRole(nameof(UserData.IsRootUser)))
            {
                <li>
                    <button class="nav-link" onclick="showRootAccountInformationModal()"><span class="display-3 ms-2"><i class="bi bi-person-gear me-2"></i>@translator.Translate(userLanguage, "Profile")</span></button>
                </li>
            } else
            {
                <li>
                    <button class="nav-link" onclick="showAccountInformationModal()"><span class="display-3 ms-2"><i class="bi bi-person-gear me-2"></i>@translator.Translate(userLanguage, "Profile")</span></button>
                </li>
            }
            <li class="nav-item" role="presentation">
                <button class="nav-link" onclick="performLogOut()"><span class="display-3 ms-2"><i class="bi bi-box-arrow-right me-2"></i>@translator.Translate(userLanguage,"Logout")</span></button>
            </li>
        }
    </ul>
</div>
<div class="container">
    <div class="row mt-2">
        <div class="d-flex lubelogger-navbar">
            <img src="@config.GetLogoUrl()" class="lubelogger-logo" />
            <div class="lubelogger-navbar-button">
                <button type="button" class="btn btn-adaptive" onclick="showMobileNav()"><i class="bi bi-list lubelogger-menu-icon"></i></button>
            </div>
        </div>
    </div>
    <hr />
    <ul class="nav nav-tabs lubelogger-tab" id="homeTab" role="tablist">
        <li class="nav-item" role="presentation">
            <button class="nav-link resizable-nav-link @(Model == "garage" ? "active" : "")" oncontextmenu="sortGarage(this)" id="garage-tab" data-bs-toggle="tab" data-bs-target="#garage-tab-pane" type="button" role="tab"><i class="bi bi-car-front"></i><span class="ms-2 d-sm-none d-md-inline">@translator.Translate(userLanguage, "Garage")</span></button>
        </li>
        @if (config.GetServerEnableShopSupplies())
        {
            <li class="nav-item" role="presentation">
                <button class="nav-link resizable-nav-link" id="supply-tab" data-bs-toggle="tab" data-bs-target="#supply-tab-pane" type="button" role="tab" aria-selected="false"><i class="bi bi-shop"></i><span class="ms-2 d-sm-none d-md-inline">@translator.Translate(userLanguage, "Supplies")</span></button>
            </li>
        }
        @if (userConfig.ShowCalendar){
            <li class="nav-item" role="presentation">
                <button class="nav-link resizable-nav-link" id="calendar-tab" data-bs-toggle="tab" data-bs-target="#calendar-tab-pane" type="button" role="tab" aria-selected="false"><i class="bi bi-calendar-week"></i><span class="ms-2 d-sm-none d-md-inline">@translator.Translate(userLanguage, "Calendar")</span></button>
            </li>
        }
        <li class="nav-item ms-auto" role="presentation">
            <button class="nav-link resizable-nav-link @(Model == "settings" ? "active" : "")" id="settings-tab" data-bs-toggle="tab" data-bs-target="#settings-tab-pane" type="button" role="tab"><i class="bi bi-gear"></i><span class="ms-2 d-sm-none d-md-inline">@translator.Translate(userLanguage, "Settings")</span></button>
        </li>
        @if (User.IsInRole("CookieAuth") || User.IsInRole("APIAuth"))
        {
            <li class="nav-item dropdown" role="presentation">
                <a class="nav-link resizable-nav-link dropdown-toggle" data-bs-toggle="dropdown" href="#" role="button" aria-expanded="false"><i class="bi bi-person"></i><span class="ms-2 d-sm-none d-md-inline">@User.Identity.Name</span></a>
                <ul class="dropdown-menu">
                    @if (User.IsInRole(nameof(UserData.IsAdmin)))
                    {
                        <li>
                            <a class="dropdown-item" href="/Admin"><i class="bi bi-people me-2"></i>@translator.Translate(userLanguage,"Admin Panel")</a>
                        </li>
                    }
                    @if (User.IsInRole(nameof(UserData.IsRootUser)))
                    {
                        <li>
                            <button class="dropdown-item" onclick="showRootAccountInformationModal()"><i class="bi bi-person-gear me-2"></i>@translator.Translate(userLanguage, "Profile")</button>
                        </li>
                    } else
                    {
                        <li>
                            <button class="dropdown-item" onclick="showAccountInformationModal()"><i class="bi bi-person-gear me-2"></i>@translator.Translate(userLanguage, "Profile")</button>
                        </li>
                    }
                    <li>
                        <button class="dropdown-item" onclick="performLogOut()"><i class="bi bi-box-arrow-right me-2"></i>@translator.Translate(userLanguage,"Logout")</button>
                    </li>
                </ul>
            </li>
        }
    </ul>
    <div class="tab-content" id="homeTab">
        <div class="tab-pane fade @(Model == "garage" ? "show active" : "")" id="garage-tab-pane" role="tabpanel" tabindex="0">
            <div id="garageContainer">

            </div>
        </div>
        <div class="tab-pane fade" id="supply-tab-pane" role="tabpanel" tabindex="0">
        </div>
        <div class="tab-pane fade" id="calendar-tab-pane" role="tabpanel" tabindex="0">
        </div>
        <div class="tab-pane fade @(Model == "settings" ? "show active" : "")" id="settings-tab-pane" role="tabpanel" tabindex="0">
        </div>
    </div>
</div>

<div class="modal fade" id="addVehicleModal" tabindex="-1" role="dialog">
    <div class="modal-dialog modal-lg" role="document">
        <div class="modal-content" id="addVehicleModalContent">
        </div>
    </div>
</div>
<div class="modal fade" id="bulkImportModal" tabindex="-1" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content" id="bulkImportModalContent">
        </div>
    </div>
</div>
<div class="modal fade" id="accountInformationModal" tabindex="-1" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content" id="accountInformationModalContent">
        </div>
    </div>
</div>
<div class="stickerPrintContainer hideOnPrint">
</div>
<script>
    loadGarage();
    bindWindowResize();
</script>