var angular = require('cla_angular');

require('../../common/file_upload_control');
qq = require('fileuploader');
window.qq = qq;

var lb = require('lightbox');
require('./lightbox_decorate.js');

require('ng.cla.core.lmsg');
require('ng.cla.core.growl');

require('./../../../../node_modules/angular-utils-pagination/dirPagination');

require('imports-loader?angular=cla_angular!exports-loader?angular!./directive/fileupload.js');
require('imports-loader?angular=cla_angular!exports-loader?angular!./directive/doclink.js');
require('imports-loader?angular=cla_angular!exports-loader?angular!./directive/link.js');
require('imports-loader?angular=cla_angular!exports-loader?angular!./directive/mention.js');

require('imports-loader?angular=cla_angular!exports-loader?angular!./directive/userDetails.js');

require('imports-loader?angular=cla_angular!exports-loader?angular!./ui_comments.js');

require('imports-loader?angular=cla_angular!exports-loader?angular!./directive/comment.js');

require('imports-loader?angular=cla_angular!exports-loader?angular!./service/comment_width.service.js');

require('imports-loader?angular=cla_angular!exports-loader?angular!./controller/commentController.js');
require('imports-loader?angular=cla_angular!exports-loader?angular!./model/commentModel.js');
require('imports-loader?angular=cla_angular!exports-loader?angular!./model/commentsCollection');

require('imports-loader?angular=cla_angular!exports-loader?angular!./directive/comment_edit.directive.js');
require('imports-loader?angular=cla_angular!exports-loader?angular!./directive/comments.directive.js');

require('imports-loader?angular=cla_angular!exports-loader?angular!./service/annotation.service.js');
require('imports-loader?angular=cla_angular!exports-loader?angular!./directive/annotation_picker.js');
require('imports-loader?angular=cla_angular!exports-loader?angular!./directive/clang_likes_modal.js');
require('imports-loader?angular=cla_angular!exports-loader?angular!./service/profile_image_url.service.js');
require('imports-loader?angular=cla_angular!exports-loader?angular!./directive/profile_image_url_loader.js');

require('../css/comments.css');

var comments = {
    angular: angular,

    init: function (element_id) {
        var comments_div = document.getElementById(element_id);

        // Only bootstrap if we are not already in an app (where a valid scope will exist)
        if (typeof angular.element(comments_div).scope() === 'undefined')
        {
            // Disable any URL manipulation when used outside an AngularJS app
            angular.module('commentsModule')
                .config( ['$provide', function ($provide){
                    $provide.decorator('$browser', ['$delegate', function ($delegate) {
                        $delegate.onUrlChange = function () {};
                        $delegate.url = function () { return ""};
                        return $delegate;
                    }]);
                }]);

            angular.bootstrap(comments_div, ["commentsModule", 'cla.core.lmsg', 'cla.core.growl']);
        }
    },

    initWhenReady: function (element_id) {
        var self = this;
        angular.element(document).ready(function() {
            self.init(element_id)
        });
    }

};

module.exports = comments;
