text: // COPYRIGHT © 2021 Esri
  //
  // All rights reserved under the copyright laws of the United States
  // and applicable international laws, treaties, and conventions.
  //
  // This material is licensed for use under the Esri Master License
  // Agreement (MLA), and is bound by the terms of that agreement.
  // You may redistribute and use this code without modification,
  // provided you adhere to the terms of the MLA and include this
  // copyright notice.
  //
  // See use restrictions at http://www.esri.com/legal/pdfs/mla_e204_e300/english
  //
  // For additional information, contact:
  // Environmental Systems Research Institute, Inc.
  // Attn: Contracts and Legal Services Department
  // 380 New York Street
  // Redlands, California, USA 92373
  // USA
  //
  // email: contracts@esri.com
  //
  // See http://js.arcgis.com/3.37/esri/copyright.txt for details.
  
  define(["esri/units","esri/dijit/geoenrichment/utils/FieldUtil","esri/dijit/geoenrichment/utils/JsonXmlConverter","../../data/AreaDataUtil","../../../../core/supportClasses/DocumentOptions","./AttrUtil","esri/dijit/geoenrichment/ReportPlayer/config","esri/dijit/geoenrichment/ReportPlayer/_devConfig"],(function(t,e,a,r,n,i,s,u){function o(t){return t.innerHTML?t.innerHTML:t.tags&&t.tags.length&&t.tags[0].text||""}var l=function(t){var e={};return t.tags.forEach((function(t){"xs:element"===t.name&&t.attributes&&"ReportData"===t.attributes.name&&a.queryJson(t,"xs:element").filter((function(t){return!!t.tags})).forEach((function(t){var r=e[t.attributes.name]={};a.queryJson(t,"xs:element").forEach((function(t){r[t.attributes.name]={type:"xs:string"===t.attributes.type?"string":"number",alias:t.attributes["msdata:Caption"]||"",vintage:t.attributes["msdata:Vintage"]||"",source:t.attributes["msdata:Source"]||""}}))}))})),e};return{parse:function(t,e){return this._parseDataXmlJson(a.parseXml(t,{saveInnerHTML:!0}),e)},_parseDataXmlJson:function(a,m){return!a||!a.tags||a.tags.length<2?[]:(a.tags.forEach((function(a){if("ReportInfo"===a.name)c=function(e){var a={Title:null,Subtitle:null,country:null,hierarchyId:null,exportSettings:null};e.tags&&e.tags.forEach((function(e){if("ReportTitle"===e.name&&(a.Title=o(e)),"ReportTitle2"===e.name&&(a.Subtitle=o(e)),"CurrencyFormat"===e.name){var r=o(e),i=r.split(";")[0].replace("0","").trim();a.country={id:null,currencySymbol:i,currencyFormat:r}}else if("ReportLayout"===e.name){var s=a.exportSettings={};e.tags&&e.tags.forEach((function(e){if("Options"===e.name&&e.attributes)s.addHeader=!!e.attributes.header,s.addDataSource=!!e.attributes.dataSource,s.addFooter=!!e.attributes.footer;else if("Page"===e.name&&e.attributes){s.pageSettings={};var a=e.attributes;if(a.width&&a.height&&a.units){var r=Number(a.width),i=Number(a.height),u=a.units===t.MILLIMETERS?"mm":a.units===t.CENTIMETERS?"cm":a.units===t.INCHES?"in":a.units===t.POINTS?"pt":null;u&&(s.pageSettings.pagesize=n.combineCustomSizeString(r,i,u))}else a.size&&a.orientation&&(s.pageSettings.pagesize=a.size.toLowerCase(),s.pageSettings.orientation=a.orientation.toLowerCase())}}))}})),a.exportSettings&&a.Subtitle&&(a.exportSettings.reportSubtitle=a.Subtitle);return a}(a);else if("ReportArea"===a.name)g=function(t){var a={areaIdToAttachmentsInfo:{},stdLevels:null,countrId:null};return t.tags&&t.tags.forEach((function(t){"StudyAreas"===t.name?function(t){t.tags&&t.tags.forEach((function(t){var r=t.attributes.AREA_ID,n=a.areaIdToAttachmentsInfo[r];n||(n={attributes:null,notes:null,images:null},a.areaIdToAttachmentsInfo[r]=n),t.tags&&t.tags.forEach((function(t){"Attributes"===t.name&&t.tags&&(n.attributes=t.tags.map((function(t){return{name:t.attributes.Name,alias:t.attributes.Alias,type:t.attributes.Type,value:e.isNumericField(t.attributes.Type)?Number(t.attributes.Value):t.attributes.Value}}))),"Notes"===t.name&&t.tags&&(n.notes=t.tags&&t.tags.map((function(t){return{text:t.attributes.Text}}))),"Images"===t.name&&t.tags&&(n.images=t.tags&&t.tags.map((function(t){return{url:t.attributes.Source,thumbnail:t.attributes.Thumbnail,description:t.attributes.Description,imageViewType:null}})))}))}))}(t):"StandardGeographyLevels"===t.name&&function(t){var e;a.stdLevels=t.tags&&t.tags.map((function(t,a){return e=e||t.attributes.Id.substr(0,t.attributes.Id.indexOf(".")),{id:t.attributes.Id,name:t.attributes.Caption,isWholeCountry:t.attributes.IsWholeCountry||0===a}})),"US"===e&&(a.countrId="US");"CAN"===e&&(a.countrId="CA")}(t)})),a}(a);else if("ReportData"===a.name){var p=function(t,e){var a,n=[],m={},c=0;return t.tags[0].tags.forEach((function(t){"xs:schema"!==t.name?function(t){var l=function(t){var r,n,l,g,f={};return t.tags.forEach((function(i){var s=o(i),m=s,c=a[t.name][i.name];"string"===(c&&c.type)?s=String(s):(s=Number(s),isNaN(s)&&(s=m),u.emulateErrors.createReportNaN&&(s=NaN),u.emulateErrors.createReportNull&&(s=null)),e&&(s=e(i.name,s,t.name)),void 0===f[i.name]&&(f[i.name]=s),"AREA_ID"===i.name&&(r=s),"IDFNDFIELD"===i.name&&(n=s),"STORE_ID"===i.name&&(l=s)})),(r=r||n)||l?(!r&&l&&(g=Number(l)),r&&void 0===m[r]&&(m[r]=c++),i.cleanUpAttrs(f,s.isPlayerOnServer?{STORE_ID:1,AREA_ID:1}:null),{name:t.name,attrs:f,areaIndex:void 0!==g?g:m[r]}):null}(t);if(!l)return;var g=n[l.areaIndex]=n[l.areaIndex]||{};g[l.name]?g[l.name].comparisonLevels.push(l.attrs):g[l.name]=r.createCalculator(l.attrs)}(t):a=l(t)})),{areaData:n,schemaParseResult:a}}(a,m);d=p.areaData,f=p.schemaParseResult}})),u.logData&&(console.log("DataXMLPareser.js => areaData:"),console.log(d)),g&&(c.country.id=g.countrId,c.areaIdToAttachmentsInfo=g.areaIdToAttachmentsInfo,c.stdLevels=g.stdLevels),c.variables=f,{reportInfo:c,areaData:d});var c,g,f,d}}}));