<style lang=sass>
@import "../../assets/components/_switch.scss";
</style>

<template>
<div class="switch" v-bind:class="checkedCls" @click="onChanged">
	<span class="text">{{text}}</span>
</div>
</template>

<script>
export default{
	props:{
		checkedText:String,
		unCheckedText:String,
		text:String,
		checked:String
	},
	data(){
		return {
			checkedCls:"",
		}
	},
	compiled(){
		if(this.checked=="checked"){
			this.checkedCls="active";
			this.text=this.checkedText;
		}else{
			this.checked="";
			this.text=this.unCheckedText;
		}
	},
	watch:{
		checked(value){
			//console.log(value)
			if(value=="checked"){
				this.checkedCls="active";
				this.text=this.checkedText;
			}else{
				this.checkedCls="";
				this.text=this.unCheckedText;
			}
		}
	},
	methods:{
		onChanged(){
			if(this.checked==""){
				this.checked="checked";
			}else{
				this.checked="";
			}
			this.$emit("changed",this.checked);
		}
	}
}
</script>