@extends ('layouts/template')

@section('content')

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

        <div class="card-header p-0">
            <div class="d-flex align-items-center border-bottom px-2 py-1">
                <strong class="mr-4">
                    <i class="fas fa-notes-medical"></i>
                    Notes
                </strong>
                <div class="ml-auto">
                    <div class="d-flex align-items-center">
                        <select class="max-width-300px form-control form-control-sm"
                                id="nf"
                                onchange="fastLoad('/practice-management/notes/' + this.value + '?itr=' + ($('#incl-test-records').prop('checked') ? '1' : ''))">
                            <option value="" {{ $filter === '' ? 'selected' : '' }}>All notes</option>
                            <option value="not-yet-signed" {{ $filter === 'not-yet-signed' ? 'selected' : '' }}>Notes not yet signed</option>
                            <option value="not-yet-signed-but-ally-signed" {{ $filter === 'not-yet-signed-but-ally-signed' ? 'selected' : '' }}>Notes not yet signed (but ally signed)</option>
                        </select>
                        <label class="my-0 ml-3 d-inline-flex align-items-center">
                            <input type="checkbox" id="incl-test-records" {{request()->input('itr') ? 'checked' : ''}}
                                   onchange="fastLoad('/practice-management/notes/' + $('#nf').val() + '?itr=' + ($(this).prop('checked') ? '1' : ''))">
                            <span class="ml-1 text-nowrap">Include test records</span>
                        </label>
                    </div>
                </div>
            </div>
        </div>
        <div class="card-body p-0">

            <table class="table table-sm table-striped p-0 m-0">
                <thead class="bg-light">
                    <tr>
                        <th class="px-3 border-0">Created</th>
                        <th class="border-0">Effective Date</th>
                        <th class="border-0">Patient</th>
                        <th class="border-0 w-50">Pro</th>
                    </tr>
                </thead>
                <tbody>
                    @foreach ($notes as $note)
                    <tr class="{{ $note->is_cancelled ? 'cancelled-item always-clickable' : '' }}">
                        <td class="px-3">
                            {{ friendly_date_time($note->created_at, true) }}
                        </td>
                        <td class="">
                            <a href="/patients/view/{{ $note->client->uid }}/notes/view/{{ $note->uid }}">
                                {{ friendly_date_time($note->effective_dateest, false) }}
                            </a>
                            <span class="ml-1">{{ $note->is_cancelled ? '[cancelled]' : '' }}</span>
                        </td>
                        <td class="">
                            <a href="/patients/view/{{ $note->client->uid }}">{{ $note->client->displayName() }}</a>
                        </td>
                        <td class="">
                            {{ $note->hcpPro ? $note->hcpPro->displayName() : '-' }}
                        </td>
                        <td class="">
                            <?php
                            $textContent = strip_tags($note->free_text_html);
                            if (strlen($textContent) > 200) {
                                $textContent = substr($textContent, 0, 200) . '…';
                            }
                            ?>
                            {!! empty($textContent) ? '-' : $textContent !!}
                        </td>
                    </tr>
                    @endforeach
                </tbody>
            </table>
            <div class="mt-3">
                {{ $notes->appends(request()->input())->links() }}
            </div>
        </div>
    </div>
</div>

@endsection