import { echartOptionProfixHandle, PublicConfigClass } from '@/packages/public'
import { ZhiGan_XianSuoShangBaoFenLeiConfig } 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: ['70%', '90%'],
      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: {
    backgroud: '#FFFFFF00',
    marginTop: 10,
    marginLeft: 10,

    sumSpanColor1: '#ffffff',
    sumSpanFontSize1: 25,
    sumSpanColor2: '#ffffff',
    sumSpanFontSize2: 16,

    listGap : 10,
    listMarginLeft: 0,
    liWidth: 186,
    liHeight: 24,
    productFontSpanColor: '#D0E6CF',
    productFontSpanFontSize: 13,
    dataFontSpanColor: '#C3D7E6',
    dataFontSpanFontSize: 13,
  },
}

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