{% extends 'edx/base.html' %}
{% load core_extras %}
{% load currency_filters %}
{% load i18n %}
{% load l10n %}
{% load offer_tags %}
{% load staticfiles %}
{% load enterprise %}

{% block title %}
  {% blocktrans trimmed with order_number=order.number %}
    Receipt for {{ order_number }}
  {% endblocktrans %}
{% endblock title %}

{% block javascript %}
  <script src="{% static 'js/apps/order_receipt_app.js' %}"></script>
{% endblock javascript %}

{% block navbar %}
  {% include 'edx/partials/_student_navbar.html' %}
{% endblock navbar %}

{% block content %}
  <div id="receipt-container"
       class="receipt container content-container"
       data-currency="{{ order.currency }}"
       data-order-id="{{ order.number }}"
       data-total-amount="{{ order.total_incl_tax | unlocalize }}">
      <h2 class="thank-you">{% trans "Thank you for your order!" %}</h2>

      <div class="list-info">
        <div class="info-item payment-info row">
          <div class="copy col-md-8">
            <div class="confirm-message">
              {% captureas link_start %}
                <a href="mailto:{{ order.user.email }}">
              {% endcaptureas %}
              {% blocktrans trimmed with email=order.user.email link_end="</a>" %}
                Your order is complete. If you need a receipt, you can print this page.
                You will also receive a confirmation message with this information at
                {{ link_start }}{{ email }}{{ link_end }}.
              {% endblocktrans %}
            </div>

            {% if order.billing_address %}
              <address class="billing-address">
                {% for field in order.billing_address.active_address_fields %}
                  {{ field }}<br/>
                {% endfor %}
              </address>
            {% endif %}
          </div>

          <div class="order-headers order-summary col-md-4">
            <dl>
              <dt>{% trans "Order Number:" %}</dt>
              <dd>{{ order.number }}</dd>
              {% if payment_method %}
                <dt>{% trans "Payment Method:" %}</dt>
                <dd>{{ payment_method }}</dd>
              {% endif %}
              <dt>{% trans "Order Date:" %}</dt>
              <dd>{{ order.date_placed|date:"E d, Y" }}</dd>
            </dl>
          </div>
        </div>

        <h2>{% trans "Order Information" %}</h2>
        <div class="table">
          <dl class="order-lines">
            <div class="header">
              <dt aria-hidden="true">{% trans "Quantity" %}</dt>
              <dt aria-hidden="true">{% trans "Description" %}</dt>
              <dt aria-hidden="true">{% trans "Item Price" %}</dt>
            </div>
            {% for line in order.lines.all %}
              <div class="order-line-data">
                <dt class="quantity sr">{% trans "Quantity:" %}</dt>
                <dd class="quantity">{{ line.quantity }}</dd>
                <dt class="course-description sr">{% trans "Description:" %}</dt>
                <dd class="course-description">
                  <span>{{ line.title }}</span>
                  {% if line.product.course %}
                    <p>{{ line.product.course.id|course_organization }}</p>
                  {% endif %}
                </dd>
                <dt class="line-price sr">{% trans "Item Price:" %}</dt>
                <dd class="line-price price">{{ line.line_price_before_discounts_incl_tax|currency:order.currency }}</dd>
              </div>
            {% endfor %}
          </dl>
          <div class="order-total">
            <div class="description">{% trans "Subtotal" %}</div>
            <div class="price">{{ order.total_before_discounts_incl_tax|currency:order.currency }}</div>
          </div>

          {% with discounts=order.basket_discounts %}
            {% if discounts %}
              {% for discount in discounts %}
                <div class="order-total">
                  <div class="description">
                    <span class="label label-success">{% trans "Discount" %}</span>

                    {% if discount.voucher_code %}
                      {% with voucher=discount.voucher %}
                        <span class="discount">{{ voucher.code }}</span>
                        <span class="discount">
                          {% blocktrans trimmed with voucher_code=voucher.code voucher_discount_amount=voucher.benefit|benefit_discount %}
                            {{ voucher_discount_amount }} off
                          {% endblocktrans %}
                        </span>
                      {% endwith %}
                    {% else %}
                      <span class="discount">{{ discount.offer_name }}</span>
                    {% endif %}

                  </div>
                  <div class="price">-{{ discount.amount|currency:order.currency }}</div>
                  {% enterprise_customer_for_voucher discount.voucher as enterprise_customer %}
                  {% if enterprise_customer %}
                      <div class="enterprise-customer">
                        {% blocktrans trimmed with enterprise_name=enterprise_customer.name %}
                            Courtesy of {{ enterprise_name }}.
                        {% endblocktrans %}
                      </div>
                  {%  endif %}
                </div>
              {% endfor %}

            {% endif %}
          {% endwith %}

          <div class="order-total">
            <div class="description">{% trans "Total" %}</div>
            <div class="price">{{ order.total_incl_tax|currency:order.currency }}</div>
          </div>
        </div>

        {% if display_credit_messaging %}
          {% captureas link_start %}
            <a href="{{ lms_dashboard_url }}">
          {% endcaptureas %}

          <div class="nav-wizard row">
            <p class="header">{% trans "Get Your Course Credit" %}</p>
            <p class="message">
              {% blocktrans trimmed with link_end="</a>" %}
                To receive academic credit for this course, you must apply for credit at the organization that offers the credit.
                You can find a link to the organization’s website on your {{ link_start }}dashboard{{ link_end }}, next to the course name.
              {% endblocktrans %}
            </p>
          </div>
        {% endif %}
      </div>

      {% if verification_url and not user_verified %}
        <div class="nav-wizard row">
            {% include 'oscar/checkout/_verification_data.html' %}
        </div>
      {% else %}
        <div id="dashboard-link">
          <a class="dashboard-link nav-link" href="{{ order_dashboard_url }}">
            {% trans "Go to Dashboard" %}
          </a>
        </div>
      {% endif %}
    </div>
  </div>
{% endblock content %}
