import * as echarts from 'echarts'

export default function (publicProps) {
    const { mainSize, partSize, platformSize, derrickSize, derrickConfig } = publicProps
    let { pipeSize } = publicProps
    const drillPipe = echarts.graphic.extendShape({
        shape: {
            x: 0,
            y: 0,
            width: 0,
            height: 0
        },
        buildPath: function (ctx, shape) {
            const leftTop = [0, 0]
            const leftBottom = [0, 100]

            ctx.moveTo(leftTop[0], leftTop[1])
            ctx.lineTo(leftBottom[0], leftBottom[1])
            ctx.lineTo()
            ctx.closePath()
        }
    })
    echarts.graphic.registerShape('drillPipeRect', drillPipe)
    function pipeSizeInit () {
        return {
            gridLeft: derrickConfig.padLeft + platformSize.caledLeftRect.rightTop.x,
            gridTop: partSize.topRed.height,
            gridWidth: platformSize.caledRightRect.leftTop.x - platformSize.caledLeftRect.rightTop.x,
            gridHeight: mainSize.height - partSize.topRed.height,
            yAxisMax: 3000,

            redBottomToPlatBoxPx: derrickSize.height + platformSize.height,

            hookHeight: 15,
            hookPipeSapce: 10,

            pipeWidth: partSize.topRed.width * 1.4,
            drillBitWidth: undefined,
            drillBitHeight: 30,  //30
            drillToolWidth: 20,
            drillToolHeight: undefined,

            leftStrataWidth: undefined,
            rightStrataWidth: undefined
        }
    }
    pipeSize = pipeSizeInit()
    function calUnderground () {
        pipeSize = pipeSizeInit()
        pipeSize.drillBitWidth = pipeSize.gridWidth - 4
        pipeSize.drillToolHeight = pipeSize.drillBitHeight * 1.2
        pipeSize.drillToolWidth = pipeSize.pipeWidth * 2
        pipeSize.leftStrataWidth = (derrickSize.width - pipeSize.gridWidth) / 2
        pipeSize.rightStrataWidth = pipeSize.leftStrataWidth
    }
    calUnderground()

    return {
        pipeSize,

        calUnderground
    }
}
