{% extends 'layout.html' %}

{% load static %}

{% load crispy_forms_tags %}

{% block content %}
<!-- Modal -->
<div class="modal fade" id="createModal" tabindex="-1" aria-labelledby="createModalLabel" aria-hidden="true">
    <div class="modal-dialog">
      <div class="modal-content">
        <div class="modal-header">
          <h1 class="modal-title fs-5" id="createModalLabel">CREATE SACHET ANALYSIS FORM</h1>
          <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
        </div>
        <div class="modal-body">
            <div class="p-1">

                <form method="post" action="" id="formPage">
                    {% csrf_token %}
                    
                    {{form|crispy}}
                    <button type="submit" class="btn btn-primary mt-5 form-control shadowed">Submit</button>
                    
                    <input id="ref_code" name="ref_code" type="hidden" placeholder="Ref Code" class="my-2" value=""/>
                
                </form>
            </div>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-secondary" data-bs-dismiss="modal" onclick="window.location.reload()">Close</button>
        </div>
      </div>
    </div>
  </div>
<!--Modal Ends-->


<div class="mx-1 my-2" style="border: 0.2px solid rgba(0, 0, 0, 0.1);">
    <h3 class="p-2" style="background-color:#212529;color:white;">SACHET ANALYSIS DASHBOARD</h3>
    <div class="px-3 pb-3">
        <div class="mb-3">
            
              <div class="input-group mb-3">
                <input type="text" class="form-control shadowed" id="myInput" placeholder="Search.." aria-label="Recipient's username" aria-describedby="button-addon2">
                <button class="btn btn-primary shadowed" type="button" data-bs-toggle="modal" data-bs-target="#createModal">Create Form</button>
              </div>

            <table class="table" id="dtBasicExample">
                <thead>
                  <tr style="background-color:#212529;color:white;">
                    <th scope="col">DATE</th>
                    <th scope="col">SHIFT</th>
                    <th scope="col">MACHINE</th>
                    <th scope="col">PRODUCT</th>
                    <th scope="col">SIZE</th>
                    <th scope="col">ANALYST</th>
                    <th scope="col">STATUS</th>
                  </tr>
                </thead>
                <tbody id="myTable">
            {% for d in data %}
                    <tr onclick="window.location.href='/sachet/analysis/detail/{{d.id}}'" onmouseover="bigImg(this)" onmouseout="normalImg(this)">
                        <td>{{ d.date }}</td>
                        <td>{{ d.shift }}</td>
                        <td>{{ d.mc_id.machine }}</td>
                        <td>{{ d.product_id.product_name }}</td>
                        <td>{{ d.product_id.product_size }}</td>
                        <td>{{ d.product_analyst }}</td>
                        <td>{{ d.status}}</td>
                    </tr>
            {% endfor %}
                </tbody>
            </table>

            <!-- PAGINATION -->
            {% if data.has_other_pages %}
              <ul class="pagination">
                {% if data.has_previous %}
                  <li class="page-item"><a href="?page={{ data.previous_page_number }}" class="page-link">&laquo;</a></li>
                {% else %}
                  <li class="page-item disabled"><span class="page-link">&laquo;</span></li>
                {% endif %}
                {% for i in data.paginator.page_range %}
                  {% if data.number == i %}
                    <li class="page-item active"><span class="page-link">{{ i }} <span class="sr-only">(current)</span></span></li>
                  {% else %}
                    <li class="page-item"><a href="?page={{ i }}" class="page-link">{{ i }}</a></li>
                  {% endif %}
                {% endfor %}
                {% if data.has_next %}
                  <li class="page-item"><a href="?page={{ data.next_page_number }}" class="page-link">&raquo;</a></li>
                {% else %}
                  <li class="page-item disabled"><span class="page-link">&raquo;</span></li>
                {% endif %}
              </ul>
            {% endif %}
            <!-- PAGINATION -->
        </div>
    </div>
</div>

<script>
    $(document).ready(function(){
        $('#id_date').attr('type', 'date');
        //setSelect('line', "{{lines|safe}}");
        //setSelect('product', "{{prods|safe}}");
        //setSelect('product_size', "{{size|safe}}");
    })
</script>
{% endblock %}