define(["Ti/_/declare","Ti/_/UI/SuperView","Ti/UI/View","Ti/UI","Ti/_/lang"],function(t,a,e,i,o){var s=require.is,r=i.FILL,n={post:"_updateTabsBackground"};return t("Ti.UI.TabGroup",a,{constructor:function(a){var s=this,n=(s.__values__.constants.tabsAtBottom=o.val(a&&a.tabsAtBottom,s.__values__.constants.tabsAtBottom),t(e,{declaredClass:"Ti.UI.TabBarContainer"}));s._tabBarContainer=new n({width:r,layout:i._LAYOUT_CONSTRAINING_HORIZONTAL}),s.tabHeight=75,s._tabContentContainer=i.createView({width:r,height:r}),s.layout=i._LAYOUT_CONSTRAINING_VERTICAL,s.tabs=[],s.tabsAtBottom=o.val(a&&a.tabsAtBottom,!0)},addTab:function(t){var a=this.tabs;a.push(t),t._setTabGroup(this),1===a.length?this.activeTab=t:this._tabBarContainer._add(this._createTabDivider()),this._tabBarContainer._add(t),this._updateTabBackground(t),this._publish(t)},_addTabContents:function(t){this._tabContentContainer._add(t)},_removeTabContents:function(t){this._tabContentContainer._remove(t)},removeTab:function(t){var a=this.tabs,e=this.tabs.indexOf(t);e>=0&&(a.splice(e,1),this._tabBarContainer.remove(t),t===this._activeTab&&this._activateTab(a[0]),this._unpublish(t))},_createTabDivider:function(){return i.createView({width:this.tabDividerWidth,height:r,backgroundColor:this.tabDividerColor})},close:function(){this._previousTab=null,a.prototype.close.call(this)},_getEventData:function(){var t=this.tabs,a=this._previousTab,e=this._activeTab;return{index:e&&t.indexOf(e),previousIndex:a&&t.indexOf(a),tab:e,previousTab:a}},_handleFocusEvent:function(){var t=this._previousTab,a=this._activeTab;t&&t._blur(),!this._focused&&this._opened&&(this.fireEvent("focus",this._getEventData()),a&&a._focus()),this._focused=1},_handleBlurEvent:function(t){if(t){for(var a,e=0,i=this.tabs.length;i>e;)a=this.tabs[e++],(2!==t||a===this._activeTab)&&a._blur();this._previousTab=void 0}this._focused&&this._opened&&this.fireEvent("blur",this._getEventData()),this._focused=0},_activateTab:function(t){var a=(this.tabs,this._activeTab);a!==t&&((this._previousTab=a)&&(a.active=!1,a._doBackground()),i.currentTab=this._activeTab=t,t.active=!0,this._updateTabsBackground())},_updateTabBackground:function(t){var a=t.active?"activeTab":"tabs";["","Focused","Disabled","Selected"].forEach(function(e){e="Background"+e,t["_default"+e+"Color"]=this[a+e+"Color"],t["_default"+e+"Image"]=this[a+e+"Image"]},this),t._doBackground()},_updateTabsBackground:function(){for(var t=this.tabs,a=0,e=t.length;e>a;)this._updateTabBackground(t[a++])},_updateDividers:function(){for(var t=this._tabBarContainer._children,a=1;a<t.length;a+=2){var e=t[a];e.width=this.tabDividerWidth,e.backgroundColor=this.tabDividerColor}},_defaultWidth:r,_defaultHeight:r,constants:{bubbleParent:!1},properties:{activeTab:{set:function(t){return s(t,"Number")&&(t=this.tabs[t]),!t in this.tabs?void 0:t},post:function(t){o.isDef(t)&&this._activateTab(t)}},tabs:{set:function(t){if(s(t,"Array")){var a,e=this._tabBarContainer;if(e._removeAllChildren(),t.length)for(a=0;a<t.length;a++)t[a]._setTabGroup(this),0==a&&this._activateTab(this.activeTab=t[a]),this._publish(t[a]),a&&e._add(this._createTabDivider()),e._add(t[a]);return t}},post:"_updateTabsBackground"},tabsAtBottom:{set:function(t,a){if(t!==a){var e=this._tabContentContainer,i=this._tabBarContainer;this._activeTab&&this._activeTab._setNavBarAtTop(t),this._remove(e),this._remove(i),t?(this._add(e),this._add(i)):(this._add(i),this._add(e))}return t}},activeTabBackgroundColor:{post:"_updateTabsBackground",value:"#fff"},activeTabBackgroundImage:n,activeTabBackgroundDisabledColor:{post:"_updateTabsBackground",value:"#888"},activeTabBackgroundDisabledImage:n,activeTabBackgroundFocusedColor:{post:"_updateTabsBackground",value:"#ccc"},activeTabBackgroundFocusedImage:n,activeTabBackgroundSelectedColor:{post:"_updateTabsBackground",value:"#ddd"},activeTabBackgroundSelectedImage:n,tabsBackgroundColor:{post:"_updateTabsBackground",value:"#aaa"},tabsBackgroundImage:n,tabsBackgroundDisabledColor:{post:"_updateTabsBackground",value:"#666"},tabsBackgroundDisabledImage:n,tabsBackgroundFocusedColor:{post:"_updateTabsBackground",value:"#ccc"},tabsBackgroundFocusedImage:n,tabsBackgroundSelectedColor:{post:"_updateTabsBackground",value:"#ddd"},tabsBackgroundSelectedImage:n,tabDividerColor:{post:"_updateDividers",value:"#555"},tabDividerWidth:{post:"_updateDividers",value:1},tabHeight:{set:function(t){return this._tabBarContainer.height=t,t}}}})});