{% extends "base.html" %}
{% from 'partials/_buttons.html' import button %}

{% block content %}
<section>
  <div class="actions-grid" style="max-width: calc(4 * 220px + 3 * .75rem);">
    {{ button('Build a Deck', variant='primary', href='/build', classes='action-button home-button') }}
    {{ button('Run a JSON Config', variant='secondary', href='/configs', classes='action-button home-button') }}
    {% if show_setup %}{{ button('Initial Setup', variant='secondary', href='/setup', classes='action-button home-button') }}{% endif %}
    {{ button('Owned Library', variant='secondary', href='/owned', classes='action-button home-button') }}
    {{ button('Browse All Cards', variant='secondary', href='/cards', classes='action-button home-button') }}
    {% if show_commanders %}{{ button('Browse Commanders', variant='secondary', href='/commanders', classes='action-button home-button') }}{% endif %}
    {{ button('Finished Decks', variant='secondary', href='/decks', classes='action-button home-button') }}
    {{ button('Browse Themes', variant='secondary', href='/themes/', classes='action-button home-button') }}
    {% if random_ui %}{{ button('Random Build', variant='secondary', href='/random', classes='action-button home-button') }}{% endif %}
    {% if show_diagnostics %}{{ button('Diagnostics', variant='secondary', href='/diagnostics', classes='action-button home-button') }}{% endif %}
    {% if show_logs %}{{ button('View Logs', variant='secondary', href='/logs', classes='action-button home-button') }}{% endif %}
  </div>
  <div id="themes-quick" style="margin-top:1rem; font-size:.85rem; color:var(--text-muted);">
    <span id="themes-quick-status">Themes: …</span>
  </div>
  <div class="actions-grid" style="max-width: calc(4 * 220px + 3 * .75rem); margin-top:2rem;">
    {{ button('GitHub', variant='secondary', href='https://github.com/mwisnowski/mtg_python_deckbuilder', classes='action-button home-button', attrs='target="_blank" rel="noopener"') }}
    {{ button('Report an Issue', variant='secondary', href='https://github.com/mwisnowski/mtg_python_deckbuilder/issues', classes='action-button home-button', attrs='target="_blank" rel="noopener"') }}
    {{ button('Request a Feature', variant='secondary', href='https://github.com/mwisnowski/mtg_python_deckbuilder/issues/new?template=other-feature-request-.md', classes='action-button home-button', attrs='target="_blank" rel="noopener"') }}
    {{ button('DockerHub', variant='secondary', href='https://hub.docker.com/repository/docker/mwisnowski/mtg-python-deckbuilder/general', classes='action-button home-button', attrs='target="_blank" rel="noopener"') }}
  </div>
</section>
<script>
(function(){
  function upd(data){
    var el = document.getElementById('themes-quick-status');
    if(!el) return;
    if(!data || !data.ok){ el.textContent='Themes: unavailable'; return; }
    var badge = '';
    if(data.phase === 'themes' || data.phase === 'themes-fast') badge=' (refreshing)';
    else if(data.stale) badge=' (stale)';
    el.textContent = 'Themes: ' + (data.theme_count != null ? data.theme_count : '?') + badge;
  }
  function poll(){
    fetch('/themes/status', { cache:'no-store' })
      .then(function(r){ return r.json(); })
      .then(upd)
      .catch(function(){});
  }
  poll();
  setInterval(poll, 7000);
})();
</script>
{% endblock %}
