<?php

if (! isset($add_edit)) {
    $add_edit = 'Add';
}

//figure out what tab is active
$selected = ' selected ';
$selected_tab_members = '';
$selected_tab_member_add = '';
$selected_tab_member_update = '';

if (stristr($_SERVER['SCRIPT_NAME'], 'manage_members.php') !== false) {
    $selected_tab_members = $selected;
} elseif (stristr($_SERVER['SCRIPT_NAME'], 'manage_member.php') !== false) {
    if (isset($_REQUEST['id'])) {
        $selected_tab_member_update = $selected;
    } else {
        $selected_tab_member_add = $selected;
    }
}

?>

<ul class="tabnav el">
    <li class="<?= $selected_tab_members ?>">
        <a href="<?= route('admin-patients', [], false) ?>">Manage</a>
    </li>
    <li class="<?= $selected_tab_member_add ?>">
        <a href="/modules/Members/admin/manage_member.php">Add</a>
    </li>
    <?php

    if ($selected_tab_member_update) { ?>
        <li class="<?= $selected_tab_member_update ?>">
            <a href="/modules/Members/admin/manage_member.php?id=<?= clean_page($_REQUEST['id']) ?>">Update</a>
        </li>
    <?php }

    if (
        stristr($_SERVER['SCRIPT_NAME'], 'manage_member.php') !== false
        || stristr($_SERVER['SCRIPT_NAME'], 'view_member_threads.php') !== false
        || stristr($_SERVER['SCRIPT_NAME'], 'view_member_thread.php') !== false
    ) {
        $event = 'Members/Admin/MemberOpenTabNav';
    } else {
        $event = 'Members/Admin/MemberTabNav';
    }

    $menu_extra = \Illuminate\Support\Facades\Event::dispatch($event, filter_input(INPUT_GET, 'id'));

    foreach (array_filter($menu_extra) as $entry) {
        echo $entry;
    }
    ?>
</ul>
