// All material copyright ESRI, All Rights Reserved, unless otherwise specified.
// See http://js.arcgis.com/3.23/esri/copyright.txt for details.
//>>built
define("esri/dijit/geoenrichment/ReportPlayer/core/annotations/image/_ImageContainerMixin","dojo/_base/declare dojo/Deferred dojo/sniff dojox/gfx dojox/gfx/matrix dojo/dom-class dojo/dom-construct dojo/dom-geometry dojo/dom-style dojo/when esri/dijit/geoenrichment/_Invoke esri/dijit/geoenrichment/utils/ImageInfoUtil ../annotationUtils/AnnotationsUtil ../annotationUtils/CircularMaskUtil ../annotationUtils/ScaleToCoverUtil ../../supportClasses/images/ImageDataHolder esri/dijit/geoenrichment/utils/DomUtil esri/dijit/geoenrichment/utils/WaitingUtil dojo/i18n!../../../../../../nls/jsapi ../../../_devConfig".split(" "),
function(r,t,u,B,C,e,k,D,c,l,v,w,p,x,y,q,d,m,n,z){n=n.geoenrichment.dijit.ReportPlayer.ReportPlayer;return r(v,{viewModel:null,themeContext:null,theme:null,imageJson:null,relativeParent:null,imageTriggerJson:null,alignParams:null,showError:!0,parentWidget:null,_createMapFunc:null,_circularMask:!1,_scaleToCover:!1,_fitParent:!0,_angle:0,_opacity:1,_isLogoPlaceholder:!1,_logoPlaceholderType:null,_dynamicBehavior:null,_isMapImage:!1,_webMapId:null,_defaultBasemapId:null,_thumbnailUrl:null,_calculatorFieldName:null,
_useDefaultImageSizeFlag:!1,_fileName:null,_imageData:null,postCreate:function(){this._configurePropertiesFromImageJson();this._isMapImage&&(this._createMapFunc=this.viewModel.dynamicReportInfo&&this.viewModel.dynamicReportInfo.createMapFunc);this.content=this._isMapImage&&this._createMapFunc?k.create("div",{"class":"templateLiveMap"}):k.create(this._isMapImage?"div":"img",{"class":"floatingElement templateImage"});this.inherited(arguments);this._configureDomNodeStylesFromParameters();this._addAdditionalUI();
this._isMapImage?this.resize():this._isLogoPlaceholder&&(this.content._wToHRatio=1,this.resize());this._applyOpacity();this._applyRotation();this.alignParams&&p.alignAnnotationContainer(this,this.alignParams);(this.imageJson.fileName||this.imageJson.isLogoPlaceholder||this._imageData)&&this._initWithImageData()},_configurePropertiesFromImageJson:function(){this.fieldStyle=this.fieldStyle||{};this.fieldStyle.width=this.imageJson.style.width||150;this.fieldStyle.height=this.imageJson.style.height||
0;this._fileName=this.imageJson.fileName;this._opacity=Math.max(0,Math.min(1,void 0!==this.imageJson.style.opacity?this.imageJson.style.opacity:1));this._angle=this.imageJson.style.angle||0;this._dynamicBehavior=this.imageJson.dynamicBehavior;this._fitParent=!1!==this.imageJson.fitParent;this._circularMask=!!this.imageJson.circularMask;this._scaleToCover=!!this.imageJson.scaleToCover;this.imageJson.style.width||(this._useDefaultImageSizeFlag=!0);this.alignParams||!this.imageJson.style.horizontalAlign&&
!this.imageJson.style.verticalAlign||(this.alignParams={horizontalAlign:this.imageJson.style.horizontalAlign,verticalAlign:this.imageJson.style.verticalAlign});this._isMapImage=!!this.imageJson.isMapImage;this._calculatorFieldName=this.imageJson.calculatorFieldName;this._webMapId=this.imageJson.webMapId;this._defaultBasemapId=this.imageJson.defaultBasemapId;this._thumbnailUrl=this.imageJson.thumbnailUrl;this._isLogoPlaceholder=!!this.imageJson.isLogoPlaceholder;this._logoPlaceholderType=this.imageJson.logoPlaceholderType},
_configureDomNodeStylesFromParameters:function(){this._isLogoPlaceholder&&e.add(this.domNode,"templateImage_logoPlaceholder");"short"===this._logoPlaceholderType&&e.add(this.domNode,"templateImage_logoPlaceholderShort");this._isMapImage&&!this._createMapFunc&&this._setMapImageBackground();e.add(this.domNode,"floatingElementContainer");c.set(this.domNode,"position","absolute");c.set(this.domNode,"top",(this.imageJson.style.top||0)+"px");c.set(this.domNode,"left",(this.imageJson.style.left||0)+"px")},
_addAdditionalUI:function(){},_applyOpacity:function(){0<=this._opacity&&1>this._opacity?(this._clickMaskDiv&&(this._clickMaskDiv.style.opacity=this._opacity),this._scaleToCoverDiv&&(this._scaleToCoverDiv.style.opacity=this._opacity),this.content.style.opacity=this._opacity):(this.content.style.opacity="",this._clickMaskDiv&&(this._clickMaskDiv.style.opacity=""),this._scaleToCoverDiv&&(this._scaleToCoverDiv.style.opacity=""))},_applyRotation:function(){this._angle=0<this._angle||0>this._angle?this._angle:
0;var a=u("webkit")?"webkitTransform":"transform";this.content.style[a]="rotate("+this._angle+"deg)";this._updateCircularMaskAndScaleToCover()},_initPromise:null,_initWithImageData:function(){var a=this;return this._initPromise=l(this._reloadImageData(),function(){a.onInitialized();a._updateCircularMaskAndScaleToCover()})},isInitialized:function(){return this._initPromise},_reloadImageData:function(){function a(a,c){return b._setImageData({data:a,fileName:c,recalcImageContainerDimentions:b._useDefaultImageSizeFlag,
preserveHeight:!1,dispatchEvents:!1})}var b=this;if(!this._isMapImage)if(this._isLogoPlaceholder){if(this.viewModel.getDynamicImageFunc)return m.showProgress(this.domNode),this.onContentLoadingStart(),l(this.viewModel.getDynamicImageFunc(this._dynamicBehavior,this.theme||this.themeContext),function(b){return b&&a(b)}).always(function(){m.removeProgress(b.domNode);b.onContentLoadingEnd()})}else return a(q.getImageData(b._fileName)||b.imageJson.data,b._fileName)},_setImageData:function(a){var b=this,
g=a.data,h=a.fileName,A=a.recalcImageContainerDimentions,f=a.preserveHeight,e=a.dispatchEvents,d=new t;this._showErrorMessage(!1);c.set(this.domNode,"opacity","0.01");w.getImageInfo(g,h).then(function(a){e&&b.onImageDataPreChanged();var g=a.width/a.height;b.content._wToHRatio=g;var h;h=b._fitParent?b._useDefaultImageSizeFlag?150:Math.min(b.getWidth(),b.getHeight()*g):b.imageJson.style.width||150;c.set(b.content,"width",h+"px");c.set(b.content,"height",h/g+"px");b.content.onload=function(){A&&b._recalcImageContainerDimentions(f);
e&&b.onImageDataChanged();d.resolve()};b.content.onerror=function(a){d.reject(a)};b._fileName=a.filename;b._imageData=a.dataUrl;b._applyBackgroundUrl(a.dataUrl);q.putImageData(a.filename,a.dataUrl);b._syncLogoStateAfterLoadingImage()},d.reject);d.promise.then(function(){b.domNode&&c.set(b.domNode,"opacity","")},function(){b._showErrorMessage(!0)});return d.promise},_syncLogoStateAfterLoadingImage:function(){this.domNode&&e[this._fileName||this._imageData?"remove":"add"](this.domNode,"templateImage_logoPlaceholder");
this._isLogoPlaceholder=!this._fileName},_showErrorMessage:function(a){this.showError&&(z.emulateErrors.contentErrors&&(a=!0),a&&!this.errorMessageDiv&&(this.errorMessageDiv=k.create("div",{"class":"esriGEReportPlayerErrorMessage",innerHTML:this._isMapImage?n.mapLoadError:n.imageLoadError},this.domNode),c.set(this.errorMessageDiv,"paddingTop",c.get(this.domNode,"height")/2-20+"px")),d[a?"show":"hide"](this.errorMessageDiv),d[a?"hide":"show"](this.contentBlock))},_recalcImageContainerDimentions:function(a){if(this.domNode){var b=
d.position(this.content),c=a&&this.getHeight();this.setWidth(b.w);this.setHeight(b.h);a&&this.setHeight(c)}},_setMapImageBackground:function(){var a=this;e.add(this.content,"templateMapImage");this._thumbnailUrl?this._applyBackgroundUrl(this._thumbnailUrl):this._webMapId&&(a._applyBackgroundUrl(null),l(this._updateThumbnailUrl(),function(){a._thumbnailUrl&&a._applyBackgroundUrl(a._thumbnailUrl);a.__updateThumbnailClass()}));this.__updateThumbnailClass()},__updateThumbnailClass:function(){e[this._thumbnailUrl?
"add":"remove"](this.content,"templateImageWithThumbnail")},_updateThumbnailUrl:function(){},_applyBackgroundUrl:function(a){this._isMapImage?this.content.style.backgroundImage=a?"url("+a+")":"":this.content.src=a||"";this.__updateThumbnailClass();this._updateCircularMaskAndScaleToCover()},_getBackgroundUrl:function(){return this._isMapImage?c.get(this.content,"backgroundImage").replace("url","").replace("(","").replace(")","").replace(/\"/g,""):this.content.src},isMapImage:function(){return this._isMapImage},
_lastAlignParams:null,resize:function(a,b){a&&(this.setWidth(a.w),this.setHeight(a.h),this._useDefaultImageSizeFlag=!1);if(this._isMapImage){var g=c.get(this.content,"width"),d=this.getWidth(),e=c.get(this.content,"height"),f=this.getHeight();if(g!==d||e!==f)c.set(this.content,"width",d+"px"),c.set(this.content,"height",f+"px"),this._createMapFunc&&this._placeMap()}else this._lastAlignParams=b,this._resizeContentImage();this._updateCircularMaskAndScaleToCover()},_getContentImageWToHRatio:function(){return this.content._wToHRatio||
(this.imageJson.style._imageW||this.imageJson.style.width)/(this.imageJson.style._imageH||this.imageJson.style.height)},_resizeContentImage:function(){var a=this._getContentImageWToHRatio(),b;b=this._fitParent?Math.min(this.getWidth(),this.getHeight()*a):Math.min(this.imageJson.style.width,this.imageJson.style.height*a,this.getWidth(),this.getHeight()*a);c.set(this.content,"width",b+"px");c.set(this.content,"height",b/a+"px");p.alignAnnotationContainer(this,this._lastAlignParams);this._updateCircularMaskAndScaleToCover()},
scaleProportionallyWithinParent:function(a){var b=this.getImageBox(!1);this.resize({w:b.w*a.xScale,h:b.h*a.yScale});c.set(this.domNode,{left:b.l*a.xScale+"px",top:b.t*a.yScale+"px"})},_isPlacingMapFlag:!1,_currentMap:null,_placeMap:function(){function a(){d&&d.remove();e&&clearTimeout(e);m.removeProgress(c.content);c._finalizePlaceMap()}function b(){a();c._showErrorMessage(!0);c.onMapLoadError()}var c=this;this._showErrorMessage(!1);this._isPlacingMapFlag&&this._finalizePlaceMap();this._currentMap&&
this._currentMap.destroy();this._currentMap=null;k.empty(this.content);m.showProgress(this.content);this.onContentLoadingStart();this._isPlacingMapFlag=!0;var d,e;return l(this._createMapFunc(this.content,{webMapId:this._webMapId,defaultBasemapId:this._defaultBasemapId,calculatorFieldName:this._calculatorFieldName}),function(f){(c._currentMap=f)?(c._mapExtentPending&&c.setVisualState({mapExtent:c._mapExtentPending}),c.own(f),f.loaded?a():(d=on.once(f,"load",a),e=setTimeout(function(){b()},6E4))):
b()},b)},_finalizePlaceMap:function(){this._isPlacingMapFlag&&(this._isPlacingMapFlag=!1,this.onContentLoadingEnd())},_mapExtentPending:null,getVisualState:function(){return{mapExtent:this._currentMap&&this._currentMap.extent}},setVisualState:function(a){this._mapExtentPending=null;a&&a.mapExtent&&(this._currentMap&&this._currentMap.setExtent?this._currentMap.setExtent(a.mapExtent):this._mapExtentPending=a.mapExtent)},_clickMaskDiv:null,_scaleToCoverDiv:null,_updateCircularMaskAndScaleToCover:function(){this._createMapFunc||
(this._clickMaskDiv=x.setCircularMask(this._circularMask&&this._imageData,this.content,this._getBackgroundUrl(),this._angle),this._scaleToCoverDiv=y.setScaleToCover(this._scaleToCover&&this._imageData,this.content,this._getBackgroundUrl(),this._angle),d[this._clickMaskDiv||this._scaleToCoverDiv?"hide":"show"](this.content),this._applyOpacity())},getFitParent:function(){return this._fitParent},setFitParent:function(a){this._fitParent=a;this._resizeContentImage()},getImageBox:function(a){a=!1!==a&&
d.position(this.content);return{w:a?a.w:this.getWidth(),h:a?a.h:this.getHeight(),l:this.domNode?c.get(this.domNode,"left"):0,t:this.domNode?c.get(this.domNode,"top"):0}},setImageWidth:function(a){this._fitParent||(this.imageJson.style.width=a,this.imageJson.style.height=a/this._getContentImageWToHRatio(),this._resizeContentImage())},setImageHeight:function(a){this._fitParent||(this.imageJson.style.height=a,this.imageJson.style.width=a*this._getContentImageWToHRatio(),this._resizeContentImage())},
onInitialized:function(){},onImageDataPreChanged:function(){},onImageDataChanged:function(){},onContentLoadingStart:function(){},onContentLoadingEnd:function(){},onMapLoadError:function(){},toJson:function(){var a=d.position(this.content),b={id:"img",fileName:this._isLogoPlaceholder?null:this._fileName,isMapImage:this._isLogoPlaceholder?!1:this._isMapImage,webMapId:this._webMapId,defaultBasemapId:this._defaultBasemapId,calculatorFieldName:this._calculatorFieldName,thumbnailUrl:this._thumbnailUrl,
circularMask:this._circularMask,scaleToCover:this._scaleToCover,isLogoPlaceholder:this._isLogoPlaceholder,logoPlaceholderType:this._isLogoPlaceholder?this._logoPlaceholderType:null,dynamicBehavior:this._isLogoPlaceholder?this._dynamicBehavior:null,fitParent:this._fitParent,style:{top:this.domNode?c.get(this.domNode,"top"):0,left:this.domNode?c.get(this.domNode,"left"):0,angle:this._angle,opacity:this._opacity,horizontalAlign:this._lastAlignParams&&this._lastAlignParams.horizontalAlign,verticalAlign:this._lastAlignParams&&
this._lastAlignParams.verticalAlign,_imageW:a&&a.w,_imageH:a&&a.h}};this._fitParent?(b.style.width=this.getWidth(),b.style.height=this.getHeight()):(b.style.width=a.w,b.style.height=a.h);return b},destroy:function(){this._finalizePlaceMap();this.inherited(arguments)}})});