@use "../../wc";

:host {
  --zn-toggle-margin: 8px 0;
}

.switch__wrapper {
  display: inline-flex;
}

.switch__input-wrapper {
  text-align: left;
  position: relative;
  display: inline-flex;
  width: 50px;
  height: 25px;
  flex-shrink: 0;
  cursor: pointer;
  border-radius: 20px;
  align-items: center;
  background: rgba(0, 0, 0, 0.15);
  border-width: 1px !important;
  margin: var(--zn-toggle-margin);
  transition: color .2s ease-in-out, background-color .4s ease-in-out, border-color .2s ease-in-out;
}

:host(:focus) .switch__input-wrapper {
  outline: rgb(var(--zn-primary)) solid 1px;
}

:host([checked]) .switch__input-wrapper {
  background: rgba(var(--zn-primary), 0.8);

  .switch__control {
    transform: translateX(calc(100% - 1px)) scale(0.8);
    background: rgba(255, 255, 255, 1);
    width: 25px;
  }
}

.switch {
  height: 100%;
  width: 100%;
  padding: 0;
  margin: 0;
  cursor: pointer;
}

.switch-label {
  font-size: 90%;
}

.switch__control {
  pointer-events: none;
  display: inline-block;
  width: 100%;
  height: 25px;
  border-radius: 100px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: rgb(255, 255, 255) 0 0 0 0, rgba(59, 130, 246, 0.5) 0 0 0 0, rgba(0, 0, 0, 0.1) 0 1px 3px 0, rgba(0, 0, 0, 0.1) 0 1px 2px -1px;

  position: relative;
  top: 0;
  transform: scale(0.8);
  transition: transform .3s ease-in-out, background-color .4s ease-in-out, opacity .2s ease-in-out, max-width .2s, width .4s;
  outline: none;
  max-width: 25px;
}

.switch__input {
  position: absolute;
  opacity: 0;
  padding: 0;
  margin: 0;
  pointer-events: none;
}

// sizes
.switch__wrapper--small .switch__input-wrapper {
  height: 20px;
  width: 35px;
}

:host([checked]) .switch__wrapper--small .switch__input-wrapper {
  .switch__control {
    transform: translateX(calc(100% - 7px)) scale(0.8);
  }
}

.switch__wrapper--small .switch__control {
  max-width: 20px;
  height: 20px;
}

// Support inline label
.switch__wrapper--inline label {
  align-items: center;
  display: flex;
  gap: 8px;

  .switch__input {
    margin-inline: 1px;
    margin-inline-end: 1px;
  }
}
