// All material copyright ESRI, All Rights Reserved, unless otherwise specified.// See https://js.arcgis.com/4.6/esri/copyright.txt for details.//>>builtdefine("require exports ../core/tsSupport/declareExtendsHelper ../core/tsSupport/decorateHelper ../core/tsSupport/paramHelper ../core/accessorSupport/decorators ../core/lang ../core/urlUtils ../core/Logger ../core/arrayUtils ../core/Error ../core/accessorSupport/ensureType ../portal/Portal ../support/arcadeUtils ../symbols/WebStyleSymbol ../symbols/support/jsonUtils ../symbols/support/styleUtils ../symbols/support/typeUtils ./Renderer ./support/LegendOptions ./support/UniqueValueInfo ./support/diffUtils".split(" "),function(G,H,w,c,x,d,g,m,y,t,z,u,p,h,A,q,B,r,C,D,n,E){varf=y.getLogger("esri.renderers.UniqueValueRenderer"),F=u.ensureType(n.default);returnfunction(v){functiona(b){b=v.call(this)||this;b._valueInfoMap={};b._isDefaultSymbolDerived=!1;b.type="unique-value";b.field=null;b.field2=null;b.field3=null;b.valueExpression=null;b.valueExpressionTitle=null;b.legendOptions=null;b.defaultLabel=null;b.fieldDelimiter=null;b.portal=null;b.styleOrigin=null;b.diff={uniqueValueInfos:function(b,a){if(b||a){if(!b||!a)return{type:"complete",oldValue:b,newValue:a};for(vare=!1,k={type:"collection",added:[],removed:[],changed:[],unchanged:[]},d=function(c){vard=t.find(b,function(b){returnb.value===a[c].value});d?E.diff(d,a[c])?k.changed.push({type:"complete",oldValue:d,newValue:a[c]}):k.unchanged.push({oldValue:d,newValue:a[c]}):k.added.push(a[c]);e=!0},c=0;c<a.length;c++)d(c);d=function(c){t.find(a,function(e){returne.value===b[c].value})||(k.removed.push(b[c]),e=!0)};for(c=0;c<b.length;c++)d(c);returne?k:void0}}};b._set("uniqueValueInfos",[]);returnb}w(a,v);l=a;a.prototype.writeType=function(b,e,a,c){e.type="uniqueValue"};a.prototype.castField=function(b){returnnull==b?b:"function"===typeofb?b:u.ensureString(b)};a.prototype.writeField=function(b,e,a,c){"string"===typeofb?e[a]=b:c&&c.messages?c.messages.push(newz("property:unsupported","UniqueValueRenderer.field set to a function cannot be written to JSON")):f.error(".field: cannot write field to JSON since it's not a string value")};Object.defineProperty(a.prototype,"compiledFunc",{get:function(){returnh.createFunction(this.valueExpression)},enumerable:!0,configurable:!0});Object.defineProperty(a.prototype,"defaultSymbol",{set:function(b){this._isDefaultSymbolDerived=!1;this._set("defaultSymbol",b)},enumerable:!0,configurable:!0});a.prototype.readDefaultSymbol=function(b,e,a){returnq.read(b,e,a)};a.prototype.writeDefaultSymbolWebScene=function(b,e,a,c){this._isDefaultSymbolDerived||q.writeTarget(b,e,a,c)};a.prototype.writeDefaultSymbol=function(b,e,a,c){this._isDefaultSymbolDerived||q.writeTarget(b,e,a,c)};a.prototype.readPortal=function(b,e,a){returna.portal||p.getDefault()};a.prototype.readStyleOrigin=function(b,e,a){if(e.styleName)returnObject.freeze({styleName:e.styleName});if(e.styleUrl)returnb=m.read(e.styleUrl,a),Object.freeze({styleUrl:b})};a.prototype.writeStyleOrigin=function(b,e,a,c){b.styleName?e.styleName=b.styleName:b.styleUrl&&(e.styleUrl=m.write(b.styleUrl,c),m.isAbsolute(e.styleUrl)&&(e.styleUrl=m.normalize(e.styleUrl)))};Object.defineProperty(a.prototype,"uniqueValueInfos",{set:function(b){this.styleOrigin?f.error("#uniqueValueInfos\x3d","Cannot modify unique value infos of a UniqueValueRenderer created from a web style"):(this._set("uniqueValueInfos",b),this._updateValueInfoMap())},enumerable:!0,configurable:!0});a.prototype.addUniqueValueInfo=function(b,e){this.styleOrigin?f.error("#addUniqueValueInfo()","Cannot modify unique value infos of a UniqueValueRenderer created from a web style"):(b="object"===typeofb?F(b):newn.default({value:b,symbol:e}),this.uniqueValueInfos.push(b),this._valueInfoMap[b.value]=b)};a.prototype.removeUniqueValueInfo=function(b){if(this.styleOrigin)f.error("#removeUniqueValueInfo()","Cannot modify unique value infos of a UniqueValueRenderer created from a web style");elsefor(vare=0;e<this.uniqueValueInfos.length;e++)if(this.uniqueValueInfos[e].value===b+""){deletethis._valueInfoMap[b];this.uniqueValueInfos.splice(e,1);break}};a.prototype.getUniqueValueInfo=function(b,e){vara=this.field,c=b.attributes,d;this.valueExpression?d=h.executeFunction(this.compiledFunc,h.createExecContext(b,h.getViewInfo(e))):"function"!==typeofa&&this.field2?(b=this.field2,e=this.field3,d=[],a&&d.push(c[a]),b&&d.push(c[b]),e&&d.push(c[e]),d=d.join(this.fieldDelimiter||"")):"function"===typeofa?d=a(b):a&&(d=c[a]);returnthis._valueInfoMap[d+""]};a.prototype.getSymbol=function(b,a){return(b=this.getUniqueValueInfo(b,a))&&b.symbol||this.defaultSymbol};a.prototype.getSymbols=function(){for(varb=[],a=0,c=this.uniqueValueInfos;a<c.length;a++){vard=c[a];d.symbol&&b.push(d.symbol)}this.defaultSymbol&&b.push(this.defaultSymbol);returnb};a.prototype.clone=function(){varb=newl({field:this.field,field2:this.field2,field3:this.field3,defaultLabel:this.defaultLabel,defaultSymbol:g.clone(this.defaultSymbol),valueExpression:this.valueExpression,valueExpressionTitle:this.valueExpressionTitle,fieldDelimiter:this.fieldDelimiter,visualVariables:g.clone(this.visualVariables),legendOptions:g.clone(this.legendOptions),authoringInfo:this.authoringInfo&&this.authoringInfo.clone()});this._isDefaultSymbolDerived&&(b._isDefaultSymbolDerived=!0);b._set("portal",this.portal);vara=g.clone(this.uniqueValueInfos);this.styleOrigin&&(b._set("styleOrigin",Object.freeze(g.clone(this.styleOrigin))),Object.freeze(a));b._set("uniqueValueInfos",a);b._updateValueInfoMap();returnb};a.prototype.collectRequiredFields=function(b){this.inherited(arguments);[this.field,this.field2,this.field3].forEach(function(a){a&&"string"===typeofa&&(b[a]=!0)});this.valueExpression&&h.extractFieldNames(this.valueExpression).forEach(function(a){b[a]=!0})};a.prototype.populateFromStyle=function(){varb=this;returnB.fetchStyle(this.styleOrigin,{portal:this.portal}).then(function(a){varc=[];b._valueInfoMap={};a&&a.data&&Array.isArray(a.data.items)&&a.data.items.forEach(function(e){vard=newA({styleUrl:a.styleUrl,styleName:a.styleName,portal:b.portal,name:e.name});b.defaultSymbol||e.name!==a.data.defaultItem||(b.defaultSymbol=d,b._isDefaultSymbolDerived=!0);d=newn.default({value:e.name,symbol:d});c.push(d);b._valueInfoMap[e.name]=d});b._set("uniqueValueInfos",Object.freeze(c));!b.defaultSymbol&&b.uniqueValueInfos.length&&(b.defaultSymbol=b.uniqueValueInfos[0].symbol,b._isDefaultSymbolDerived=!0);returnb})};a.prototype._updateValueInfoMap=function(){varb=this;this._valueInfoMap={};this.uniqueValueInfos.forEach(function(a){returnb._valueInfoMap[a.value+""]=a})};a.fromPortalStyle=function(b,a){varc=newl(a&&a.properties);c._set("styleOrigin",Object.freeze({styleName:b}));c._set("portal",a&&a.portal||p.getDefault());a=c.populateFromStyle();a.otherwise(function(a){f.error("#fromPortalStyle('"+b+"'[, ...])","Failed to create unique value renderer from style name",a)});returna};a.fromStyleUrl=function(a,c){c=newl(c&&c.properties);c._set("styleOrigin",Object.freeze({styleUrl:a}));c=c.populateFromStyle();c.otherwise(function(b){f.error("#fromStyleUrl('"+a+"'[, ...])","Failed to create unique value renderer from style URL",b)});returnc};c([d.property()],a.prototype,"type",void0);c([d.writer("type")],a.prototype,"writeType",null);c([d.property({json:{type:String,read:{source:"field1"},write:{target:"field1"}}})],a.prototype,"field",void0);c([d.cast("field")],a.prototype,"castField",null);c([d.writer("field")],a.prototype,"writeField",null);c([d.property({type:String,json:{write:!0}})],a.prototype,"field2",void0);c([d.property({type:String,json:{write:!0}})],a.prototype,"field3",void0);c([d.property({type:String,json:{write:!0}})],a.prototype,"valueExpression",void0);c([d.property({type:String,json:{write:!0}})],a.prototype,"valueExpressionTitle",void0);c([d.property({dependsOn:["valueExpression"]})],a.prototype,"compiledFunc",null);c([d.property({type:D.default,json:{write:!0}})],a.prototype,"legendOptions",void0);c([d.property({type:String,json:{write:!0}})],a.prototype,"defaultLabel",void0);c([d.property({types:r.types})],a.prototype,"defaultSymbol",null);c([d.reader("defaultSymbol")],a.prototype,"readDefaultSymbol",null);c([d.writer("web-scene","defaultSymbol",{defaultSymbol:{types:r.types3D}})],a.prototype,"writeDefaultSymbolWebScene",null);c([d.writer("defaultSymbol")],a.prototype,"writeDefaultSymbol",null);c([d.property({type:String,json:{write:!0}})],a.prototype,"fieldDelimiter",void0);c([d.property({type:p,readOnly:!0})],a.prototype,"portal",void0);c([d.reader("portal",["styleName"])],a.prototype,"readPortal",null);c([d.property({readOnly:!0})],a.prototype,"styleOrigin",void0);c([d.reader("styleOrigin",["styleName","styleUrl"])],a.prototype,"readStyleOrigin",null);c([d.writer("styleOrigin",{styleName:{type:String},styleUrl:{type:String}})],a.prototype,"writeStyleOrigin",null);c([d.property({type:[n.default],json:{write:{overridePolicy:function(){returnthis.styleOrigin?{enabled:!1}:{enabled:!0}}}}})],a.prototype,"uniqueValueInfos",null);c([d.property({dependsOn:["field","field2","field3","valueExpression"],readOnly:!0})],a.prototype,"requiredFields",void0);c([x(1,d.cast(r.ensureType))],a.prototype,"addUniqueValueInfo",null);returna=l=c([d.subclass("esri.renderers.UniqueValueRenderer")],a);varl}(d.declared(C))});