<!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?_=2"></script>

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

    {{-- Quill RTE --}}
    <script>
        let stagQuillConfig = {
            toolbar: ['bold', 'italic', 'underline', { 'list': 'ordered'}, { 'list': 'bullet' }],
            keyboard: {
                bindings: {
                    handleEnter: {
                        key: 13,
                        handler: function() {
                            if(!$('.stag-shortcuts:visible').length) return true;
                        }
                    }
                }
            }
        };
    </script>
    <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="/js/jquery.form.min.js"></script>
    <script src="{{ asset('js/toastr.min.js') }}" type="application/javascript"></script>
    <script src="/js/yemi.js?_=7" 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.standalone.min.css' rel="stylesheet">
    <script src='/bootstrap-datepicker/js/bootstrap-datepicker.min.js'></script>

    {{-- pdfjs --}}
    <script src="https://mozilla.github.io/pdf.js/build/pdf.js"></script>

    {{-- WebSockets --}}
    <script src="https://cdnjs.cloudflare.com/ajax/libs/sockjs-client/1.5.0/sockjs.min.js"
            integrity="sha512-5yJ548VSnLflcRxWNqVWYeQZnby8D8fJTmYRLyvs445j1XmzR8cnWi85lcHx3CUEeAX+GrK3TqTfzOO6LKDpdw=="
            crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/stomp.js/2.3.3/stomp.min.js"
            integrity="sha512-iKDtgDyTHjAitUDdLljGhenhPwrbBfqTKWO1mkhSFH3A7blITC9MhYon6SjnMhp4o0rADGw9yAC6EW4t5a4K3g=="
            crossorigin="anonymous"></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: 97; width: 100%; height: 100%; display: none;">
    </div>



    <nav class="navbar navbar-expand-md navbar-dark stag-primary-bg py-1 mcp-theme-1 px-2">
        <a class="navbar-brand" href="{{ route('dashboard') }}">
            <img src="/img/logo_white.svg" alt="Leadership Health">
        </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-home"></i> Home</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>
                @if($pro && ($pro->can_add_patients || $pro->pro_type== 'ADMIN'))
                <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>
                @endif
                <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 mcp-theme-1" aria-labelledby="practice-management">
                        {{--<a class="dropdown-item" href="{{ route('practice-management.dashboard') }}">Dashboard</a>--}}
                        @if($pro && $pro->pro_type == 'ADMIN')
                            <a class="dropdown-item" href="/practice-management/rates/all">Payment Rates</a>
                        @endif
                        {{--<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="{{ route('practice-management.myTickets') }}">My Tickets</a>
                        <a class="dropdown-item" href="{{ route('practice-management.myTextShortcuts') }}">My Text Shortcuts</a>
                        <a class="dropdown-item" href="{{ route('practice-management.myFavorites') }}">My Favorites</a>
                        <a class="dropdown-item" href="{{ route('practice-management.proAvailability') }}">Pro Availability</a>
                        <a class="dropdown-item" href="{{ route('practice-management.proCalendar') }}">Pro Calendar</a>

                        <a class="dropdown-item" href="{{ route('practice-management.billingManager') }}">Billing Manager</a>

                        @if($pro && $pro->pro_type == 'ADMIN')
                            <a class="dropdown-item" href="{{ route('practice-management.processingBillMatrix') }}">Processing Bills</a>
                            <a class="dropdown-item" href="{{ route('practice-management.cellularMeasurements') }}">Cellular Measurements</a>
                            <a class="dropdown-item" href="{{ route('practice-management.cellularDeviceManager') }}">Cellular Device Manager</a>
                            <a class="dropdown-item" href="{{ route('practice-management.claims') }}">Claims</a>
                            <a class="dropdown-item" href="{{ route('practice-management.hcpBillMatrix') }}">HCP Bill Matrix</a>
                            <a class="dropdown-item" href="{{ route('practice-management.treatmentServiceUtil') }}">Treatment Service Util.</a>
                            <a class="dropdown-item" href="/practice-management/tickets">Tickets</a>
                        @endif
                    </div>
                </li>
            </ul>
            {{-- if pro is working on a client and is not in tht client --}}
            <div class="current-work mr-2">
                @include('app/current-work')
            </div>
            <a href="#" class="mr-2 text-white small" onclick="fastReload()"><i class="fa fa-sync"></i></a>
            <div class="d-inline-flex pr-2 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">

                <div class="dropdown">
                    <a class="nav-link dropdown-toggle text-white pl-1 pr-0" href="#" id="account-menu" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                        <span class="text-white my-0 small">Hi, <b title="Cell# {{$pro->cell_number}}">{{ $pro->name_first }}!</b></span>
                    </a>
                    <div class="dropdown-menu dropdown-menu-right mcp-theme-1 pt-0 pb-1" aria-labelledby="account-menu">
                        @if($performer->logged_in_as_pro_from_admin_pro_app_session_id)
                            <form action="{{route('back-to-admin-pro')}}" method="post" target="_top" class="d-block pt-1">
                                @csrf
                                <button class="d-block ml-2">
                                    Admin
                                </button>
                            </form>
                        @endif
                        @if($pro->pro_type == 'ADMIN')
                            <a href="{{route('log-in-as')}}" native target="_top" class="d-block ml-2 pt-1">Log In As</a>
                        @endif
                        @if($pro->pro_type == 'ADMIN')
                            <a native target="_top" class="d-block ml-2 pt-1"
                               href="{{config('stag.adminPortalUrl')}}/pro_log_in_with_session_key/{{$performer->session_key}}" title="">
                                Admin
                            </a>
                        @endif
                        <a native target="_top" class="d-block ml-2 pt-1" href="{{config('stag.authUrl')}}" title="">
                            Exit
                        </a>
                        <a native target="_top" href="{{route('logout')}}" class="d-block ml-2 pt-1">
                            Sign Out
                        </a>
                    </div>
                </div>
            </div>
        </div>

        <a href="#" class="stag_rhs_toggle d-none d-md-block text-white" 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>

    <!-- pro suggest component -->
    <script src="/js/pro-suggest.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() {
            window.toggleChildLinks = function(_element) {
                $(_element).closest('.nav-item').toggleClass('nav-child-collapsed');
                return false;
            }
            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 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:
                            window.setTimeout(onQueryChange, 50);
                            break;
                    }
                })
                .on('keypress paste', function(e) {
                    window.setTimeout(onQueryChange, 50);
                });
            function onQueryChange() {
                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.patient-suggest[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 src="/js/stag-popup.js"></script>
    <script src="/js/option-list.js"></script>
    @include('app/pdf/viewer')
    <script>
        let socket = new SockJS("{{ config('app.backend_ws_url') }}");
        window.socketClient = Stomp.over(socket);
        window.socketClient.connect({}, (frame) => {

            window.socketClient.send("/app/register", {},     // register self
                JSON.stringify({
                    sessionKey: '{{$performer->session_key}}'
                })
            );

            window.socketClient.subscribe("/user/topic/myCurrentProClientWork", function(message) {
                console.log("You have a client pro work: ", message);
                $.get('/current-work', function(_data) {
                    $('.current-work').html(_data);
                    //initFastLoad($('.current-work'));
                    fastReload();
                });
            });

            window.socketClient.subscribe("/user/topic/killMyCurrentProClientWork", function(message) {
                console.log("You have killed your current pro client work: ", message);
                $.get('/current-work', function(_data) {
                    $('.current-work').html(_data);
                    //initFastLoad($('.current-work'));
                    fastReload();
                });
            });



        });
    </script>
</body>

</html>
