<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <title>{{ config('app.name') }}</title>

    <!-- Fonts -->
    <link href="https://fonts.googleapis.com/css?family=Nunito:200,600" rel="stylesheet">

    {{-- mc initializers --}}
    <script src="/js/mc-init.js"></script>

    {{-- vue --}}
    <script src="/js/vue.js"></script>

    {{-- Quill RTE --}}
    <link href="/quill/quill.snow.css" rel="stylesheet">
    <script src="/quill/quill.js"></script>

    <!-- <link href="{{ asset('bootstrap-4.5.0/css/bootstrap.css') }}" rel="stylesheet"> -->
    <link rel="stylesheet" href="/fontawesome-free-5.13.1-web/css/all.min.css">
    <link href="{{ asset('/css/app.css') }}" rel="stylesheet">
    <link href="{{ asset('/css/style.css') }}" rel="stylesheet">
    <link href="{{ asset('/css/yemi.css') }}" rel="stylesheet">
    <link rel="stylesheet" href="{{ asset('/css/toastr.min.css') }}">
    <link href="{{asset('/css/z.css')}}" rel=stylesheet>
    <!-- Styles -->

    <script src="{{ asset('js/app.js') }}" type="application/javascript"></script>
    <script src="/js/jquery-3.5.1.min.js"></script>
    <script src="{{ asset('js/toastr.min.js') }}" type="application/javascript"></script>
    <script src="/js/yemi.js?_=6" type="application/javascript"></script>

    {{-- med ac --}}
    <link href='/css/autocomplete-lhc.min.css' rel="stylesheet">
    <script src='/js/autocomplete-lhc.js'></script>

    {{-- inline bootstrap datepicker --}}
    <link href='/bootstrap-datepicker/css/bootstrap-datepicker.min.css' rel="stylesheet">
    <script src='/bootstrap-datepicker/js/bootstrap-datepicker.min.js'></script>

    @yield('head')
</head>

<body>
    <div id="mask" style="background: rgba(0, 0, 0, 0) url(&quot;/vanillaspin.gif&quot;) no-repeat scroll center center; position: fixed; top: 0px; left: 0px; z-index: 9999; width: 100%; height: 100%; display: none;">
    </div>
    <div id="moe-form-mask" style="background: rgba(0, 0, 0, .1) no-repeat scroll center center; position: fixed; top: 0px; left: 0px; z-index: 99; width: 100%; height: 100%; display: none;">
    </div>

    <nav class="navbar navbar-expand-md navbar-dark stag-primary-bg py-1">
        <a class="navbar-brand" href="{{ route('dashboard') }}">Scholar</a>
        <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navBar" aria-controls="navBar" aria-expanded="false" aria-label="Toggle navigation">
            <span class="navbar-toggler-icon"></span>
        </button>

        <div class="collapse navbar-collapse" id="navBar">
            <ul class="navbar-nav mr-auto">
                <li class="nav-item"><a class="nav-link" href="{{ route('dashboard') }}"><i class="mr-1 fas fa-tachometer-alt"></i> Dashboard</a> </li>
                <li class="nav-item"><a class="nav-link" href="{{ route('patients') }}"><i class="mr-1 fas fa-user-injured"></i> Patients</a> </li>
                <li class="nav-item"><a class="nav-link" href="{{ route('new-patient') }}"><i class="mr-1 fas fa-user-plus"></i> New Patient</a> </li>
                <li class="nav-item dropdown">
                    <a class="nav-link dropdown-toggle" href="#" id="practice-management" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><i class="mr-1 fas fa-tasks"></i> Practice</a>
                    <div class="dropdown-menu" aria-labelledby="practice-management">
                        {{--<a class="dropdown-item" href="{{ route('practice-management.dashboard') }}">Dashboard</a>--}}
                        <a class="dropdown-item" href="{{ route('practice-management.rates') }}">Payment Rates</a>
                        <a class="dropdown-item" href="{{ route('practice-management.previousBills') }}">Previous Bills</a>
                        <a class="dropdown-item" href="{{ route('practice-management.financialTransactions') }}">Financial Transactions</a>
                        <a class="dropdown-item" href="/practice-management/bills/not-yet-signed">Pending Bills to Sign</a>
                        <a class="dropdown-item" href="/practice-management/notes/not-yet-signed">Pending Notes to Sign</a>
                        <a class="dropdown-item" href="{{ route('unmapped-sms') }}">Unmapped SMS</a>
                        {{--<a class="dropdown-item" href="/practice-management/hr">HR</a>--}}
                        <a class="dropdown-item" href="{{ route('practice-management.myTextShortcuts') }}">My Text Shortcuts</a>
                    </div>
                </li>
            </ul>
            <a href="#" class="mr-3 text-white small" onclick="fastReload()"><i class="fa fa-sync"></i></a>
            <div class="d-inline-flex pr-3 mcp-theme-1 position-relative">
                <input id="patient-search" type="search" class="form-control form-control-sm outline-0" autocomplete="off" placeholder="Search Patients">
                <div class="suggestions-outer position-absolute d-none">

                </div>
            </div>
            <div class="d-flex align-items-center">
                <p class="text-white my-0 mr-2 small">Hello, <b title="Cell# {{$pro->cell_number}}">{{ $pro->name_first }}!</b></p>
                <form action="{{ route('logout') }}" method="post" target="_top">
                    @csrf
                    <button class="btn btn-sm btn-link text-light">
                        <i class="fas fa-sign-out-alt"></i>
                        <span class="small"></span>Log Out
                    </button>
                </form>
            </div>
            @if($pro->pro_type == 'ADMIN')
            <div class="mr-2 d-inline-block">|</div>
            <div class="d-flex align-items-center">
                <a href="{{route('log-in-as')}}" class="text-white">Log In As</a>
            </div>
            @endif

            @if($performer->logged_in_as_pro_from_admin_pro_app_session_id)
            <form action="{{route('back-to-admin-pro')}}" method="post" target="_top">
                @csrf
                <button class="btn btn-sm btn-link text-light">
                    <i class="fas fa-sign-out-alt"></i>
                    <span class="small"></span>Back to Admin
                </button>
            </form>
            @endif
        </div>

        <a href="#" class="stag_rhs_toggle d-none d-md-block" title="Toggle Video Pane">
            <i class="fa fa-arrow-right"></i>
        </a>
    </nav>


    <main role="main" class="stag-content px-0">

        @yield('content')

    </main><!-- /.container -->


    <!-- shortcut/suggest component -->
    <link href="/css/shortcut.css" rel=stylesheet>
    <script src="/js/shortcut.js" type="application/javascript"></script>

    <!-- script to handle history/back/forward for mc/xxx pages
    + all other JS initialization needed in fastLoaded pages  -->
    <script src="/js/find-event-handlers.js" type="application/javascript"></script>
    <script src="/js/mc.js?_=4" type="application/javascript"></script>

    <form url="/api/proTextShortcut/create" id="create-shortcut-form" class="mcp-theme-1">
        <input type="hidden" name="proUid" value="{{ $pro->uid  }}">
        <div class="mb-2">
            <input type="text" class="form-control form-control-sm" name="shortcut" value="" placeholder="Shortcut Name" required>
        </div>
        <div class="mb-2">
            <textarea name="text" class="form-control form-control-sm" rows="3" id="selected-sc-text" placeholder="Content" required></textarea>
        </div>
        <div class="mb-0">
            <button class="btn btn-primary btn-sm" type="submit">Save</button>
            <button class="btn btn-default border btn-sm ml-1" type="reset">Cancel</button>
        </div>
    </form>

    <script>
        $(document).ready(function() {
            const debounce = (func, wait) => {
                let timeout;
                return function executedFunction(...args) {
                    const later = () => {
                        clearTimeout(timeout);
                        func(...args);
                    };
                    clearTimeout(timeout);
                    timeout = setTimeout(later, wait);
                };
            };
            var lastTerm = '';
            var returnedFunction = debounce(function() {
                var term = $.trim($('#patient-search').val());
                if (!!term && lastTerm !== term) {
                    $.get('/patients-suggest?term=' + term, function(_data) {
                        $('.suggestions-outer').html(_data).removeClass('d-none');
                    });
                    lastTerm = term;
                } else {
                    $('.suggestions-outer').addClass('d-none');
                }
            }, 250);
            $('#patient-search')
                .on('keydown', function(e) {
                    var term = $.trim($('#patient-search').val());
                    var activeItem = $('.suggestions-outer .suggest-item.active');
                    switch (e.which) {
                        case 27:
                            $('.suggestions-outer').addClass('d-none');
                            return false;
                        case 38:
                            if (activeItem.prev().length) {
                                activeItem.prev()
                                    .addClass('active')
                                    .siblings().removeClass('active');
                                activeItem = $('.suggestions-outer .suggest-item.active');
                                if (activeItem.length) {
                                    activeItem[0].scrollIntoView();
                                }
                            }
                            return false;
                        case 40:
                            if (activeItem.next().length) {
                                activeItem.next()
                                    .addClass('active')
                                    .siblings().removeClass('active');
                                activeItem = $('.suggestions-outer .suggest-item.active');
                                if (activeItem.length) {
                                    activeItem[0].scrollIntoView();
                                }
                            }
                            return false;
                        case 13:
                            if (activeItem.length) {
                                activeItem.first().click();
                            }
                            return false;
                        default:
                            if (!!term) {
                                $('.suggestions-outer')
                                    .html('<span class="d-block no-suggest-items">Searching...</span>')
                                    .removeClass('d-none');
                                returnedFunction();
                            } else {
                                $('.suggestions-outer').addClass('d-none');
                            }
                            break;
                    }
                })
                .on('keypress', function(e) {
                    var term = $.trim($('#patient-search').val());
                    if (!!term) {
                        $('.suggestions-outer')
                            .html('<span class="d-block no-suggest-items">Searching...</span>')
                            .removeClass('d-none');
                        returnedFunction();
                    } else {
                        $('.suggestions-outer').addClass('d-none');
                    }
                });
            $(document).on('click', '.suggest-item[data-target-uid]', function() {
                $('#patient-search').val('');
                $('.suggestions-outer').addClass('d-none');
                fastLoad('/patients/view/' + $(this).attr('data-target-uid'), true, false, false);
                return false;
            });
        });
    </script>
    <script>
        (function() {
            function init() {
                $('input[type="text"][name="ICD"]').each(function() {
                    var elem = this, dynID = 'icd-' + Math.ceil(Math.random() * 1000000);
                    $(elem).attr('id', dynID);
                    new window.Def.Autocompleter.Search(dynID,
                        'https://clinicaltables.nlm.nih.gov/api/icd10cm/v3/search?sf=code,name&ef=name',
                        {
                            tableFormat: true,
                            valueCols: [0],
                            colHeaders: ['Code', 'Name'],
                        }
                    );
                    window.Def.Autocompleter.Event.observeListSelections(dynID, function() {
                        var autocomp = elem.autocomp;
                        var name = autocomp.getSelectedItemData()[0].data['name'];
                        $(elem).closest('form').find('[name="contentText"]').val(name);
                        return false;
                    });
                });
                $('[rx-section] input[type="text"][name="contentText"]').each(function() {
                    var elem = this, dynID = 'rx-' + Math.ceil(Math.random() * 1000000);
                    $(elem).attr('id', dynID);
                    var strengthElem = $(elem).closest('form').find('[name="strength"]')[0],
                        dynStrengthsID = 'rx-' + Math.ceil(Math.random() * 1000000) + '-strengths';
                    $(strengthElem).attr('id', dynStrengthsID);
                    new window.Def.Autocompleter.Prefetch(dynStrengthsID, []);
                    new window.Def.Autocompleter.Search(dynID,
                        'https://clinicaltables.nlm.nih.gov/api/rxterms/v3/search?ef=STRENGTHS_AND_FORMS');
                    window.Def.Autocompleter.Event.observeListSelections(dynID, function() {
                        var autocomp = elem.autocomp;
                        var strengths =
                            autocomp.getSelectedItemData()[0].data['STRENGTHS_AND_FORMS'];
                        if (strengths)
                            strengthElem.autocomp.setListAndField(strengths, '');
                    });
                });
            }
            addMCInitializer('patient-single', init);
        })();
    </script>

</body>

</html>
