using Blazorise; using FoodsharingSiegen.Contracts.Entity; using FoodsharingSiegen.Server.BaseClasses; using FoodsharingSiegen.Server.Data.Service; using Microsoft.AspNetCore.Components; namespace FoodsharingSiegen.Server.Dialogs { public record InteractionDialogParameter(InteractionType Type, Guid ProspectId, string HeaderText, Func OnSuccess); public partial class InteractionDialog : FsBase { #region Dependencies /// /// Gets or sets the value of the prospect service (ab) /// [Inject] public ProspectService ProspectService { get; set; } = null!; #endregion #region Parameters [Parameter] public string? InfoName { get; set; } [Parameter] public Interaction Interaction { get; set; } = new(); [Parameter] public Func? OnSuccess { get; set; } [Parameter] public bool ShowAlert { get; set; } [Parameter] public bool ShowInfo { get; set; } [Parameter] public bool ShowNotNeeded { get; set; } #endregion #region Public Method ShowAsync /// /// Displays the InteractionDialog modal with the specified parameters. /// /// The modal service used to display the dialog. /// The parameters required for the dialog, including type, prospect ID, header text, and success callback. /// /// A task representing the asynchronous operation. /// public static async Task ShowAsync(IModalService modalService, InteractionDialogParameter parameter) { var showInfo = parameter.Type switch { InteractionType.EinAb => true, InteractionType.Complete => true, InteractionType.IdCheck => true, InteractionType.PrintPass => true, InteractionType.PdfPass => true, InteractionType.ReleasedForVerification => true, _ => false }; var infoName = parameter.Type switch { InteractionType.EinAb => "Welcher Betrieb?", InteractionType.ReleasedForVerification => "Hinweis", _ => "Kommentar" }; var showAlert = parameter.Type switch { InteractionType.EinAb => true, InteractionType.IdCheck => true, _ => false }; var showNotNeeded = parameter.Type switch { InteractionType.PrintPass => true, InteractionType.PdfPass => true, _ => false }; var interaction = new Interaction { Type = parameter.Type, Date = DateTime.UtcNow, ProspectID = parameter.ProspectId }; await modalService.Show(parameter.HeaderText, p => { p.Add(nameof(Interaction), interaction); p.Add(nameof(ShowInfo), showInfo); p.Add(nameof(InfoName), infoName); p.Add(nameof(ShowAlert), showAlert); p.Add(nameof(ShowNotNeeded), showNotNeeded); p.Add(nameof(OnSuccess), parameter.OnSuccess); }); } #endregion #region Private Method AddInteractionAsync /// /// Adds a new interaction for the current user using the ProspectService and hides the modal. /// /// /// A task representing the asynchronous operation. /// private async Task AddInteractionAsync() { Interaction.UserID = CurrentUser.Id; var addR = await ProspectService.AddInteraction(Interaction); if (addR.Success && OnSuccess != null) await OnSuccess.Invoke(); await ModalService.Hide(); } #endregion } }