<?php

/**
 * The Template for displaying all single products
 *
 * This template can be overridden by copying it to yourtheme/woocommerce/single-product.php.
 *
 * @see         https://docs.woocommerce.com/document/template-structure/
 * @package     WooCommerce\Templates
 * @version     1.6.4
 */

if (!defined('ABSPATH')) {
    exit; // Exit if accessed directly
}

// Check for 'bs' parameter in URL and sanitize
$layout = isset($_GET['bs']) ? sanitize_text_field($_GET['bs']) : glamer_options('glamer_single_shop_layout', 'right-sidebar');

// Determine the column class based on the layout
$column_class = ($layout === 'left-sidebar' || $layout === 'right-sidebar') ? 'col-12 col-sm-12 col-md-12 col-lg-7 col-xl-8' : 'col-12 col-sm-12 col-md-12 col-lg-12 col-xl-12';

get_header('single_shop');

do_action('woocommerce_before_main_content');
?>
<div class="page-layout woo-layout-single <?php echo esc_attr($layout); ?>">
    <div class="row">
        <?php if ($layout === 'left-sidebar' && is_active_sidebar('glamer-shop-single')) : ?>
            <div id="secondary" class="col-xl-4 col-lg-5 col-md-12 col-sm-12 col-12 sidebar-widget-area woo-widget-area">
                <?php dynamic_sidebar('glamer-shop-single'); ?>
            </div>
        <?php endif; ?>

        <div class="<?php echo esc_attr($column_class . ' gl-shop-wrapper'); ?>">
            <div class="all-posts-wrapper woo-single-post">
                <?php while (have_posts()) : the_post(); ?>
                    <?php wc_get_template_part('content', 'single-product'); ?>
                <?php endwhile; ?>
            </div>
        </div>

        <?php if ($layout === 'right-sidebar' && is_active_sidebar('glamer-shop-single')) : ?>
            <div id="secondary" class="col-xl-4 col-lg-5 col-md-12 col-sm-12 col-12 sidebar-widget-area woo-widget-area">
                <?php dynamic_sidebar('glamer-shop-single'); ?>
            </div>
        <?php endif; ?>
    </div>
</div>

<?php
do_action('woocommerce_after_main_content');
get_footer('single_shop');
