/* COPYRIGHT Esri - https://js.arcgis.com/5.1.2/LICENSE.txt */
import e from"../../../Color.js";import{clone as o}from"../../../core/lang.js";import{px2pt as t}from"../../../core/screenUtils.js";import r from"../../../symbols/CIMSymbol.js";const i="spike-height-override",l=t(8),n=t(20),a="triangle-solid-fill-open-outline";function s(e){const{field:o,normalizationField:t,sizeStops:r}=e,{value:l,size:n}=r[0],{value:a,size:s}=r[1];let c,f=0;o&&(f=`$feature["${o}"]`,c=`\n      if(!HasValue($feature, "${o}")){\n        return 0;\n      }\n      $feature["${o}"];\n    `),t&&(f=`$feature["${o}"] / $feature["${t}"]`,c=`if(!HasValue($feature, "${o}") || !HasValue($feature, "${t}") || $feature["${t}"] <= 0){\n        return 0;\n      }\n      $feature["${o}"];\n      $feature["${t}"];`);return[{type:"CIMPrimitiveOverride",primitiveName:i,propertyName:"Length",valueExpressionInfo:{type:"CIMExpressionInfo",title:"Custom",expression:`\n        ${c}\n        var value = ${f};\n\n        var maxSize = ${s};\n        var minSize = ${n};\n\n        var minDataValue = ${l};\n        var maxDataValue = ${a};\n\n        var ratio = Constrain(( value - minDataValue ) / ( maxDataValue - minDataValue ), 0, 1);\n\n        var size = Constrain(maxSize * ratio, minSize, maxSize);\n        return size;\n      `,returnType:"Default"}}]}function c(e){const{primitiveOverrides:o,baseWidth:t,defaultHeight:a}=e,s=f(e);return new r({data:{type:"CIMSymbolReference",symbol:{type:"CIMPointSymbol",effects:[{type:"CIMGeometricEffectRadial",primitiveName:i,angle:90,length:a??n},{type:"CIMGeometricEffectTaperedPolygon",fromWidth:t??l,toWidth:1,length:5}],symbolLayers:s,haloSize:1,scaleX:1,angleAlignment:"Display"},primitiveOverrides:o}})}function f(e){const o=[u(e)],t=m(e);return t&&o.push(t),o}function u(e){const{strokeColor:o,strokeWidth:r,symbolStyle:i}=e,l=i?.includes("solid-fill")||i?.includes("gradient-fill");let n=o?.toArray(),a=!1;return i?.includes("outline")&&l?a=!0:n=e.color?.toArray(),{type:"CIMSolidStroke",effects:p(i),enable:!0,colorLocked:a,capStyle:"Round",joinStyle:"Round",lineStyle3D:"Strip",miterLimit:4,width:r??t(1),color:n}}function p(e){if(!e?.includes("closed"))return[{type:"CIMGeometricEffectAddControlPoints",angleTolerance:90,primitiveName:"spike-control-points"},{type:"CIMGeometricEffectSuppress",suppress:!0,invert:!0,primitiveName:"spike-stroke-suppress"}]}function m(e){const{color:o,symbolStyle:t}=e,r=t?.includes("solid-fill"),i=t?.includes("gradient-fill");if(!r&&!i||!o)return;if(r)return{type:"CIMSolidFill",enable:!0,colorLocked:!1,color:o?.toArray()};const l=o.clone();return l.a=0,{type:"CIMGradientFill",enable:!0,angle:90,colorRamp:{type:"CIMMultipartColorRamp",colorRamps:[{type:"CIMLinearContinuousColorRamp",fromColor:o.toArray(),toColor:l.toArray()}],weights:[1]},gradientMethod:"Linear",gradientSize:70,gradientSizeUnits:"Relative",gradientType:"Continuous"}}function d(t,r){const{defaultHeight:l,baseWidth:n,color:a,strokeColor:s,primitiveOverrides:c,symbolStyle:f,strokeWidth:p}=r,d="CIMPointSymbol"===t.data.symbol?.type?t.data.symbol:null,C=d?.symbolLayers;if(!C)return t;const v=d.effects,S=v?.find(e=>"CIMGeometricEffectTaperedPolygon"===e.type),$=v?.find(e=>"CIMGeometricEffectRadial"===e.type&&e.primitiveName===i);null!=n&&S&&(S.fromWidth=n),null!=l&&$&&($.length=l);const h=C?.find(e=>"CIMSolidStroke"===e.type),M=C?.find(e=>"CIMSolidFill"===e.type),g=C?.find(e=>"CIMGradientFill"===e.type),I="CIMMultipartColorRamp"===g?.colorRamp?.type&&"CIMLinearContinuousColorRamp"===g.colorRamp.colorRamps[0]?.type?g.colorRamp.colorRamps[0]:null;if(f){const o=M?.color??I?.fromColor??h?.color,t=a??(o?new e(o):void 0),i=h?.color??o,l=s??(i?new e(i):void 0),n=f.includes("solid-fill"),c=f.includes("gradient-fill");if(n||c||y(C,M??g),t)if(n)y(C,g),M?M.color=t?.toArray():C.push(m({...r,color:t}));else if(c)if(y(C,M),g){if(I&&a){const e=t.clone();e.a=0,I.fromColor=t.toArray(),I.toColor=e.toArray()}}else C.push(m({...r,color:t}));if(h){const e=u({...r,strokeColor:l,color:t});h.effects=e.effects,h.color=e.color,h.width=e.width,h.colorLocked=e.colorLocked}}else if(h&&(s&&(h.color=s.toArray()),null!=p&&(h.width=p)),M&&a&&(M.color=a.toArray()),I&&a){const e=a.clone();e.a=0,I.fromColor=a.toArray(),I.toColor=e.toArray()}return void 0!==c&&(t.data.primitiveOverrides=o(c)),t}function y(e,o){if(!o)return;const t=e.indexOf(o);-1!==t&&e.splice(t,1)}export{s as createPrimitiveOverrides,c as createSpikeSymbol,a as defaultSpikeSymbolStyle,d as updateSpikeSymbol};
