import { echartOptionProfixHandle, PublicConfigClass } from '@/packages/public'
import { HuoQingDetailPieConfig } from './index'
import { chartInitConfig } from '@/settings/designSetting'
import { CreateComponentType } from '@/packages/index.d'
import cloneDeep from 'lodash/cloneDeep'
import dataJson from './data.json'

export const includes = ['legend']

const { dimensions, source } = dataJson;

const option = {
  type: 'ring',
  tooltip: {
    show: false,
    trigger: 'item'
  },
  legend: {
    show: false
  },
  series: [
    {
      type: 'pie',
      radius: ['60%', '75%'],
      center: ['50%', '50%'],
      roseType: false,
      avoidLabelOverlap: false,
      itemStyle: {
        show: true,
        borderRadius: 0,
        borderColor: '#ffffff',
        borderWidth: 0,
      },
      label: {
        show: false,
        position: 'center',
        formatter: function (params) {
          return `${params.value.product}\n${params.value.data}`;
        },
        fontWeight: 'normal',
        fontSize: 5,
        color: '#ffffff',
        textBorderColor: '#ffffff',
        textBorderWidth: 1
      },
      emphasis: {
        label: {
          show: true,
          fontSize: '20',
          fontWeight: 'bold'
        }
      },
      labelLine: {
        show: false
      }
    }
  ],
  dimensions: dimensions,
  dataset: source,
  dataStyle: {
    sumSpanColor1: '#ffffff',
    sumSpanFontSize1: 25,
    sumSpanColor2: '#ffffff',
    sumSpanFontSize2: 16,

    listMarginLeft: 20,
    liMarginBottom : 5,

    liFontSpanColor1: '#ffffff',
    liFontSpanFontSize1: 16,
    liFontSpanColor2: '#ffffff',
    liFontSpanFontSize2: 16,
  },
}

export default class Config extends PublicConfigClass implements CreateComponentType {
  public key: string = HuoQingDetailPieConfig.key
  public attr = { ...chartInitConfig, w: 300, h: 320, zIndex: 1 }
  public chartConfig = cloneDeep(HuoQingDetailPieConfig)
  public option = echartOptionProfixHandle(option, includes)
  public filter = "return res.result;"
}
