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