const formatArcgisrest = function (attributes) {
  for (const [key, value] of Object.entries(attributes)) {
    const result =
      String(value).includes("https:") || String(value).includes("http:")
        ? value
        : null;

    if (result) {
      attributes[key] = `<a href="${value}" target="_new" > ${value} </a>`;
    }
  }
  return attributes;
};

const formatArcgisVector = function (results) {
  results.map((feat) => {
    for (const [key, value] of Object.entries(feat.properties)) {
      const result =
        String(value).includes("https:") || String(value).includes("http:")
          ? value
          : null;

      if (result) {
        feat.properties[
          key
        ] = `<a href="${value}" target="_new" > ${value} </a>`;
      }
    }
  });
  return results;
};

const identifyColumnsArcgisrest = function (data, excludedColumns) {
  data.results.forEach((result) => {
    if(result.attributes){
        excludedColumns.forEach((column) => {
          delete result.attributes[column];
        });  
    }
    return result.attributes
  });
  return data;
};

const identifyColumnsArcgisvector = function (data, excludedColumns) {
  data.forEach((feature) => {
    if(feature.properties){
        excludedColumns.forEach((column) => {
          delete feature.properties[column];
        });
    }
      return feature.properties
  });
  
  return data;
};


export { formatArcgisVector, formatArcgisrest, identifyColumnsArcgisrest, identifyColumnsArcgisvector };
