using Microsoft.AspNetCore.Components;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TIAMSharedUI.Shared.Components;
using TIAMWebApp.Shared.Application.Interfaces;

namespace TIAMSharedUI.Pages.Components
{
    public partial class AuthComponent : ComponentBase
    {
        [Inject]
        public ISessionService sessionService { get; set; }
        public bool IsLoggedIn = false;
        [Inject]
        public IComponentUpdateService componentUpdateService { get; set; }

        [CascadingParameter]
        private PopupMessageBox PopupMessageBox { get; set; } = default!;

        public bool IsVisible = true;

        protected override async Task OnInitializedAsync()
        {
            await base.OnInitializedAsync();
            IsLoggedIn = sessionService.IsAuthenticated;
            await PopupMessageBox.ShowAsync("AuthComponent", "Initialized", null, null, null, PopupMessageBox.ButtonOk);

            //if (await PopupMessageBox.Show("Cancel", "Cancel this stuff",
            //PopupMessageBox.ButtonNo, PopupMessageBox.ButtonYes) == PopupMessageBox.ButtonNo)
            //{
                //Something is cancelled
                //args.Cancel = true;
            //}
            componentUpdateService.CallRequestRefresh();
            StateHasChanged();
        }

        protected override void OnAfterRender(bool firstRender)
        {
            base.OnAfterRender(firstRender);

            
        }

        private void ToggleAuthComponent(Microsoft.AspNetCore.Components.Web.MouseEventArgs e)
        {
            IsVisible = false;
        }
    }
}
