using Insight.Infrastructure.Entities;
using Insight.Web.Constants;
using Insight.Web.Middleware;
using Insight.Web.Models.Account;
using Microsoft.AspNetCore.Components;
using MudBlazor;

namespace Insight.Web.Pages.Account;

public partial class ProfilePasswordDialog
{
    [CascadingParameter(Name = "User")] public InsightUser? User { get; set; }

    [Inject] private NavigationManager NavigationManager { get; init; } = default!;
    [Inject] private ISnackbar Snackbar { get; init; } = default!;

    private void Submit(ChangePasswordModel model)
    {
        if (model.NewPassword != model.ConfirmNewPassword)
        {
            Notification.Error(Snackbar, "Passwords not matching");
            return;
        }

        var key = Guid.NewGuid();
        IdentityMiddleware.Passwords[key] = model;

        NavigationManager.NavigateTo(Navigation.Account.ChangePasswordHref(key), true);
    }
}