using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;
using System.Text;

namespace MeteoWebApp.ViewComponents
{
    [ViewComponent(Name = "LoginDropDown")]
    public class LoginDropDownViewComponent : ViewComponent
    {
        public async Task<IViewComponentResult> InvokeAsync()
        {

            byte[] sessionKey;
            if (HttpContext.Session.TryGetValue("Authorized", out sessionKey))
            {
                if (Encoding.UTF8.GetString(sessionKey) == "true")
                {
                    HttpContext.Session.TryGetValue("User", out sessionKey);
                    return View("LoggedInDropDown", Encoding.UTF8.GetString(sessionKey));
                }
            }
            return View("NotLoggedInDropDown");
        }
    }
}
