import { FILTER_FOLER_REG } from './constants';

let timestamp = new Date().getTime();

export const guid = function(prefix) {
  prefix = prefix || '';
  return prefix + (timestamp++).toString(36);
};
// web5 web4路由菜单生成

//重写菜单生成, web4和web5分开

const generRotes = data => {
  let ret = [];
  data.forEach(item => {
    if (item.hasOwnProperty('widgets')) {
      ret.push({
        name: item.label,
        path: `/civweb/${guid('web_console')}`,
        component: 'BasicLayout',
        routes: generRotes(item.widgets),
        extData: { ...item },
      });
    } else {
      const baseURL = FILTER_FOLER_REG.test(item.url) ? 'civweb4' : 'civweb5';
      ret.push({
        name: item.label,
        component: 'BasicLayout',
        path: item.hasOwnProperty('url')
          ? `/${baseURL}/${item.url.replace(/\s*/g,"")}`
          : guid('web_console'),
        extData: { ...item },
      });
    }
  });
  return ret;
};

export default generRotes;
