/**
 * 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.reject("Empty offer")},r.error=function(e,t){n.reject(t)},t.getOffer(r),n.promise}function r(e,o){return e(function(e,r){t.applyOffer(o),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 u(e){this.isRouteAllowed=function(t){return i(t,e)}}function s(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 l(t,o,r){e.module("target.angular.common",[]).constant("version","0.3.0").constant("settings",t).constant("logger",o).constant("customOptions",r||{}).factory("options",["settings","customOptions",s]).service("routeService",["options",u]).service("offerService",["$q",n])}t.registerExtension({name:"angular.setupCommon",modules:["settings","logger"],register:function(e,t){return function(o){l(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){e.resolve=e.resolve||{},e.resolve.offerData=t}function n(e,t,o,n){this.applyTargetToRoutes=function(i){Object.keys(i).forEach(function(u){e.isRouteAllowed(u)&&(n.log("location: "+u),r(i[u],function(){return t.getOfferPromise(o)}))})}}function i(e){e.service("ngRouteService",["routeService","offerService","options","logger",n]),e.run(["$rootScope","$route","offerService","ngRouteService","logger",function(e,t,o,r,n){r.applyTargetToRoutes(t.routes),e.$on("$viewContentLoaded",function(){var e=t.current.locals.offerData;e&&o.applyOfferPromise(e)["catch"](function(e){n.error("AT applyOffer error: "+e)})})}])}t.ext.angular.initRoutes=function(r,n){t.ext.angular.setupCommon(n);var u="string"==typeof r?e.module(r):r;o(u,["target.angular.common"]),i(u)}}(angular,adobe.target);