<?php
/**
 * Single product content
 *
 * @see https://woocommerce.com/document/template-structure/
 * @package WooCommerce\Templates
 */

defined( 'ABSPATH' ) || exit;

global $product;

/**
 * Hook: woocommerce_before_single_product.
 *
 * @hooked woocommerce_output_all_notices - 10
 */
do_action( 'woocommerce_before_single_product' );

if ( post_password_required() ) {
    echo get_the_password_form(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
    return;
}

$enable_summary = get_theme_mod( 'enable_single_product_summary_section', 'on' );
$enable_about   = get_theme_mod( 'enable_product_about_section', 'on' );

$summary_class = 'col-xl-5';
$about_class   = 'col-xl-7';

if ( $enable_summary && ! $enable_about ) {
    $summary_class = 'col-xl-7';
} elseif ( ! $enable_summary && $enable_about ) {
    $about_class = 'col-xl-5';
}
?>

<div id="product-<?php the_ID(); ?>" <?php wc_product_class( '', $product ); ?>>
    <div class="row mt-5">

        <!-- PRODUCT IMAGES -->
        <div class="<?php echo esc_attr( $summary_class ); ?>">

            <?php
            $attachment_ids = $product->get_gallery_image_ids();

            if ( ! empty( $attachment_ids ) ) :
            ?>
                <div class="woo-product-big-img">
                    <?php foreach ( $attachment_ids as $attachment_id ) : ?>
                        <?php
                        $img_url = wp_get_attachment_image_url( $attachment_id, 'large' );
                        $alt     = get_post_meta( $attachment_id, '_wp_attachment_image_alt', true );
                        ?>
                        <div class="woo-spimg">
                            <a href="<?php echo esc_url( $img_url ); ?>">
                                <img src="<?php echo esc_url( $img_url ); ?>"
                                     alt="<?php echo esc_attr( $alt ? $alt : get_the_title() ); ?>">
                            </a>
                        </div>
                    <?php endforeach; ?>
                </div>

                <div class="woo-product-small-img">
                    <?php foreach ( $attachment_ids as $attachment_id ) : ?>
                        <?php
                        $thumb = wp_get_attachment_image_url( $attachment_id, 'thumbnail' );
                        $alt   = get_post_meta( $attachment_id, '_wp_attachment_image_alt', true );
                        ?>
                        <div class="woo-sspimg">
                            <img src="<?php echo esc_url( $thumb ); ?>"
                                 alt="<?php echo esc_attr( $alt ? $alt : get_the_title() ); ?>">
                        </div>
                    <?php endforeach; ?>
                </div>

            <?php else : ?>

                <?php the_post_thumbnail( 'large' ); ?>

            <?php endif; ?>

        </div>

        <!-- PRODUCT SUMMARY -->
        <div class="<?php echo esc_attr( $about_class ); ?>">
            <div class="product-about">
                <?php
                /**
                 * Hook: woocommerce_single_product_summary.
                 */
                do_action( 'woocommerce_single_product_summary' );
                ?>
            </div>
        </div>

        <!-- PRODUCT TABS / RELATED -->
        <div class="product-tab-area">
            <?php
            /**
             * Hook: woocommerce_after_single_product_summary.
             */
            do_action( 'woocommerce_after_single_product_summary' );
            ?>
        </div>

    </div>
</div>

<?php
/**
 * Hook: woocommerce_after_single_product.
 */
do_action( 'woocommerce_after_single_product' );
