/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["../../../../core/maybe","./enums","./shaders/MaterialPrograms"],(function(r,e,t){"use strict";const a=r=>r===e.WGLDrawPhase.HITTEST||r===e.WGLDrawPhase.LABEL_ALPHA,s=r=>(a(r)?1:0)|(r===e.WGLDrawPhase.HIGHLIGHT?2:0),o=({rendererInfo:e,drawPhase:t},a,o,i)=>`${a.getVariationHash()}-${i.join(".")}-${s(t)}-${e.getVariationHash()}-${r.isSome(o)&&o.join(".")}`,i=(t,s,o,i)=>{const n=i.reduce(((r,e)=>({...r,[e]:t.context.driverTest[e]})),{}),h={...s.getVariation(),...t.rendererInfo.getVariation(),highlight:t.drawPhase===e.WGLDrawPhase.HIGHLIGHT,id:a(t.drawPhase),...n};if(r.isSome(o))for(const r of o)h[r]=!0;return h};return function(){function r(r){this._rctx=r,this._programByKey=new Map}var e=r.prototype;return e.dispose=function(){this._programByKey.forEach((r=>r.dispose())),this._programByKey.clear()},e.getProgram=function(r,e=[],a=[]){const s=r.vsPath+"."+r.fsPath+JSON.stringify(e)+a.join(".");if(this._programByKey.has(s))return this._programByKey.get(s);const o=a.reduce(((r,e)=>({...r,[e]:this._rctx.driverTest[e]})),{}),i={...e.map((r=>"string"==typeof r?{name:r,value:!0}:r)).reduce(((r,e)=>({...r,[e.name]:e.value})),{}),...o},{vsPath:n,fsPath:h,attributes:g}=r,c=t.createProgramTemplate(n,h,g,i),m=this._rctx.programCache.acquire(c.shaders.vertexShader,c.shaders.fragmentShader,c.attributes);if(!m)throw new Error("Unable to get program for key: ${key}");return this._programByKey.set(s,m),m},e.getMaterialProgram=function(r,e,a,s,n,h=["ignoresSamplerPrecision"]){const g=o(r,e,n,h);if(this._programByKey.has(g))return this._programByKey.get(g);const c=i(r,e,n,h),m=t.createProgramTemplate(a,a,s,c),y=this._rctx.programCache.acquire(m.shaders.vertexShader,m.shaders.fragmentShader,m.attributes);if(!y)throw new Error("Unable to get program for key: ${key}");return this._programByKey.set(g,y),y},r}()}));
