<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">Equipment
            <span v-if="statusFilter === 'open'" class="text-secondary font-weight-normal">(@{{ equipmentNumOpen }} open)</span>
            <span v-if="statusFilter === 'closed'" class="text-secondary font-weight-normal">(@{{ equipmentNumClosed }} closed)</span>
            <span v-if="statusFilter === 'all'" class="text-secondary font-weight-normal">(@{{ equipmentNumOpen }} open, @{{ equipmentNumClosed }} closed)</span>
        </h4>
        <a class="px-3 c-pointer font-weight-bold"
           v-on:click.prevent="equipmentShowPopup()">+ New</a>
        <a class="py-0 font-weight-normal c-pointer flex-grow-1 text-right pr-2"
           v-if="!equipmentCollapsed"
           v-on:click.prevent="equipmentCollapsed = 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="equipmentCollapsed"
           v-on:click.prevent="equipmentCollapsed = false">
            <i class="text-secondary fa fa-chevron-down"></i>
        </a>
    </div>
    <div class="ticket-section" :class="equipmentCollapsed ? 'ticket-section-collapsed' : ''">
        <table class="table table-sm tickets-table mb-0 border-bottom">
            <tbody>
            <tr v-for="(item, index) in ticketsByType.equipment"
                v-if="(statusFilter === 'all' || (statusFilter === 'open' && item.is_open) || (statusFilter === 'closed' && !item.is_open)) && (item.data.items && Array.isArray(item.data.items) && item.data.items.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="equipmentShowPopup(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.items && Array.isArray(item.data.items) ? item.data.items.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="equipment-popup">
        <form method="POST" action="" class="p-0">
            <h3 class="stag-popup-title mb-0 p-3 bg-light sticky-top">
                <span v-if="equipmentPopupMode === 'add'" class="flex-grow-1 text-nowrap overflow-hidden text-ellipsis mr-3">Add Equipment Ticket</span>
                <span v-if="equipmentPopupMode === 'edit'" class="flex-grow-1 text-nowrap overflow-hidden text-ellipsis mr-3"
                      v-html="equipmentPopupItem.data.items && Array.isArray(equipmentPopupItem.data.items) ? equipmentPopupItem.data.items.join(', ') : 'Edit Lab Ticket'"></span>
                @include('app.patient.tickets.header-end', ['category' => 'equipment'])
            </h3>

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

            <!-- equipment 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">Equipment</label>
                    </div>
                </div>


                <div class="mb-2">
                    <div class="d-flex align-items-center mb-1">
                        <label class="text-sm text-secondary mb-0">Items</label>
                        <span class="text-sm mx-2 text-secondary">|</span>
                        <a href="#" class="text-sm" v-on:click.prevent="equipmentPopupItem.data.items.push('')">Add</a>
                    </div>
                    <div class="d-flex align-items-center mb-0" v-for="(item, itemIndex) in equipmentPopupItem.data.items">
                        <div class="position-relative flex-grow-1">
                            <input required type="text" data-option-list v-model="equipmentPopupItem.data.items[itemIndex]" class="form-control form-control-sm" placeholder="Item">
                            <div class="data-option-list">
                                <div>Weight Scale</div>
                                <div>Pulse Ox</div>
                                <div>Temperature Gun</div>
                            </div>
                        </div>
                        <a v-if="equipmentPopupItem.data.items.length > 1" class="ml-2 text-danger" href="#" v-on:click.prevent="equipmentPopupItem.data.items.splice(itemIndex, 1)">
                            <i class="fa fa-trash-alt"></i>
                        </a>
                    </div>
                </div>
                <div class="mb-2">
                    <label class="text-sm text-secondary mb-1">Purpose</label>
                    <input type="text" v-model="equipmentPopupItem.data.purpose" class="form-control form-control-sm" placeholder="Purpose">
                </div>
                <div class="mb-2">
                    <label class="text-sm text-secondary mb-1">Memo</label>
                    <input type="text" v-model="equipmentPopupItem.data.memo" class="form-control form-control-sm" placeholder="Memo">
                </div>


                <div v-if="equipmentPopupMode === '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="equipmentSavePopupItem()">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' => 'equipment'])

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

        </form>
    </div>
</div>
