function getSeries({ children, keys, values, title }) {
  let data = [
    {
      title,
      //   itemStyle: {
      //     color: 'red',
      //   },
      level: 1,
      label: {
        rotate: 'tangential',
      },

      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,
      label: {
        rotate: 'tangential',
      },
      children: [],
    }
  })

  //   console.log(data[0]['children'])

  let totalValue = 0

  data[0]['children'] = data[0]['children'].map(item => {
    let childrenOPtions = []
    //决定tooltip的文本显示///1:该大区有数据///0:该大区暂无数据
    let info = 0
    const name = item['name']
    let value = 0
    if (keys[name].length > 0) {
      info = 1
      keys[name].map(el => {
        value = value + values[el]
        totalValue = totalValue + values[el]
        const obj = {
          name: el,
          value: values[el] || 0,
          label: {
            rotate: 'tangential',
          },
        }
        childrenOPtions.push(obj)
      })
    } else {
      childrenOPtions = []
      info = 0
    }

    // console.log(childrenOPtions)
    if (value === 0) {
      value = totalValue * 0.2
    }
    return {
      ...item,
      value,
      children: childrenOPtions,
      info,
    }
  })

  //   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 tooltip = {
    trigger: 'item',
    formatter: params => {
      let dataStr = ''
      //   console.log(params)
      if (params['data']['info'] == '0') {
        dataStr = '暂未接入'
      } else if (params['data']['level'] === 1) {
        dataStr = params['data']['title']
      } else if (!params['dataType']) {
        dataStr = ''
      } else {
        dataStr = `客流数:${params['value']}`
      }
      return dataStr
    },
  }

  const options = {
    series,
    tooltip,
  }

  return options
}
