<?php
/**
 * Custom Single Product Template - Courses (Udemy Style)
 *
 * Overrides WooCommerce single product layout for <?php echo $product_type; ?>s.
 */

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

get_header('shop');

do_action('woocommerce_before_main_content');

global $product;
if (!$product || !is_a($product, 'WC_Product')) {
    $product = wc_get_product(get_the_ID());
}

$product_type = esc_attr($product->get_type());
?>
		<?php while ( have_posts() ) : ?>
			<?php the_post(); ?>
<?php

remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_price', 10);
remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_title', 5);
remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 20);

echo "<style>
    /* Dynamic Amazon-Style Layout */
    .$product_type-layout {
        margin: auto;
        display: grid;
        grid-template-columns: 40% 30% 30%;
        gap: 30px;
        background: #fff;
    }

    .$product_type-images {
        display: flex;
        flex-direction: column;
    }

    .$product_type-data {
        padding: 20px;
    }

    .$product_type-summary {
        background: #f7f7f7;
        padding: 20px;
        border-radius: 5px;
        position: sticky;
        top: 20px;
        text-align: center;
    }

    .$product_type-data .price {
        font-size: 24px;
        font-weight: bold;
        margin-bottom: 10px;
    }

    .$product_type-summary .add-to-cart button {
        width: 100%;
        padding: 12px;
        font-size: 18px;
        border: none;
        background: #FF9900;
        color: #fff;
        cursor: pointer;
        border-radius: 5px;
        transition: 0.3s;
    }
    .$product_type-summary .add-to-cart button:hover {
        background: #CC7700;
    }

    .product-highlights {
        margin-top: 20px;
    }

    .product-highlights ul {
        list-style: disc;
        padding-left: 20px;
    }
    .$product_type-summary .quantity {
        margin-bottom: 10px;
    }

    @media (max-width: 768px) {
        .$product_type-layout {
            grid-template-columns: 1fr;
        }
    }
    .woocommerce div.$product_type-images div.images .woocommerce-product-gallery__trigger {
        position: absolute;
        top: .5em;
        left: .5em;
        font-size: 2em;
        z-index: 9;
        width: 36px;
        height: 36px;
        background: #fff;
        text-indent: -9999px;
        border-radius: 100%;
        box-sizing: content-box;
    }

    .woocommerce div.$product_type-images div.images .woocommerce-product-gallery__trigger::before {
        content: '';
        display: block;
        width: 10px;
        height: 10px;
        border: 2px solid #000;
        border-radius: 100%;
        position: absolute;
        top: 9px;
        right: 9px;
        box-sizing: content-box;
    }

    .woocommerce div.$product_type-images div.images .woocommerce-product-gallery__trigger::after {
        content: '';
        display: block;
        width: 2px;
        height: 8px;
        background: #000;
        border-radius: 6px;
        position: absolute;
        top: 19px;
        right: 22px;
        transform: rotate(45deg);
        box-sizing: content-box;
    }

    .woocommerce div.$product_type-images div.images.woocommerce-product-gallery {
        position: relative;
    }

</style>
";
wc_print_notices();

?>


<div class="<?php echo $product_type ?>-layout">
    <div class="<?php echo $product_type ?>-images">
        <?php woocommerce_show_product_images(); ?>
    </div>
    <div class="<?php echo $product_type ?>-data">
    <h1 class="product-title"><?php the_title(); ?></h1>

        <div class="woocommerce-product-rating">
            <?php woocommerce_template_single_rating(); ?>
        </div>
        <div class="product-highlights">
            <p class="price"> <?php echo $product->get_price_html(); ?></p>
            <?php echo nl2br($product->get_short_description()); ?>
        </div>
    </div>
    <aside class="<?php echo $product_type ?>-summary">
        <div class="add-to-cart">
            <?php do_action('woocommerce_single_product_summary'); ?>
        </div>
    </aside>

</div>
<div class="product product-tabs">
    <?php woocommerce_output_product_data_tabs(); ?>
</div>

<?php woocommerce_output_related_products(); ?>
<?php endwhile; // end of the loop. ?>

<?php
do_action('woocommerce_after_main_content');
get_footer('shop');
?>