{% extends edc_base_template %}

{% load static i18n %}

{% block main %}
  {{ block.super }}
  <div class="container">
    <div class="col-sm-4">
    </div>
    <div class="col-sm-4">
      <div style="padding:10px"><a href="{% url "edc_pharmacy:home_url" %}">Pharmacy</a> > <a href="{{ source_changelist_url }}?q={{ source_pk }}">{{ source_model_name }}</a> > Confirm stock</div>
      <div class="panel panel-default">
        <div class="panel-heading"># <a href="{{ source_changelist_url }}?q={{ source_pk }}">{{ source_identifier }}</a>: {{ confirmed_count }}/{{ total_stock_code_count }} items {{ transaction_word }}</div>
        <div class="panel-body">
          <form class="form-horizontal" action="{{ url }}" method="post" onSubmit="document.getElementById('submit').disabled=true;" >
            {% csrf_token %}
            {% if unconfirmed_count == 0 %}<i class="fa-solid fa-check fa-fw"></i> <span class="text text-success">{% translate 'All items are confirmed.' %}</span> {% endif %}
            <div class="form-group">
              {% for i in item_count %}
                <label class="control-label col-sm-2" for="stock_codes">{{ i }}.</label>
                <div class="col-sm-10">
                  <input type="text" class="form-control" id="stock_codes" name="stock_codes" placeholder="code # {{ i }} " value="" pattern="[A-Z0-9]{6}" required autofocus>
                </div>
              {% endfor %}
            </div>
            <input type="hidden" id="session_uuid" name="session_uuid"  value="{{ session_uuid }}">
            <button type="submit" class="btn btn-default" name="submit" id="submit" {% if unconfirmed_count == 0 %}disabled{% endif %} >Submit</button>
            <button class="btn btn-default" onclick="window.location.href='{{ source_changelist_url }}?q={{ source_pk }}'">Done</button>
          </form>
        </div>
      </div>
    </div>
    <div class="col-sm-4">
      <div style="padding:10px">&nbsp;</div>
      <div class="panel panel-default">
        <div class="panel-heading">Last scanned {{ confirmed_count }}</div>
        <div class="panel-body">
          <div class="col-sm-10">
            <table class="table table-condensed">
              {% for code, cond, word in last_stock_codes %}
                <tr>
                  <td class="text text-{% if cond == CONFIRMED %}success{% elif cond == ALREADY_CONFIRMED %}warning{% elif cond == INVALID %}danger{% else %}default{% endif %}">
                    {% if cond == CONFIRMED %}<i class="fa-solid fa-check fa-fw"></i>
                    {% elif cond == ALREADY_CONFIRMED %}<i class="fa-solid fa-minus fa-fw"></i>
                    {% elif cond == INVALID %}<i class="fa-solid fa-xmark fa-fw"></i>
                    {% endif %}
                  </td>
                  <td class="text text-{% if cond == CONFIRMED %}success{% elif cond == ALREADY_CONFIRMED %}warning{% elif cond == INVALID %}danger{% else %}default{% endif %}">
                    {{ code }}
                  </td>
                  <td class="text text-{% if cond == CONFIRMED %}success{% elif cond == ALREADY_CONFIRMED %}warning{% elif cond == INVALID %}danger{% else %}default{% endif %}">
                    {{ word }}
                  </td>
                </tr>
              {% endfor %}
             </table>
          </div>
        </div>
      </div>
    </div>
  </div>
{% endblock main %}
