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

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

.switch__wrapper {
  display: inline-flex;
}

.switch__input-wrapper {
  box-sizing: border-box;
  text-align: left;
  position: relative;
  display: inline-flex;
  width: 42px;
  height: 24px;
  flex-shrink: 0;
  cursor: pointer;
  border-radius: 12px;
  align-items: center;
  background-color: rgba(0, 0, 0, 0.15);
  border: 0.92px solid transparent;
  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-color: rgb(var(--zn-color-primary));
  border-color: rgb(var(--zn-color-primary));

  .switch__control {
    transform: translate(16px, -50%);
  }
}

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

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

.switch__control {
  pointer-events: none;
  position: absolute;
  top: 50%;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  box-shadow: rgba(0, 0, 0, 0.1) 0 1px 3px 0, rgba(0, 0, 0, 0.1) 0 1px 2px -1px;

  transform: translateY(-50%);
  transition: transform .3s ease-in-out, background-color .4s ease-in-out;
  outline: none;
}

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

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

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

:host([checked]) .switch__wrapper--small .switch__input-wrapper {
  .switch__control {
    transform: translate(13px, -50%);
  }
}

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

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