/* COPYRIGHT Esri - https://js.arcgis.com/5.1.0/LICENSE.txt */
import e from"../../../../../core/Error.js";import{ShaderTechniqueConfigurationKey as t}from"./ShaderTechniqueConfigurationKey.js";import{NoParameters as r}from"../../../../webgl/NoParameters.js";class a extends r{constructor(){super(),this._parameterBits=this._parameterBits?.map(()=>0)??[],this._parameterNames??=[]}get key(){return this._key??=new t(this._parameterBits),this._key}decode(e=this.key){const t=this._parameterBits;this._parameterBits=[...e.bits];const r=this._parameterNames.map(e=>`    ${e}: ${this[e]}`).join("\n");return this._parameterBits=t,r}}function i(t={}){return(r,a)=>{r.hasOwnProperty("_parameterNames")||Object.defineProperty(r,"_parameterNames",{value:r._parameterNames?.slice()??[],configurable:!0,writable:!0}),r.hasOwnProperty("_parameterBits")||Object.defineProperty(r,"_parameterBits",{value:r._parameterBits?.slice()??[0],configurable:!0,writable:!0}),r._parameterNames.push(a);const i=t.count||2,s=Math.ceil(Math.log2(i)),o=r._parameterBits;let n=0;for(;o[n]+s>16;)n++,n>=o.length&&o.push(0);const p=o[n],m=(1<<s)-1<<p;o[n]+=s,t.count?Object.defineProperty(r,a,{get(){return(this._parameterBits[n]&m)>>p},set(r){const i=this._parameterBits[n];if((i&m)>>p!==r){if(this._key=null,this._parameterBits[n]=i&~m|+r<<p&m,"number"!=typeof r)throw new e("internal:invalid-shader-configuration",`Configuration value for ${a} must be a number, got ${typeof r}`);if(null==t.count)throw new e("internal:invalid-shader-configuration",`Configuration value for ${a} must provide a count option`)}}}):Object.defineProperty(r,a,{get(){return!!((this._parameterBits[n]&m)>>p)},set(t){const r=this._parameterBits[n];if(!!((r&m)>>p)!==t&&(this._key=null,this._parameterBits[n]=r&~m|+t<<p,"boolean"!=typeof t))throw new e("internal:invalid-shader-configurationx",`Configuration value for ${a} must be boolean, got ${typeof t}`)}})}}export{a as ShaderTechniqueConfiguration,i as parameter};
