<?php

/**
 * Site Menu Navigation
 *
 * @category Plugins
 * @package  Mtc_Site_Menu
 * @author   mtc. Martins Fridenbergs <martins.fridenbergs@mtcmedia.co.uk>
 */

namespace Mtc\Plugins\SiteMenu\Classes;

use Mtc\Plugins\SiteMenu\Classes\SiteMenu;

?>
<ul class="tabnav el">
    <?php

    $selected = '';
    $add_edit = 'Add';
    if ($_SERVER['SCRIPT_NAME'] == '/plugins/SiteMenu/admin/index.php') {
        $selected = ' class="selected"';
    }
    ?>
    <li <?= $selected ?>>
        <?php if (isset($_REQUEST['id'])) { ?>
            <?php $menu = SiteMenu::find((int) $_REQUEST['id']); ?>
            <?php if ($menu): ?>
                <a href="/plugins/SiteMenu/admin/index.php?id=<?= $menu->parent_id ?>">Manage</a>
            <?php else: ?>
                <a href="/plugins/SiteMenu/admin/index.php">Manage</a>
            <?php endif ?>
        <?php } elseif (isset($_REQUEST['parent_id'])) { ?>
            <a href="/plugins/SiteMenu/admin/index.php?id=<?= $_REQUEST['parent_id'] ?>">Manage</a>
        <?php } else { ?>
            <a href="/plugins/SiteMenu/admin/index.php">Manage</a>
        <?php } ?>
    </li>

    <?php

    $selected = '';
    if ($_SERVER['SCRIPT_NAME'] == '/plugins/SiteMenu/admin/edit.php') {
        $selected = ' class="selected"';
        $add_edit = 'Edit';
        if (isset($_REQUEST['parent_id'])) {
            $add_edit = 'Add';
        }
    }
    ?>
    <li <?= $selected ?>>
        <?php

        if (isset($_REQUEST['id'])) { ?>
            <a href="/plugins/SiteMenu/admin/edit.php?parent_id=<?= $_REQUEST['id'] ?>"><?= $add_edit ?></a>
            <?php } elseif (isset($_REQUEST['menu_id'])) {
            $menu = SiteMenu::find($_REQUEST['menu_id']);
            ?>
            <a href="/plugins/SiteMenu/admin/edit.php?parent_id=<?= $menu->parentMenu->id ?>"><?= $add_edit ?></a>
            <?php
        } else { ?>
            <a href="/plugins/SiteMenu/admin/edit.php"><?= $add_edit ?></a>
            <?php }
        ?>
    </li>

    <?php

    $selected = '';
    if ($_SERVER['SCRIPT_NAME'] === '/plugins/SiteMenu/admin/trash.php') {
        $selected = ' class="selected"';
    }
    ?>
    <li <?= $selected ?>>
        <a href="/plugins/SiteMenu/admin/trash.php">Restore Deleted Menu Entries</a>
    </li>
</ul>
