using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Forms;
using Microsoft.AspNetCore.Identity.UI.Services;
using System.Net;

namespace CtrlAltAssist.Components.UI;

public partial class ContactUsForm
{
    [Inject] IEmailSender EmailSender { get; set; }

    [SupplyParameterFromForm(FormName = "ContactUs")]
    public ContactUsFormModel model { get; set; } = new();

    private bool isSubmitting = false;
    private string feedback = String.Empty;
    private string feedbackclass = String.Empty;

    private async Task SubmitContactFormAsync()
    {
        isSubmitting = true;
        feedback = "Sending email.\r\nPlease wait...";
        feedbackclass = "secondary";
        StateHasChanged();

        await EmailSender.SendEmailAsync("olivia@ctrlaltassist.co.za",
            "Ctrl Alt Assist website - Contact Us Form Submission",
            $"Name: {model.name}<br/>Email: {model.email}<br/>Message: {model.message}");

        feedback = "Thank you for contacting us! We will get back to you shortly.";
        feedbackclass = "success";
        StateHasChanged();

        await Task.Delay(5000);

        isSubmitting = false;
        model = new();
        feedback = "";
        StateHasChanged();

    }
}
