{"version":3,"file":"MapUtilities.mjs","names":["isEqualWith","getLowestLevelObject","obj","options","length","getChildrenObjectsWithNoChildren","arr","valueKey","reduce","result","children","childrenWithNoChildren","push","searchForLayerOptions","data","searchString","i","title","value","titleString","toString","valueString","toLowerCase","includes","childOptions","getLayer","layerKeys","layerKeySeparator","stringValue","forEach","key","index","generateGeoJsonList","mappingConfig","map","item","type","id","featureId","geometry","geometryType","coordinates","properties","propertiesObj","getKeyValuePairs","object","Object","keys","filterObjectKeys","keysToKeep","removeObjects","entries","filter","acc","getSelectedFeaturePropertyKeyValuePairs","featurePropertiesToDisplay","featureProperties","keyVals","filteredObj","isEqualIgnoreFunctions","a","b","val1","val2","undefined","getPrimaryFeatureCoordinate","dig","coords","Array","isArray","first","resolved"],"sources":["../../../../src/UI/mapLayout/utilities/MapUtilities.js"],"sourcesContent":["import {isEqualWith} from 'lodash-es'\n\nexport const getLowestLevelObject = (obj) => {\n  if (!!!obj?.options || obj?.options?.length === 0) {\n    return obj;\n  } else {\n    return getLowestLevelObject(obj.options[0]);\n  }\n};\n\nexport const getChildrenObjectsWithNoChildren = (arr, valueKey) => {\n  if (!!!arr) return [];\n\n  return arr.reduce((result, obj) => {\n    const children = obj?.options ?? [];\n    const childrenWithNoChildren = getChildrenObjectsWithNoChildren(\n      children,\n      valueKey\n    );\n\n    if (childrenWithNoChildren.length > 0) {\n      result.push(...childrenWithNoChildren);\n    } else if (children.length === 0) {\n      result.push(obj[valueKey]);\n    }\n\n    return result;\n  }, []);\n};\n\nexport const searchForLayerOptions = (data, searchString = '') => {\n  let result = [];\n\n  for (let i = 0; i < data?.length; i++) {\n    const obj = data[i];\n    const { title, value, options } = obj;\n    const titleString = typeof title !== 'string' ? title.toString() : title;\n    const valueString = typeof value !== 'string' ? value.toString() : value;\n\n    if (\n      titleString?.toLowerCase()?.includes(searchString?.toLowerCase()) ||\n      valueString?.toLowerCase()?.includes(searchString?.toLowerCase())\n    ) {\n      result.push(obj);\n    } else if (options && options?.length > 0) {\n      const childOptions = searchForLayerOptions(options, searchString);\n      if (childOptions?.length > 0) {\n        result.push({ title, value, options: childOptions });\n      }\n    }\n  }\n\n  return result;\n};\n\nexport const getLayer = (layerKeys, layerKeySeparator, obj) => {\n  let stringValue = '';\n  layerKeys?.forEach((key, index) => {\n    stringValue +=\n      obj[key] + (index !== layerKeys?.length - 1 ? layerKeySeparator : '');\n  });\n\n  return stringValue;\n};\n\nexport const generateGeoJsonList = (data, mappingConfig) => {\n  if (data?.length > 0 && mappingConfig) {\n    return data?.map((item) => {\n      return {\n        type: 'Feature',\n        id: item[mappingConfig.featureId],\n        geometry: {\n          type: item[mappingConfig.geometryType],\n          coordinates: item[mappingConfig.coordinates]\n        },\n        properties:\n          mappingConfig.propertiesObj && !!item[mappingConfig.propertiesObj]\n            ? {\n                ...item[mappingConfig.propertiesObj],\n                id: item[mappingConfig.featureId]\n              }\n            : {\n                ...item,\n                id: item[mappingConfig.featureId]\n              }\n      };\n    });\n  }\n\n  return [];\n};\n\nexport function getKeyValuePairs(object) {\n  return Object.keys(object).map((key) => {\n    return { key: key, value: object[key] };\n  });\n}\n\nexport function filterObjectKeys(\n  object,\n  keysToKeep,\n  removeObjects = false\n) {\n  if (removeObjects) {\n    return Object.entries(object)\n      .filter(\n        ([key, value]) => typeof value !== 'object' && keysToKeep.includes(key)\n      )\n      .reduce((acc, [key, value]) => {\n        acc[key] = value ? value : '-';\n        return acc;\n      }, {});\n  }\n  return Object.entries(object)\n    .filter(([key]) => keysToKeep.includes(key))\n    .reduce((acc, [key, value]) => {\n      acc[key] = value ? value : '-';\n      return acc;\n    }, {});\n}\n\nexport function getSelectedFeaturePropertyKeyValuePairs(featurePropertiesToDisplay=[], featureProperties){\n  let keyVals = []\n  if(featureProperties){\n   if(featurePropertiesToDisplay){\n     const filteredObj = filterObjectKeys(featureProperties, featurePropertiesToDisplay, true)\n     keyVals = filteredObj ? getKeyValuePairs(filteredObj) : []\n   }\n   else{\n     keyVals = featureProperties ? getKeyValuePairs(featureProperties) : []\n   }\n  }\n  return keyVals;\n}\n\nexport const isEqualIgnoreFunctions = (a, b) =>\n  isEqualWith(a, b, (val1, val2) => {\n    if (typeof val1 === 'function' && typeof val2 === 'function') {\n      return true; // ignore function differences\n    }\n    // fall back to default comparison\n    return undefined;\n  });\n\n  export const getPrimaryFeatureCoordinate = (geometry) => {\n    if (!geometry?.coordinates) {\n      return [0,0];\n    }\n\n    const dig = (coords) => {\n      if (!Array.isArray(coords)) {\n        return coords;\n      }\n\n      if (coords.length === 0) {\n        return coords;\n      }\n\n      const first = coords[0];\n\n      if (!Array.isArray(first)) {\n        return coords;\n      }\n\n      return dig(first);\n    };\n\n    const resolved = dig(geometry.coordinates);\n\n    return Array.isArray(resolved) ? resolved : [0,0];\n  };\n"],"mappings":";;AAUA,MAAaK,oCAAoCC,KAAKC,aAAa;AACjE,KAAI,CAAC,CAAC,CAACD,IAAK,QAAO,EAAE;AAErB,QAAOA,IAAIE,QAAQC,QAAQP,QAAQ;EACjC,MAAMQ,WAAWR,KAAKC,WAAW,EAAE;EACnC,MAAMQ,yBAAyBN,iCAC7BK,UACAH,SACD;AAED,MAAII,uBAAuBP,SAAS,EAClCK,QAAOG,KAAK,GAAGD,uBAAuB;WAC7BD,SAASN,WAAW,EAC7BK,QAAOG,KAAKV,IAAIK,UAAU;AAG5B,SAAOE;IACN,EAAE,CAAC;;AA4BR,MAAagB,YAAYC,WAAWC,mBAAmBzB,QAAQ;CAC7D,IAAI0B,cAAc;AAClBF,YAAWG,SAASC,KAAKC,UAAU;AACjCH,iBACE1B,IAAI4B,QAAQC,UAAUL,WAAWtB,SAAS,IAAIuB,oBAAoB;GACpE;AAEF,QAAOC;;AAGT,MAAaI,uBAAuBlB,MAAMmB,kBAAkB;AAC1D,KAAInB,MAAMV,SAAS,KAAK6B,cACtB,QAAOnB,MAAMoB,KAAKC,SAAS;AACzB,SAAO;GACLC,MAAM;GACNC,IAAIF,KAAKF,cAAcK;GACvBC,UAAU;IACRH,MAAM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