<?php
$formname    = "form_contact_card";
$translation = \DynCom\mysyde\common\classes\Registry::get("translation");
$inputname   = "input_id";
?>

<div id="overlaycrumb">
    <?php if ($input_contact["id"] == "") {
        echo $translation->get("new_user");
    } else {
        echo $input_contact["name"] . " " . $translation->get("edit_small");
    }
    ?>
    <div id="closeoverlay" onclick="disableOverlay();"></div>
</div>
    <ul class="toolbar_menu flex_toolbar main_contact">
        <?= button("save", $translation->get("save"), $formname, "loadCard('save', true)"); ?>
        <?= button("save", $translation->get("save_and_close"), $formname, "loadCard('save', true, '', true)"); ?>
        <?= button("copy", $translation->get("new_worker_report"), $formname, "loadCard('report', true)", "", FALSE); ?>
        <?= button("copy", $translation->get("worker_dismissal_report"), $formname, "loadCard('report_dismissal', true)", "", FALSE); ?>
        <?= button("copy", $translation->get("Hausausweis beantragen"), $formname, "loadCard('hausausweis_request', true)", "", FALSE); ?>

        <?php
        if ($input_contact["id"] != "") {
            echo button("delete", $translation->get("delete"), $formname, "loadCard('delete', true, '{$translation->get('delete_user_confirm')}', true)", "", FALSE);
        }
        ?>

    </ul>

<?php
if ($messages !== null) {
    if (count($messages)) {
        echo '<div id="overlayMessages">' . join("\r\n", $messages) . '</div>';
    }
}
 
?>
<div class="cardform_wrapper">
    <div class="pop_up_buttons">
        <button class="pop_up_button" data-popup-id="popup-1" >Stammdaten</button>
        <button class="pop_up_button" data-popup-id="popup-2" >Mandanten</button>
        <!-- <button class="pop_up_button" data-popup-id="popup-9" >Zertifikate</button> -->
    </div>
    <form id="<?= $formname ?>" name="<?= $formname ?>" method="post">
        <div class="pop_up_element" id="popup-1">
            <input name="input_id" type="hidden" value="<?= $input_contact["id"] ?>">

            <table class="cardform" border="0" cellspacing="0" cellpadding="0">
                <tr>
                    <td>
                        <? input($translation->get("name"), "input_name", "hidden", $input_contact["name"], 45) ?>
                        <? input($translation->get("email"), "input_email", "hidden", $input_contact["email"], 100) ?>
                        <? input($translation->get("name"), "input_name", "text", $input_contact["name"], 45) ?>
                        <? input($translation->get("email"), "input_email", "text", $input_contact["email"], 100) ?>
                        <!-- <? input($translation->get("shortcut"), "input_shortcut", "text", $input_contact["shortcut"], 20) ?> -->
                        <!-- <? input($translation->get("password"), "input_password", "password","", 45, false) ?> -->
                        <? input($translation->get("image"), "input_image", "file", $input_contact["image"], 45);
                            $valFile = '';
                            if($input_contact['image'] != '' && $input_contact['image'] != NULL){
                                $valFile = $input_contact['image'];
                            }
                        ?>
                        <? input($translation->get("phone_no"), "input_phone_no", "text", $input_contact["phone_no"], 100) ?>
                        <? input($translation->get("cost_center"), "input_cost_center", "text", $input_contact["cost_center"], 255) ?>
                        
                        <?php
                            if($input_contact["image"] != NULL && $input_contact["image"] != ''){
                                echo "<div class='img_container intranet_user_image'>";
                                echo "<img class='img-fluid' src='/userdata/intranet/contact/".$input_contact["image"]."'>";
                                echo button("delete", $translation->get("delete"), $formname, "loadCard('delete_image', true, '{$translation->get('delete_user_picture')}', false)", "", FALSE);
                                echo "</div>";

                            }
                        ?>
                        <? input($translation->get("image"), "user_image_old", "hidden", $valFile, 100) ?>
                    </td>
                    <td>
                        <? input($translation->get("address"), "input_address", "text", $input_contact["address"], 50) ?>
                        <? input($translation->get("post_code"), "input_post_code", "text", $input_contact["post_code"], 50) ?>
                        <? input($translation->get("city"), "input_city", "text", $input_contact["city"], 50) ?>
                        <? input($translation->get("birthday"), "input_birthday", "date", $input_contact["birthday"], 50) ?>
                    </td>
                </tr>
            </table>
        </div>

        <div class="pop_up_element" id="popup-2">
            <!-- <input type="text" placeholder="Suche"> -->
            <table class="mandant_table">
                <thead>
                    <tr>
                        <th><?=$translation->get("mandant")?></th>
                        <th><?=$translation->get("top_department")?></th>
                        <th><?=$translation->get("top_space")?></th>
                        <th>Einrichtung</th>
                        <th>Rolle</th>
                        <th style="display: none;">Telefonnummer</th>
                        <th style="display: none;">E-Mail</th>
                        <!-- <th>Aktion</th> -->
                    </tr>
                </thead>
                <tbody>
                    <?php load_mandant_list_new($input_contact); ?>
                    
                </tbody>
            </table>
        </div>
        <?php load_permission($input_contact); ?>
    </form>
</div>

<script>
try {
    

const showPopupButtons = document.querySelectorAll('.pop_up_button');
const popups = document.querySelectorAll('.pop_up_element');

// Standardmäßig den ersten Button aktivieren
showPopupButtons[0].classList.add('aktiv');
popups[0].style.display = 'block';

showPopupButtons.forEach(button => {
    button.addEventListener('click', () => {
        // Verberge alle Pop-ups
        popups.forEach(popup => {
            popup.style.display = 'none';
        });

        // Entferne die "aktiv" Klasse von allen Buttons
        showPopupButtons.forEach(btn => {
            btn.classList.remove('aktiv');
        });

        // Füge die "aktiv" Klasse zum angeklickten Button hinzu
        button.classList.add('aktiv');

        const popupId = button.getAttribute('data-popup-id');
        const popup = document.getElementById(popupId);
        if (popup) {
            popup.style.display = 'block';
        }
    });
});
} catch (error) {
    console.log(error);
}

</script>