/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["exports","../../symbols","../../core/devEnvironmentUtils","../../core/Error","../../core/maybe","../../core/urlUtils","../../portal/Portal","../../chunks/persistableUrlUtils","./jsonUtils","./StyleOrigin","./styleUtils","./Thumbnail"],(function(e,t,l,r,o,n,a,m,s,i,u,y){"use strict";function b(e,t,l,o){return e.name?e.styleName&&"Esri2DPointSymbolsStyle"===e.styleName?f(e,t,o):u.fetchStyle(e,t,o).then((r=>c(r,e.name,t,l,o))):Promise.reject(new r("symbolstyleutils:style-symbol-reference-name-missing","Missing name in style symbol reference"))}function c(e,b,c,f,S){const p=e.data,h=c&&o.isSome(c.portal)?c.portal:a.getDefault(),d={portal:h,url:n.urlToObject(e.baseUrl),origin:"portal-item"},g=p.items.find((e=>e.name===b));if(!g){const e=`The symbol name '${b}' could not be found`;return Promise.reject(new r("symbolstyleutils:symbol-name-not-found",e,{symbolName:b}))}let O=m.fromJSON(u.symbolUrlFromStyleItem(g,f),d),U=g.thumbnail&&g.thumbnail.href;const N=g.thumbnail&&g.thumbnail.imageData;l.isDevEnvironment()&&(O=l.adjustStaticAGOUrl(O),U=l.adjustStaticAGOUrl(U));const j={portal:h,url:n.urlToObject(n.removeFile(O)),origin:"portal-item"};return u.requestJSON(O,S).then((l=>{const r="cimRef"===f?u.makeCIMSymbolRef(l.data):l.data,o=s.fromJSON(r,j);if(o&&t.isSymbol3D(o)){if(U){const e=m.fromJSON(U,d);o.thumbnail=new y.Thumbnail({url:e})}else N&&(o.thumbnail=new y.Thumbnail({url:`data:image/png;base64,${N}`}));e.styleUrl?o.styleOrigin=new i({portal:c.portal,styleUrl:e.styleUrl,name:b}):e.styleName&&(o.styleOrigin=new i({portal:c.portal,styleName:e.styleName,name:b}))}return o}))}function f(e,t,l){const r=u.Style2DUrlTemplate.replace(/\{SymbolName\}/gi,e.name),m=o.isSome(t.portal)?t.portal:a.getDefault();return u.requestJSON(r,l).then((e=>{const t=u.makeCIMSymbolRef(e.data);return s.fromJSON(t,{portal:m,url:n.urlToObject(n.removeFile(r)),origin:"portal-item"})}))}e.fetchSymbolFromStyle=c,e.resolveWebStyleSymbol=b,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
