<template>
    <div class="card">
        <div class="card-header">Controller Settings</div>
        <div class="card-body">
            <div class="row mb-1" v-for="item, name in settingsList">
                <div class="col-1">{{ name }}</div>
                <div class="col-auto">
                    <input v-model="values[name]" type="number" step="0.1" class="form-control form-control-sm">
                </div>
                <div class="col-auto">
                <span v-if="values[name] !== settings[name]">
                        <button :disabled="disabled" class="btn btn-sm btn-outline-secondary" @click="saveSetting(name)">Save</button>
                    </span>
                </div>
                <div class="col">
                    {{ description[name] }}
                </div>
            </div>
        </div>
    </div>
</template>

<script>
    export default {
        props: {
            settings: Object,
            disabled: false
        },
        data: function () {
            return {
                values: {},
                description: {
"0": "Step pulse time, microseconds",
"1": "Step idle delay, milliseconds",
"2": "Step pulse invert, mask",
"3": "Step direction invert, mask",
"4": "Invert step enable pin, boolean",
"5": "Invert limit pins, boolean/mask",
"6": "Invert probe pin, boolean",
"7": "Disable spindle with 0 speed, boolean",
"8": "Ganged axes direction invert as bitfield",
"10": "Status report options, mask",
"11": "Junction deviation, millimeters",
"12": "Arc tolerance, millimeters",
"13": "Report in inches, boolean",
"14": "Limit pins invert, mask",
"15": "Coolant pins invert, mask",
"16": "Spindle pins invert, mask",
"17": "Control pins pullup disable, mask",
"18": "Limit pins pullup disable, mask",
"19": "Probe pin pullup disable, boolean",
"20": "Soft limits enable, boolean",
"21": "Hard limits enable, boolean",
"22": "Homing cycle enable, boolean (Grbl) / mask (GrblHAL)",
"23": "Homing direction invert, mask",
"24": "Homing locate feed rate, mm/min",
"25": "Homing search seek rate, mm/min",
"26": "Homing switch debounce delay, milliseconds",
"27": "Homing switch pull-off distance, millimeters",
"28": "G73 retract distance, in mm",
"29": "Step pulse delay (ms)",
"30": "Maximum spindle speed, RPM",
"31": "Minimum spindle speed, RPM",
"32": "Laser-mode enable, boolean",
"33": "Spindle PWM frequency",
"34": "Spindle off Value",
"35": "Spindle min value",
"36": "Spindle max value",
"37": "Stepper deenergize mask",
"39": "Enable printable realtime command characters, boolean",
"40": "Apply soft limits for jog commands, boolean",
"43": "Homing passes",
"44": "Homing cycle 1",
"45": "Homing cycle 2",
"46": "Homing cycle 3",
"47": "Homing cycle 4",
"62": "Sleep Enable",
"63": "Feed Hold Actions",
"64": "Force Init Alarm",
"65": "Require homing sequence to be executed at startup",
"70": "Network Services",
"73": "Wifi Mode",
"74": "",
"75": "",
"100": "X-axis steps per millimeter",
"101": "Y-axis steps per millimeter",
"102": "Z-axis steps per millimeter",
"103": "A-axis steps per millimeter",
"110": "X-axis maximum rate, mm/min",
"111": "Y-axis maximum rate, mm/min",
"112": "Z-axis maximum rate, mm/min",
"113": "A-axis maximum rate, mm/min",
"120": "X-axis acceleration, mm/sec^2",
"121": "Y-axis acceleration, mm/sec^2",
"122": "Z-axis acceleration, mm/sec^2",
"123": "A-axis acceleration, mm/sec^2",
"130": "X-axis maximum travel, millimeters",
"131": "Y-axis maximum travel, millimeters",
"132": "Z-axis maximum travel, millimeters",
"133": "A-axis maximum travel, millimeters",
"300": "Hostname",
"302": "IP Address",
"303": "Gateway",
"304": "Netmask",
"305": "Telnet Port",
"306": "HTTP Port",
"307": "Websocket Port",
"341": "Tool Change Mode",
"342": "Tool Change probing distance",
"343": "Tool Change Locate Feed rate",
"344": "Tool Change Search Seek rate",
"345": "Tool Change Probe Pull Off rate",
"370": "Invert I/O Port Inputs (mask)",
"384": "Disable G92 Persistence",
"346": "ToolChangeOptions",
"372": "Io Port Invert Out",
"376": "Rotary Axes",
"394": "Spindle On Delay",
"398": "Planner Blocks",
"481": "Auto Report Interval",
"484": "Unlock After EStop",
"486": "Offset Lock",
"538": "Rotary Wrap",
"539": "Spindle Off Delay",
"673": "Coolant On Delay",
"676": "Reset Actions",
"680": "Stepper Enable Delay"

                }
            }
        },
        computed: {
            settingsList () {
                for (let key in this.settings) {
                    if (typeof this.values[key] == 'undefined' ) {
                        this.values[key] = this.settings[key]
                    }
                }
                return this.values
            }
        },
        methods: {
            saveSetting(name) {
                let commands = ['$'+name+'='+this.values[name], '$'+name]
                this.$emit('sendCommand', commands)
            }
        }
    }
</script>

<style>

</style>