<script lang="ts" setup>
const emit = defineEmits<{
  (e: 'click'): void;
}>();

const props = defineProps<{
  twoWay?: boolean;
  color?: string;
  disable?: boolean;
}>();

const model = defineModel<boolean>({ default: false });

function handleClick() {
  if (props.disable) return;
  emit('click');
}
</script>
<template>
  <label class="switch" @click.stop="handleClick">
    <input type="checkbox" :disabled="twoWay || disable" v-model="model" />
    <div class="slider round" :class="{ disable: disable }"></div>
  </label>
</template>
<style lang="scss" scoped>
.switch {
  position: relative;
  display: inline-block;
  width: 42px;
  height: 25px;
}

.switch input {
  display: none;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: hsl(var(--text-mute));
  -webkit-transition: 0.3s;
  transition: 0.3s;

  &.disable {
    cursor: not-allowed !important;
    background-color: var(--stone-4);
  }
}

.slider:before {
  position: absolute;
  content: '';
  height: 18px;
  width: 18px;
  left: 3.5px;
  bottom: 3.5px;
  background-color: white;
  -webkit-transition: 0.3s;
  transition: 0.3s;
}

input:checked + .slider {
  background-color: hsl(var(--positive-bg));

  &.disable {
    background-color: var(--stone-4);
  }
}

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

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

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

.slider.round:before {
  border-radius: 50%;
}
</style>
