@extends('adminlte::page')

@section('title', 'IPRS | Contract Users')

@section('content_header')
    <div class="col-9 mx-auto d-flex justify-content-between align-items-center">
        <div class="row">
            <div class="col-sm-9">
                <ol class="breadcrumb">
                    <li class="breadcrumb-item"><a href="{{ route('dashboard') }}">Dashboard</a></li>
                    <li class="breadcrumb-item active">Contract Users</li>
                </ol>
            </div>
            <div class="col-sm-12">
                <h1 class="m-0">Contract Users</h1>
            </div>
        </div>
        <div>
            <div class="d-flex justify-content-end align-content-end">
                <a href="{{ route('sub-account.create') }}" class="btn btn-primary">New User</a>
            </div>
        </div>
    </div>
@stop

@section('plugins.Datatables', true)

@section('content')
    <div class="col-9 mx-auto">
        {{-- Setup data for datatables --}}
        @php
            $headings = [
                'ID',
                'Name',
                'E-Mail',
                'Client',
                'Contract (RID)',
                'Role',
                ['label' => 'Status'],
                ['label' => 'Actions', 'no-export' => true, 'width' => 5],
            ];
        @endphp

        <x-adminlte-card>
            {{-- Minimal example / fill data using the component slot --}}
            <x-adminlte-datatable id="clients-table" :heads="$headings" striped hoverable bordered>
                @foreach($users as $user)
                    <tr>
                        <td>{{ $user->id }}</td>
                        <td>{{ ucfirst($user->name) }}</td>
                        <td>{{ $user->email }}</td>
                        <td class="text-primary" >
                            {{ $user->contract->client->name_fl }}
                        </td>
                        <td>
                            <span class="badge badge-light">{{ $user->contract_rid }}</span>
                        </td>
                        <td>
                            @foreach($roles as $role)
                                @if($user->hasRole($role->name))
                                    <span class="badge rounded-pill bg-info">{{ $role->name }}</span>
                                @endif
                            @endforeach
                        </td>
                        <td>
                            @if($user->status_l == 1)
                                <div class="badge badge-success">Active</div>
                            @else
                                <div class="badge badge-secondary">Locked</div>
                            @endif
                        </td>
                        <td>
                            <nobr>
                                <a href="{{ route('sub-account.show', $user->id) }}"
                                class="btn btn-xs btn-default text-teal mx-1 shadow" title="Details">
                                    <i class="fa fa-lg fa-fw fa-eye"></i>
                                </a>
                                <a href="{{ route('sub-account.edit', $user->id) }}"
                                class="btn btn-xs btn-default text-primary mx-1 shadow" title="Edit">
                                    <i class="fa fa-lg fa-fw fa-pen"></i>
                                </a>

                                <a href="#" class="btn btn-xs btn-default text-danger mx-1 shadow" title="Delete"
                                onclick="function submit() {
                                    if (confirm('Are you sure you want to delete?')) {
                                    document.getElementById('form{{$user->id}}').submit();
                                    }
                                    }
                                    submit()"><i class="fa fa-lg fa-fw fa-trash"></i></a>
                                <form
                                    id="form{{$user->id}}"
                                    action="{{route('sub-account.destroy',$user->id)}}"
                                    method="post">
                                    @csrf
                                    {{method_field('DELETE')}}
                                </form>

                            </nobr>

                        </td>
                    </tr>
                @endforeach
            </x-adminlte-datatable>
        </x-adminlte-card>
    </div>
@stop
