<script>
export default {
    name: "ToggleButton",
    props: {
        modelValue: Boolean,
        reverseState: Boolean
    },
    emits: [ "update:modelValue" ],
    computed: {
        myValue: {
            get() {
                return this.reverseState ? !this.modelValue : this.modelValue;
            },
            set(newValue) {
                this.$emit("update:modelValue", this.reverseState ? !newValue : newValue);
            }
        }
    },
    methods: {
        toggle() {
            this.myValue = !this.myValue;
        }
    }
}
</script>

<template>
<button class="base" @click="toggle" :class="{ 'toggled': myValue }" type="button">
    <slot />
</button>
</template>

<style lang="scss" scoped>
.base {
    @extend .btn-fab;
    color: var(--bg-color);
    background-color: var(--paper-color);
    box-shadow: var(--primary-box-shadow-thin);
}

.toggled {
    color: var(--fg-color);
    background-color: var(--bg-color);
}
</style>
