'use strict';
define(function() {
  var StepContainerDirective = function($compile, $scope) {
    return {
      //templateUrl:'js/XG/biz/yamoussoukro/modules/form/stepcontainer/view/StepContainer.html',
      template: '<div id="stepcontdiv_{{thisId}}"></div>',
      restrict: 'A',
      controller: 'StepContainerCtrl',
      scope: {},
      link: function($scope, element, attrs) {
        var update = function() {
          setTimeout(function() {
            var elt = document.getElementById('stepcontdiv_' + $scope.thisId);
            if ($scope.stepsConfig != null && $scope.stepsConfig != 'automatic')
              return;
            if (!$scope.ready || elt == null) update();
            else {
              var str =
                '<div class="gcff_accordion__tab" ng-repeat="theStep in steps">';
              str +=
                '  <div class="gcff_accordion__tab-title" ng-click="openTab(theStep.title);">{{theStep.title}}</div>';
              str +=
                '  <div class="gcff_accordion__tab-content" ng-show="isOpenTab(theStep.title)">';
              str += '     <div FormFieldPanelDirective>';
              str += '     </div>';
              str += '  </div>';
              str += '</div>';
              var cmp = $compile(str)($scope);
              angular.element(elt).append(cmp);
            }
          }, 250);
        };

        if ($scope.stepsConfig == null || $scope.stepsConfig == 'automatic')
          update();
      },
    };
  };

  StepContainerDirective.$inject = ['$compile'];
  return StepContainerDirective;
});
