<!doctype html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
<meta charset="utf-8">
    <link rel="icon" href="{{ asset('img/icon_pkb.png') }}">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <!-- CSRF Token -->
    <meta name="csrf-token" content="{{ csrf_token() }}">

    <title>
        @if (isset($cawangan_info['details_caw']) && $cawangan_info['details_caw'] == 'Putatan')
            v2 Putatan Lama
        @elseif (isset($cawangan_info['details_caw']) && $cawangan_info['details_caw'] == 'Putatan 2')
            v2 Putatan Baru
        @else
            SISTEM AR-RAHN
        @endif
    </title>

    <!-- Scripts -->
    <script src="{{ asset('js/app.js') }}" defer></script>
    <script src="{{ asset('vendor/adminlte/dist/js/adminlte.js') }}" defer></script>

    <!-- Fonts -->
    <link rel="dns-prefetch" href="//fonts.gstatic.com">
    <link href="https://fonts.googleapis.com/css?family=Nunito" rel="stylesheet">

    <!-- Styles -->
    <link href="{{ asset('css/app.css') }}" rel="stylesheet">
    <link href="{{ asset('css/main.css') }}" rel="stylesheet">
    <link href="{{ asset('css/loader.css') }}" rel="stylesheet">
    <link href="{{ asset('vendor/adminlte/dist/css/adminlte.css') }}" rel="stylesheet">
    <link href="{{ asset('vendor/fontawesome-free/css/all.css') }}" rel="stylesheet">
    <link href="{{ asset('vendor/DataTables/datatables.min.css') }}" rel="stylesheet">
    <link rel="stylesheet" href="https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css">
    <link rel="stylesheet" href="{{ asset('vendor/bootstrap/css/bootstrap.min.css') }}">
    <link href="{{ asset('css/select2.min.css') }}" rel="stylesheet" />
    <link rel="stylesheet" href="{{ asset('vendor/datepicker/css/bootstrap-datepicker.min.css') }}"/>
    <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
    <script src="{{ asset('js/jquery.min.js') }}"></script>
    <script src="{{ asset('vendor/bootstrap/js/bootstrap.min.js') }}"></script>
    <script src="{{ asset('js/select2.min.js') }}"></script>
    <script src="{{ asset('js/apexcharts.js') }}"></script>
    <script src="{{ asset('js/numeral.min.js') }}"></script>
    <script src="{{ asset('js/sweetalert.min.js') }}"></script>
    <script src="{{ asset('js/popper.min.js') }}"></script>
    <script src="{{ asset('vendor/DataTables/datatables.min.js') }}"></script>
    <script src="{{ asset('vendor/datepicker/js/bootstrap-datepicker.min.js') }}"></script>
    <script src="{{ asset('js/typehead.jquery.js') }}"></script>


    {{-- jquery validation --}}
    <script src="{{ asset('js/jquery.validate.min.js') }}"></script>
    <script src="{{ asset('js/additional-methods.min.js') }}"></script>

    {{-- Pusher --}}
    <script src="{{ asset('js/pusher.min.js') }}"></script>

    @if(Auth::user()->roles == 'ppc' || Auth::user()->roles == 'pc')
        <script>
            window.api = "{{ config('api.url') }}";
            window.kodcaw = "{{ Auth::user()->cawangan }}";
            window.apikey = "{{ env('PUSHER_APP_KEY') }}";
        </script>
        <script type="module" src="{{ asset('js/notification.js') }}?v={{ filemtime(public_path('js/notification.js')) }}"></script>
    @endif

    <script>
        function startTime() {
            var today = new Date();
            var d = today.getDate();
            var mon = today.getMonth()+1;
            var y = today.getFullYear();
            var h = today.getHours();
            var m = today.getMinutes();
            var s = today.getSeconds();
            m = checkTime(m);
            s = checkTime(s);
            document.getElementById('displaytime').innerHTML =
            d + "/" + mon + "/" + y + "  " +h + ":" + m + ":" + s;
            var t = setTimeout(startTime, 500);
        }
        function checkTime(i) {
            if (i < 10) {i = "0" + i};  // add zero in front of numbers < 10
            return i;
        }
    </script>

    <style>
        .custom-radio {
            font-size:18px;
            margin:20px 20px 20px 20px;
            display: inline-flex !important;
            flex-direction: column;
            align-items: flex-start !important;
        }

        .select2-container .select2-selection--single {
            height: 37px;
        }

        .select2-container .select2-selection--single .select2-selection__rendered {
            padding-left: 0px;
        }

        fieldset.scheduler-border {
            border: 1px dashed #eb2f06 !important;
            padding: 10px 5px 5px 5px;
            margin-left:-5px;
            margin-right:-5px;
            margin-bottom:5px;
            -webkit-box-shadow:  0px 0px 0px 0px #000;
            box-shadow:  0px 0px 0px 0px #000;
        }
        legend.scheduler-border {
            font-size: 1.2em !important;
            font-weight: bold !important;
            text-align: left !important;
            width:auto;
            padding:0 10px;
            border-bottom:none;
        }

        .text-gold {
            color: gold !important;
        }

    </style>

</head>
<body onload="startTime()" style="background-color:#BAC1C9;">

    @php
        $auth_user = Auth::user();

        if($auth_user['role_harian'] == 'teller')
        {
            $api_url = config('api.url');
            $gadai = Http::withOptions(['verify' => config('app.api_verify')])->get( config('api.url') .'/api/gadai/serah_marhun/khazanah/'. $auth_user['cawangan'])->json();
            $listserah = Http::withOptions(['verify' => config('app.api_verify')])->get(config('api.url').'/api/listSerahMarhunController/'.$auth_user['cawangan'])->json();
        }
    @endphp
    <div id="app">
        <div id="page_loader" class="not-loading"></div>
        <nav class="navbar navbar-expand-md navbar-light shadow-sm" 
             style="height:100px; 
                    background-color: 
                        {{ isset($cawangan_info['details_caw']) && $cawangan_info['details_caw'] == 'Putatan' ? 'red' : 
                           (isset($cawangan_info['details_caw']) && $cawangan_info['details_caw'] == 'Putatan 2' ? '#FF6961' : 'white') }};">
            <div class="container">
                <a class="navbar-brand" href="#" style="cursor:not-allowed;">
                    <img src="{{ asset('img/icon_pkb.png') }}" class="logo-arrahn-header" alt="Logo Ar Rahn" />
                    <span style="color: {{ isset($cawangan_info['details_caw']) && $cawangan_info['details_caw'] == 'Putatan 2' ? 'black' : 'white' }}; font-weight: bold;">
                        @if (isset($cawangan_info['details_caw']) && $cawangan_info['details_caw'] == 'Putatan')
                            arOS v2
                        @elseif (isset($cawangan_info['details_caw']) && $cawangan_info['details_caw'] == 'Putatan 2')
                            arOS v2
                        @endif
                    </span>
                </a>
                <!-- Display Time -->
                <div class="col-2">
                    <div 
                        id="displaytime" 
                        style="color: {{ isset($cawangan_info['details_caw']) && ($cawangan_info['details_caw'] == 'Putatan' || $cawangan_info['details_caw'] == 'Putatan 2') ? 'gold' : '#eb2f06' }}; font-weight:bold;">
                    </div>
                </div>
                <div class="navbar-brand ml-3">
                    <b class="{{ isset($cawangan_info['details_caw']) && $cawangan_info['details_caw'] == 'Putatan 2' ? 'text-black' : 
                                (isset($cawangan_info['details_caw']) && $cawangan_info['details_caw'] == 'Putatan' ? 'text-gold' : 'text-secondary') }}">
                        Cawangan :
                    </b>
                    <span style="color: {{ isset($cawangan_info['details_caw']) && $cawangan_info['details_caw'] == 'Putatan 2' ? 'black' : 
                                       (isset($cawangan_info['details_caw']) && $cawangan_info['details_caw'] == 'Putatan' ? 'white' : '#1abc9c') }}; font-weight:bold;">
                        {{ $cawangan_info["details_caw"] }}
                    </span>
                    @if (isset($cawangan_info['details_caw']) && ($cawangan_info['details_caw'] == 'Putatan' || $cawangan_info['details_caw'] == 'Putatan 2'))
                        <span class="badge badge-info">
                            @if ($cawangan_info['details_caw'] == 'Putatan')
                                Lama
                            @elseif ($cawangan_info['details_caw'] == 'Putatan 2')
                                Baru
                            @endif
                        </span>
                    @endif
                </div>
                
                <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="{{ __('Toggle navigation') }}">
                    <span class="navbar-toggler-icon"></span>
                </button>

                <div class="collapse navbar-collapse" id="navbarSupportedContent">
                    <!-- Left Side Of Navbar -->
                    <ul class="navbar-nav mr-auto">

                    </ul>

                    <!-- Right Side Of Navbar -->
                    <ul class="navbar-nav ml-auto">



                        @php $auth_user = Auth::user(); @endphp
                        @if ($auth_user['roles'] == 'ppc' || $auth_user['roles'] == 'pc')
                            <li class="nav-item dropdown" style="margin-right:10px;">
                                <a id="navbarDropdown" 
                                   class="nav-link" 
                                   href="#" 
                                   role="button" 
                                   data-toggle="dropdown" 
                                   aria-haspopup="true" 
                                   aria-expanded="false" 
                                   v-pre 
                                   style="color: {{ isset($cawangan_info['details_caw']) && $cawangan_info['details_caw'] == 'Putatan 2' ? 'black' : '#1abc9c' }};">
                                    <i id="bell" class="fa fa-bell"></i>
                                </a>

                                <div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarDropdown">
                                    <div id="divbiasa">
                                        <a class="dropdown-item" id="linkz" href="#">
                                            Tiada Data
                                        </a>
                                    </div>
                                </div>
                            </li>

                            <script>
                                var audiokhazanah = new Audio("{{ asset('sound/3.wav') }}");
                                audiokhazanah.muted = true;


                                // Enable pusher logging - don't include this in production
                                // Pusher.logToConsole = true;

                                var pusher = new Pusher("{{ env('PUSHER_APP_KEY') }}", {
                                    cluster: 'ap1',
                                    encrypted: true
                                });

                                var cawangankhazanah = '{{ $auth_user["cawangan"] }}';

                                var channel = pusher.subscribe('status-liked');
                                channel.bind('my-event', function(data) {
                                    // let message = JSON.stringify(data);

                                    if(cawangankhazanah == data.cawangan)
                                    {

                                        $('#bell').css("color", "red");
                                        $('#linkz').text(data.namateller + " Memohon Kelulusan");
                                        $("#linkz").attr("href", "{{ url('kelulusan') }}");


                                        audiokhazanah.play();
                                        audiokhazanah.muted = false;


                                        const Toast = Swal.mixin({
                                            toast: true,
                                            position: 'top-end',
                                            showConfirmButton: false,
                                            timer: 5000,
                                            timerProgressBar: true,
                                            didOpen: (toast) => {
                                                toast.addEventListener('mouseenter', Swal.stopTimer)
                                                toast.addEventListener('mouseleave', Swal.resumeTimer)
                                            }
                                        })

                                        Toast.fire({
                                            icon: 'error',
                                            title: 'Kelulusan Dipohon Sekarang!'
                                        })
                                    }

                                });

                                $("#navbarDropdown").click(function(){
                                    $('#bell').css("color", "grey");
                                });

                            </script>
                        @elseif($auth_user['role_harian'] == 'teller')
                            <li class="nav-item dropdown" style="margin-right:10px;">
                                <a id="navbarDropdown" 
                                   class="nav-link" 
                                   href="#" 
                                   role="button" 
                                   data-toggle="dropdown" 
                                   aria-haspopup="true" 
                                   aria-expanded="false" 
                                   v-pre 
                                   style="color: {{ isset($cawangan_info['details_caw']) && $cawangan_info['details_caw'] == 'Putatan' ? 'white' : (isset($cawangan_info['details_caw']) && $cawangan_info['details_caw'] == 'Putatan 2' ? 'black' : '#1abc9c') }};">
                                    <i id="bell" class="fa fa-bell"></i>
                                </a>

                                <div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarDropdown">
                                    <div id="divbiasa">
                                        <a class="dropdown-item" id="gadailinkz" href="#">
                                            Tiada Data
                                        </a>
                                    </div>
                                </div>
                            </li>

                            {{-- <script>

                                // Enable pusher logging - don't include this in production
                                // Pusher.logToConsole = true;

                                var pusher = new Pusher("{{ env('PUSHER_APP_KEY') }}", {
                                    cluster: 'ap1',
                                    encrypted: true
                                });

                                var channel = pusher.subscribe('notifikasi-pembayaran');
                                channel.bind('trigger-pembayaran', function(data) {
                                    let message = JSON.stringify(data);

                                    $('#bell').css("color", "red");
                                    $('#gadailinkz').text("Khazanah Serah Marhun Teller");
                                    // $("#gadailinkz").attr("href", "{{ url('kelulusan') }}");

                                    const Toast = Swal.mixin({
                                    toast: true,
                                    position: 'top-end',
                                    showConfirmButton: false,
                                    timer: 5000,
                                    timerProgressBar: true,
                                    didOpen: (toast) => {
                                        toast.addEventListener('mouseenter', Swal.stopTimer)
                                        toast.addEventListener('mouseleave', Swal.resumeTimer)
                                    }
                                    });

                                    Toast.fire({
                                    icon: 'error',
                                    title: 'Notifikasi Pembayaran!'
                                    });

                                });

                                $("#navbarDropdown").click(function(){
                                    $('#bell').css("color", "grey");
                                });

                            </script> --}}

                        @endif



                        <!-- Authentication Links -->
                        @guest
                            <li class="nav-item">
                                <a class="nav-link" href="{{ route('login') }}">{{ __('Login') }}</a>
                            </li>
                            @if (Route::has('register'))
                                <li class="nav-item">
                                    <a class="nav-link" href="{{ route('register') }}">{{ __('Register') }}</a>
                                </li>
                            @endif
                        @else
                            <li class="nav-item dropdown">
                                <!-- User Name at Top Right Corner -->
                                <a id="navbarDropdown" 
                                   class="nav-link dropdown-toggle" 
                                   href="#" 
                                   role="button" 
                                   data-toggle="dropdown" 
                                   aria-haspopup="true" 
                                   aria-expanded="false" 
                                   v-pre 
                                   style="color: {{ isset($cawangan_info['details_caw']) && $cawangan_info['details_caw'] == 'Putatan' ? 'white' : 
                                                   (isset($cawangan_info['details_caw']) && $cawangan_info['details_caw'] == 'Putatan 2' ? 'black' : '#1abc9c') }}; font-weight:bold;">
                                    {{ Auth::user()->name }}
                                </a>

                                <div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarDropdown">
                                    <a class="dropdown-item" href="{{ route('profile') }}">
                                        {{ __('Profile') }}
                                    </a>
                                    <a class="dropdown-item" href="{{ route('logout') }}"
                                       onclick="event.preventDefault();
                                                     document.getElementById('logout-form').submit();">
                                        {{ __('Logout') }}
                                    </a>

                                    <form id="logout-form" action="{{ route('logout') }}" method="POST" class="d-none">
                                        @csrf
                                    </form>
                                </div>
                            </li>

                        @endguest
                    </ul>

                </div>

                @php
                $gadaiNumber = isset($gadai) == false ? '0' : count($gadai);
                $listSerahNumber = isset($listserah) == false ? '0' : count($listserah);

                if($auth_user['role_harian'] == 'teller')
                {
                    echo '<div class="col-3">
                                <div class="col-12 pl-5">
                                    <div class="row">
                                        <h5 class="pr-3">G : <span class="text-success">' .$gadaiNumber. '</span></h5>
                                        <h5>T : 
                                            <span style="color: '.(isset($cawangan_info['details_caw']) && $cawangan_info['details_caw'] == 'Putatan' ? 'white' : 'red').';">
                                                '.$listSerahNumber.'
                                            </span>
                                        </h5>
                                    </div>
                                </div>
                        </div>';
                }
                @endphp

            </div>




        </nav>
        @if ($auth_user['roles'] == 'ppc' || $auth_user['roles'] == 'pc')

        @php
                $current = Carbon\Carbon::now();
                $tarikhsemasa = $current->toDateString();

                $cawangan = App\CawanganAR::where('kodcaw',$auth_user['cawangan'])->get()->toArray();
                $getVault = Http::withOptions(['verify' => config('app.api_verify')])->get(config('api.url').'/api/TunaiDiTangan/' . $auth_user['cawangan'],['tarikh' => $tarikhsemasa])->json();
        @endphp
                @if(floatval($getVault) > $cawangan[0]['max'])
                    <div id="notify-maksimum" style="z-index: 1" class="alert alert-warning sticky-top text-center" role="alert">
                        Baki peti besi anda sekarang adalah <b>RM{{ number_format($getVault,2) }}</b> dan melebihi had maksimum peti besi. Sila buat permohonan bayaran balik segera!
                    </div>
                @elseif(floatval($getVault) < $cawangan[0]['min'])
                    <div id="notify-minimum" style="z-index: 1" class="alert alert-danger sticky-top text-center" role="alert">
                        Baki peti besi anda sekarang adalah <b>RM{{ number_format($getVault,2) }}</b> dan kurang dari had minima peti besi. Sila buat permohonan wang segera!
                    </div>
                @else
                @endif
        @endif

        @if(session()->has('iklan') && session()->get('iklan') == 0)

        <div class="toast" role="alert" aria-live="assertive" aria-atomic="true" style="position: absolute; top: 1rem; right: 1rem; width:100%;z-index:1;" data-autohide="false">
            <div class="toast-header">

                <i class="text-danger fa-2x fa fa-exclamation-triangle mr-2"></i>
                <strong class="mr-auto text-danger fa-2x">Amaran</strong>
                {{-- <small>11 mins ago</small> --}}
                <button type="button" class="ml-2 mb-1 close" data-dismiss="toast" aria-label="Close">
                <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="toast-body">
                <b style="font-size:18px;">sila tukar kata laluan asal dengan segera!</b>
            </div>
        </div>
            <script>
                $('.toast').toast('show');
            </script>
        @endif


        <main class="py-4">
            @yield('content')
        </main>
    </div>
 
    {{-- @if (request()->route()->getName() === 'penebusan')
        @include('widgets.calculator')
    @endif --}}

    @yield('footer')
</body>
{{-- JS Stack--}}
@stack('additional_scripts')
</html>
