const tableResult = ChartEditor.getLoadedData().lunapark_api;
const params = ChartEditor.getParams()


/*tableResult = {
  "quantiles":["50%","75%","80%","85%","90%","95%","98%","99%"],
  "cases": {"overall":[80.0,83.0,84.0,86.0,147.0,484.0,1380.0,2150.0], "case1":[80.0,83.0,84.0,86.0,147.0,484.0,1380.0,2150.0], "case2":[80.0,83.0,84.0,86.0,147.0,484.0,1380.0,2150.0]}
};*/

//console.log('data', tableResult)

const head = [
    {
        id: 'case',
        name: 'Кейс',
        type: 'text',
        css: {
            'font-weight': 'bold'
        }
    }
]
tableResult.quantiles.forEach((q) => {
    head.push({
        id: q,
        name: q,
        type: 'text',
    });
})

const rows = [{cells:[
            {
                value: 'Весь тест',
                css: { 
                    'font-weight': 600,
                }
            }
]}]

tableResult.cases.overall.forEach((value) => {
    rows[0].cells.push(
            {
                value: value
            }
    );
});


Object.keys(tableResult.cases).forEach((c) => {
    if (c != "overall") {
        //case cell
        rows.push({
            cells:[
            {
                value: c,
                css: { 
                    'font-weight': 600,
                }
            }]
        });
        tableResult.cases[c].forEach((value) => {
            rows[rows.length - 1].cells.push(
               {
                    value: value
                }
            )
        })
    }
});

module.exports = {head, rows};

