@use '../../../tokens/variables';

/* Patterns - Content - Wizard */
////
/// @group Patterns-Wizard
/// Patterns - Content - Wizard

///
.osui-wizard {
	display: flex;

	// Cases where there is no list child
	&:not(:has(> .list)) {
		&.is-horizontal {
			flex-direction: row;
		}

		&.is-vertical {
			flex-direction: column;
		}
	}

	// Cases where there is a list as child of the wizard
	&:has(> .list) {
		&.is-horizontal {
			.list {
				flex-direction: row;
			}
		}

		&.is-vertical {
			.list {
				flex-direction: column;
			}
		}
	}

	&.is-vertical {
		[data-block*='WizardItem']:last-child {
			.osui-wizard-item {
				margin-block-end: variables.$token-scale-0;
			}
		}

		.osui-wizard-item {
			align-items: center;
			flex-direction: row;
			margin-block-end: var(--osui-wizard-item-spacing);

			&.is-reversed {
				flex-direction: row-reverse;

				.osui-wizard-item-label {
					text-align: end;
				}

				.osui-wizard-item-icon-wrapper {
					margin-block: variables.$token-scale-0;
					margin-inline-end: variables.$token-scale-0;
					margin-inline-start: variables.$token-scale-200;
				}
			}

			.osui-wizard-item-icon-wrapper {
				margin-block: variables.$token-scale-0;
				margin-inline-end: variables.$token-scale-200;
				margin-inline-start: variables.$token-scale-0;
				width: auto;

				// Same marker-centre-to-marker-centre rule as the horizontal connector, on
				// the block axis. Here `100%` is the marker itself (the wrapper shrinks to
				// it), so the item's own `margin-bottom` is what carries the line up to the
				// previous marker's centre.
				&:before {
					bottom: 50%;
					height: calc(100% + #{variables.$token-scale-800});
					left: 50%;
					top: auto;
					transform: translateY(0) translateX(-50%);
					width: var(--osui-wizard-connector-size);
				}

				// With an empty marker the dot no longer sets the row height — the label's
				// line-height does — so `100%` (the marker) falls short of the previous
				// centre. Centre-to-centre is the row pitch, which here is the label plus
				// the item's own spacing; both are read from their knobs so the connector
				// follows any change to either.
				&:has(.osui-wizard-item-icon:empty):before {
					height: calc(var(--osui-wizard-label-line-height) + var(--osui-wizard-item-spacing));
				}
			}
		}
	}

	&.is-interactive {
		.osui-wizard-item.is-past {
			cursor: pointer;
			pointer-events: auto;
		}
	}

	// List container
	.list {
		display: flex;
		width: 100%;
	}

	[data-block*='WizardItem'] {
		align-items: center;
		cursor: default;
		display: flex;
		flex-direction: column;
		flex: 1;
		pointer-events: none;
		position: relative;
		width: 100%;

		&:first-child {
			.osui-wizard-item-icon-wrapper {
				&:before {
					content: none;
				}
			}
		}
	}
}

/* Hybrid Service Studio => Service Studio Preview */
html[data-uieditorversion^='1'] {
	.osui-wizard {
		.OSBlockWidget {
			// Service Studio Preview
			& {
				-servicestudio-display: contents;
			}

			&:first-child {
				.osui-wizard-item-icon-wrapper {
					&:before {
						& {
							-servicestudio-content: none;
						}
					}

					&.is-reversed {
						& {
							-servicestudio-flex-direction: column-reverse;
						}
					}
				}
			}
		}

		&.is-vertical {
			.OSBlockWidget {
				.osui-wizard-item {
					&.is-reversed {
						& {
							-servicestudio-flex-direction: row-reverse;
						}
					}
				}

				&:last-child {
					& {
						-servicestudio-margin-bottom: variables.$token-scale-0;
					}
				}
			}
		}
	}

	.osui-wizard-item {
		& {
			-servicestudio-display: flex;
			-servicestudio-flex-direction: column;
			-servicestudio-width: 100%;
		}
	}
}
