@extends('layouts.master')
@section('title', 'إدارة الصفحات')

@section('content')
<div style="max-width: 800px; margin: 0 auto;">
    <div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 15px;">
        <h2 style="color: #333; font-weight: 800; margin: 0;">إدارة الصفحات</h2>
        <a href="/admin/pages/create" class="btn btn-primary btn-sm" style="font-weight: 700;">+ إنشاء صفحة جديدة</a>
    </div>

    @if (session('flash_notification'))
        <div id="flash">
        @foreach (session('flash_notification', collect())->toArray() as $msg)
            <div class="alert alert-{{ $msg['level'] }}">{{ $msg['message'] }}</div>
        @endforeach
        </div>
    @endif

    <table class="table table-striped">
        <thead>
            <tr>
                <th>العنوان</th>
                <th>الرابط</th>
                <th>الموقع</th>
                <th>الحالة</th>
                <th>إجراءات</th>
            </tr>
        </thead>
        <tbody>
            @forelse($pages as $page)
            <tr>
                <td style="font-weight: 700;">{{ $page->title }}</td>
                <td><a href="/page/{{ $page->slug }}" target="_blank">/page/{{ $page->slug }}</a></td>
                <td>
                    @if($page->position == 'navbar')
                        <span class="badge badge-info">شريط التنقل</span>
                    @elseif($page->position == 'footer')
                        <span class="badge badge-info">الفوتر</span>
                    @elseif($page->position == 'both')
                        <span class="badge badge-info">شريط + فوتر</span>
                    @else
                        <span class="badge badge-warning">بدون عرض</span>
                    @endif
                </td>
                <td>
                    @if($page->is_active)
                        <span class="badge badge-success">مفعّل</span>
                    @else
                        <span class="badge badge-danger">معطّل</span>
                    @endif
                </td>
                <td style="white-space: nowrap;">
                    <a href="/admin/pages/{{ $page->id }}/edit" class="btn btn-primary btn-sm">تعديل</a>
                    <form method="POST" action="/admin/pages/{{ $page->id }}/delete" style="display: inline-block;" onsubmit="return confirm('هل أنت متأكد من حذف هذه الصفحة؟');">
                        {{ csrf_field() }}
                        {{ method_field('DELETE') }}
                        <button type="submit" class="btn btn-danger btn-sm">حذف</button>
                    </form>
                </td>
            </tr>
            @empty
            <tr>
                <td colspan="5" style="text-align: center; color: #666;">لا توجد صفحات</td>
            </tr>
            @endforelse
        </tbody>
    </table>
</div>
@endsection
