<?php 
defined('_FEXEC') or die();

// Determine item text based on quantity
$item = ($i > 1) ? ITEMS : ITEM;

// Define constants
define('MODULE_NAVBAR_SHOPPING_CART_CONTENTS', '<i class="bi bi-cart2"></i><span id="total_head_seats" class="d-inline d-sm-none d-md-inline ms-1">%1$s ' . $item . '</span>');
define('MODULE_NAVBAR_SHOPPING_CART_HAS_CONTENTS', '<span id="total_seats">%s ' . $item . ' %s</span>');
define('MODULE_NAVBAR_SHOPPING_CART_CHECKOUT', '<i class="bi bi-arrow-90deg-right me-1"></i>' . HEADER_TITLE_CHECKOUT);
define('MODULE_NAVBAR_SHOPPING_CART_PRODUCT', '<div class="indiv_ticket ticket_id_%s"><a href="' . tep_href_link('product_info.php', 'products_id=%s') . '"><span class="cnt">%s</span>&nbsp;x&nbsp;<span class="pn">%s</span><span class="pp d-none">%s</span></a><span class="top_category_name d-none">%s</span></div>');
?>

<li class="dropdown cart-dropdown">
  <a
    id="navDropdownCart"
    class="dropdown-toggle"
    href="<?php echo tep_href_link('shopping_cart.php'); ?>"
    role="button"
    data-bs-toggle="dropdown"
    aria-expanded="false"
  >
    <?php echo sprintf(MODULE_NAVBAR_SHOPPING_CART_CONTENTS, $cart->count_contents_gt()); ?>
  </a>

  <ul class="dropdown-menu dropdown-menu-end cart-menu" aria-labelledby="navDropdownCart">
    <li class="cart-summary">
      <a class="dropdown-item cart-summary-link" href="<?php echo tep_href_link('shopping_cart.php'); ?>">
        <?php echo sprintf(MODULE_NAVBAR_SHOPPING_CART_HAS_CONTENTS, $cart->count_contents_gt(), $currencies->format($cart->show_total())); ?>
      </a>
    </li>

    <li><hr class="dropdown-divider"></li>

    <li class="cart-items-wrap">
      <div class="ticket_list">
        <?php
        if ($cart->count_contents() > 0) {
          $products = $cart->get_products();
          foreach ($products as $k => $v) {
            if ($v['sku'] == 6) {
              $v['quantity'] = 1;
            }

            $tax_rate = tep_get_tax_rate($v['tax_class_id']);
            $products_price = tep_add_tax(tep_get_plain_products_price($v['final_price']), $tax_rate);

            echo sprintf(
              MODULE_NAVBAR_SHOPPING_CART_PRODUCT,
              $v['id'],
              $v['id'],
              $v['quantity'],
              $v['name'],
              $products_price,
              $v['top_category_name']
            );
          }
        } else {
          echo '<div class="px-3 py-2">' . TEXT_CART_EMPTY . '</div>';
        }
        ?>
      </div>
    </li>

    <li><hr class="dropdown-divider"></li>

    <li class="cart-footer text-end">
      <a class="dropdown-item cart-checkout-link" style="width: 150px" href="<?php echo tep_href_link('checkout_shipping.php', '', 'SSL'); ?>">
        <?php echo MODULE_NAVBAR_SHOPPING_CART_CHECKOUT; ?>
      </a>
    </li>
  </ul>

  <div id="ajax_status"></div>
</li>