@extends('admin.layouts.default')

@section('page_title', trans('common.card_requests'))

@section('content')
<div class="container-fluid">
    <div class="card card-custom">
        <div class="card-header">
            <h3 class="card-title">{{ trans('common.card_requests') }}</h3>
        </div>
        <div class="card-body">
            <div class="table-responsive">
                <table class="table table-head-custom table-vertical-center" id="kt_advance_table_widget_1">
                    <thead>
                        <tr class="text-left text-uppercase">
                            <th>{{ trans('common.member') }}</th>
                            <th>{{ trans('common.card') }}</th>
                            <th>{{ trans('common.club') }}</th>
                            <th>{{ trans('common.created') }}</th>
                            <th class="text-right">{{ trans('common.actions') }}</th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach($applications as $app)
                        <tr>
                            <td>
                                <div class="d-flex align-items-center">
                                    <div class="symbol symbol-40 symbol-light-primary mr-3">
                                        <span class="symbol-label font-size-h5 font-weight-bold">{{ substr($app->members->first()->name ?? 'M', 0, 1) }}</span>
                                    </div>
                                    <div>
                                        <a href="#" class="text-dark-75 font-weight-bolder text-hover-primary mb-1 font-size-lg">{{ $app->members->first()->name ?? 'N/A' }}</a>
                                        <span class="text-muted font-weight-bold d-block">{{ $app->members->first()->email ?? '' }}</span>
                                    </div>
                                </div>
                            </td>
                            <td>
                                <span class="label label-lg label-inline label-light-info font-weight-bold">{{ $app->name }}</span>
                                <small class="d-block text-muted">{{ $app->unique_identifier }}</small>
                            </td>
                            <td>{{ $app->club->name ?? '-' }}</td>
                            <td>{{ $app->created_at->format('Y-m-d H:i') }}</td>
                            <td class="text-right">
                                <form action="{{ route('admin.card-requests.approve', $app->id) }}" method="POST" style="display:inline;">
                                    @csrf
                                    <button type="submit" class="btn btn-sm btn-success font-weight-bolder pr-5 pl-5">
                                        <i class="fa fa-check p-0"></i> {{ trans('common.approve') }}
                                    </button>
                                </form>
                                
                                <form action="{{ route('admin.card-requests.destroy', $app->id) }}" method="POST" style="display:inline;" onsubmit="return confirm('Are you sure?')">
                                    @csrf
                                    @method('DELETE')
                                    <button type="submit" class="btn btn-sm btn-icon btn-light-danger">
                                        <i class="fa fa-trash"></i>
                                    </button>
                                </form>
                            </td>
                        </tr>
                        @endforeach
                    </tbody>
                </table>
            </div>
            @if($applications->isEmpty())
                <div class="text-center p-10">
                    <img src="{{ asset('assets/media/logos/empty.svg') }}" style="width:100px" class="mb-5 opacity-20">
                    <p class="text-muted font-size-h6">مفيش طلبات جديدة حالياً.. الدنيا هادية!</p>
                </div>
            @endif
        </div>
    </div>
</div>
@stop