@page "/dbtest"
@using TIAMSharedUI.Pages.Components
@using TIAMWebApp.Shared.Application.Interfaces
@using TIAMWebApp.Shared.Application.Models.ClientSide.UI.WizardModels
@using TIAMWebApp.Shared.Application.Utility
@using TIAM.Entities.TransferDestinations
@inject LogToBrowserConsole logToBrowserConsole
@inject IWizardProcessor WizardProcessor
<h3>TestPage</h3>
<div class="container mt-3">
    
<ChooseDestination></ChooseDestination>
<hr/>
<DbTestComponent></DbTestComponent>
    <div class="target-container" @onclick="@(() => EulaVisible = true)">
        <button class="btn btn-primary">NEW TRANSFERDESTINATION</button>
        
    </div>
    <div class="target-container" @onclick="@(() => EulaVisible2 = true)">
        <button class="btn btn-primary">NEW TRANSFER</button>
        
    </div>
    <DxPopup CssClass="popup-demo-events"
             @bind-Visible="@EulaVisible"
             ShowFooter="true"
             CloseOnEscape="false"
             CloseOnOutsideClick="false"
             ShowCloseButton="false"
             HeaderText="DevExpress EULA"
             Closing="EulaPopupClosing"
             Closed="EulaPopupClosed">
        <BodyContentTemplate>
            <InputWizard Data=@myModel OnSubmit="SubmitForm" IgnoreReflection="@TransferDestinationIgnorList"></InputWizard>
        </BodyContentTemplate>
        <FooterContentTemplate Context="Context">
            <div class="popup-demo-events-footer">
                <!--DxCheckBox CssClass="popup-demo-events-checkbox" @bind-Checked="@EulaAccepted">I accept the terms of the EULA</!--DxCheckBox-->
                <!--DxButton CssClass="popup-demo-events-button ms-2" RenderStyle="ButtonRenderStyle.Primary" Text="OK" Click="Context.CloseCallback" /-->
                <DxButton CssClass="popup-demo-events-button ms-2" RenderStyle="ButtonRenderStyle.Secondary" Text="Cancel" Click="CancelEulaClick" />
            </div>
        </FooterContentTemplate>
    </DxPopup>
    <DxPopup CssClass="popup-demo-events"
             @bind-Visible="@EulaVisible2"
             ShowFooter="true"
             CloseOnEscape="false"
             CloseOnOutsideClick="false"
             ShowCloseButton="false"
             HeaderText="New Transfer"
             Closing="EulaPopupClosing"
             Closed="EulaPopupClosed">
        <BodyContentTemplate>
            <InputWizard Data=@myModel2 
                OnSubmit="SubmitForm" 
                IgnoreReflection="@TransferIgnorList" 
                SubmitButtonText="ButtonSend" 
                TitleResourceString="TransferTitle"
            SubtitleResourceString="TransferSubtitle"></InputWizard>
        </BodyContentTemplate>
        
        <FooterContentTemplate Context="Context">
            <div class="popup-demo-events-footer">
                <!--DxCheckBox CssClass="popup-demo-events-checkbox" @bind-Checked="@EulaAccepted">I accept the terms of the EULA</!--DxCheckBox-->
                <!--DxButton CssClass="popup-demo-events-button ms-2" RenderStyle="ButtonRenderStyle.Primary" Text="OK" Click="Context.CloseCallback" /-->
                <DxButton CssClass="popup-demo-events-button ms-2" RenderStyle="ButtonRenderStyle.Secondary" Text="Cancel" Click="CancelEulaClick" />
            </div>
        </FooterContentTemplate>
    </DxPopup>
    <DxPopup @bind-Visible="@MessageBoxVisible"
             ShowFooter="true"
             HeaderText="DevExpress EULA"
             BodyText="You must read and accept the terms of the EULA to continue.">
        <FooterContentTemplate Context="Context">
            <DxButton CssClass="popup-button my-1 ms-2" RenderStyle="ButtonRenderStyle.Primary" Text="OK" Click="Context.CloseCallback" />
            <DxButton CssClass="popup-button my-1 ms-2" RenderStyle="ButtonRenderStyle.Secondary" Text="Cancel" Click="CancelEulaClick" />
        </FooterContentTemplate>
    </DxPopup>
    <TiamDXTextBox></TiamDXTextBox>

</div>
@code {

    public TransferDestinationWizardModel myModel = new TransferDestinationWizardModel();
    public TransferWizardModel myModel2 = new TransferWizardModel();

    bool EulaAccepted { get; set; }
    bool EulaVisible { get; set; }
    bool EulaVisible2 { get; set; }
    bool MessageBoxVisible { get; set; }
    bool SkipEulaCheck { get; set; }
    public List<string> TransferIgnorList = new List<string>
    {
       "Id",       
       "Price"    
    };
    public List<string> TransferDestinationIgnorList = new List<string>
    {       
       // "Latitude",
       // "Longitude"
    };
    

    void TryAgainClick()
    {
        MessageBoxVisible = false;
    }
    void CancelEulaClick()
    {
        myModel = new TransferDestinationWizardModel();
        SkipEulaCheck = true;
        MessageBoxVisible = false;
        EulaVisible = false;
        EulaVisible2 = false;
    }
    void EulaPopupClosed()
    {
        EulaAccepted = false;
        SkipEulaCheck = false;
    }
    void EulaPopupClosing(PopupClosingEventArgs args)
    {
        if (SkipEulaCheck)
            return;
        args.Cancel = !EulaAccepted;
        MessageBoxVisible = !EulaAccepted;
    }

    //-----------------------------------------------------------------------------------

    
    public async Task SubmitForm(object Result)
    {
        var transferDestination = await WizardProcessor.ProcessWizardAsync<TransferDestination>(Result.GetType(), Result);
        logToBrowserConsole.LogToBC($"Submitted nested form: {Result.GetType().FullName}");
    }
}




