define(["Ti/_/declare","Ti/_/lang","Ti/_/UI/Widget","Ti/_/style","Ti/UI/MobileWeb/TableViewSeparatorStyle","Ti/UI"],function(e,t,r,i,o,s){var a=require.is,h=i.set,n=/(click|singletap|longpress)/;return e("Ti.UI.TableViewSection",r,{constructor:function(){this._indexedContent=[];for(var e=0,t=3,r=["_header","_rows","_footer"];t>e;)this._add(this[r[e++]]=s.createView({height:s.SIZE,width:s.INHERIT,layout:s._LAYOUT_CONSTRAINING_VERTICAL}));this.layout=s._LAYOUT_CONSTRAINING_VERTICAL},_defaultWidth:s.INHERIT,_defaultHeight:s.SIZE,fireEvent:function(e){n.test(e)&&this._tableView&&(this._tableView._tableViewSectionClicked=this),r.prototype.fireEvent.apply(this,arguments)},_tableView:null,_createSeparator:function(){var e=this._tableView&&this._tableView.separatorStyle===o.SINGLE_LINE,t=s.createView({height:e?1:0,width:s.INHERIT,backgroundColor:e?this._tableView.separatorColor:"transparent"});return h(t.domNode,"minWidth","100%"),t},_createDecorationLabel:function(e){return s.createLabel({text:e,backgroundColor:"darkGrey",color:"white",width:s.INHERIT,height:s.SIZE,left:0,font:{fontSize:18}})},_refreshRows:function(){if(this._tableView){var e,t,r=this._rows._children,i=this._tableView,s=this.__values__.constants.rows=[];for(e=1;e<r.length;e+=2)t=r[e],t._defaultHeight=i.rowHeight,t._minHeight=i.minRowHeight,t._maxHeight=i.maxRowHeight,s.push(t);for(e=0;e<r.length;e+=2)t=r[e],i.separatorStyle===o.SINGLE_LINE?(t.height=1,t.backgroundColor=i.separatorColor):(t.height=0,t.backgroundColor="transparent")}},_insertHelper:function(e,r){t.isDef(e.declaredClass)&&"Ti.UI.TableViewRow"==e.declaredClass||(e=s.createTableViewRow(e)),this._rows._insertAt(e,2*r+1),this._rows._insertAt(this._createSeparator(),2*r+2),e._tableViewSection=this,this.rowCount++,this._refreshRows()},add:function(e,r){var i=this._rows._children,o=this.rowCount;if(t.isDef(r)||(r=o),!(0>r||r>o))if(0===i.length&&this._rows._add(this._createSeparator()),a(e,"Array"))for(var s in e)this._insertHelper(e[s],r++);else this._insertHelper(e,r)},_removeAt:function(e){0>e||e>=this.rowCount||(this._rows._children[2*e+1]._tableViewSection=null,this._rows.remove(this._rows._children[2*e+1]),this._rows.remove(this._rows._children[2*e+1]),1===this._rows._children.length&&this._rows.remove(this._rows._children[0]),this._refreshRows())},remove:function(e){var t=this._rows._children.indexOf(e);-1!==t&&this._removeAt(t)},constants:{rows:void 0},properties:{footerTitle:{set:function(e,t){return t!=e&&(this._footer._removeAllChildren(),this._footer._add(this._createDecorationLabel(e)),this._footer._add(this._createSeparator())),e}},footerView:{set:function(e,t){return t!=e&&(this._footer._removeAllChildren(),this._footer._add(e)),e}},headerTitle:{set:function(e,t){return t!=e&&(this._header._removeAllChildren(),this._header._add(this._createDecorationLabel(e)),this._header._add(this._createSeparator())),e}},headerView:{set:function(e,t){return t!=e&&(this._header._removeAllChildren(),this._header._add(e)),e}},rowCount:function(){return Math.floor(this._rows._children.length/2)}}})});