/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["exports","../../chunks/_rollupPluginBabelHelpers","../../request","../../core/Error","../../core/maybe","../../core/promiseUtils","../../core/urlUtils","../../portal/Portal","../../portal/PortalQueryParams","../../support/featureFlags"],(function(e,t,r,o,s,n,l,u,a,y){"use strict";const i={};function c(e,t){return f.apply(this,arguments)}function f(){return(f=t._asyncToGenerator((function*(e,t){try{return{data:(yield w(e,t)).data,baseUrl:l.removeFile(e),styleUrl:e}}catch(r){return n.throwIfAbortError(r),null}}))).apply(this,arguments)}function m(e,t,r){const o=s.isSome(t.portal)?t.portal:u.getDefault();let n;const l=`${o.url} - ${o.user&&o.user.username} - ${e}`;return i[l]||(i[l]=p(e,o,r).then((e=>(n=e,e.fetchData()))).then((t=>({data:t,baseUrl:n.itemUrl,styleName:e})))),i[l]}function p(e,t,r){return t.load(r).then((()=>{const o=new a({disableExtraQuery:!0,query:`owner:${U} AND type:${N} AND typekeywords:"${e}"`});return t.queryItems(o,r)})).then((({results:t})=>{let s=null;const n=e.toLowerCase();if(t&&Array.isArray(t))for(const e of t){if(e.typeKeywords.some((e=>e.toLowerCase()===n))&&e.type===N&&e.owner===U){s=e;break}}if(!s)throw new o("symbolstyleutils:style-not-found",`The style '${e}' could not be found`,{styleName:e});return s.load(r)}))}function d(e,t,r){return e.styleUrl?c(e.styleUrl,r):e.styleName?m(e.styleName,t,r):Promise.reject(new o("symbolstyleutils:style-url-and-name-missing","Either styleUrl or styleName is required to resolve a style"))}function b(e){return null===e||"CIMSymbolReference"===e.type?e:{type:"CIMSymbolReference",symbol:e}}function h(e,t){if("cimRef"===t)return e.cimRef;if(e.formatInfos&&!y.enableWebStyleForceWOSR())for(const r of e.formatInfos)if("gltf"===r.type)return r.href;return e.webRef}function S(e){for(const t of e.typeKeywords)if(/^Esri.*Style$/.test(t)&&"Esri Style"!==t)return t}function w(e,t){const o={responseType:"json",query:{f:"json"},...t};return r(l.normalize(e),o)}const U="esri_en",N="Style",g="https://cdn.arcgis.com/sharing/rest/content/items/220936cc6ed342c9937abd8f180e7d1e/resources/styles/cim/{SymbolName}.json?f=json";e.Style2DUrlTemplate=g,e.fetchStyle=d,e.makeCIMSymbolRef=b,e.requestJSON=w,e.styleNameFromItem=S,e.symbolUrlFromStyleItem=h,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
