// Copyright (C) 2018 The Trustees of Indiana University
// SPDX-License-Identifier: BSD-3-Clause

@use '../core' as *;
@use 'sass:math';

$padding: math.div(3rem, 16);

.#{$prefix}-radio {
  display: inline-block;
  padding-left: $spacing-lg;
  position: relative;

  input[type='radio'] {
    cursor: pointer;
    height: $spacing-md;
    left: 0;
    margin: 0;
    opacity: 0;
    position: absolute;
    top: 0;
    width: $spacing-lg;
  }

  &--sr-only-label {
    padding-left: $spacing-md;
  }

  &--sr-only-label input[type='radio'] {
    width: $spacing-md;
  }

  &--sr-only-label input[type='radio'] ~ label {
    height: 0;
    overflow: hidden;
    padding: 0;
    width: 0;
  }

  input[type='radio'] ~ label {
    cursor: pointer;
    display: inline-block;
    line-height: $line-height-base;
  }

  input[type='radio'] ~ label::before {
    background-color: $color-white-base;
    border: math.div($spacing-xxs, 2) solid $color-black-300;
    border-radius: $spacing-sm;
    box-shadow: inset 0 0 0 $padding $color-white-base;
    content: '';
    display: inline-block;
    height: $spacing-sm;
    left: math.div($spacing-xxs, 2);
    position: absolute;
    top: math.div($spacing-xxs, 2);
    width: $spacing-sm;
  }

  input[type='radio']:checked ~ label::before {
    background-color: $color-blue-500;
    border-color: $color-blue-500;
  }

  input[type='radio']:focus ~ label::before {
    border-color: $color-blue-500;
    box-shadow:
      inset 0 0 0 $padding $color-white-base,
      0 0 0 $spacing-xxs $color-blue-200;
  }

  input[type='radio']:disabled {
    cursor: default;
  }

  input[type='radio']:disabled ~ label {
    color: $color-black-400;
    cursor: default;
  }

  input[type='radio']:disabled ~ label::before {
    background-color: $color-black-100;
    border-color: $color-black-300;
    box-shadow: inset 0 0 0 $padding $color-black-100;
  }

  input[type='radio']:disabled:checked ~ label::before {
    background-color: $color-black-300;
  }

  &__description {
    color: $color-black-400;
    display: block;
    font-size: $ts-14;
  }
}
