var __hasProp=Object.prototype.hasOwnProperty,__extends=function(a,b){function d(){this.constructor=a}for(var c in b)__hasProp.call(b,c)&&(a[c]=b[c]);return d.prototype=b.prototype,a.prototype=new d,a.__super__=b.prototype,a},__bind=function(a,b){return function(){return a.apply(b,arguments)}};define(["common/models/state","cilantro/types/domain/views"],function(a,b){var c,d,e,f;return c=function(){function b(){b.__super__.constructor.apply(this,arguments)}return __extends(b,a.Model),b}(),d=function(){function a(){a.__super__.constructor.apply(this,arguments)}return __extends(a,Backbone.Collection),a.prototype.model=c,a.prototype.url=App.urls.domains,a.prototype.initialize=function(){return this.bind("active",this.activate),this.bind("inactive",this.inactivate),App.hub.subscribe("domain/request",__bind(function(a){var b,c;return b=this.get(a),b?b.activate():(c=this.subdomains.get(a),b=this.get(c.get("parent").id),b.activate(),c.activate())},this))},a.prototype.parse=function(a,c){var d,e,g,h,i;e=_.groupBy(a,function(a){var b;return((b=a["parent"])!=null?b.id:void 0)||null}),this.subdomains=new f,new b.SubdomainCollectionView({collection:this.subdomains}),d=e["null"],delete e["null"],i=_.flatten(_.values(e));for(h in e)g=parseInt(h),i.push({id:g,name:"All",parent:{id:g}});return this.subdomains.reset(i),d},a.prototype.activate=function(a){return App.hub.publish("domain/active",a.id),this.chain().without(a).map(function(a){return a.inactivate()})},a.prototype.inactivate=function(a){return App.hub.publish("domain/inactive",a.id)},a}(),e=function(){function a(){a.__super__.constructor.apply(this,arguments)}return __extends(a,c),a}(),f=function(){function a(){this.toggleEnableByDomain=__bind(this.toggleEnableByDomain,this),a.__super__.constructor.apply(this,arguments)}return __extends(a,d),a.prototype.model=e,a.prototype.initialize=function(){return App.hub.subscribe("domain/active",this.toggleEnableByDomain),this.bind("reset",this.groupByDomain),this.bind("active",this.activate),this.bind("inactive",this.inactivate)},a.prototype.comparator=function(a){return a.id},a.prototype.groupByDomain=function(){return this._byDomain=this.groupBy(function(a){return a.get("parent").id})},a.prototype.toggleEnableByDomain=function(a){var b;b=!1,this.map(__bind(function(c){if(c.get("parent").id!==a)return c.disable();c.enable({reactivate:!0});if(c.isActive())return b=!0},this));if(!b&&this._byDomain[a])return this.get(a).activate()},a.prototype.activate=function(a){return App.hub.publish("subdomain/active",a.id),_(this._byDomain[a.get("parent").id]).without(a).map(function(a){return a.inactivate()})},a.prototype.inactivate=function(a){return App.hub.publish("subdomain/inactive",a.id)},a}(),{Model:c,Collection:d}})