<?php
// Map each WhatsApp subdomain to its number (international format, no +, no spaces)
$numbers = [
	'wa.22sim.com'   => '447988541235',
	'whatsapp.22sim.com'   => '447988541235',
    'wa.vpn.app'     => '447988541235',
    'wa.22calls.com' => '447988541235'
];

// Optional: a default prefilled message per brand
$messages = [
	'wa.22sim.com' => 'Hello 22SIM, I need help with my eSIM.',
	'whatsapp.22sim.com' => 'Hello 22SIM, I need help with my eSIM.',
    'wa.vpn.app'   => 'Hello, I need help with 22VPN.',
];

$host = strtolower($_SERVER['HTTP_HOST'] ?? '');

if (!isset($numbers[$host])) {
    http_response_code(404);
    exit('Unknown WhatsApp endpoint.');
}

$number = $numbers[$host];

// Allow ?text=... to override, else use the per-brand default if set
$text = $_GET['text'] ?? ($messages[$host] ?? '');

$url = 'https://wa.me/' . $number;
if ($text !== '') {
    $url .= '?text=' . rawurlencode($text);
}

header('Location: ' . $url, true, 302);
exit;
