<?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
echo "<style>
    /* Udemy-Style Layout */
    .$product_type-layout {
        max-width: 1200px;
        margin: auto;
        padding: 20px;
    }

    /* Header Section */
    .$product_type-header {
        text-align: center;
        padding-bottom: 20px;
        border-bottom: 2px solid #ddd;
    }

    .$product_type-header h1 {
        font-size: 32px;
        font-weight: bold;
        margin-bottom: 5px;
    }


    /* Layout 1 Container */
    .$product_type-container {
        display: flex;
        flex-wrap: wrap;
        justify-content: space-between;
        margin-top: 20px;
    }

    /* Left Section - Layout 1 Content */
    .$product_type-main {
        flex: 2;
        padding: 20px;
    }

    .$product_type-main .$product_type-meta-info {
        display: flex;
        gap: 10px;
        font-size: 16px;
        margin-bottom: 15px;
        color: #777;
    }

    .$product_type-description {
        margin-top: 20px;
        padding: 20px;
        border-radius: 5px;
    }

    /* Fixed Sidebar */
    .$product_type-sidebar {
        flex: 1;
        padding: 20px;
        /* border-left: 1px solid #ddd; */
        background: #f9f9f9;
        position: sticky;
        top: 20px;
        height: auto;
        text-align: center;
    }


    .$product_type-sidebar .$product_type-video img {
        width: 100%;
        height: auto;
        border-radius: 5px;
    }

    /* Layout 1 Price */
    .$product_type-sidebar .price {
        font-size: 24px;
        color: #333;
        margin-bottom: 10px;
        margin: 10px 0;
    }

    .$product_type-sidebar .quantity {
        margin: 10px 0;
    }


 
    /* Enrollment Button */
    .$product_type-enrollment button {
        width: 100%;
        padding: 12px;
        font-size: 18px;
        font-weight: bold;
        border: none;
        background: #ff8800;
        color: #fff;
        cursor: pointer;
        border-radius: 5px;
    }
    .woocommerce div.$product_type-video 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-video 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-video 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-video div.images.woocommerce-product-gallery {
        position: relative;
    }

    .woocommerce .$product_type-layout .woocommerce-product-rating .star-rating {
    margin: auto;
    float: none;
}
    /* Responsive */
    @media (max-width: 768px) {
        .$product_type-container {
            flex-direction: column;
        }

        .$product_type-sidebar {
            position: relative;
            border-left: none;
            border-top: 2px solid #ddd;
            padding-top: 20px;
        }
    }
</style>

";

wc_print_notices();
?>

<div class="<?php echo $product_type; ?>-layout">

    <!-- Layout 1 Header -->
    <div class="<?php echo $product_type; ?>-header">
        <h1 class="<?php echo $product_type; ?>-title"><?php the_title(); ?></h1>
        <div class="woocommerce-product-rating">
            <?php woocommerce_template_single_rating(); ?>
            <?php if ($rating_count = $product->get_rating_count()) { ?>
                <span class="rating-count">(<?php echo $rating_count; ?> ratings)</span>
            <?php } ?>
        </div>
    </div>

    <div class="<?php echo $product_type; ?>-container">

        <!-- Layout 1 Content -->
        <div class="product <?php echo $product_type; ?>-main">

        <p class="<?php echo $product_type; ?>-meta"><?php echo $product->get_short_description(); ?></p>

            <!-- Product Tabs (Description, Curriculum, Reviews) -->
            <div class="<?php echo $product_type; ?>-description">
                <?php woocommerce_output_product_data_tabs(); ?>
            </div>

        </div>

        <!-- Fixed Sidebar (Pricing & Enrollment) -->
        <aside class="<?php echo $product_type; ?>-sidebar">
            <div class="<?php echo $product_type; ?>-video">
                <?php woocommerce_show_product_images(); ?>
            </div>

            <div class="<?php echo $product_type; ?>-enrollment">
                <?php
                remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_title', 5);

                // remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_rating', 10);
                // remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_price', 10);
                remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 20);
                // remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30);
                // remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_meta', 40);
                // remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_sharing', 50);
                // remove_action('woocommerce_single_product_summary', array('WC_Structured_Data', 'generate_product_data'), 60);
                do_action('woocommerce_single_product_summary');
                ?>
            </div>
        </aside>

    </div>

</div>

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

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