/**
 * An element which displays custom git-specific setup information for its build triggers.
 */
angular.module('quay').directive('triggerSetupCustom', function() {
  var directiveDefinitionObject = {
    priority: 0,
    templateUrl: '/static/directives/trigger-setup-custom.html',
    replace: false,
    transclude: false,
    restrict: 'C',
    scope: {
      'repository': '=repository',
      'trigger': '=trigger',

      'nextStepCounter': '=nextStepCounter',
      'currentStepValid': '=currentStepValid',

      'analyze': '&analyze'
    },
    controller: function($scope, $element, ApiService) {
      $scope.analyzeCounter = 0;
      $scope.setupReady = false;

      $scope.state = {
        'build_source': null,
        'subdir': null
      };

      $scope.stepsCompleted = function() {
        $scope.analyze({'isValid': $scope.state.build_source != null && $scope.state.subdir != null});
      };

      $scope.$watch('state.build_source', function(build_source) {
        $scope.trigger['config']['build_source'] = build_source;
      });

      $scope.$watch('state.subdir', function(subdir) {
        $scope.trigger['config']['subdir'] = subdir;
        $scope.trigger.$ready = subdir != null;
      });

      $scope.nopLoad = function(callback) {
        callback();
      };
    }
  };

  return directiveDefinitionObject;
});
