import type { AdminDrawListItem } from "@/types/api/admin-draws";

const CANCELLABLE_STATUSES = new Set(["pending", "open", "closing", "closed"]);

export function drawHasNoBets(row: AdminDrawListItem): boolean {
  return (row.total_bet_minor ?? 0) === 0;
}

export function canEditDrawRow(row: AdminDrawListItem): boolean {
  if (!drawHasNoBets(row)) {
    return false;
  }
  return row.status === "pending" || row.status === "open";
}

export function canDeleteDrawRow(row: AdminDrawListItem): boolean {
  return row.status === "pending" && drawHasNoBets(row);
}

export function canCancelDrawRow(row: AdminDrawListItem): boolean {
  if (!drawHasNoBets(row)) {
    return false;
  }
  return CANCELLABLE_STATUSES.has(row.status);
}
