{{-- 파트너별 현황 탭 --}}
<div class="space-y-6">
    {{-- 필터 --}}
    <div class="bg-white rounded-lg shadow-sm p-4">
        <form hx-get="{{ route('finance.settlement.partner-summary') }}"
              hx-target="#partner-content"
              hx-trigger="submit"
              class="grid grid-cols-1 md:grid-cols-4 gap-4">
            <div>
                <label class="block text-sm font-medium text-gray-700 mb-1">검색</label>
                <input type="text" name="search" placeholder="파트너명 / 파트너코드"
                       value="{{ request('search') }}"
                       class="w-full rounded-lg border-gray-300 focus:border-indigo-500 focus:ring-indigo-500">
            </div>
            <div>
                <label class="block text-sm font-medium text-gray-700 mb-1">유형</label>
                <select name="type" class="w-full rounded-lg border-gray-300 focus:border-indigo-500 focus:ring-indigo-500">
                    <option value="">전체</option>
                    <option value="individual" {{ request('type') == 'individual' ? 'selected' : '' }}>개인</option>
                    <option value="corporate" {{ request('type') == 'corporate' ? 'selected' : '' }}>단체</option>
                </select>
            </div>
            <div>
                <label class="block text-sm font-medium text-gray-700 mb-1">상태</label>
                <select name="status" class="w-full rounded-lg border-gray-300 focus:border-indigo-500 focus:ring-indigo-500">
                    <option value="active" {{ request('status', 'active') == 'active' ? 'selected' : '' }}>활성</option>
                    <option value="all" {{ request('status') == 'all' ? 'selected' : '' }}>전체</option>
                </select>
            </div>
            <div class="flex items-end">
                <button type="submit" class="w-full px-4 py-2 bg-indigo-600 hover:bg-indigo-700 text-white rounded-lg transition-colors">
                    조회
                </button>
            </div>
        </form>
    </div>

    {{-- 테이블 --}}
    <div class="bg-white rounded-lg shadow-sm overflow-hidden">
        <div class="overflow-x-auto">
            <table class="min-w-full divide-y divide-gray-200">
                <thead class="bg-gray-50">
                    <tr>
                        <th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">파트너명</th>
                        <th class="px-4 py-3 text-center text-xs font-medium text-gray-500 uppercase tracking-wider">유형</th>
                        <th class="px-4 py-3 text-center text-xs font-medium text-gray-500 uppercase tracking-wider">수당률</th>
                        <th class="px-4 py-3 text-center text-xs font-medium text-gray-500 uppercase tracking-wider">계약건수</th>
                        <th class="px-4 py-3 text-right text-xs font-medium text-gray-500 uppercase tracking-wider">누적 수당</th>
                        <th class="px-4 py-3 text-right text-xs font-medium text-gray-500 uppercase tracking-wider">미지급</th>
                        <th class="px-4 py-3 text-right text-xs font-medium text-gray-500 uppercase tracking-wider">지급완료</th>
                        <th class="px-4 py-3 text-center text-xs font-medium text-gray-500 uppercase tracking-wider">최근 지급일</th>
                        <th class="px-4 py-3 text-center text-xs font-medium text-gray-500 uppercase tracking-wider">액션</th>
                    </tr>
                </thead>
                <tbody class="bg-white divide-y divide-gray-200">
                    @forelse ($partners as $partner)
                        @php
                            $stats = $commissionStats[$partner->id] ?? null;
                            $paidTotal = $stats->paid_total ?? 0;
                            $unpaidTotal = $stats->unpaid_total ?? 0;
                            $totalCount = $stats->total_count ?? $partner->total_contracts ?? 0;
                            $lastPaidDate = $stats->last_paid_date ?? null;
                        @endphp
                        <tr class="hover:bg-gray-50">
                            <td class="px-4 py-3">
                                <div class="text-sm font-medium text-gray-900">{{ $partner->user?->name ?? '-' }}</div>
                                <div class="text-xs text-gray-500">{{ $partner->partner_code }}</div>
                            </td>
                            <td class="px-4 py-3 text-center">
                                @if ($partner->partner_type === 'corporate')
                                    <span class="inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium bg-amber-100 text-amber-700">단체</span>
                                @else
                                    <span class="inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium bg-sky-100 text-sky-700">개인</span>
                                @endif
                            </td>
                            <td class="px-4 py-3 text-center text-sm text-gray-900">
                                {{ $partner->commission_rate }}%
                            </td>
                            <td class="px-4 py-3 text-center text-sm text-gray-900">
                                {{ number_format($totalCount) }}
                            </td>
                            <td class="px-4 py-3 text-right text-sm font-medium text-gray-900">
                                {{ number_format($paidTotal + $unpaidTotal) }}원
                            </td>
                            <td class="px-4 py-3 text-right text-sm font-medium {{ $unpaidTotal > 0 ? 'text-red-600' : 'text-gray-400' }}">
                                {{ number_format($unpaidTotal) }}원
                            </td>
                            <td class="px-4 py-3 text-right text-sm font-medium text-green-600">
                                {{ number_format($paidTotal) }}원
                            </td>
                            <td class="px-4 py-3 text-center text-sm text-gray-500">
                                {{ $lastPaidDate ? \Carbon\Carbon::parse($lastPaidDate)->format('Y-m-d') : '-' }}
                            </td>
                            <td class="px-4 py-3 text-center">
                                <a href="{{ route('finance.settlement', ['tab' => 'commission', 'partner_id' => $partner->id]) }}"
                                   class="inline-flex items-center px-2.5 py-1 text-xs font-medium text-indigo-600 hover:text-indigo-800 hover:bg-indigo-50 rounded transition-colors">
                                    상세보기
                                </a>
                            </td>
                        </tr>
                    @empty
                        <tr>
                            <td colspan="9" class="px-4 py-8 text-center text-gray-500">
                                등록된 파트너가 없습니다.
                            </td>
                        </tr>
                    @endforelse
                </tbody>
            </table>
        </div>

        @if ($partners->hasPages())
            <div class="px-4 py-3 border-t border-gray-200">
                {{ $partners->links() }}
            </div>
        @endif
    </div>
</div>
