<div class="mb-8 relative">
    <div class="flex items-center justify-between gap-3 mb-6 pb-4 border-b border-slate-100">
        <div class="flex items-center gap-3">
            <div class="p-2 bg-indigo-50 rounded-lg text-indigo-600">
                <svg class="w-6 h-6" 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"></path></svg>
            </div>
            <div>
                <h3 class="text-xl font-bold text-slate-800">إدارة العملات (Currencies)</h3>
                <p class="text-slate-500 text-sm mt-1">إضافة وتعديل العملات التي سيتعامل معها النظام، مع وحدات التفقيط الخاصة بها.</p>
            </div>
        </div>
        @if(!$isEditing)
            <button wire:click.prevent="create" class="bg-indigo-600 hover:bg-indigo-700 text-white px-4 py-2 rounded-lg text-sm font-bold shadow transition flex items-center gap-2">
                <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="M12 4v16m8-8H4"></path></svg>
                إضافة عملة
            </button>
        @endif
    </div>

    @if (session()->has('currency_message'))
        <div class="mb-6 p-4 bg-emerald-50 text-emerald-800 rounded-xl flex items-center gap-3 border border-emerald-200">
            <svg class="w-5 h-5 text-emerald-600" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"></path></svg>
            <span class="font-bold text-sm">{{ session('currency_message') }}</span>
        </div>
    @endif

    @if($isEditing)
        <div class="bg-slate-50 p-6 rounded-2xl border border-slate-200 shadow-inner mb-6">
            <h4 class="font-bold text-slate-700 mb-6 pb-2 border-b border-slate-200">
                {{ $editId ? 'تعديل عملة' : 'إضافة عملة جديدة' }}
            </h4>
            <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
                <div>
                    <label class="block text-sm font-bold text-slate-700 mb-2">رمز العملة (Code)</label>
                    <input type="text" wire:model="form.code" class="w-full border-slate-300 rounded-xl shadow-sm focus:ring-indigo-500 focus:border-indigo-500 text-sm p-3" placeholder="مثال: SAR">
                    @error('form.code') <span class="text-rose-500 text-xs mt-1 block">{{ $message }}</span> @enderror
                </div>
                <div>
                    <label class="block text-sm font-bold text-slate-700 mb-2">اسم العملة (Name)</label>
                    <input type="text" wire:model="form.name" class="w-full border-slate-300 rounded-xl shadow-sm focus:ring-indigo-500 focus:border-indigo-500 text-sm p-3" placeholder="مثال: ريال سعودي">
                    @error('form.name') <span class="text-rose-500 text-xs mt-1 block">{{ $message }}</span> @enderror
                </div>
                <div>
                    <label class="block text-sm font-bold text-slate-700 mb-2">إشارة العملة (Symbol)</label>
                    <input type="text" wire:model="form.symbol" class="w-full border-slate-300 rounded-xl shadow-sm focus:ring-indigo-500 focus:border-indigo-500 text-sm p-3" placeholder="مثال: ر.س">
                </div>
                <div>
                    <label class="block text-sm font-bold text-slate-700 mb-2">حالة العملة</label>
                    <select wire:model="form.is_active" class="w-full border-slate-300 rounded-xl shadow-sm focus:ring-indigo-500 focus:border-indigo-500 text-sm p-3 bg-white">
                        <option value="1">نشطة (فعالة)</option>
                        <option value="0">معطلة</option>
                    </select>
                </div>
                <div class="md:col-span-2 grid grid-cols-2 gap-6 bg-white p-4 rounded-xl border border-slate-200">
                    <h5 class="col-span-2 text-xs font-bold text-slate-400 uppercase tracking-wider">وحدات التفقيط</h5>
                    <div>
                        <label class="block text-sm font-bold text-slate-700 mb-2">الوحدة الكبرى (Major Unit)</label>
                        <input type="text" wire:model="form.major_unit" class="w-full border-slate-300 rounded-xl shadow-sm focus:ring-indigo-500 focus:border-indigo-500 text-sm p-3" placeholder="مثال: ريال">
                    </div>
                    <div>
                        <label class="block text-sm font-bold text-slate-700 mb-2">الوحدة الصغرى (Minor Unit)</label>
                        <input type="text" wire:model="form.minor_unit" class="w-full border-slate-300 rounded-xl shadow-sm focus:ring-indigo-500 focus:border-indigo-500 text-sm p-3" placeholder="مثال: هللة">
                    </div>
                </div>
            </div>
            
            <div class="mt-6 flex justify-end gap-3">
                <button wire:click.prevent="cancel" type="button" class="bg-white border border-slate-300 text-slate-700 hover:bg-slate-50 px-5 py-2.5 rounded-xl text-sm font-bold shadow-sm transition">
                    إلغاء
                </button>
                <button wire:click.prevent="save" type="button" class="bg-indigo-600 hover:bg-indigo-700 text-white px-5 py-2.5 rounded-xl text-sm font-bold shadow-md transition">
                    حفظ العملة
                </button>
            </div>
        </div>
    @endif

    @if(!$isEditing)
        <div class="bg-white border border-slate-200 rounded-2xl shadow-sm overflow-hidden">
            <table class="w-full text-right text-sm">
                <thead class="bg-slate-50 border-b border-slate-200 text-slate-500">
                    <tr>
                        <th class="p-4 font-bold">الرمز</th>
                        <th class="p-4 font-bold">اسم العملة</th>
                        <th class="p-4 font-bold">الإشارة</th>
                        <th class="p-4 font-bold">التفقيط (كبرى/صغرى)</th>
                        <th class="p-4 font-bold text-center">الحالة</th>
                        <th class="p-4 font-bold text-center">إجراءات</th>
                    </tr>
                </thead>
                <tbody class="divide-y divide-slate-100">
                    @forelse($currencies as $currency)
                        <tr class="hover:bg-slate-50 transition">
                            <td class="p-4 font-bold text-indigo-700">{{ $currency->code }}</td>
                            <td class="p-4 font-semibold text-slate-800">{{ $currency->name }}</td>
                            <td class="p-4 text-slate-600">{{ $currency->symbol }}</td>
                            <td class="p-4 text-slate-600">{{ $currency->major_unit }} / {{ $currency->minor_unit }}</td>
                            <td class="p-4 text-center">
                                @if($currency->is_active)
                                    <span class="bg-emerald-100 text-emerald-700 px-3 py-1 rounded-full text-xs font-bold">نشط</span>
                                @else
                                    <span class="bg-rose-100 text-rose-700 px-3 py-1 rounded-full text-xs font-bold">معطل</span>
                                @endif
                            </td>
                            <td class="p-4 text-center">
                                <div class="flex justify-center gap-2">
                                    <button wire:click.prevent="edit({{ $currency->id }})" class="text-slate-400 hover:text-indigo-600 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="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"></path></svg>
                                    </button>
                                    <button wire:click.prevent="delete({{ $currency->id }})" wire:confirm="هل أنت متأكد من حذف هذه العملة؟" class="text-slate-400 hover:text-rose-600 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="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"></path></svg>
                                    </button>
                                </div>
                            </td>
                        </tr>
                    @empty
                        <tr>
                            <td colspan="6" class="p-8 text-center text-slate-400 font-bold">
                                لا يوجد عملات مضافة حالياً.
                            </td>
                        </tr>
                    @endforelse
                </tbody>
            </table>
        </div>
    @endif
</div>
