// All material copyright ESRI, All Rights Reserved, unless otherwise specified.
// See http://js.arcgis.com/3.23/esri/copyright.txt for details.
//>>built
define("esri/dijit/geoenrichment/ReportPlayer/core/conversion/portalToEditorUtils/parsers/FieldParser","esri/dijit/geoenrichment/utils/JsonXmlConverter ../../../supportClasses/templateJsonUtils/fieldInfo/RichTextJsonUtil ../../../supportClasses/templateJsonUtils/fieldInfo/FieldInfoBuilder ../../ConversionUtil ../../ShapeConverter ../../../annotations/shape/ShapeJsonUtil ./_FieldInfoBuilder ./ImageParser ./AlignParser ../../../../_devConfig".split(" "),function(r,w,g,m,t,x,n,u,y,z){function p(a){(a=
a.attributes||{},!a.m)&&(a.decimals||a.symbol||a.thousands)&&(a.m={showCurrency:"currency"===a.symbol,showPercent:"percent"===a.symbol,useThousandsSeparator:!1!==a.thousands,decimals:Number(a.decimals)||0});return a}function v(a){return r.queryJson(a,/^d$|^text$|^reportName$|^reportTitle2/)}var h={},q={parseImageTrigger:function(a,b){var c=n.getCalculatorOrScriptFieldInfo(a.attributes.field,b);if(!c)return console.log("Parse template error \x3d\x3e can't build fieldInfo for field "+a.attributes.field),
console.log(a),null;var d={fieldInfo:c,cases:[]},e=this;a.tags.forEach(function(a){var c="case"===a.name?a.attributes.key:"default";a=a.tags[0];var f=b.processFileName(a.attributes.value);d.cases.push({compareInfos:e._getCompareInfosFromTriggerKey(c),setters:[{property:a.attributes.property,value:f}]});b.putImageData(f)});return d},parseFieldTrigger:function(a,b,c){b.triggerJson={fieldInfo:c&&n.getCalculatorOrScriptFieldInfo(a.attributes.field,c),cases:[]};var d=this;a.tags.forEach(function(a){var c=
{compareInfos:d._getCompareInfosFromTriggerKey("case"===a.name?a.attributes.key:"default"),setters:[]};b.triggerJson.cases.push(c);a.tags.forEach(function(a){c.setters.push({property:a.attributes.property,value:a.attributes.value})})})},_getCompareInfosFromTriggerKey:function(a){return a.split(m.KEY_INTERVAL_SEPARATOR).map(function(a){var b=m.ONE_FIELD_KEY_TEST.test(a)?a.replace(m.KEY_OPERATOR_RE,""):a;a=a.substr(0,a.length-b.length)||"\x3d";return{value:b,operator:a}})}},A={getFieldInfo:function(a,
b,c,d){return(a=d.parsers.getParser("chart").portalToEditor(a,b,d))&&g.createFieldInfoFromChart(a)}},B={getFieldInfo:function(a,b,c,d){return(a=d.parsers.getParser("infographic").portalToEditor(a,b,d))&&g.createFieldInfoFromInfographic(a)}},C={getFieldInfo:function(a,b,c,d){b=u.getElement(a,d);var e;a.tags&&a.tags[0]&&"trigger"===a.tags[0].name&&(e=q.parseImageTrigger(a.tags[0],d));return g.createFieldInfoFromImage(b,e)}},D={getFieldInfo:function(a,b,c,d){b=t.svgJsonToShapeObject(a);c=t.getStylesFromSvgJson(a);
b=x.createShapeJsonFromShapeObj(b,c);a=a.attributes;b.style.angle=Number(a.angle)||0;y.parseAlign(a,b.style);return g.createFieldInfoFromShape(b)}},E={getFieldInfo:function(a,b,c,d){a=d.parsers.getParser("section").parseSection(a,d);return g.createFieldInfoFromSection(a)}},l={getFieldInfo:function(a,b,c,d,e){a=p(a);b=b||a.f;if(e.templateJson.metadata.mapImageInfosHash[b])return b=u.parseMapImageDField(b,e),g.createFieldInfoFromImage(b);var f=g.createFieldInfoFromSpecialFieldName(b,a.m);if(!f){var h;
2===c.tags.length&&"#text"===c.tags[1].name&&(h=c.tags[1].text);f=n.getCalculatorOrScriptFieldInfo(b,e,{format:a.m,additionalText:h})}f&&d&&(q.parseFieldTrigger(d,f,e),f.triggerJson&&!f.triggerJson.fieldInfo&&(f.triggerJson.fieldInfo=null,console.log("Parse template error \x3d\x3e can't build fieldInfo for field "+d.attributes.field),console.log(d)));return f}};h.parseField=function(a,b,c,d){var e;if(z.emulateErrors.layoutParseError)throw Error("Error test: something crashed during the parsing of the layout!");
if(a){if("chart"===a.name)return A.getFieldInfo(a,b,c,d);if("infographic"===a.name)return B.getFieldInfo(a,b,c,d);if(("img"===a.name||"mapImage"===a.name)&&a.attributes)return C.getFieldInfo(a,b,c,d);if("svg"===a.name)return D.getFieldInfo(a,b,c,d);if("section"===a.name)return E.getFieldInfo(a,b,c,d);if("d"===a.name)e=l.getFieldInfo(a,null,b,c,d);else if("a"===a.name&&a.tags&&"d"===a.tags[0].name){var f=a.tags[0];(e=l.getFieldInfo(f,null,b,c,d))&&a.attributes&&a.attributes.hreff&&(e.linkFieldInfo=
l.getFieldInfo(f,a.attributes.hreff,b,c,d))}else e="text"===a.name?g.createFieldInfoFromSpecialFieldName(p(a).name):g.createFieldInfoFromSpecialFieldName(a.name,p(a).m)}if(!e){a=v(b);if(1===a.length&&a[0].attributes&&"TrialUrlText"===a[0].attributes.name)return g.createFieldInfoFromSpecialFieldName(a[0].attributes.name);e=h.parseRichTextTag(b,d)}return e};h.parseRichTextTag=function(a,b){var c,d=v(a);if(d.length){var e=[],f=[],h=!0;d.some(function(c,d){var k=c.attributes?c.attributes.name:c.name,
k="d"===c.name?l.getFieldInfo(c,null,a,null,b):k&&g.createFieldInfoFromSpecialFieldName(k);if(!k)return h=!1,!0;"d"===c.name?e.push(k):f.push(k)});h&&(c=w.createFieldInfoFromRichText(r.getInnerHTML(a),e,f))}return c};h.parseFieldTrigger=function(a,b,c){b=b||{};q.parseFieldTrigger(a,b,c);return b.triggerJson};return h});