<?php include "../../root.class.php";
$html = new html();
$html->add_styles_page();
$calendar = new calendar();

$name = new input();
$name->type("text");
$name->placeholder("name");
$name->name("name");
$name->required();
$name->class("inputs");
$name->id("name");

$public_holiday = new select();
$public_holiday->name("public_holiday");
$public_holiday->class("inputs");
$public_holiday->id("public_holiday");
$public_holiday->required();
$public_holiday->add_option("", "INCLUDE PUBLIC HOLIDAYS");
$public_holiday->add_option("0", "No");
$public_holiday->add_option("1", "Yes");
?>


<div class="form_down">
    <h1>ADD Service Ticket </h1>
    <hr>
    <?php echo $html->select_html_from_db("clients", "record_id", "name", "", "client_id", "client_id"); ?>
    <button type="button" class="submit_btn" onclick="new_client_popup();" id="quick_add_client">New Client</button>
    <?php echo $html->date_input_html("date_time_created", "date_time_created", "inputs", "", date('Y-m-d H:i', strtotime("+2 Hours")), "", ""); ?>
    <?php echo $html->date_input_html("action_date", "action_date", "inputs", "", date('Y-m-d H:i', strtotime("+2 Hours")), "", ""); ?>
    <?php echo $html->select_html_from_db("users", "record_id", "username", "", "user_id_assigned", "user_id_assigned"); ?>
    <?php echo $html->input_html("", "{$_SESSION['user_id']}", "user_id_created", "user_id_created", "", "", "", "", "hidden"); ?>
    <?php echo $html->select_html_from_db("service_ticket_types", "record_id", "name", "", "service_ticket_type_id", "service_ticket_type_id");
    $name->add();
    $public_holiday->add();
    ?>
    <?php echo $html->complete_text_editor('description');
    echo $html->submit_btn('submit', 'ADD', 'add_service_ticket()');
    $calendar->generateCalendar(0, false, false)
        ?>
</div>

<div style="display: none" class="overlay_iframe" id="overlay_iframe">
    <iframe id="add_client_iframe" name="add_client_iframe" src="../../app/clients/add_client.php"></iframe>
    <button class="close_btn" onclick="close_new_client_popup();">X</button>
</div>

<?php
$html->html_form_ajax("add_service_ticket", "INSERT", "service_tickets", '', false, [], '', ['description'], "", "");
?>

<script>
    function new_client_popup() {
        document.getElementById('overlay_iframe').style.display = "flex";
    }
    function close_new_client_popup() {
        document.getElementById('overlay_iframe').style.display = "none";
        document.getElementById('add_client_iframe').src = document.getElementById('add_client_iframe').src;
        location.reload();
    }
</script>