@extends ('layouts/template')

@section('content')

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

        <div class="card-header px-3 py-2 d-flex align-items-center">
            <strong class="">
                <i class="fas fa-user-injured"></i>
                My Tickets
            </strong>
            <select class="ml-auto max-width-300px form-control form-control-sm"
                    onchange="fastLoad('/practice-management/my-tickets/' + this.value, true, false, false)">
                <option value="open" {{ $filter === 'open' ? 'selected' : '' }}>Open tickets</option>
                <option value="closed" {{ $filter === 'closed' ? 'selected' : '' }}>Closed tickets</option>
                <option value="all" {{ $filter === 'all' ? 'selected' : '' }}>All tickets</option>
            </select>
        </div>
        <div class="card-body p-0">
            <table class="table table-condensed p-0 m-0">
                <thead class="bg-light">
                <tr>
                    <th class="border-0">Patient</th>
                    <th class="border-0">Type</th>
                    <th class="border-0 w-50">Details</th>
                    <th class="border-0">Role</th>
                    <th class="border-0"></th>
                </tr>
                </thead>
                <tbody>
                @foreach($myTickets as $ticket)
                    <tr>
                        <td class="text-nowrap">
                            <a class="font-weight-bold" href="/patients/view/{{ $ticket->patient->uid }}">{{ $ticket->patient->displayName() }}</a>
                        </td>
                        <td>{{ strtoupper($ticket->category) }}</td>
                        <td>
                            <?php
                            $display = '-';
                            $parsed = json_decode($ticket->data);
                            switch($ticket->category) {
                                case 'erx':
                                    if(@$parsed->medication) {
                                        $display = $parsed->medication;
                                    }
                                    break;
                                case 'lab':
                                case 'imaging':
                                    if(@$parsed->tests && is_array($parsed->tests) && count($parsed->tests)) {
                                        $display = implode(", ", $parsed->tests);
                                    }
                                    break;
                                case 'equipment':
                                    if(@$parsed->items && is_array($parsed->items) && count($parsed->items)) {
                                        $display = implode(", ", $parsed->items);
                                    }
                                    if(@$parsed->shipping_status) {
                                        $display .= '<span class="ml-3">Shipping: <b>' . $parsed->shipping_status . '</b></span>';
                                        if(@$parsed->tracking_number) {
                                            $display .= '<span class="ml-3">Tracking #: <b>' . $parsed->tracking_number . '</b></span>';
                                        }
                                    }
                                    break;
                            }
                            ?>
                            {!! $display !!}
                        </td>
                        <td>
                            <?php
                            $roles = [];
                            if($ticket->assigned_pro_id === $pro->id) $roles[] = 'Assigned';
                            if($ticket->manager_pro_id === $pro->id) $roles[] = 'Manager';
                            if($ticket->ordering_pro_id === $pro->id) $roles[] = 'Ordering';
                            if($ticket->initiating_pro_id === $pro->id) $roles[] = 'Initiating';
                            $roles = implode(", ", $roles);
                            ?>
                            {{ $roles }}
                        </td>
                        <td>
                            <a class="font-weight-bold" href="/patients/view/{{ $ticket->patient->uid }}/action-items-{{ $ticket->category }}/view/{{ $ticket->uid }}">Open</a>
                        </td>
                    </tr>
                @endforeach
                </tbody>
            </table>
        </div>
    </div>
    </div>

@endsection
