// WooCommerce quantity field with the −/+ stepper from
// src/shared/quantity-stepper.js. Import with
// `@use "../../shared/scss/quantity" as *;` and include inside the container:
// `noah-quantity-form` for single product cart forms (Add To Cart block,
// Quick View), `noah-quantity` for the field alone (Cart Table).
@use "mixins" as *;

@mixin noah-quantity-form {

	@include noah-quantity;

	// Quantity and button on one row, same height. Variable products keep their
	// attribute table above; grouped products keep their table.
	form.cart:not(.variations_form):not(.grouped_form),
	.woocommerce-variation-add-to-cart {
		display: flex;
		flex-wrap: wrap;
		align-items: stretch;
		gap: 0.5rem;

		// WooCommerce's clearfix pseudo-elements would become flex items (extra gap).
		&::before,
		&::after {
			content: none;
		}

		// Hooked extras (wishlist, compare, add-on fields…) go on their own row.
		> :not(.quantity):not(.single_add_to_cart_button):not([type="hidden"]) {
			flex-basis: 100%;
		}

		.quantity {
			margin: 0;
		}

		.single_add_to_cart_button {
			margin: 0;
		}
	}
}

@mixin noah-quantity {

	.quantity {
		display: inline-flex;
		align-items: stretch;
		min-height: 3rem;
		box-sizing: border-box;
		border: 1px solid color-mix(in srgb, currentcolor 22%, transparent);
		border-radius: 999px;
		background: var(--wp--preset--color--base, #fff);
		overflow: hidden;

		@include noah-transition(border-color, box-shadow);

		&:focus-within {
			border-color: currentcolor;
			box-shadow: 0 0 0 1px currentcolor;
		}

		// Sold individually: WooCommerce prints a hidden input only.
		&:has(> input[type="hidden"]:only-of-type) {
			display: none;
		}

		input.qty {
			width: 2.25rem;
			min-height: 0;
			margin: 0;
			padding: 0 0.25rem;
			border: 0;
			border-radius: 0;
			background: transparent;
			box-shadow: none;
			color: inherit;
			font: inherit;
			font-weight: 600;
			text-align: center;
			-moz-appearance: textfield;
			appearance: textfield;

			&::-webkit-outer-spin-button,
			&::-webkit-inner-spin-button {
				margin: 0;
				-webkit-appearance: none;
			}

			&:focus {
				outline: none;
			}
		}

		// No stepper (script not loaded yet): give the lone input some room.
		&:not(.noah-qty) input.qty {
			width: 4.5rem;
			padding-inline: 1rem;
		}
	}

	.noah-qty__btn {
		display: inline-flex;
		flex: 0 0 auto;
		align-items: center;
		justify-content: center;
		width: 2.25rem;
		margin: 0;
		padding: 0;
		border: 0;
		border-radius: 0;
		background: transparent;
		color: inherit;
		font-size: 1.25rem;
		line-height: 1;
		cursor: pointer;

		@include noah-transition(background-color);

		&:hover {
			background: color-mix(in srgb, currentcolor 8%, transparent);
		}

		&:focus-visible {
			outline: 2px solid currentcolor;
			outline-offset: -4px;
			border-radius: 999px;
		}

		&:disabled {
			opacity: 0.35;
			cursor: not-allowed;
		}
	}
}
