@using CouchLog.Data

<MudCard Elevation="4">
    <MudCardContent Class="pa-0">
        <MudGrid Spacing="0">
            <!--<editor-fold desc="Poster-Image">-->
            <MudItem xs="4">
                <MudImage 
                    Src="@PrivateEntity.GlobalEntity.PicturePath" 
                    Alt=""
                    ObjectFit="ObjectFit.Cover"
                    Style="width: 100%; height: 100%; min-height: 180px; border-radius: 4px 0 0 4px;" />
            </MudItem>
            <!--</editor-fold>-->
            
            <MudItem xs="8">
                <MudStack Class="pa-3" Spacing="2">
                    <!--<editor-fold desc="Options">-->
                    <MudStack Row="true" AlignItems="AlignItems.Center" Justify="Justify.SpaceBetween">
                        <MudText Typo="Typo.h6">@PrivateEntity.GlobalEntity.Title</MudText>
                        <MudMenu Icon="@Icons.Material.Filled.MoreVert" Color="Color.Default" Dense="true">
                            <MudMenuItem>Edit</MudMenuItem>
                            <MudMenuItem OnClick="@(() => OnRemove.InvokeAsync())">Remove</MudMenuItem>
                        </MudMenu>
                    </MudStack>
                    <!--</editor-fold>-->

                    <!--<editor-fold desc="Dropdown-States">-->
                    <MudSelect
                        T="int"
                        Value="PrivateEntity.UserWatchStatus!.Id"
                        ValueChanged="@(newStatusId => OnWatchStatusChange.InvokeAsync(newStatusId))"
                        Dense="true"
                        Variant="Variant.Outlined"
                        Label="">
                        @foreach (var status in UserWatchStatuses)
                        {
                            <MudSelectItem Value="status.Id">@status.Name</MudSelectItem>
                        }
                    </MudSelect>
                    <!--</editor-fold>-->

                    <!--<editor-fold desc="Dropdown-Season">-->
                    <MudSelect 
                        T="int?" 
                        Value="PrivateEntity.Season"
                        ValueChanged="@(newSeason => OnSeasonChange.InvokeAsync(newSeason))"
                        Dense="true"
                        Variant="Variant.Outlined"
                        Label="">
                        @{
                            int? currentSeason = PrivateEntity.Season ?? 1;
                            int? startOffsetSeason = currentSeason > 1 ? -1 : 0;
                        }
                        @for (int? i = startOffsetSeason; i <= 5; i++)
                        {
                            int? season = currentSeason + i;
                            <MudSelectItem Value="@season">Staffel @season</MudSelectItem>
                        }
                    </MudSelect>
                    <!--</editor-fold>-->

                    <!--<editor-fold desc="Dropdown-Episode">-->
                    <MudSelect 
                        T="int?" 
                        Value="PrivateEntity.Episode"
                        ValueChanged="@(newEpisode => OnEpisodeChange.InvokeAsync(newEpisode))"
                        Dense="true"
                        Variant="Variant.Outlined"
                        Label="">
                        @{
                            int? currentEpisode = PrivateEntity.Episode ?? 1;
                            int? startOffsetEpisode = currentEpisode > 1 ? -1 : 0;
                        }
                        @for (int? i = startOffsetEpisode; i <= 5; i++)
                        {
                            int? episode = currentEpisode + i;
                            <MudSelectItem Value="@episode">Episode @episode</MudSelectItem>
                        }
                    </MudSelect>
                    <!--</editor-fold>-->

                    <!--<editor-fold desc="Details Button">-->
                    <MudStack Row="true" Justify="Justify.FlexEnd">
                        <MudButton 
                            Variant="Variant.Outlined" 
                            Size="Size.Small">
                            Details
                        </MudButton>
                    </MudStack>
                    <!--</editor-fold>-->
                </MudStack>
            </MudItem>
        </MudGrid>
    </MudCardContent>
</MudCard>

@code
{
    [Parameter] public PrivateEntity PrivateEntity { get; set; } = null!;
    [Parameter] public List<UserWatchStatus> UserWatchStatuses { get; set; } = null!;
    
    [Parameter] public EventCallback<int> OnWatchStatusChange { get; set; }
    [Parameter] public EventCallback<int?> OnSeasonChange { get; set; }
    [Parameter] public EventCallback<int?> OnEpisodeChange { get; set; }
    
    [Parameter] public EventCallback OnRemove { get; set; } 
}
