<?php include_once "../config/siteconfig.php";?>
<!DOCTYPE html>
<html>
<head>
    <title>Open App</title>
</head>
<body>


<script>
    var appScheme = 'ibix://quiz';
    var playStoreURL = '<?php echo PLAYSTOREURL; ?>'; // e.g., https://play.google.com/store/apps/details?id=com.yourapp.package
    var androidPackageName = 'com.ideascaards.app'; // <-- Replace this with your app's package name

    function getMobileOperatingSystem() {
        var userAgent = navigator.userAgent || navigator.vendor || window.opera;

        if (/android/i.test(userAgent)) {
            return "Android";
        } else if (/iPad|iPhone|iPod/.test(userAgent) && !window.MSStream) {
            return "iOS";
        } else {
            return "Web";
        }
    }

    function launchApp() {
        var os = getMobileOperatingSystem();

        if (os === "Android") {
            // Use intent scheme for Android
            var intentUrl = 'intent://quiz#Intent;scheme=ibix;package=' + androidPackageName + ';S.browser_fallback_url=' + encodeURIComponent(playStoreURL) + ';end';
            window.location = intentUrl;

        } else if (os === "iOS") {
            // Try opening via custom scheme
            window.location = appScheme;

            // Fallback manually after timeout (optional for iOS)
            setTimeout(function () {
                window.location.href = playStoreURL;
            }, 2000);

        } else {
            // Desktop fallback
            window.location.href = playStoreURL;
        }
    }
    launchApp();
</script>

</body>
</html>
