/*!
    Copyright (C) 2016 Google Inc., authors, and contributors <see AUTHORS file>
    Licensed under http://www.apache.org/licenses/LICENSE-2.0 <see LICENSE file>
    Created By: ivan@reciprocitylabs.com
    Maintained By: ivan@reciprocitylabs.com
*/

(function (can, $) {
  can.Component.extend({
    tag: 'tabs',
    template: can.view(GGRC.mustache_path + '/base_objects/tabs.mustache'),
    scope: {
      panels: [],
      setActive: function (scope, el, ev) {
        scope.panel.attr('active', true);
      }
    }
  });

  can.Component.extend({
    tag: 'tab-panel',
    template: can.view(GGRC.mustache_path + '/base_objects/tab_panel.mustache'),
    scope: {
      active: false,
      title: '@',
      panels: null
    },
    events: {
      inserted: function () {
        var panels = this.scope.attr('panels');
        panels.push({
          title: this.scope.attr('title'),
          panel: this.scope
        });
      },
      '{scope.panels} change': function (list, ev, item, action, status) {
        var index;
        var panel;

        item.split('.');
        index = Number(item[0]);
        panel = list[index].panel;
        if (status && this.scope !== panel) {
          this.scope.attr('active', false);
        }
      }
    }
  });
})(window.can, window.can.$);

@@ -458,24 +458,53 @@
 , el, ev) %7B%0A
+        ev.preventDefault();%0A
         scop
@@ -533,32 +533,517 @@
  true);%0A      %7D%0A
+    %7D,%0A    events: %7B%0A      '%7Bscope.panels%7D length': function (list, ev, item, action, status) %7B%0A        var panels = this.element.find('tab-panel');%0A        var active;%0A%0A        if (list.length !== panels.length) %7B%0A          return;%0A        %7D%0A        active = _.filter(list, function (item) %7B%0A          if (item.panel) %7B%0A            return item.panel.attr('active');%0A          %7D%0A        %7D);%0A        if (!active.length) %7B%0A          list%5B0%5D.panel.attr('active', true);%0A        %7D%0A      %7D%0A
     %7D%0A  %7D);%0A%0A  c

Set default active tab if none defined