@extends('admin.layouts.app')
@section('content')
<div class="row">
    <div class="col-12">
        <div class="card">
            <div class="card-body">
                @include('admin.partial.list-filter', ['filterRoute' => 'users.index', 'extraFilterView' => 'admin.users.partial-filter'])
                <div id="datatable_wrapper" class="dataTables_wrapper dt-bootstrap4 no-footer">
                    <div class="row">
                        <div class="col-sm-12">
                            <table id="datatable" class="table table-bordered dt-responsive nowrap dataTable no-footer dtr-inline" style="border-collapse: collapse; border-spacing: 0px; width: 100%;" role="grid" aria-describedby="datatable_info">
                                <thead>
                                    <tr role="row">
                                        <th>نام</th>
                                        <th>ایمیل</th>
                                        <th>شماره تلفن</th>
                                        <th>نوع</th>
                                        <th>روز اشتراک</th>
                                        <th>عملیات</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    @foreach ($users as $user)
                                    <tr>
                                        <td>{{ $user->name }}</td>
                                        <td>{{ $user->email }}</td>
                                        <td>{{ $user->mobile }}</td>
                                        <td>{{ $user->is_admin ? 'ادمین' : 'مشتری' }}</td>
                                        <td>
                                            {{ $user->userSubscribers->sum(function ($subscriber) { return $subscriber->expired_at ? $subscriber->expired_at->diffInDays(now()) : 0; }) }}
                                        </td>
                                        <td>
                                            <form action="{{ route('users.destroy', $user->id) }}" id="user-{{$user->id}}-delete" method="POST" style="display: inline;">
                                                @csrf
                                                @method('DELETE')
                                                <button type="submit" class="btn btn-danger waves-effect waves-light" onclick="return confirm('آیا مطمئنید که می‌خواهید این کاربر را حذف کنید؟')">حذف</button>
                                            </form>
                                            <a href="{{route('users.edit',$user->id)}}" type="button" class="btn btn-primary waves-effect waves-light">ویرایش</a>
                                        </td>
                                    </tr>
                                    @endforeach
                                </tbody>
                            </table>
                        </div>
                    </div>
                    <div class="d-flex justify-content-center mt-3">
                        {{ $users->withQueryString()->links() }}
                    </div>
                </div>

            </div>

        </div>
    </div>
</div>
@endsection
