<?php

require_once '../includes/auth.php';

require_login();

if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
    header('Location: ../dashboard/cds_groups.php');
    exit;
}

$memberId = $_POST['member_id'] ?? 0;
$groupId = $_POST['group_id'] ?? 0;

if (empty($memberId) || empty($groupId)) {
    $_SESSION['error'] = "Invalid request.";
    header("Location: ../dashboard/cds_group_members.php?id={$groupId}");
    exit;
}

$stmt = $db->prepare("
    DELETE FROM cds_group_members
    WHERE corps_member_id = ?
    AND cds_group_id = ?
");

$stmt->execute([
    $memberId,
    $groupId
]);

$_SESSION['success'] = "Member removed successfully.";

header("Location: ../dashboard/cds_group_members.php?id={$groupId}");
exit;