import {Injectable} from '@angular/core';
import {FrameService} from '../frame/frame.service';
import {CookieService} from 'ngx-cookie-service';

@Injectable()
export class SettingsService {

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


  constructor(public cookie: CookieService) {

    // User Settings
    // -----------------------------------
    this.user = FrameService.FrameOptr;
    // App Settings
    // -----------------------------------
    this.app = {
      name: '禾木后台管理框架',
      description: ''
    };
    this.layout = {
      isFixed: this.cookie.get('frame.layout.isFixed') ? this.cookie.get('frame.layout.isFixed') : true,
      isCollapsed: false,
      isBoxed:  this.cookie.get('frame.layout.isBoxed') ? this.cookie.get('frame.layout.isBoxed') : false,
      isRTL:  this.cookie.get('frame.layout.isRTL') ? this.cookie.get('frame.layout.isRTL') : false,
      horizontal:  this.cookie.get('frame.layout.horizontal') ? this.cookie.get('frame.layout.horizontal') : false,
      isFloat:  this.cookie.get('frame.layout.isFloat') ? this.cookie.get('frame.layout.isFloat') : false,
      asideHover:  this.cookie.get('frame.layout.asideHover') ? this.cookie.get('frame.layout.asideHover') : false,
      theme:  this.cookie.get('frame.layout.theme') ? this.cookie.get('frame.layout.theme') : null,
      asideScrollbar:  this.cookie.get('frame.layout.asideScrollbar') ? this.cookie.get('frame.layout.asideScrollbar') : false,
      isCollapsedText:  this.cookie.get('frame.layout.isCollapsedText') ? this.cookie.get('frame.layout.isCollapsedText') : false,
      useFullLayout:  this.cookie.get('frame.layout.useFullLayout') ? this.cookie.get('frame.layout.useFullLayout') : false,
      hiddenFooter:  this.cookie.get('frame.layout.hiddenFooter') ? this.cookie.get('frame.layout.hiddenFooter') : false,
      offsidebarOpen: false,
      asideToggled:  this.cookie.get('frame.layout.asideToggled') ? this.cookie.get('frame.layout.asideToggled') : false,
      viewAnimation: this.cookie.get('frame.layout.viewAnimation') ? this.cookie.get('frame.layout.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.cookie.set('frame.layout.' + name, value);
      return this.layout[name] = value;
    }
  }

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

}
