<? $formname        = "form_edit_main_navigation_card";
$main_layout_id     = $GLOBALS["language"]["main_layout_id"];
$main_navigation_id = $input_main_navigation["id"];
$translation        = \DynCom\mysyde\common\classes\Registry::get("translation");
// echo var_dump($GLOBALS);
?>

<script type="text/javascript">
    function select_forwardtype( value ) {
        $('#select_navigation_id, #select_page_id, #external_url, #insert_path').hide();
        value = parseInt(value);
        switch (value) {
            case 1:
                $('#select_page_id').show();
                break;

            case 2:
                $('#select_navigation_id').show();
                break;

            case 3:
                $('#external_url').show();
                break;

            case 5:
            	$('#insert_path').show();
            	break;
        }
    }
</script>

<div id="overlaycrumb">
    <?php if ($input_main_navigation["id"] == "") {
        echo $translation->get("new_menuitem_headline");
    } else {
        echo $translation->get("edit_menuitem");
    }
    ?>
    <div id="closeoverlay" onclick="disableOverlay();"></div>
</div>

<ul class="toolbar_menu">
    <?= button("save", $translation->get("save"), $formname, "loadCard('save_navigation', true)"); ?>
    <?= button("save", $translation->get("save_and_close"), $formname, "loadCard('save_navigation', true, '', true)"); ?>
    <li>
        <ul>

            <?php
            if ($input_main_navigation["id"] != "") {

                if ($input_main_navigation['forward_type'] == 1 && $input_main_navigation['forward_page_id'] > 0) {
                    button("edit", $translation->get("edit_site"), $formname, "gotoLocation('" . get_menu_link('structure/sites', $GLOBALS["site"], $GLOBALS["language"], "?action=open_card_page&input_page_id=" . $input_main_navigation['forward_page_id']) . "')", "", FALSE);
                }

                echo button("delete", $translation->get("delete"), $formname, "loadCard('delete_navigation', true, '{$translation->get('delete_navitem_confirm')}', true)", "", FALSE);

            }
            ?>
        </ul>
    </li>
</ul>

<?php
if ($messages !== null) {
    if (count($messages)) {
            echo '<div id="overlayMessages">' . join("\r\n", $messages) . '</div>';
    } 
  }
?>

<form id="<?= $formname ?>" name="<?= $formname ?>" method="post">
    <input name="input_main_navigation_id" type="hidden" value="<?= $input_main_navigation["id"] ?>">
    <input name="input_main_layout_id" type="hidden" value="<?= $main_layout_id ?>">

    <table class="cardform" border="0" cellspacing="0" cellpadding="0">
        <tr>
            <td>
                <? input($translation->get("textkey"), "input_code", "code", $input_main_navigation["code"], 20) ?>
                <? input($translation->get("name"), "input_menu_name", "text", $input_main_navigation["menu_name"], 100) ?>
                <br />
                <?php input_select($translation->get("use_menuitem_for"), "input_forward_type", array(0 => "1", 1 => "2", 2 => "3", 3 => "4", 4 => "5"), array(0 => $translation->get("assign_page"), 1 => $translation->get("internal_forward"), 2 => $translation->get("external_forward"), 3 => $translation->get("placeholder"), 4 => $translation->get("internal_path_forward")), $input_main_navigation['forward_type'], FALSE, FALSE, 'onchange="select_forwardtype(this.value);"') ?>
                <div
                    id="select_navigation_id" <?php echo $input_main_navigation['forward_type'] != 2 ? 'style="display:none;"' : ''; ?>>
                    <? navigation_select($translation->get("choose_navigation_item"), "input_forward_navigation_id", $input_main_navigation["forward_navigation_id"], $GLOBALS["site"]['id'], $GLOBALS["language"]['id'], FALSE); ?>
                </div>

                <div
                    id="select_page_id" <?php echo $input_main_navigation['forward_type'] != 1 && $input_main_navigation['forward_type'] != 0 ? 'style="display:none;"' : ''; ?>>
                    <? page_select($translation->get("choose_page"), "input_forward_page_id", $input_main_navigation, FALSE); ?>
                </div>

                <div
                    id="external_url" <?php echo $input_main_navigation['forward_type'] != 3 ? 'style="display:none;"' : ''; ?>>
                    <? input($translation->get("external_url"), "input_forward_url_external", "text", $input_main_navigation["forward_url"], 255) ?>
                </div>

                <div id="insert_path" <?php echo $input_main_navigation['forward_type'] != 5 ? 'style="display:none;"' : ''; ?>>
                	<? input($translation->get("internal_url"), "input_forward_url", "text", $input_main_navigation["forward_url"], 255) ?>
                </div>
                <? create_preview_select($input_main_navigation) ?>

                <!-- <? input($translation->get("description"), "input_description", "textarea", $input_main_navigation["description"]) ?> -->
                <!-- <? input($translation->get("image"), "input_image", "file", $input_main_navigation["image"], 45, $disabled);
                        $valFile = '';
                        if($input_main_navigation['image'] != '' && $input_main_navigation['image'] != NULL){
                            $valFile = $input_main_navigation['image'];
                        }
                ?>
                      <input type="hidden" name="input_image_old" value="<?=$valFile;?>"> -->
                <!-- <?php
                        // if($input_main_navigation["image"] != NULL && $input_main_navigation["image"] != ''){
                        //     echo "<div class='img_container navigation_image'><img class='img-fluid' src='/userdata/navigation/".$input_main_navigation["image"]."'></div>";
                        //     echo button("delete", $translation->get("delete"), $formname, "loadCard('delete_image', true, '{$translation->get('delete_image')}', false)", "", FALSE);
                        // }
                ?> -->
            </td>
            <td style="display:block;">
                <? input($translation->get("active"), "input_active", "checkbox", $input_main_navigation["active"]) ?>
                <? input($translation->get("validity_from"), "input_validity_from", "date", datefromsql($input_main_navigation["validity_from"]), 10) ?>
                <? input($translation->get("validity_to"), "input_validity_to", "date", datefromsql($input_main_navigation["validity_to"]), 10) ?>
                <h3>Filtern für:</h3>
                <?php
                try {
                    //code...

                    multi_select_permission($input_main_navigation['id'], 'mandant');
                    multi_select_permission($input_main_navigation['id'], 'department');
                    multi_select_permission($input_main_navigation['id'], 'role');
                    multi_select_permission($input_main_navigation['id'], 'einricht');
                    multi_select_permission($input_main_navigation['id'], 'fachbereich');
                } catch (\Throwable $th) {
                    echo $th;
                }
                ?>
                <br />
            </td>
        </tr>
    </table>

</form>