<?php
require_once '../init.php';

$error = '';
$success = '';

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $planType = $_POST['plan_type'] ?? 'monthly';
    
    $result = $subscription->upgradeSubscription($_SESSION['user_id'], $planType);
    
    if ($result['success']) {
        $_SESSION['success'] = 'Silakan lakukan pembayaran untuk mengaktifkan langganan';
        Helper::redirect('payment-detail.php?payment_id=' . $result['payment_id']);
    } else {
        $error = $result['message'] ?? 'Terjadi kesalahan';
    }
}

$pageTitle = 'Upgrade Paket - KasirMurah.biz.id';
$customCSS = '
    .plan-card {
        border: 2px solid #ddd;
        border-radius: 10px;
        transition: all 0.3s;
    }
    .plan-card:hover {
        border-color: #007bff;
        box-shadow: 0 5px 15px rgba(0,123,255,0.2);
    }
    .plan-card.featured {
        border-color: #28a745;
        transform: scale(1.05);
    }
';
?>
<?php include '../layout/header.php'; ?>
    <?php include '../layout/navbar.php'; ?>
    
    <div class="container mt-4">
        <h1>Pilih Paket Langganan</h1>
        
        <?php if ($error): ?>
        <div class="alert alert-danger"><?php echo $error; ?></div>
        <?php endif; ?>
        
        <div class="row mt-4">
            <!-- Monthly Plan -->
            <div class="col-md-6">
                <div class="card plan-card">
                    <div class="card-body text-center">
                        <h3 class="card-title">Paket Bulanan</h3>
                        <p class="text-muted">Sempurna untuk usaha kecil</p>
                        
                        <div class="my-4">
                            <p style="font-size: 48px; font-weight: bold; color: #28a745;">
                                Rp 50.000
                            </p>
                            <p class="text-muted">per bulan</p>
                        </div>
                        
                        <ul class="list-unstyled mb-4">
                            <li><i class="fas fa-check text-success"></i> Akses penuh sistem POS</li>
                            <li><i class="fas fa-check text-success"></i> Kelola produk unlimited</li>
                            <li><i class="fas fa-check text-success"></i> Laporan penjualan</li>
                            <li><i class="fas fa-check text-success"></i> Support via email</li>
                        </ul>
                        
                        <form method="POST" style="display: inline;">
                            <input type="hidden" name="plan_type" value="monthly">
                            <button type="submit" class="btn btn-primary btn-lg w-100">
                                Pilih Paket
                            </button>
                        </form>
                    </div>
                </div>
            </div>
            
            <!-- Yearly Plan -->
            <div class="col-md-6">
                <div class="card plan-card featured">
                    <div class="card-body text-center">
                        <h3 class="card-title">Paket Tahunan</h3>
                        <p class="text-muted">Hemat 17% per tahun</p>
                        
                        <div class="my-4">
                            <p style="font-size: 48px; font-weight: bold; color: #28a745;">
                                Rp 500.000
                            </p>
                            <p class="text-muted">per tahun</p>
                        </div>
                        
                        <ul class="list-unstyled mb-4">
                            <li><i class="fas fa-check text-success"></i> Semua fitur paket bulanan</li>
                            <li><i class="fas fa-check text-success"></i> Hemat biaya tahunan</li>
                            <li><i class="fas fa-check text-success"></i> Support prioritas</li>
                            <li><i class="fas fa-check text-success"></i> Update gratis</li>
                        </ul>
                        
                        <form method="POST" style="display: inline;">
                            <input type="hidden" name="plan_type" value="yearly">
                            <button type="submit" class="btn btn-success btn-lg w-100">
                                Pilih Paket
                            </button>
                        </form>
                    </div>
                </div>
            </div>
        </div>
        
        <div class="row mt-4">
            <div class="col-12">
                <a href="../dashboard.php" class="btn btn-secondary">Kembali</a>
            </div>
        </div>
    </div>
    
    <?php include '../layout/footer.php'; ?>
    
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>
