<?php
include "classes/class.loader.php";
$html = new html();
$html->bacground_emoji();
$calls = new functions();
$db = new db();
$html->header();

?>
<style>
    body {
        background-color: #bebebee7;
        color: white;
    }
</style>



<div class="home_container">
    <div class="data_container_for_adding">
        <div class="data_row">
            <form action="upload_news.php" method="post" id="news_form" class="form_class">
                <label>HEADER</label>
                <input type="text" id="heading" name="heading" value="">
                <br>
                <label>DESCRIPTION</label>
                <textarea id="description" name="description" rows="10"></textarea>
                <br>
                <label>IMAGE</label>
                <input type="file" id="image" name="image">
                <br><br>
                <button type="submit" id="button_1">ADD</button>
            </form>
            <div id="message"></div>
            <script>
                document.addEventListener("DOMContentLoaded", function () {
                    document.getElementById('news_form').addEventListener('submit', function (e) {
                        document.getElementById("button_1").innerHTML = "UPLODAING...";
                        e.preventDefault();
                        let formData = new FormData(this);
                        let xhr = new XMLHttpRequest();
                        xhr.open('POST', 'upload_news.php', true);
                        xhr.onload = function () {
                            if (xhr.status >= 200 && xhr.status < 400) {
                                if (xhr.responseText == "NEWS UPLOADED") {
                                    document.getElementById("button_1").innerHTML = "UPLODAING...";
                                    document.getElementById("news_form").reset();
                                    window.location.href = "news.php";
                                }
                            }
                        };
                        xhr.send(formData);
                    });
                });
            </script>

        </div>
    </div>

    <?php $html->html_end(); ?>