var Mosaic=function(){"use strict";var e=function(e){function t(t){e.call(this),this.app=t,this.player=this.app.core.get("Player"),this.__is_enter=!1}e&&(t.__proto__=e),t.prototype=Object.create(e&&e.prototype),t.prototype.constructor=t;var i={mosaics:{configurable:!0}};return i.mosaics.get=function(){return this.app.RepairManager.mosaics},t.prototype.enter=function(){var e=this;this.__is_enter||this.player.flyToNewMode({mode:"panorama",pano:this.player.currentPano,callback:function(){e.player.paintEditor.start(),e.player.OverlayManager.hide("all"),e.player.viewLinkManager.hideAllViews(),e.__is_enter=!0}})},t.prototype.exit=function(){this.__is_enter&&(this.__is_enter=!1,this.player.paintEditor.cancel(),this.player.OverlayManager.show("all"),this.player.viewLinkManager.showAllViews())},t.prototype.setBrush=function(e){-1!=["pen","eraser"].indexOf(e)&&(e="eraser"==e?0:1,this.player.paintEditor.changeBrush(e))},t.prototype.setBrushSize=function(e){this.player.paintEditor.setBrushSize(e)},t.prototype.confirm=function(e){void 0===e&&(e=!0);var t=this.player.paintEditor.save();return t.func&&t.func(),e&&this.exit(),{data:t.data,panoId:t.panoId}},t.prototype.remove=function(e){if(this.mosaics.length){this.player.paintEditor.paintData=this.player.paintEditor.paintData.filter((function(t){return t.panoId!=e})),this.player.currentPano.id==e&&this.player.paintEditor.updatePanoPaint(e,e);for(var t=this.mosaics.length-1;t>=0;t--)if(e==this.mosaics[t].panoId){this.mosaics.splice(t,1);break}}},t.prototype.save=function(){var e=this,t=this.app.config.num,i=this.player.paintEditor.save(),a=i.data,n=i.func,r=i.panoId,o=KanKan.Deferred(),s=t+"-"+r+".png";return this.app.remote_editor.upload_files({base64:a,bizType:"mosaic-pic",num:t,type:0,fileName:s}).then((function(i){if(i.success){var a={num:t,data:JSON.stringify([{fileName:s,panoId:r}])};e.app.remote_editor.mosaics_add(a).then((function(t){t.success?(n(),e.exit(),o.resolve(t)):o.reject(t)})).catch((function(e){return o.reject(e)}))}else o.reject(i)})).catch((function(e){return o.reject(e)})),o},t.prototype.delete=function(e){var t=this;return e&&e.length&&this.mosaics.length?new Promise((function(i,a){t.app.remote_editor.mosaics_delete({num:t.app.config.num,panoIdList:e}).then((function(n){n.success?(e.forEach((function(e){t.remove(e)})),i(n)):a(n)})).catch((function(e){return a(e)}))})):Promise.resolve({success:!0})},Object.defineProperties(t.prototype,i),t}(KanKan.MITT.Emiter);return function(t,i){var a=KanKan.Deferred();return t.Scene.on("loaded",(function(){var n=new e(t,i);n.$name="Mosaic",n.$load=function(){t.RepairManager.install("mosaic",n)},a.resolve(n)})),a}}();
