import olMap from 'ol/Map.js';
import { transform } from 'ol/proj';
import { transformExtent } from 'ol/proj';
import View from 'ol/View';
import ScaleBar from 'ol/control/ScaleLine';

const createResourceGroup = (items) => {
   let resourceGroups = [];

   for (let i = 0; i < items.length; i++) {
      let id = items[i].resource_group_id;
      
      if(id) {
         let group = {
            groupId: id,
            groupDescription: items[i]["group description"],
            groupName: items[i]["group name"],
            groupSort: items[i]["group_sort"],
         }
         resourceGroups.push(group);
      }
   }
   
   let filteredArr = resourceGroups.reduce((acc, current) => {
      const x = acc.find(item => item.groupId === current.groupId);
      if (!x) {
        return acc.concat([current]);
      } else {
        return acc;
      }
    }, []);
   
   filteredArr.sort((a,b) => a.groupSort - b.groupSort);
   
   return filteredArr;
}

export { createResourceGroup };