@page "/"
@inject IJSRuntime JS
@inject NavigationManager Nav

<PageTitle>FilterCair Dashboard</PageTitle>
<div class="container py-5">
    <div class="text-center mb-5">
        <h2 class="fw-bold text-primary mb-2">
            <i class="bi bi-wind me-2"></i> Willkommen bei FilterCair
        </h2>
        <p class="text-secondary fs-5">FÜÜS - Filter Überprüf- und Überwachungssoftware</p>
    </div>

    <!-- RESPONSIVES GRID MIT ICONS -->
    <div class="row g-4 justify-content-center">
        <!-- MEINE AUFGABEN -->
        <div class="col-12 col-sm-6 col-lg-4">
            <div class="card dashboard-tile h-100 shadow-sm border-0 rounded-4" 
                 @onclick="@(() => Nav.NavigateTo("/tasks"))" 
                 style="cursor: pointer;">
                <div class="card-body d-flex flex-column justify-content-center align-items-center text-center p-4">
                    <i class="bi bi-list-check display-5 mb-3 text-primary"></i>
                    <h5 class="fw-semibold mb-2">Meine Aufgaben</h5>
                    <p class="text-muted small mb-0">Übersicht aller offenen Wartungen und Filterprüfungen.</p>
                </div>
            </div>
        </div>

        <!-- KUNDENÜBERSICHT -->
        <div class="col-12 col-sm-6 col-lg-4">
            <div class="card dashboard-tile h-100 shadow-sm border-0 rounded-4" 
                 @onclick="@(() => Nav.NavigateTo("/customers"))" 
                 style="cursor: pointer;">
                <div class="card-body d-flex flex-column justify-content-center align-items-center text-center p-4">
                    <i class="bi bi-buildings display-5 mb-3 text-primary"></i>
                    <h5 class="fw-semibold mb-2">Kundenübersicht</h5>
                    <p class="text-muted small mb-0">Wähle den Kundenstandort aus, um Filterdaten zu erfassen.</p>
                </div>
            </div>
        </div>
    </div>
    <!-- GRID END -->

    <!-- STANDORTANZEIGE -->
    <div class="text-center mt-5 text-muted small">
        <i class="bi bi-geo-alt-fill me-1"></i> Aktueller Standort: @currentLocation
    </div>
</div>

    
@code {
    private bool isOnline = true;
    private string currentLocation = "unbekannt";

    protected override async Task OnInitializedAsync()
    {
        await JS.InvokeVoidAsync("FilterCair.registerNetworkHandler", DotNetObjectReference.Create(this));
        isOnline = await JS.InvokeAsync<bool>("FilterCair.isOnline");
        currentLocation = await JS.InvokeAsync<string>("FilterCair.getLocation");
    }

    [JSInvokable]
    public void UpdateNetworkStatus(bool online)
    {
        isOnline = online;
        StateHasChanged();
    }

    private void ShowOfflineData()
    {
        Console.WriteLine("Offline-Daten anzeigen");
    }
}
