using GameIdeas.BlazorApp.Shared.Components.Select; using GameIdeas.BlazorApp.Shared.Components.Select.Models; using GameIdeas.Resources; using GameIdeas.Shared.Dto; using Microsoft.AspNetCore.Components; namespace GameIdeas.BlazorApp.Pages.Games.Components; public class GameBase : ComponentBase { [Parameter] public GameDto GameDto { get; set; } = new(); [Parameter] public EventCallback OnDelete { get; set; } = new(); [Parameter] public EventCallback OnEdit { get; set; } = new(); [Inject] public NavigationManager NavigationManager { get; set; } = default!; protected SelectParams SelectParams = default!; protected Select? SelectOption; protected override void OnInitialized() { SelectParams = new() { Items = [DetailOptions.Detail, DetailOptions.Edit, DetailOptions.Delete], GetItemLabel = GetDetailOptionsLabel }; } protected async Task HandlerSelectValuesChanged(IEnumerable detailOptions) { var option = detailOptions.First(); switch (option) { case DetailOptions.Detail: NavigationManager.NavigateTo($"/Detail/{GameDto.Id}"); break; case DetailOptions.Edit: await OnEdit.InvokeAsync(GameDto); break; case DetailOptions.Delete: await OnDelete.InvokeAsync(GameDto); break; default: break; } SelectOption?.Close(); } private string GetDetailOptionsLabel(DetailOptions options) { return options switch { DetailOptions.Detail => ResourcesKey.Detail, DetailOptions.Edit => ResourcesKey.Edit, DetailOptions.Delete => ResourcesKey.Delete, _ => ResourcesKey.Unknown }; } }