define(["ember","app","text!../templates/growth/book.hbs"],function(a,b,c){var d=a.Object.extend({index:0,zIndex:0,isRender:!1,style:function(){return"z-index:%@;".fmt(this.get("zIndex"))}.property("zIndex")});return b.GrowthBookView=a.View.extend({template:a.Handlebars.compile(c),pages:[],autoPlay:!1,autoPlayTitle:function(){return this.get("autoPlay")?"停止":"自动播放"}.property("autoPlay"),pageIndex:0,pageNumber:1,maxlength:3,balance:1,isFlipping:!1,renderPages:function(){var a=this.get("maxlength"),b=this.get("pages").map(function(b,c){return d.create({angle:"x"+c%a,index:c,pageNumber:c+1,entity:b,zIndex:0})}),c=b.get("length");return b.forEach(function(a,b){a.set("zIndex",c-b-1)}),b}.property("pages"),initialize:function(){this.changePageState()}.on("init"),didPageChanged:function(){this.changePageState()}.observes("pageIndex","renderPages"),changePageState:function(){var a=this.get("maxlength"),b=this.get("balance");if(console.log(this.get("renderPages")),a>=this.get("renderPages.length"))return void this.get("renderPages").setEach("isRender",!0);var c=this.get("renderPages"),d=this.get("renderPages.length")-1,e=[];0<=this.get("pageIndex")-b&&d>=this.get("pageIndex")+b?e=e.concat(c.slice(this.get("pageIndex")-b,this.get("pageIndex")+b+1)):0>this.get("pageIndex")-b?e=e.concat(c.slice(0,a)).concat(c.slice(d+1+(this.get("pageIndex")-b),d+1)):d<this.get("pageIndex")+b&&(e=e.concat(c.slice(d-(a-1),d+1)).concat(c.slice(0,this.get("pageIndex")+b-d))),console.log(e),this.get("renderPages").forEach(function(a){a.set("isRender",e.contains(a))})},flipPage:function(a){var b=this;if(!b.get("isFlipping")){b.set("isFlipping",!0);var c=b.get("pageIndex");c+=a?1:-1,-1==c?c=b.get("renderPages.length")-1:b.get("renderPages.length")==c&&(c=0);var d=a?b.get("pageIndex"):c,e=a?-1:b.get("renderPages.length");b.set("pageNumber",c+1),b.$('.book-page[pageindex="'+d+'"]').velocity({top:(a?"-":"")+b.$().height()},"slow",function(){b.get("isDestroyed")||b.get("isDestroying")||b.$(this).css("z-index",e).velocity({top:0},"slow",function(){if(!b.get("isDestroyed")&&!b.get("isDestroying")){b.get("renderPages").findBy("index",d).set("zIndex",e);var f=b.get("renderPages").sortBy("zIndex");a?f.reverse().forEach(function(a){a.incrementProperty("zIndex")}):f.forEach(function(a){a.decrementProperty("zIndex")}),b.set("pageIndex",c),b.set("isFlipping",!1)}})})}},domReady:function(){var a=this;a.$(".book-button-prev").click(function(){a.get("autoPlay")||a.flipPage(!1)}),a.$(".book-button-next").click(function(){a.get("autoPlay")||a.flipPage(!0)}),a.$(".book-button-autoplay").click(function(){a.set("autoPlay",!a.get("autoPlay"))})}.on("didInsertElement"),autoPalyChanged:function(){var a=this;a.get("autoPlay")?(a.flipPage(!0),a.set("intervalFunc",setInterval(function(){0==a.get("pageIndex")?a.set("autoPlay",!1):a.flipPage(!0)},2e3))):this.get("intervalFunc")&&(clearInterval(a.get("intervalFunc")),a.set("intervalFunc",null))}.observes("autoPlay"),domDestroy:function(){this.get("intervalFunc")&&clearInterval(this.get("intervalFunc"))}.on("willDestroyElement")})});