<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Halbear.Net</title>
    <link rel="stylesheet" href="AccountCentre.css">
    <link rel="stylesheet" href="AccountWindow.css">
</head>
<body onload="CalculateGrid(); SetUp();  startApps();">
<?php
$_SESSION['desktop'] = false;
$UniqueSession = false;
require("../Hidden/Security/StartSession.php");
if($_GET['logout']){
    session_unset();
    session_destroy();
    $UniqueSession = true;
    require("../Hidden/Security/StartSession.php");
}
$_SESSION["ReturnPage"] = "";
if($_GET['Action'] == "LogIn" || $_GET['Action'] == "Visit") {
    $_SESSION["Action"] = $_GET['Action'];
    $_SESSION["ReturnPage"] = $_GET['SourcePage'];
    if($_GET['Action'] == "LogIn")echo("<script>setTimeout(()=>{signInForm();},500);</script>");
}
$LoggedIn = (isset($_SESSION["logged_in"])) ? $_SESSION["logged_in"] : false;
$Page = "AccountCentre";
require_once("../Hidden/Security/PasswordObfsucation.php");
require_once("AccountCentreHotbar.php");
if(!$LoggedIn){
    echo("<div class='ErrorMessageWrapper'>
    <div class='ErrorMessage'><div class='ErrorMessageImage'></div>Uh Oh! looks like you aren't logged in, please log in or sign up to manage your account!</div>
    <div class='LogInButtonWrapper'>
        <button class='HotbarButton' onclick='signInForm();'>Log In</button>
        <button class='HotbarButton' onclick='signUpForm();'>Sign Up</button>
    </div>
</div>");
} else{
    echo("<div class='ErrorMessageWrapper'>
    <div class='ErrorMessage'><div class='ErrorMessageImage' style='background-image: url(".'"'.((isset($_SESSION["user_pfp"])) ? $_SESSION["user_pfp"] : "../GeneralAssets/AccountSymbol.png").'"'.")'></div>DisplayName: ".$_SESSION["display_name"]."<br>UserName: ".$_SESSION["username"]." </div>
</div>");
}
?>
<div class="FormWindowContainer" id="FormContainer"></div>
<script src="DragAccountWindows.js"></script>
<script>
    var CurrentlyLoaded;
    function removeWindow(){
        document.getElementById("FormContainer").innerHTML = "";
    }
    function signInForm(){
        document.getElementById("FormContainer").innerHTML = "";
        var NewAppLoaded = new XMLHttpRequest();
        NewAppLoaded.open('GET', "LogInForm.php", true);
        NewAppLoaded.onreadystatechange = function () {
            if (NewAppLoaded.readyState !== 4) return;
            if (NewAppLoaded.status !== 200) return;
            var NewForm = NewAppLoaded.responseText;
            document.getElementById("FormContainer").insertAdjacentHTML("beforeend",NewForm);
        };
        NewAppLoaded.send();
        setTimeout(()=>{
            document.getElementById("FormBox").classList.remove("minimised");
            setTimeout(()=>{
                document.getElementById("FormBox").classList.remove("animationTransition");
                DragWindow(document.getElementById("FormBox"));
            },500);
        },100);
    }
    function signUpForm(){
        document.getElementById("FormContainer").innerHTML = "";
        var NewAppLoaded = new XMLHttpRequest();
        NewAppLoaded.open('GET', "SignUpForm.php", true);
        NewAppLoaded.onreadystatechange = function () {
            if (NewAppLoaded.readyState !== 4) return;
            if (NewAppLoaded.status !== 200) return;
            var NewForm = NewAppLoaded.responseText;
            document.getElementById("FormContainer").insertAdjacentHTML("beforeend",NewForm);
        };
        NewAppLoaded.send();
        setTimeout(()=>{
            document.getElementById("FormBox").classList.remove("minimised");
            setTimeout(()=>{
                document.getElementById("FormBox").classList.remove("animationTransition");
                DragWindow(document.getElementById("FormBox"));
            },500);
        },100);
    }

    function showpasstext(){
        document.getElementById("showloginpasswordcheckbox").checked = !document.getElementById("showloginpasswordcheckbox").checked;
        showpass();
    }
    function showpass(){
        var pwdBox = document.getElementById("password");
        if(document.getElementById("showloginpasswordcheckbox").checked){
            pwdBox.type = "text";
        } else pwdBox.type = "password";
    }
</script>
<div class="Copyright">©Halbear Networking & Software Ltd</div>
</body>
</html>