<template>
    <div :class="radioClass" :style="iconColors">
        <Radio
            :disabled="disabled"
            :value="val"
            v-model="radioValue">
            <div class="radio__label" v-if="label">
                {{ label }}
            </div>
            <template slot="input-box">
                <div class="radio">
                </div>
            </template>
        </Radio>
    </div>
</template>

<script lang="ts">
    import Vue from "vue";
    import {
        RADIO__CHECKED_CLASS,
        RADIO__DISABLED_CLASS,
        RADIO__SMALL_CLASS,
        RADIO__WRAPPER_CLASS,
    } from "./constants";
    import {Radio} from 'vue-checkbox-radio';
    // @ts-ignore
    import themeVariables from "../../../assets/scss/colors.scss";

    export default Vue.extend({
        name: "RadioComponent",
        props: {
            val: {
                type: String,
                required: true,
            },
            value: {
                type: String,
                required: true,
            },
            disabled: {
                type: Boolean,
                default: false,
            },
            label: {
                type: String,
                default: '',
            },
            hasError: {
                type: Boolean,
                default: false,
            },
            color: {
                type: String,
                default(): string {
                    return themeVariables.primary;
                },
            },
            small: {
                type: Boolean,
                default: false,
            },
        },
        data() {
            return {};
        },
        components: {
            Radio,
        },
        computed: {
            radioValue: {
                get(): string {
                    return this.value;
                },
                set(value: string): void {
                    this.$emit('input', value);
                },
            },
            radioClass(): object {
                return {
                    [RADIO__WRAPPER_CLASS]: true,
                    [RADIO__DISABLED_CLASS]: this.disabled,
                    [RADIO__CHECKED_CLASS]: this.isChecked,
                    [RADIO__SMALL_CLASS]: this.small,
                };
            },
            iconColors(): object {
                return {
                    '--color': this.color,
                };
            },
            isChecked(): boolean {
                return this.radioValue === this.val;
            },
        },
    });
</script>

<style scoped lang="scss">
    @import "radioComponent";
</style>
