<?php
session_start();
header('Content-Type: application/json');
if (!isset($_SESSION['admin_id']) && $_SESSION['role'] != 'admin') {
    echo json_encode(['success' => false, 'message' => 'Unauthorized']);
    exit();
}
include '../../../include/config.php';

$data = json_decode(file_get_contents('php://input'), true);
$id = $data['id'] ?? 0;
$action = $data['action'] ?? '';

if ($action == 'approve') {
    $conn->query("UPDATE withdrawal_requests SET status = 'approved', processed_at = NOW() WHERE id = '$id'");
    echo json_encode(['success' => true, 'message' => 'Withdrawal approved']);
} elseif ($action == 'reject') {
    $conn->query("UPDATE withdrawal_requests SET status = 'rejected', processed_at = NOW() WHERE id = '$id'");
    echo json_encode(['success' => true, 'message' => 'Withdrawal rejected']);
} else {
    echo json_encode(['success' => false, 'message' => 'Invalid action']);
}
?>