<x-filament-panels::page>
    {{ $this->form }}

    <h2 class="text-base font-semibold leading-6 text-gray-950 dark:text-white mt-6">
        {{ __('dberp.resources.purchase_analysis.section_summary') }}
    </h2>
    <div class="grid gap-4 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 2xl:grid-cols-6">
        @foreach ([
            ['k' => 'order_count', 'label' => __('dberp.resources.purchase_analysis.card_order_count')],
            ['k' => 'total_amount', 'label' => __('dberp.resources.purchase_analysis.card_total_amount')],
            ['k' => 'paid_amount', 'label' => __('dberp.resources.purchase_analysis.card_paid')],
            ['k' => 'unpaid_amount', 'label' => __('dberp.resources.purchase_analysis.card_unpaid')],
            ['k' => 'total_quantity', 'label' => __('dberp.resources.purchase_analysis.card_total_qty')],
            ['k' => 'arrived_quantity', 'label' => __('dberp.resources.purchase_analysis.card_arrived_qty')],
            ['k' => 'remaining_arrival_quantity', 'label' => __('dberp.resources.purchase_analysis.card_remaining_arrival')],
            ['k' => 'overdue_arrival_order_count', 'label' => __('dberp.resources.purchase_analysis.card_overdue_orders')],
            ['k' => 'partial_received_order_count', 'label' => __('dberp.resources.purchase_analysis.card_partial_received')],
            ['k' => 'fully_received_order_count', 'label' => __('dberp.resources.purchase_analysis.card_fully_received')],
            ['k' => 'exception_count', 'label' => __('dberp.resources.purchase_analysis.card_exceptions')],
            ['k' => 'return_order_count', 'label' => __('dberp.resources.purchase_analysis.card_returns')],
        ] as $card)
            <div class="fi-wi-stats-overview-stat">
                <div class="fi-wi-stats-overview-stat-content">
                    <div class="fi-wi-stats-overview-stat-label-ctn">
                        <span class="fi-wi-stats-overview-stat-label">{{ $card['label'] }}</span>
                    </div>
                    <div class="fi-wi-stats-overview-stat-value">
                        {{ $this->dberpFormatReportScalar($card['k'], $this->summary[$card['k']] ?? null) }}
                    </div>
                </div>
            </div>
        @endforeach
    </div>

    <h2 class="text-base font-semibold leading-6 text-gray-950 dark:text-white">
        {{ __('dberp.resources.purchase_analysis.section_trend') }}
    </h2>
    <div class="fi-ta-ctn">
        <div class="fi-ta-main overflow-x-auto">
            <table class="fi-ta-table w-full table-auto divide-y divide-gray-200 text-start text-sm dark:divide-white/5">
                    <thead>
                        <tr>
                            <th class="px-4 py-3 text-start text-sm font-semibold text-gray-950 dark:text-white">
                                {{ __('dberp.resources.purchase_analysis.trend_date') }}
                            </th>
                            <th class="px-4 py-3 text-start text-sm font-semibold text-gray-950 dark:text-white">
                                {{ __('dberp.resources.purchase_analysis.trend_orders') }}
                            </th>
                            <th class="px-4 py-3 text-start text-sm font-semibold text-gray-950 dark:text-white">
                                {{ __('dberp.resources.purchase_analysis.trend_amount') }}
                            </th>
                        </tr>
                    </thead>
                    <tbody>
                        @forelse ($this->trend as $row)
                            <tr>
                                <td class="px-4 py-3 text-sm text-gray-950 dark:text-white">{{ $row['date'] }}</td>
                                <td class="px-4 py-3 text-sm text-gray-950 dark:text-white">{{ $row['order_count'] }}</td>
                                <td class="px-4 py-3 text-sm text-gray-950 dark:text-white">{{ $this->dberpFormatReportScalar('amount', $row['amount'] ?? null) }}</td>
                            </tr>
                        @empty
                            <tr>
                                <td colspan="3" class="px-4 py-8 text-center text-sm text-gray-500 dark:text-gray-400">
                                    {{ __('dberp.resources.purchase_analysis.empty_trend') }}
                                </td>
                            </tr>
                        @endforelse
                    </tbody>
            </table>
        </div>
    </div>

    <div class="grid gap-6 lg:grid-cols-2">
        <div class="grid gap-2">
            <h2 class="text-base font-semibold leading-6 text-gray-950 dark:text-white">
                {{ __('dberp.resources.purchase_analysis.section_supplier') }}
            </h2>
            <div class="fi-ta-ctn">
                <div class="fi-ta-main overflow-x-auto">
                    <table class="fi-ta-table w-full table-auto divide-y divide-gray-200 text-start text-sm dark:divide-white/5">
                        <thead>
                            <tr>
                                <th class="px-4 py-3 text-start text-sm font-semibold text-gray-950 dark:text-white">
                                    {{ __('dberp.resources.purchase_analysis.col_name') }}
                                </th>
                                <th class="px-4 py-3 text-start text-sm font-semibold text-gray-950 dark:text-white">
                                    {{ __('dberp.resources.purchase_analysis.col_amount') }}
                                </th>
                                <th class="px-4 py-3 text-start text-sm font-semibold text-gray-950 dark:text-white">
                                    {{ __('dberp.resources.purchase_analysis.col_orders') }}
                                </th>
                            </tr>
                        </thead>
                        <tbody>
                            @forelse ($this->topSuppliers as $row)
                                <tr>
                                    <td class="px-4 py-3 text-sm text-gray-950 dark:text-white">{{ $row['name'] }}</td>
                                    <td class="px-4 py-3 text-sm text-gray-950 dark:text-white">{{ $this->dberpFormatReportScalar('amount', $row['amount'] ?? null) }}</td>
                                    <td class="px-4 py-3 text-sm text-gray-950 dark:text-white">{{ $row['order_count'] }}</td>
                                </tr>
                            @empty
                                <tr>
                                    <td colspan="3" class="px-4 py-6 text-center text-sm text-gray-500 dark:text-gray-400">{{ __('dberp.resources.purchase_analysis.empty_structure') }}</td>
                                </tr>
                            @endforelse
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
        <div class="grid gap-2">
            <h2 class="text-base font-semibold leading-6 text-gray-950 dark:text-white">
                {{ __('dberp.resources.purchase_analysis.section_product') }}
            </h2>
            <div class="fi-ta-ctn">
                <div class="fi-ta-main overflow-x-auto">
                    <table class="fi-ta-table w-full table-auto divide-y divide-gray-200 text-start text-sm dark:divide-white/5">
                        <thead>
                            <tr>
                                <th class="px-4 py-3 text-start text-sm font-semibold text-gray-950 dark:text-white">
                                    {{ __('dberp.resources.purchase_analysis.col_name') }}
                                </th>
                                <th class="px-4 py-3 text-start text-sm font-semibold text-gray-950 dark:text-white">
                                    {{ __('dberp.resources.purchase_analysis.col_amount') }}
                                </th>
                                <th class="px-4 py-3 text-start text-sm font-semibold text-gray-950 dark:text-white">
                                    {{ __('dberp.resources.purchase_analysis.col_qty') }}
                                </th>
                            </tr>
                        </thead>
                        <tbody>
                            @forelse ($this->topProducts as $row)
                                <tr>
                                    <td class="px-4 py-3 text-sm text-gray-950 dark:text-white">{{ $row['name'] }}</td>
                                    <td class="px-4 py-3 text-sm text-gray-950 dark:text-white">{{ $this->dberpFormatReportScalar('amount', $row['amount'] ?? null) }}</td>
                                    <td class="px-4 py-3 text-sm text-gray-950 dark:text-white">{{ $this->dberpFormatReportScalar('quantity', $row['quantity'] ?? null) }}</td>
                                </tr>
                            @empty
                                <tr>
                                    <td colspan="3" class="px-4 py-6 text-center text-sm text-gray-500 dark:text-gray-400">{{ __('dberp.resources.purchase_analysis.empty_structure') }}</td>
                                </tr>
                            @endforelse
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</x-filament-panels::page>
