@using ErsatzTV.Application.MediaCards
@using ErsatzTV.Application.MediaItems
@using static Prelude
@inject NavigationManager NavigationManager
@inject IDialogService Dialog
@inject IMediator Mediator
@if (SelectClicked.HasDelegate || !string.IsNullOrWhiteSpace(Href))
{
@if (string.IsNullOrWhiteSpace(Data.Poster))
{
string placeholder = GetPlaceholder(Data.SortTitle);
Typo typo = placeholder.Length switch
{
> 12 => Typo.h3,
> 2 => Typo.h2,
_ => Typo.h1
};
@placeholder
}
else
{
}
@if (IsSelected)
{
}
@if (Data.State == MediaItemState.FileNotFound)
{
}
else if (Data.State == MediaItemState.Unavailable)
{
}
@if (SelectClicked.HasDelegate)
{
}
@if (!IsSelectMode)
{
@if (AddToCollectionClicked.HasDelegate || AddToPlaylistClicked.HasDelegate || Data.HasMediaInfo)
{
@if (AddToCollectionClicked.HasDelegate)
{
}
@if (AddToPlaylistClicked.HasDelegate)
{
}
@if (Data.HasMediaInfo)
{
}
}
@if (DeleteClicked.HasDelegate)
{
}
}
}
else
{
@if (string.IsNullOrWhiteSpace(Data.Poster))
{
string placeholder = GetPlaceholder(Data.SortTitle);
Typo typo = placeholder.Length switch
{
> 12 => Typo.h3,
> 2 => Typo.h2,
_ => Typo.h1
};
@placeholder
}
else
{
}
}
@(Title ?? Data.Title)
@(Subtitle ?? Data.Subtitle)
@code {
[Parameter]
public MediaCardViewModel Data { get; set; }
[Parameter]
public string Href { get; set; }
[Parameter]
public EventCallback DataRefreshed { get; set; }
[Parameter]
public string Placeholder { get; set; }
[Parameter]
public string Title { get; set; }
[Parameter]
public string Subtitle { get; set; }
[Parameter]
public string ContainerClass { get; set; }
[Parameter]
public string CardClass { get; set; }
[Parameter]
public ArtworkKind ArtworkKind { get; set; }
[Parameter]
public EventCallback DeleteClicked { get; set; }
[Parameter]
public EventCallback AddToCollectionClicked { get; set; }
[Parameter]
public EventCallback AddToPlaylistClicked { get; set; }
[Parameter]
public EventCallback SelectClicked { get; set; }
[Parameter]
public bool IsSelectMode { get; set; }
[Parameter]
public bool IsSelected { get; set; }
[Parameter]
public Color SelectColor { get; set; } = Color.Tertiary;
[Parameter]
public bool IsRemoteArtwork { get; set; }
private string _overlayClass = "media-card-overlay";
private string GetPlaceholder(string sortTitle)
{
if (Placeholder != null)
{
return Placeholder;
}
char first = Optional(sortTitle).Map(t => t.ToUpperInvariant().HeadOrNone()).Flatten().Match(head => head, () => ' ');
return char.IsDigit(first) || !char.IsLetter(first) ? "#" : first.ToString();
}
private string GetPosterUrl()
{
if (string.IsNullOrWhiteSpace(Data.Poster))
{
return null;
}
if (IsRemoteArtwork || Data.Poster.StartsWith("http://") || Data.Poster.StartsWith("https://"))
{
return Data.Poster;
}
return $"artwork/{PathForArtwork()}/{Data.Poster}";
}
private string PathForArtwork() => ArtworkKind switch
{
ArtworkKind.Thumbnail => "thumbnails",
_ => "posters"
};
private void OnOverlayClick(MouseEventArgs e)
{
if (IsSelectMode || string.IsNullOrWhiteSpace(Href))
{
SelectClicked.InvokeAsync(e);
}
else
{
NavigationManager.NavigateTo(Href);
}
}
private void OnMenuOpenChanged(bool open)
{
_overlayClass = open
? "media-card-overlay media-card-overlay-menu-open"
: "media-card-overlay";
StateHasChanged();
}
private async Task ShowMediaInfo()
{
Either maybeInfo = await Mediator.Send(new GetMediaItemInfo(Data.MediaItemId));
foreach (MediaItemInfo info in maybeInfo.RightToSeq())
{
var parameters = new DialogParameters { { "MediaItemInfo", info } };
var options = new DialogOptions { CloseButton = true, CloseOnEscapeKey = true, MaxWidth = MaxWidth.Medium, FullWidth = true };
IDialogReference dialog = await Dialog.ShowAsync(Data.Title, parameters, options);
DialogResult _ = await dialog.Result;
}
}
private void TroubleshootPlayback() => NavigationManager.NavigateTo($"system/troubleshooting/playback?mediaItem={Data.MediaItemId}");
}