<div class="my-4">
    <div class="d-flex align-items-end mb-3">
        <h4 class="font-weight-bold m-0 text-secondary font-size-16">Imaging
            <span v-if="statusFilter === 'open'" class="text-secondary font-weight-normal">(@{{ imagingNumOpen }} open)</span>
            <span v-if="statusFilter === 'closed'" class="text-secondary font-weight-normal">(@{{ imagingNumClosed }} closed)</span>
            <span v-if="statusFilter === 'all'" class="text-secondary font-weight-normal">(@{{ imagingNumOpen }} open, @{{ imagingNumClosed }} closed)</span>
        </h4>
        <a class="px-3 c-pointer font-weight-bold"
           v-on:click.prevent="imagingShowPopup()">+ New</a>
        <a class="py-0 font-weight-normal c-pointer flex-grow-1 text-right pr-2"
           v-if="!imagingCollapsed"
           v-on:click.prevent="imagingCollapsed = true">
            <i class="text-secondary fa fa-chevron-up"></i>
        </a>
        <a class="py-0 font-weight-normal c-pointer flex-grow-1 text-right pr-2"
           v-if="imagingCollapsed"
           v-on:click.prevent="imagingCollapsed = false">
            <i class="text-secondary fa fa-chevron-down"></i>
        </a>
    </div>
    <div class="ticket-section" :class="imagingCollapsed ? 'ticket-section-collapsed' : ''">
        <table class="table table-sm tickets-table mb-0 border-bottom">
            <tbody>
            <tr v-for="(item, index) in ticketsByType.imaging"
                v-if="(statusFilter === 'all' || (statusFilter === 'open' && item.is_open) || (statusFilter === 'closed' && !item.is_open)) && (item.data.tests && Array.isArray(item.data.tests) && item.data.tests.length)"
                :class="(item.is_open ? ' ' : 'opacity-60 bg-light ') + (currentItemUid === item.uid ? 'current' : '')">
                <td class="px-2 py-2 c-pointer" v-on:click.prevent="imagingShowPopup(item)">
                    <div class="d-flex align-items-center">
                        <div class="pro-initials text-uppercase"
                             :title="allProsFlat['pro_' + item.assigned_pro_id].displayedName"
                             :style="'background-color: ' + allProsFlat['pro_' + item.assigned_pro_id].colors.bc + '; color: ' + allProsFlat['pro_' + item.assigned_pro_id].colors.fc + ';'">
                            @{{allProsFlat['pro_' + item.assigned_pro_id].displayedInitials}}
                        </div>
                        <div class="flex-grow-1 d-inline-flex ml-2 flex-wrap align-items-center">
                            <span class="font-weight-bold text-dark font-size-13"
                                  v-html="item.data.tests && Array.isArray(item.data.tests) ? item.data.tests.join(', ') : '-'"></span>
                            <span class="ml-3 font-weight-bold" v-if="item.data.attachments && item.data.attachments.length">
                                <i class="fa fa-paperclip"></i>
                            </span>
                            <span class="text-nowrap ml-auto text-sm" v-if="item.data.due_date">
                                <div title="Due Date" class="pro-initials text-uppercase text-white bg-info"><i class="fa fa-calendar-day"></i></div>
                                <span class="text-secondary ml-1">@{{ item.data.due_date }}</span>
                            </span>
                        </div>
                    </div>
                    <!--
                    <div>
                        <span class="text-secondary text-sm mt-1">Created:</span>
                        @{{ item.created_at }}
                    </div>
                    -->
                </td>

            </tr>
            </tbody>
        </table>
    </div>
    <div v-if="!preparing" class="stag-popup stag-popup-sm stag-slide mcp-theme-1" stag-popup-key="imaging-popup">
        <form method="POST" action="" class="p-0">
            <h3 class="stag-popup-title mb-0 p-3 bg-light sticky-top">
                <span v-if="imagingPopupMode === 'add'" class="flex-grow-1 text-nowrap overflow-hidden text-ellipsis mr-3">Add Imaging Ticket</span>
                <span v-if="imagingPopupMode === 'edit'" class="flex-grow-1 text-nowrap overflow-hidden text-ellipsis mr-3"
                      v-html="imagingPopupItem.data.tests && Array.isArray(imagingPopupItem.data.tests) ? imagingPopupItem.data.tests.join(', ') : 'Edit Imaging Ticket'"></span>
                @include('app.patient.tickets.header-end', ['category' => 'imaging'])
            </h3>

            <!-- common - only applicable for edit -->
            @include('app.patient.tickets.common-fields', ['category' => 'imaging'])

            <!-- imaging specific -->
            <div class="p-3 border-bottom">

                <div class="row mb-2">
                    <div class="col-12">
                        <label class="text-secondary mb-0 font-weight-normal font-size-16">Imaging</label>
                    </div>
                </div>

                <div class="mb-2">
                    <div class="d-flex align-items-center mb-1">
                        <label class="text-sm text-secondary mb-0">Tests</label>
                        <span class="text-sm mx-2 text-secondary">|</span>
                        <a href="#" class="text-sm" v-on:click.prevent="imagingPopupItem.data.tests.push('')">Add</a>
                    </div>
                    <div class="d-flex align-items-center mb-2" v-for="(test, testIndex) in imagingPopupItem.data.tests">
                        <div class="position-relative flex-grow-1">
                            <input required type="text" data-option-list v-model="imagingPopupItem.data.tests[testIndex]" class="form-control form-control-sm" placeholder="Test">
                            <div class="data-option-list">
                                <div>CAT Scan</div>
                                <div>Fluoroscopy</div>
                                <div>MRI Scan</div>
                                <div>Mammography</div>
                                <div>X-Ray</div>
                                <div>PET</div>
                                <div>PET-CT</div>
                            </div>
                        </div>
                        <a v-if="imagingPopupItem.data.tests.length > 1" class="ml-2 text-danger" href="#" v-on:click.prevent="imagingPopupItem.data.tests.splice(testIndex, 1)">
                            <i class="fa fa-trash-alt"></i>
                        </a>
                    </div>
                </div>
                <div class="mb-2">
                    <div class="d-flex align-items-center mb-1">
                        <label class="text-sm text-secondary mb-0">ICDs</label>
                        <span class="text-sm mx-2 text-secondary">|</span>
                        <a href="#" class="text-sm" v-on:click.prevent="imagingAddICD()">Add</a>
                    </div>
                    <div class="d-flex align-items-center mb-2" v-for="(icd, icdIndex) in imagingPopupItem.data.icds">
                        <div class="position-relative flex-grow-1">
                            <input required type="text" data-field="icd" :data-index="icdIndex" placeholder="ICD"
                                   v-model="imagingPopupItem.data.icds[icdIndex]" class="form-control form-control-sm">
                        </div>
                        <a v-if="imagingPopupItem.data.icds.length > 1" class="ml-2 text-danger" href="#" v-on:click.prevent="imagingPopupItem.data.icds.splice(icdIndex, 1)">
                            <i class="fa fa-trash-alt"></i>
                        </a>
                    </div>
                </div>
                <div class="mb-2">
                    <label class="text-sm text-secondary mb-1">Memo</label>
                    <input type="text" v-model="imagingPopupItem.data.memo" class="form-control form-control-sm">
                </div>


                <div v-if="imagingPopupMode === 'add'" class="d-flex align-items-center justify-content-start mt-3">
                    <button type="button" class="btn btn-sm btn-primary mr-2" v-on:click.prevent="saveimagingPopupItem()">Submit</button>
                    <button type="button" class="btn btn-sm btn-default border" onclick="return closeStagPopup()">Cancel</button>
                </div>
            </div>

            <!-- attachments -->
            @include('app.patient.tickets.attachments', ['category' => 'imaging'])

            <!-- comments -->
            @include('app.patient.tickets.comments', ['category' => 'imaging'])
        </form>
    </div>
</div>
