function getSeries({ children, keys, values, title }) {
  let data = [
    {
      name: title,
      //   itemStyle: {
      //     color: 'red',
      //   },
      children: [],
    },
  ]
  let series = {
    type: 'sunburst',
    radius: [0, '100%'],
    label: {
      rotate: 'radial',
    },
    levels: [
      {},
      {
        itemStyle: {
          color: '#FDF5EF',
        },
      },
      {
        itemStyle: {
          color: '#0E7BFC',
        },
      },
      {
        itemStyle: {
          color: '#D1E7FE',
        },
      },
    ],
  }

  data[0]['children'] = children.map(item => {
    return {
      name: item,
      value: 1,
      children: [],
    }
  })

  let totalValue = 0

  data[0]['children'] = data[0]['children'].map(item => {
    let childrenOPtions = []
    const name = item['name']
    let value = 0
    keys[name].map(el => {
      value = value + values[el]
      totalValue = totalValue + values[el]
      const obj = {
        name: el,
        value: values[el] || 0,
        label: {
          formatter: '{b}: {@score}',
          align: 'left',
        },
      }
      childrenOPtions.push(obj)
    })
    // console.log(childrenOPtions)
    if (value === 0) {
      value = totalValue * 0.2
    }
    return {
      ...item,
      value,
      children: childrenOPtions,
    }
  })

  console.log(data)

  series['data'] = data

  return series
}

export const sunburst = (keys, values, settings, extra) => {
  const children = Object.keys(keys)

  const title = settings['title'] || ''

  console.log(children, title)

  const series = getSeries({
    children,
    keys,
    values,
    title,
  })

  const options = {
    series,
  }

  return options
}
