import _ from 'lodash';
import {BISplitLineColor, BIAxisLableColor, BIAxisLabelColor, BIAxisLineColor} from "./theme";

/**
 * 1. 背景
 * 2. 坐标轴、字体颜色
 * 3. 分割线
 * 4. legend的文字颜色
 * 5. markPoint的颜色设置
 * 6. tooltip 背景
 * */
const handleYAxis = (item, _opt) => {
    item.minorSplitLine = {
        ...item.minorSplitLine,
        show: false,
        lineStyle: {
            type: 'solid',
            color: '#38435a'
        }
    };
    item.splitLine = {
        ...item.splitLine,
        show: true,
        lineStyle: {
            type: 'solid',
            color: BISplitLineColor
        }
    };
    item.axisLabel = {
        ...item.axisLabel,
        color: BIAxisLabelColor
    };
    item.axisLine = {
        ...(_opt?.xAxis?.axisLine ?? {}),
        show: true,
        lineStyle: {
            type: 'solid',
            color: BIAxisLineColor
        }
    };
}
const patchBIOption = (option, theme) => {
    let _opt = _.cloneDeep(option);
    // 1. 修改legend颜色
    if (_opt?.legend) {
        _opt.legend.textStyle = {
            ...(_opt?.legend?.textStyle ?? {}),
            color: theme.legendTextColor
        }
    }
    //2. 分割线样式调整
    _opt.xAxis.minorSplitLine = {
        ..._opt.xAxis.minorSplitLine,
        show: false,
        lineStyle: {
            type: 'solid',
            color: BISplitLineColor
        }
    };
    _opt.xAxis.axisLine = {
        ..._opt.xAxis.axisLine,
        show: true,
        lineStyle: {
            type: 'solid',
            color: BIAxisLineColor
        }
    };
    _opt.xAxis.splitLine = {
        ..._opt.xAxis.splitLine,
        show: true,
        lineStyle: {
            type: 'solid',
            color: BISplitLineColor
        }
    };
    _opt.xAxis.axisLabel = {
        ..._opt.xAxis.axisLabel,
        color: BIAxisLabelColor
    };
    if (_opt && _.isArray[_opt.yAxis]) {
        _opt.yAxis.forEach(item => {
            handleYAxis(item, _opt);
        })
    } else if (_opt && !_.isArray(_opt.yAxis)) {
        handleYAxis(_opt.yAxis, _opt);
    }

    return _opt;
};
export default patchBIOption;
