<template>
    <div :class="keyboardClass"></div>
</template>

<script>
import Keyboard from 'simple-keyboard'

const german = {
    default: [
        'q w e r t z u i o p ü',
        'a s d f g h j k l ö ä',
        'y x c v b n m {bksp}',
    ],
}

export default {
    name: 'FuggerKeyboard',
    props: {
        keyboardClass: {
            default: 'simple-keyboard',
            type: String,
        },
    },
    data: () => ({
        keyboard: null,
    }),
    watch: {
        input(input) {
            this.keyboard.setInput(input)
        },
    },
    mounted() {
        this.keyboard = new Keyboard({
            onChange: this.onChange,
            onKeyPress: this.onKeyPress,
            layout: german,
            display: {
                '{bksp}': '⌫',
            },
        })
    },
    methods: {
        onChange(input) {
            this.$emit('onChange', input)
        },
        onKeyPress(button) {
            this.$emit('onKeyPress', button)
        },
    },
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="scss">
@import 'assets/scss/variables';
@import 'assets/scss/simplekeyboard';

.simple-keyboard.hg-theme-default .hg-button {
    height: calc(115vh * var(--pxToVw));
}

.simple-keyboard.hg-theme-default .hg-button {
    background-color: white;
    color: #fff;
    font-size: calc(50vh * var(--pxToVw));
}

.simple-keyboard {
    position: absolute;
    bottom: 7.5vh;
    width: 69vw;
    left: 50%;
    transform: translateX(-50%);

    .hg-row:nth-child(1) {
        padding-right: 2.875vw;
    }
    .hg-row:nth-child(2) {
        padding-left: 2.875vw;
    }
    .hg-row:nth-child(3) {
        padding-left: 5.75vw;
    }

    .hg-button {
        width: 5.75vw;
        span {
            color: var(--primary);
        }
        &-bksp {
            width: 8.625vw;
            margin-left: 12.075vw;
        }
    }
}

.keyboard input {
    background-color: #9e917a;
    color: #fff;
    font-size: calc(32vh * var(--pxToVw));
    border-radius: calc(20vh * var(--pxToVw));
    margin-bottom: calc(50vh * var(--pxToVw));
    width: 90%;
    border: none;
    padding: calc(5vh * var(--pxToVw)) calc(25vh * var(--pxToVw));
}

::placeholder {
    color: #fff;
    font-size: calc(32vh * var(--pxToVw));
}
</style>
