@import '@cmsgov/design-system-support/src/settings/index';

$ds-c-inset-border-width: $spacer-half;

// Hide the default browser checkbox/radio button since we'll
// create our own custom version

.ds-c-choice {
  left: -999em;
  opacity: 0;
  position: absolute;

  // Checked children container
  &__checkedChild {
    border-left: $ds-c-inset-border-width solid $color-primary;
    margin-bottom: $spacer-2;
    margin-left: ($choice-size / 2) - ($ds-c-inset-border-width / 2);
    padding: $spacer-2;

    // Checked children container on dark background
    &--inverse {
      border-left-color: $color-white;
    }

    // Small input variant
    &--small {
      margin-left: $spacer-1;
    }
  }
}

.ds-c-choice + label {
  align-items: center;
  cursor: pointer;
  display: flex;
  flex-wrap: wrap;
  font-weight: $font-normal;
  margin: $spacer-1 0;
  max-width: $measure-base;
  min-height: $choice-size;
  padding-left: $choice-size + $spacer-1;
  position: relative;
}

// Create a custom checkbox/radio button
.ds-c-choice + label::before {
  background-color: $color-background;
  border: $choice-border-width solid $choice-border-color;
  box-sizing: border-box;
  content: '\a0';
  height: $choice-size;
  left: 0;
  line-height: $choice-size;
  position: absolute;
  text-indent: 0.15em;
  top: 0;
  width: $choice-size;
}

.ds-c-choice--inverse + label::before {
  background-color: $color-background-inverse;
  border-color: $choice-border-color-inverse;
}

// Display an outline
.ds-c-choice:focus + label::before {
  @if $ds-include-focus-styles {
    border-color: $color-base;
    border-width: 3px;
    box-shadow: 0 0 0 3px $focus-color;
    // Transparent outline for Windows High Contrast Mode
    outline: 3px solid transparent;
    outline-offset: 3px;
  } @else {
    box-shadow: 0 0 0 2px $color-background, 0 0 2px 4px $color-focus;
  }
}

@if $ds-include-focus-styles {
  .ds-c-choice--small:focus + label::before {
    border-width: 2px;
  }
  .ds-c-choice:checked:focus + label::before {
    border-color: $color-primary-darker;
  }
}

.ds-c-choice--inverse:focus + label::before {
  @if $ds-include-focus-styles {
    border-color: $choice-border-color-inverse;
    box-shadow: 0 0 0 3px $focus-color-inverse;
  } @else {
    box-shadow: 0 0 0 2px $color-background-inverse, 0 0 2px 4px $color-focus-inverse;
  }
}

// Display a checkmark
.ds-c-choice:checked + label::before {
  background-color: $choice-checked-background-color;
  background-image: url('#{$image-path}/checkmark-white.svg');
  background-position: 50%;
  background-repeat: no-repeat;
  background-size: $choice-size - $spacer-1;
  border-color: $choice-checked-background-color;
}

// Fade the checkbox and label
.ds-c-choice:disabled {
  + label {
    color: $color-muted;

    &::before {
      background-color: $color-gray-lighter;
      border: 1px solid $color-gray-light;
      cursor: not-allowed;
    }
  }
}

.ds-c-choice--inverse:disabled {
  + label {
    color: $color-muted-inverse;

    &::before {
      background-color: rgba($color-muted-inverse, 0.15);
      box-shadow: 0 0 0 1px $color-muted-inverse;
    }
  }
}

// Display a circular radio button
.ds-c-choice[type='radio'] + label::before {
  border-radius: 100%;
}

/*
Right-to-Left
*/

.ds-c-choice--right + label {
  padding-left: 0;
  padding-right: $choice-size + $spacer-1;

  &::before {
    left: auto;
    right: 0;
  }
}

/*
Size variants
*/

.ds-c-choice--small {
  + label {
    min-height: $choice-size-small;
    padding-left: $choice-size-small + $spacer-1;
    padding-top: 0;

    &::before {
      height: $choice-size-small;
      top: 2px;
      width: $choice-size-small;
    }
  }

  &:checked + label::before {
    background-size: $choice-size-small;
  }

  &.ds-c-choice--right + label {
    padding-left: 0;
    padding-right: $choice-size-small + $spacer-1;
  }
}
