{% extends "/layouts/main.twig" %}

{% set active_menu = '/admin/orders' %}

{% set xdata %}
list("orders")
{% endset %}

{% block title p__('title', 'Orders')|title %}

{% block template %}
	{# Header #}
	<div class="flex justify-between items-center">
		<div>
			<h1>{{ p__('heading', 'Orders') }}</h1>

			<template x-if="total !== null">
				<div class="text-sm text-content-dimmed md:hidden">
					{{ __('Total :count orders')|replace({':count': '<span x-text="total"></span>'})|raw }}
				</div>
			</template>
		</div>

		<div class="flex gap-2 items-center md:hidden">
			<button type="button" class="hidden w-8 h-8 avatar">
				<i class="text-lg ti ti-adjustments-horizontal"></i>
			</button>
		</div>

		<div class="hidden gap-2 items-center md:flex">
			<button type="button" class="button button-outline button-sm" @click="exportData" :processing="isExporting">
				{% include "/snippets/spinner.twig" %}

				{{ p__('button', 'Export') }}
			</button>
		</div>
	</div>

	{# Filters #}
	{% 
  include "/snippets/filters.twig" with { 
    search: true,
    total: __('Total :count orders'),
    sort: [
      {
        value: null,
        label: p__('label', 'Default')
      },
    
      {
        value: 'created_at',
        label: p__('label', 'Date')
      },
    ],
    filters: [
      {
        label: p__('label', 'Status'),
        model: 'status',
        options: [
          {
            value: 'draft',
            label: p__('order-status', 'Draft')
          },
          {
            value: 'pending',
            label: p__('order-status', 'Pending')
          },
          {
            value: 'failed',
            label: p__('order-status', 'Failed')
          },
          {
            value: 'processing',
            label: p__('order-status', 'Processing')
          },
          {
            value: 'completed',
            label: p__('order-status', 'Completed')
          },
          {
            value: 'cancelled',
            label: p__('order-status', 'Cancelled')
          },
        ]
      },
      {
        label: 'Plan',
        model: 'plan',
        options: [
        ]
      },
      {
        label: p__('label', 'Billing cycle'),
        model: 'billing_cycle',
        options: [
          {
            value: 'monthly',
            label: p__('billing-cycle', 'Monthly')
          },
          {
            value: 'yearly',
            label: p__('billing-cycle', 'Yearly')
          },
          {
            value: 'lifetime',
            label: p__('billing-cycle', 'Lifetime')
          },
          {
            value: 'one-time',
            label: p__('billing-cycle', 'Add-on credit')
          },
        ]
      },
      {
        label: p__('label', 'Workspace'),
        model: 'workspace',
        hidden: true,
      },
      {
        label: p__('label', 'Coupon'),
        model: 'coupon',
        hidden: true,
      },
      {
        label: p__('label', 'Plan snapshot'),
        model: 'plan_snapshot',
        hidden: true,
      },
    ]
  } 
%}

	{# List #}
	<div class="group/list" :data-state="state">
		<div class="hidden group-data-[state=empty]/list:block">
			{% include "sections/empty.twig" with { title: p__('heading', 'Empty result set'), message: __('There are no order yet.'), reset: __('There are no order matching your search.') } %}
		</div>

		<div class="hidden md:grid grid-cols-12 gap-3 items-center px-3 py-2 text-content-dimmed text-xs group-data-[state=empty]/list:hidden">
			<div class="col-span-3">{{ p__('label', 'Order') }}</div>
			<div class="col-span-2">{{ p__('label', 'Status') }}</div>
			<div class="col-span-2">{{ p__('label', 'Credits') }}</div>
			<div class="col-span-2">{{ p__('label', 'Total') }}</div>
			<div class="col-span-2">{{ p__('label', 'Created') }}</div>
			<div class="col-span-1"></div>
		</div>

		<div class="text-sm flex flex-col gap-1 group-data-[state=empty]:hidden">
			{% for i in range(1,5) %}
				{% include "snippets/cards/order.twig" with {placeholder: true, type: 'admin'} %}
			{% endfor %}

			<template x-for="order in resources" :key="order.id">
				{% include "snippets/cards/order.twig" with {ref: 'order', type: 'admin'} %}
			</template>
		</div>
	</div>
{% endblock %}
