using Microsoft.AspNetCore.Components; using System.Runtime.CompilerServices; using System.Threading.Tasks; using WebWindowComplex.Models; using static WebWindowComplex.Json.WindowConst; namespace WebWindowComplex.Compo { public partial class AreaHwOption { #region Public Properties /// /// Sash corrente rispetto alla lista Sash /// [CascadingParameter(Name = "CurrSashGroup")] public Sash CurrSashGroup { get; set; } = null!; /// /// Vocabolario con traduzione lingua corrente /// [CascadingParameter(Name = "Vocabulary")] public Dictionary Vocabulary { get; set; } = null!; /// /// Evento per aggiornare gli hardware option /// [Parameter] public EventCallback EC_UpdateHwOpt { get; set; } /// /// Evento per chiamare la prima volta la lista delle opzioni /// [Parameter] public EventCallback EC_FirstHwOptionList { get; set; } [CascadingParameter(Name = "IsLoading")] public List IsLoading { get; set; } = new List(); #endregion Public Properties #region Protected Methods protected override void OnParametersSet() { HwOptDict = Vocabulary.Where(x => x.Key.Contains("CWHwOpt_")).ToDictionary(x => x.Key, y => y.Value); } protected override void OnAfterRender(bool firstRender) { if (firstRender) { hwOptCollapsed = true; } } #endregion Protected Methods #region Private Fields private Dictionary HwOptDict = new(); #endregion Private Fields #region Private Properties private bool hwOptCollapsed { get; set; } = true; private bool IsLoadingHwOpt { get => IsLoading != null && IsLoading.Count > 0 && IsLoading.Contains("LoadHwOpt"); } private string hwIcon { get => hwOptCollapsed ? "fa-solid fa-chevron-down" : "fa-solid fa-chevron-up"; } #endregion Private Properties #region Private Methods /// /// Metodo per aprire/chiudere area per hw option /// /// private async Task changeCollapsed() { hwOptCollapsed = !hwOptCollapsed; if (CurrSashGroup.HwOptionList.Count == 0) { await EC_FirstHwOptionList.InvokeAsync(); } } /// /// Report aggiornamento Option Combo /// /// /// private Task RaiseOptCombo(AGBOptionCombo updRec) { var args = new DataUpdateHwOption { AGBOptCombo = updRec }; return EC_UpdateHwOpt.InvokeAsync(args); } /// /// Report aggiornamento Option Text /// /// /// private Task RaiseOptText(AGBOptionText updRec) { var args = new DataUpdateHwOption { AGBOptText = updRec }; return EC_UpdateHwOpt.InvokeAsync(args); } /// /// Metodo per traduzione in lingua corrente /// /// /// private string Traduci(string lemma) { string ans = lemma; if (HwOptDict != null && HwOptDict.ContainsKey(lemma)) { ans = HwOptDict.GetValueOrDefault(lemma) ?? ""; } return ans; } #endregion Private Methods } /// /// Classe per oggetto di aggiornamento delle opzioni /// public class DataUpdateHwOption { public AGBOptionText AGBOptText { get; set; } = null!; public AGBOptionCombo AGBOptCombo { get; set; } = null!; } }