define(["ember","app","broad","fm","../../helpers/download_manage","../../helpers/fetch_state"],function(a,b,c,d,e,f){return b.VideosController=a.ObjectController.extend({model:{},needs:["videoPlayer"],histories:a.computed.alias("session.histories"),schoolyear:null,online:null,videos:[],filterCount:0,reloadModel:function(){if(1<=this.get("filterCount")&&this.get("schoolyear")){c.trigger("loading");var b=this,e="~/%@-%@".fmt(this.get("schoolyear.schoolyear"),this.get("schoolyear.semester"));["fileLocal","finalClassVideo","finalClassVideoLocal"].forEach(function(a){b.store.unloadAll(a)});var g=[this.store.find("fileLocal",{_path_:e})];return g.addObject(this.get("session.online")?this.store.find("finalClassVideo",{schoolyear:this.get("schoolyear.schoolyear"),semester:this.get("schoolyear.semester")}):this.store.find("finalClassVideoLocal",{_path_:e})),a.RSVP.Promise.all(g).then(function(e){var g=e[1].map(function(c){var d=e[0].findBy("id",c.get("FilePath"));return a.Object.create({entity:c,state:f.create({state:d?d.get("Status"):b.get("session.online")?"online":"loaded",error:d||b.get("session.online")?"":"error1"})})});if(!b.get("session.online")){g=g.filterBy("state.isFetched",!0);var h=b.get("schoolyear.schoolyear")+"-"+b.get("schoolyear.semester");g.forEach(function(a){a.set("entity.FilePath",d.achieveSync({folder:h,url:a.get("entity.FilePath")})),a.set("entity.ThumbPath","")})}c.trigger("loaded"),b.set("videos",g.sortBy("entity.Intime"))},function(a){console.log(a),c.trigger("loaded"),b.get("dialogManager").notice(a.message||a.toString())})}this.incrementProperty("filterCount")}.observes("online","schoolyear"),actions:{play:function(a){var b=this.get("controllers.videoPlayer"),c={width:830,height:476,filename:a.get("FileName"),url:a.get("FilePath")};this.get("dialogManager").custom("video/player",b,c),b.set("dialogid",Math.random())},download:function(a){c.trigger("loading"),e.downloadVideos(this.store,this.get("schoolyear.schoolyear"),this.get("schoolyear.semester"),[a.get("entity")]).then(function(){a.set("state.state","init")})["finally"](function(){c.trigger("loaded")})}}})});