{{define "content"}}
<div class="space-y-6">
    <div class="sm:flex sm:items-center sm:justify-between">
        <h1 class="text-2xl font-bold text-gray-900">Orders</h1>
        <a href="/orders/new" class="inline-flex items-center rounded-md bg-indigo-600 px-3 py-2 text-sm font-semibold text-white shadow-sm hover:bg-indigo-500">
            + New Order
        </a>
    </div>

    <!-- Status Filter -->
    <div class="flex space-x-2">
        <a href="/orders"
            class="{{if eq .FilterStatus ""}}bg-indigo-100 text-indigo-700{{else}}bg-white text-gray-700 hover:bg-gray-50{{end}} rounded-md px-3 py-1.5 text-sm font-medium ring-1 ring-inset ring-gray-300">All</a>
        <a href="/orders?status=draft"
            class="{{if eq .FilterStatus "draft"}}bg-indigo-100 text-indigo-700{{else}}bg-white text-gray-700 hover:bg-gray-50{{end}} rounded-md px-3 py-1.5 text-sm font-medium ring-1 ring-inset ring-gray-300">Draft</a>
        <a href="/orders?status=confirmed"
            class="{{if eq .FilterStatus "confirmed"}}bg-indigo-100 text-indigo-700{{else}}bg-white text-gray-700 hover:bg-gray-50{{end}} rounded-md px-3 py-1.5 text-sm font-medium ring-1 ring-inset ring-gray-300">Confirmed</a>
        <a href="/orders?status=fulfilled"
            class="{{if eq .FilterStatus "fulfilled"}}bg-indigo-100 text-indigo-700{{else}}bg-white text-gray-700 hover:bg-gray-50{{end}} rounded-md px-3 py-1.5 text-sm font-medium ring-1 ring-inset ring-gray-300">Fulfilled</a>
        <a href="/orders?status=cancelled"
            class="{{if eq .FilterStatus "cancelled"}}bg-indigo-100 text-indigo-700{{else}}bg-white text-gray-700 hover:bg-gray-50{{end}} rounded-md px-3 py-1.5 text-sm font-medium ring-1 ring-inset ring-gray-300">Cancelled</a>
    </div>

    <div id="order-table">
        {{template "order-table" .}}
    </div>
</div>
{{end}}

{{define "order-table"}}
<div class="overflow-hidden bg-white shadow ring-1 ring-black ring-opacity-5 sm:rounded-lg">
    <table class="min-w-full divide-y divide-gray-300">
        <thead class="bg-gray-50">
            <tr>
                <th class="py-3.5 pl-4 pr-3 text-left text-sm font-semibold text-gray-900">Order #</th>
                <th class="px-3 py-3.5 text-left text-sm font-semibold text-gray-900">Customer</th>
                <th class="px-3 py-3.5 text-left text-sm font-semibold text-gray-900">Date</th>
                <th class="px-3 py-3.5 text-left text-sm font-semibold text-gray-900">Status</th>
                <th class="px-3 py-3.5 text-right text-sm font-semibold text-gray-900">Amount</th>
                <th class="px-3 py-3.5 text-left text-sm font-semibold text-gray-900">Actions</th>
            </tr>
        </thead>
        <tbody class="divide-y divide-gray-200 bg-white">
            {{if .Orders}}
                {{range .Orders}}
                <tr class="hover:bg-gray-50">
                    <td class="whitespace-nowrap py-4 pl-4 pr-3 text-sm font-medium text-indigo-600">
                        <a href="/orders/{{.ID}}">#{{.ID}}</a>
                    </td>
                    <td class="whitespace-nowrap px-3 py-4 text-sm text-gray-900">
                        <a href="/customers/{{.CustomerID}}" class="hover:text-indigo-600">{{.CustomerName}}</a>
                    </td>
                    <td class="whitespace-nowrap px-3 py-4 text-sm text-gray-500">{{formatDate .OrderDate}}</td>
                    <td class="whitespace-nowrap px-3 py-4 text-sm">{{statusBadge .Status}}</td>
                    <td class="whitespace-nowrap px-3 py-4 text-sm text-gray-900 text-right">{{formatMoney .TotalAmount}}</td>
                    <td class="whitespace-nowrap px-3 py-4 text-sm">
                        <a href="/orders/{{.ID}}" class="text-indigo-600 hover:text-indigo-900">View</a>
                    </td>
                </tr>
                {{end}}
            {{else}}
                <tr>
                    <td colspan="6" class="px-3 py-8 text-center text-sm text-gray-500">No orders found. <a href="/orders/new" class="text-indigo-600 hover:text-indigo-500">Create one</a>.</td>
                </tr>
            {{end}}
        </tbody>
    </table>
</div>
{{end}}
