<?php
require_once __DIR__ . '/../includes/functions.php';
requireLogin();

$cardCode = trim($_GET['card_code'] ?? $_POST['card_code'] ?? '');
if (!$cardCode) jsonResponse(['success'=>false,'error'=>'No card code provided.']);

$member = getMemberByCard($cardCode);
if (!$member) {
    jsonResponse(['success'=>false,'error'=>'Card not found. Generate and save the card first.']);
}

// Surface deactivated status as a dedicated flag so all callers can handle it
$member['points']      = getMemberBalance((int)$member['id']);
$member['is_active']   = ($member['status'] ?? 'active') === 'active';
$member['deactivated'] = !$member['is_active'];

jsonResponse(['success'=>true, 'member'=>$member]);
