<?php

defined('ABSPATH') || exit;

// WooCommerce templates execute in the template loader's local scope and use its documented product global.
// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
global $product; // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- WooCommerce exposes the current product through this documented global.

$asuka_product_designer_product = $product;

if (! $asuka_product_designer_product instanceof WC_Product) {
    $asuka_product_designer_product = wc_get_product(get_the_ID());
}

if (! $asuka_product_designer_product instanceof WC_Product) {
    return;
}

$asuka_product_designer_integration = new \APD\WooCommerce\ProductIntegration();
$asuka_product_designer_payload = $asuka_product_designer_integration->getFullWidthTemplatePayload($asuka_product_designer_product);

get_header();

do_action('woocommerce_before_main_content');
?>
<?php while (have_posts()) : the_post(); ?>
    <?php do_action('woocommerce_before_single_product'); ?>

    <div id="product-<?php the_ID(); ?>" <?php wc_product_class('apd-single-product apd-single-product--full-width-template', $asuka_product_designer_product); ?>>
        <div class="apd-single-product__designer woocommerce-product-gallery woocommerce-product-gallery--with-images images">
            <?php
            $asuka_product_designer_integration->renderShellSwitcher(
                $asuka_product_designer_payload['shells'],
                $asuka_product_designer_payload['defaultKey'],
                'apd-product-gallery-replacement apd-product-gallery-replacement--template',
                __('Choose a variation to load the linked custom product designer.', 'asuka-product-designer')
            );
            ?>
        </div>

        <div class="summary entry-summary apd-single-product__summary">
            <?php do_action('woocommerce_single_product_summary'); ?>
        </div>

        <div class="woocommerce-tabs wc-tabs-wrapper apd-single-product__meta">
            <?php do_action('woocommerce_after_single_product_summary'); ?>
        </div>
    </div>

    <?php do_action('woocommerce_after_single_product'); ?>
<?php endwhile; ?>
<?php

do_action('woocommerce_after_main_content');
get_footer();
// phpcs:enable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
