// sass-lint:disable no-qualifying-elements
/// @access private
/// @param {Boolean} $disabled Whether to output disabled state styling
/// @output Styling for box-styled radio inputs
@mixin _oFormsRadioBox($disabled: null, $themes) {
	.o-forms-input--radio-box {
		@include _oFormsRadioBoxInputStyles();

		.o-forms-input--radio-box__container {
			@include _oFormsControlsBoxContainer();
		}

		&.o-forms-input--invalid .o-forms-input--radio-box__container {
			border-color: _oFormsGet('invalid-base');
		}

		label {
			@include _oFormsControlsBoxBase();

			.o-forms-input__label {
				box-sizing: border-box;
				padding: $_o-forms-spacing-one $_o-forms-spacing-two;
				transition: 0.3s background-color, 0.15s color ease-out;
				width: 100%;
				height: 100%;
				max-height: 28px;
				display: inline-flex;
				align-items: center;
				justify-content: center;
			}
		}

		input[type='radio'] {
			position: absolute;
			// Hide visually while remaining accessible to voice control like Dragon
			// Dragon requires the input it is trying to click to be actually clickable
			opacity: 0;
			z-index: 1;
			width: 100%;
			height: 100%;
			cursor: pointer;

			@if $disabled {
				&:disabled + .o-forms-input__label {
					cursor: default;
					opacity: 0.4;
				}
			}
		}

		@include oPrivateGridRespondTo(S) {
			&.o-forms-input--inline .o-forms-input__state {
				position: relative;
				margin-bottom: 0;
			}
		}

		.o-forms-input__state {
			position: relative;
			margin-bottom: -($_o-forms-spacing-five + $_o-forms-spacing-half);
		}
	}

	@each $theme in $themes {
		@if _oFormsSupports('#{$theme}') {
			.o-forms-field--#{$theme} .o-forms-input--radio-box {
				@include _oFormsRadioBoxInputStyles($theme);
			}
		}
	}
}

/// @access private
/// @param {Map|null} $theme Custom theme map
/// @output styling for box-styled radio inputs
@mixin _oFormsRadioBoxInputStyles($theme: null) {
	border-color: _oFormsGet('default-border', $from: $theme);

	.o-forms-input--radio-box__container {
		background-color: _oFormsGet('radio-background');

		label .o-forms-input__label {
			border-radius: oPrivateFoundationGet('o3-border-radius-1');
		}

		.o-forms-input--radio-box__container,
		label:not(:first-of-type) {
			border-color: _oFormsGet('default-border', $from: $theme);
		}

		input[type='radio'] {
			& + .o-forms-input__label {
				color: _oFormsGet('controls-base', $from: $theme);
			}

			&:not(:checked):not(:disabled):hover + .o-forms-input__label {
				background-color: rgba(
					_oFormsGet('controls-base', $from: $theme),
					0.15
				);
			}

			&:focus {
				@include oPrivateNormaliseFocusUnsetContent();

				& + .o-forms-input__label {
					$default-text: _oFormsGet('default-text', $theme);
					@if $default-text and
						oPrivateColorsColorBrightness($default-text) >
						65%
					{
						@include oPrivateNormaliseFocusContentInverse();
					} @else {
						@include oPrivateNormaliseFocusContent();
					}
				}
			}

			// Unset :focus styles where :focus-visible is supported.
			// Ideally we would set `:focus-visible` by default and use
			// `@supports not selector(:focus-visible)` to provide a
			// `:focus` fallback, however some of our supported browsers
			// do not understand `@supports: selector()`.
			@supports selector(:focus-visible) {
				&:focus + .o-forms-input__label {
					@include oPrivateNormaliseFocusUnsetContent();
				}

				&:focus-visible {
					& + .o-forms-input__label {
						$default-text: _oFormsGet('default-text', $theme);
						@if $default-text and
							oPrivateColorsColorBrightness($default-text) >
							65%
						{
							@include oPrivateNormaliseFocusContentInverse();
						} @else {
							@include oPrivateNormaliseFocusContent();
						}
					}
				}
			}

			&:checked + .o-forms-input__label {
				background-color: _oFormsGet('controls-base', $from: $theme);
				color: _oFormsGet('controls-checked-base', $from: $theme);

				&.o-forms-input__label--negative {
					background-color: _oFormsGet(
						'controls-negative-checked-background',
						$from: $theme
					);
				}
			}
		}
	}
}
