{#
/**
 * @file
 * Order template used on the admin order page.
 *
 * Available variables:
 * - attributes: HTML attributes for the wrapper.
 * - order: The rendered order fields.
 *   Use 'order' to print them all, or print a subset such as
 *   'order.order_number'. Use the following code to exclude the
 *   printing of a given field:
 *   @code
 *   {{ order|without('order_number') }}
 *   @endcode
 * - order_entity: The order entity.
 *
 * @ingroup themeable
 */
#}
{% set is_completed = order_entity.getState.getId == 'completed' %}
{% set is_draft = order_entity.getState.getId == 'draft' %}
{% set is_canceled = order_entity.getState.getId == 'canceled' %}
{% set is_paid = order_entity.isPaid %}
{{ attach_library('commerce_order/admin-order') }}
<div class="order-admin layout-commerce-admin">
  <div class="layout-region layout-region--commerce-main order-admin__main">
    <div class="layout-region__content order-admin__content">
      {{ draft_warning }}
      <div class="order-admin__profile-cards">
        {% if order.billing_profile %}
          <div class="order-admin__billing">
            {{ order.billing_profile.0 }}
          </div>
        {% endif %}
        {% if order.shipments %}
          <div class="order-admin__shipments">
            {{ order.shipments.0 }}
          </div>
        {% elseif order.shipping_information %}
          <div class="order-admin__shipping">
            {% include 'commerce:commerce-admin-card' with {
              id: 'shipping-information-admin-card',
              title: 'Shipping information'|t,
              content: order.shipping_information,
            } %}
          </div>
        {% endif %}
      </div>
      <div class="order-admin__order-items">
        {{ order.order_items }}
      </div>
      <div class="order-admin__total">
        {{ order.total_price }}
      </div>
      {% if order.activity %}
        <div class="order-admin__activity">
          <h2 class="order-admin__activity-title">{% trans %}Order activity{% endtrans %}</h2>
          <div class="order-admin__activity-content">
            {{ order.activity }}
          </div>
        </div>
      {% endif %}
    </div>
  </div>
  <div class="layout-region layout-region--commerce-secondary order-admin__sidebar">
    <div class="order-admin__state-card">
      {% set order_state_badge %}
        {% if not is_canceled %}
          {% if is_cart %}
            {% include 'commerce:commerce-status-badge' with {
              text: "Cart"|t,
              variant: 'neutral',
              } %}
          {% elseif not is_draft %}
            {% include 'commerce:commerce-status-badge' with {
              text: is_paid ? "Paid"|t : "Unpaid"|t,
              variant: is_paid ? 'success' : 'neutral',
              } %}
          {% endif %}
        {% endif %}
      {% endset %}
      {% set order_title %}
        {% if is_canceled %}
          {{ 'Canceled order'|t }}
        {% elseif is_draft %}
          {{ 'Draft order'|t }}
        {% else %}
          {{ 'Placed order'|t }}
        {% endif %}
      {% endset %}
      {% embed 'commerce:commerce-admin-card' with {
        id: 'order-state',
        title: order_title,
        title_tag: 'h4',
        badge: order_state_badge,
      } %}
        {% block card_content %}
          <div class="order-admin__state-fields">
            {% if is_draft %}
              {{ order.created }}
            {% endif %}
            {{ order.placed }}
            <div class="field order-admin__state-field field--label-inline">
              <div class="field__label">{{ 'State' }}</div>
              <div class="field__item">
                {% if is_completed and order_entity.getCompletedTime %}
                  <span class="commerce-help-text" title="{{ order_entity.getCompletedTime|format_date('short') }}">{{ order_entity.getState.getLabel }}</span>
                {% else %}
                  {{ order_entity.getState.getLabel }}
                {% endif %}
              </div>
            </div>
            {% if stores_count > 1 and order.store_id %}
              <div class="form-item order-admin__state-field order-admin__state-field--store">
                {{ order.store_id }}
              </div>
            {% endif %}
            {{ order.uid }}
            {{ order.ip_address }}
          </div>
        {% endblock %}
      {% endembed %}
    </div>
    <div class="order-admin__actions-card">
      {% embed 'commerce:commerce-admin-card' with {
        id: 'order-actions'
      } %}
        {% block card_content %}
          {% if order_entity.getState.getTransitions is not empty %}
            <div class="commerce-actions__actions order-admin__state-transitions">
              {{ order.state }}
            </div>
          {% else %}
            {{ 'No transitions available.'|t }}
          {% endif %}
        {% endblock %}
      {% endembed %}
    </div>
    <div class="order-admin__details-card">
      {% embed 'commerce:commerce-admin-card' with {
        id: 'order-details',
        title: 'Order details'|t,
        title_tag: 'h4',
        badge: edit_order_modal_link|default(''),
      } %}
        {% block card_content %}
          <div class="order-admin__details-fields">
            {{ order_details_fields }}
            {{ additional_order_fields }}
          </div>
        {% endblock %}
      {% endembed %}
    </div>
    <div class="order-admin__footnote">
      {% if order.created.0 %}
        <span class="order-admin__footnote-item">
          {{ 'Created'|t }} {{ order.created.0 }}
        </span>
      {% endif %}
      {% if order.changed.0 %}
        <span class="order-admin__footnote-item">
          {{ 'Updated'|t }} {{ order.changed.0 }}
        </span>
      {% endif %}
      {% if order.completed.0 %}
        <span class="order-admin__footnote-item">
          {{ 'Completed'|t }} {{ order.completed.0 }}
        </span>
      {% endif %}
    </div>
  </div>
</div>
