<?php
global $product;
$image_id = $product->get_image_id();
$image_url = wp_get_attachment_image_url($image_id, 'large');
$title = $product->get_name();
$description = apply_filters('the_content', $product->get_description());
$image = wp_get_attachment_image_src(get_post_thumbnail_id(), 'large');
$price_html = $product->get_price_html();
$orange_title   = get_field('orange_title', $product->get_id());
$promo_text     = get_field('promo_text', $product->get_id());
$product_icons  = get_field('product_icons', $product->get_id());

?>

    <div class="breadcrumb">
        <?php
        if (function_exists('woocommerce_breadcrumb')) {
            woocommerce_breadcrumb([
                'delimiter'   => ' / ',
                'wrap_before' => '<nav class="woocommerce-breadcrumb">',
                'wrap_after'  => '</nav>',
                'before'      => '',
                'after'       => '',
            ]);
        }
        ?>
    </div>

    <section class="product-highlight-block">
        <?php include('detox_single_product-css.php'); ?>
        <div class="container">
            <div class="product-wrap">
                <div class="product-image">
                    <?php if ( $product->is_on_sale() ){ ?>
                        <div class="product-sale-badge">SALE</div>
                    <?php } ?>

                    <img src="<?= esc_url($image_url); ?>" alt="<?= esc_attr($product->get_name()); ?>">
                </div>
                <div class="product-card">
                    <?php
                    $terms = get_the_terms( $product->get_id(), 'product_cat' );
                    if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) {
                        echo '<div class="product-category">' . esc_html( $terms[0]->name ) . '</div>';
                    }
                    ?>

                    <h1><?= esc_html($title); ?></h1>
                    <div class="product-description">
                        <?= $description; ?>
                    </div>

                    <?php if ($orange_title){ ?>
                        <div class="orange-title"><?= esc_html($orange_title); ?></div>
                    <?php } ?>

                    <div class="product-price"><?= $price_html; ?></div>

                    <div class="but-product-box">
                        <?php if ($promo_text){ ?>
                            <div class="product-promo">
                                <?= esc_html($promo_text); ?>
                            </div>
                        <?php } ?>
                        <form class="cart" action="<?= esc_url(get_permalink($product->get_id())); ?>" method="post" enctype="multipart/form-data">
                            <?php
                            woocommerce_quantity_input([
                                'min_value'   => 1,
                                'max_value'   => $product->get_max_purchase_quantity(),
                                'input_value' => 1,
                            ]);
                            ?>
                            <button type="submit" name="add-to-cart" value="<?= esc_attr($product->get_id()); ?>" class="button add-to-cart button_basic">
                                <?= esc_html($product->single_add_to_cart_text()); ?>
                            </button>
                        </form>
                    </div>

                    <?php if ($product_icons){ ?>
                        <div class="product-icons">
                            <?php foreach ($product_icons as $icon){ ?>
                                <div class="product-item">
                                    <img src="<?= esc_url($icon['icon']['url']); ?>" alt="<?= esc_attr($icon['icon']['alt']); ?>">
                                    <div class="product-item-title"><?= esc_html($icon['title']); ?></div>
                                </div>
                            <?php } ?>
                        </div>
                    <?php } ?>
                </div>
            </div>
        </div>
    </section>
<?php
$title     = get_field('title', 'option');
$shortcode = get_field('testimonials_shortcode', 'option');
?>

<?php if ( $title || $shortcode ){ ?>
    <section class="detox-testimonials">
        <?php include get_stylesheet_directory() . '/template-parts/blocks/detox_testimonials_block/detox_testimonials_block-css.php';?>
        <?php if ($title){ ?>
            <h2><?= esc_html($title); ?></h2>
        <?php } ?>

        <div class="testimonials-widget">
            <?= do_shortcode($shortcode); ?>
        </div>
    </section>
<?php } ?>