
myVueMixin.push({
    mounted() {
        this.loadOSC();
    },
    methods: {
        loadOSC() {
            axios({
                method: 'GET',
                url: this.$store.state.config.base_url + '/panel/osc',
            }).then((response) => {
                if (!isObject(response.data)) return setTimeout(this.loadOSC, 1000);
                if (!response.data.app_id) return;
                this.osc = response.data;
                try {
                    this.initOnesignal();
                } catch (error) {

                }
            }, (error) => { });
        },
        initOnesignal() {
            OneSignal.push(() => {
                this.osc.init = {
                    appId: this.osc.app_id,
                    safari_web_id: this.osc.safari_web_id,
                    notifyButton: {
                        enable: false,
                    },
                    autoResubscribe: true,
                    allowLocalhostAsSecureOrigin: true,
                    promptOptions: {
                        slidedown: {
                            prompts: [{
                                type: "push", // current types are "push" & "category"
                                autoPrompt: true,
                                text: {
                                    /* limited to 90 characters */
                                    actionMessage: "Izinkan Aplikasi Untuk Memberikan Pemberitahuan",
                                    /* acceptButton limited to 15 characters */
                                    acceptButton: "Izinkan",
                                    /* cancelButton limited to 15 characters */
                                    cancelButton: "Tidak"
                                },
                                delay: {
                                    pageViews: 1,
                                    timeDelay: 1
                                }
                            }]
                        }
                    },
                };

                OneSignal.SERVICE_WORKER_PARAM = {
                    scope: '/'
                };
                OneSignal.SERVICE_WORKER_PATH = 'OneSignalSDKWorker.js'
                OneSignal.SERVICE_WORKER_UPDATER_PATH = 'OneSignalSDKUpdaterWorker.js'
                OneSignal.init(this.osc.init);

                OneSignal.getExternalUserId().then((externalUserId) => {
                    if (externalUserId != this.osc.euid) {
                        OneSignal.removeExternalUserId();
                        OneSignal.showSlidedownPrompt();
                    }
                    OneSignal.setExternalUserId(this.osc.euid);
                });
            });

        }
    }
})