@extends('layouts.app')
@section('title', __('medward::lang.admissions'))
@section('content')
<section class="content-header"><h1>@lang('medward::lang.admissions')</h1>
    <p>@lang('medward::lang.admissions_help')</p>
</section>
<section class="content">
    @component('components.widget', ['class' => 'box-primary'])
        <div class="row" style="margin-bottom:12px;">
            <div class="col-md-4">
                @can('medward.admission.create')
                <a class="btn btn-primary btn-sm" href="{{ route('medward.admissions.create') }}">
                    <i class="fa fa-plus"></i> @lang('medward::lang.admit_patient')
                </a>
                @endcan
            </div>
            <div class="col-md-4">
                <select id="mw_status_filter" class="form-control input-sm">
                    <option value="">@lang('medward::lang.all')</option>
                    @foreach($statuses as $st)
                        <option value="{{ $st }}">@lang('medward::lang.adm_status_' . $st)</option>
                    @endforeach
                </select>
            </div>
            <div class="col-md-4">
                <label class="checkbox-inline"><input type="checkbox" id="mw_icu_only"> @lang('medward::lang.icu_only')</label>
            </div>
        </div>
        <div class="table-responsive">
            <table class="table table-bordered table-striped" id="medward_adm_table">
                <thead><tr>
                    <th>@lang('medward::lang.admission_no')</th>
                    <th>@lang('medward::lang.patient')</th>
                    <th></th>
                    <th>@lang('medward::lang.ward')</th>
                    <th>@lang('medward::lang.bed')</th>
                    <th>@lang('medward::lang.admitted_at')</th>
                    <th>@lang('medward::lang.status')</th>
                    <th>@lang('medward::lang.actions')</th>
                </tr></thead>
            </table>
        </div>
    @endcomponent
</section>
@endsection
@section('javascript')
<script>
$(function () {
    var table = $('#medward_adm_table').DataTable({
        processing: true, serverSide: true,
        ajax: {
            url: '{{ route('medward.admissions.index') }}',
            data: function (d) {
                d.status = $('#mw_status_filter').val();
                d.icu_only = $('#mw_icu_only').is(':checked') ? 1 : 0;
            }
        },
        order: [[5, 'desc']],
        columns: [
            { data: 'admission_no', name: 'medward_admissions.admission_no' },
            { data: 'patient_name', name: 'patient_name', orderable: false, searchable: false },
            { data: 'is_icu', name: 'medward_admissions.is_icu' },
            { data: 'ward_name', name: 'medward_wards.name' },
            { data: 'bed_number', name: 'medward_beds.bed_number' },
            { data: 'admitted_at', name: 'medward_admissions.admitted_at' },
            { data: 'status', name: 'medward_admissions.status' },
            { data: 'action', name: 'action', orderable: false, searchable: false },
        ],
    });
    $('#mw_status_filter, #mw_icu_only').on('change', function () { table.ajax.reload(); });
});
</script>
@endsection
