@inherits ComponentBase
@using System.Globalization

<BaseContainer @ref="_container" Title="@_title" Breadcrumbs="@_breadcrumbs" LoadData="LoadDataAsync">
    <Content>
            <MudGrid>
                <MudItem xs="12" sm="6" md="6" lg="3">
                    <KeyValueCard T="string" Key="Serial" Value="@_agent?.Serial" />
                </MudItem>

                <MudItem xs="12" sm="6" md="6" lg="3">
                    <KeyValueCard T="string" Key="Hostname" Value="@_agent?.Hostname" />
                </MudItem>

                <MudItem xs="12" sm="6" md="6" lg="3">
                <KeyValueCard T="string" OnClick="()=>_hostDialog?.ToggleAsync(_agent?.Id)" Key="Host" Value="@(_agent?.Hosts?.FirstOrDefault()?.Name ?? "-")" Icon="@Icons.Material.Outlined.Devices" IconColor="@Color.Primary" />
                </MudItem>

                <MudItem xs="12" sm="6" md="6" lg="3">
                    <KeyValueCard T="long?" Href="@Navigation.Management.Agents.LogsHref(AgentId)" Key="Logs" Value="@_logs" Icon="@Icons.Material.Outlined.Assignment" IconColor="@Color.Primary" />
                </MudItem>

                <MudItem xs="12" sm="6" md="6" lg="3">
                    @if (_agent is not null)
                    {
                        <KeyValueCard T="string" Key="Status" Value="@(_agent.GetOnlineState() ? "Online" : "Offline")" ValueColor="@(_agent.GetOnlineState() ? Color.Success : Color.Error)" />
                    }
                </MudItem>

                <MudItem xs="12" sm="6" md="6" lg="3">
                    <KeyValueCard T="Version" Key="Version" Value="@_agent?.Version" />
                </MudItem>

                @if (_agent?.Connected is not null)
                {
                    <MudItem xs="12" sm="6" md="6" lg="3">
                        <KeyValueCard T="string" Key="Connected" Value="@_agent.Connected?.ToLocalTime().ToString("dd.MM.yyyy HH:mm:ss")" />
                    </MudItem>
                }

                @if (_agent?.Activity is not null)
                {
                    <MudItem xs="12" sm="6" md="6" lg="3">
                        <KeyValueCard T="string" Key="Activity" Value="@_agent?.Activity?.ToLocalTime().ToString("dd.MM.yyyy HH:mm:ss")" />
                    </MudItem>
                }

                @if (_agent is not null && _agent.GetOnlineState())
                {
                    @*<MudItem xs="12" sm="6" md="6" lg="3">
                        <KeyValueCard T="string" Key="Latency" Value="@($"{_agent?.Latency?.TotalMilliseconds} ms")" />
                    </MudItem>*@

                    <MudItem xs="12" sm="6" md="6" lg="3">
                        <KeyValueCard T="string" Key="Packets Sent" Value="@($"{_agent?.SentPackets}")" /> 
                    </MudItem>

                    <MudItem xs="12" sm="6" md="6" lg="3">
                        <KeyValueCard T="string" Key="Packets Received" Value="@($"{_agent?.ReceivedPackets}")" />
                    </MudItem>

                    <MudItem xs="12" sm="6" md="6" lg="3">
                        <KeyValueCard T="string" Key="Bytes Sent" Value="@($"{_agent?.SentBytes} Bytes")" />
                    </MudItem>

                    <MudItem xs="12" sm="6" md="6" lg="3">
                        <KeyValueCard T="string" Key="Bytes Received" Value="@($"{_agent?.ReceivedBytes} Bytes")" />
                    </MudItem>

                    <MudItem xs="12" sm="6" md="6" lg="3">
                        <KeyValueCard T="string" Key="Endpoint" Value="@_agent.Endpoint" />
                    </MudItem>
                }
            </MudGrid>
    </Content>
</BaseContainer>

<AgentHostDialog @ref="_hostDialog" OnChanges="OnRefreshAsync" />

@code {
    private AgentHostDialog? _hostDialog;
}