import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
// import { BackgroundMode, LocalNotifications } from 'ionic-native';
import { PreferencesProvider } from '../../providers/preferences-provider';

@Component({
    selector: 'page-settings',
    templateUrl: 'settings.html'
})
export class SettingsPage {

    startPage: number;
    sync: boolean;
    syncFrecuency: string;

    constructor(
        public navCtrl: NavController,
        public preferencesProvider: PreferencesProvider
    ) { 
        this.initialize();
    }

    ionViewDidLoad() {
        console.log('Hello Settings Page');
    }

    /**
     *
     */
    initialize() {
        this.startPage = this.preferencesProvider.getStartPage();
        this.sync = this.preferencesProvider.getSync();
        this.syncFrecuency = this.preferencesProvider.getSyncFrecuency();
    }

    /**
     *
     */
    changeStartPage(e: any) {
        this.preferencesProvider.setStartPage(e);
    }

    /**
     *
     */
    changeSync(e: any) {
        this.sync = e;
        this.preferencesProvider.setSync(e);
        
        // if (e) {
        //     BackgroundMode.enable();

        //     LocalNotifications.schedule({
        //         id: 1,
        //         title: "Actualización de datos de Odoo Mobile",
        //         every: "minute"
        //     });

        //     LocalNotifications.on("trigger", () => { 
        //         console.log("Realizar actualización");
        //     });
        // } else {
        //     BackgroundMode.disable();

        //     LocalNotifications.clearAll();
        // }
    }

    /**
     *
     */
    changeSyncFrecuency(e: any) {
        this.preferencesProvider.setSyncFrecuency(e);
    }
}
