import { journals } from '../stores/journalStore.js';
import { nameToId } from '../shared/countries.js';

let selected = $state(new Set());
let totalCountries = $state(0);

// Derive visited countries from journal entries
journals.subscribe((entries) => {
  const ids = new Set();
  for (const e of entries) {
    const id = nameToId[e.location?.country];
    if (id) ids.add(id);
  }
  selected = ids;
});

export function getSelected() {
  return selected;
}

export function setTotalCount(n) {
  totalCountries = n;
}

export function getTotalCount() {
  return totalCountries;
}
