<template>
  <div class="toggle-switch-wrapper">
    <label class="toggle-switch" :class="{ 'disabled': disabled }">
      <input
          type="checkbox"
          :checked="modelValue"
          :disabled="disabled"
          @change="handleToggle"
          class="toggle-input"
      />
      <span class="toggle-slider" :class="{ 'active': modelValue }">
        <span class="toggle-knob" :class="{ 'active': modelValue }"></span>
      </span>
      <span v-if="label" class="toggle-label">{{ label }}</span>
    </label>
  </div>
</template>

<script>
export default {
  name: 'ToggleSwitch',
  props: {
    modelValue: {
      type: Boolean,
      default: false
    },
    label: {
      type: String,
      default: ''
    },
    disabled: {
      type: Boolean,
      default: false
    }
  },
  emits: ['update:modelValue', 'change'],
  methods: {
    handleToggle(event) {
      if (this.disabled) return;

      const newValue = event.target.checked;
      this.$emit('update:modelValue', newValue);
      this.$emit('change', newValue);
    }
  }
}
</script>

<style scoped>
.toggle-switch-wrapper {
  display: inline-block;
}

.toggle-switch {
  display: flex;
  align-items: center;
  cursor: pointer;
  user-select: none;
  gap: 1.2rem;
}

.toggle-switch.disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.toggle-input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: relative;
  width: 4.8rem;
  height: 2.4rem;
  background-color: rgba(107, 134, 156, 0.1);
  border-radius: 1.4rem;
  transition: all 0.3s ease;
  box-shadow: inset 0 0.2rem 0.4rem rgba(0, 0, 0, 0.1);
}

.toggle-slider.active {
  background-color: #5AF0B4;
}

.toggle-knob {
  position: absolute;
  top: 0.4rem;
  left: 0.4rem;
  width: 1.6rem;
  height: 1.6rem;
  background-color: #ffffff;
  border-radius: 50%;
  transition: all 0.3s ease;
  box-shadow: 0 0.2rem 0.4rem rgba(0, 0, 0, 0.2);
}

.toggle-knob.active {
  transform: translateX(2.4rem);
  background-color: #ffffff;
}

.toggle-label {
  font-size: 1.4rem;
  font-weight: 500;
  color: #374151;
}

/* Hover-Effekte */
.toggle-switch:not(.disabled):hover .toggle-slider {
  box-shadow: inset 0 0.2rem 0.4rem rgba(0, 0, 0, 0.15), 0 0 0 0.2rem rgba(0, 47, 84, 0.1);
}

.toggle-switch:not(.disabled):hover .toggle-slider.active {
  box-shadow: inset 0 0.2rem 0.4rem rgba(0, 0, 0, 0.15), 0 0 0 0.2rem rgba(0, 47, 84, 0.15);
}

/* Animation beim Laden */
.toggle-slider,
.toggle-knob {
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
</style>