@import 'mediawiki.mixins.less';
@import 'mediawiki.ui/variables.less';

// Radio
//
// Styling radios in a way that works cross browser is a tricky problem to solve.
// In MediaWiki UI put a radio and label inside a mw-ui-radio div.
// You should give the radio and label matching "id" and "for" attributes, respectively.
//
// Markup:
// <div class="mw-ui-radio">
//   <input type="radio" id="component-example-4" name="component-example-4">
//   <label for="component-example-4">Standard radio</label>
// </div>
// <div class="mw-ui-radio">
//   <input type="radio" id="component-example-4-checked" name="component-example-4" checked>
//   <label for="component-example-4-checked">Standard checked radio</label>
// </div>
// <div class="mw-ui-radio">
//   <input type="radio" id="component-example-4-disabled" name="component-example-4-disabled" disabled>
//   <label for="component-example-4-disabled">Disabled radio</label>
// </div>
// <div class="mw-ui-radio">
//   <input type="radio" id="component-example-4-disabled-checked" name="component-example-4-disabled" disabled checked>
//   <label for="component-example-4-disabled-checked">Disabled checked radio</label>
// </div>
.mw-ui-radio {
	display: inline-block;
	vertical-align: middle;
}

// We disable this styling on JavaScript disabled devices. This fixes the issue with
// Opera Mini where checking/unchecking doesn't apply styling but potentially leaves other
// more capable browsers with unstyled radio buttons.
.client-js .mw-ui-radio {
	// Position relatively so we can make use of absolute pseudo elements
	position: relative;
	line-height: @size-input-binary;

	* {
		// reset font sizes (see T74727)
		font-size: inherit;
		vertical-align: middle;
	}

	[ type='radio' ] {
		// ensure the invisible radio takes up the required width
		width: @size-input-binary;
		height: @size-input-binary;
		// This is needed for Firefox mobile (See T73750 to workaround default Firefox stylesheet)
		max-width: none;
		// Hide `input[ type=radio ]` and instead style the label that follows
		// Support: VoiceOver. Use `opacity` so that VoiceOver can still identify the radio
		opacity: 0;

		& + label {
			padding-left: 0.4em;

			// Pseudo `:before` element of the label after the radio now looks like a radio
			&:before {
				content: '';
				background-color: #fff;
				.box-sizing( border-box );
				position: absolute;
				left: 0;
				width: @size-input-binary;
				height: @size-input-binary;
				border: 1px solid @colorGray7;
				border-radius: 100%;
			}

			// Needed for `:focus` state's inner white circle
			&:after {
				content: ' ';
				position: absolute;
				top: 2px; // `px` unit due to pixel rounding error when using `@size-input-binary / 4`
				left: 2px;
				width: 1.14285em; // equals `@size-input-binary - 4px`
				height: 1.14285em;
				border: 1px solid transparent;
				border-radius: 100%;
			}
		}

		// Apply a dot on the pseudo `:before` element when the input is checked
		&:checked + label:before {
			border-width: @border-width-radio--checked;
		}

		&:enabled {
			cursor: pointer;

			& + label:before {
				cursor: pointer;
				.transition( ~'background-color 100ms, color 100ms, border-color 100ms' );
			}

			&:hover + label:before {
				// FIXME: Replace with WikimediaUI Base `@border-color*` var when available.
				border-color: @color-primary;
			}

			&:active + label:before {
				// FIXME: Replace with WikimediaUI Base `@background-color*` var when available.
				background-color: @color-primary--active;
				border-color: @border-color-input-binary--active;
			}

			&:checked {
				& + label:before {
					border-color: @border-color-input-binary--checked;
				}

				&:focus + label:after {
					border-color: #fff;
				}

				&:hover + label:before {
					// FIXME: Replace with WikimediaUI Base `@border-color*` var when available.
					border-color: @color-primary--hover;
				}

				&:active {
					& + label:before {
						border-color: @border-color-input-binary--active;
						box-shadow: @box-shadow-input-binary--active;
					}

					& + label:after {
						border-color: @border-color-input-binary--active;
					}
				}
			}
		}

		&:disabled {
			& + label:before {
				background-color: @colorGray12;
				border-color: @colorGray12;
			}

			&:checked + label:before {
				background-color: #fff;
			}
		}
	}
}
