const STORAGE_KEY = 'sk_tax_forms_ab';

function collectData() {
  const data = {};
  document.querySelectorAll('input, select').forEach(i => {
    if (i.type !== 'file') data[i.id] = i.value;
  });
  data.activeForm = document.querySelector('.tab.active').dataset.form;
  data.calculation = getCalculation();
  return data;
}

function applyData(data) {
  Object.keys(data).forEach(key => {
    const el = document.getElementById(key);
    if (el) el.value = data[key];
  });
  if (data.activeForm) switchForm(data.activeForm);
}

function saveData() {
  localStorage.setItem(STORAGE_KEY, JSON.stringify(collectData()));
  alert('Údaje boli uložené.');
}

function loadData() {
  const raw = localStorage.getItem(STORAGE_KEY);
  if (raw) applyData(JSON.parse(raw));
}
