<?php include "../../root.class.php";
$html = new html();
$html->add_styles_page();
// $html->check_user_type("ADMIN");

// HTML FORM ELEMENTS

$username_label = new label();
$username_label->for("username");
$username_label->value("USERNAME : ");
$username_label->addAttribute("style", "font-size: 1.5em; width: 30%;");

$username = new input();
$username->class("inputs");
$username->type("text");
$username->placeholder("Username");
$username->name("username");
$username->style("font-size: 1.5em; width: 80%; margin: 0.5vw auto;");
$username->id("username");

$password_label = new label();
$password_label->for("user_password");
$password_label->value("PASSWORD : ");
$password_label->addAttribute("style", "font-size: 1.5em; width: 30%;");

$password = new input();
$password->class("inputs");
$password->type("text");
$password->placeholder("Password");
$password->name("user_password");
$password->style("font-size: 1.5em; width: 80%; margin: 0.5vw auto;");
$password->id("user_password");

$user_type = new select();
$user_type->class("inputs");
$user_type->name("user_type");
$user_type->id("user_type");
$user_type->style("font-size: 1.5em; width: 80%; margin: 0.5vw auto;");
$user_type->add_option("", "USER TYPE");
$user_type->fill_from_db("user_type", "name", "name");
$user_type->onchange("geteams()");

$user_type_label = new label();
$user_type_label->for("user_type");
$user_type_label->value("USER TYPE : ");
$user_type_label->addAttribute("style", "font-size: 1.5em; width: 30%;");

$team_label = new label();
$team_label->for("team");
$team_label->value("TEAM : ");
$team_label->addAttribute("style", "font-size: 1.5em; width: 30%;");

$team = new select();
$team->class("inputs");
$team->name("team_id");
$team->id("team_id");
$team->style("font-size: 1.5em; width: 80%; margin: 0.5vw auto;");
$team->fill_from_db("teams", "name", "name");

$submit_btn = new button();
$submit_btn->value("ADD");
$submit_btn->onclick("add_user()");

?>

<div class="form_down">
    <h1>ADD USER</h1>

    <div style="display: flex; flex-direction: row; width: 100%;">
        <?php
        $username_label->add();
        $username->add();
        ?>
    </div>

    <div style="display: flex; flex-direction: row; width: 100%;">
        <?php
        $password_label->add();
        $password->add();
        ?>
    </div>

    <div style="display: flex; flex-direction: row; width: 100%;">
        <?php
        $user_type_label->add();
        $user_type->add();
        ?>
    </div>

    <div style="display: flex; flex-direction: row; width: 100%;">
        <?php
        $team_label->add();
        $team->add();
        ?>
    </div>
    <?php




    $submit_btn->add();
    ?>
</div>

<?php

$ajax = new js_ajax();
$ajax->function_name("add_user");
$ajax->submit_btn_id("submit");
$ajax->insert("users");
$ajax->on_success("SUCCESSFULLY ADDED THE USER");
$ajax->redirect("../users/home.php");
?>