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

    <div class="grid gap-4 lg:grid-cols-3">
        <x-filament::section>
            <x-slot name="heading">{{ __('dberp.purchase_inquiry_comparison.stat_quote_count') }}</x-slot>
            <div style="font-size: 24px; font-weight: 700; color: #111827;">{{ $totals['quote_count'] ?? 0 }}</div>
        </x-filament::section>
        <x-filament::section>
            <x-slot name="heading">{{ __('dberp.purchase_inquiry_comparison.stat_recommended_count') }}</x-slot>
            <div style="font-size: 24px; font-weight: 700; color: #047857;">{{ $totals['recommended_count'] ?? 0 }}</div>
        </x-filament::section>
        <x-filament::section>
            <x-slot name="heading">{{ __('dberp.purchase_inquiry_comparison.stat_expiring_count') }}</x-slot>
            <div style="font-size: 24px; font-weight: 700; color: #b45309;">{{ $totals['expiring_count'] ?? 0 }}</div>
        </x-filament::section>
    </div>

    <x-filament::section>
        <x-slot name="heading">{{ __('dberp.purchase_inquiry_comparison.section_overview') }}</x-slot>

        <div style="overflow: auto; max-height: 70vh; border: 1px solid #e5e7eb; border-radius: 10px; position: relative;">
            <table style="width: 100%; min-width: 1380px; border-collapse: collapse; font-size: 13px; line-height: 1.55;">
                <colgroup>
                    <col style="width: 130px;">
                    <col style="width: 140px;">
                    <col style="width: 230px;">
                    <col style="width: 170px;">
                    <col style="width: 120px;">
                    <col style="width: 140px;">
                    <col style="width: 170px;">
                    <col style="width: 160px;">
                    <col style="width: 110px;">
                    <col style="width: 110px;">
                    <col style="width: 320px;">
                </colgroup>
                <thead>
                    <tr style="background: #f9fafb; border-bottom: 1px solid #e5e7eb;">
                        <th style="padding: 12px 10px; text-align: left; font-weight: 600; color: #4b5563; white-space: nowrap; position: sticky; top: 0; left: 0; z-index: 40; background: #f9fafb; box-shadow: 1px 0 0 #e5e7eb;">{{ __('dberp.purchase_inquiry_comparison.col_inquiry_no') }}</th>
                        <th style="padding: 12px 10px; text-align: left; font-weight: 600; color: #4b5563; white-space: nowrap; position: sticky; top: 0; z-index: 30; background: #f9fafb;">{{ __('dberp.purchase_inquiry_comparison.col_purchase_request') }}</th>
                        <th style="padding: 12px 10px; text-align: left; font-weight: 600; color: #4b5563; white-space: nowrap; position: sticky; top: 0; z-index: 30; background: #f9fafb;">{{ __('dberp.purchase_inquiry_comparison.col_product') }}</th>
                        <th style="padding: 12px 10px; text-align: left; font-weight: 600; color: #4b5563; white-space: nowrap; position: sticky; top: 0; z-index: 30; background: #f9fafb;">{{ __('dberp.purchase_inquiry_comparison.col_supplier') }}</th>
                        <th style="padding: 12px 10px; text-align: right; font-weight: 600; color: #4b5563; white-space: nowrap; position: sticky; top: 0; z-index: 30; background: #f9fafb;">{{ __('dberp.purchase_inquiry_comparison.col_quote_unit_price') }}</th>
                        <th style="padding: 12px 10px; text-align: right; font-weight: 600; color: #4b5563; white-space: nowrap; position: sticky; top: 0; z-index: 30; background: #f9fafb;">{{ __('dberp.purchase_inquiry_comparison.col_lowest_valid_quote') }}</th>
                        <th style="padding: 12px 10px; text-align: right; font-weight: 600; color: #4b5563; white-space: nowrap; position: sticky; top: 0; z-index: 30; background: #f9fafb;">{{ __('dberp.purchase_inquiry_comparison.col_supplier_last_deal_price') }}</th>
                        <th style="padding: 12px 10px; text-align: right; font-weight: 600; color: #4b5563; white-space: nowrap; position: sticky; top: 0; z-index: 30; background: #f9fafb;">{{ __('dberp.purchase_inquiry_comparison.col_product_last_purchase_price') }}</th>
                        <th style="padding: 12px 10px; text-align: right; font-weight: 600; color: #4b5563; white-space: nowrap; position: sticky; top: 0; z-index: 30; background: #f9fafb;">{{ __('dberp.purchase_inquiry_comparison.col_lead_time') }}</th>
                        <th style="padding: 12px 10px; text-align: right; font-weight: 600; color: #4b5563; white-space: nowrap; position: sticky; top: 0; z-index: 30; background: #f9fafb;">{{ __('dberp.purchase_inquiry_comparison.col_recent_lead_time') }}</th>
                        <th style="padding: 12px 10px; text-align: left; font-weight: 600; color: #4b5563; white-space: nowrap; position: sticky; top: 0; z-index: 30; background: #f9fafb;">{{ __('dberp.purchase_inquiry_comparison.col_hint') }}</th>
                    </tr>
                </thead>
                <tbody>
                    @forelse ($rows as $row)
                        <tr style="border-bottom: 1px solid #f3f4f6; vertical-align: top;">
                            <td style="padding: 11px 10px; white-space: nowrap; color: #374151; position: sticky; left: 0; z-index: 20; background: #ffffff; box-shadow: 1px 0 0 #f3f4f6;">{{ $row['quote_code'] }}</td>
                            <td style="padding: 11px 10px; white-space: nowrap; color: #4b5563;">{{ $row['purchase_request_code'] }}</td>
                            <td style="padding: 11px 10px; color: #1f2937;">{{ $row['product_name'] }}{{ $row['product_spec'] ? ' / '.$row['product_spec'] : '' }}</td>
                            <td style="padding: 11px 10px; white-space: nowrap; color: #374151;">{{ $row['supplier_name'] }}</td>
                            <td style="padding: 11px 10px; text-align: right; white-space: nowrap; color: #111827; font-weight: 600;">{{ \App\Support\DberpNumberFormatter::price($row['unit_price'] ?? null) }}</td>
                            <td style="padding: 11px 10px; text-align: right; white-space: nowrap; color: #4b5563;">{{ $row['lowest_inquiry_unit_price'] ? \App\Support\DberpNumberFormatter::price($row['lowest_inquiry_unit_price']) : '-' }}</td>
                            <td style="padding: 11px 10px; text-align: right; white-space: nowrap; color: #4b5563;">{{ $row['recent_supplier_transaction_unit_price'] ? \App\Support\DberpNumberFormatter::price($row['recent_supplier_transaction_unit_price']) : '-' }}</td>
                            <td style="padding: 11px 10px; text-align: right; white-space: nowrap; color: #4b5563;">{{ $row['recent_product_transaction_unit_price'] ? \App\Support\DberpNumberFormatter::price($row['recent_product_transaction_unit_price']) : '-' }}</td>
                            <td style="padding: 11px 10px; text-align: right; white-space: nowrap; color: #374151;">{{ $row['lead_time_days'] !== null ? __('dberp.purchase_inquiry_comparison.lead_time_days_unit', ['days' => $row['lead_time_days']]) : '-' }}</td>
                            <td style="padding: 11px 10px; text-align: right; white-space: nowrap; color: #6b7280;">{{ $row['recent_supplier_lead_time_days'] !== null ? __('dberp.purchase_inquiry_comparison.lead_time_days_unit', ['days' => $row['recent_supplier_lead_time_days']]) : '-' }}</td>
                            <td style="padding: 11px 10px; min-width: 300px; color: #4b5563;">
                                <div class="{{ $row['is_recommended'] ? 'bg-emerald-100 text-emerald-700 dark:bg-emerald-900/30 dark:text-emerald-300' : 'bg-blue-100 text-blue-700 dark:bg-blue-900/30 dark:text-blue-300' }}" style="display: inline-flex; align-items: center; border-radius: 999px; padding: 3px 10px; margin-bottom: 6px;">
                                    {{ $row['comparison_label'] }}{{ $row['is_recommended'] ? __('dberp.purchase_inquiry_comparison.recommended_suffix') : '' }}
                                </div>
                                <div style="color: #4b5563; line-height: 1.6;">{{ $row['comparison_note'] }}</div>
                            </td>
                        </tr>
                    @empty
                        <tr>
                            <td colspan="11" style="padding: 18px; text-align: center; color: #6b7280;">{{ __('dberp.purchase_inquiry_comparison.empty_filtered') }}</td>
                        </tr>
                    @endforelse
                </tbody>
            </table>
        </div>
    </x-filament::section>
</x-filament-panels::page>
