<template>
    <div class="clear" v-if='clear'></div>
    <div class="switch-box">
        <label class="switch">
            <input v-model="value" type="checkbox"  @click="onClick">
            <span class="slider round"></span>
            <span v-if="value" class="switch-label-on">ON</span>
            <span v-if="!value" class="switch-label-off">OFF</span>
        </label>
    </div>
    <div class="switch-title">
        <span>{{label}}</span>
    </div>
</template>
<script lang="ts">
export default {
    name: 'Switch',
    props:{
        label: { type: String, default: '' },
        clear: { type: Boolean, default: false },
        value: { type: Boolean, default: false },
    },
    methods: {
        onClick(){
            this.$emit("update:input", !this.value);
        }
    }
};
</script>
<style scoped>
.clear{
    clear: both;
}
.switch-title{
    display: table !important;
    float: left !important;
    padding-right: 5px !important;
}
.switch-box{
    float: left !important;
    padding-right: 5px !important;
    padding-left: 15px !important;
}
.switch {
    position: relative;
    display: inline-block;
    width: 55px;
    height: 20px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #f0f0f0;
    -webkit-transition: .4s;
    transition: .4s;
    border-radius: 0px 10px 10px 0px;
    box-shadow: inset 0px 0px 5px black;
    cursor: pointer;
}

.slider:before {
    position: absolute;
    content: "";
    height: 13px;
    width: 13px;
    left: 4px;
    bottom: 4px;
    background-color: white;
    -webkit-transition: .4s;
    transition: .4s;
    border: solid 1px black;
    box-shadow: 0px 0px 3px black, inset 0px 0px 5px grey;
}

input:checked + .slider {
    background-color: #fb4d0a;
}

input:focus + .slider {
    box-shadow: 0 0 1px #fb4d0a;
}

input:checked + .slider:before {
    -webkit-transform: translateX(35px);
    -ms-transform: translateX(35px);
    transform: translateX(35px);
}

.slider.round {
    border-radius: 34px;
}

.slider.round:before {
    border-radius: 50%;
}

.switch-label-on{
    position: absolute;
    left: 5px;
    color:#f0f0f0;
}

.switch-label-off{
    position: absolute;
    left: 20px;
}
</style>