<?php
require_once __DIR__ . "/Febe.php";
$febe = new Febe;
$queryString = "";
$language = !empty($_GET["intgrtn_language"]) ? $_GET["intgrtn_language"] : null;
$country = !empty($_GET["country"]) ? $_GET["country"] : null;
$ipCountryIso = $_SERVER['HTTP_PX_IPCOUNTRYISO'] ?? null;
if (!empty($_SERVER['QUERY_STRING'])) {
    $queryString = '?' . $_SERVER['QUERY_STRING'];
}

if ($language) {
    header('Location: ' . $febe->redirectByLanguage($language) . '/index.php' . $queryString);
    exit();
}
if ($country) {
    header('Location: ' . $febe->redirectByCountry($country) . '/index.php' . $queryString);
    exit();
}
if ($ipCountryIso) {
    header('Location: ' . $febe->redirectByIpCountryIso($ipCountryIso) . '/index.php' . $queryString);
    exit();
}

header('Location: ' . $febe->getFallbackLanguage() . '/index.php' . $queryString);
exit();