/* COPYRIGHT Esri - https://js.arcgis.com/5.1.2/LICENSE.txt */
import{__decorate as r}from"tslib";import t from"../../core/Accessor.js";import{JSONMap as s}from"../../core/jsonMap.js";import a from"../../core/Logger.js";import{property as o,subclass as e}from"../../core/accessorSupport/decorators.js";import i from"./ColorVariable.js";import l from"./OpacityVariable.js";import n from"./RotationVariable.js";import p from"./SizeVariable.js";import{addUnsupportedMessage as c}from"../../webdoc/support/unsupportedErrors.js";const b={color:i,size:p,opacity:l,rotation:n},u=new s({colorInfo:"color",transparencyInfo:"opacity",rotationInfo:"rotation",sizeInfo:"size"}),V=/^\[([^\]]+)\]$/i;let h=class extends t{constructor(){super(...arguments),this.colorVariables=null,this.opacityVariables=null,this.rotationVariables=null,this.sizeVariables=null}set visualVariables(r){if(this._resetVariables(),r=r?.filter(r=>!!r),r?.length){for(const t of r)switch(t.type){case"color":this.colorVariables.push(t);break;case"opacity":this.opacityVariables.push(t);break;case"rotation":this.rotationVariables.push(t);break;case"size":this.sizeVariables.push(t)}if(this.sizeVariables.length){this.sizeVariables.some(r=>!!r.target)&&r.sort((r,t)=>{let s=null;return s=r.target===t.target?0:r.target?1:-1,s})}for(let t=0;t<r.length;t++){r[t].index=t}this._set("visualVariables",r)}else this._set("visualVariables",r)}readVariables(r,t,s){const{rotationExpression:o,rotationType:e}=t,i=o?.match(V),l=i?.[1];if(l&&(r||(r=[]),r.push({type:"rotationInfo",rotationType:e,field:l})),r)return r.map(r=>{const t=u.read(r.type),o=b[t];o||(a.getLogger(this).warn(`Unknown variable type: ${t}`),c(s,"warning","visual-variable",`visualVariable of type '${t}' is not supported`,{definition:r}));const e=new o;return e.read(r,s),e})}writeVariables(r,t){const s=[];for(const a of r){const r=a.toJSON(t);r&&s.push(r)}return s}_resetVariables(){this.colorVariables=[],this.opacityVariables=[],this.rotationVariables=[],this.sizeVariables=[]}};r([o()],h.prototype,"visualVariables",null),h=r([e("esri.renderers.visualVariables.VisualVariableFactory")],h);export{h as default};
