// All material copyright ESRI, All Rights Reserved, unless otherwise specified.
// See http://@sbaseurl@/jsapi/jsapi/esri/copyright.txt and http://www.arcgis.com/apps/webappbuilder/copyright.txt for details.

//>>built
define("dojo/_base/lang esri/request dojo/promise/all jimu/shared/basePortalUrlUtils dojo/Deferred esri/lang jimu/portalUtils jimu/Role jimu/utils esri/urlUtils".split(" "),function(g,l,u,m,h,r,t,v,k,p){var n={getBaseHrefUrl:function(a){var b="HTML3D"===window.appInfo.appType?"webappviewer3d":"webappviewer",c="";window.isXT?c=window.location.protocol+"//"+window.location.host+window.appInfo.appPath:(c=k.urlToObject(window.location.href).query||{},c=c.appid?a+"apps/"+b+"/index.html?appid\x3d"+c.appid:
c.id?a+"apps/"+b+"/index.html?id\x3d"+c.id:k.getAppHref());return c},addQueryParamToUrl:function(a,b,c,d){a=p.urlToObject(a);a.query||(a.query={});a.query[b]=c;b=a.path;for(var e in a.query)c=a.query[e],!0===d&&(c=encodeURIComponent(c)),b=b===a.path?b+"?"+e+"\x3d"+c:b+"\x26"+e+"\x3d"+c;return b},getQueryParamFromUrl:function(a,b){a=p.urlToObject(a);a.query||(a.query={});return a.query[b]},removeQueryParamFromUrl:function(a,b,c){a=p.urlToObject(a);a.query&&delete a.query[b];b=a.path;for(var d in a.query){var e=
a.query[d];!0===c&&(e=encodeURIComponent(e));b=b===a.path?b+"?"+d+"\x3d"+e:b+"\x26"+d+"\x3d"+e}return b},getShareUrlContent:function(a){return"\x3cdiv class\x3d'marker-feature-action-popup'\x3e\x3cdiv class\x3d'item'\x3e\x3cspan class\x3d'sub-title jimu-float-leading'\x3e"+window.jimuNls.common.url+"\x3c/span\x3e\x3cinput type\x3d'text' class\x3d'jimu-float-leading' readonly\x3d'readonly' value\x3d"+a+"\x3e\x3c/input\x3e\x3c/div\x3e\x3c/div\x3e"},getShareUrl:function(a,b,c){var d=n.getBaseHrefUrl(window.portalUrl),
e="";if(b)if(b.longitude&&b.latitude){var f=b.longitude;var q=b.latitude;e=b.longitude+","+b.latitude+","}else if(b.x&&b.y&&b.spatialReference&&b.spatialReference.wkid){var w=b.x;var x=b.y;var y=b.spatialReference.wkid;e=b.x+","+b.y+","+b.spatialReference.wkid}d=n.addQueryParamToUrl(d,"marker",e,!0);d=n.addQueryParamToUrl(d+",,,","markertemplate",encodeURIComponent(JSON.stringify({title:b.title,x:w,y:x,wkid:y,longitude:f,latitude:q,isIncludeShareUrl:c})));b=a.getLevel();return d="number"===typeof b&&
-1!==b?n.addQueryParamToUrl(d,"level",a.getLevel(),!0):n.addQueryParamToUrl(d,"scale",a.getScale(),!0)},getXyContent:function(a){var b="\x3cdiv class\x3d'marker-feature-action-popup'\x3e";a.longitude&&a.latitude?b+="\x3cdiv class\x3d'item clearFix'\x3e\x3cspan class\x3d'sub-title'\x3e"+window.jimuNls.common.longitude+"\x3c/span\x3e\x3cspan class\x3d'val'\x3e"+k.localizeNumber(parseFloat(a.longitude).toFixed(4))+"\x3c/span\x3e\x3c/div\x3e\x3cdiv class\x3d'item clearFix'\x3e\x3cspan class\x3d'sub-title'\x3e"+
window.jimuNls.common.latitude+"\x3c/span\x3e\x3cspan class\x3d'val'\x3e"+k.localizeNumber(parseFloat(a.latitude).toFixed(4))+"\x3c/span\x3e\x3c/div\x3e":a.x&&a.y&&(b+="\x3cdiv class\x3d'item clearFix'\x3e\x3cspan class\x3d'sub-title'\x3ex\x3c/span\x3e\x3cspan class\x3d'val'\x3e"+k.localizeNumber(parseFloat(a.x).toFixed(4))+"\x3c/span\x3e\x3c/div\x3e\x3cdiv class\x3d'item'\x3e\x3cspan class\x3d'sub-title'\x3ey\x3c/span\x3e\x3cspan class\x3d'val'\x3e"+k.localizeNumber(parseFloat(a.y).toFixed(4))+"\x3c/span\x3e\x3c/div\x3e");
return b+"\x3c/div\x3e"},_isUserOwnTheApp:function(a){return a&&a.username&&a.username===window.appInfo.appOwner?!0:!1},getItemByUserAndItemId:function(a,b,c,d){var e=new h;d=m.getStandardPortalUrl(d);d=d+"/sharing/rest/content/users/"+(b?b.username?b.username:b.email:c.email);if(r.isDefined(a.folderId)&&"/"!==a.folderId||r.isDefined(a.ownerFolder)&&"/"!==a.ownerFolder)d+="/"+(a.folderId||a.ownerFolder);d+="/items/"+a.id;l({url:d,handleAs:"json",content:{f:"json"},callbackParamName:"callback"}).then(g.hitch(this,
function(f){e.resolve(f)}),g.hitch(this,function(f){console.error(f);e.reject(f)}));return e},_getProfile:function(a,b){var c=new h;a=m.getUserUrl(b,a.owner);l({url:a,handleAs:"json",content:{f:"json"},callbackParamName:"callback"}).then(g.hitch(this,function(d){c.resolve(d)}),g.hitch(this,function(d){console.error(d);c.reject(d)}));return c},_unshareItemById:function(a,b,c){var d=new h;c=m.getStandardPortalUrl(c);c+="/sharing/rest/content/items/"+b+"/unshare";b={f:"json"};b=g.mixin(b,a);l({url:c,
handleAs:"json",content:b,callbackParamName:"callback"},{usePost:!0}).then(g.hitch(this,function(e){d.resolve(e)}),g.hitch(this,function(e){console.error(e);d.reject(e)}));return d},canSharePublic:function(a){return!a.selfUrl||!0!==a.canSharePublic&&!1!==a.canSharePublic?!0:a.canSharePublic},unshareItemsByUser:function(a,b,c){var d=new h;c=m.getStandardPortalUrl(c);c+="/sharing/rest/content/users/"+a+"/unshareItems";a={f:"json"};a=g.mixin(a,b);l({url:c,handleAs:"json",content:a,callbackParamName:"callback"},
{usePost:!0}).then(g.hitch(this,function(e){d.resolve(e)}),g.hitch(this,function(e){console.error(e);d.reject(e)}));return d},unshareItems:function(a,b,c){var d=new h;c=m.getStandardPortalUrl(c);c+="/sharing/rest/content/users/"+(b.owner||a.email)+"/unshareItems";a={f:"json"};a=g.mixin(a,b);l({url:c,handleAs:"json",content:a,callbackParamName:"callback"},{usePost:!0}).then(g.hitch(this,function(e){d.resolve(e)}),g.hitch(this,function(e){console.error(e);d.reject(e)}));return d},shareItemsByUser:function(a,
b,c){var d=new h;c=m.getStandardPortalUrl(c);c+="/sharing/rest/content/users/"+a+"/shareItems";a={f:"json"};a=g.mixin(a,b);l({url:c,handleAs:"json",content:a,callbackParamName:"callback"},{usePost:!0}).then(g.hitch(this,function(e){d.resolve(e)}),g.hitch(this,function(e){console.error(e);d.reject(e)}));return d},shareItems:function(a,b,c){var d=new h;c=m.getStandardPortalUrl(c);c+="/sharing/rest/content/users/"+(b.owner||a.email)+"/shareItems";a={f:"json"};a=g.mixin(a,b);l({url:c,handleAs:"json",
content:a,callbackParamName:"callback"},{usePost:!0}).then(g.hitch(this,function(e){d.resolve(e)}),g.hitch(this,function(e){console.error(e);d.reject(e)}));return d},getItemsGroups:function(a,b){var c=new h;b=m.getStandardPortalUrl(b);b+="/sharing/rest/content/items/"+a.id+"/groups";l({url:b,handleAs:"json",content:{f:"json"},callbackParamName:"callback"},{usePost:!0}).then(g.hitch(this,function(d){c.resolve(d)}),g.hitch(this,function(d){console.error(d);c.reject(d)}));return c},isSharedToPublic:function(a){return window.isXT?
!1:null===a?!0:"undefined"!==typeof a&&"undefined"!==typeof a.item&&"undefined"!==typeof a.item.access&&"public"===a.item.access?!0:!1},isShowSocialMediaLinks:function(a){return window.isXT?!0:null===a?!0:"undefined"!==typeof a&&"undefined"!==typeof a.item&&"undefined"!==typeof a.item.access&&"private"===a.item.access?!1:!0},getItemShareInfo:function(a){var b=new h,c="";if(window.isXT)return b.resolve(null);c=k.urlToObject(k.getAppHref()).query||{};c=c.id||c.appid;if("undefined"===typeof c||""===
c)return b.resolve(null);t.getPortal(a).getItemById(c).then(g.hitch(this,function(d){var e={};e.item=d;e.item&&"undefined"===typeof e.item.sharing&&e.item.access&&(e.item.sharing={access:e.item.access});b.resolve(e)}),g.hitch(this,function(d){console.log(d);b.resolve(null)}));return b},getShareInfo:function(a){var b=t.getPortal(a),c=new h,d="";if(window.isXT)return c.resolve(null);d=k.urlToObject(k.getAppHref()).query||{};d=d.id||d.appid;if("undefined"===typeof d||""===d)return c.resolve(null);u({getUser:b.getUser(),
loadSelfInfo:b.loadSelfInfo(),getItem:b.getItemById(d)}).then(g.hitch(this,function(e){var f={};f.item=e.getItem;f.item&&f.item.ownerFolder&&f.item.ownerFolder.length&&"/"!==f.item.ownerFolder&&(f.item.folderId=f.item.ownerFolder);"undefined"===typeof f.item.sharing&&f.item.access&&(f.item.sharing={access:f.item.access});f.user=e.getUser;n._setUserRole(e.loadSelfInfo,f);f.currentUser=f.user;f.isAdmin=!1;f.userRole&&(f.userRole.isAdmin()||f.userRole.isCustom()&&f.userRole.canUpdateOrgItems())?(f.isAdmin=
!0,f.item.owner!==f.currentUser.name?n._getProfile(f.item,a).then(g.hitch(this,function(q){f.itemUser=q;f.itemUser.orgId!==f.currentUser.orgId&&(f.isAdmin=!1);c.resolve(f)})):(f.itemUser=f.currentUser,c.resolve(f))):(f.currentUser&&(f.itemUser=f.currentUser),c.resolve(f))}),g.hitch(this,function(e){console.log(e);c.resolve(null)}));return c},_setUserRole:function(a,b){b.userPortalUrl=a.urlKey?a.urlKey+"."+a.customBaseUrl:this.portalUrl;!a||a.code||a.message||(b.organization=a);if(a&&a.user)b.userRole=
new v({id:a.user.roleId?a.user.roleId:a.user.role,role:a.user.role}),b._isCustomRole=b.userRole.isCustom(),b._roleCanShareToGroup=b._isCustomRole&&b.userRole.canShareItemToGroup(),b._roleCanShareToOrg=b._isCustomRole&&b.userRole.canShareItemToOrg(),b._roleCanSharePublic=b._isCustomRole&&b.userRole.canShareItemToPublic(),b._roleCanShare=b._roleCanShareToGroup||b._roleCanShareToOrg||b._roleCanShareToPublic,b._roleCanUpdateItems=b._isCustomRole&&b.userRole.canUpdateOrgItems(),b._roleCanShareOthersItemsToGroup=
b._isCustomRole&&b.userRole.canShareOthersItemsToGroup(),b._roleCanShareOthersItemsToOrg=b._isCustomRole&&b.userRole.canShareOthersItemsToOrg(),b._roleCanShareOthersItemsToPublic=b._isCustomRole&&b.userRole.canShareOthersItemsToPublic(),b._roleCanShareOthersItems=b._isCustomRole&&(b.userRole.canShareOthersItemsToGroup()||b.userRole.canShareOthersItemsToOrg()||b._roleCanShareOthersItemsToPublic),b._orgUserCanSharePublicOrOverride=b.organization&&(!0===b.organization.canSharePublic&&(!b._isCustomRole||
b._roleCanSharePublic||b._roleCanShareOthersItemsToPublic)||b.userRole.isAdmin());else return!1},getItemById:function(a,b){var c=new h;b=m.getStandardPortalUrl(b);b+="/sharing/rest/content/items/"+a.id;l({url:b,handleAs:"json",content:{f:"json"},callbackParamName:"callback"}).then(g.hitch(this,function(d){c.resolve(d)}),g.hitch(this,function(d){console.error(d);c.reject(d)}));return c},disableWebMapPopup:function(a){a&&a.setInfoWindowOnClick&&a.setInfoWindowOnClick(!1)},enableWebMapPopup:function(a){a&&
a.setInfoWindowOnClick&&a.setInfoWindowOnClick(!0)}};return n});