define("matrixGallery",["lodash","skins","core","santaProps","utils","galleriesCommon","displayer"],function(a,b,c,d,e,f,g){"use strict";var h=c.compMixins;var i=f.utils.matrixCalculations;var j=f.utils.matrixScalingCalculations;var k=f.utils.galleriesHelperFunctions;var l=e.galleriesCommonLayout;var m=70;var n=["topPadding","imgHeightDiff"];function o(a,b,c){return c<=a*b?"fullView":"hiddenChildren"}function p(a){return Math.max(m,a)}return{displayName:"MatrixGallery",propTypes:a.assign({renderFlags:d.Types.renderFlags.isRequired,compProp:d.Types.Component.compProp.isRequired,compData:d.Types.Component.compData.isRequired,style:d.Types.Component.style.isRequired,skin:d.Types.Component.skin.isRequired,compTheme:d.Types.Component.theme.isRequired,currentUrlPageId:d.Types.Component.currentUrlPageId.isRequired,isMobileView:d.Types.isMobileView,isMobileDevice:d.Types.Device.isMobileDevice,isTabletDevice:d.Types.Device.isTabletDevice,compActions:d.Types.Component.compActions.isRequired},d.santaTypesUtils.getSantaTypesByDefinition(g)),statics:{useSantaTypes:true},mixins:[h.skinBasedComp,h.skinInfo],getInitialState:function(){this.shouldResetGalleryToOriginalState=this.props.renderFlags.shouldResetGalleryToOriginalState;var a=i.getAvailableRowsNumber(this.props.compProp.maxRows,this.props.compProp.numCols,this.props.compData.items.length);var c=this.props.isMobileView?"mobileView":"desktopView";this.showMoreClicked=false;this.galleryHeight=p(this.props.style.height);this.itemHeight=i.getItemHeight(this.props.compProp.margin,this.galleryHeight,a,k.getSkinHeightDiff(this.props.skin));this.currentStyle=this.props.compTheme;var d=this.getParams(n,this.getDisplayerSkin());this.currentHeightDiff=k.getDisplayerHeightDiff(b.skins[this.getDisplayerSkin()],d,c);return{numberOfRows:a,$mobile:this.props.isMobileDevice||this.props.isTabletDevice?"mobile":"notMobile",$displayDevice:c,$state:o(a,this.props.compProp.numCols,this.props.compData.items.length)}},createDisplayer:function(a,c,d,e){var f=this.getDisplayerSkin();var g=b.skins[this.props.skin];var h=g.exports&&g.exports.bottomGap||0;var l=this.getParams(n,f);var m=k.getDisplayerHeightDiff(b.skins[f],l,this.state.$displayDevice);var o=k.getDisplayerWidthDiff(b.skins[f],this.state.$displayDevice);var p=j.getSizeAfterScaling({itemHeight:e,itemWidth:d,displayerData:a,imageMode:this.props.compProp.imageMode,widthDiff:o,heightDiff:m,bottomGap:h});var q=i.getItemPosition(c,d,e,this.props.compProp.margin,this.props.compProp.numCols);return this.createChildComponent(a,"wysiwyg.viewer.components.Displayer","imageItem",{key:a.id,ref:this.props.id+a.id+c,id:this.props.id+a.id+c,currentUrlPageId:this.props.currentUrlPageId,galleryId:this.props.id,galleryDataId:this.props.compData.id,imageWrapperSize:p.imageWrapperSize,imageIndex:c,heightDiff:m,widthDiff:o,bottomGap:h,compActions:this.props.compActions,style:{width:p.displayerSize.width,height:p.displayerSize.height,position:"absolute",left:q.left,top:q.top}})},createDisplayers:function(){var b=a.take(this.props.compData.items,this.props.compProp.numCols*this.state.numberOfRows);var c=i.getItemWidth(this.props.compProp.margin,this.props.compProp.numCols,this.props.style.width,k.getSkinWidthDiff(this.props.skin));var d=this.itemHeight||i.getItemHeight(this.props.compProp.margin,this.galleryHeight,this.state.numberOfRows,k.getSkinHeightDiff(this.props.skin));return a.map(b,function(a,b){return this.createDisplayer(a,b,c,d)},this)},componentWillReceiveProps:function(c){var d=i.getAvailableRowsNumber(c.compProp.maxRows,c.compProp.numCols,c.compData.items.length);var e={};if(this.props.compProp.maxRows!==c.compProp.maxRows||this.props.compProp.numCols!==c.compProp.numCols||this.props.compData.items.length!==c.compData.items.length){e.numberOfRows=d;this.galleryHeight=p(k.getGalleryHeight(this.state.numberOfRows,d,this.props.compProp.margin,this.props.skin,this.galleryHeight));e.$state=o(d,c.compProp.numCols,c.compData.items.length)}if(this.props.style.height!==c.style.height){this.galleryHeight=p(c.style.height)}if(!a.isEmpty(e)){this.setState(e)}if(this.shouldResetGalleryToOriginalState!==c.renderFlags.shouldResetGalleryToOriginalState){if(this.shouldResetGalleryToOriginalState&&this.resetGalleryState){this.resetGalleryState()}this.shouldResetGalleryToOriginalState=c.renderFlags.shouldResetGalleryToOriginalState}var f=c.compTheme;if(f.skin===this.currentStyle.skin&&this.shouldRecalculateHeightOnSkinParamChange(this.currentStyle.style.properties,f.style.properties)){var g=this.getDisplayerSkin();var h=this.getParams(n,g);var j=k.getDisplayerHeightDiff(b.skins[g],h,this.state.$displayDevice);var l=this.itemHeight||i.getItemHeight(this.props.compProp.margin,this.galleryHeight,this.state.numberOfRows,k.getSkinHeightDiff(this.props.skin));this.itemHeight=l-(this.currentHeightDiff-j);var m=k.getSkinHeightDiff(this.props.skin);this.galleryHeight=this.state.numberOfRows*this.itemHeight+(this.state.numberOfRows-1)*this.props.compProp.margin+m;this.currentHeightDiff=j;this.currentStyle=f}if(!a.isEmpty(e)){this.setState(e)}},getSkinProperties:function(){var a={showMore:{children:this.props.compProp.showMoreLabel,onClick:this.showMoreRows},itemsContainer:{children:this.createDisplayers(),style:{height:this.galleryHeight}},"":{"data-height-diff":k.getSkinHeightDiff(this.props.skin),"data-width-diff":k.getSkinWidthDiff(this.props.skin),"data-presented-row":this.state.numberOfRows,style:{height:this.galleryHeight}}};if(this.showMoreClicked||this.state.$state==="fullView"){l.updateSkinPropsForFlexibleHeightGallery(a,this.galleryHeight)}return a},showMoreRows:function(){var a=i.getAvailableRowsNumber(this.state.numberOfRows+this.props.compProp.incRows,this.props.compProp.numCols,this.props.compData.items.length);this.showMoreClicked=true;this.galleryHeight=p(k.getGalleryHeight(this.state.numberOfRows,a,this.props.compProp.margin,this.props.skin,this.galleryHeight));this.registerReLayout();this.setState({numberOfRows:a,$state:o(a,this.props.compProp.numCols,this.props.compData.items.length)})},getDisplayerSkin:function(){return this.getSkinExports().imageItem.skin},shouldRecalculateHeightOnSkinParamChange:function(b,c){var d=a.pick(b,n);var e=a.pick(c,n);return!a.isEqual(d,e)}}});