<?php
require_once __DIR__ . "/../Febe.php";
$febe = new Febe;
$febe->setCurrentSubFolderLanguageCookie();
$lpType = !empty($_GET["intgrtn_lpType"]) ? $_GET["intgrtn_lpType"] : "";
function getRegistrationForm($lpType) {
    switch ($lpType) {
        case "1step":
            $formType = "one-step-signup.php";
            break;
        case "2steps":
            $formType = "two-steps-signup.php";
            break;
        case "3steps":
            $formType = "three-steps-signup.php";
            break;
        default:
            $formType = "two-steps-signup.php";
    }
    return __DIR__ . "/../common/" . $formType;
}
function getTrackingUrl(): string
{
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "https://server.4markets.net/api/v2/offers/tracking-domain");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, [
        "Referer: https://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'],
    ]);
    curl_setopt($ch, CURLOPT_TIMEOUT, 10);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
    $response = curl_exec($ch);
    $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);

    if ($httpCode != 200) {
        return "";
    }
    if (empty($response)) {
        return "";
    }

    $responseTrackingDomainJson = json_decode($response);

    if (empty($responseTrackingDomainJson)) {
        return "";
    }

    return $responseTrackingDomainJson->details->endpoint;
}

$trackingUrl = getTrackingUrl();
?>
<!DOCTYPE html>

<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">

    <title>Loading...</title>
    <base href="<?= $febe->getHref(); ?>">

    <link rel="preconnect" href="https://fonts.googleapis.com/">
    <link rel="preconnect" href="https://fonts.googleapis.com/" crossorigin="true">
    <link rel="stylesheet" href="css/fonts.css">
    <link rel="stylesheet" href="css/styles.css">
    <link rel="stylesheet" href="css/intgrtn.css">
