import defaultsDeep from 'lodash/defaultsDeep';
export default function getPie(
    charsData,
    color,
    center,
    tooltipFormatter,
    pieFormatter,
    pieOpt,
    insertPieOpt,
    insertText,
    insertColor,
    insertTextColor,
    changeOpt,
    type
) {
    let opt = {
        color,
        tooltip: {
            trigger: 'item',
            tooltipFormatter
        },
        legend: {
            icon: "circle",
            textStyle: {
                color: type == "dark" ? "#fff" : "#000",
                fontSize: 12
            },
            itemWidth: 8
        },
        series: [
            {
                type: 'pie',
                radius: ['50%', '70%'],
                center,
                data: charsData,
                minAngle: 10,
                label: {
                    normal: {
                        fontSize: 14,
                        lineHeight: 18,
                        formatter: pieFormatter
                    }
                },
                itemStyle: {
                    emphasis: {
                        shadowBlur: 10,
                        shadowOffsetX: 0,
                        shadowColor: 'rgba(0, 0, 0, 0.5)'
                    }
                }
            },
            {
                name: '内环',
                type: 'pie',
                silent: true,
                clockWise: true,
                hoverAnimation: false,
                radius: "50%",
                center,
                label: {
                    normal: {
                        position: 'center'
                    }
                },
                data: [{
                    value: 100,
                    text: insertText,
                    itemStyle: {
                        normal: {
                            color: insertColor
                        }
                    },
                    label: {
                        show: true,
                        position: 'center',
                        color: insertTextColor,
                        fontSize: 14,
                        formatter: function (o) {
                            return o.data.text
                        }
                    },
                }]
            },
        ]
    }
    if (changeOpt) {
        opt = defaultsDeep({}, changeOpt, opt)
    }
    if (pieOpt){
        opt.series[0] = defaultsDeep({}, pieOpt, opt.series[0])
        if (pieOpt.hasOwnProperty('radius')) {
            opt.series[1].radius = pieOpt.radius[0]
        }
    }
    if (insertPieOpt){
        opt.series[1] = defaultsDeep({}, insertPieOpt, opt.series[1])
    }
    return opt
}
