// Using bower to manage the dependency
// Define module & its deps
// For init app
require.config({
  waitSeconds: 45,
  urlArgs: 'bust=' + new Date().getTime(), // Prevent cache
  baseUrl: 'js',
  paths: {
    // Vendors
    angular: 'libs/angular.min',
    angular_route: 'libs/angular-route.min',
    angular_cookie: 'libs/cookies.min',
    angular_i18next: 'libs/ng-i18next.min',
    angular_sanitize: '../bower_components/angular-sanitize/angular-sanitize.min',
    angular_ui_route: 'libs/angular-ui-router.min',

    // jQuery
    jquery: 'libs/jquery-1.10.2.min',
    jquery_ui: 'libs/jquery.ui.min',
    lodash: 'libs/lodash.min',
    i18next: 'libs/i18next-1.9.0.min',
    noty: 'libs/noty.min',
    bootstrap: 'libs/bootstrap.min',
    datatable: 'libs/jquery.dataTables.min',
    icheck: 'libs/icheck',
    dt_bootstrap: 'libs/dataTables.bootstrap.min',
    bootstrap_ui: 'libs/ui-bootstrap-tpls-0.12.0.min',
    ui_select: '../bower_components/angular-ui-select/dist/select.min',
    jquery_cookie: 'libs/jquery.cookie',

    oc_lazyload: 'libs/ocLazyLoad.min',
    moment: 'libs/moment/moment.min',
    moment_ja: 'libs/moment/locale/ja',
    moment_vi: 'libs/moment/locale/vi',
    moment_locale: 'libs/moment/locale/moment-with-locales',
    bootstrap_dialog: 'libs/bootstrap-dialog',
    select_box_it: 'libs/jquery.selectBoxIt.min',
    tokenfield: 'libs/bootstrap-tokenfield.min',
    selectonic: 'libs/jquery.selectonic.min',
    // Other plugins
    plugins: 'libs/hogo-pro-plugin.min',
    // My app
    // Shared components
    session: 'shared/session',
    util: 'shared/util',
    constant: 'shared/constant',
    // model: 'shared/model',

    // Directive & filter
    filters: 'common/filters/filters.min',
    directives: 'common/directives/directives',

    THREE: '../bower_components/threejs/build/three',
    // Push notification lib
    socket_notification: 'shared/SocketNotificationService',
    // highcharts
    highcharts: 'libs/highcharts/highcharts.min',
    angular_highcharts: 'libs/highcharts/highcharts-ng.min',

    // Copy to clibboard
    angular_zeroclipboard: 'libs/zeroclipboard/angular-zeroclipboard.min',

    // load config server (local/dev/prod)
    // config_server: 'shared/config/pro-server',
    config_server: 'shared/config/dev-server',

    // Inbrowser viewer
    viewer: 'components/view-online/viewer',
    theme: '../theme/js/theme',
    porthole: 'libs/porthole.min',

    // PL upload
    plupload: 'plupload/plupload.full.min',
    // Pusher
    pusher: '../bower_components/pusher-js/dist/web/pusher',
    clipboard: '../bower_components/clipboard/dist/clipboard.min',

    placeholder: 'libs/jquery.placeholder.min',
    ngFileSaver: '../bower_components/angular-file-saver/dist/angular-file-saver.bundle.min',
    angular_daterangepicker: '../bower_components/daterangepicker/angular-daterangepicker.min',
    daterangepicker: '../bower_components/daterangepicker/daterangepicker',
  },
  // Define dependency for each object
  // If we do this, we dont have to use define
  // There're a lot of things that I can't understand from this config
  shim: {
    angular: ['jquery'], // Prevent using jqLite
    // Angular modules
    angular_route: ['angular'],
    oc_lazyload: ['angular'],
    bootstrap_ui: ['angular'],
    angular_cookie: ['angular'],
    ui_select: ['angular'],
    angular_sanitize: ['angular'],
    angular_ui_route: ['angular'],
    angular_i18next: ['angular', 'plugins'],
    // jQuery plug-ins
    jquery_ui: ['jquery'],
    icheck: ['jquery'],
    datatable: ['jquery'],
    dt_bootstrap: ['datatable'],
    bootstrap: ['jquery'],
    bootstrap_dialog: ['bootstrap'],
    noty: ['jquery'],
    moment: ['jquery'],
    tokenfield: ['jquery'],
    selectonic: ['jquery'],
    select_box_it: ['jquery_ui'],
    plugins: ['jquery_ui'],
    i18next: ['jquery'],
    jquery_scroll: ['jquery'],
    jquery_cookie: ['jquery'],

    // Filter & directive
    filters: ['angular'],

    // Our app
    session: [
      'util',
      'angular_cookie',
      'oc_lazyload',
      'constant',
      'socket_notification',
      'jquery_cookie',
      'config_server',
    ],
    constant: ['app'],
    // 'model': [ 'app' ],
    config_server: ['app'],
    directives: [
      'app',
      'icheck',
      'plugins',
      'select_box_it',
      'dt_bootstrap',
      'tokenfield',
      'selectonic',
    ], // jquery_ui_touch
    ngFileSaver: ['angular'],

    // Components
    share: ['angular'],
    // Three
    THREE: {
      exports: 'THREE',
    },
    // Define all services
    util: [
      'angular',
      'jquery',
      'lodash',
      'noty',
      'bootstrap_dialog',
      'moment',
      'moment_locale',
      'clipboard',
      'ngFileSaver',
    ],
    theme: ['bootstrap'],
    // Main module
    app: [
      'angular_route',
      'angular_i18next',
      'angular_sanitize',
      'angular_ui_route',
      'i18next',
      'theme',
    ],

    socket_notification: ['angular', 'constant', 'pusher'],
    plupload: { exports: 'plupload' },
    // highcharts
    highcharts: ['jquery'],
    angular_highcharts: ['highcharts', 'angular'],

    angular_zeroclipboard: ['angular'],
    placeholder: ['jquery'],

    porthole: {
      exports: 'Porthole',
    },

    daterangepicker: ['jquery', 'moment'],
    angular_daterangepicker: ['daterangepicker', 'angular'],
  },
  priority: ['jquery', 'angular'],
});

// Bootstrap the app
// All modules have to be available here
// It hard to understand with jqLite
require([
  'app',
  'filters',
  'directives',
  'bootstrap_ui',
  'ui_select',
  'session',
  'angular_highcharts',
  'angular_zeroclipboard',
  //    'stripe',
  'plupload',
  'placeholder',
  'porthole',
  'angular_daterangepicker',
], function () {
  angular.element().ready(function () {
    document.body.style.backgroundImage = 'none';
    // bootstrap the app manually
    angular.bootstrap(document, ['689Cloud']);
  });
});
