/**
 * @module widget-myportal-login-ng
 * @author Lenin Meza <lmeza@anzen.com.mx>
 *
 * @description
 * Login
 */
import angular from "vendor-bb-angular";
import _ from "vendor-lodash";
// Dependencies
import widgetModuleKey, { widgetKey } from "lib-bb-widget-ng";
import eventBusModuleKey, { eventBusKey } from "lib-bb-event-bus-ng";
import extendHooks from "lib-bb-widget-extension-ng";
import modelLoginModuleKey, {
    modelLoginKey,
} from "model-myportal-login-ng";
import ngMessages from "vendor-bb-angular-ng-messages";
import bbStorageModuleKey, { bbStorageServiceKey } from "lib-bb-storage-ng";

import Controller from "./controller";

import defaultHooks from "./default-hooks";

const moduleKey = "widget-myportal-login-ng";
const hooksKey = `${moduleKey}:hooks`;

export default angular
  .module(moduleKey, [
    widgetModuleKey,
    eventBusModuleKey,
    modelLoginModuleKey,
    ngMessages,
    bbStorageModuleKey,
  ])
  .factory(hooksKey, extendHooks(defaultHooks))
  .constant("_", _)
  .controller("LoginController", [
    // dependencies to inject
    eventBusKey,
    hooksKey,
    modelLoginKey,
    widgetKey,
    bbStorageServiceKey,
    "_",
    /* into */
    Controller,
  ])
  .run([eventBusKey, widgetKey, (bus, widget) => {
    bus.publish("cxp.item.loaded", {
      id: widget.getId(),
    });
  }])
  .name;
