@extends('admin.layouts.app')

@section('content')
    <section class="section">
        <div class="section-header">
            <h1>{{ $pageTitle }}</h1>
            <div class="section-header-breadcrumb">
                <div class="breadcrumb-item active"><a href="/admin/">{{ trans('admin/main.dashboard') }}</a></div>
                <div class="breadcrumb-item"><a href="/admin/additional_page/montessori_membership_applications">طلبات عضوية المونتيسوري</a></div>
                <div class="breadcrumb-item">{{ $pageTitle }}</div>
            </div>
        </div>

        <div class="section-body">
            @if(!empty(session()->has('msg')))
                <div class="alert alert-success my-25 d-flex align-items-center">
                    <i data-feather="check-square" width="20" height="20" class="mr-2"></i>
                    {{ session()->get('msg') }}
                </div>
            @endif

            <div class="row">
                <div class="col-12">
                    <div class="card">
                        <div class="card-header">
                            <h4>تفاصيل طلب العضوية #{{ $application->id }}</h4>
                        </div>

                        <div class="card-body">
                            @php
                                $formData = is_array($application->form_data) ? $application->form_data : json_decode($application->form_data, true);
                            @endphp

                            <div class="row">
                                <div class="col-12">
                                    <table class="table table-bordered">
                                        @foreach($formData as $key => $value)
                                            @if(!empty($value))
                                                <tr>
                                                    <th style="width: 200px; background: #f8f9fa;">{{ ucfirst(str_replace('_', ' ', $key)) }}</th>
                                                    <td>
                                                        @if(is_string($value) && (Str::startsWith($value, '/store/montessori_membership_files/') || Str::contains($value, ['jpg', 'jpeg', 'png', 'gif'])))
                                                            <div>
                                                                <a href="{{ $value }}" target="_blank">
                                                                    <img src="{{ $value }}" alt="{{ $key }}" style="max-width: 300px; max-height: 300px; border: 1px solid #ddd; border-radius: 4px; padding: 5px;">
                                                                </a>
                                                                <br>
                                                                <small><a href="{{ $value }}" target="_blank">عرض الصورة بالحجم الكامل</a></small>
                                                            </div>
                                                        @else
                                                            {{ $value }}
                                                        @endif
                                                    </td>
                                                </tr>
                                            @endif
                                        @endforeach
                                        <tr>
                                            <th style="background: #f8f9fa;">الحالة</th>
                                            <td>
                                                <span class="badge badge-{{ $application->status == 'approved' ? 'success' : ($application->status == 'pending' ? 'warning' : 'danger') }}">
                                                    @if($application->status == 'approved')
                                                        مقبولة
                                                    @elseif($application->status == 'pending')
                                                        قيد الانتظار
                                                    @else
                                                        مرفوضة
                                                    @endif
                                                </span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <th style="background: #f8f9fa;">تاريخ التسجيل</th>
                                            <td>{{ date('Y-m-d H:i:s', $application->created_at) }}</td>
                                        </tr>
                                    </table>
                                </div>
                            </div>

                            <div class="row mt-4">
                                <div class="col-12">
                                    <form action="/admin/additional_page/montessori_membership_applications/{{ $application->id }}/update-status" method="POST">
                                        {{ csrf_field() }}
                                        <div class="form-group">
                                            <label>تغيير الحالة</label>
                                            <select name="status" class="form-control">
                                                <option value="pending" {{ $application->status == 'pending' ? 'selected' : '' }}>قيد الانتظار</option>
                                                <option value="approved" {{ $application->status == 'approved' ? 'selected' : '' }}>قبول</option>
                                                <option value="rejected" {{ $application->status == 'rejected' ? 'selected' : '' }}>رفض</option>
                                            </select>
                                        </div>
                                        <button type="submit" class="btn btn-primary">حفظ</button>
                                        <a href="/admin/additional_page/montessori_membership_applications" class="btn btn-secondary">رجوع</a>
                                    </form>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>
@endsection
