import DataUtils from '../../../../brain/tools/utilities/DataUtils';
import * as DataEvent from '../../../../brain/tools/events/DataEvent';
import DashManager from './controllers/DashManager';
import DBUtils from '../../../../brain/tools/utilities/DBUtils';
export default class Base {
	//--------------------------
	// constructor
	//--------------------------
	constructor() {
		this.dashManager = [];
		this.dataUtils = new DataUtils();
		this.dbUtils = new DBUtils();
		this.settings = [];
		this.storeLocalData();
	}
	start() {
		this.dashManager = new DashManager();
	}
	//--------------------------
	// methods
	//--------------------------
	storeLocalData() {
		var self = this;
		this.dataUtils
			.request('/api/post/json', DataEvent.SETTINGS_LOADED)
			.then(response => {
				let posts = JSON.parse(response.request['response']);
				let list = [];
				for (let index = 0; index < posts.length; index++) {
					list.push({ id: posts[index].id, post: posts[index].post });
				}
				self.dbUtils
					.syncLocal(list)
					.then(() => {
						self.start();
					})
					.catch(err => {
						console.log(err);
					});
			})
			.catch(err => {
				console.log(err);
			});
	}
	//--------------------------
	// event handlers
	//--------------------------
}
