@use "@wordpress/base-styles/variables" as *;
@use "@wordpress/base-styles/mixins" as *;

.components-tab-panel__tabs {
	display: flex;
	align-items: stretch;
	flex-direction: row;

	&[aria-orientation="vertical"] {
		flex-direction: column;
	}
}

.components-tab-panel__tabs-item {
	position: relative;
	isolation: isolate;
	border-radius: 0;
	height: $grid-unit-60 !important; // https://github.com/WordPress/gutenberg/pull/65075#discussion_r1746282734
	background: transparent;
	border: none;
	cursor: var(--wpds-cursor-control);
	padding: 3px var(--wpds-dimension-padding-lg); // Use padding to offset the is-active border, this benefits Windows High Contrast mode
	margin-left: 0;
	font-weight: var(--wpds-typography-font-weight-default);

	&[aria-selected="true"] {
		cursor: default;

	}

	&:disabled,
	&[aria-disabled="true"] {
		color: var(--wpds-color-foreground-interactive-neutral-disabled);
	}

	// Keep Button's hover color from overriding the resting tab color.
	.components-tab-panel__tabs &:not(:disabled, [aria-disabled="true"]) {
		color: var(--wpds-color-foreground-interactive-neutral);

		&:is(:hover, :active):not([aria-selected="true"]),
		&:focus-visible {
			color: var(--wpds-color-foreground-interactive-neutral-active);

			&::before {
				background-color: var(--wpds-color-background-interactive-neutral-weak-active);
			}
		}
	}

	&:focus:not(:disabled) {
		position: relative;
		outline: none;
	}

	// Tab indicator
	&::after {
		content: "";
		position: absolute;
		right: 0;
		bottom: 0;
		left: 0;
		pointer-events: none;

		// Draw the indicator.
		background: currentColor;
		height: calc(0 * var(--wpds-border-width-focus));
		border-radius: 0;

		// Animation
		@media not (prefers-reduced-motion) {
			transition: height 0.1s linear;
		}
	}

	// Active.
	&.is-active::after {
		height: calc(1 * var(--wpds-border-width-focus));

		// Windows high contrast mode.
		outline: 2px solid transparent;
		outline-offset: -1px;
	}

	// Interaction background and focus ring.
	&::before {
		content: "";
		position: absolute;
		z-index: -1;
		inset: var(--wpds-dimension-padding-md);
		pointer-events: none;
		border-radius: var(--wpds-border-radius-sm);
	}

	&:focus-visible::before {
		@include outset-ring__focus();
		outline-offset: 0;
	}

	.components-tab-panel__tabs[aria-orientation="vertical"] & {
		&::before {
			inset: 0;
			outline-offset: calc(-1 * var(--wpds-border-width-focus));
		}

		& .components-tab-panel__tabs-item-label {
			position: relative;
			display: inline-flex;
		}

		&::after {
			inset-block-start: 50%;
			inset-block-end: auto;
			inset-inline: 0 auto;
			width: 0;
			height: var(--wpds-dimension-size-sm);
			transform: translateY(-50%);

			@media not (prefers-reduced-motion) {
				transition-property: width;
			}
		}

		&:not(.has-icon)::after {
			content: none;
		}

		& .components-tab-panel__tabs-item-label::after {
			content: "";
			position: absolute;
			inset-block: 0;
			inset-inline-start: calc(-1 * var(--wpds-dimension-padding-lg));
			width: 0;
			background: currentColor;
			pointer-events: none;

			@media not (prefers-reduced-motion) {
				transition: width 0.1s linear;
			}
		}

		&.is-active::after,
		&.is-active .components-tab-panel__tabs-item-label::after {
			width: var(--wpds-border-width-focus);
			outline: 2px solid transparent;
			outline-offset: -1px;
		}
	}
}

.components-tab-panel__tab-content {
	&:focus {
		outline: none;
	}

	&:focus-visible {
		@include outset-ring__focus();
		outline-offset: 0;
	}
}
