@use "variables";

$defaultHeight: 16px;
$defaultWidth: 16px;
$lgHeight: 24px;
$lgWidth: 24px;

%checkbox-label-before {
  flex-direction: row-reverse;
  justify-content: space-between;

  .fwe-checkbox-label-content {
    margin-left: 0px;
    margin-right: 8px;
  }
}

%checkbox-label-below {
  flex-direction: column;

  .fwe-checkbox-label-content {
    margin: 8px 0px 0px 0px;
  }
}

%checkmark-lg {
  height: $lgHeight;
  min-height: $lgHeight;
  width: $lgWidth;
  min-width: $lgWidth;
  border-radius: variables.$border-radius-s;
  &:before {
    height: 18px;
    width: 18px;
    left: 2px;
    top: 2px;
  }
}

.fwe-checkbox-group {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-evenly;

  &.fwe-checkbox-lg {
    label.fwe-checkbox {
      .fwe-checkbox-checkmark {
        @extend %checkmark-lg;
      }
    }
  }

  &.fwe-checkbox-label-before {
    label.fwe-checkbox {
      @extend %checkbox-label-before;
    }
  }

  &.fwe-checkbox-label-below {
    label.fwe-checkbox {
      @extend %checkbox-label-below;
    }
  }
}

label.fwe-checkbox {
  cursor: pointer;
  display: flex;
  align-items: center;
  white-space: nowrap;
  vertical-align: middle;
  -webkit-user-select: none;
  user-select: none;

  .fwe-checkbox-checkmark {
    box-sizing: border-box;
    position: relative;
    height: $defaultHeight;
    min-height: $defaultHeight;
    width: $defaultWidth;
    min-width: $defaultWidth;
    border-radius: 2px;
    border: 1px solid variables.$control-border;
    background-color: white;
    &::before {
      content: "";
      height: 14px;
      width: 14px;
      background-image: url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxNiAxNiI+PGcgZGF0YS1uYW1lPSJjb250ZW50Ij48cGF0aCBmaWxsPSJub25lIiBkPSJNMCAwaDE2djE2SDB6Ii8+PHBhdGggZmlsbD0iI2ZmZiIgZD0iTTYuMTQxIDEyLjgxNCAxLjkzNCA4LjYwN2wxLjQxNC0xLjQxNCAyLjc5MyAyLjc5MyA2Ljc5My02Ljc5MyAxLjQxNCAxLjQxNC04LjIwNyA4LjIwN3oiLz48L2c+PC9zdmc+");
      display: none;
      position: absolute;
    }
  }

  &.fwe-checkbox-lg {
    .fwe-checkbox-checkmark {
      @extend %checkmark-lg;
    }
  }

  .fwe-checkbox-label-content {
    line-height: 24px;
    margin-left: 8px;
  }

  &.fwe-checkbox-label-before {
    @extend %checkbox-label-before;
  }

  &.fwe-checkbox-label-below {
    @extend %checkbox-label-below;
  }

  input[type="checkbox"] {
    position: absolute;
    opacity: 0;
    cursor: pointer;

    &:hover ~ .fwe-checkbox-checkmark {
      background-color: variables.$control;
    }

    &:active ~ .fwe-checkbox-checkmark {
      background-color: variables.$control-hover;
    }

    &:indeterminate ~ .fwe-checkbox-checkmark {
      &::before {
        background-image: url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxNiAxNiI+PGcgZGF0YS1uYW1lPSJjb250ZW50Ij48cGF0aCBmaWxsPSJub25lIiBkPSJNMCAwaDE2djE2SDB6Ii8+PHBhdGggZmlsbD0iI2ZmZiIgZD0iTTIgN2gxMnYySDJ6Ii8+PC9nPjwvc3ZnPg==");
      }
    }

    &:checked ~ .fwe-checkbox-checkmark,
    &:indeterminate ~ .fwe-checkbox-checkmark {
      background-color: variables.$hero;
      border-color: variables.$hero;
    }

    &:hover:checked:not(:disabled) ~ .fwe-checkbox-checkmark,
    &:hover:indeterminate:not(:disabled) ~ .fwe-checkbox-checkmark {
      background-color: variables.$hero-hover;
      border-color: variables.$hero-hover;
    }

    &:active:checked:not(:disabled) ~ .fwe-checkbox-checkmark,
    &:active:indeterminate:not(:disabled) ~ .fwe-checkbox-checkmark {
      background-color: variables.$hero-active;
      border-color: variables.$hero-active;
    }

    &:checked ~ .fwe-checkbox-checkmark:before,
    &:indeterminate ~ .fwe-checkbox-checkmark:before {
      display: block;
    }

    &:disabled ~ .fwe-checkbox-checkmark {
      background-color: variables.$white;
      border-color: variables.$control-disabled;
      cursor: not-allowed;
    }

    &:disabled:checked ~ .fwe-checkbox-checkmark,
    &:disabled:indeterminate ~ .fwe-checkbox-checkmark {
      background-color: variables.$control-disabled;
      border-color: variables.$control-disabled;
    }

    &:disabled {
      cursor: not-allowed;
    }

    &:disabled ~ .fwe-checkbox-label-content {
      color: variables.$text-disabled;
      cursor: not-allowed;
    }

    &:user-invalid ~ .fwe-checkbox-checkmark {
      border-color: variables.$red;
    }
  }
}
