<?php include "../../root.class.php";
$html = new html();
$html->add_styles_page();
// $html->check_user_type("ADMIN");

// HTML FORM ELEMENTS
$name = new input();
$name->class("inputs");
$name->type("text");
$name->placeholder("ASSET NAME");
$name->name("name");
$name->required();
$name->id("name");

$type = new select();
$type->class("inputs");
$type->name("asset_type_id");
$type->id("asset_type_id");
$type->fill_from_db("asset_type", "record_id", "name");
$type->required();

$asset_image_label = new label();
$asset_image_label->for("asset_image");
$asset_image_label->value("PICTURE OF ASSET");

$asset_image = new file_upload();
$asset_image->class("inputs");
$asset_image->name("asset_image");
$asset_image->id("asset_image");
$asset_image->file_save_path("../images");


$name_label = new label();
$name_label->for("name");
$name_label->value("ASSET NAME");

$status_label = new label();
$status_label->for("status");
$status_label->value("STATUS");

$type_label = new label();
$type_label->for("type");
$type_label->value("ASSET TYPE");

$amount_label = new label();
$amount_label->for("amount");
$amount_label->value("AMOUNT");

$amount = new input();
$amount->class("inputs");
$amount->type("number");
$amount->placeholder("AMOUNT");
$amount->name("amount");
$amount->id("amount");

$current_level_label = new label();
$current_level_label->for("current_level_label");
$current_level_label->value("CURRENT LEVEL");

$current_level = new input();
$current_level->class("inputs");
$current_level->type("number");
$current_level->placeholder("CURRENT LEVEL");
$current_level->name("current_level");
$current_level->id("current_level");

$odo_type_label = new label();
$odo_type_label->for("odo_type");
$odo_type_label->value("ODO TYPE");

$odo_type = new select();
$odo_type->class("inputs");
$odo_type->name("odo_type");
$odo_type->id("odo_type");
$odo_type->add_option("", "ODO TYPE");
$odo_type->add_option("Meters", "Meters");
$odo_type->add_option("Kilometers", "Kilometers");
$odo_type->required();

$odo_label = new label();
$odo_label->for("odo");
$odo_label->value("ODO");

$odo = new input();
$odo->class("inputs");
$odo->type("number");
$odo->placeholder("ODO");
$odo->name("odo");
$odo->id("odo");

$status = new select();
$status->class("inputs");
$status->name("status");
$status->id("status");
$status->add_option("", "STATUS");
$status->add_option("ACTIVE", "ACTIVE");
$status->add_option("INACTIVE", "INACTIVE");

$submit_btn = new button();
$submit_btn->value("ADD");
$submit_btn->onclick("add_asset()");

?>

<div class="form_down">
    <h1>ADD ASSETS</h1>

    <div style="display: flex;flex-direction: row;">
        <div style="display: flex;flex-direction: column;">
            <?php
            $name_label->add();
            $name->add();
            ?>
        </div>
        <div style="display: flex;flex-direction: column;">
            <?php
            $asset_image_label->add();
            $asset_image->add();
            ?>
        </div>
    </div>

    <div id="name" style="display: flex;flex-direction: column;">
        <?php
        $type_label->add();
        $type->add();
        ?>
    </div>

    <div id="level" style="display: flex;flex-direction: row;">
        <div style="display: flex;flex-direction: column;">
            <?php
            $amount_label->add();
            $amount->add();
            ?>
        </div>
        <div style="display: flex;flex-direction: column;">
            <?php
            $current_level_label->add();
            $current_level->add();
            ?>
        </div>
    </div>

    <div id="odo" style="display: flex;flex-direction: row;">
        <div style="display: flex;flex-direction: column;">
            <?php
            $odo_type_label->add();
            $odo_type->add();
            ?>
        </div>
        <div style="display: flex;flex-direction: column;">
            <?php
            $odo_label->add();
            $odo->add();
            ?>
        </div>
    </div>

    <?php
    $status_label->add();
    $status->add();
    $submit_btn->add();
    ?>
</div>

<script>
    function get_asset_type() {
        var asset_type_id = document.getElementById("asset_type_id").innerHTML;
        var level = document.getElementById("level");
        var odo = document.getElementById("odo");

        if (asset_type_id == "Vehicles & Transport") {
            level.style.display = "flex";
            odo.style.display = "flex";
        }
    }
</script>

<?php

$ajax = new js_ajax();
$ajax->function_name("add_asset");
$ajax->submit_btn_id("submit");
$ajax->insert("assets");
$ajax->on_success("ASSET SUCCESSFULLY ADDED");

?>