/*!
 * Copyright 2024 Adobe. All rights reserved.
 *
 * This file is licensed to you under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License. You may obtain a copy
 * of the License at <http://www.apache.org/licenses/LICENSE-2.0>
 *
 * Unless required by applicable law or agreed to in writing, software distributed under
 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
 * OF ANY KIND, either express or implied. See the License for the specific language
 * governing permissions and limitations under the License.
 */

@import "./themes/spectrum-two.css";

/* --- High contrast settings --- */
@media (forced-colors: active) {
	.spectrum-Stepper {
		--highcontrast-stepper-border-color: CanvasText;
		--highcontrast-stepper-border-color-hover: Highlight;
		--highcontrast-stepper-border-color-focus: Highlight;
		--highcontrast-stepper-border-color-focus-hover: Highlight;
		--highcontrast-stepper-border-color-keyboard-focus: CanvasText;
		--highcontrast-stepper-focus-indicator-color: Highlight;

		&.is-invalid {
			--highcontrast-stepper-border-color: Highlight;
			--highcontrast-stepper-border-color-hover: Highlight;
			--highcontrast-stepper-border-color-focus: Highlight;
			--highcontrast-stepper-border-color-focus-hover: Highlight;
			--highcontrast-stepper-border-color-keyboard-focus: Highlight;
		}

		&.is-disabled {
			--highcontrast-stepper-border-color: GrayText;
			--highcontrast-stepper-buttons-border-width: var(--mod-stepper-border-width, var(--spectrum-stepper-border-width));
		}

		&:not(.is-disabled) {
			&:hover {
				--highcontrast-stepper-border-color: var(--highcontrast-stepper-border-color-hover);
			}

			&.is-focused,
			&:focus {
				--highcontrast-stepper-border-color: var(--highcontrast-stepper-border-color-focus);

				&:hover {
					--highcontrast-stepper-border-color: var(--highcontrast-stepper-border-color-focus-hover);
				}
			}

			&.is-keyboardFocused,
			&:focus-visible {
				--highcontrast-stepper-border-color: var(--highcontrast-stepper-border-color-keyboard-focus);
			}
		}
	}

	/* @passthrough start */
	.spectrum-Stepper-input {
		--highcontrast-textfield-border-color: var(--highcontrast-stepper-border-color);
	}
	/* @passthrough end */

	/* @passthrough start */
	.spectrum-Stepper-button {
		--highcontrast-infield-button-border-color: var(--highcontrast-stepper-border-color);
		--highcontrast-infield-button-border-color-active: var(--highcontrast-stepper-border-color);
	}
	/* @passthrough end */
}

/* --- Component-level definitions --- */
.spectrum-Stepper {
	--spectrum-stepper-border-color: var(--highcontrast-stepper-border-color, var(--mod-stepper-border-color, var(--spectrum-stepper-border-color-default)));
	--spectrum-stepper-border-radius: var(--mod-stepper-border-radius, var(--spectrum-corner-radius-100));

	--spectrum-stepper-focus-indicator-width: var(--mod-stepper-focus-indicator-width, var(--spectrum-focus-indicator-thickness));
	--spectrum-stepper-focus-indicator-gap: var(--mod-stepper-focus-indicator-gap, var(--spectrum-focus-indicator-gap));
	--spectrum-stepper-focus-indicator-color: var(--highcontrast-stepper-focus-indicator-color, var(--mod-stepper-focus-indicator-color, var(--spectrum-focus-indicator-color)));

	--spectrum-stepper-animation-duration: var(--mod-stepper-animation-duration, var(--spectrum-animation-duration-100));

	&,
	&.spectrum-Stepper--sizeM {
		--spectrum-stepper-button-width: var(--mod-stepper-button-width, var(--spectrum-in-field-button-width-stacked-medium));
		--spectrum-stepper-height: var(--mod-stepper-height, var(--spectrum-component-height-100));
	}

	&.spectrum-Stepper--sizeS {
		--spectrum-stepper-button-width: var(--mod-stepper-button-width, var(--spectrum-in-field-button-width-stacked-small));
		--spectrum-stepper-height: var(--mod-stepper-height, var(--spectrum-component-height-75));
	}

	&.spectrum-Stepper--sizeL {
		--spectrum-stepper-button-width: var(--mod-stepper-button-width, var(--spectrum-in-field-button-width-stacked-large));
		--spectrum-stepper-height: var(--mod-stepper-height, var(--spectrum-component-height-200));
	}

	&.spectrum-Stepper--sizeXL {
		--spectrum-stepper-button-width: var(--mod-stepper-button-width, var(--spectrum-in-field-button-width-stacked-extra-large));
		--spectrum-stepper-height: var(--mod-stepper-height, var(--spectrum-component-height-300));
	}

	&.is-disabled {
		--spectrum-stepper-buttons-border-width: var(--spectrum-stepper-button-border-width-disabled);
		--spectrum-stepper-buttons-background-color: var(--spectrum-stepper-buttons-background-color-disabled);
	}

	&.is-invalid {
		--mod-stepper-border-color: var(--mod-stepper-border-color-invalid, var(--spectrum-negative-border-color-default));
		--mod-stepper-border-color-hover: var(--mod-stepper-border-color-hover-invalid, var(--spectrum-negative-border-color-hover));
		--mod-stepper-border-color-focus: var(--mod-stepper-border-color-focus-invalid, var(--spectrum-negative-border-color-focus));
		--mod-stepper-border-color-focus-hover: var(--mod-stepper-border-color-focus-hover-invalid, var(--spectrum-negative-border-color-focus-hover));
		--mod-stepper-border-color-keyboard-focus: var(--mod-stepper-border-color-keyboard-focus-invalid, var(--spectrum-negative-border-color-key-focus));
	}

	&:not(.is-disabled):hover {
		--mod-stepper-border-color: var(--highcontrast-stepper-border-color-hover, var(--mod-stepper-border-color-hover, var(--spectrum-stepper-border-color-hover)));
	}

	&:not(.is-disabled).is-focused,
	&:not(.is-disabled):focus {
		--mod-stepper-border-color: var(--highcontrast-stepper-border-color-focus, var(--mod-stepper-border-color-focus, var(--spectrum-stepper-border-color-focus)));
		--mod-stepper-buttons-border-color: var(--highcontrast-stepper-border-color-focus, var(--mod-stepper-border-color-focus, var(--spectrum-stepper-border-color-focus)));

		&:hover {
			--mod-stepper-border-color: var(--highcontrast-stepper-border-color-focus-hover, var(--mod-stepper-border-color-focus-hover, var(--spectrum-stepper-border-color-focus-hover)));
			--mod-stepper-buttons-border-color: var(--highcontrast-stepper-border-color-focus-hover, var(--mod-stepper-border-color-focus-hover, var(--spectrum-stepper-border-color-focus-hover)));
		}
	}

	&:not(.is-disabled).is-keyboardFocused {
		--mod-stepper-border-color: var(--highcontrast-stepper-border-color-focus, var(--mod-stepper-border-color-focus, var(--spectrum-stepper-border-color-keyboard-focus)));
	}

	&.spectrum-Stepper--quiet {
		--mod-stepper-buttons-background-color: transparent;

		/* quiet hover */
		&:not(.is-disabled) {
			&:hover {
				--mod-stepper-buttons-background-color: transparent;
			}

			&.is-keyboardFocused {
				/* quiet focus indicator only on bottom border */
				--mod-stepper-focus-indicator-visibility: visible;
			}
		}

		&.is-invalid {
			--mod-stepper-border-color: var(--mod-stepper-border-color-invalid, var(--spectrum-negative-border-color-default));
		}
	}
}

/* --- Component-level passthroughs for nested components --- */
/* @passthrough start -- MODS for sub components */
.spectrum-Stepper {
	--mod-infield-button-border-color: var(--mod-stepper-buttons-border-color, var(--spectrum-stepper-buttons-border-color));
	--mod-infield-button-border-color-quiet-disabled: var(--spectrum-disabled-border-color);
	--mod-infield-button-border-width: var(--mod-stepper-button-border-width, var(--spectrum-stepper-button-border-width));

	--mod-textfield-border-width: var(--mod-stepper-border-width, var(--spectrum-stepper-border-width));
	--mod-textfield-border-color: var(--spectrum-stepper-border-color);

	&:not(.spectrum-Stepper--quiet) {
		--mod-textfield-border-color-disabled: var(--spectrum-stepper-border-color-disabled);
	}

	&:hover:not(.is-invalid, .is-disabled, .is-focused) {
		--mod-infield-button-border-color: var(--mod-stepper-buttons-border-color-hover, var(--spectrum-stepper-buttons-border-color-hover));
	}

	&:not(.is-disabled) {
		.is-focused,
		&:focus {
			--mod-infield-button-border-color: var(--highcontrast-stepper-border-color-focus, var(--mod-stepper-buttons-border-color-focus, var(--spectrum-stepper-buttons-border-color-focus)));
			--mod-textfield-focus-indicator-width: 0;

			&:hover {
				/* stylelint-disable-next-line spectrum-tools/no-unknown-custom-properties -- allows for --spectrum-stepper-buttons-border-color-focus-hover to be defined outside of current context */
				--mod-infield-button-border-color: var(--mod-stepper-buttons-border-color-focus-hover, var(--spectrum-stepper-buttons-border-color-focus-hover));
				--mod-textfield-focus-indicator-width: 0;
				--mod-textfield-border-color: var(--highcontrast-stepper-border-color-focus-hover, var(--mod-stepper-border-color-focus-hover, var(--spectrum-stepper-border-color-focus-hover)));
			}
		}

		&.is-keyboardFocused,
		&:focus-visible {
			--mod-infield-button-border-color: var(--highcontrast-stepper-border-color-keyboard-focus, var(--mod-stepper-buttons-border-color-keyboard-focus, var(--spectrum-stepper-buttons-border-color-keyboard-focus)));
			--mod-textfield-focus-indicator-width: 0;
			--mod-textfield-border-color: var(--highcontrast-stepper-border-color-keyboard-focus, var(--mod-stepper-border-color-keyboard-focus, var(--spectrum-stepper-border-color-keyboard-focus)));

			/* keyboard focus indicator is visible */
			outline: var(--spectrum-stepper-focus-indicator-width) solid;
			outline-color: var(--spectrum-stepper-focus-indicator-color);
			outline-offset: var(--spectrum-stepper-focus-indicator-gap);
		}
	}

	&.is-invalid {
		--mod-infield-button-border-color: var(--highcontrast-stepper-border-color, var(--mod-stepper-border-color-invalid, var(--spectrum-stepper-border-color-invalid)));
		--mod-textfield-icon-spacing-inline-start-invalid: 0;

		&:hover {
			--mod-infield-button-border-color: var(--highcontrast-stepper-border-color, var(--mod-stepper-border-color-hover-invalid, var(--spectrum-negative-border-color-hover)));
		}

		&.is-focused,
		&:focus {
			--mod-infield-button-border-color: var(--highcontrast-stepper-border-color, var(--mod-stepper-border-color-focus-invalid, var(--spectrum-stepper-border-color-focus-invalid)));

			&:hover {
				--mod-infield-button-border-color: var(--highcontrast-stepper-border-color, var(--mod-stepper-border-color-focus-hover-invalid, var(--spectrum-stepper-border-color-focus-hover-invalid)));
			}
		}

		&.is-keyboardFocused,
		&:focus-visible {
			--mod-infield-button-border-color: var(--highcontrast-stepper-border-color, var(--mod-stepper-border-color-keyboard-focus-invalid, var(--spectrum-stepper-border-color-keyboard-focus-invalid)));
		}
	}

	&.spectrum-Stepper--quiet {
		--mod-infield-button-width-stacked: var(--mod-stepper-button-width-quiet, var(--spectrum-stepper-button-width));
		--mod-infield-button-border-color: var(--spectrum-stepper-border-color);
		--mod-infield-button-border-color-quiet: var(--spectrum-stepper-border-color);
		--mod-infield-button-border-block-end-width: var(--mod-stepper-border-width, var(--spectrum-stepper-border-width));
		--mod-infield-button-stacked-bottom-border-block-end-width: var(--mod-stepper-border-width, var(--spectrum-stepper-border-width));
		--mod-infield-button-stacked-bottom-border-radius-end-end: 0;
		--mod-infield-button-stacked-bottom-border-radius-end-start: 0;
		--mod-infield-button-fill-justify-content: flex-end;
		--mod-infield-button-inner-edge-to-fill: var(--spectrum-stepper-button-edge-to-fill);
		--mod-infield-button-edge-to-fill: var(--spectrum-stepper-button-edge-to-fill);

		--mod-textfield-focus-indicator-color: transparent;
		--mod-textfield-background-color: transparent;
		--mod-textfield-border-color-hover: var(--highcontrast-stepper-border-color, var(--mod-stepper-border-color-hover, var(--spectrum-stepper-border-color-hover)));

		&:not(.is-disabled) {
			&:hover {
				--mod-textfield-border-color-hover: var(--highcontrast-stepper-border-color, var(--mod-stepper-border-color-hover, var(--spectrum-stepper-border-color-hover)));
				--mod-infield-button-border-color: var(--highcontrast-stepper-border-color, var(--mod-stepper-border-color-hover, var(--spectrum-stepper-border-color-hover)));
			}

			/* quiet focus */
			&.is-focused,
			&:focus {
				--mod-infield-button-border-color: var(--highcontrast-stepper-border-color, var(--mod-stepper-border-color-focus, var(--spectrum-stepper-border-color-focus)));

				/* stylelint-disable-next-line max-nesting-depth -- @todo reduce complexity of selectors */
				&:hover {
					--mod-infield-button-border-color: var(--highcontrast-stepper-border-color, var(--mod-stepper-border-color-focus-hover, var(--spectrum-stepper-border-color-focus-hover)));
				}
			}

			&.is-keyboardFocused {
				--mod-infield-button-border-color: var(--highcontrast-stepper-border-color, var(--mod-stepper-border-color-keyboard-focus, var(--spectrum-stepper-border-color-keyboard-focus)));

				/* stylelint-disable-next-line max-nesting-depth -- @todo reduce complexity of selectors */
				&:hover {
					--mod-infield-button-border-color: var(--highcontrast-stepper-border-color, var(--mod-stepper-border-color-hover, var(--spectrum-stepper-border-color-hover)));
				}
			}
		}
	}
}
/* @passthrough end */

/* --- Component styles --- */
.spectrum-Stepper {
	--spectrum-stepper-width: var(--mod-stepper-width, calc(var(--spectrum-stepper-height) * var(--mod-stepper-min-width-multiplier, var(--spectrum-text-field-minimum-width-multiplier)) + var(--spectrum-stepper-button-width) + (var(--mod-stepper-border-width, var(--spectrum-stepper-border-width)) * 2)));

	position: relative;
	display: inline-flex;
	flex-flow: row nowrap;

	inline-size: var(--spectrum-stepper-width);
	block-size: var(--spectrum-stepper-height);

	border-radius: var(--spectrum-stepper-border-radius);

	&::before {
		content: "";
	}
}

/* Nested textfield subcomponent */
.spectrum-Stepper-input {
	border-start-end-radius: 0;
	border-end-end-radius: 0;
	border-inline-end-width: 0;
}

/* container for stepUp and stepDown buttons */
.spectrum-Stepper-buttons {
	display: flex;
	flex-direction: column;
	justify-content: center;
	box-sizing: border-box;

	block-size: var(--spectrum-stepper-height);
	inline-size: var(--spectrum-stepper-button-width);

	border-color: var(--spectrum-stepper-border-color);
	border-style: var(--mod-stepper-buttons-border-style, var(--spectrum-stepper-buttons-border-style));
	border-width: var(--highcontrast-stepper-buttons-border-width, var(--mod-stepper-buttons-border-width, var(--spectrum-stepper-buttons-border-width)));
	border-inline-start-width: 0;

	/* Have to add border radius here to avoid overlapping textfield border */
	border-start-end-radius: var(--spectrum-stepper-border-radius);
	border-end-end-radius: var(--spectrum-stepper-border-radius);

	background-color: var(--mod-stepper-buttons-background-color, var(--spectrum-stepper-buttons-background-color));
	transition: border-color var(--spectrum-stepper-animation-duration) ease-in-out;
}

/* stylelint-disable-next-line selector-class-pattern -- @todo update hide-stepper class to standard variant syntax */
.spectrum-Stepper.hide-stepper .spectrum-Stepper-input {
	border-start-end-radius: var(--spectrum-stepper-border-radius);
	border-end-end-radius: var(--spectrum-stepper-border-radius);
	border-inline-end-width: var(--mod-stepper-border-width, var(--spectrum-stepper-border-width));
}

/* --- Quiet variant styles --- */
.spectrum-Stepper--quiet {
	/* quiet corners are not rounded */
	border-start-start-radius: 0;
	border-start-end-radius: 0;
	border-end-start-radius: 0;
	border-end-end-radius: 0;

	/* stylelint-disable selector-class-pattern -- @todo update hide-stepper class to standard variant syntax */
	&.hide-stepper .spectrum-Stepper-input {
		border-inline-end-width: 0;
		border-end-end-radius: 0;
	}
	/* stylelint-enable selector-class-pattern */

	&::after {
		visibility: var(--mod-stepper-focus-indicator-visibility, hidden);
		content: "";
		position: absolute;
		inset-block-end: calc(-1 * (var(--spectrum-stepper-focus-indicator-gap) + var(--spectrum-stepper-focus-indicator-width)));
		inset-inline-start: 0;
		inline-size: 100%;
		block-size: var(--spectrum-stepper-focus-indicator-width);
		background-color: var(--spectrum-stepper-focus-indicator-color);
	}

	/* quiet hover */
	&.is-keyboardFocused:not(.is-disabled) {
		outline: none;
	}
}
