{% extends 'buybackprogram/page.html' %}
{% load i18n %}
{% load humanize %}
{% load bootstrap %}
{% load static %}
{% load price_formats %}
{% load help_icons %}

{% block body %}


{% if buyback_data %}
<div class="card text-white bg-success">
  <div class="card-header">{% trans "Calculation Succesfull" %}</div>
  <div class="card-body">
    {% include "buybackprogram/partials/calculate/calculation_success.html" %}
  </div>
</div>

<div class="card" style="margin-top:10px;">
  <div class="card-header"><h5>{% trans "Accepted location(s)" %} <i class="fas fa-light fa-question" title="{% help 'accepted_locations' %}"></i></h5></div>
  <div class="card-body">
    {% include "buybackprogram/partials/calculate/accepted_locations.html" %}
  </div>
</div>

<div class="card" style="margin-top:10px;">
  <div class="card-header"><h5>{% trans "Contact Settings" %} <i class="fas fa-light fa-question" title="{% help 'contract_settings' %}"></i></h5></div>
  <div class="card-body">
    {% include "buybackprogram/partials/calculate/contract_settings.html" %}
  </div>
</div>

<div class="card" style="margin-top:10px;">
  <div class="card-header"><h5>{% trans "Invoice" %} <i class="fas fa-light fa-question" title="{% help 'invoice' %}"></i></h5></div>
  <div class="card-body">
    {% include "buybackprogram/partials/calculate/invoice.html" %}
  </div>
</div>

<div class="card" style="margin-top:10px;">
  <div class="card-header"><h5>{% trans "Item Details" %} <i class="fas fa-light fa-question" title="{% help 'item_details' %}"></i></h5></div>
  <div class="card-body">
    {% include "buybackprogram/partials/calculate/item_details.html" %}
  </div>
</div>
    {% endif %}

<div class="card" style="margin-top:10px;">
    <h5 class="card-header">{% trans "Contract calculator" %}</h5>
    <div class="card-body">
        <form class="form" action="{% url 'buybackprogram:program_calculate' program_pk=program.id %}" method="POST">
            {% csrf_token %}
            {{ form|bootstrap }}
            <button type="submit" class="btn btn-primary">{% trans "Calculate" %}</button>
            </form>
    </div>
    <div class="card-footer text-muted" >
        <b>{% trans "Selected Program:" %} </b>{% if program.name %}{{program.name}},{% endif %} managed by {% if program.is_corporation %}{{ program.owner.corporation }}{% else %}{{ program.owner.character.character }}{% endif %}
    </div>
</div>

{% endblock %}

{% block extra_javascript %}
<script>
document.querySelectorAll('button[data-type="copy"]')
  .forEach(function(button){
      button.addEventListener('click', function(){
      let email = this.parentNode.parentNode
        .querySelector('td[data-type="copy_value"]')
        .innerText;

      let tmp = document.createElement('textarea');
          tmp.value = email;
          tmp.setAttribute('readonly', '');
          tmp.style.position = 'absolute';
          tmp.style.left = '-9999px';
          document.body.appendChild(tmp);
          tmp.select();
          document.execCommand('copy');
          document.body.removeChild(tmp);
          console.log(`${email} copied.`);
    });
});
</script>
{% endblock %}

{% block extra_css %}
{% include "buybackprogram/bundles/buybackprogram-css-light.html" %}
{% endblock %}

{% block extra_script %}
{% endblock %}
