import { useStore } from "@/store/index.js";
const userstore = useStore();
export function provincialUrbanAreas() {
    let aa = userstore.returnCode(11);
    for (let i = 0; i < aa.length; i++) {
        if (aa[i].code.substring(2, 6) == '0000') {
            aa[i]['parentCode'] = ''
        } 
        if (aa[i].code.substring(4, 6) == '00'&&aa[i].code.substring(2, 4) != '00') {
            aa[i]['parentCode'] = aa[i].code.substring(0, 2) + '0000';
        } else if (aa[i].code.substring(4, 6) != '00') {
            aa[i]['parentCode'] = aa[i].code.substring(0, 4) + '00';
        }
    }
    return recursionDataTree(aa);
}
function recursionDataTree(menu) {
    let result = [];
    menu.forEach(item => {
      delete item.children;
    });

    let map = {};
    menu.forEach(item => {
      map[item.code] = item;
    });

    menu.forEach(item => {
      let parent = map[item.parentCode];
      if (parent) {
        (parent.children || (parent.children = [])).push(item);
      } else {
        result.push(item);
      }
    });
    return result;
}
