<div id="history-table-container">
    <table class="min-w-full divide-y divide-gray-200">
        <thead class="bg-gray-50">
            <tr>
                <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">ID</th>
                <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">발송자</th>
                <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">대상</th>
                <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">제목</th>
                <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">결과</th>
                <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">상태</th>
                <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">발송일시</th>
            </tr>
        </thead>
        <tbody class="bg-white divide-y divide-gray-200">
            @forelse($logs as $log)
                <tr>
                    <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">{{ $log->id }}</td>
                    <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900">{{ $log->sender?->name ?? '-' }}</td>
                    <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
                        {{ $log->tenant?->company_name ?? '전체' }}
                        @if($log->platform)
                            <span class="ml-1 text-xs text-gray-400">({{ $log->platform }})</span>
                        @endif
                    </td>
                    <td class="px-6 py-4 whitespace-nowrap">
                        <div class="text-sm font-medium text-gray-900 truncate max-w-[200px]" title="{{ $log->title }}">{{ $log->title }}</div>
                        <div class="text-sm text-gray-500 truncate max-w-[200px]" title="{{ $log->body }}">{{ $log->body }}</div>
                    </td>
                    <td class="px-6 py-4 whitespace-nowrap">
                        <div class="text-sm">
                            <span class="text-green-600">{{ $log->success_count }}/{{ $log->total_count }}</span>
                            <span class="text-gray-400">({{ $log->success_rate }}%)</span>
                        </div>
                        @if($log->invalid_token_count > 0)
                            <div class="text-xs text-red-500">무효: {{ $log->invalid_token_count }}</div>
                        @endif
                    </td>
                    <td class="px-6 py-4 whitespace-nowrap">
                        <span class="px-2 py-1 text-xs rounded-full
                            @if($log->status === 'pending') bg-gray-100 text-gray-800
                            @elseif($log->status === 'sending') bg-blue-100 text-blue-800
                            @elseif($log->status === 'completed') bg-green-100 text-green-800
                            @else bg-red-100 text-red-800
                            @endif">
                            @switch($log->status)
                                @case('pending') 대기 @break
                                @case('sending') 발송 중 @break
                                @case('completed') 완료 @break
                                @case('failed') 실패 @break
                                @default {{ $log->status }}
                            @endswitch
                        </span>
                        @if($log->error_message)
                            <div class="text-xs text-red-500 mt-1">{{ $log->error_message }}</div>
                        @endif
                    </td>
                    <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
                        {{ $log->created_at?->format('Y-m-d H:i') ?? '-' }}
                    </td>
                </tr>
            @empty
                <tr>
                    <td colspan="7" class="px-6 py-12 text-center text-gray-500">
                        발송 이력이 없습니다.
                    </td>
                </tr>
            @endforelse
        </tbody>
    </table>

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