/**
 * Copyright 2016 Adobe Systems, Inc. http://www.adobe.com
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
!function(e,t){"use strict";function o(e,o){o=o||{};var r={mbox:o.mbox,params:o.params,timeout:o.timeout},n=e.defer();return r.success=function(e){e&&e.length>0?n.resolve({mbox:o.mbox,offer:e,selector:o.selector||o.element}):n.resolve({error:"Empty offer"})},r.error=function(e,t){n.resolve({error:t})},t.getOffer(r),n.promise}function r(e,o){return e(function(e,r){return o||(o={error:"Missing offer param"}),o.error?void r(o.error):(t.applyOffer(o),void e())})}function n(e){this.getOfferPromise=function(t){return o(e,t)},this.applyOfferPromise=function(t){return r(e,t)}}function i(e,t){return!(0!==t.allowedRoutesFilter.length&&t.allowedRoutesFilter.indexOf(e)===-1||t.disallowedRoutesFilter.length>0&&t.disallowedRoutesFilter.indexOf(e)!==-1)}function s(e){this.isRouteAllowed=function(t){return i(t,e)}}function u(e,t){return{mbox:t.mbox||e.globalMboxName,timeout:t.timeout||e.timeout,globalMboxAutoCreate:e.globalMboxAutoCreate,params:t.params||null,selector:t.selector||null,allowedRoutesFilter:t.allowedRoutesFilter||[],disallowedRoutesFilter:t.disallowedRoutesFilter||[],appendToSelector:t.appendToSelector||!1}}function a(t,o,r){e.module("target.angular.common",[]).constant("version","0.1.2").constant("settings",t).constant("logger",o).constant("customOptions",r||{}).factory("options",["settings","customOptions",u]).service("routeService",["options",s]).service("offerService",["$q",n])}t.registerExtension({name:"angular.setupCommon",modules:["settings","logger"],register:function(e,t){return function(o){a(e,t,o)}}})}(angular,adobe.target),function(e,t){"use strict";function o(e,t){t.forEach(function(t){e.requires.indexOf(t)===-1&&e.requires.push(t)})}function r(e,t,o){e.applyOfferPromise(t)["catch"](function(e){o.error("AT applyOffer error: "+e)})}function n(e){e.run(["$transitions","offerService","routeService","logger",function(e,t,o,n){e.onCreate({},function(e){this.routeService.isRouteAllowed(e.to().url)&&e.addResolvable(i,e.to().name)},{bind:{routeService:o}}),e.onSuccess({},function(e){if(e.getResolveTokens().indexOf("targetOfferData")>-1){var t=e.injector().get("targetOfferData");r(this.offerService,t,n)}},{bind:{offerService:t,logger:n}})}])}var i={token:"targetOfferData",policy:{when:"EAGER",async:"WAIT"},deps:["offerService","options"],resolveFn:function(e,t){return e.getOfferPromise(t)}};t.ext.angular.initStates=function(r,i){t.ext.angular.setupCommon(i);var s="string"==typeof r?e.module(r):r;o(s,["target.angular.common"]),n(s)}}(angular,adobe.target);