<?php

/**
 * Tab template (style 1)
 *
 * @package storzen
 */

if (! defined('ABSPATH')) {
    exit;
}

if ($settings['style'] == 'style-1') :

?>
    <!-- Shop Section Start -->
    <section class="shop-section fix section-padding pt-0">
        <div class="wco-container">
            <div class="custom-tabs">

                <ul class="tab-buttons <?php echo esc_attr($settings['tab_alignment']); ?>">
                    <?php
                    if (is_array($settings['select_cat'])) :
                        $storzen_i = 1;
                        foreach ($settings['select_cat'] as $term) :
                    ?>
                            <li class="tab-btn <?php echo ($storzen_i == 1 ? 'active' : ''); ?>" data-tab="tab<?php echo esc_attr($storzen_i); ?>">
                                <?php echo esc_html(storzen_get_cat_name($term)); ?>
                            </li>
                    <?php $storzen_i++;
                        endforeach;
                    endif; ?>
                </ul>

                <div class="tab-content">
                    <?php
                    $storzen_i = 1;
                    if (is_array($settings['select_cat'])) :

                        foreach ($settings['select_cat'] as $term) :
                    ?>
                            <div class="tab <?php echo ($storzen_i == 1 ? 'active' : ''); ?>" id="tab<?php echo esc_attr($storzen_i); ?>">
                                <div class="wco-row wco-g-4">
                                    <?php
                                    $storzen_args = array(
                                        'post_type'           => 'product',
                                        'post_status'         => 'publish',
                                        'ignore_sticky_posts' => 1,
                                        'posts_per_page'      => $settings['ppr'],
                                    );

                                    $storzen_args['orderby'] = $settings['orderby'];
                                    $storzen_args['order']   = $settings['order'];


                                    $storzen_args['tax_query'][] = array(
                                        'taxonomy' => 'product_cat',
                                        'field'    => 'term_id',
                                        'terms'    => $term,
                                        'operator' => 'IN',
                                    );

                                    if (!empty($settings['exclude_cat'])) {
                                        $storzen_args['tax_query'][] = array(
                                            'taxonomy' => 'product_cat',
                                            'field'    => 'id',
                                            'terms'    => array_values($settings['exclude_cat']),
                                            'operator' => 'NOT IN'
                                        );
                                    }

                                    $storzen_posts_query = new \WP_Query($storzen_args);

                                    if ($storzen_posts_query->have_posts()) :
                                        while ($storzen_posts_query->have_posts()) : $storzen_posts_query->the_post();
                                            $storzen_img_src = wp_get_attachment_image_src(get_post_thumbnail_id(), 'full');
                                            global $product;

                                            // Initialize regular_price variable
                                            $storzen_regular_price = '';
                                            if ($product) {
                                                $storzen_regular_price = $product->get_regular_price();
                                            }

                                    ?>
                                            <div class="wco-col-xl-3 wco-col-lg-4 wco-col-sm-6">
                                                <div class="shop-card-items mt-0">
                                                    <div class="image">
                                                        <div class="badges">
                                                        <?php do_action( 'storzen_shop_card_badges', $product ); ?>
								</div>
                                                        <?php the_post_thumbnail('storzen_255x283'); ?>
                                                        <div class="social-style-two">
                                                            <?php echo storzen_add_to_cart_button(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- storzen_add_to_cart_button() returns markup already escaped with esc_url/esc_attr/wc_implode_html_attributes. ?>
                                                            <?php do_action( 'storzen_shop_card_overlay', $product ); ?>
                                                        </div>
                                                    </div>
                                                    <div class="content">
                                                        <a href="#" class="category"><?php echo esc_html(storzen_get_cat_name($term)); ?></a>
                                                        <<?php echo esc_attr($settings['titltag']); ?>>
                                                            <a <?php echo esc_attr(('new-window' == $settings['open-url'] ? 'target="_blank"' : '')); ?> href="<?php the_permalink(); ?>" class="woo-title">
                                                                <?php
                                                                if ('full' == $settings['dtitle']) :

                                                                    the_title();

                                                                else :
                                                                    echo esc_html(wp_trim_words(get_the_title(), $settings['title_excerpt_length'], ''));
                                                                endif;
                                                                ?>
                                                            </a>
                                                        </<?php echo esc_attr($settings['titltag']); ?>>
                                                        <div class="prices"><?php echo wp_kses_post($product->get_price_html()); ?></div>
								<?php do_action( 'storzen_shop_card_after_title', $product ); ?>
                                                    </div>
                                                </div>
                                            </div>
                                    <?php endwhile;
                                    endif; ?>
                                </div>
                            </div>
                        <?php $storzen_i++;
                        endforeach;
                    else : ?>
                        <h3><?php echo esc_html__('Please Select A Category', 'storzen'); ?></h3>
                    <?php endif;  ?>
                </div>

            </div>
        </div>
    </section>
<?php endif;
