<!DOCTYPE html>
<html lang="en">

<head>
  <!-- Required meta tags -->
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
{{--    <META http-equiv="refresh" content="1">--}}
  <title>{{env('APP_ENV').'  '.__('auto.管理控制台')}}</title>
  <!-- plugins:css -->
  <link rel="stylesheet" href="/assets/vendors/iconfonts/mdi/css/materialdesignicons.min.css">
  <link rel="stylesheet" href="/assets/vendors/css/vendor.bundle.base.css">
  <!-- endinject -->
  <!-- inject:css -->
  <link rel="stylesheet" href="/assets/css/style.css">
  <!-- endinject -->
  <link rel="shortcut icon" href="/assets/images/favicon.png" />
  <style>
    /*定义滚动条高宽及背景 高宽分别对应横竖滚动条的尺寸*/
    ::-webkit-scrollbar
    {
      width: 0px;
      height: 0px;
      background-color: #F5F5F5;
    }
    .sidebar .nav .nav-item.active > .nav-link .menu-title {
        color: #343a40;
        font-family: "ubuntu-medium", sans-serif;
    }
    .sidebar .nav .nav-item.active > .nav-link i {
        color: #bba8bff5;
    }
    .sidebar .nav.sub-menu .nav-item .nav-link.active {
        color: #343a40;
        background: transparent;
    }
  </style>
</head>
<body>
<div class="container-scroller">
  <!-- partial:partials/_navbar.html -->
  <nav class="navbar default-layout-navbar col-lg-12 col-12 p-0 fixed-top d-flex flex-row">
    <div class="text-center navbar-brand-wrapper d-flex align-items-center justify-content-center">
        <button class="navbar-toggler navbar-toggler-right d-lg-none align-self-center" type="button" data-toggle="offcanvas">
            <span class="mdi mdi-menu"></span>
        </button>
      <a class="navbar-brand brand-logo" href="/admin/bx_nb">
{{--          <img src="/uploads/config/20181107/5be269ef937d1.png" alt="logo"/>--}}
      </a>
      <a class="navbar-brand brand-logo-mini" href="/admin/bx_nb"><img src="/assets/images/logo-mini.svg" alt="logo"/></a>
    </div>
    <div class="navbar-menu-wrapper d-flex align-items-stretch">
      <div class="search-field d-none d-md-block">

      </div>
      <ul class="navbar-nav navbar-nav-right">
        <li class="nav-item nav-profile dropdown">
          <a class="nav-link dropdown-toggle" id="profileDropdown" href="#" data-toggle="dropdown" aria-expanded="false">
{{--            <div class="nav-profile-img">--}}
{{--              <img src="{{ session('admin')->avatar }}" alt="image">--}}
{{--              <span class="availability-status online"></span>--}}
{{--            </div>--}}
{{--            <div class="nav-profile-text">--}}
{{--              <p class="mb-1 text-black">{{ session('admin')->account }}</p>--}}
{{--            </div>--}}
          </a>
          <div class="dropdown-menu navbar-dropdown" aria-labelledby="profileDropdown">
            <a class="dropdown-item" onclick="editInfo({{ session('admin')->id }})" href="javascript:;">
              <i class="mdi mdi-border-color mr-2 text-success"></i>
              {{__('auto.修改信息')}}}
            </a>
            <div class="dropdown-divider"></div>
            <a class="dropdown-item" href="/logout">
              <i class="mdi mdi-logout mr-2 text-primary"></i>
                {{__('auto.退出登录')}}
              </a>
            </div>
          </li>
          <li class="nav-item d-none d-lg-block full-screen-link">
            <a class="nav-link">
              <i class="mdi mdi-fullscreen" id="fullscreen-button"></i>
            </a>
          </li>
          <li class="nav-item dropdown">
            <a class="nav-link count-indicator dropdown-toggle" id="messageDropdown" href="/admin/complaint/opinion" data-toggle="dropdown" aria-expanded="false">
              <i class="mdi mdi-email-outline"></i>
                <div id="add_text" style="color: red;font-size: 20px;font-family: 'Microsoft YaHei';">

                </div>
            </a>
          </li>


          <li class="nav-item dropdown">
            <a class="nav-link count-indicator dropdown-toggle" id="notificationDropdown" href="#" data-toggle="dropdown">
              <i class="mdi mdi-bell-outline"></i>
                <div id="xitong_text" style="color: red;font-size: 20px;font-family: 'Microsoft YaHei';">
                </div>

            </a>
          </li>

        </ul>

      </div>
    </nav>
    <!-- partial -->
    <div class="container-fluid page-body-wrapper">
      <!-- partial:partials/_sidebar.html -->
      <nav class="sidebar sidebar-offcanvas" id="sidebar" style="overflow:auto;max-height: calc(100vh - 70px);width:{{session('admin')->locale=="zh_CN"?"230px":"250px"}}">
      <ul class="nav">
{{--        <li class="nav-item nav-profile">--}}
{{--          <a href="#" class="nav-link">--}}
{{--            <div class="nav-profile-image">--}}
{{--              <img src="{{ session('admin')->avatar }}" alt="profile">--}}
{{--              <span class="login-status online"></span>--}}
{{--            </div>--}}
{{--            <div class="nav-profile-text d-flex flex-column">--}}
{{--              <span class="font-weight-bold mb-2">{{ session('admin')->account }}</span>--}}
{{--              <span class="text-secondary text-small">{{ session('admin')->nickname }}</span>--}}
{{--            </div>--}}
{{--            <i class="mdi mdi-bookmark-check text-success nav-profile-badge"></i>--}}
{{--          </a>--}}
{{--        </li>--}}

        <li class="nav-item">
          <a class="nav-link" href="{{ url('console') }}" data-url="{{ url('console') }}" target="main">
            <span class="menu-title">@lang('menu.游戏概况')</span>
            <i class="mdi mdi-home menu-icon"></i>
          </a>
        </li>

        @foreach($menu as $k=>$v)
          @if($v->hasChild)
                <li class="nav-item">
                    <a class="nav-link" data-toggle="collapse" href="#system-pages-{{$v->id}}" aria-expanded="false" aria-controls="general-pages">
                        <span class="menu-title">{{ $v->name }}</span>
                        <i class="menu-arrow"></i>
                        <i class="{{ $v->icon }} menu-icon"></i>
                    </a>
                    <div class="collapse" id="system-pages-{{$v->id}}">
                        <ul class="nav flex-column sub-menu">
                            @foreach($v->children as $key=>$val)

                                    <li class="nav-item"> <a class="nav-link" target="main" data-url="{{ $val->url }}" href="{{ $val->url }}">{{ $val->name }}</a></li>

                            @endforeach
                        </ul>
                    </div>
                </li>
          @else
                <li class="nav-item">
                    <a class="nav-link" target="main" data-url="{{ $v->url }}" href="{{ $v->url }}">
                        <span class="menu-title">{{ $v->name }}</span>
                        <i class="{{ $v->icon }} menu-icon"></i>
                    </a>
                </li>
          @endif
        @endforeach
        @if(session('admin')->roles[0]->id == 1)
        <li class="nav-item">
            <a
                class="nav-link"
                data-toggle="collapse"
                href="#system-pages"
                aria-expanded="false"
                aria-controls="general-pages"
            >
                <span class="menu-title">{{__('auto.系统设置')}}</span>
                <i class="menu-arrow"></i>
                <i class="mdi mdi-settings menu-icon"></i>
            </a>
            <div class="collapse" id="system-pages">
            <ul class="nav flex-column sub-menu">
                @if (hidden() != 'general_administrator')
                    <li class="nav-item"> <a class="nav-link" target="main" href="/admin/menu/list">菜单</a></li>
                    <li class="nav-item"> <a class="nav-link" target="main" href="/admin/permission/list">权限</a></li>
                    <li class="nav-item"> <a class="nav-link" target="main" href="/admin/role/list">角色</a></li>
                    <li class="nav-item"> <a class="nav-link" target="main" href="/admin/administrator/list">管理员</a></li>
                @endif
                <li class="nav-item"> <a class="nav-link" target="main" href="/admin/burying_point/weight">埋点权重配置</a></li>
                <li class="nav-item"> <a class="nav-link" target="main" href="/admin/IpWhiteList/list">IP白名单管理</a></li>
                <li class="nav-item"> <a class="nav-link" target="main" href="/admin/login_ip/list">后台账号登录管理IP管理</a></li>
            </ul>
            </div>
        </li>
        @endif

        {{--<li class="nav-item sidebar-actions">--}}
        {{--<span class="nav-link">--}}
        {{--<div class="border-bottom">--}}
        {{--<h6 class="font-weight-normal mb-3">Projects</h6>                --}}
        {{--</div>--}}
        {{--<button class="btn btn-block btn-lg btn-gradient-primary mt-4">+ Add a project</button>--}}
        {{--<div class="mt-4">--}}
        {{--<div class="border-bottom">--}}
        {{--<p class="text-secondary">Categories</p>                  --}}
        {{--</div>--}}
        {{--<ul class="gradient-bullet-list mt-4">--}}
        {{--<li>Free</li>--}}
        {{--<li>Pro</li>--}}
        {{--</ul>--}}
        {{--</div>--}}
        {{--</span>--}}
        {{--</li>--}}
      </ul>
    </nav>

    <iframe id="mainiframe" name="main" width="100%"  src="{{ url('console') }}"  frameborder="0"  scrolling="auto" marginheight="0" marginwidth="0"></iframe>
    <!-- main-panel ends -->
  </div>
  <!-- page-body-wrapper ends -->
</div>
<!-- container-scroller -->
<script src="/assets/js/jquery-3.0.0.min.js"></script>
<script src="/assets/layer/layer.js"></script>

<script>

    var ws = {};//new WebSocket('ws://8.129.90.91:9500')  // 内网
    // var ws = new WebSocket('ws://65.1.231.63:9500')     // 外网
    var message_num = 0
    var withdrawal_num = 0

    ws.onopen = function () {
        // Web Socket 已连接上，使用 send() 方法发送数据
        var data = '{"type":"get_count"}'
        ws.send(data)
    };

    ws.onmessage = function (evt) {

        var received_msg = evt.data;


        if (received_msg == ''){
            return;
        }
        received_msg = JSON.parse(received_msg)
        var type = received_msg.type


        switch (type) {
            case 'ping':
                ws.send('pong')
                break;
            case 'back_count':
                var message_count = received_msg.message_count
                var withdrawal_count = received_msg.withdrawal_count

                if (message_count > 0){
                    if (message_num != message_count){
                        playSound()
                        message_num = message_count
                    }

                    $("#add_text").html('<span class="count-symbol bg-warning">&nbsp;&nbsp;'+message_count+'&nbsp;&nbsp;</span>')
                }else {
                    $("#add_text").html('')
                }
                if (withdrawal_count > 0){

                    if (withdrawal_num != message_count){
                        withdrawal_num = withdrawal_count
                        playSound()
                    }

                    $("#xitong_text").html('<span class="count-symbol bg-danger">&nbsp;&nbsp;'+withdrawal_count+'&nbsp;&nbsp;</span>')
                }else {
                    $("#xitong_text").html('')
                }

                var data = '{"type":"get_count"}'
                ws.send(data)
                break
        }

    }

    ws.onclose = function () {
        // 关闭 websocket
        console.log('关闭socket')
    };


    function playSound() {
        var borswer = window.navigator.userAgent.toLowerCase();
        if(borswer.indexOf('ie') >= 0) {
            var strEmbed = '<embed name="embedPlay" src="/mp3/yinxiao.mp3" autostart="true" hidden="true" loop="false" />';
            if($('body').find('embed').length <= 0) {
                $('body').append(strEmbed);
            }
            var embed = document.embedPlay;
            //浏览器不支持audio，则使用embed播放
            embed.volume = 100;
        } else {
            //非IE内核浏览器
            var strAudio = '<audio id="audioPlay" src="/mp3/yinxiao.mp3" hidden="true" autoplay="autoplay"/>';
            if($('body').find('audio').length <= 0) {
                $('body').append(strAudio);
            }

            var audio = $('#audioPlay')[0];
            audio.play()

        }
    }
</script>


<script>
    function updateURLParam(param, value) {
        if(value.includes("system-pages"))return;
        var currentURL = window.location.href + '#';
        if(value.includes('{{ url('console') }}')){
            window.history.replaceState(null, null, currentURL.split('#')[0]);
            return
        }
        var regex = new RegExp(param + "=.*?#");
        var newURL = currentURL.replace(regex, param + "=" + value + "#");
        if (!regex.test(currentURL)) {
            newURL = currentURL + param + "=" + value;
        }
        window.history.replaceState(null, null, newURL.slice(0, -1));
    }

    document.addEventListener('DOMContentLoaded', function () {
        // 恢复菜单状态
        const collapsedItems = localStorage.getItem('collapsedItems');
        if (collapsedItems) {
            const ids = JSON.parse(collapsedItems);
            ids.forEach(id => {
                const element = document.getElementById(id);
                if (element) {
                    element.classList.add('show');
                }
            });
        }

        // 添加事件监听器来保存菜单状态
        document.querySelectorAll('.nav-link[data-toggle="collapse"]').forEach(link => {
            link.addEventListener('click', function () {
                const targetId = link.getAttribute('href').substring(1);
                const targetElement = document.getElementById(targetId);
                if (targetElement) {
                    let collapsedItems = localStorage.getItem('collapsedItems');
                    collapsedItems = collapsedItems ? JSON.parse(collapsedItems) : [];

                    if (targetElement.classList.contains('show')) {
                        const index = collapsedItems.indexOf(targetId);
                        if (index > -1) {
                            collapsedItems.splice(index, 1);
                        }
                    } else {
                        if (!collapsedItems.includes(targetId)) {
                            collapsedItems.push(targetId);
                        }
                    }
                    localStorage.setItem('collapsedItems', JSON.stringify(collapsedItems));
                }
            });
        });
        document.querySelectorAll('.nav-link').forEach(link => {
            link.addEventListener('click', function (e) {
                e.preventDefault();
                const url = link.getAttribute('href');
                if(url=="#")return;
                if(url.includes("system-pages"))return;
                document.getElementById('mainiframe').src = url;
                updateURLParam('page', url);
            });
        });

        const urlParams = new URLSearchParams(window.location.hash);
        const page = urlParams.get('#page')

        if (page) {
            document.getElementById('mainiframe').src = page;
        } else {
            document.getElementById('mainiframe').src = '{{ url('console') }}';
        }
    });

    function reurl(){
        url = location.href;
        var times = url.split("?t=");
        if(times[1] != 1){
            url += "?t=1";
            self.location.replace(url);
        }
    }
    οnlοad=reurl
   function editInfo(id) {
       var page = layer.open({
           type: 2,
           title: '{{__('auto.修改个人信息')}}',
           shadeClose: true,
           shade: 0.8,
           area: ['70%', '90%'],
           content: '/edit/info/'+id
       });
   }
</script>
<!-- plugins:js -->
<script src="/assets/vendors/js/vendor.bundle.base.js"></script>
<script src="/assets/vendors/js/vendor.bundle.addons.js"></script>
<!-- endinject -->
<!-- Plugin js for this page-->
<!-- End plugin js for this page-->
<!-- inject:js -->
<script src="/assets/js/off-canvas.js"></script>
{{--<script src="/assets/js/misc.js"></script>--}}
<!-- endinject -->
<!-- Custom js for this page-->
<script src="/assets/js/dashboard.js"></script>
<!-- End custom js for this page-->
</body>

</html>
