@extends('layouts.app')

@section('title')
    {{ $pageInfo['title'] }}
@endsection


@section('admin-content')
    <section class="content-header">
        <div class="container-fluid">
            <div class="row mb-2">
                <div class="col-sm-6">
                    <h1>{{ $pageInfo['title'] }}</h1>
                </div>
                <div class="col-sm-6">
                    <ol class="breadcrumb float-sm-right">
                        <li class="breadcrumb-item"><a href="{{ route('admin.dashboard') }}">{{ __('Dashboard') }}</a></li>
                        <li class="breadcrumb-item active"><a href="{{ $pageInfo['path'] }}">{{ $pageInfo['title'] }}</a>
                        </li>
                    </ol>
                </div>
            </div>
        </div>
    </section>

    <section class="content">
        <div class="container-fluid">
            <div class="row">
                <div class="col-12">
                    <div class="card">
                        <div class="card-body">
                            <h4 class="header-title float-left">{{ $pageInfo['title'] }}</h4>
                            <p class="float-right mb-2">
                                @if (auth()->user()->can('admin.edit'))
                                    <a class="btn btn-primary text-white" href="{{ route('admin.admins.create') }}">
                                        Add New User Access
                                    </a>
                                @endif
                            </p>
                            <div class="clearfix"></div>
                            <div class="data-tables">
                                @include('backend.layouts.partials.messages')
                                <div class="table-responsive">
                                    <table id="dataTable" class="text-center">
                                        <thead class="bg-light text-capitalize">
                                            <tr>
                                                <th width="5%">{{ __('Sl') }}</th>
                                                <th width="10%">{{ __('Name') }}</th>
                                                <th width="10%">{{ __('Email') }}</th>
                                                <th width="20%">{{ __('Roles') }}</th>
                                                <th width="5%">Region</th>
                                                <th width="5%">Cabang</th>
                                                <th width="5%">Rayon</th>
                                                <th width="15%">{{ __('Action') }}</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            @foreach ($admins as $admin)
                                                <tr>
                                                    <td>{{ $loop->index + 1 }}</td>
                                                    <td>{{ $admin->name }}</td>
                                                    <td>{{ $admin->email }}</td>
                                                    <td>
                                                        @foreach ($admin->roles as $role)
                                                            <span class="badge badge-info mr-1">
                                                                {{ $role->name }}
                                                            </span>
                                                        @endforeach
                                                    </td>
                                                    <td>{{ $admin->getRegion->name ?? '-' }}</td>
													<td>{{ $admin->cabang->cabang->name ?? '-' }}</td>
                                                    <td>{{ $admin->getRayon->name ?? '-' }}</td>
                                                    <td>
                                                        <a class="btn btn-success text-white" href="{{ route('admin.admins.expense', $admin->id) }}">View Expense</a>
                                                        @if (auth()->user()->can('admin.edit'))
                                                            <a class="btn btn-success text-white"
                                                                href="{{ route('admin.admins.edit', $admin->id) }}">Edit</a>
                                                        @endif

                                                        @if (auth()->user()->can('admin.delete'))
                                                            <a class="btn btn-danger text-white" href="javascript:void(0);"
                                                                onclick="event.preventDefault(); if(confirm('Are you sure you want to delete?')) { document.getElementById('delete-form-{{ $admin->id }}').submit(); }">
                                                                {{ __('Delete') }}
                                                            </a>

                                                            <form id="delete-form-{{ $admin->id }}"
                                                                action="{{ route('admin.admins.destroy', $admin->id) }}"
                                                                method="POST" style="display: none;">
                                                                @method('DELETE')
                                                                @csrf
                                                            </form>
                                                        @endif
                                                    </td>
                                                </tr>
                                            @endforeach
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>
@endsection

@section('scripts')
    <script>
        $(document).ready(function () {
            if ($('#dataTable').length) {
                $('#dataTable').DataTable({
                    responsive: false,
                    dom: 'Bfrtip',
                    buttons: [
                        'excel', 'pdf', 'print'
                    ]
                });
            }
        });
    </script>
@endsection
