{% extends "admin/base.html" %}
{% import "macros/ui.html" as ui %}

{% block title %}{{ t(key="admin-orders", lang=lang | default(value='sk')) }}{% endblock title %}
{% block crumb %}{{ t(key="admin-orders", lang=lang | default(value='sk')) }}{% endblock crumb %}

{% block content %}
{% set L = lang | default(value='sk') %}
<div class="flex flex-wrap items-center justify-between gap-3">
  <h1 class="text-2xl font-bold text-on-surface-strong dark:text-on-surface-dark-strong">{{ t(key="admin-orders", lang=L) }}</h1>

  <!-- order search: order number, customer, email, company, phone, tracking -->
  <form method="get" action="/admin/orders" role="search" class="relative w-full max-w-xs">
    <span class="pointer-events-none absolute inset-y-0 left-0 flex items-center pl-3 text-on-surface/50 dark:text-on-surface-dark/50">
      {{ ui::icon(name="search", size="size-5") }}
    </span>
    <input type="search" name="q" value="{{ query | default(value='') }}" autocomplete="off"
      placeholder="{{ t(key='order-search-placeholder', lang=L) }}" aria-label="{{ t(key='order-search-placeholder', lang=L) }}"
      class="w-full rounded-radius border border-outline bg-surface py-2 pl-10 pr-3 text-sm text-on-surface placeholder:text-on-surface/50 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary dark:border-outline-dark dark:bg-surface-dark-alt dark:text-on-surface-dark dark:placeholder:text-on-surface-dark/50 dark:focus-visible:outline-primary-dark">
  </form>
</div>

{% if query and query != "" %}
<p class="mt-2 text-sm text-on-surface/70 dark:text-on-surface-dark/70">{{ t(key="results-count", lang=L, count=total) }} · “{{ query }}”</p>
{% endif %}

<div class="mt-6 {{ ui::table_wrap_cls() }}">
  {% if orders | length > 0 %}
  <table class="{{ ui::table_cls() }}">
    <thead class="{{ ui::thead_cls() }}">
      <tr>
        {{ ui::th(label=t(key="order-number", lang=lang | default(value='sk'))) }}
        {{ ui::th(label=t(key="order-customer", lang=lang | default(value='sk'))) }}
        {{ ui::th(label=t(key="order-status", lang=lang | default(value='sk'))) }}
        {{ ui::th(label=t(key="order-total", lang=lang | default(value='sk')), align="text-right") }}
        {{ ui::th(label="") }}
      </tr>
    </thead>
    <tbody class="{{ ui::tbody_cls() }}">
      {% for order in orders %}
      <tr class="{{ ui::row_cls() }}">
        <td class="px-4 py-3 font-mono font-medium text-on-surface-strong dark:text-on-surface-dark-strong">{{ order.order_number }}</td>
        <td class="px-4 py-3">{{ order.email }}</td>
        <td class="px-4 py-3">
          {{ ui::badge(label=t(key="order-status-" ~ order.status, lang=lang | default(value='sk')), variant="neutral") }}
        </td>
        <td class="px-4 py-3 text-right tabular-nums">{{ order.total }} €</td>
        <td class="px-4 py-3 text-right">
          {{ ui::button(variant="outline-secondary", label=t(key="view", lang=lang | default(value='sk')), href="/admin/orders/" ~ order.id, size="px-3 py-1.5 text-xs") }}
        </td>
      </tr>
      {% endfor %}
    </tbody>
  </table>
  {% else %}
  <div class="px-4 py-16 text-center text-on-surface/70 dark:text-on-surface-dark/70">{{ t(key="admin-no-orders", lang=lang | default(value='sk')) }}</div>
  {% endif %}
</div>
{% endblock content %}
