define(["Ti/_/Layouts/Base","Ti/_/declare","Ti/API","Ti/UI","Ti/_/lang"],function(e,t,i,d,a){var h=a.isDef,r=Math.round,o=Math.floor,n=Math.ceil;return t("Ti._.Layouts.Horizontal",e,{_doLayout:function(e,t,a,h,_){var u,s,x,g,l,f,m,p,N,L,c,W,y,b,w,H,I,T,R,S,F={width:0,height:0},E=e._children,C=0,v="px",z=0,A=0,O=[[]],Z=[],k=[],B=0,M=E.length,V=this._measureNode;for(C=0;M>C;C++)u=e._children[C],u._alive&&u.domNode?(u._measuredRunningWidth=A,u._markedForLayout&&((u._preLayout&&u._preLayout(t,a,h,_)||u._needsMeasuring)&&V(u,u,u._layoutCoefficients,this),x=u._layoutCoefficients,g=x.width,l=x.height,f=x.sandboxWidth,N=x.left,c=g.x1*t+g.x2*(t-A)+g.x3,W=0===l.x2?l.x1*a+l.x3:0/0,isNaN(c)||isNaN(l.x1)?(L=u._getContentSize?u._getContentSize(c,W):u._layout._doLayout(u,isNaN(c)?t:c-u._borderLeftWidth-u._borderRightWidth,isNaN(W)?a:W-u._borderTopWidth-u._borderBottomWidth,isNaN(c),isNaN(W)),isNaN(c)&&(c=L.width+u._borderLeftWidth+u._borderRightWidth),isNaN(l.x1)&&(W=L.height+u._borderTopWidth+u._borderBottomWidth),u._childrenLaidOut=!0,0===l.x2||isNaN(l.x2)||(i.warn("Child of width SIZE and height FILL detected in a horizontal layout. Performance degradation may occur."),u._childrenLaidOut=!1)):u._childrenLaidOut=!1,u._measuredWidth=c,u._measuredHeight=W,b=u._measuredSandboxWidth=f.x1*t+f.x2+c,w=N.x1*t+N.x2+A,!h&&o(b+A)>n(t)&&(O.push([]),w-=A,A=0),u._measuredLeft=w,O[O.length-1].push(u),A+=b),A>F.width&&(F.width=A)):this.handleInvalidState(u,e);for(M=O.length,C=0;M>C;C++){for(I=O[C],T=0,R=I.length,s=0;R>s;s++)u=I[s],u._markedForLayout&&(x=u._layoutCoefficients,p=x.top,l=x.height,m=x.sandboxHeight,W=u._measuredHeight,isNaN(W)&&(u._measuredHeight=W=l.x1*a+l.x2*(a-z)+l.x3),u._childrenLaidOut||(c=u._measuredWidth,u._childrenLaidOut=!0,u._layout._doLayout(u,isNaN(c)?t:c-u._borderLeftWidth-u._borderRightWidth,isNaN(W)?a:W-u._borderTopWidth-u._borderBottomWidth,isNaN(c),isNaN(W))),0!==p.x2?(k.push(u),H=z):u._measuredTop=H=p.x1*a+p.x3*W+p.x4+z,u._measuredSandboxHeight=y=m.x1*a+m.x2+W+H-z,y>T&&(T=y));Z.push(T),z+=T}for(z=0,M=O.length,C=0;M>C;C++){for(I=O[C],T=Z[C],R=I.length,s=0;R>s;s++)u=I[s],u._measuredRunningHeight=z,u._measuredRowHeight=T,~k.indexOf(u)&&u._markedForLayout&&(W=u._measuredHeight,p=u._layoutCoefficients.top,u._measuredTop=p.x1*a+p.x2*T+p.x3*W+p.x4+z);z+=T}if(F.height=z,!_)switch(this._defaultVerticalAlignment){case"end":B=a-z;case"center":B/=2}for(M=E.length,C=0;M>C;C++)u=E[C],u._markedForLayout&&(d._elementLayoutCount++,u=E[C],S=u.domNode.style,S.zIndex=u.zIndex,S.left=r(u._measuredLeft)+v,S.top=r(u._measuredTop)+v,S.width=r(u._measuredWidth-u._borderLeftWidth-u._borderRightWidth)+v,S.height=r(u._measuredHeight-u._borderTopWidth-u._borderBottomWidth)+v,u._markedForLayout=!1,u.fireEvent("postlayout"));return this._computedSize=F},_getWidth:function(e,t){return!h(t)&&(t=e._defaultWidth),t===d.INHERIT?e._parent._parent?e._parent._parent._layout._getWidth(e._parent,e._parent.width)===d.SIZE?d.SIZE:d.FILL:d.FILL:t},_getHeight:function(e,t){return!h(t)&&(t=e._defaultHeight),t===d.INHERIT?e._parent._parent?e._parent._parent._layout._getHeight(e._parent,e._height)===d.SIZE?d.SIZE:d.FILL:d.FILL:t},_isDependentOnParent:function(e){var t=e._layoutCoefficients;return!isNaN(t.width.x1)&&0!==t.width.x1||!isNaN(t.width.x2)&&0!==t.width.x2||!isNaN(t.height.x1)&&0!==t.height.x1||!isNaN(t.height.x2)&&0!==t.height.x2||0!==t.sandboxWidth.x1||0!==t.sandboxHeight.x1||0!==t.left.x1||0!==t.top.x1},_doAnimationLayout:function(e,t){var i=e._parent._measuredWidth,d=e._parent._measuredHeight,a=e._measuredHeight,h=e._measuredRunningWidth,r=e._measuredRunningHeight,o=e._measuredRowHeight;return{width:t.width.x1*i+t.width.x2*(i-h)+t.width.x3,height:t.height.x1*d+t.height.x2*(d-r)+t.height.x3,left:t.left.x1*i+t.left.x2+h,top:t.top.x1*d+t.top.x2*o+t.top.x3*a+t.top.x4+r}},_measureNode:function(e,t,i,a){e._needsMeasuring=!1;var h,r,o,n,_=a.getValueType,u=a.computeValue,s=a._getWidth(e,t.width),x=_(s),g=u(s,x),l=a._getHeight(e,t.height),f=_(l),m=u(l,f),p=t.left,N=_(p),L=u(p,N),c=t.right,W=_(c),y=u(c,W),b=t.top,w=_(b),H=u(b,w),I=t.bottom,T=_(I),R=u(I,T),S=i.width,F=i.height,E=i.sandboxWidth,C=i.sandboxHeight,v=i.left,z=i.top;if(h=r=o=0,x===d.SIZE?h=r=o=0/0:x===d.FILL?(r=1,"%"===N&&(h=-L),"#"===N&&(o=-L),"%"===W&&(h=-y),"#"===W&&(o=-y)):"%"===x?h=g:"#"===x&&(o=g),S.x1=h,S.x2=r,S.x3=o,h=r=0,"%"===N&&(h=L),"#"===N&&(r=L),"%"===W&&(h+=y),"#"===W&&(r+=y),E.x1=h,E.x2=r,h=r=o=0,f===d.SIZE?h=r=o=0/0:f===d.FILL?(r=1,"%"===w&&(h=-H),"#"===w&&(o=-H)):"%"===f?h=m:"#"===f&&(o=m),F.x1=h,F.x2=r,F.x3=o,C.x1="%"===T?R:0,C.x2="#"===T?R:0,v.x1="%"===N?L:0,v.x2="#"===N?L:0,h=r=o=n=0,"%"===w)h=H;else if("#"===w)n=H;else if("%"===T)h=1-R,o=-1;else if("#"===T)h=1,o=-1,n=-R;else switch(a._defaultRowAlignment){case"center":r=.5,o=-.5;break;case"end":r=1,o=-1}z.x1=h,z.x2=r,z.x3=o,z.x4=n},_defaultHorizontalAlignment:"start",_defaultVerticalAlignment:"start",_defaultRowAlignment:"center"})});