<!-- BEGIN: Vendor JS-->
<script src="{{ url('theme/vendors/js/vendors.min.js') }}"></script>
<!-- BEGIN Vendor JS-->

<!-- BEGIN: Page Vendor JS-->
<script src="{{ url('theme/vendors/js/ui/jquery.sticky.js') }}"></script>
{{-- <script src="{{ url('theme/vendors/js/charts/apexcharts.min.js') }}"></script> --}}
<script src="{{ url('theme/vendors/js/extensions/toastr.min.js') }}"></script>
<!-- END: Page Vendor JS-->

<!-- BEGIN: Theme JS-->
<script src="{{ url('theme/js/core/app-menu.js') }}"></script>
<script src="{{ url('theme/js/core/app.js') }}"></script>
<!-- END: Theme JS-->

<!-- BEGIN: Page JS-->
{{-- <script src="{{ url('theme/js/scripts/pages/dashboard-ecommerce.js') }}"></script> --}}
<script src="{{ asset('js/sweetalert.js') }}"></script>
<!-- END: Page JS-->
<script src="{{ asset('theme/vendors/js/forms/select/select2.full.min.js') }}"></script>
<script src="{{ asset('theme/js/scripts/forms/form-select2.min.js') }}"></script>
{{-- <script src="{{ asset('theme/js/scripts/extensions/ext-component-blockui.js') }}"></script> --}}
<script>
    $(window).on('load', function() {
        if (feather) {
            feather.replace({
                width: 14,
                height: 14
            });
        }
    })
</script>
{{-- @livewireScripts --}}
@once
<script>
    window.addEventListener('notify-swal', function(e) {
        let data = e.detail;
        let title = data.title;
        let message = data.message;
        let type = data.type;

        Swal.fire({
            position: 'top-end',
            icon: type,
            title: title,
            showConfirmButton: false,
            timer: 1500
        })
    });
</script>
<script>
    @if(Session::has('error'))
    Swal.fire({
        position: 'top-end',
        icon: 'error',
        title: '{{ Session::get('error') }}',
        showConfirmButton: false,
        timer: 1500
    });
    @elseif (Session::has('success'))
    Swal.fire({
        position: 'top-end',
        icon: 'success',
        title: '{{ Session::get('success') }}',
        showConfirmButton: false,
        timer: 1500
    });
    @endif

    $(document).ready( function () {
        $('.dataTable').DataTable();
    } );

    $(document).ready(function() {
    $('.dataTableExcel').DataTable( {
        dom: 'Bfrtip',
        buttons: [
            'excel'
        ]
    } );
} );
</script>
<script>
    window.addEventListener('close-modal', e => {
        $('#'+e.detail.modal_id).modal('hide');
    });

    window.addEventListener('open-modal', e => {
        $('#'+e.detail.modal_id).modal('show');
    });

    $(document).ready(function() {
        $(".modal").on("show.bs.modal", function() {
            $(".dynamic").html('<div class="d-flex justify-content-center"><div class="spinner-border text-primary" role="status"></div></div>');
        });
    });

    window.addEventListener('refresh-icon', e => {
        feather.replace();
    });
</script>
@endonce
{{-- <script src="https://www.gstatic.com/firebasejs/7.23.0/firebase.js"></script>
<script>
    var firebaseConfig = {
        apiKey: "AIzaSyDASAxfCBxABno3XrIb7d1QPQJWw4cSYtM",
        authDomain: "umc-push-notification.firebaseapp.com",
        projectId: "umc-push-notification",
        storageBucket: "umc-push-notification.appspot.com",
        messagingSenderId: "539322685533",
        appId: "1:539322685533:web:69d3c15dcdf8ceb7a795b4",
        measurementId: "G-J4MT1RC45T"
    };

    var deviceToken = '';

    firebase.initializeApp(firebaseConfig);
    const messaging = firebase.messaging();

    initFirebaseMessaging();

    // function setNotificationSetting(element) {
    //     let notif = 0;

    //     if($(element).prop('checked')){
    //         notif = 1;
    //     }

    //     $.ajaxSetup({
    //         headers: {
    //             'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
    //         }
    //     });

    //     $.ajax({
    //         url: "{{ route('save-firebase-token') }}",
    //         type: 'POST',
    //         data: {
    //             token: deviceToken,
    //             notif: notif
    //         },
    //         dataType: 'html',
    //         success: function (response) {
    //             // Swal.fire({
    //             //     position: 'top-end',
    //             //     icon: 'success',
    //             //     title: 'Setting berhasil disimpan',
    //             //     showConfirmButton: false,
    //             //     timer: 1500
    //             // });
    //             // alert('Token saved successfully.');
    //         },
    //         error: function (err) {
    //             Swal.fire({
    //                 position: 'top-end',
    //                 icon: 'error',
    //                 title: 'Setting gagal disimpan',
    //                 text: 'Mohon untuk refresh browser anda!',
    //                 showConfirmButton: false,
    //                 timer: 2500
    //             });
    //             // console.log('User Chat Token Error'+ err);
    //         },
    //     });
    // }

    function initFirebaseMessaging() {
            messaging
            .requestPermission()
            .then(function () {
                return messaging.getToken()
            })
            .then(function(token) {
                console.log(token);
                deviceToken = token;

                if(token == "{{ Auth::user()->firebase_token }}" && "{{ Auth::user()->notification }}" == 1){
                    console.log('podo');
                    $('#systemNotification').prop('checked', true);
                }
                else{
                    console.log('bedo');
                    $('#systemNotification').prop('checked', false);
                }

            }).catch(function (err) {
                console.log('User Chat Token Error'+ err);
            });
     }

    messaging.onMessage(function(payload) {
        Swal.fire({
            icon: 'success',
            title: payload.notification.title,
            text: payload.notification.body,
            showConfirmButton: true,
        });
        const noteTitle = payload.notification.title;
        const noteOptions = {
            body: payload.notification.body,
            icon: payload.notification.icon,
        };
        new Notification(noteTitle, noteOptions);
    });

    function testMessage(){
        let url = "{{ route('test-message') }}";
        let request = $.ajax({
            url: url,
            type: 'GET',
            dataType: 'html',
            success: function(response){
                // Swal.fire({
                //     position: 'top-end',
                //     icon: 'success',
                //     title: 'Terkirim',
                //     showConfirmButton: false,
                //     timer: 1500
                // });
            },
            error: function(err){
                Swal.fire({
                    position: 'top-end',
                    icon: 'error',
                    title: 'Gagal terkirim',
                    showConfirmButton: false,
                    timer: 2500
                });
            }
        });
    }
</script> --}}
@stack('js')
@yield('js')
