{#
  _auto_send_toggle.html — comutatorul "Trimite automat la RAR" (PRD 5.19 US-004).

  Plasat in clusterul de header (base.html, langa .rar-chip) — D1. NU face parte din
  swap-ul periodic al #status-bar (every 15s) -> fara flicker / pierdere focus (D3).

  Non-optimist (D2): la esec POST bifa revine + toast eroare (hx-on::response-error).
  account_id vine din SESIUNE server-side (ruta /auto-send), niciodata din formular.

  Raspunsul POST re-randeaza acest fragment (outerHTML pe #auto-send-toggle-wrap):
    - confirmare_release=True -> injecteaza modalul de confirmare OOB in #modal-confirma-slot;
    - curata_modal=True       -> goleste slotul de modal (dupa activare reusita).
#}
<span id="auto-send-toggle-wrap" class="auto-send-wrap"
      style="display:inline-flex; align-items:center; gap:6px;">
  <input type="hidden" id="auto-send-csrf" name="csrf_token" value="{{ csrf_token | default('') }}">
  <label class="auto-send-label"
         title="Trimite automat la RAR. Debifat: prezentarile asteapta confirmarea ta."
         style="display:inline-flex; align-items:center; gap:6px; cursor:pointer;
                font-size:var(--fs-sm); white-space:nowrap; user-select:none;">
    <input type="checkbox" name="enabled" value="1"
           {% if auto_send_enabled|default(false) %}checked{% endif %}
           hx-post="/auto-send"
           hx-include="#auto-send-csrf"
           hx-target="#auto-send-toggle-wrap"
           hx-swap="outerHTML"
           hx-on::response-error="this.checked = !this.checked; if(window.arataToast) window.arataToast('Nu am putut salva setarea Auto-send', 's-error');"
           aria-label="Trimite automat la RAR"
           style="width:16px; height:16px; cursor:pointer;">
    <span class="auto-send-text">Trimite automat la RAR</span>
  </label>

  {% if confirmare_release|default(false) %}
  {# OOB: modal de confirmare tipata pentru auto-release OFF->ON (garda F4/D4). #}
  <span hx-swap-oob="innerHTML:#modal-confirma-slot">
    {% set cf_id = 'modal-auto-release' %}
    {% set cf_titlu = 'Activezi trimiterea automata?' %}
    {% set cf_count = release_count %}
    {% set cf_env = release_env %}
    {% set cf_url = '/auto-send' %}
    {% set cf_vals = '{"enabled":"1","confirma":"1"}' %}
    {% set cf_target = '#auto-send-toggle-wrap' %}
    {% set cf_swap = 'outerHTML' %}
    {% set cf_confirm_label = 'Activez si trimit ' ~ release_count %}
    {% set cf_deschis = true %}
    {% include '_modal_confirma_trimitere.html' %}
  </span>
  {% endif %}

  {% if curata_modal|default(false) %}
  {# Curata slotul de modal dupa o comutare reusita (fara modal rezidual). #}
  <span hx-swap-oob="innerHTML:#modal-confirma-slot"></span>
  {% endif %}
</span>
