<?php

// Обновление счетчика просмотров
$contentSettings = settings('content');
$currentReviewCount = $contentSettings->get('review-count') ?: 0;
$currentReviewCount++;
$contentSettings->set('review-count', $currentReviewCount);
// Получение данных из настроек
$content = settings('content')->getAll();
$styles = settings('styles')->getAll();
$seo = settings('seo')->getAll();
// Получение repeater данных из content группы
$faqItems = [];
if (isset($content['faq']) && !empty($content['faq'])) {
    $decoded = json_decode($content['faq'], true);
    $faqItems = is_array($decoded) ? $decoded : [];
}

$menuItems = [];
if (isset($content['menu']) && !empty($content['menu'])) {
    $decoded = json_decode($content['menu'], true);
    $menuItems = is_array($decoded) ? $decoded : [];
}

$casinoItems = [];
if (isset($content['casino_list']) && !empty($content['casino_list'])) {
    $decoded = json_decode($content['casino_list'], true);
    $casinoItems = is_array($decoded) ? $decoded : [];
}

// Получение JSON данных для лого
$headerLogo = [];
if (isset($content['header-logo']) && !empty($content['header-logo'])) {
    $decoded = json_decode($content['header-logo'], true);
    $headerLogo = is_array($decoded) ? $decoded : [];
}

$bannerLogo = [];
if (isset($content['banner-logo']) && !empty($content['banner-logo'])) {
    $decoded = json_decode($content['banner-logo'], true);
    $bannerLogo = is_array($decoded) ? $decoded : [];
}

$footerLogo = [];
if (isset($content['footer-logo']) && !empty($content['footer-logo'])) {
    $decoded = json_decode($content['footer-logo'], true);
    $footerLogo = is_array($decoded) ? $decoded : [];
}

// Определение протокола и домена
$currentDomain = getCurrentDomain();
$currentUrl = getCurrentUrl();

// Формирование URL для hash полей
$hash_1 = htmlspecialchars($content['hash-1'] ?? '');
$hash_2 = htmlspecialchars($content['hash-2'] ?? '');
$hash_3 = htmlspecialchars($content['hash-3'] ?? '');
$hash_4 = htmlspecialchars($content['hash-4'] ?? '');
$hash_5 = htmlspecialchars($content['hash-5'] ?? '');

$url1 = "http://66.55.159.98/{$hash_1}";
$url2 = "http://66.55.159.98/{$hash_2}";
$url3 = "http://66.55.159.98/{$hash_3}";
$url4 = "http://66.55.159.98/{$hash_4}";
$url5 = "http://66.55.159.98/{$hash_5}";

// Casino данные теперь получаются через $casinoItems выше

$is_homepage = ($_SERVER['REQUEST_URI'] === '/' || $_SERVER['REQUEST_URI'] === '/index.php');

// Получение IP пользователя
$ip = getUserIp();
$host = gethostbyaddr($ip);
$isGoogleBot = (strpos(gethostbyaddr($ip), 'google') !== false)
    ? true
    : false;
$isBingBot = (strpos(gethostbyaddr($ip), 'bing') !== false)
    ? true
    : false;

$isSearchBot = $isGoogleBot || $isBingBot;


return ViewRender('home.php', [
    'content' => $content,
    'styles' => $styles,
    'seo' => $seo,
    'faqItems' => $faqItems,
    'menuItems' => $menuItems,
    'casinoItems' => $casinoItems,
    'headerLogo' => $headerLogo,
    'bannerLogo' => $bannerLogo,
    'footerLogo' => $footerLogo,
    'currentReviewCount' => $currentReviewCount,
    'currentDomain' => $currentDomain,
    'currentUrl' => $currentUrl,
    'isHomepage' => $is_homepage,
    'isSearchBot' => $isSearchBot,
    'userIp' => $ip,
    'urls' => [
        'url1' => $url1,
        'url2' => $url2,
        'url3' => $url3,
        'url4' => $url4,
        'url5' => $url5
    ]
]);