<?php
ob_start();

do_action( 'woocommerce_before_mini_cart' );

if (WC()->cart->get_cart_contents_count() == 0) {
  if (Inoby_Config::categories_in_empty_cart()) {
    echo "<div class='empty-cart-wrapper'>";
    echo file_get_contents(INOBY_BASE_URI . '/assets/icons/empty-cart.svg');
    echo "<div class='text-wrapper'>";
    echo '<h3>'.__("Váš nákupný košík je prázdny", "inoby").'</h3>';
    echo '<p>'.__("Vyberte si niečo a naplňte svoj košík.", 'inoby').'</p>';
    echo "</div>";
    echo '<a href="'.get_permalink( wc_get_page_id( 'shop' ) ).'" class="button">'.__("Obchod", 'inoby').'</a>';
    echo "<div class='category-wrapper'>";
    $exclude_id = null;
    $uncategorized_slug = sanitize_title(_x("uncategorized", "slug", "woocommerce"));
    $exclude_id = get_term_by("slug", $uncategorized_slug, "product_cat")->term_id ?? 0;
    
      $product_categories = get_terms( 'product_cat', array(
        'hide_empty' => true,
        'number' => 8,
        'parent'  => 0,
        "exclude" => $exclude_id,
        'suppress_filters'  => true,
      ) );
      foreach( $product_categories as $category ) {
        echo "<div class='category-item'>";
        echo "<a href='" . get_term_link( $category ) . "'>";
        echo "<div class='img-wrp'>";
        echo wp_get_attachment_image(get_term_meta($category->term_id, "thumbnail_id", true), "o-2");
        echo "</div>";
        echo "<div class='category-name'>" . $category->name . "</div>";
        echo "</a>";
        echo "</div>";
      }
    echo "</div>";
    echo "</div>";
    
  } else {
    echo __("Košík je prázdny", "inoby");
  }
} else {
  wc_get_template("cart/cart.php", ["minicart" => true]);
}

$content = ob_get_clean();
$id = "cart-wrapper";

if (RC_ENABLED) {
  rc_get_template("global/popup.php", ["id" => $id, "content" => $content]);
}