text: 'use strict';
  
  const angular = require('angular');
  
  import { AccountService, Registry, StageConstants } from '@spinnaker/core';
  
  module.exports = angular
    .module('spinnaker.kubernetes.pipeline.stage.enableAsgStage', [])
    .config(function() {
      Registry.pipeline.registerStage({
        provides: 'enableServerGroup',
        cloudProvider: 'kubernetes',
        templateUrl: require('./enableAsgStage.html'),
        executionDetailsUrl: require('./enableAsgExecutionDetails.html'),
        executionConfigSections: ['enableServerGroupConfig', 'taskStatus'],
        executionStepLabelUrl: require('./enableAsgStepLabel.html'),
        validators: [
          { type: 'requiredField', fieldName: 'cluster' },
          { type: 'requiredField', fieldName: 'target' },
          { type: 'requiredField', fieldName: 'namespaces' },
          { type: 'requiredField', fieldName: 'credentials', fieldLabel: 'account' },
        ],
      });
    })
    .controller('kubernetesEnableAsgStageCtrl', [
      '$scope',
      function($scope) {
        let stage = $scope.stage;
  
        $scope.state = {
          accounts: false,
          namespacesLoaded: false,
        };
  
        AccountService.listAccounts('kubernetes').then(function(accounts) {
          $scope.accounts = accounts;
          $scope.state.accounts = true;
        });
  
        $scope.targets = StageConstants.TARGET_LIST;
  
        stage.namespaces = stage.namespaces || [];
        stage.cloudProvider = 'kubernetes';
        stage.interestingHealthProviderNames = ['KubernetesService'];
  
        if (!stage.credentials && $scope.application.defaultCredentials.kubernetes) {
          stage.credentials = $scope.application.defaultCredentials.kubernetes;
        }
  
        if (!stage.target) {
          stage.target = $scope.targets[0].val;
        }
  
        $scope.$watch('stage.credentials', $scope.accountUpdated);
      },
    ]);
  