<?php
/**
 * Team Members 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, name, position, bio, email, linkedin_url, photo
        FROM team_members
        WHERE status = 'active'
        ORDER BY display_order ASC, created_at DESC
    ");
    
    $members = [];
    while ($row = $stmt->fetch()) {
        $members[] = [
            'id' => $row['id'],
            'name' => $row['name'],
            'position' => $row['position'],
            'bio' => $row['bio'],
            'email' => $row['email'],
            'linkedin_url' => $row['linkedin_url'],
            'photo' => $row['photo'] ? '/backend/uploads/team/' . $row['photo'] : null
        ];
    }
    
    echo json_encode([
        'success' => true,
        'members' => $members
    ]);
    
} catch (Exception $e) {
    error_log("Team API error: " . $e->getMessage());
    http_response_code(500);
    echo json_encode([
        'success' => false,
        'members' => []
    ]);
}

