{# LIBRARIES #}
{{ attach_library('ui_patterns/nre_ad_boards.nre_ad_lib') }}
{{ attach_library('ui_patterns/libraries.bs_collapse') }}
{{ attach_library('ui_patterns/libraries.bs_spinners') }}

{# VARIABLES #}
{% set initial_state = initial_state|default('off') %}
{% set auto_disabled = (initial_state == 'on') ? '0' : '1' %}
{% set seconds = seconds|default(0) %}
{% set tabbed = tabbed|default(false) %}
{% set tid = 'nre-ldb-stations' %}
{% set ajax_attrs = altcom_ajax_attrs_string(
  'nre_ldb_stations',
  tid,
  { 'station': station,
    'calling_at': calling_at,
    'tabbed': tabbed
  }, 1, 1, 0, seconds|number_format)
%}

{# TEMPLATE #}
<div id="nre-ad-block">
  <span class="visually-hidden" {{ ajax_attrs|raw }}>Load stations</span>
  <div>
    {% set on_string = "<i class='fas fa-power-off'></i> Turn on auto update" %}
    {% set off_string = "<i class='fas fa-sync' id='#{ tid }-spin'></i> Turn off auto update" %}
    <div class="table-meta mb-3">
      {{ altcom_ajax_toggle(tid, 'sgl', initial_state, on_string, off_string, 'light') }}
      {{ altcom_ajax_update(tid, 'Last updated:') }}
    </div>
  </div>

  <div id="{{ tid }}" data-altcom-ajax-disabled="{{ auto_disabled }}">
    {% include "@molecules/tm-bs/spinner/spinner.twig" with {
      'size': 'sm',
      'show_text': true,
      'status': 'light',
    } only %}
    {% if aadc %}<div class="aadc">{{ aadc }}</div>{% endif %}
  </div>
</div>
