<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<title>Crack the Fortune Cookie </title>
	<link rel="icon" href="favicon.png">
	<!-- CSS FILES -->

	<base href="https://fortunecookie.luckylongfu.com/fortunecookie/">
	<link rel="stylesheet" type="text/css" href="assets/uikit-3.24.2/css/uikit.min.css">
	
	<link rel="preconnect" href="https://fonts.googleapis.com">
	<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
	<link href="https://fonts.googleapis.com/css2?family=Sofia+Sans:ital,wght@0,1..1000;1,1..1000&display=swap" rel="stylesheet">

	<?php

	$language = isset($_GET['lang']) ? $_GET['lang'] : '';
	 if ($language == 'vn') { ?>
		<link rel="preconnect" href="https://fonts.googleapis.com">
		<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
		<link href="https://fonts.googleapis.com/css2?family=Noto+Sans:ital,wght@0,100..900;1,100..900&family=Noto+Serif+Thai:wght@100..900&display=swap" rel="stylesheet">

	<?php } ?>

	<script>

		var init = {};
		var siteContent = {};

	</script>


	<script src="assets/language/cn.js?a11"></script>
	<script src="assets/language/en.js?a11"></script>
	<script src="assets/language/id.js?a11"></script>
	<script src="assets/language/my.js?a11"></script>
	<script src="assets/language/th.js?a11"></script>
	<script src="assets/language/vn.js?a11"></script>

	<script>

		// deep merge language content
		function deepMerge(a, b) {
			const result = { ...a };

			for (const key in b) {
				// If both sides are plain objects → merge deeper
				if (
						typeof b[key] === "object" &&
						b[key] !== null &&
						!Array.isArray(b[key]) &&
						typeof a[key] === "object" &&
						!Array.isArray(a[key])
					) {
					result[key] = deepMerge(a[key], b[key]);
				}

				// If array → overwrite or merge depending on your preference
				else if (Array.isArray(b[key])) {
					result[key] = [...b[key]]; // overwrite array completely
				}
				else {
					result[key] = b[key];
				}
			}

			return result;
		}

		// ES6 async function to detect country and language
		const detectCountryAndLanguage = async () => {
			try {
				const response = await fetch('https://ipapi.co/json/');
				if (!response.ok) throw new Error('Failed to fetch IP info');

				const data = await response.json();
				const country = data.country_name;   // Country name
				const countryCode = data.country;    // Country code (ISO)
				const language = navigator.language || navigator.userLanguage; // Browser language

				console.log(`Country: ${country} (${countryCode})`);
				console.log(`Language: ${language}`);

				return { country, countryCode, language };
			} catch (error) {
				console.error('Error detecting country and language:', error);
				return null;
			}
		};


		const currencyToCountry = (currency) => {
			const countries = {
				// 'usd': 'th',
				'thb': 'th',
				'vnd': 'vn',
				'myr': 'my',
				'idr': 'id',
				'sgd': 'sg',
				// 'cn': 'cn',
			}
			return countries[currency] || 'th';
		}
		const countryToCurrency = (country) => {
		  const currencies = {
		    'th': 'thb',
		    'vn': 'vnd',
		    'my': 'myr',
		    'id': 'idr',
		    'sg': 'sgd',
		  };
		  
		  // Returns the currency, or 'thb' as a default if not found
		  return currencies[country.toLowerCase()] || 'thb';
		};

		// Get current URL parameters
		const params = new URLSearchParams(window.location.search);
		// usage
		// const lang = params.get('lang') || 'en';       // default to 'en' if missing

		// const USER_CURRENCY = $_GETparams.get('currency') || 'myr';
		// const USER_LANGUAGE = params.get('lang') || 'en';

		<?php

		$_USER_LANGUAGE = isset($_GET['lang']) ? $_GET['lang'] : 'en';
		$_USER_CURRENCY = isset($_GET['currency']) ? $_GET['currency'] : '';


		?>
		// const USER_CURRENCY = '<?php echo $_USER_CURRENCY;?>';
		const USER_LANGUAGE = '<?php echo $_USER_LANGUAGE;?>';

		// 2. Use the param if it exists, otherwise derive it from the language code
		const USER_CURRENCY = '<?php echo $_USER_CURRENCY;?>' || countryToCurrency(USER_LANGUAGE);
		


		const USER_COUNTRY = currencyToCountry(USER_CURRENCY);


		console.log('currency', params.get('currency') );
		console.log('lang', params.get('lang') );

	</script>

	<link rel="stylesheet" type="text/css" href="assets/css/styles.css">
	<style type="text/css">


		<?php if ($_GET['lang'] == 'vn') { ?>

		html, body { font-family: "Noto Sans", sans-serif;  }
		.font-light { font-family: "Noto Sans", sans-serif;}
		.font-regular { font-family: "Noto Sans", sans-serif;}
		.font-medium { font-family: "Noto Sans", sans-serif;}
		.font-bold {font-family: "Noto Sans", sans-serif;}

		<?php } ?>

	</style>

<script>


init.site = {

	"language": "English",
	"language_code": "en",
	
	"images": {
		"thumbnail": "thumbnail.jpg",
		"promo_banner": "promo-banner.jpg",
		"teaser_main": "teaser_banner.jpg",
		"teaser_bg": "teaser_bg.jpg"
	},

	"promo": {
		"title": "200% up to %__USD_10__% + 60 FS +1 bonus crab xx",
		"description": "<s>100% up to </s><b>%__USD_12__%</b> + 60 FS +12 bonus crab",
		"cta": [
			{
				"text": "Claim %__USD_12__%",
				"link": "#link-1"
			},
			// {
			// 	"text": "cta 2",
			// 	"link": "#link-2"
			// },
		]
	},

	
	"teaser": [{
		"title": "Promo Title",
		"description": "Promo Description",
		"cta": "Join Now!",
	}],

	"tnc": {
		"title": "Terms and ConditionsNEW",
		"show_more": "Show more",
		"show_less": "Show less",
	},

	"section": {
		"title": "Rewards",
		"cards": [
			{
				"title": "xChallenges",
				"description": "1,500 Coins!",
				"link": "#card-1",
				"size": "uk-width-1-2 ",
				"image": "assets/img/challenge-icon.png",
				"image_desktop": "assets/img/challenge-desktop-icon.png",
			},
			{
				"title": "xWheel of Fortune",
				"description": "30,000RM rewards!",
				"link": "#card-2",
				"size": "uk-width-1-2 ",
				"image": "assets/img/wheel-offortune-icon.png",
				"image_desktop": "assets/img/wheel-offortune-desktop.png",
			},
			{
				"title": "xTournaments",
				"description": "Win 200,000,000RM!",
				"link": "#card-3",
				"size": "uk-width-1-3@m uk-width-1-1",
				"image": "assets/img/tournaments-icon.png",
				"image_desktop": "assets/img/tournaments-icon-desktop.png",
			},
			{
				"title": "xBonus Crab",
				"description": "Grab 800,000RM!",
				"link": "#card-4",
				"size": "uk-width-1-3@m uk-width-1-2",
				"image": "assets/img/bonus-crab-icon.png",
				"image_desktop": "assets/img/bonus-crab-icon-desktop.png",
			},
			{
				"title": "xCollections",
				"description": "Claim 35,000RM!",
				"link": "#card-5",
				"size": "uk-width-1-3@m uk-width-1-2",
				"image": "assets/img/collections-icon.png",
				"image_desktop": "assets/img/collections-icon-desktop.png",
			},
		]
	},

	"footer": {
		"dark-buttons": [
			{
				"attr": "uk-toggle",
				"icon": "assets/img/en.png",
				"link": "#language",
				"text": "English",
			},
			{
				"attr": " uk-toggle new-list",
				"link": "#help",
				"icon": "assets/img/icon-view-box.svg",
				"text": "Help Centre",
			},
			{
				"attr": " uk-toggle new-list",
				"link": "#help",
				"icon": "assets/img/icon-view-box.svg",
				"text": "Help Centre",
			},
			
		],
		"links": [
			{
				"text": "Home",
				"link": "#Home",
			},
			{
				"text": "Casino",
				"link": "#Casino",
			},
			{
				"text": "Live Casino",
				"link": "#Live-Casino",
			},
			{
				"text": "Fishing",
				"link": "#Fishing",
			},
			/** {
				"text": "Jackpots",
				"link": "#Jackpots",
			},
			{
				"text": "P2P",
				"link": "#P2P",
			},
			{
				"text": "Fast Games",
				"link": "#Fast-Games",
			},
			{
				"text": "Sports",
				"link": "#Sports",
			},
			{
				"text": "Lottery",
				"link": "#Lottery",
			}, **/
		],
		"payments": [
			{
				"code": "visa",
				"icon": "assets/img/visa-icon.svg",
			},
			{
				"code": "master",
				"icon": "assets/img/mastercard-icon.png",
			},
			{
				"code": "ecopayz",
				"icon": "assets/img/ecopayz.svg",
			},
			{
				"code": "astropay",
				"icon": "assets/img/astropay.svg",
			},

		],
		"captions": {
			"license": "License",
			"payment_more": "More payment",
			"game_addition": "Gambling can be addictive. Play responsibly. LONGFU88.com accepts customers only over 18 years of age.",
			"copyright": "2019-2021 © LONGFU88.com All rights reserved. "
		},

	}
}


// apply user language selection
init.site = siteContent[USER_LANGUAGE];

// init.site.terms_and_condition = `
// 	<li>This offer is available for XX hours, expiring at the stated time on ‘My Bonuses’ section</li>
// 	<li>Reload Bonus is 200% up to %__USD_30__%</li>
// 	<li>Reload Bonus minimum deposit: %__USD_10__%</li>
// 	<li>Reload Bonus wagering requirements: 30x deposit + bonus</li>
// 	<li>Maximum bet: %__USD_5__%</li>
// 	<li>Bonus will be credited automatically once activated from ‘My Bonuses’ section</li>
// 	<li>Reload Bonus wagering requirements must be met within the ‘Expiration Date’ stated on the bonus</li>
// 	<li><a href="#">General terms and conditions apply</a></li>
// 	<li>18+ Eligible Players only</li>
// `;

init.site.currency = {

	"usd": {
		"text": "USD",
		"symbol": "$",
		"caption": "%__{SYMBOL}__%%__{AMOUNT}__%", // $10 - result
	},
	"cny": {
		"text": "CNY",
		"symbol": "¥",
		"caption": "%__{AMOUNT}__%%__{SYMBOL}__%", // 10 CNY - result
	},
	"thb": {
		"text": "THB",
		"symbol": "฿",
		"caption": "%__{TEXT}__% %__{AMOUNT}__%", // 10 CNY - result
	},
	"vnd": {
		"text": "VND",
		"symbol": "₫",
		"caption": "%__{TEXT}__% %__{AMOUNT}__%", // 10 CNY - result
	},
	"myr": {
		"text": "MYR",
		"symbol": "RM",
		"caption": "%__{TEXT}__% %__{AMOUNT}__%", // 10 CNY - result
	},
	"idr": {
		"text": "IDR",
		"symbol": "Rp",
		"caption": "%__{TEXT}__% %__{AMOUNT}__%", // 10 CNY - result
	},
	"sgd": {
		"text": "SGD",
		"symbol": "$",
		"caption": "%__{TEXT}__% %__{AMOUNT}__%", // 10 CNY - result
	},
}

// currency table
//

init.site.currency_table = {

	"USD_3": {
		"amount": 3,
		"currency": "usd",
		"convert": {
			"thb": 97.23,
			"vnd": '79,131',
			"myr": 12.45,
			"idr": '50,166',
			"sgd": 3.912,
		}
	},
	"USD_5": {
		"amount": 5,
		"currency": "usd",
		"convert": {
			"thb": 162.05,
			"vnd": '131,885',
			"myr": 20.75,
			"idr": 83610,
			"sgd": 6.52,
		}
	},
	"USD_10": {
		"amount": 10,
		"currency": "usd",
		"convert": {
			"thb": 324.1,
			"vnd": '263,770',
			"myr": 41.5,
			"idr": '167,220',
			"sgd": 13.04,
		}
	},
	"USD_12": {
		"amount": 12,
		"currency": "usd",
		"convert": {
			"thb": 388.92,
			"vnd": '316,524',
			"myr": 49.8,
			"idr": '200,664',
			"sgd": 15.648,
		}
	},
	"USD_30": {
		"amount": 30,
		"currency": "usd",
		"convert": {
			"thb": 388.92,
			"vnd": '316,524',
			"myr": 49.8,
			"idr": '200,664',
			"sgd": 15.648,
		}
	},
	"USD_720": {
		"amount": 720,
		"currency": "usd",
		"convert": {
			"thb": '23,335.2',
			"vnd": '18,991,440',
			"myr": '2,988',
			"idr": '12,039,840',
			"sgd": 938.88,
		}
	},
	

}

</script>
</head>
<body>

	<header>
		<div class="uk-container">

			<nav id="navbar" uk-navbar>
				<div class="uk-navbar-left">
					<a class="uk-navbar-item uk-logo" href="https://fortunecookie2-my.luckylongfu.com/" title="Logo"><img src="assets/img/logo.svg" alt="Logo"></a>
				</div>

				<div class="uk-navbar-right nav-overlay">
					
					<ul class="uk-navbar-nav">
						<li>
							<a class="uk-button uk-button-default" href="#modal-language" uk-toggle>
								<img src="assets/img/en.png" class="user-flag"> <span class="user-lang">EN</span>
							</a>
						</li>
			        </ul>

				</div>
			</nav>

			</div>
		</div>
	</header>

	<section class="uk-section" id="promo-banner">
		<div class="uk-container" uk-parallax="bgy: -100" style="background-image: url('promo/landing-page-banner.png');">
			
		</div>

	</section>

	<section class="uk-section" id="promo-content">
		<div class="uk-container uk-container-small " uk-scrollspy="target: > h2, > h1, > div ; cls: uk-animation-slide-top-medium; delay: 200">
			<h1 data-text="promo[title]" class="uk-text-uppercase">Promo Description</h1>
			<h2 data-text="promo[description]">Promo Title</h2>

			<div class="primary-cta">
				<div><a href="#modal-result" class="button primary" data-text="promo[primary]" uk-toggle>TEST</a></div>
			</div>
		</div>
	</section>

	<section class="uk-section" id="tnc_container">
		<div class="uk-container uk-container-small" uk-scrollspy="target: > h3, > div ; cls: uk-animation-slide-top-medium; delay: 200">
			<h3 class="uk-text-center" data-text="tnc[title]">Terms & Conditions</h3>


			<div id="terms-and-conditions" class="uk-container uk-container-xsmall uk-overflow-hidden uk-position-relative">
				<ol class="uk-list uk-list-decimal uk-margin-remove tnc-content" data-text="terms_and_condition" >
					<li><a href="#">General terms and conditions apply</a></li>
					<li>18+ Eligible Players only</li>
				</ol>
				<div class="fade-overlay"></div>
			</div>


			<div class="uk-text-center uk-margin-small-top">
    			<span id="show_tnc" class="uk-text-bold uk-link-toggle" href="#" uk-toggle="target: #show_tnc .show_more, #show_tnc .show_less; cls: uk-hidden;">

      				<span data-text="tnc[show_more]" class="show_more">more</span>
      				<span data-text="tnc[show_less]" class="show_less uk-hidden">less</span>
      				<img src="assets/img/arrows.svg">
    			</span>
  			</div>

		</div>
	</section>
	
	<section class="uk-section uk-padding-remove-bottom  uk-hidden" id="blocks" uk-parallax="y: -10, 0">
		<div class="uk-container">
			<h3 class="uk-text-italic" data-text="section[title]">Section</h3>

			<div class="uk-position-relative uk-child-width-1-3 uk-grid-small block-container" data-text="section[cards]" uk-grid uk-scrollspy="target: > div ; cls: uk-animation-slide-top-medium; delay: 180">

				<div class="uk-width-1-2">
					<div class="item-block">
						<p>
							<span>Card</span>
							Card description
						</p>

						<img src="assets/img/challenge-desktop-icon.png" class="uk-position-bottom-right uk-visible@m">
						<img src="assets/img/challenge-icon.png" class="mobile-icon uk-position-bottom-right uk-hidden@m">
					</div>
				</div>

				<div class="uk-width-1-2">
					<div class="item-block">
						<p>
							<span>Card</span>
							Card description
						</p>
						<img src="assets/img/wheel-offortune-desktop.png" class="uk-position-bottom-right uk-visible@m">
						<img src="assets/img/wheel-offortune-icon.png" class="mobile-icon uk-position-bottom-right uk-hidden@m">
					</div>
				</div>
				
				<div class="uk-width-1-3@m uk-width-1-1">
					<div class="item-block">
						<p>
							<span>Card</span>
							Card description
						</p>

						<img src="assets/img/tournaments-icon-desktop.png" class="uk-position-bottom-right uk-visible@m">
						<img src="assets/img/tournaments-icon.png" class="mobile-icon uk-position-bottom-right uk-hidden@m">
					</div>
				</div>

				<div class="uk-width-1-3@m uk-width-1-2">
					<div class="item-block">
						<p>
							<span>Card</span>
							Card description
						</p>

						<img src="assets/img/bonus-crab-icon-desktop.png" class="uk-position-bottom-right uk-visible@m">
						<img src="assets/img/bonus-crab-icon.png" class="mobile-icon uk-position-bottom-right uk-hidden@m">
					</div>
				</div>

				<div class="uk-width-1-3@m uk-width-1-2">
					<div class="item-block">
						<p>
							<span>Card</span>
							Card description
						</p>

						<img src="assets/img/collections-icon-desktop.png" class="uk-position-bottom-right uk-visible@m">
						<img src="assets/img/collections-icon.png" class="mobile-icon uk-position-bottom-right uk-hidden@m">
					</div>
				</div>
				
			</div>


		</div>
	</section>

	<footer>
		<div id="footer" class="uk-container">

			<div class="dark-button uk-hidden" data-text="footer[dark-buttons]">
				<a class="button dark" href="#modal-language" uk-toggle>
					<img src="assets/img/en.png"> English
				</a>

				<a href="#" class="button dark">
					<img src="assets/img/icon-view-box.svg"> Help Centre
				</a>
			</div>

			<div class="links-container  uk-hidden">
				<ul class="links" data-text="footer[links]" uk-scrollspy="target: > li ; cls: uk-animation-slide-top-medium; delay: 100"> 
					<li><a href="#">Home</a></li>
					<li><a href="#">Casino</a></li>
					<li><a href="#">Live Casino</a></li>
					<li><a href="#">Fishing</a></li>
					<li><a href="#">Jackpots</a></li>
					<li><a href="#">P2P</a></li>
					<li><a href="#">Fast Games</a></li>
					<li><a href="#">Sports</a></li>
					<li><a href="#">Lottery</a></li>
				</ul>
			</div>
				
			<div class="payments uk-margin-small  uk-hidden" data-text="footer[payments]">
				<button><img src="assets/img/visa-icon.svg"></button>
				<button><img src="assets/img/mastercard-icon.png"></button>
				<a href="#"> More <img src="assets/img/arrows.svg"> </a>
			</div>


			<div class="copyrights">
				<p>
					<img src="assets/img/18plus.svg">
				</p>

				<p data-caption="game_addition" class="uk-margin-small-top">
					Gambling can be addictive. Play responsibly. LONGFU88.com accepts customers only over 18 years of age.
				</p>
				<p data-caption="copyright">
					2019-2025 © LONGFU88.com All rights reserved. 
				</p>
				
			</div>

		</div>
	</footer>



<div id="modal-result" class="uk-flex-top" uk-modal="bg-close: false; esc-close: false;" style="overflow: hidden;background: transparent;">

<video autoplay="autoplay" loop="loop" muted="muted" playsinline="" preload="auto" class="uk-hiddenx game__win-video" style="mix-blend-mode:plus-lighter; -webkit-tap-highlight-color: rgba(0,0,0,0); position: absolute; top: 0 ; left: 0;">
	<source src="https://rabona.com/simg/landings/rabona-new/rbnn16cm/video.mp4" type="video/mp4" codecs="hevc">
</video>

    <div class="uk-modal-dialog uk-margin-auto-vertical">
	    <div class="uk-modal-body uk-text-center">

	    	<img src="assets/img/cookie.png">

	    	<h3 class="uk-text-italic prize">--</h3>
			<hr>
			<a href="#promo-banner" id="claim-tracking-btn" class="button primary active uk-width-expand" data-text="promo[button-claim]" >Mobile CTA!</a>

	    </div>
    </div>
</div>


<div id="modal-language" class="uk-flex-top" uk-modal="bg-close: false; esc-close: false;">
    <div class="uk-modal-dialog uk-margin-auto-vertical">
	    <div class="uk-modal-body">

	    	<h3 class="uk-text-italic">Region and Language</h3>
	        <button class="uk-modal-close-default" type="button" uk-close style="stroke: blue;stroke-width: 3px !important;"></button>

	        <ul class="language-list">
	        	<li> 
	        		<img src="assets/img/th-flag.svg" class="flag">
	        		<div class="language-details">
	        			<h4>Thailand</h4>

	        			<div data-country="th">
		        			<button type="button" class="lang-toggle font-regular" data-href="?currency=thb&lang=en" data-lang="en">
		        				English
		        			</button>
		        			<button type="button" class="lang-toggle font-regular" data-href="?currency=thb&lang=th" data-lang="th">
		        				 ภาษาไทย 
		        			</button>
		        			<button type="button" class="lang-toggle font-regular" data-href="?currency=thb&lang=cn" data-lang="cn">
		        				中文  
		        			</button>
	        			</div>
	        		</div>
	        	</li>

	        	<li> 
	        		<img src="assets/img/vn-flag.svg" class="flag">
	        		<div class="language-details">
	        			<h4>Vietnam</h4>

	        			<div data-country="vn">
		        			<button type="button" class="lang-toggle font-regular" data-href="?currency=vnd&lang=en" data-lang="en">
		        				English
		        			</button>
		        			<button type="button" class="lang-toggle font-regular" data-href="?currency=vnd&lang=vn" data-lang="vn">
		        				Tiếng Việt 
		        			</button>
		        			<button type="button" class="lang-toggle font-regular" data-href="?currency=vnd&lang=cn" data-lang="cn">
		        				中文  
		        			</button>
	        			</div>
	        		</div>
	        	</li>

	        	<li> 
	        		<img src="assets/img/my-flag.svg" class="flag">
	        		<div class="language-details">
	        			<h4>Malaysia</h4>

	        			<div data-country="my">
		        			<button type="button" class="lang-toggle font-regular" data-href="?currency=myr&lang=en" data-lang="en">
		        				English
		        			</button>
		        			<button type="button" class="lang-toggle font-regular" data-href="?currency=myr&lang=my" data-lang="en">
		        				Melayu
		        			</button>
		        			<button type="button" class="lang-toggle font-regular" data-href="?currency=myr&lang=cn" data-lang="cn">
		        				中文  
		        			</button>
	        			</div>
	        		</div>
	        	</li>

	        	<li> 
	        		<img src="assets/img/id-flag.svg" class="flag">
	        		<div class="language-details">
	        			<h4>Indonesia</h4>

	        			<div data-country="id">
		        			<button type="button" class="lang-toggle font-regular" data-href="?currency=idr&lang=en" data-lang="en">
		        				English
		        			</button>
		        			<button type="button" class="lang-toggle font-regular" data-href="?currency=idr&lang=id" data-lang="id">
		        				Bahasa Indonesia
		        			</button>
		        			<button type="button" class="lang-toggle font-regular" data-href="?currency=idr&lang=cn" data-lang="cn">
		        				中文  
		        			</button>
	        			</div>
	        		</div>
	        	</li>

	        	<li> 
	        		<img src="assets/img/sg-flag.svg" class="flag">
	        		<div class="language-details">
	        			<h4>Singapore</h4>

	        			<div data-country="sg">
		        			<button type="button" class="lang-toggle font-regular" data-href="?currency=sgd&lang=en" data-lang="en">
		        				English
		        			</button>
		        			<button type="button" class="lang-toggle font-regular" data-href="?currency=sgd&lang=cn" data-lang="cn">
		        				中文
		        			</button>
	        			</div>
	        		</div>
	        	</li>
	        	
	        </ul>
	    </div>
    </div>
</div>

	<!-- JS FILES -->
	<script src="assets/js/jquery-3.7.1.min.js"></script>
	<script src="assets/uikit-3.24.2/js/uikit.min.js"></script>
	<script src="assets/uikit-3.24.2/js/uikit-icons.min.js"></script>

	<script>

		// Usage
		/**
		detectCountryAndLanguage().then(info => {
		if (info) {
			

			console.log(info);


		}
		});

		**/

		window.addEventListener('scroll', () => {
			// const teaser = document.getElementById('teaser');
			// const triggerPoint = window.innerHeight * 0.5; // 80% of viewport height
			// if (window.scrollY > triggerPoint) {
			// 	teaser.classList.add('show');
			// } else {
			// 	teaser.classList.remove('show');
			// }
		});

		document.getElementById('show_tnc').addEventListener('click', function(e) {
  			// e.preventDefault();

			const termsBox = document.getElementById('terms-and-conditions');
			// const textSpan = this.querySelector('span:first-child');
			// const icon = this.querySelector('[uk-icon]');
			termsBox.classList.toggle('expanded');
		});



// set active langauge checked
const countryContainer = document.querySelector(`[data-country="${USER_COUNTRY}"]`);
if (countryContainer){
	const activeBtn = countryContainer.querySelector(`button[data-lang="${USER_LANGUAGE}"]`);
	if (activeBtn) {

		// Create the <span> element
		const icon = document.createElement('span');
		icon.setAttribute('uk-icon', 'icon: check;');

		// Prepend the icon to the button
		activeBtn.prepend(icon);
		activeBtn.classList.add("active");
	}
}




// Select all buttons inside ul > li
const buttons = document.querySelectorAll("ul.language-list li button");
buttons.forEach(button => {
	button.addEventListener("click", () => {

		// Find parent div with data-country
		const parentCountry = button.closest("[data-country]")?.dataset.country;

		console.log("Country:", parentCountry);
		const language = button.dataset.lang;   // data-language

		console.log("Language:", language);

		// return ;


		const url = button.dataset.href;
		if (url) window.location.href = window.location.origin + url;


    // Get data attributes
    // const language = button.dataset.language;   // data-language
    // const currency = button.dataset.currency;   // data-currency

    // console.log("Button clicked:", button.textContent);
    // console.log("Language:", language);
    // console.log("Currency:", currency);

    // const button = e.target;
  });
});

		async function loadJSON() {
			try {
				const response = await fetch('assets/language/en.json');
				if (!response.ok) throw new Error('Network error');
				const data = await response.json();
				// console.log('Loaded JSON:', data);
			} catch (error) {
				console.error('Error loading JSON:', error);
			}
		}
		// loadJSON();



// ** Text Replacement  - DYNAMIC **
$(document).ready(() => {


	// set flag and language
	$('.user-flag').attr('src', `assets/img/${USER_COUNTRY}-flag.svg`);
	$('.user-lang').html(init.site.language);
	// $('.user-lang').html(USER_LANGUAGE);
	// <img src="assets/img/en.png" class="user-flag"> <span class="user-lang">EN</span>


	const captions = init?.site || {};

	/**
	 * key: e.g. "usd_10"
	 * targetCurrency: optional, e.g. "cny"
	 */
	const convertAndFormatCurrency = async (key, targetCurrency = null) => {
		const table = init.site.currency_table;
		const types = init.site.currency;

		const data = table[key];
		if (!data) return null;

		let currencyCode = data.currency; // original currency
		let amount = data.amount;

		// If target currency exists in convert map, apply conversion
		if (targetCurrency && data.convert && data.convert[targetCurrency] != null) {
			amount = data.convert[targetCurrency];
			currencyCode = targetCurrency;
		}

		const type = types[currencyCode];
		if (!type) return null;

		const { text, symbol, caption } = type;

		// Replace placeholders in caption
		return caption
			.replace(/%__\{SYMBOL\}__%/g, symbol)
			.replace(/%__\{AMOUNT\}__%/g, amount)
			.replace(/%__\{TEXT\}__%/g, text);
	};

	// helper: safely get nested property by string like "promo[description]"
	const getNestedValue = (obj, keyPath) => {
		try {
			return keyPath
				.replace(/\]/g, "")
				.split("[")
				.reduce((o, k) => o?.[k], obj);
		} catch (e) {
			console.error(`❌ Error accessing keyPath "${keyPath}":`, e);
			return undefined;
		}
	};

	// handle CTA element
	const handleCTA = ($el, value) => {
		const $container = $el.closest(".action-btn"); // get the .action-btn container
		if (!$container.length) {
			console.warn("⚠️ .action-btn container not found for CTA");
			return;
		}

		// remove existing CTA links inside container
		$container.empty();

		if (Array.isArray(value)) {
			// multiple CTAs
			value.forEach(item => {
				// create the <a> element
				const $a = $("<a>")
					.attr("href", item.link || "#")
					.addClass("button primary")
					.text(item.text);

				// wrap <a> in a <div> and append to container
				$("<div>").append($a).appendTo($container);
			});

		} else {
			console.warn("⚠️ CTA should array");
		}

		$container.css("visibility", "visible");
	};

	// handle Footer dark buttons element
	const handlefooterdarkButtons = ($el, value) => {
		const $container = $el; // get the .action-btn container

		if (!$container.length) {
			console.warn("⚠️ .links container not found for footer");
			return;
		}

		// remove existing links inside container
		$container.empty();

		if (Array.isArray(value)) {

			value.forEach(item => {
				const $a = $("<a>")
				.addClass("button dark")
				.attr("href", item.link || "#");

				// Apply custom attributes (supports multiple)
				if (item.attr && item.attr.trim() !== "") {
					const attrs = item.attr.trim().split(/\s+/);  // split by spaces
					attrs.forEach(a => $a.attr(a, ""));           // boolean attribute
				}

				// Add icon
				if (item.icon) {
					$("<img>").attr("src", item.icon).appendTo($a);
				}

				// Add text
				if (item.text) {
					$a.append(document.createTextNode(item.text));
				}

				$container.append($a);
			});

		} else {
			console.warn("⚠️ Links should array");
		}

		$container.css("visibility", "visible");
	};

	// handle Footer Links element
	const handlefooterLinks = ($el, value) => {
		const $container = $el; // get the .action-btn container

		if (!$container.length) {
			console.warn("⚠️ .links container not found for footer");
			return;
		}

		// remove existing links inside container
		$container.empty();

		if (Array.isArray(value)) {
			// multiple CTAs
			value.forEach(item => {
				// create the <a> element
				const $a = $("<a>")
					.attr("href", item.link || "#")
					// .addClass("button primary")
					.text(item.text);

				// wrap <a> in a <div> and append to container
				$("<li>").append($a).appendTo($container);
			});

		} else {
			console.warn("⚠️ Links should array");
		}

		$container.css("visibility", "visible");
	};
  
	// handle Footer payment element
	const handlefooterPayment = ($el, value) => {
		const $container = $el; // get the .action-btn container

		if (!$container.length) {
			console.warn("⚠️ .links container not found for footer");
			return;
		}

		// remove existing links inside container
		$container.empty();

		if (Array.isArray(value)) {
			const caption_more = getNestedValue(captions, 'footer[captions][payment_more]');

			// multiple payment icon
			value.forEach(item => {
				const $a = $("<img>")
					.attr("src", item.icon || "#");
					// .addClass("button primary")
					// .text(item.text);

				// wrap <a> in a <div> and append to container
				$("<button>").append($a).appendTo($container);
			});

			$(`<a href="#"> ${caption_more} <img src="assets/img/arrows.svg"> </a>`).appendTo($container);
		} else {
			console.warn("⚠️ payment should array");
		}

		$container.css("visibility", "visible");
	};

	// handle blocks section
	const handleBlocks = ($el, value) => {

		// remove existing blocks inside container
		$el.empty();

		// Loop cards
		value.forEach((card) => {
			const $col = $("<div>").addClass(card.size || "uk-width-1-3");

			const $block = $(`
				<a href="${card.link}">
					<div class="item-block">
						<p>
							<span>${card.title}</span>
							${card.description}
						</p>
						<img src="${card.image_desktop}" class="uk-position-bottom-right uk-visible@m">
						<img src="${card.image}" class="mobile-icon uk-position-bottom-right uk-hidden@m">
					</div>
				</a>
			`);

			$block.appendTo($col);
			$el.append($col);
		});

		$el.css("visibility", "visible");
	};

	// handle footer text
	const handlefooterText = ($el, value) => {

		// remove existing blocks inside container
		$el.empty();

		// Example: log all keys and values
		for (const key in value) {
			// if (value.hasOwnProperty(key)) {
			// console.log(key, value[key]);
			// }
		}

		$el.css("visibility", "visible");
	};

	// function handles
	const handlers = [
		{ match: "cta",           fn: handleCTA },
		{ match: "cards",         fn: handleBlocks },
		{ match: "dark-buttons",  fn: handlefooterdarkButtons },
		{ match: "links",         fn: handlefooterLinks },
		{ match: "payments",      fn: handlefooterPayment }
	];
	
	// dynamically update all elements
	$("[data-text]").each(function () {
		const $el = $(this);
		const keyPath = $el.attr("data-text");
		const value = getNestedValue(captions, keyPath);

		// console.log(keyPath, value);

		if (value !== undefined) {
			const key = keyPath.toLowerCase();

			// Find the matching handler
			const handler = handlers.find(h => key.includes(h.match));

			if (handler) {
				handler.fn($el, value);
			} else {
				$el.html(value).css("visibility", "visible");
			}

		} else {
			console.warn(`⚠️ Value not found for data-text="${keyPath}"`);
		}
	});

	// dynamic text footer update
	const captionFooter = captions?.footer?.captions || {};
	$("[data-caption]").each(function () {
		const $el = $(this);
		const keyPath = $el.attr("data-caption");
		$el.html(captionFooter[keyPath]).css("visibility", "visible");
	});

	const replaceAllCurrencyPlaceholders = async () => {
		const walker = document.createTreeWalker(
			document.body,
			NodeFilter.SHOW_TEXT,
			null,
			false
		);

		const regex = /%__([a-z0-9_]+)__%/gi;
		let node;

		while ((node = walker.nextNode())) {
			const text = node.nodeValue;

			// Check if text contains placeholder
			if (regex.test(text)) {

				// Replace all matches asynchronously
				const newText = await text.replace(regex, async (match, key) => {
					// Call your async formatter/converter
					const formatted = await convertAndFormatCurrency(key, USER_CURRENCY);
					return formatted || match; // fallback to original
				});

				// Note: .replace with async inside doesn't await properly in JS, 
				// so we need a workaround using Promise.all for multiple matches
				const matches = [...text.matchAll(regex)];
				if (matches.length) {
					const promises = matches.map(async m => {
						const k = m[1];
						return await convertAndFormatCurrency(k, USER_CURRENCY) || m[0];
					});

					const results = await Promise.all(promises);

					// Reconstruct text replacing sequentially
					let updatedText = text;
					results.forEach((res, i) => {
						updatedText = updatedText.replace(matches[i][0], res);
					});

					node.nodeValue = updatedText;
				}
			}
		}
	};


	// Convert USD 10 to CNY
	replaceAllCurrencyPlaceholders();


/**
	"prizes" : {
		"egg_1": "Try Again",
		"egg_2": "150% Bonus + 18 Free spins",
		"egg_3": "200% Bonus + 38 Free spins",
		"egg_4": "88 Free spins",
		"egg_5": "150 Free spins",
		"egg_6": "Iphone 17 Pro Max",
		"egg_7": "Macbook Pro 16 M5",
		"egg_8": "Gold Bars"
	},

**/

	let prizes_link = {
		"egg_1": "#try-again",
		"egg_2": "https://lngf.lynmonkel.com/?mid=350647_2022842",
		"egg_3": "https://lngf.lynmonkel.com/?mid=350648_2022843",
		"egg_4": "https://lngf.lynmonkel.com/?mid=350649_2022844",
		"egg_5": "https://lngf.lynmonkel.com/?mid=350650_2022845",
		"egg_6": "#Iphone-17-ProMax",
		"egg_7": "#Macbook-Pro16-M5",
		"egg_8": "#Gold-Bars"
	};


	let domain_links = {
		'fortunecookie1-id.luckylongfu.com' : {
			"egg_2": "https://lngf.lynmonkel.com/?mid=350647_2033535",
			"egg_3": "https://lngf.lynmonkel.com/?mid=350648_2033540",
			"egg_4": "https://lngf.lynmonkel.com/?mid=350649_2033545",
			"egg_5": "https://lngf.lynmonkel.com/?mid=350650_2033550",
		},
		'fortunecookie1-vn.luckylongfu.com' : {
			"egg_2": "https://lngf.lynmonkel.com/?mid=350647_2033537",
			"egg_3": "https://lngf.lynmonkel.com/?mid=350648_2033542",
			"egg_4": "https://lngf.lynmonkel.com/?mid=350649_2033547",
			"egg_5": "https://lngf.lynmonkel.com/?mid=350650_2033552",
		},
		'fortunecookie2-vn.luckylongfu.com' : {
			"egg_2": "https://lngf.lynmonkel.com/?mid=350647_2054140",
			"egg_3": "https://lngf.lynmonkel.com/?mid=350648_2054143",
			"egg_4": "https://lngf.lynmonkel.com/?mid=350649_2054149",
			"egg_5": "https://lngf.lynmonkel.com/?mid=350650_2054157",
		},
		'fortunecookie1-th.luckylongfu.com' : {
			"egg_2": "https://lngf.lynmonkel.com/?mid=350647_2033536",
			"egg_3": "https://lngf.lynmonkel.com/?mid=350648_2033541",
			"egg_4": "https://lngf.lynmonkel.com/?mid=350649_2033546",
			"egg_5": "https://lngf.lynmonkel.com/?mid=350650_2033551",
		},
		'fortunecookie2-th.luckylongfu.com' : {
			"egg_2": "https://lngf.lynmonkel.com/?mid=350647_2054174",
			"egg_3": "https://lngf.lynmonkel.com/?mid=350648_2054179",
			"egg_4": "https://lngf.lynmonkel.com/?mid=350649_2054183",
			"egg_5": "https://lngf.lynmonkel.com/?mid=350650_2054189",
		},
		'fortunecookie1-my.luckylongfu.com' : {
			"egg_2": "https://lngf.lynmonkel.com/?mid=350647_2033539",
			"egg_3": "https://lngf.lynmonkel.com/?mid=350648_2033544",
			"egg_4": "https://lngf.lynmonkel.com/?mid=350649_2033549",
			"egg_5": "https://lngf.lynmonkel.com/?mid=350650_2033554",
		},
		'fortunecookie1-sg.luckylongfu.com' : {
			"egg_2": "https://lngf.lynmonkel.com/?mid=350647_2033538",
			"egg_3": "https://lngf.lynmonkel.com/?mid=350648_2033543",
			"egg_4": "https://lngf.lynmonkel.com/?mid=350649_2033548",
			"egg_5": "https://lngf.lynmonkel.com/?mid=350650_2033553",
		},
	}



	let prizes_probability = {
		"egg_1": 0,
		"egg_2": 40,
		"egg_3": 40,
		"egg_4": 15,
		"egg_5": 5,
		"egg_6": 0,
		"egg_7": 0,
		"egg_8": 0,
	}


	const getRandomPrizeKey = (probabilities) => {
		const entries = Object.entries(probabilities);
		const totalWeight = entries.reduce((acc, [_, weight]) => acc + weight, 0);
		let random = Math.random() * totalWeight;
		for (const [key, weight] of entries) {
			if (random < weight) {
				return key;
			}
			random -= weight;
		}
	};

	// Usage:
	const winningKey = getRandomPrizeKey(prizes_probability);
	const winningPrize = captions.prizes[winningKey];

	// console.log(winningPrize);

	$('.button.primary', '.primary-cta').click ( function(){
		// sdfsdfsdf

		$('.prize' ,'#modal-result').html(winningPrize);


		// tracking link final

		
		hostname = window.location.hostname;

		if (domain_links[hostname][winningKey] === undefined || domain_links[hostname][winningKey].length == 0) {
    		var tracking_link = prizes_link[winningKey];
    		console.log('empty array - use default');
		} else {
			var tracking_link = domain_links[hostname][winningKey];
		}


		$('#claim-tracking-btn').attr('href', tracking_link);

	});

	document.title = captions.promo.title;


});

	</script>

</body>
</html>