@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">{{ $pageTitle }}</div>
            </div>
        </div>

        <div class="section-body">
            <section class="card">
                <div class="card-body">
                    <form action="/admin/diploma-counters" method="get" class="row mb-0" id="diplomaCounterFilterForm">
                        <div class="col-12 col-md-4">
                            <div class="form-group">
                                <label for="filter_webinar_id" class="input-label">{{ trans('admin/main.course') }}</label>
                                <select name="webinar_id" id="filter_webinar_id" class="form-control">
                                    <option value="">{{ trans('admin/main.all_courses') }}</option>
                                    @foreach(\App\Models\Webinar::where('status', 'active')->get() as $webinar)
                                        <option value="{{ $webinar->id }}" {{ request()->get('webinar_id') == $webinar->id ? 'selected' : '' }}>{{ $webinar->title }}</option>
                                    @endforeach
                                </select>
                            </div>
                        </div>

                        <div class="col-12 col-md-3 d-flex align-items-end">
                            <button type="submit" id="filterSubmitBtn" class="btn btn-primary w-100">{{ trans('admin/main.filter') }}</button>
                        </div>
                    </form>
                </div>
            </section>

            <section class="card">
                <div class="card-body">
                    <div class="table-responsive">
                        <table class="table table-striped text-center font-14">
                            <tr>
                                <th>{{ trans('admin/main.course') }}</th>
                                <th>عدد الطلبات</th>
                                <th>إجمالي المبيعات</th>
                                <th>عدد المنتجات</th>
                                <th>نسبة الإنجاز</th>
                                <th>عدد المشاركين</th>
                                <th>{{ trans('admin/main.status') }}</th>
                                <th>{{ trans('admin/main.actions') }}</th>
                            </tr>

                            @foreach($counters as $counter)
                                <tr>
                                    <td>{{ $counter->webinar ? $counter->webinar->title : '-' }}</td>
                                    <td>{{ number_format($counter->orders_count) }}</td>
                                    <td>{{ number_format($counter->total_sales, 0) }}</td>
                                    <td>{{ number_format($counter->products_count) }}</td>
                                    <td>{{ number_format($counter->completion_rate) }}%</td>
                                    <td>{{ number_format($counter->participants_count) }}</td>
                                    <td>
                                        @if($counter->is_active)
                                            <span class="badge badge-success">{{ trans('admin/main.active') }}</span>
                                        @else
                                            <span class="badge badge-danger">{{ trans('admin/main.inactive') }}</span>
                                        @endif
                                    </td>
                                    <td>
                                        <div class="btn-group dropdown table-actions">
                                            <a href="/admin/diploma-counters/{{ $counter->id }}/edit" class="btn btn-sm btn-primary mr-1" title="{{ trans('admin/main.edit') }}">
                                                <i class="fa fa-edit"></i> {{ trans('admin/main.edit') }}
                                            </a>
                                            <a href="/admin/diploma-counters/{{ $counter->id }}/delete" class="btn btn-sm btn-danger mr-1 delete-action" title="{{ trans('admin/main.delete') }}">
                                                <i class="fa fa-times"></i> {{ trans('admin/main.delete') }}
                                            </a>
                                            <button type="button" class="btn-transparent dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                                                <i class="fa fa-ellipsis-v"></i>
                                            </button>
                                            <div class="dropdown-menu text-left webinars-lists-dropdown">
                                                <a href="/admin/diploma-counters/{{ $counter->id }}/edit" class="dropdown-item">
                                                    <i class="fa fa-edit"></i> {{ trans('admin/main.edit') }}
                                                </a>
                                                <a href="/admin/diploma-counters/{{ $counter->id }}/delete" class="dropdown-item delete-action">
                                                    <i class="fa fa-times"></i> {{ trans('admin/main.delete') }}
                                                </a>
                                            </div>
                                        </div>
                                    </td>
                                </tr>
                            @endforeach
                        </table>
                    </div>
                </div>

                <div class="card-footer text-center">
                    {{ $counters->appends(request()->input())->links() }}
                </div>
            </section>

            <div class="text-center mt-3">
                <a href="/admin/diploma-counters/create" class="btn btn-primary">{{ trans('admin/main.create') }}</a>
            </div>
        </div>
    </section>
@endsection

