@extends('layouts.app')

@section('title', '실행 이력 - ' . $flow->name)

@section('content')
    <!-- 페이지 헤더 -->
    <div class="flex justify-between items-center mb-6">
        <div class="flex items-center gap-4">
            <a href="{{ route('dev-tools.flow-tester.edit', $flow->id) }}"
               class="p-2 text-gray-600 hover:bg-gray-100 rounded-lg transition">
                <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 19l-7-7 7-7" />
                </svg>
            </a>
            <div>
                <h1 class="text-2xl font-bold text-gray-800">실행 이력</h1>
                <p class="text-sm text-gray-500">{{ $flow->name }}</p>
            </div>
        </div>
    </div>

    <!-- 이력 목록 -->
    <div class="bg-white rounded-lg shadow-sm overflow-hidden">
        @if($runs->isEmpty())
            <div class="text-center py-12 text-gray-500">
                <svg class="w-16 h-16 mx-auto mb-4 text-gray-300" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z" />
                </svg>
                <p class="text-lg font-medium">실행 이력이 없습니다</p>
                <p class="text-sm mt-1">플로우를 실행하면 이력이 기록됩니다.</p>
            </div>
        @else
            <table class="w-full">
                <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-right text-xs font-medium text-gray-500 uppercase tracking-wider">액션</th>
                    </tr>
                </thead>
                <tbody class="divide-y divide-gray-200">
                    @foreach($runs as $run)
                        <tr class="hover:bg-gray-50">
                            <td class="px-6 py-4 text-sm text-gray-900">#{{ $run->id }}</td>
                            <td class="px-6 py-4">
                                <span class="px-2 py-1 text-xs font-medium rounded {{ $run->status_color }}">
                                    {{ $run->status_label }}
                                </span>
                            </td>
                            <td class="px-6 py-4 text-sm text-gray-500">
                                {{ $run->completed_steps }}/{{ $run->total_steps ?? '-' }}
                            </td>
                            <td class="px-6 py-4 text-sm text-gray-500">
                                @if($run->duration_ms)
                                    {{ number_format($run->duration_ms / 1000, 2) }}s
                                @else
                                    -
                                @endif
                            </td>
                            <td class="px-6 py-4 text-sm text-gray-500">
                                {{ $run->created_at->format('Y-m-d H:i:s') }}
                            </td>
                            <td class="px-6 py-4 text-right">
                                <a href="{{ route('dev-tools.flow-tester.run-detail', $run->id) }}"
                                   class="text-blue-600 hover:text-blue-800 text-sm">
                                    상세 보기
                                </a>
                            </td>
                        </tr>
                    @endforeach
                </tbody>
            </table>

            <!-- 페이지네이션 -->
            @if($runs->hasPages())
                <div class="px-6 py-4 border-t border-gray-200">
                    {{ $runs->links() }}
                </div>
            @endif
        @endif
    </div>
@endsection
