<?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_title', 5);

echo "<style>
    .$product_type-layout {
        max-width: 1200px;
        margin: auto;
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 40px;
        background: #f5f5f5;
        border-radius: 10px;
    }
.cwpt-field label {
    color: #ffff;
}
    .$product_type-header {
        text-align: left;
        padding-bottom: 15px;
    }

    .$product_type-main {
        padding: 30px;
        background: #fff;
        border-radius: 10px;
        box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
    }

    .$product_type-sidebar {
        background: #333;
        color: #fff;
        padding: 30px;
        border-radius: 10px;
        position: sticky;
        top: 20px;
        text-align: left;
    }

    .$product_type-sidebar h3 {
        font-size: 24px;
        margin-bottom: 10px;
    }

    .$product_type-sidebar .$product_type-booking button {
        width: 100%;
        padding: 14px;
        font-size: 18px;
        border: none;
        background: #ff5500;
        color: #fff;
        cursor: pointer;
        border-radius: 5px;
        transition: 0.3s;
    }

    .$product_type-sidebar .$product_type-booking button:hover {
        background: #cc4400;
    }
    .$product_type-sidebar .price {
        font-size: 26px;
        font-weight: bold;
        margin-bottom: 10px;
    }
    .$product_type-sidebar .quantity {
        margin: 10px 0;
    }

    .$product_type-sidebar {
        text-align: center;
    }
    .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;
    }

    @media (max-width: 768px) {
        .$product_type-layout {
            grid-template-columns: 1fr;
        }
    }
</style>
";
wc_print_notices();

?>


<div class="<?php echo $product_type; ?>-layout">
    <div class="product <?php echo $product_type; ?>-main">
        <h1 class="<?php echo $product_type; ?>-title"><?php the_title(); ?></h1>
        <p class="<?php echo $product_type; ?>-meta"><?php echo $product->get_short_description(); ?></p>
        <div class="<?php echo $product_type; ?>-description">
            <?php woocommerce_output_product_data_tabs(); ?>
        </div>
    </div>
    <aside class="<?php echo $product_type; ?>-sidebar">
    <div class="<?php echo $product_type; ?>-images">
            <?php woocommerce_show_product_images(); ?>
        </div>

        <div class="<?php echo $product_type; ?>-booking">
            <?php do_action('woocommerce_single_product_summary'); ?>
        </div>
    </aside>
</div>

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

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