import Portal from"@arcgis/core/portal/Portal";import{isArcGisApiVersion3x}from"./ArcGisApiVersion.js";import{GenericActivityError,ActivityNotImplementedError}from"../../Errors.js";class GetPortalUser{async execute(r,t){const e={user:void 0,groups:[]};try{var o=isArcGisApiVersion3x?this.getPortalUrl(t):void 0,i=await this.getPortalUser(o);i&&(e.user=i,!1!==r.loadGroups&&(e.groups=await this.getPortalGroups(i)))}catch(r){throw console.error(r),new GenericActivityError('Error running the "Get Portal User" activity. The requested resource failed to load.')}return e}async getPortalUser(r){let o;if(!isArcGisApiVersion3x)return o=new Portal,await o.load(),o.user;return r?(o=new Portal(r),await new Promise((t,e)=>{require(["dojo/on"],r=>{r(o,"load",r=>r.signIn().then(t,e))})}),o.getPortalUser()):void 0}getPortalUrl(r){throw new ActivityNotImplementedError(GetPortalUser.action)}async getPortalGroups(r){return r[isArcGisApiVersion3x?"getGroups":"fetchGroups"]()}}GetPortalUser.action="gcx:wf:arcgis::GetPortalUser",GetPortalUser.suite="gcx:wf:builtin";export{GetPortalUser};