@php use Carbon\Carbon; @endphp
@extends('adminlte::page')

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

@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">Contracts</li>
                </ol>
            </div>
            <div class="col-sm-12">
                <h1 class="m-0">Contracts</h1>
            </div>
        </div>
        <div>
            <div class="d-flex justify-content-end align-content-end">
                <a href="{{ route('contract.create') }}" class="btn btn-primary">New Contract</a>
            </div>
        </div>
    </div>
@stop

@section('plugins.Datatables', true)

@section('content')
    <div class="col-10 offset-1">
        {{-- Setup data for datatables --}}
        @php
            $headings = [
                'ID',
                'Contract No.',
                ['label' => 'Issue Date', 'width' => 12],
                'Client Name',
                ['label' => 'Begin Date', 'width' => 12],
                ['label' => 'End Date', 'width' => 10],
                ['label' => 'Status'],
                ['label' => 'Tokens'],
                ['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($contracts as $row)
                    <tr>
                        <td>{{ $row->rid }}</td>
                        <td>{{ $row->n_doc }}</td>
                        <td>{{ Carbon::parse($row->d_doc)->format("d-m-Y") }}</td>
                        <td>{{ ucfirst($row->client->name_fl ?? "") }}</td>
                        <td>{{ Carbon::parse($row->d_bgn)->format("d-m-Y") }}</td>
                        <td>{{ Carbon::parse($row->d_end)->format("d-m-Y") }}</td>
                        <td>
                            @if(!Carbon::parse($row->d_end)->isPast())
                                @if($row->in_use == 1)
                                    <div class="badge badge-success">Active</div>
                                @else
                                    <div class="badge badge-secondary">In Active</div>
                                @endif
                            @else
                                <div class="badge badge-danger">Expired</div>
                            @endif
                        </td>
                        <td>12</td>
                        <td>
                            <nobr>
                                <a href="{{ route('contract.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('contract.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("contract.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
