<?php
use Illuminate\Support\Facades\Event;
use  Mtc\Shop\Events\ItemAdminTabnavEvent;

?>
<ul class="tabnav el">
    <li class="<?= $_SERVER['SCRIPT_NAME'] == '/shop/admin/products/manage.products.php' ? 'selected' : '' ?>">
        <a href="/shop/admin/products/manage.products.php">Manage</a>
    </li>
    <?php
    if ((isset($_REQUEST['id']) && $_REQUEST['id'] > 0)) {
        ?>
        <li class="<?= $_SERVER['SCRIPT_NAME'] == '/shop/admin/products/item.php' ? 'selected' : '' ?>">
            <a href="/shop/admin/products/item.php?id=<?= $_REQUEST['id'] ?>">Item Details</a>
        </li>

        <li class="<?= $_SERVER['SCRIPT_NAME'] == '/shop/admin/products/images.php' ? 'selected' : ''?>">
            <a href="/shop/admin/products/images.php?id=<?= $_REQUEST['id'] ?>">Images</a>
        </li>

        <?php
        if (ITEMS_SIZES) {
            ?>
            <li class="<?= $_SERVER['SCRIPT_NAME'] == '/shop/admin/products/manage.sizes.php' ? 'selected' : '' ?>">
                <a href="/shop/admin/products/manage.sizes.php?id=<?= $_REQUEST['id'] ?>">Sizes</a>
            </li>
            <?php
        }
        if (defined('ITEM_INDIVIDUAL_DELIVERY_RATE_ENABLED') && (int)ITEM_INDIVIDUAL_DELIVERY_RATE_ENABLED === 1) {
            ?>
            <li class="<?= $_SERVER['SCRIPT_NAME'] == '/shop/admin/products/manage.delivery.php' ? 'selected' : '' ?>">
                <a href="/shop/admin/products/manage.delivery.php?id=<?= (int)$_REQUEST['id'] ?>">Delivery</a>
            </li>
            <?php
        }
    } else {
        ?>
        <li
            <?php
            if ($_SERVER['REQUEST_URI'] == '/shop/admin/products/item.php') {
                ?>
                class="selected"
                <?php
            }
            ?>
        >
            <a href="/shop/admin/products/item.php">Add</a>
        </li>
        <?php
    }
    if (empty($item)) {
        // Listing page doesn't have item
        $item = new Item();
    }

    if (isset($_REQUEST['id'])) {
        foreach (Event::dispatch(new ItemAdminTabnavEvent($item, $_REQUEST)) as $nav_item) {
            echo $nav_item;
        }
    }
    ?>
</ul>
