@if($policies->isEmpty())
    <div class="p-12 text-center">
        <svg class="mx-auto h-12 w-12 text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8c-1.657 0-3 .895-3 2s1.343 2 3 2 3 .895 3 2-1.343 2-3 2m0-8c1.11 0 2.08.402 2.599 1M12 8V7m0 1v8m0 0v1m0-1c-1.11 0-2.08-.402-2.599-1M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
        </svg>
        <h3 class="mt-2 text-sm font-medium text-gray-900">등록된 정책이 없습니다</h3>
        <p class="mt-1 text-sm text-gray-500">시더를 실행하여 기본 정책을 등록해주세요.</p>
    </div>
@else
    <div class="overflow-auto">
        <table class="min-w-full divide-y divide-gray-200">
            <thead class="bg-gray-50">
                <tr>
                    <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
                        서비스
                    </th>
                    <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
                        기본 제공량
                    </th>
                    <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
                        추가 과금
                    </th>
                    <th scope="col" class="px-6 py-3 text-center text-xs font-medium text-gray-500 uppercase tracking-wider">
                        상태
                    </th>
                    <th scope="col" class="px-6 py-3 text-right text-xs font-medium text-gray-500 uppercase tracking-wider w-20">
                        관리
                    </th>
                </tr>
            </thead>
            <tbody class="bg-white divide-y divide-gray-200">
                @foreach($policies as $policy)
                    @php
                        $colors = [
                            'card' => ['bg' => 'bg-blue-100', 'text' => 'text-blue-800'],
                            'tax_invoice' => ['bg' => 'bg-purple-100', 'text' => 'text-purple-800'],
                            'bank_account' => ['bg' => 'bg-green-100', 'text' => 'text-green-800'],
                        ];
                        $color = $colors[$policy->service_type] ?? ['bg' => 'bg-gray-100', 'text' => 'text-gray-800'];
                    @endphp
                    <tr class="hover:bg-gray-50 transition-colors group">
                        <td class="px-6 py-4 whitespace-nowrap">
                            <div class="flex items-center gap-3">
                                <span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium {{ $color['bg'] }} {{ $color['text'] }}">
                                    {{ $policy->name }}
                                </span>
                            </div>
                            @if($policy->description)
                            <p class="text-xs text-gray-400 mt-1">{{ $policy->description }}</p>
                            @endif
                        </td>
                        <td class="px-6 py-4 whitespace-nowrap">
                            <span class="text-sm font-medium text-gray-900">{{ number_format($policy->free_quota) }}{{ $policy->free_quota_unit }}</span>
                            <span class="text-xs text-gray-500">무료</span>
                        </td>
                        <td class="px-6 py-4 whitespace-nowrap">
                            @if($policy->additional_price > 0)
                                @if($policy->additional_unit > 1)
                                    <span class="text-sm text-gray-900">{{ number_format($policy->additional_unit) }}{{ $policy->additional_unit_label }} 단위</span>
                                @else
                                    <span class="text-sm text-gray-900">1{{ $policy->additional_unit_label }}당</span>
                                @endif
                                <span class="text-sm font-medium text-red-600">{{ number_format($policy->additional_price) }}원</span>
                            @else
                                <span class="text-sm text-gray-400">-</span>
                            @endif
                        </td>
                        <td class="px-6 py-4 whitespace-nowrap text-center">
                            <span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full {{ $policy->is_active ? 'bg-green-100 text-green-800' : 'bg-gray-100 text-gray-800' }}">
                                {{ $policy->is_active ? '활성' : '비활성' }}
                            </span>
                        </td>
                        <td class="px-6 py-4 whitespace-nowrap text-right">
                            <button
                                type="button"
                                onclick="editPolicy({{ $policy->id }}, {{ json_encode($policy) }})"
                                class="p-2 text-blue-600 hover:bg-blue-50 rounded-lg opacity-30 group-hover:opacity-100 transition"
                                title="수정"
                            >
                                <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z" />
                                </svg>
                            </button>
                        </td>
                    </tr>
                @endforeach
            </tbody>
        </table>
    </div>

    <!-- 안내 메시지 -->
    <div class="p-4 bg-gray-50 border-t border-gray-200">
        <p class="text-xs text-gray-500 flex items-center gap-1">
            <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
            </svg>
            이 정책은 월별 과금 처리 시 적용됩니다. 기본 제공량을 초과한 사용량에 대해 추가 과금이 발생합니다.
        </p>
    </div>
@endif
