<?php
header('Content-Type: application/json');
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: PUT');
header('Access-Control-Allow-Headers: Content-Type');

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

$data = json_decode(file_get_contents('php://input'), true);

if (empty($data['id'])) {
    http_response_code(400);
    echo json_encode(['success' => false, 'message' => 'ID requis']);
    exit;
}

try {
    $stmt = getDB()->prepare("UPDATE team_members SET name = ?, role = ?, bio = ?, image = ?, email = ?, linkedin = ?, order_position = ?, status = ? WHERE id = ?");
    $stmt->execute([
        $data['name'],
        $data['role'],
        $data['bio'] ?? '',
        $data['image'] ?? '',
        $data['email'] ?? '',
        $data['linkedin'] ?? '',
        $data['order_position'] ?? 0,
        $data['status'] ?? 'active',
        $data['id']
    ]);
    
    echo json_encode([
        'success' => true,
        'message' => 'Membre mis à jour avec succès'
    ]);
} catch (Exception $e) {
    http_response_code(500);
    echo json_encode(['success' => false, 'message' => $e->getMessage()]);
}
