{{-- 정산 상세 모달 --}}
<div class="p-6 border-b border-gray-200">
    <div class="flex items-center justify-between">
        <h3 class="text-lg font-semibold text-gray-800">정산 상세</h3>
        <button type="button" onclick="closeDetailModal()" class="text-gray-400 hover:text-gray-600">
            <svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"/>
            </svg>
        </button>
    </div>
</div>

@if ($commission)
<div class="p-6">
    {{-- 기본 정보 --}}
    <div class="grid grid-cols-2 gap-4 mb-6">
        <div>
            <h4 class="text-sm font-medium text-gray-500 mb-1">테넌트</h4>
            <p class="text-gray-900">{{ $commission->tenant->name ?? $commission->tenant->company_name ?? '-' }}</p>
        </div>
        <div>
            <h4 class="text-sm font-medium text-gray-500 mb-1">상태</h4>
            @php
                $statusColors = [
                    'pending' => 'bg-yellow-100 text-yellow-800',
                    'approved' => 'bg-blue-100 text-blue-800',
                    'paid' => 'bg-green-100 text-green-800',
                    'cancelled' => 'bg-red-100 text-red-800',
                ];
            @endphp
            <span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium {{ $statusColors[$commission->status] ?? 'bg-gray-100 text-gray-800' }}">
                {{ $commission->status_label }}
            </span>
        </div>
        <div>
            <h4 class="text-sm font-medium text-gray-500 mb-1">입금 구분</h4>
            <span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium
                {{ $commission->payment_type === 'deposit' ? 'bg-blue-100 text-blue-800' : 'bg-green-100 text-green-800' }}">
                {{ $commission->payment_type_label }}
            </span>
        </div>
        <div>
            <h4 class="text-sm font-medium text-gray-500 mb-1">입금일</h4>
            <p class="text-gray-900">{{ $commission->payment_date->format('Y-m-d') }}</p>
        </div>
    </div>

    {{-- 금액 정보 --}}
    <div class="bg-gray-50 rounded-lg p-4 mb-6">
        <h4 class="text-sm font-medium text-gray-700 mb-3">금액 정보</h4>
        <div class="space-y-2">
            <div class="flex justify-between">
                <span class="text-gray-600">입금액</span>
                <span class="font-medium">{{ number_format($commission->payment_amount) }}원</span>
            </div>
            <div class="flex justify-between">
                <span class="text-gray-600">수당 기준액 (개발비 50%)</span>
                <span class="font-medium">{{ number_format($commission->base_amount) }}원</span>
            </div>
        </div>
    </div>

    {{-- 수당 정보 --}}
    <div class="bg-emerald-50 rounded-lg p-4 mb-6">
        <h4 class="text-sm font-medium text-emerald-800 mb-3">수당 정보</h4>
        <div class="space-y-2">
            <div class="flex justify-between items-center">
                <div>
                    <span class="text-gray-700">영업파트너</span>
                    <span class="text-sm text-gray-500 ml-2">{{ $commission->partner?->user?->name ?? '-' }}</span>
                </div>
                <div class="text-right">
                    <span class="text-xs text-gray-500">{{ $commission->partner_rate }}%</span>
                    <span class="ml-2 font-medium text-emerald-600">{{ number_format($commission->partner_commission) }}원</span>
                </div>
            </div>
            <div class="flex justify-between items-center">
                <div>
                    <span class="text-gray-700">매니저</span>
                    <span class="text-sm text-gray-500 ml-2">{{ $commission->manager?->name ?? '-' }}</span>
                </div>
                <div class="text-right">
                    <span class="text-xs text-gray-500">{{ $commission->manager_rate }}%</span>
                    <span class="ml-2 font-medium text-blue-600">{{ number_format($commission->manager_commission) }}원</span>
                </div>
            </div>
            <div class="border-t border-emerald-200 pt-2 mt-2 flex justify-between">
                <span class="font-medium text-gray-700">총 수당</span>
                <span class="font-bold text-emerald-700">{{ number_format($commission->total_commission) }}원</span>
            </div>
        </div>
    </div>

    {{-- 지급 일정 --}}
    <div class="grid grid-cols-2 gap-4 mb-6">
        <div>
            <h4 class="text-sm font-medium text-gray-500 mb-1">지급예정일</h4>
            <p class="text-gray-900">{{ $commission->scheduled_payment_date->format('Y-m-d') }}</p>
        </div>
        <div>
            <h4 class="text-sm font-medium text-gray-500 mb-1">실제지급일</h4>
            <p class="text-gray-900">{{ $commission->actual_payment_date?->format('Y-m-d') ?? '-' }}</p>
        </div>
    </div>

    {{-- 승인 정보 --}}
    @if ($commission->approved_at)
        <div class="grid grid-cols-2 gap-4 mb-6">
            <div>
                <h4 class="text-sm font-medium text-gray-500 mb-1">승인자</h4>
                <p class="text-gray-900">{{ $commission->approver?->name ?? '-' }}</p>
            </div>
            <div>
                <h4 class="text-sm font-medium text-gray-500 mb-1">승인일시</h4>
                <p class="text-gray-900">{{ $commission->approved_at->format('Y-m-d H:i') }}</p>
            </div>
        </div>
    @endif

    {{-- 이체 참조번호 --}}
    @if ($commission->bank_reference)
        <div class="mb-6">
            <h4 class="text-sm font-medium text-gray-500 mb-1">이체 참조번호</h4>
            <p class="text-gray-900">{{ $commission->bank_reference }}</p>
        </div>
    @endif

    {{-- 메모 --}}
    @if ($commission->notes)
        <div class="mb-6">
            <h4 class="text-sm font-medium text-gray-500 mb-1">메모</h4>
            <p class="text-gray-900">{{ $commission->notes }}</p>
        </div>
    @endif

    {{-- 상품별 상세 내역 --}}
    @if ($commission->details->count() > 0)
        <div class="mb-6">
            <h4 class="text-sm font-medium text-gray-700 mb-3">상품별 수당 내역</h4>
            <div class="border rounded-lg overflow-hidden">
                <table class="min-w-full divide-y divide-gray-200">
                    <thead class="bg-gray-50">
                        <tr>
                            <th class="px-4 py-2 text-left text-xs font-medium text-gray-500">상품</th>
                            <th class="px-4 py-2 text-right text-xs font-medium text-gray-500">개발비</th>
                            <th class="px-4 py-2 text-right text-xs font-medium text-gray-500">파트너수당</th>
                            <th class="px-4 py-2 text-right text-xs font-medium text-gray-500">매니저수당</th>
                        </tr>
                    </thead>
                    <tbody class="divide-y divide-gray-200">
                        @foreach ($commission->details as $detail)
                            <tr>
                                <td class="px-4 py-2 text-sm text-gray-900">{{ $detail->contractProduct?->product?->name ?? '-' }}</td>
                                <td class="px-4 py-2 text-sm text-right text-gray-900">{{ number_format($detail->registration_fee) }}원</td>
                                <td class="px-4 py-2 text-sm text-right text-emerald-600">{{ number_format($detail->partner_commission) }}원</td>
                                <td class="px-4 py-2 text-sm text-right text-blue-600">{{ number_format($detail->manager_commission) }}원</td>
                            </tr>
                        @endforeach
                    </tbody>
                </table>
            </div>
        </div>
    @endif

    {{-- 액션 버튼 --}}
    <div class="flex justify-end gap-2">
        @if ($commission->status === 'pending')
            <button type="button"
                    onclick="approveCommission({{ $commission->id }})"
                    class="px-4 py-2 bg-blue-600 hover:bg-blue-700 text-white rounded-lg transition-colors">
                승인
            </button>
            <button type="button"
                    onclick="cancelCommission({{ $commission->id }})"
                    class="px-4 py-2 bg-red-600 hover:bg-red-700 text-white rounded-lg transition-colors">
                취소
            </button>
        @elseif ($commission->status === 'approved')
            <button type="button"
                    onclick="unapproveCommission({{ $commission->id }})"
                    class="px-4 py-2 bg-yellow-500 hover:bg-yellow-600 text-white rounded-lg transition-colors">
                승인취소
            </button>
            <button type="button"
                    onclick="markPaidCommission({{ $commission->id }})"
                    class="px-4 py-2 bg-green-600 hover:bg-green-700 text-white rounded-lg transition-colors">
                지급완료
            </button>
        @endif
        <button type="button"
                onclick="closeDetailModal()"
                class="px-4 py-2 bg-gray-200 hover:bg-gray-300 text-gray-700 rounded-lg transition-colors">
            닫기
        </button>
    </div>
</div>
@else
<div class="p-6 text-center text-gray-500">
    정산 정보를 찾을 수 없습니다.
</div>
@endif
