export default function (publicProps) {
    const { partSize, derrickSize } = publicProps
    let { platformSize, platformData } = publicProps
    function platformSizeInit () {
        return {
            width: partSize.topRedBottom.width * 3,
            height: 30,
            top: partSize.topRed.height + derrickSize.height,
            caledLeftRect: {},
            caledRightRect: {}
        }
    }
    platformSize = platformSizeInit()
    platformData = [{ coords: [], lineStyle: { width: 1 } }, { coords: [], lineStyle: {} }, { coords: [], lineStyle: {} }, { coords: [], lineStyle: { width: 2 } }]
    function calPlatform () {
        platformSize = platformSizeInit()
        const initPoint = { x: undefined, y: undefined }
        const leftRect = {
            leftTop: { ...initPoint },
            leftBottom: { ...initPoint },
            rightBottom: { ...initPoint },
            rightTop: { ...initPoint }
        }
        const rightRect = {
            leftTop: { ...initPoint },
            leftBottom: { ...initPoint },
            rightBottom: { ...initPoint },
            rightTop: { ...initPoint }
        }
        const per = platformSize.width / 6
        const middle = 1.8
        const left = (6 - middle) / 2
        const right = middle + left
        leftRect.leftTop = { x: 0, y: 0 }
        leftRect.leftBottom = { x: 0, y: platformSize.height }
        leftRect.rightBottom = { x: 0 + per * left, y: platformSize.height }
        leftRect.rightTop = { x: 0 + per * left, y: 0 }

        rightRect.leftTop = { x: 0 + per * right, y: 0 }
        rightRect.leftBottom = { x: 0 + per * right, y: platformSize.height }
        rightRect.rightBottom = { x: platformSize.width, y: platformSize.height }
        rightRect.rightTop = { x: platformSize.width, y: 0 }
        function p2A (p) {
            return [p.x, p.y]
        }
        platformSize.caledLeftRect = leftRect
        platformSize.caledRightRect = rightRect

        platformData[0].coords = [
            p2A(leftRect.leftTop),
            p2A(leftRect.leftBottom),
            p2A(leftRect.rightBottom),
            p2A(leftRect.rightTop),
            p2A(leftRect.leftTop)
        ]

        platformData[1].coords = [
            p2A(leftRect.rightTop),
            p2A(rightRect.leftTop)
        ]
        platformData[2].coords = [
            p2A(leftRect.rightBottom),
            p2A(rightRect.leftBottom)
        ]

        platformData[3].coords = [
            p2A(rightRect.leftTop),
            p2A(rightRect.leftBottom),
            p2A(rightRect.rightBottom),
            p2A(rightRect.rightTop),
            p2A(rightRect.leftTop)
        ]
    }
    calPlatform()

    return {
        platformSize,
        platformData,

        calPlatform
    }
}
