(async () => {
  const result = await browser.storage.local.get('erledigt_config');
  const actions = (result.erledigt_config || {}).actions || [];
  const list = document.getElementById('action-list');

  if (actions.length === 0) {
    list.innerHTML = '<div class="empty-state">Keine Aktionen konfiguriert.</div>';
    return;
  }

  for (let i = 0; i < actions.length; i++) {
    const action = actions[i];
    const btn = document.createElement('button');
    btn.textContent = action.name || `Aktion ${i + 1}`;
    btn.addEventListener('click', async () => {
      await browser.runtime.sendMessage({ action: 'erledigtAction', index: i });
      window.close();
    });
    list.appendChild(btn);
  }
})();
