// export const lineAndBar = `
// const obj = {
//     dimensions: ['product', 'data1'],
//     source:[]
//   }
//   if(res.type === 'bar' || res.type === 'line'){
//         res.data.forEach((item,index) => {
//             obj.source.push({
//                 product: res.xData[index] ,
//                 data1: item,
//             })
//         });
//   }else if(res.type === 'pie'){
//     res.data.forEach((item)=>{
//         obj.source.push({
//             product:item.name,
//             data1:item.value,
//         })
//     })
//   }

// return obj `

const lineAndBar = `
  const obj = {
        dimensions: ['product', '数据'],
        source:[]
    }
    res.data.forEach((item,index) => {
            obj.source.push({
                product: res.xData[index] ,
                数据: item,
            })
        });
    return obj`

const pie = `
     const obj = {
        dimensions: ['product', '数据'],
        source:[]
    }
        res.data.forEach((item)=>{
                obj.source.push({
                    product:item.name,
                    数据:item.value,
                })
            })
    return obj
    `

const TableList = `

    let list = []

    if(res.data.length <= 0) return list

    const lableList = res.data[0].list
    const valueList = res.data[1].list

    lableList.forEach((item,index)=>{
             list.push({
                name:item,
                value:valueList[index]
            })
        })
     console.log(list,'过滤')      
    return list
`
const TablesBasic = `

    const dimensions = [];
    const source = [];

    // 生成 dimensions
    data.forEach((item, index) => {
        dimensions.push({
            title: item.column.trim(),
            key: "key" + (index+1),
            align: "center"
        });
    });

    // 生成 source
    const maxLength = Math.max(...data.map(item => item.list.length));
    for (let i = 0; i < maxLength; i++) {
        const row = { key: i };
        data.forEach((item, index) => {
            row["key" + (index+1)] = item.list[i] || null;
        });
        source.push(row);
    }

    return {
        dimensions,
        source
    };

`

const filterData = {
  LineCommon: lineAndBar,
  LineLinearSingle: lineAndBar,
  BarCommon: lineAndBar,
  BarCrossrange: lineAndBar,
  PieCommon: pie,
  PieCircle: 'return  res.data',
  Dial: 'return  res.data',
  TableList: TableList,
  TablesBasic: TablesBasic
}

export { filterData }
