@use "@wordpress/base-styles/colors" as *;
@use "@wordpress/base-styles/mixins";
@use "@wordpress/base-styles/variables" as *;
@use "../utils/theme-variables" as *;

.value-input.value-input.value-input {
	input {
		display: block;
		width: 100%;
	}

	:global(.components-input-control__backdrop) {
		transition: box-shadow 0.1s linear;
	}
}

@mixin unit-label {
	box-sizing: border-box;
	min-width: 24px;
	max-width: 48px;
	height: 24px;
	margin-inline-end: $grid-unit-10;
	padding: $grid-unit-05;
	font-size: 13px;
	line-height: 1;
	text-align-last: center;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
	field-sizing: content;
}

@mixin small-unit-label {
	box-sizing: border-box;
	padding: 2px 1px;
	width: 20px;
	font-size: 8px;
	line-height: 1;
	letter-spacing: -0.5px;
	text-transform: uppercase;
	text-align-last: center;

	&:not(:disabled) {
		color: $gray-800;
	}
}

.unit-label.unit-label.unit-label {
	pointer-events: none;
	color: $gray-900;

	&:where(:not(.is-small)) {
		@include unit-label;
	}
	&:where(.is-small) {
		@include small-unit-label;
	}
}

// Triple specificity counteracts wp-admin forms.css.
.unit-select.unit-select.unit-select {
	appearance: none;
	background: transparent;
	border-radius: $radius-x-small;
	border: none;
	display: block;
	outline: none;
	// Keep focus styles overlaid neatly on the input wrapper.
	margin: 0;
	min-height: auto;
	font-family: inherit;

	&:not(:disabled) {
		cursor: var(--wpds-cursor-control);

		&:hover {
			background-color: $gray-100;
		}
	}

	&:focus {
		@include mixins.outset-ring__focus();
		// Reset the wp-admin forms.css focus box-shadow.
		box-shadow: none;
	}

	&:where(.is-small) {
		@include small-unit-label;
		height: 100%;
		border-start-start-radius: 0;
		border-end-start-radius: 0;

		// Draw the focus ring inside, since the select is flush with the input edge.
		&:focus {
			z-index: 1;
			outline-offset: calc(-1 * var(--wpds-border-width-focus));
		}
	}

	&:where(:not(.is-small)) {
		@include unit-label;
		border-radius: var(--wpds-border-radius-sm);
		display: flex;
		justify-content: center;
		align-items: center;

		&:not(:disabled) {
			color: $components-color-accent;
		}
	}
}
