import { Injectable } from '@angular/core';
//import { Storage } from '@ionic/storage';
import * as CryptoBrowserify from 'crypto-browserify';
import { BehaviorSubject } from 'rxjs';
// import { FloatSessionProvider } from '../providers/float-session/float-session';

export let CONFIG = {
  appVersion: 'myFloatApp 1.0.0',
  firebaseConfig: {
    apiKey: 'AIzaSyCQ1AZ-BWDWY9bLCEh-D6hLUOfDK7FnbTQ',
    authDomain: 'float-app-224118.firebaseapp.com',
    databaseURL: 'https://float-app-224118.firebaseio.com',
    projectId: 'float-app-224118',
    storageBucket: 'float-app-224118.appspot.com',
    messagingSenderId: '343605975098',
  },
  googleMapsKey: 'AIzaSyCPFo6GfBNOYEsUeFiw9Zq2XD54O5hXuO4',
  clientId: "FloatApp",
  googleWebClientId:
    '343605975098-ao362h3sq637l91q7o5haiv7gu44spo6.apps.googleusercontent.com',
  googleScopes:
    'email profile openid https://www.googleapis.com/auth/gmail.readonly',
  googleClientSecret: 'qj115Y45Ovs1WCJSa4xbCw46',
  oneSignal: {
    appId: 'e9a7bb38-0a27-4250-9fb7-9bd7871d7b63',
    apiKey: 'NjE2OTg4ZDAtMWQ5MC00ZGMwLThhM2MtY2JhZTkzMjAyNzBi',
    googleProjectNumber: '858926099772',
  },
  app: {
    environment: 'production',
    password: '342b90d2fc96017673858f5aecab4e1d',
    iv: '0dbe837a2196f4c5',
  },
  locationTracker: {
    cacheSize: 50,
  },
  decrypt: function (iv: string, text: string, password: string) {
    const decipher = CryptoBrowserify.createDecipheriv(
      'aes-256-ctr',
      password,
      iv
    );
    let dec = decipher.update(text, 'hex', 'utf8');
    dec += decipher.final('utf8');
    return JSON.parse(dec);
  },
  development: function () {
    return CONFIG.decrypt(
      CONFIG.app.iv,
      '078eb203fce4db5b9c7ab388dc6d98e103e284c6641f084f50ece99c6cfaebfdb1863f70e53d03f7bd24472112a4310e2b7b4c8d83f171e1028906f70212d41b9669d35d68533d5911ebdd030504885f8fe87dea68fe6f5bddb1336c6ba352c129d4aa3baaf953284c22f40ca3aa069a21a2a1e2f098071dccfc95307f8e42401f7c61a41eccb46e2dc244bef0aca5e11551ff8ee39781d359539f59c0a69d91a1e9094483c64f55feacffcda19acc3f7c738eebb0ca151a8c98b7490fc8fd5c0662ee8edd9a2cb2',
      CONFIG.app.password
    );
  },
  production: function () {
    return CONFIG.decrypt(
      CONFIG.app.iv,
      '078eb203fce4db5b9c7ab388dc6d98e103e284c6641f084f50ece99c6cfaebfdb1863f70e53d03e2a624543e4ff9304068101883d0b673ed288904b6525bbf5ecf69880d237e3b4657e4c4120b5f885cd3be79e96ebe743598a0762969af78c12b91e478f8a0037e4023f935bfa350c96eeed3e5bddc0b058da99e327cde1543172332f0199db1387cc645bda0afabb41f59edc38bd4c5961f519373c0a4d8dfe2bb5014d5ca4e58c583ad83e8d7c4404b358df8a5c3444bdd99b04c07c4ef3719',
      CONFIG.app.password
    );
  },
  development_tolik: function () {
    return CONFIG.decrypt(
      CONFIG.app.iv,
      '078eb203fce4db5b9c7ab388dc6d98e103e284c6641f084f50ece99c6cfaece4af9c3528e0325ff7ab3d43334ff9200d36714b8d96fa3cac7c8755b0001efe1b966b920d2138780252a1946a5944ce03caf971b56ffa3d0c8de6356b7eeb3dd06c91a83780f9532a096cb75efaf8179d2dbe93f7fdd35253a5a8de21719b5646157665f04a98e8327b9214eea0fcf5e71f5bfbdab7c3dd8f0f10d13084e3db93adc3094481830116acf5addca696d00f5a25dda4fcb2710b828da34f05c2f9085236b2d28bd944acb1a900c50578',
      CONFIG.app.password
    );
  },
};

@Injectable({ providedIn: 'root' })
export class AppSettingsProvider {
  private theme: BehaviorSubject<String>;

  constructor(/*private storage: Storage*/) {
    /*
    console.log('AppSettingsProvider::constructor');
    this.theme = new BehaviorSubject('light-theme');
    this.storage.get('selectedTheme').then(val => {
      console.log('AppSettingsProvider::constructor => ' + val);
      if (val == null || val !== 'dark-theme') {
        val = 'light-theme';
      }
      this.setActiveTheme(val);
    });
    */
  }

  setActiveTheme(val) {
    console.log('AppSettingsProvider::setActiveTheme(' + val + ')');
  //  this.storage.set('selectedTheme', val);
    this.theme.next(val);
  }

  getActiveTheme() {
    return this.theme.asObservable();
  }
}
