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

    <div class="grid gap-4 lg:grid-cols-3">
        <x-filament::section>
            <x-slot name="heading">客户数</x-slot>
            <div style="font-size: 24px; font-weight: 700; color: #111827;">{{ $totals['customer_count'] ?? 0 }}</div>
        </x-filament::section>
        <x-filament::section>
            <x-slot name="heading">风险客户数</x-slot>
            <div style="font-size: 24px; font-weight: 700; color: #b45309;">{{ $totals['blocked_count'] ?? 0 }}</div>
        </x-filament::section>
        <x-filament::section>
            <x-slot name="heading">逾期笔数合计</x-slot>
            <div style="font-size: 24px; font-weight: 700; color: #dc2626;">{{ $totals['overdue_count'] ?? 0 }}</div>
        </x-filament::section>
    </div>

    <x-filament::section>
        <x-slot name="heading">客户信用概览</x-slot>

        <div style="overflow-x: auto;">
            <table style="width: 100%; border-collapse: collapse; font-size: 13px;">
                <thead>
                    <tr style="background: #f9fafb; border-bottom: 1px solid #e5e7eb;">
                        <th style="padding: 10px; text-align: left;">客户</th>
                        <th style="padding: 10px; text-align: left;">{{ __('dberp.fields.price_level_code') }}</th>
                        <th style="padding: 10px; text-align: right;">默认账期</th>
                        <th style="padding: 10px; text-align: right;">信用额度</th>
                        <th style="padding: 10px; text-align: right;">当前占用</th>
                        <th style="padding: 10px; text-align: right;">预计占用</th>
                        <th style="padding: 10px; text-align: right;">逾期笔数</th>
                        <th style="padding: 10px; text-align: right;">逾期金额</th>
                        <th style="padding: 10px; text-align: left;">最早逾期日</th>
                        <th style="padding: 10px; text-align: left;">信用结果</th>
                    </tr>
                </thead>
                <tbody>
                    @forelse ($rows as $row)
                        <tr style="border-bottom: 1px solid #f3f4f6;">
                            <td style="padding: 10px;">{{ $row['customer_name'] }}</td>
                            <td style="padding: 10px;">{{ $row['price_level_label'] ?? ($row['price_level_code'] ?: '-') }}</td>
                            <td style="padding: 10px; text-align: right;">{{ $row['default_payment_term_days'] ?? '-' }}</td>
                            <td style="padding: 10px; text-align: right;">{{ $row['credit_limit_amount'] !== '' ? $row['credit_limit_amount'] : '-' }}</td>
                            <td style="padding: 10px; text-align: right;">{{ $row['occupied_amount'] ?: '-' }}</td>
                            <td style="padding: 10px; text-align: right;">{{ $row['projected_amount'] ?: '-' }}</td>
                            <td style="padding: 10px; text-align: right;">{{ $row['overdue_count'] }}</td>
                            <td style="padding: 10px; text-align: right;">{{ $row['overdue_amount'] ?: '-' }}</td>
                            <td style="padding: 10px;">{{ $row['earliest_due_date'] ?: '-' }}</td>
                            <td style="padding: 10px;">
                                <span style="display: inline-flex; align-items: center; border-radius: 999px; padding: 3px 10px; background: {{ $row['credit_check_result'] === 'pass' ? '#ecfdf5' : '#fff7ed' }}; color: {{ $row['credit_check_result'] === 'pass' ? '#047857' : '#c2410c' }};">
                                    {{ $row['credit_check_result_label'] }}
                                </span>
                            </td>
                        </tr>
                    @empty
                        <tr>
                            <td colspan="10" style="padding: 18px; text-align: center; color: #6b7280;">当前筛选下暂无客户信用数据。</td>
                        </tr>
                    @endforelse
                </tbody>
            </table>
        </div>
    </x-filament::section>
</x-filament-panels::page>