define(["Ti/_/declare","Ti/_/UI/FontWidget","Ti/_/css","Ti/_/style","Ti/UI"],function(t,e,i,o,r){var a=o.set,d={post:function(){this.backgroundColor||this.backgroundDisabledColor||this.backgroundDisabledImage||this.backgroundFocusedColor||this.backgroundFocusedImage||this.backgroundImage||this.backgroundSelectedColor||this.backgroundSelectedImage?this._clearDefaultLook():this._setDefaultLook(),this._doBackground()}};return t("Ti.UI.Switch",e,{constructor:function(){var t=this._contentContainer=r.createView({width:r.INHERIT,height:r.INHERIT,layout:r._LAYOUT_CONSTRAINING_VERTICAL,borderColor:"transparent"});this._add(t),t._add(this._switchTitle=r.createLabel({width:r.INHERIT,height:r.INHERIT,verticalAlign:r.TEXT_VERTICAL_ALIGNMENT_CENTER,textAlign:r.TEXT_ALIGNMENT_CENTER})),t._add(this._switchIndicator=r.createView({width:40,height:10,borderRadius:4,borderWidth:1,borderColor:"#888"})),this._setDefaultLook();var e=this;e.addEventListener("singletap",function(){e.value=!e.value}),this.value=!1},_setDefaultLook:function(){this._hasDefaultLook||(this._hasDefaultLook=!0,this._previousBorderWidth=this.borderWidth,this._previousBorderColor=this.borderColor,i.add(this.domNode,"TiUIElementGradient"),i.add(this.domNode,"TiUIButtonDefault"),this._contentContainer.borderWidth=6,this._getBorderFromCSS())},_clearDefaultLook:function(){this._hasDefaultLook&&(this._hasDefaultLook=!1,this.borderWidth=this._previousBorderWidth,this.borderColor=this._previousBorderColor,i.remove(this.domNode,"TiUIElementGradient"),i.remove(this.domNode,"TiUIButtonDefault"),this._contentContainer.borderWidth=0)},_defaultWidth:r.SIZE,_defaultHeight:r.SIZE,properties:{backgroundColor:d,backgroundDisabledColor:d,backgroundDisabledImage:d,backgroundFocusedColor:d,backgroundFocusedImage:d,backgroundImage:d,backgroundSelectedColor:d,backgroundSelectedImage:d,enabled:{set:function(t,e){return t!==e&&(this._hasDefaultLook&&(t?(i.add(this.domNode,"TiUIElementGradient"),a(this.domNode,"backgroundColor","")):(i.remove(this.domNode,"TiUIElementGradient"),a(this.domNode,"backgroundColor","#aaa"))),this._setTouchEnabled(t)),t},value:!0},textAlign:{set:function(t){return this._switchTitle.textAlign=t,t}},titleOff:{set:function(t){return this.value||(this._switchTitle.text=t),t},value:"Off"},titleOn:{set:function(t){return this.value&&(this._switchTitle.text=t),t},value:"On"},value:{set:function(t){return this._switchIndicator.backgroundColor=t?"#0f0":"#aaa",t=!!t,this._switchTitle.text=t?this.titleOn:this.titleOff,t},post:function(){this.fireEvent("change",{value:this.value})}},verticalAlign:{set:function(t){this._switchTitle.verticalAlign=t},value:r.TEXT_VERTICAL_ALIGNMENT_CENTER}}})});