<!-- Top Bar -->
<nav class="navbar bg-deep-orange">
    <div class="container-fluid">
        <div class="navbar-header">
            <a href="javascript:void(0);" class="navbar-toggle collapsed" data-toggle="collapse"
               data-target="#navbar-collapse" aria-expanded="false"></a>
            <a href="javascript:void(0);" class="bars"></a>
            <a class="navbar-brand text-center" href="javascript:void(0);">
                <?php echo (new CoreSystem())->TitleSite(); ?>
                <!--                <img src="ResourcesHolder/resource/css/logo.png" style="height: 180%">-->
            </a>
        </div>
        <?php if ((new CoreSystem())->GetType() === 'direct') { ?>
            <div class="collapse navbar-collapse fIranianSans" id="navbar-collapse">
                <ul class="nav navbar-nav navbar-right">
                    <!-- Notifications -->
                    <li class="dropdown client-requests">
                        <a href="javascript:void(0);" class="dropdown-toggle waves-effect" data-toggle="dropdown"
                           role="button">
                            <div data-toggle="tooltip" data-placement="bottom"
                                 title="درخواست های ارسال شده از طرف کاربران">
                                <i class="material-icons">mail</i>
                                <span class="label-count">0</span>
                            </div>
                        </a>
                    </li>
                    <!-- #END# Notifications -->
                    <!-- Notifications -->
                    <li class="dropdown ticket-requests">
                        <a href="javascript:void(0);" class="dropdown-toggle waves-effect" data-toggle="dropdown"
                           role="button">
                            <div data-toggle="tooltip" data-placement="bottom" title="پیام های کاربران">
                                <i class="material-icons">notifications</i>
                                <span class="label-count">0</span>
                            </div>
                        </a>
                    </li>
                    <!-- #END# Notifications -->
                </ul>
            </div>
        <?php } ?>
    </div>
</nav>
<!-- #Top Bar -->
<?php if ((new CoreSystem)->GetType() === 'direct') { ?>
    <script type="text/javascript">
        (function ($) {
            let DataStructuresTopBar = {
                element: {notification: null, request: null},
                OnInit: null,
                event: {
                    OnLoad: null,
                    OnNotification: null,
                    OnClientRequest: null,
                },
            };
            DataStructuresTopBar.event.OnNotification = function () {
                LoadData({request: 'proxy', action: 'notification-page'}, LoadScreen(true), false, null);
            };

            DataStructuresTopBar.event.OnClientRequest = function () {
                LoadData({request: 'proxy', action: 'request-page'}, LoadScreen(true), false, null);
            };

            DataStructuresTopBar.event.OnLoad = function (request, tag, key) {
                LoadData({request: 'proxy', action: request}, null, true, function (data) {
                    try {
                        if (data[0]['error'] === 0) {
                            tag.text(data[0][key]);
                        } else {
                            tag.text('error');
                        }
                    } catch (err) {
                        console.log(err.message);
                    }
                });
            };

            DataStructuresTopBar.OnInit = function () {
                let element = DataStructuresTopBar.element;
                element.notification = $('.ticket-requests');
                element.request = $('.client-requests');


                DataStructuresTopBar.event.OnLoad('mail-help-count', element.notification.find('span'), 'notification-mail-number');
                DataStructuresTopBar.event.OnLoad('mail-count', element.request.find('span'), 'mail-number-wait');

                element.notification.unbind().bind('click, tap', function (e) {
                    DataStructuresTopBar.event.OnNotification();
                });

                element.request.unbind().bind('click, tap', function (e) {
                    DataStructuresTopBar.event.OnClientRequest();
                });
            };
            $(document).ready(function () {
                DataStructuresTopBar.OnInit();
            });

        }(jQuery));
    </script>
<?php } ?>