<?php
/**
 * Technology & Equipment API Endpoint
 */

header('Content-Type: application/json');
header('Access-Control-Allow-Origin: *');

require_once __DIR__ . '/../config/database.php';

try {
    $pdo = getDBConnection();
    
    $stmt = $pdo->query("
        SELECT id, title, description, icon_class, image_url, category, features, display_order
        FROM technology_items 
        WHERE status = 'active'
        ORDER BY display_order ASC, created_at DESC
    ");
    
    $items = [];
    while ($row = $stmt->fetch()) {
        $features = json_decode($row['features'], true);
        if (!is_array($features)) {
            $features = [];
        }
        
        $items[] = [
            'id' => (int)$row['id'],
            'title' => $row['title'],
            'description' => $row['description'],
            'icon_class' => $row['icon_class'],
            'image_url' => $row['image_url'] ? '/backend/uploads/technology/' . $row['image_url'] : null,
            'category' => $row['category'],
            'features' => $features,
            'display_order' => (int)$row['display_order']
        ];
    }
    
    echo json_encode([
        'success' => true,
        'items' => $items
    ]);
    
} catch (Exception $e) {
    error_log("Technology API error: " . $e->getMessage());
    http_response_code(500);
    echo json_encode([
        'success' => false,
        'items' => []
    ]);
}

