// F8-11 battles table — module-level sort rune.
//
// Held outside the component so the user's sort choice survives the
// component being unmounted (row click → battle viewer → back to the
// table). Held in memory only; an F5 reloads the report and the
// defaults take over.

export type BattlesSortColumn = "planet" | "shots";

export type BattlesSortDirection = "asc" | "desc";

export interface BattlesTableState {
	sortColumn: BattlesSortColumn;
	sortDirection: BattlesSortDirection;
}

const DEFAULT_STATE: BattlesTableState = {
	sortColumn: "shots",
	sortDirection: "desc",
};

export const battlesTableState: BattlesTableState = $state({
	...DEFAULT_STATE,
});

/**
 * resetBattlesTableState restores every field to its default value.
 * Production code never calls it; the Vitest harness uses it from
 * `beforeEach` to keep cases independent (the rune is a module-level
 * singleton that otherwise carries state across test boundaries).
 */
export function resetBattlesTableState(): void {
	Object.assign(battlesTableState, DEFAULT_STATE);
}
