<?php
/**
 * APP下载页面 - Default模板风格
 * 独立页面，无需登录
 */
if (!defined('IN_CRONLITE')) {
    require_once __DIR__ . '/../../../MPHX/common.php';
}

// 获取当前域名
$domain = $_SERVER['HTTP_HOST'];
$protocol = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? 'https' : 'http';
$baseUrl = $protocol . '://' . $domain;
$apkUrl = $baseUrl . '/app/app.apk';

// 检查APK文件是否存在
$apkPath = __DIR__ . '/../../../app/app.apk';
$apkExists = file_exists($apkPath);

// 页面标题
$pageTitle = 'APP下载';
$siteName = $conf['name'] ?? '虚拟空间';
?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title><?php echo $pageTitle; ?> - <?php echo $siteName; ?></title>
    
    <!-- 引入模板样式 -->
    <link rel="stylesheet" href="/static/css/bootstrap.min.css">
    <link rel="stylesheet" href="/static/css/all.min.css">
    <link rel="stylesheet" href="/templates/default/assets/css/style.css?v=20260406_1">
    
    <style>
        /* APP下载页面样式 - 匹配Default模板风格 */
        .app-download-wrapper {
            min-height: 100vh;
            background: #f5f7fa;
            padding: 40px 20px;
        }
        
        .download-container {
            max-width: 480px;
            margin: 0 auto;
        }
        
        .download-card {
            background: #fff;
            border-radius: 8px;
            box-shadow: 0 1px 3px rgba(0,0,0,0.1);
            padding: 40px;
            text-align: center;
        }
        
        .app-icon {
            width: 80px;
            height: 80px;
            background: #e6f4ea;
            border-radius: 16px;
            margin: 0 auto 20px;
            display: flex;
            align-items: center;
            justify-content: center;
        }
        
        .app-icon i {
            font-size: 40px;
            color: #188038;
        }
        
        .app-name {
            font-size: 22px;
            font-weight: 600;
            color: #202124;
            margin-bottom: 6px;
        }
        
        .app-version {
            font-size: 13px;
            color: #5f6368;
            margin-bottom: 30px;
        }
        
        .qr-section {
            background: #f8f9fa;
            border: 1px solid #e8eaed;
            border-radius: 8px;
            padding: 25px;
            margin-bottom: 25px;
        }
        
        .qr-title {
            font-size: 14px;
            color: #5f6368;
            margin-bottom: 15px;
        }
        
        #qrcode {
            display: inline-block;
            padding: 10px;
            background: white;
            border-radius: 4px;
            border: 1px solid #e8eaed;
        }
        
        .qr-hint {
            font-size: 12px;
            color: #80868b;
            margin-top: 10px;
        }
        
        .download-btn {
            display: block;
            width: 100%;
            padding: 14px 30px;
            background: #188038;
            color: white;
            text-decoration: none;
            border-radius: 4px;
            font-size: 15px;
            font-weight: 500;
            transition: all 0.2s;
            border: none;
            cursor: pointer;
        }
        
        .download-btn:hover {
            background: #137333;
            color: white;
            text-decoration: none;
        }
        
        .download-btn i {
            margin-right: 8px;
        }
        
        .tips {
            margin-top: 20px;
            font-size: 13px;
            color: #5f6368;
        }
        
        .tips-item {
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 6px;
            margin: 8px 0;
        }
        
        .tips-item i {
            color: #188038;
            font-size: 12px;
        }
        
        /* 返回按钮 */
        .back-link {
            display: inline-flex;
            align-items: center;
            gap: 6px;
            color: #5f6368;
            text-decoration: none;
            margin-bottom: 20px;
            font-size: 13px;
            transition: all 0.2s;
        }
        
        .back-link:hover {
            color: #188038;
            text-decoration: none;
        }
        
        /* 页脚 */
        .page-footer {
            text-align: center;
            margin-top: 30px;
            color: #80868b;
            font-size: 12px;
        }
        
        /* 响应式 */
        @media (max-width: 480px) {
            .app-download-wrapper {
                padding: 20px 15px;
            }
            
            .download-card {
                padding: 30px 20px;
            }
            
            .app-icon {
                width: 70px;
                height: 70px;
            }
            
            .app-icon i {
                font-size: 35px;
            }
            
            .app-name {
                font-size: 20px;
            }
        }
    </style>
</head>
<body>
    <div class="app-download-wrapper">
        <div class="download-container">
            <!-- 返回链接 -->
            <a href="/" class="back-link">
                <i class="fas fa-arrow-left"></i> 返回首页
            </a>
            
            <div class="download-card">
                <!-- APP图标 -->
                <div class="app-icon">
                    <i class="fas fa-mobile-alt"></i>
                </div>
                
                <!-- APP名称 -->
                <h1 class="app-name"><?php echo $siteName; ?> APP</h1>
                <p class="app-version">最新版本 V1.1.0</p>
                
                <!-- 二维码区域 -->
                <div class="qr-section">
                    <p class="qr-title"><i class="fas fa-qrcode"></i> 扫码下载</p>
                    <div id="qrcode"></div>
                    <p class="qr-hint">使用手机浏览器扫描二维码</p>
                </div>
                
                <!-- 下载按钮 -->
                <?php if ($apkExists): ?>
                <a href="<?php echo $apkUrl; ?>" class="download-btn">
                    <i class="fas fa-download"></i> 立即下载
                </a>
                <?php else: ?>
                <div class="download-btn" style="background: #ccc; cursor: not-allowed; opacity: 0.7;">
                    <i class="fas fa-clock"></i> 即将上线
                </div>
                <?php endif; ?>
                
                <!-- 提示信息 -->
                <div class="tips">
                    <div class="tips-item">
                        <i class="fab fa-android"></i>
                        <span>支持 Android 5.0 及以上系统</span>
                    </div>
                    <div class="tips-item">
                        <i class="fas fa-shield-alt"></i>
                        <span>安全无毒，请放心下载</span>
                    </div>
                </div>
            </div>
            
            <!-- 页脚 -->
            <div class="page-footer">
                <p>&copy; <?php echo date('Y'); ?> <?php echo $siteName; ?> - All Rights Reserved</p>
            </div>
        </div>
    </div>
    
    <!-- QRCode.js -->
    <script src="https://cdn.jsdelivr.net/npm/qrcodejs@1.0.0/qrcode.min.js"></script>
    <script>
        // 生成二维码
        document.addEventListener('DOMContentLoaded', function() {
            new QRCode(document.getElementById('qrcode'), {
                text: '<?php echo $apkUrl; ?>',
                width: 160,
                height: 160,
                colorDark: '#202124',
                colorLight: '#ffffff',
                correctLevel: QRCode.CorrectLevel.M
            });
        });
    </script>
</body>
</html>
