@extends ('layouts/template')

@section('content')

<div class="p-3 mcp-theme-1">
    <div class="card">

        <div class="card-header px-2 py-1 d-flex align-items-center">
            <strong class="mr-4">
                <i class="fas fa-user"></i>
                Accounts Invites ({{ $accountInvites->total() }})
            </strong>
        </div>
        <div class="card-body p-0">
        <div class="p-3">
                @include('app.practice-management.patients-accounts-invites-filters')
            </div>
            <table class="table table-sm table-striped border-top p-0 m-0">
                <thead class="bg-light">
                    <tr>
                        <th class="text-secondary border-0">Created At</th>
                        <th class="text-secondary border-0">Client</th>
                        <th class="text-secondary border-0">Name</th>
                        <th class="text-secondary border-0">Email</th>
                        <th class="text-secondary border-0">Cell Number</th>
                        <th class="text-secondary border-0">Status</th>
                        <th class="text-secondary border-0">&nbsp;</th>
                    </tr>
                </thead>
                <tbody>
                    @foreach($accountInvites as $accountInvite)
                    <tr>                        
                        <td>
                            {{ friendlier_date_time($accountInvite->created_at) }}
                            @if($accountInvite->status === 'CANCELLED')
                            <span class="text-sm text-secondary">(CANCELLED)</span>
                            @endif
                        </td>
                        <td>{{ $accountInvite->client->displayName() }}</td>
                        <td>{{ $accountInvite->first_name }} {{ $accountInvite->last_name }}</pre>
                        </td>
                        <td>{{ $accountInvite->to_email_address }}</td>
                        <td>{{ $accountInvite->cell_number }}</td>
                        <td>{{ $accountInvite->status }} <span class="text-sm text-secondary">(Updated: {{friendlier_date_time($accountInvite->status_updated_at)}})</span>
                            @if($accountInvite->status_memo)
                            <div class="py-1 font-italic text-secondary text-sm">{{$accountInvite->status_memo}}</div>
                            @endif
                        </td>
                        <td>
                            <div class="d-flex">
                                @if($accountInvite->status === 'PENDING')
                                <span moe class="ml-1" relative>
                                    <a class="" href="" show start>Cancel</a>
                                    <form url="/api/accountInvite/markAsCancelled" right>
                                        <input type="hidden" name="uid" value="{{$accountInvite->uid}}">
                                        <p>Cancel this invite?</p>
                                        <div class="mb-0">
                                            <button class="btn btn-primary btn-sm" submit>Submit</button>
                                            <button class="btn btn-default border btn-sm" cancel>Cancel</button>
                                        </div>
                                    </form>
                                </span>
                                @endif
                                @if($accountInvite->status == 'CANCELLED')
                                <span moe class="ml-1" relative>
                                    <a class="" href="" show start>Undo Cancel</a>
                                    <form url="/api/accountInvite/undoMarkAsCancelled" right>
                                        <input type="hidden" name="uid" value="{{$accountInvite->uid}}">
                                        <p>Un-cancel this invite?</p>
                                        <div class="mb-0">
                                            <button class="btn btn-primary btn-sm" submit>Submit</button>
                                            <button class="btn btn-default border btn-sm" cancel>Cancel</button>
                                        </div>
                                    </form>
                                </span>
                                @endif
                            </div>
                        </td>
                    </tr>
                    @endforeach
                </tbody>
            </table>
            <div class="ml-2 mt-2">
                {{ $accountInvites->appends(request()->input())->links() }}
            </div>
        </div>
    </div>
</div>

@endsection