
@using global::Shared.DTOs
@inject HttpClient _hc
@inject NavigationManager nav
<div class="contact-info-area pb-90" id="contact">
    <div class="container">
        <div class="row">
        </div>
    </div>
</div>
<div class="contact-form-area pb-120">
    <div class="container">
        <div class="row gx-0">
            <div class="col-xl-5 col-lg-6">
                <div class="contact-form-left">
                    <div class="contact-form-section-box pb-80">
                        <h5 class="inner-section-subtitle">ارتباط با ما</h5>
                        <h4 class="tp-section-title pb-10">
                            ما مشتاقانه منتظر <br> نظرات شما هستیم

                        </h4>
                    </div>
                    <div class="contact-form-social-box p-relative">

                        <div class="contact-form-section-img">
                            <img src="img/contact/contact-icon-sm-4.png" alt="">
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-xl-7 col-lg-6">
                <div class="contact-form-right-warp">
                    <div class="postbox__comment-form">
                        <EditForm EditContext="editContext" OnValidSubmit="newTicket">
                        <DataAnnotationsValidator />
                            <div class="postbox__comment-input mb-35">
                                <ValidationMessage For="()=>model.FullName" />
                                <ValidationMessage For="()=>model.Mobile" />
                                <ValidationMessage For="()=>model.Title" />
                                <ValidationMessage For="()=>model.Text" />
                            </div>
                            <div class="row gx-20">
                                <div class="col-12">
                                    <div class="postbox__comment-input mb-30">
                                        <InputText style="text-align:center" onkeydown="@OnClearmessageStore" @bind-Value="model.FullName" id="FullName" type="text" class="inputText" required="" />
                                        <span class="floating-label">نام شما</span>
                                    </div>
                                </div>
                                <div class="col-12">
                                    <div class="postbox__comment-input mb-35">
                                        <InputText dir="ltr" style="text-align:center" onkeydown="@OnClearmessageStore" @bind-Value="model.Mobile" id="Mobile" type="number" class="inputText" required="" />
                                        <span class="floating-label">موبایل</span>
                                    </div>
                                </div>
                                <div class="col-12">
                                    <div class="postbox__comment-input mb-35">
                                        <InputText style="text-align:right" @bind-Value="model.Title" id="Title" type="text" class="inputText" required="" />
                                        <span class="floating-label">عنوان</span>
                                    </div>
                                </div>
                                <div class="col-xxl-12">
                                    <div class="postbox__comment-input mb-30">
                                        <InputText style="text-align:right" @bind-Value="model.Text" id="Text" class="textareaText" required=""></InputText>
                                        <span class="floating-label-2">پیام شما ...</span>
                                    </div>
                                </div>
                                <div class="col-xxl-10">
                                    <div class="postbox__btn-box">
                                        <Button Disabled="SpinnerVisible" Type="ButtonType.Submit" Color="ButtonColor.Primary">ارسال پیام</Button>
                                    </div>
                                </div>
                                <div class="col-md-2" style="align-content:center">
                                    <Spinner Visible="SpinnerVisible" Color="SpinnerColor.Primary" />
                                </div>
                            </div>
                        </EditForm>
                        

                    </div>
                </div>
            </div>
        </div>
    </div>
</div>



@code {
    public bool SpinnerVisible { get; set; } = false;
    string type = "NewTicketNoAuthentication";
    private EditContext? editContext;
    [SupplyParameterFromForm]
    private CTicketNoAuthenticationDto? model { get; set; } = new CTicketNoAuthenticationDto();

    private ValidationMessageStore? messageStore;

    protected override void OnInitialized()
    {
        // modelTaxTools ??= new();
        // editContext = new(modelTaxTools);
        // editContext.OnValidationRequested += HandleValidationRequested;
        // messageStore = new(editContext);
        SpinnerVisible = false;
        editContext = new EditContext(model);
        messageStore = new(editContext);
    }
}
@functions{
    private async Task OnClearmessageStore() => messageStore?.Clear();
    private async Task newTicket(){
        SpinnerVisible = true;
        var request = await _hc.PostAsJsonAsync("Ticket/NewTicketNoAuthentication", model);
        if (request.IsSuccessStatusCode)
        {
            messageStore?.Clear();
            var VerificationID = await request.Content.ReadFromJsonAsync<int>();
            nav.NavigateTo($"Verification/{VerificationID}");
        }
        else
        {
            var error = await request.Content.ReadFromJsonAsync<List<string>>();
            messageStore?.Add(() => model.Mobile, error);

        }
        SpinnerVisible = false;
    }


   

}
