@extends('layouts.app')

@section('content')
<div class="container mx-auto px-4 py-6">
    <div class="mb-6">
        <h1 class="text-2xl font-bold text-gray-800">إدارة الترجمات</h1>
        <p class="text-gray-600">البحث والتصفية</p>
    </div>

    <div class="bg-white rounded-xl shadow-lg p-6 mb-6">
        <form method="GET" class="space-y-4">
            <div class="grid grid-cols-1 md:grid-cols-3 gap-4">
                <div>
                    <label class="block text-sm font-medium text-gray-700 mb-2">البحث</label>
                    <input type="text" name="search" placeholder="ابحث عن كلمة..." value="{{ request('search') }}" class="w-full rounded-lg border border-gray-300 px-3 py-2 focus:outline-none focus:border-blue-500 focus:ring-2 focus:ring-blue-200">
                </div>

                <div>
                    <label class="block text-sm font-medium text-gray-700 mb-2">اللغة</label>
                    <select name="language_id" class="w-full rounded-lg border border-gray-300 px-3 py-2">
                        <option value="">جميع اللغات</option>
                        @foreach($languages as $lang)
                        <option value="{{ $lang->id }}" @selected($languageId == $lang->id)>
                            {{ $lang->flag_emoji }} {{ $lang->name }}
                        </option>
                        @endforeach
                    </select>
                </div>

                <div class="flex items-end">
                    <button type="submit" class="w-full px-4 py-2 bg-blue-600 hover:bg-blue-700 text-white rounded-lg transition-colors">
                        <i class="fas fa-search ml-1"></i> بحث
                    </button>
                </div>
            </div>
        </form>
    </div>

    <div class="bg-white rounded-xl shadow-lg overflow-hidden border border-gray-200">
        <div class="overflow-x-auto">
            <table class="w-full">
                <thead class="bg-gradient-to-r from-gray-800 to-gray-900 text-white">
                    <tr>
                        <th class="px-6 py-4 text-right font-semibold text-sm">#</th>
                        <th class="px-6 py-4 text-right font-semibold text-sm">اللغة</th>
                        <th class="px-6 py-4 text-right font-semibold text-sm">المفتاح</th>
                        <th class="px-6 py-4 text-right font-semibold text-sm">الترجمة</th>
                        <th class="px-6 py-4 text-right font-semibold text-sm">المجموعة</th>
                        <th class="px-6 py-4 text-right font-semibold text-sm">الحالة</th>
                        <th class="px-6 py-4 text-center font-semibold text-sm">الإجراءات</th>
                    </tr>
                </thead>
                <tbody class="divide-y divide-gray-200">
                    @forelse($translations as $translation)
                    <tr class="hover:bg-blue-50 transition-colors duration-150">
                        <td class="px-6 py-4 text-gray-600 font-medium">{{ $loop->iteration }}</td>
                        <td class="px-6 py-4">
                            <span class="inline-flex items-center px-3 py-1 rounded-full text-sm font-medium bg-blue-100 text-blue-800">
                                {{ $translation->language->flag_emoji }} {{ $translation->language->code }}
                            </span>
                        </td>
                        <td class="px-6 py-4">
                           <td class="px-6 py-4">
    <code class="bg-gray-100 px-2 py-1 rounded text-sm">{{ $translation->translationKey?->key ?? 'بدون مفتاح' }}</code>
</td>
<td class="px-6 py-4 max-w-xs">{{ Str::limit($translation->value, 50) }}</td>
<td class="px-6 py-4">{{ $translation->translationKey?->group ?? '-' }}</td>

                        <td class="px-6 py-4">
                            @if($translation->status === 'draft')
                            <span class="inline-flex items-center px-3 py-1 rounded-full text-sm font-medium bg-yellow-100 text-yellow-800">
                                <i class="fas fa-pause-circle ml-1"></i> مسودة
                            </span>
                            @elseif($translation->status === 'published')
                            <span class="inline-flex items-center px-3 py-1 rounded-full text-sm font-medium bg-green-100 text-green-800">
                                <i class="fas fa-check-circle ml-1"></i> منشورة
                            </span>
                            @else
                            <span class="inline-flex items-center px-3 py-1 rounded-full text-sm font-medium bg-blue-100 text-blue-800">
                                <i class="fas fa-thumbs-up ml-1"></i> موافق عليها
                            </span>
                            @endif
                        </td>
                        <td class="px-6 py-4">
                            <div class="flex items-center justify-center gap-1">
                                <a href="{{ route('localization.translations.edit', $translation) }}" class="inline-flex items-center px-3 py-2 rounded-lg bg-amber-100 text-amber-600 hover:bg-amber-200 transition-all duration-150 text-sm font-medium" title="تعديل">
                                    <i class="fas fa-edit"></i>
                                </a>
                                <form action="{{ route('localization.translations.destroy', $translation) }}" method="POST" style="display:inline;">
                                    @csrf
                                    @method('DELETE')
                                    <button type="submit" class="inline-flex items-center px-3 py-2 rounded-lg bg-red-100 text-red-600 hover:bg-red-200 transition-all duration-150 text-sm font-medium" title="حذف" onclick="return confirm('هل أنت متأكد؟')">
                                        <i class="fas fa-trash"></i>
                                    </button>
                                </form>
                            </div>
                        </td>
                    </tr>
                    @empty
                    <tr>
                        <td colspan="7" class="px-6 py-4 text-center text-gray-500">
                            لا توجد نتائج
                        </td>
                    </tr>
                    @endforelse
                </tbody>
            </table>
        </div>
    </div>

    @if($translations->hasPages())
    <div class="mt-6">
        {{ $translations->links() }}
    </div>
    @endif
</div>
@endsection
