@extends('adminlte::page')

@section('title', 'IPRS | Clients')

@section('content_header')
    <div class="col-10 offset-1 d-flex justify-content-between align-items-center">
        <div class="row">
            <div class="col-sm-8">
                <ol class="breadcrumb">
                    <li class="breadcrumb-item"><a href="{{ route('dashboard') }}">Dashboard</a></li>
                    <li class="breadcrumb-item active">Clients</li>
                </ol>
            </div>
            <div class="col-sm-12">
                <h1 class="m-0">Clients</h1>
            </div>
        </div>
        <div>
            <div class="d-flex justify-content-end align-content-end">
                <a href="{{ route('client.create') }}" class="btn btn-primary">New Client</a>
            </div>
        </div>
    </div>
@stop

@section('plugins.Datatables', true)

@section('content')
    <div class="col-10 offset-1">
        {{-- Setup data for datatables --}}
        @php
            $headings = [
                'ID',
                'ID Code',
                'Organization Name',
                ['label' => 'No. of Contracts'],
                ['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($clients as $row)
                    <tr>
                        <td>{{ $row->rid }}</td>
                        <td>{{ $row->id_code }}</td>
                        <td>{{ $row->name_fl }}</td>
                        <td>{{ $row->contracts->count() }}</td>
                        <td>
                            <nobr>
                                <a href="{{ route('client.show', $row->rid) }}" 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('client.edit', $row->rid) }}" 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{{$row->rid}}').submit();
                                    }
                                    }
                                    submit()"><i class="fa fa-lg fa-fw fa-trash"></i></a>
                                <form
                                    id="form{{$row->rid}}"
                                    action="{{route("client.destroy",$row->rid)}}"
                                    method="post">
                                    @csrf
                                    {{method_field('DELETE')}}
                                </form>
                            </nobr>

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

@stop

@section('css')
    {{-- Add here extra stylesheets --}}
    {{-- <link rel="stylesheet" href="/css/admin_custom.css"> --}}
@stop

@section('js')

@stop
