import { Injectable } from '@angular/core';
import {CookieService} from 'ngx-cookie-service';
declare var $: any;

@Injectable()
export class SettingsService {

    private user: any;
    private app: any;
    private layout: any;

    constructor(private cookieService: CookieService) {

        // User Settings
        // -----------------------------------
        this.user = {
            name: '张小庆',
            job: 'ng-developer',
            picture: 'assets/img/user/02.jpg'
        };

        // App Settings
        // -----------------------------------
        this.app = {
            name: 'HmSoft Frame',
            description: 'Angular Bootstrap Admin Template',
            year: ((new Date()).getFullYear())
        };

        // Layout Settings
        // -----------------------------------
        this.layout = {
            isFixed: this.cookieService.get('layout.isFixed') === 'false' ? false : true,
            isCollapsed: this.cookieService.get('layout.isCollapsed') === 'true' ? true : false,
            isBoxed: this.cookieService.get('layout.isBoxed') === 'true' ? true : false,
            isRTL: this.cookieService.get('layout.isRTL') === 'true' ? true : false,
            horizontal: this.cookieService.get('layout.horizontal') === 'true' ? true : false,
            isFloat:  this.cookieService.get('layout.isFloat') === 'true' ? true : false,
            asideHover:  this.cookieService.get('layout.asideHover') === 'true' ? true : false,
            theme: this.cookieService.get('layout.theme'),
            asideScrollbar:  this.cookieService.get('layout.asideScrollbar') === 'true' ? true : false,
            isCollapsedText:  this.cookieService.get('layout.isCollapsedText') === 'true' ? true : false,
            useFullLayout: false,
            hiddenFooter: false,
            offsidebarOpen: false,
            asideToggled: false,
            viewAnimation: 'ng-fadeInUp'
        };

    }

    getAppSetting(name) {
        return name ? this.app[name] : this.app;
    }
    getUserSetting(name) {
        return name ? this.user[name] : this.user;
    }
    getLayoutSetting(name) {
        return name ? this.layout[name] : this.layout;
    }

    setLayoutSetting(name, value) {
        if (typeof this.layout[name] !== 'undefined') {
          this.cookieService.set('layout.' + name, value);
          return this.layout[name] = value;
        }
    }

    toggleLayoutSetting(name) {
        return this.setLayoutSetting(name, !this.getLayoutSetting(name));
    }

}
