/// @access private
/// @param {Boolean} $disabled Whether to output disabled state styling
/// @param {Boolean} $right Whether to display checkbox to the right of text
/// @param {List} $themes List of themes to output.
/// @output Styling for text inputs
@mixin _oFormsCheckbox($disabled: null, $right: null, $themes: ()) {
	.o-forms-input--checkbox {
		input[type='checkbox'] {
			@include _oFormsControlsBase($disabled);

			&:focus {
				@include oPrivateNormaliseFocusUnsetContent();
				& + .o-forms-input__label:before {
					@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:before {
					@include oPrivateNormaliseFocusUnsetContent();
				}

				&:focus-visible {
					& + .o-forms-input__label:before {
						@include oPrivateNormaliseFocusContent();
					}
				}
			}

			&:indeterminate + .o-forms-input__label:after {
				@include oPrivateIconsContent(
					'minus',
					_oFormsGet('controls-checked-base'),
					$_o-forms-checkbox-radio-width
				);
				background-color: _oFormsGet('controls-base');
				opacity: 1;
			}
		}

		@if $right {
			.o-forms-input__right {
				display: inline-block;

				input[type='checkbox'] {
					right: 0;
				}
				input[type='checkbox'] ~ .o-forms-input__label {
					padding-left: 0;
					padding-right: $_o-forms-spacing-controls;

					&:before,
					&:after {
						// right: 0;
						left: calc(100% - #{$_o-forms-checkbox-radio-width});
					}
				}
			}
		}

		input[type='checkbox'] ~ .o-forms-input__label {
			display: inline-block;
			padding: 0 0 0 $_o-forms-spacing-controls;
			vertical-align: top;

			&:before {
				@include _oFormsControlsPseudoElements();
				border: $_o-forms-border;
				background-color: _oFormsGet('default-background');
				border-radius: oPrivateFoundationGet('o3-border-radius-1');
			}

			&:after {
				@include _oFormsControlsPseudoElements();
				@include oPrivateIconsContent(
					'tick',
					_oFormsGet('controls-checked-base'),
					$_o-forms-checkbox-radio-width
				);
				background-color: _oFormsGet('controls-base');
				opacity: 0;
				transition: opacity 0.1s ease;
				border-radius: oPrivateFoundationGet('o3-border-radius-1');
			}

			// this handles spacing between two input__label spans for the same input element,
			// which is necessary in the case of 'additional content'
			& + .o-forms-input__label {
				padding-top: $_o-forms-spacing-three;
			}
		}
	}

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

/// Output styles required to set a checkbox theme.
/// @param {String} $theme Theme to output
@mixin _oFormsCheckboxThemeContent($theme) {
	.o-forms-input--checkbox {
		input[type='checkbox'] {
			&:indeterminate + .o-forms-input__label:after {
				@include oPrivateIconsContent(
					'minus',
					_oFormsGet('controls-checked-base', $theme),
					$_o-forms-checkbox-radio-width
				);
				background-color: _oFormsGet('controls-base', $theme);
			}
		}

		input[type='checkbox'] ~ .o-forms-input__label {
			&:before {
				border: 1px solid _oFormsGet('default-border', $theme);
			}

			&:after {
				@include oPrivateIconsContent(
					'tick',
					_oFormsGet('controls-checked-base', $theme),
					$_o-forms-checkbox-radio-width
				);
				background-color: _oFormsGet('controls-base', $theme);
			}
			.o-forms-input__label__prompt {
				color: _oFormsGet('default-text', $theme);
			}
		}

		@if $theme and
			oPrivateColorsColorBrightness(_oFormsGet('default-text', $theme)) >
			65%
		{
			input[type='checkbox'] {
				&:focus {
					@include oPrivateNormaliseFocusUnsetContent();
					& + .o-forms-input__label:before {
						@include oPrivateNormaliseFocusContentInverse();
					}
				}

				// 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:before {
						@include oPrivateNormaliseFocusUnsetContent();
					}

					&:focus-visible {
						& + .o-forms-input__label:before {
							@include oPrivateNormaliseFocusContentInverse();
						}
					}
				}
			}
		}
	}
}
