@extends('layouts.app')

@section('title', '레코드 변경 이력')

@section('content')
<div class="flex justify-between items-center mb-6">
    <div>
        <h1 class="text-2xl font-bold text-gray-800">레코드 변경 이력</h1>
        <p class="text-sm text-gray-500 mt-1">
            <span class="font-medium">{{ $tableName }}</span> / Row
            <span class="font-medium">{{ $rowId }}</span>
        </p>
    </div>
    <a href="{{ route('trigger-audit.index', ['table_name' => $tableName]) }}"
       class="bg-gray-200 hover:bg-gray-300 text-gray-700 px-4 py-2 rounded-lg text-sm">목록으로</a>
</div>

<!-- 타임라인 -->
<div class="space-y-4">
    @forelse($logs as $log)
    <div class="bg-white rounded-lg shadow-sm p-4 border-l-4
        {{ $log->dml_type === 'INSERT' ? 'border-green-500' : '' }}
        {{ $log->dml_type === 'UPDATE' ? 'border-yellow-500' : '' }}
        {{ $log->dml_type === 'DELETE' ? 'border-red-500' : '' }}">
        <div class="flex justify-between items-start">
            <div class="flex items-center gap-3">
                <span class="px-2 py-1 rounded text-xs font-medium
                    {{ $log->dml_type === 'INSERT' ? 'bg-green-100 text-green-700' : '' }}
                    {{ $log->dml_type === 'UPDATE' ? 'bg-yellow-100 text-yellow-700' : '' }}
                    {{ $log->dml_type === 'DELETE' ? 'bg-red-100 text-red-700' : '' }}">
                    {{ $log->dml_type }}
                </span>
                <span class="text-sm text-gray-500">{{ $log->created_at->format('Y-m-d H:i:s') }}</span>
                <span class="text-xs text-gray-400">{{ $log->db_user }}</span>
            </div>
            <a href="{{ route('trigger-audit.show', $log->id) }}"
               class="text-blue-600 hover:underline text-sm">상세 보기</a>
        </div>

        @if($log->changed_columns)
        <div class="mt-2">
            <span class="text-xs text-gray-500">변경 컬럼:</span>
            @foreach($log->changed_columns as $col)
            <span class="inline-block bg-yellow-100 text-yellow-700 px-2 py-0.5 rounded text-xs mr-1">{{ $col }}</span>
            @endforeach
        </div>
        @endif
    </div>
    @empty
    <div class="bg-white rounded-lg shadow-sm p-8 text-center text-gray-400">
        이 레코드의 변경 이력이 없습니다.
    </div>
    @endforelse
</div>

<!-- 페이지네이션 -->
<div class="mt-4">
    {{ $logs->links() }}
</div>
@endsection
