import { Builtin } from '@vizality/entities';

import * as modules from './modules';

export default class Enhancements extends Builtin {
  async start () {
    this.injectStyles('styles/main.scss');
    this.callbacks = [];
    Object.keys(modules).forEach(async mod => {
      try {
        const callback = await modules[mod].default(this);
        if (typeof callback === 'function') {
          this.callbacks.push(callback);
        }
      } catch (err) {
        return this.error(this._labels.concat(modules[mod].labels), err);
      }
    });
  }

  stop () {
    for (const callback of this.callbacks) {
      (async () => {
        try {
          return callback();
        } catch (err) {
          return this.error(err);
        }
      })();
    }
  }
}
