<?php
$hero_image = HERO_IMG;
$bgStyle = '';
$bgUrl = !empty(HERO_BG)
    ? HERO_BG
    : 'templates/webengine/assets/img/hero-bg.webp';
$overlayPercent = defined('HERO_BG_OVERLAY') ? (int)HERO_BG_OVERLAY : 50;
// Keep safe range
if ($overlayPercent < 0) $overlayPercent = 0;
if ($overlayPercent > 90) $overlayPercent = 90;

$opacity = $overlayPercent / 100;

if (HERO_BG_OVERLAY_ACCENT == 1) {
    $overlay = "rgba(var(--we-accent-rgb), $opacity)";
} else {
    $overlay = "rgba(0,0,0, $opacity)";
}

$bgStyle = "background-image: linear-gradient($overlay, $overlay), url('" . htmlspecialchars($bgUrl, ENT_QUOTES, 'UTF-8') . "');"
          . "background-size:cover;"
          . "background-repeat:no-repeat;"
          . "background-position:top center;";
?>
<section id="hero" class="hero d-flex align-items-center" style="<?= $bgStyle ?>">
    <div class="container d-flex flex-column" data-aos="zoom-out">
      <div class="row">
<div class="col-lg-7 d-flex flex-column justify-content-center pt-4 pt-lg-0 order-2 order-lg-1">
		<h1><?php echo TEXT_HERO_TITLE; ?></h1>
		<h3><?php echo TEXT_HERO_SUBTITLE; ?></h3>
	    <div class="d-flex">
        <a href="featured_categories.php" class="btn btn-hero--accent btn-lg"><?php echo TEXT_GET_TICKETS; ?></a>
		&nbsp;
		<a href="login.php" class="btn btn-hero--secondary btn-lg"><?php echo TEXT_LOGIN; ?></a>
        </div>
</div>
<div class="col-lg-5 order-1 order-lg-2">
<?php
// Get embed config
$embed_query = tep_db_query("
    SELECT configuration_value
    FROM " . TABLE_CONFIGURATION . "
    WHERE configuration_key = 'EMBED_VIDEO'
    LIMIT 1
");

$embed = tep_db_fetch_array($embed_query);
$embed_raw = trim($embed['configuration_value'] ?? '');

// Nothing set → do not show iframe
if ($embed_raw !== '' && strpos($embed_raw, '|') !== false) {

// Split type|value
list($type, $value) = explode('|', $embed_raw, 2);

$type  = trim($type);
$value = trim($value);

// ============================
// VIDEOCHAIN
// ============================
if ($type === 'videochain') {

    // Allow only safe slug characters
    $slug = preg_replace('/[^a-zA-Z0-9\-]/', '', $value);

    if ($slug !== '') {

        echo '<iframe
            src="https://www.videochainmaker.com/embed.php?slug=' . htmlspecialchars($slug) . '"
            style="width:100%;max-width:900px;aspect-ratio:16/10;border:0;border-radius:16px;overflow:hidden;"
            allow="autoplay; encrypted-media; picture-in-picture"
            allowfullscreen>
        </iframe>';
    }
}

// ============================
// YOUTUBE
// ============================
elseif ($type === 'youtube') {

    // Extract video ID from full URL or direct ID
    if (preg_match('/(?:v=|youtu\.be\/|embed\/)([a-zA-Z0-9_-]{11})/', $value, $m)) {
        $video_id = $m[1];
    } else {
        $video_id = preg_replace('/[^a-zA-Z0-9_-]/', '', $value);
    }

    if (!empty($video_id)) {

        echo '<iframe
            src="https://www.youtube.com/embed/' . htmlspecialchars($video_id) . '"
            style="width:100%;max-width:900px;aspect-ratio:16/9;border:0;border-radius:16px;overflow:hidden;"
            allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
            allowfullscreen>
        </iframe>';
    }
}

}
?>
</div>
  </div>
	  </div>
  </section><!-- End Hero -->
