'use strict';
define(function() {
  var ImportWmswidget = function() {
    return {
      templateUrl: 'js/XG/widgets/mapapp/importwms/views/importwmswidget.html',
      controller: 'ImportWmsCtrl',
      restrict: 'A',

      link: function(scope, elt, attrs, ctrl) {
        // Toggle list of suggestions
        elt.find('.ga-import-wms-open').on('click', function(evt) {
          elt.find('.tt-dropdown-menu').toggle();
          // Re-initialize the list of suggestions
          initSuggestions();
        });

        /*$rootScope.$on('$translateChangeEnd', function() {
                scope.handleFileUrl();
              });*/

        // Fill the list of suggestions with all the data
        function initSuggestions() {
          var taView = $(taElt).data('ttView');
          var dataset = taView.datasets[0];
          dataset.getSuggestions('http', function(suggestions) {
            taView.dropdownView.renderSuggestions(dataset, suggestions);
          });
        }
      },
    };
  };

  ImportWmswidget.$inject = [];
  return ImportWmswidget;
});
