<?php
    $title = $title ?? '';
    $video_url = $video_url ?? '';
    $aspect_ratio = $aspect_ratio ?? '16:9';

    $embed_url = '';
    if (!empty($video_url)) {
        if (preg_match('%(?:youtube(?:-nocookie)?\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\.be/)([^"&?/ ]{11})%i', $video_url, $match)) {
            $embed_url = "https://www.youtube.com/embed/" . $match[1];
        } elseif (preg_match('%vimeo\.com/(?:channels/(?:\w+/)?|groups/([^/]*)/videos/|album/(\d+)/video/|video/|)(\d+)(?:$|[?&])%i', $video_url, $match)) {
            $embed_url = "https://player.vimeo.com/video/" . $match[3];
        } else {
            // Fallback to whatever URL was provided if it's already an embed URL
            $embed_url = $video_url;
        }
    }

    $aspect_class = match($aspect_ratio) {
        '4:3' => 'aspect-w-4 aspect-h-3',
        '1:1' => 'aspect-w-1 aspect-h-1',
        default => 'aspect-w-16 aspect-h-9',
    };
?>

<div class="bg-gray-100 py-16 border-b border-gray-200">
    <div class="max-w-4xl mx-auto px-4 sm:px-6 lg:px-8">
        <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if(!empty($title)): ?>
            <div class="text-center mb-8">
                <h2 class="text-2xl sm:text-3xl font-extrabold text-gray-900 tracking-tight"><?php echo e($title); ?></h2>
                <div class="mt-2 h-1 w-12 bg-indigo-650 mx-auto rounded-full"></div>
            </div>
        <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>

        <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if(!empty($embed_url)): ?>
            <div class="relative overflow-hidden rounded-2xl shadow-lg bg-black <?php echo e($aspect_class); ?>" style="aspect-ratio: <?php echo e(str_replace(':', '/', $aspect_ratio)); ?>">
                <iframe 
                    src="<?php echo e($embed_url); ?>" 
                    class="absolute inset-0 w-full h-full" 
                    frameborder="0" 
                    allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" 
                    allowfullscreen
                ></iframe>
            </div>
        <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
    </div>
</div>
<?php /**PATH C:\laragon\www\Sawdabazar\resources\views/storefront/blocks/video_embed.blade.php ENDPATH**/ ?>