import DATA from './auth.json';

export const getData = function () {
  const myMap1 = new Map();
  const myMap2 = new Map();
  const rowData = DATA.map((item: any) => {
    const data = item.i18n;

    // Map1
    const nameArr1 = item.name.split('/');
    const key1 = nameArr1[0] + '/' + nameArr1[1];
    const title1 = data['zh-TW'].split('/');
    const origin1 = data['en-US'].split('/');
    const type1 = data['zh-CN'].split('/');
    const obj1 = {
      title: title1[1],
      origin: origin1[1],
      type: [type1[0], type1[1]],
    };

    if (!myMap1.has(key1)) {
      myMap1.set(key1, obj1);
    }

    // Map2
    const key2 = nameArr1[0];
    const obj2 = {
      title: title1[0],
      origin: origin1[0],
      type: [type1[0]],
    };

    if (!myMap2.has(key2)) {
      myMap1.set(key2, obj2);
    }

    return {
      title: data['zh-TW'].split('/')[2],
      origin: data['en-US'].split('/')[2],
      type: data['zh-CN'].split('/'),
    };
  });

  for (const value of myMap1.values()) {
    rowData.push(value);
  }
  for (const value of myMap2.values()) {
    rowData.push(value);
  }
  return rowData;
  //   const rowData = [
  //     {
  //       title: '系統設置',
  //       origin: 'System Setting',
  //       type: ['系统设置'],
  //     },
  //     {
  //       title: '用戶管理',
  //       origin: 'User Management',
  //       type: ['系统设置', '用户管理'],
  //     },
  //     {
  //       title: '查看',
  //       origin: 'Read',
  //       type: ['系统设置', '用户管理', '查看'],
  //     },
  //     {
  //       title: '新建',
  //       origin: 'Create',
  //       type: ['系统设置', '用户管理', '新建'],
  //     },
  //   ];
};