@extends('layouts.app')
@section('title', __('meddocuments::lang.browser'))
@section('content')
<section class="content-header">
    <h1>@lang('meddocuments::lang.meddoc_module')<small> @lang('meddocuments::lang.browser')</small></h1>
</section>
<section class="content">
    @component('components.widget', ['class' => 'box-primary'])
        @slot('tool')
            <div class="box-tools">
                @can('meddoc.upload')
                <button class="btn btn-primary meddoc-modal-btn" data-href="{{ route('meddoc.documents.create') }}">
                    <i class="fa fa-upload"></i> @lang('meddocuments::lang.upload_document')
                </button>
                @endcan
            </div>
        @endslot

        <div class="row" style="margin-bottom:12px;">
            <div class="col-md-3">
                {!! Form::label('filter_type', __('meddocuments::lang.doc_type') . ':') !!}
                {!! Form::select('filter_type', $types, null, ['class' => 'form-control input-sm', 'id' => 'meddoc_filter_type', 'placeholder' => __('meddocuments::lang.all')]) !!}
            </div>
            <div class="col-md-3">
                {!! Form::label('filter_status', __('meddocuments::lang.status') . ':') !!}
                {!! Form::select('filter_status', ['active' => __('meddocuments::lang.status_active'), 'archived' => __('meddocuments::lang.status_archived')], null, ['class' => 'form-control input-sm', 'id' => 'meddoc_filter_status', 'placeholder' => __('meddocuments::lang.all')]) !!}
            </div>
        </div>

        <div class="table-responsive">
            <table class="table table-bordered table-striped" id="meddoc_documents_table" style="width:100%">
                <thead><tr>
                    <th>@lang('meddocuments::lang.title')</th>
                    <th>@lang('meddocuments::lang.doc_type')</th>
                    <th>@lang('meddocuments::lang.entity')</th>
                    <th>@lang('meddocuments::lang.patient')</th>
                    <th>@lang('meddocuments::lang.versions')</th>
                    <th>@lang('meddocuments::lang.updated')</th>
                    <th>@lang('meddocuments::lang.status')</th>
                    <th>@lang('messages.action')</th>
                </tr></thead>
            </table>
        </div>
    @endcomponent
    <div class="modal fade meddoc_modal" tabindex="-1" role="dialog"></div>
</section>
@endsection
@section('javascript')
<script>
$(function () {
    var table = $('#meddoc_documents_table').DataTable({
        processing: true, serverSide: true,
        ajax: {
            url: '{{ route('meddoc.documents.data') }}',
            data: function (d) {
                d.doc_type_id = $('#meddoc_filter_type').val();
                d.status = $('#meddoc_filter_status').val();
            }
        },
        columns: [
            { data: 'title', name: 'title' },
            { data: 'type_label', name: 'type_label', orderable: false },
            { data: 'entity', name: 'entity', orderable: false, searchable: false },
            { data: 'patient', name: 'patient', orderable: false, searchable: false },
            { data: 'versions', name: 'versions', orderable: false, searchable: false },
            { data: 'updated_at', name: 'updated_at' },
            { data: 'status', name: 'status', orderable: false, searchable: false },
            { data: 'action', name: 'action', orderable: false, searchable: false },
        ],
        order: [[5, 'desc']],
    });
    window.__meddocTables = window.__meddocTables || []; window.__meddocTables.push(table);
    $('#meddoc_filter_type, #meddoc_filter_status').on('change', function () { table.ajax.reload(); });
});
</script>
@include('meddocuments::partials.crud_scripts')
@endsection
