<?php
/**
 * WooCommerce Template Wrapper
 *
 * @package shopbar
 */

defined( 'ABSPATH' ) || exit;

// For shop archive pages
if ( is_shop() || is_product_category() || is_product_tag() || is_post_type_archive( 'product' ) ) {
	include get_template_directory() . '/woocommerce/archive-product.php';
	return;
}

// For single product pages
if ( is_product() ) {
	include get_template_directory() . '/woocommerce/single-product.php';
	return;
}

// For all other WooCommerce pages
get_header();

// Build breadcrumb items for WooCommerce pages
$breadcrumb_items = array();
$breadcrumb_items[] = array( 'label' => __( 'Home', 'shopbar' ), 'url' => home_url( '/' ) );

if ( is_cart() ) {
	$breadcrumb_items[] = array( 'label' => __( 'Cart', 'shopbar' ), 'url' => '' );
} elseif ( is_checkout() ) {
	$breadcrumb_items[] = array( 'label' => __( 'Cart', 'shopbar' ), 'url' => wc_get_cart_url() );
	$breadcrumb_items[] = array( 'label' => __( 'Checkout', 'shopbar' ), 'url' => '' );
} elseif ( function_exists( 'is_wc_endpoint_url' ) && is_wc_endpoint_url( 'order-received' ) ) {
	$breadcrumb_items[] = array( 'label' => __( 'Cart', 'shopbar' ), 'url' => wc_get_cart_url() );
	$breadcrumb_items[] = array( 'label' => __( 'Checkout', 'shopbar' ), 'url' => wc_get_checkout_url() );
	$breadcrumb_items[] = array( 'label' => __( 'Order Received', 'shopbar' ), 'url' => '' );
} elseif ( is_account_page() ) {
	$breadcrumb_items[] = array( 'label' => __( 'My Account', 'shopbar' ), 'url' => '' );
} else {
	// Fallback for any other WooCommerce page
	$breadcrumb_items[] = array( 'label' => get_the_title(), 'url' => '' );
}
?>

<!-- Breadcrumbs -->
<div class="shop-breadcrumbs">
	<div class="container">
		<nav class="shop-breadcrumb-nav" aria-label="<?php esc_attr_e( 'Breadcrumb', 'shopbar' ); ?>">
			<?php foreach ( $breadcrumb_items as $i => $item ) : ?>
				<?php if ( ! empty( $item['url'] ) ) : ?>
					<a href="<?php echo esc_url( $item['url'] ); ?>"><?php echo esc_html( $item['label'] ); ?></a>
					<span class="shop-breadcrumb-sep">/</span>
				<?php else : ?>
					<span class="shop-breadcrumb-current"><?php echo esc_html( $item['label'] ); ?></span>
				<?php endif; ?>
			<?php endforeach; ?>
		</nav>
	</div>
</div>

<div class="container">
	<div id="primary" class="content-area">
		<main id="main" class="site-main" role="main">
			<div class="content-inner">
				<?php woocommerce_content(); ?>
			</div>
		</main>
	</div>
</div>

<?php
get_footer();
