@using System.Text.RegularExpressions
@using System.ComponentModel.DataAnnotations
@using MarketData.MarketDataModel
@using MarketData.Utils
@using eNavigator.Interfaces
@using eNavigator.Models
@using eNavigator.Routes
@using eNavigator.Components.Shared
@using Microsoft.AspNetCore.Components.Web.Virtualization
@inject IMarketDataServiceClient marketDataServiceClient
@inject ISnackbar snackbarService
@attribute [Route(PageRoute.Headlines)]

<div>
<div style="align-items: center; vertical-align: middle">
    <BusyIndicator IsBusy="@IsBusy" Message="@BusyMessage"></BusyIndicator>
</div>

<style>
    .selected {
        background-color: #1E88E5 !important;
    }
    .selected > td {
        color: white !important;
    }
    .selected > td .mud-input {
        color: white !important;
    }
</style>

<MudGrid>
    <MudItem xs="2">
        <MudItem Class="overflow-y-hidden" Style="height: 70px">
            <MudSelect Variant="Variant.Outlined" T="DateTime" Label="Date" @bind-value="@SelectedDate" @bind-value:after="@OnValueChanged">        
              <Virtualize Context="date" Items="@AvailableDates" OverscanCount="15">
                <MudSelectItem T="DateTime" Value="@date">@date.ToShortDateString()</MudSelectItem>
              </Virtualize>         
            </MudSelect>
        </MudItem>
       <MudButton Variant="Variant.Filled" Color="Color.Primary" OnClick="@RefreshClicked">Refresh</MudButton>
    </MudItem>
    <MudItem xs="10">
        <MudTable T="Headline" Items="@HeadlinesCollection" Hover="true" Breakpoint="Breakpoint.Sm" @ref="mudTable"
            RowClass="cursor-pointer" RowClassFunc="@SelectedRowClassFunc" OnRowClick="RowClickEvent">
        <HeaderContent>
            <MudTh>Date</MudTh>
            <MudTh>Modified</MudTh>
            <MudTh>Symbol</MudTh>
            <MudTh>Source</MudTh>
            <MudTh>Company Name</MudTh>
            <MudTh>Headline</MudTh>
        </HeaderContent>
        <RowTemplate>
            <MudTd DataLabel="Date">@context.Date.ToShortDateString()</MudTd>
            <MudTd DataLabel="Modfiied">@Utility.DateTimeToStringHHMMSSTT(context.Modified)</MudTd>
            <MudTd DataLabel="Symbol">@context.Symbol</MudTd>
            <MudTd DataLabel="Source">@context.Source</MudTd>
            <MudTd DataLabel="Company Name">@context.CompanyName</MudTd>
            <MudTd DataLabel="Headline">@context.Entry</MudTd>
        </RowTemplate>
        </MudTable>
    </MudItem>
</MudGrid>
</div>
