@extends('layouts.admin')

@section('title', 'Admin Dashboard')

@section('content')
    <section class="dashboard-head">
        <div>
            <span class="eyebrow">Operations</span>
            <h1>Admin Dashboard</h1>
        </div>
        <div class="dashboard-actions">
            <a class="button ghost" href="{{ route('admin.orders.index') }}">Orders</a>
            <a class="button primary" href="{{ route('admin.products.create') }}">Add product</a>
        </div>
    </section>

    <section class="metrics">
        @foreach ($metrics as $metric)
            <article class="metric">
                <span>{{ $metric['label'] }}</span>
                <strong>{{ $metric['value'] }}</strong>
                <small>{{ $metric['note'] }}</small>
            </article>
        @endforeach
    </section>

    <section class="admin-grid">
        <article class="panel">
            <div class="panel-head">
                <div>
                    <h2>Recent Orders</h2>
                    <span>Live fulfillment queue</span>
                </div>
                <a class="text-button" href="{{ route('admin.orders.index') }}">View all</a>
            </div>
            <div class="table-wrap">
                <table>
                    <thead>
                        <tr>
                            <th>Order</th>
                            <th>Customer</th>
                            <th>Status</th>
                            <th>Total</th>
                        </tr>
                    </thead>
                    <tbody>
                        @forelse ($orders as $order)
                            <tr>
                                <td><strong>{{ $order->order_number }}</strong></td>
                                <td>{{ $order->customer->name }}</td>
                                <td><span class="status pending">{{ $order->statusLabel() }}</span></td>
                                <td><strong>{{ \App\Models\SiteSetting::formatPrice($order->total) }}</strong></td>
                            </tr>
                        @empty
                            <tr><td colspan="4">No orders yet.</td></tr>
                        @endforelse
                    </tbody>
                </table>
            </div>
        </article>

        <article class="panel">
            <div class="panel-head">
                <div>
                    <h2>Inventory</h2>
                    <span>Low stock alerts</span>
                </div>
            </div>
            <div class="inventory-list">
                @forelse ($inventory as $item)
                    <div class="inventory-item">
                        <div class="inventory-top">
                            <span>{{ $item['name'] }}</span>
                            <span>{{ $item['stock'] }} left</span>
                        </div>
                        <div class="bar"><span style="width: {{ min(100, max(5, $item['stock'] * 20)) }}%"></span></div>
                    </div>
                @empty
                    <p class="empty-state">No low stock items.</p>
                @endforelse
            </div>
        </article>
    </section>

    <section class="panel">
        <div class="panel-head">
            <div>
                <h2>Customers</h2>
            <span>Recent accounts</span>
            </div>
        </div>
        <div class="customer-grid">
            @forelse ($customers as $customer)
                <article class="customer-card">
                    <strong>{{ $customer->name }}</strong>
                    <span>{{ $customer->email }}</span>
                    <small>{{ $customer->created_at->format('M d, Y') }}</small>
                </article>
            @empty
                <p class="empty-state">No customers yet.</p>
            @endforelse
        </div>
    </section>
@endsection
