<?php
header('Content-Type: application/json');
require_once '../config.php';

try {
    $pdo = getDB();
    $stmt = $pdo->query("SELECT id, name, plan_type, duration_days, price, max_devices, features FROM packages WHERE is_active = 1 ORDER BY sort_order, id");
    $packages = $stmt->fetchAll();
    
    echo json_encode([
        'success' => true,
        'packages' => $packages
    ]);
} catch (Exception $e) {
    echo json_encode([
        'success' => false,
        'error' => 'Failed to fetch packages'
    ]);
}
