export default {
  methods: {
    async controllerMove(cmdName) {
        //let cmd = ''
        let commands = []
        switch (cmdName) {
            case 'X-Y+':
                commands = [`$J=G21G91X-${this.movingOptions.stepSize}Y${this.movingOptions.stepSize}F${this.movingOptions.feedRateXYZ}`]
                break;
            case 'Y+':
                commands = [`$J=G21G91Y${this.movingOptions.stepSize}F${this.movingOptions.feedRateXYZ}`]
                break;
            case 'X+Y+':
                commands = [`$J=G21G91X${this.movingOptions.stepSize}Y${this.movingOptions.stepSize}F${this.movingOptions.feedRateXYZ}`]
                break;
            case 'X-':
                commands = [`$J=G21G91X-${this.movingOptions.stepSize}F${this.movingOptions.feedRateXYZ}`]
                break;
            case 'X+':
                commands = [`$J=G21G91X${this.movingOptions.stepSize}F${this.movingOptions.feedRateXYZ}`]
                break;
            case 'X-Y-':
                commands = [`$J=G21G91X-${this.movingOptions.stepSize}Y-${this.movingOptions.stepSize}F${this.movingOptions.feedRateXYZ}`]
                break;
            case 'Y-':
                commands = [`$J=G21G91Y-${this.movingOptions.stepSize}F${this.movingOptions.feedRateXYZ}`]
                break;
            case 'X+Y-':
                commands = [`$J=G21G91X${this.movingOptions.stepSize}Y-${this.movingOptions.stepSize}F${this.movingOptions.feedRateXYZ}`]
                break;
            case 'Z+':
                commands = [`$J=G21G91Z${this.movingOptions.stepSize}F${this.movingOptions.feedRateXYZ}`]
                break;
            case 'Z-':
                commands = [`$J=G21G91Z-${this.movingOptions.stepSize}F${this.movingOptions.feedRateXYZ}`]
                break;
            case 'RL':
                commands = [`$J=G21G91A${this.movingOptions.rotateStep}F${this.movingOptions.feedRateA}`]
                break;
            case 'RR':
                commands = [`$J=G21G91A-${this.movingOptions.rotateStep}F${this.movingOptions.feedRateA}`]
                break;

            case 'Return':
                commands = ["G90 G0 X0 Y0"]
                break;
            case 'ReturnZ':
                commands = ["G90 G0 Z0"]
                break;
            case 'Reset':
                cmd = String.fromCharCode(24)
                break;
            case 'State':
                commands = ["$G"]
                break;
            case 'Pos':
                commands = ["?"]
                break; 
            case 'Home':
                commands = ["$H"]
                break;
            case 'Unlock':
                commands = ["$X"]
                break;
            case 'ResetZero':
                commands = ["G10 P0 L20 X0 Y0 Z0"]
                break;
            case 'HomeResetZero':
                commands.push("$H")
                commands.push("G10 P0 L20 X0 Y0 Z0")
                break;
            case 'Parking':
                commands.push(`G0 Z${this.settings.parking.pos.z}`)
                commands.push(`G0 X${this.settings.parking.pos.x} Y${this.settings.parking.pos.y} A0`)
                break;
        }

        //if (cmd != '') {
        //    await this.sendCommandUI(cmd)
        //}

        //if (commands.length > 0) {
            for (let cmd of commands) {
                await this.sendCommandUI(cmd)
            }
            //this.sendCommands(commands, true)
        //}

    },

    controllerTogglePump() {
        let cmd = this.pumpState?this.settings.pump.Off:this.settings.pump.On
        this.sendCommandUI(cmd)
    },

    controllerToggleValve(valve) {
        let cmd = this.valvesState[valve]?this.settings.heads[valve].valveOff:this.settings.heads[valve].valveOn
        this.sendCommandUI(cmd)
    },

    controllerToggleCamNozzlePosition() {
        let cmd
        let topCamOffset = this.settings.cams[0].offset
        if (this.movingOptions.topCamNozzlePos == 0) {
            this.movingOptions.topCamNozzlePos = 1
            cmd = `$J=G21G91X${-topCamOffset.x}Y${-topCamOffset.y}F${this.movingOptions.feedRateXYZ}`
        } else {
            this.movingOptions.topCamNozzlePos = 0
            cmd = `$J=G21G91X${topCamOffset.x}Y${topCamOffset.y}F${this.movingOptions.feedRateXYZ}`                    
        }
        this.sendCommandUI(cmd)
    }
  }
}