text: // Copyright (c) 2009-2017 SAP SE, All Rights Reserved
  sap.ui.define(["sap/ushell/utils","sap/ushell/services/_ClientSideTargetResolution/Utils","sap/ushell/navigationMode","sap/ushell/services/AppConfiguration","sap/ushell/Config","sap/ui/thirdparty/jquery","sap/base/util/ObjectPath","sap/base/util/isEmptyObject","sap/base/util/isPlainObject","sap/ui/generic/app/navigation/service/SelectionVariant"],function(u,c,n,a,C,q,O,i,b,S){"use strict";function m(M,A){var D=new q.Deferred(),N,R=M.resolutionResult,t=M.inbound&&(M.inbound.signature||{}),v=h(R)||t.additionalParameters==="ignored"||k(M);if(!v){e(D,M);return D.promise();}var w=M.intentParamsPlusAllDefaults["sap-xapp-state"]&&M.intentParamsPlusAllDefaults["sap-xapp-state"][0];if(w){s(A,w).then(p).then(function(V){if(h(R)){var P=c.constructParameterDominatorMap(t.parameters);Object.keys(R.oNewAppStateMembers).forEach(function(x){var y=P[x].dominatedBy;if(g(V,y)){delete R.oNewAppStateMembers[x];}});}var I=t.additionalParameters==="ignored";if(!h(R)&&!k(M)&&!I){e(D,M);return;}N=A.createEmptyAppState(undefined,true);if(N){N.setData(V);d(N,M,D);}},function(){delete R.oNewAppStateMembers;e(D,M);return;});return D.promise();}if(h(R)){var E=A.createEmptyAppState(undefined,true);d(E,M,D);return D.promise();}e(D,M);return D.promise();}function d(N,M,D){var t=N.getData()||{},v,w={},x=M.inbound.signature,R=M.resolutionResult;if(t.selectionVariant){v=new S(JSON.stringify(t.selectionVariant));}else{v=new S();}if(h(R)){Object.keys(R.oNewAppStateMembers).forEach(function(y){v.massAddSelectOption(y,R.oNewAppStateMembers[y].Ranges);});}var I=x.additionalParameters==="ignored";v=r(v,w,x.parameters,I);if(v.getParameterNames().length!==0||v.getSelectOptionsPropertyNames().length!==0||w.deleted){t.selectionVariant=v.toJSONObject();}if(!w.changed&&!w.deleted&&!h(R)){e(D,M);return;}N.setData(t);N.save().done(function(){M.intentParamsPlusAllDefaults["sap-xapp-state"]=[N.getKey()];M.mappedIntentParamsPlusSimpleDefaults["sap-xapp-state"]=[N.getKey()];e(D,M);});}function e(D,M){var N;l(M);o(M);N=n.compute(O.get("inbound.resolutionResult.applicationType",M),(M.intentParamsPlusAllDefaults["sap-ushell-next-navmode"]||[])[0],(M.intentParamsPlusAllDefaults["sap-ushell-navmode"]||[])[0],(a.getCurrentApplication()||{}).applicationType,C.last("/core/navigation/enableInPlaceForClassicUIs"));u.shallowMergeObject(M.resolutionResult,N);delete M.resolutionResult.oNewAppStateMembers;D.resolve(M);}function h(R){return R.oNewAppStateMembers&&!i(R.oNewAppStateMembers);}function f(L,P){return Array.isArray(L)&&L.some(function(M){return(P.indexOf(M)!==-1);});}function g(A,P){if(A&&A.selectionVariant){var t=new S(JSON.stringify(A.selectionVariant)),v=(t.getSelectOptionsPropertyNames()||[]),w=(t.getParameterNames()||[]);if(f(v,P)||f(w,P)){return true;}}return false;}function r(t,R,P,I){var v=new S(),w=(t.getParameterNames()||[]),x=(t.getSelectOptionsPropertyNames()||[]),y,z;w.forEach(function(A){y=t.getParameter(A);if(I&&!P[A]){R.deleted=true;return;}if(P[A]&&P[A].renameTo){if((v.getParameter(P[A].renameTo)===undefined)&&(v.getSelectOption(P[A].renameTo)===undefined)){v.addParameter(P[A].renameTo,y);R.changed=true;}else{q.sap.log.error("renaming of appstate creates duplicates "+A+"->"+P[A].renameTo);}}else if((v.getParameter(A)===undefined)&&(v.getSelectOption(A)===undefined)){v.addParameter(A,y);}});x.forEach(function(A){z=t.getSelectOption(A);if(I&&!P[A]){R.deleted=true;return;}if(P[A]&&P[A].renameTo){if((v.getSelectOption(P[A].renameTo)===undefined)&&(v.getParameter(P[A].renameTo)===undefined)){v.massAddSelectOption(P[A].renameTo,z);R.changed=true;}else{q.sap.log.error("renaming of appstate creates duplicates "+A+"->"+P[A].renameTo);}}else if((v.getSelectOption(A)===undefined)&&(v.getParameter(A)===undefined)){v.massAddSelectOption(A,z);}});w.forEach(function(A){t.removeParameter(A);});x.forEach(function(A){t.removeSelectOption(A);});v.getParameterNames().forEach(function(A){t.addParameter(A,v.getParameter(A));});v.getSelectOptionsPropertyNames().forEach(function(A){t.massAddSelectOption(A,v.getSelectOption(A));});return t;}function j(D){if(D===undefined||b(D)){return false;}return true;}function k(M){return M.inbound&&M.inbound.signature&&M.inbound.signature.parameters&&Object.keys(M.inbound.signature.parameters).some(function(K){return!!(M.inbound.signature.parameters[K].renameTo);});}function l(M){M.defaultedParamNames=M.defaultedParamNames.filter(function(N){if(M.intentParamsPlusAllDefaults[N]&&!Array.isArray(M.intentParamsPlusAllDefaults[N])){if(!(M.resolutionResult.oNewAppStateMembers&&M.resolutionResult.oNewAppStateMembers[N])){return false;}}return true;});}function o(M){var P=(O.get("inbound.signature.parameters",M)||{}),t={};M.defaultedParamNames.forEach(function(N){var v=(P[N]&&P[N].renameTo)||N;if(t[v]){q.sap.log.error("renaming of defaultedParamNames creates duplicates"+N+"->"+v);}else{t[v]=true;}});M.mappedDefaultedParamNames=Object.keys(t).sort();}function p(A){if(j(A)){return Promise.reject();}return Promise.resolve(A);}function s(A,t){return new Promise(function(R,v){A.getAppState(t).done(function(w){R(w.getData());}).fail(function(E){v(E);});});}return{mixAppStateIntoResolutionResultAndRename:m,_hasRenameTo:k};});
  