/* COPYRIGHT Esri - https://js.arcgis.com/5.0/LICENSE.txt */
import e from"../../Graphic.js";import{px2pt as t}from"../../core/screenUtils.js";import{isSharedTemplateMetadata as r,isStandardFeatureTemplate as i}from"../../editing/templateUtils.js";import{isGraphic as n}from"../../support/graphicInstanceUtils.js";import{renderPreviewHTML as o}from"../../symbols/support/symbolUtils.js";async function a(e,a,m){if(!n(e)&&r(e)&&e.thumbnail){const t=`data:image/png;base64,${e.thumbnail.imageData}`,r=document.createElement("div");return r.classList.add("esri-thumbnail-preview"),"geometryType"in a&&a.geometryType&&r.classList.add(`esri-thumbnail-preview--${a.geometryType}`),r.style.backgroundImage=`url(${t})`,r}const l=await s(a,e);if(null==l)return null;const y={maxSize:t(m?.maxSize??32),ariaLabel:m?.ariaLabel};if((n(e)||i(e))&&"renderer"in a&&"dictionary"===a.renderer?.type&&(y.fieldMap=a.renderer.fieldMap??void 0,y.feature=n(e)?e:{attributes:e.prototype.attributes??{}}),n(e)&&e.geometry&&!1!==m?.useGeometry&&!e.geometry.type.includes("point")){y.geometry=e.geometry,y.useMarkerSymbolSize=!1;const r=t(m?.maxSize??22);y.size={width:r,height:r}}return await o(l,y)}async function s(t,i){if(!n(i)&&r(i))return l(t);if("renderer"in t&&t.renderer){const{renderer:r}=t,o=n(i)?i:new e({attributes:i.prototype.attributes});if("getSymbolAsync"in r){const e=await r.getSymbolAsync(o);if(e)return e}}return"graphics"===t.type&&n(i)&&i.geometry?m(i.geometry.type):l(t)}async function m(e){const t="point"===e||"multipoint"===e?await import("../../symbols/SimpleMarkerSymbol.js"):"polyline"===e?await import("../../symbols/SimpleLineSymbol.js"):"polygon"===e||"mesh"===e||"multipatch"===e?await import("../../symbols/SimpleFillSymbol.js"):null;return t?new t.default:null}async function l(e){return"geometryType"in e&&e.geometryType?m(e.geometryType):null}export{a as fetchThumbnail};
