@use "../teydea-admin" as *;

/**
 * Ordered list
 */
.tsc-ordered-list {
	background: $tsc-surface;
	border: 1px solid $tsc-border;
	border-radius: $tsc-radius-lg;
	display: flex;
	flex-direction: column;

	&__header {
		align-items: flex-start;
		display: flex;
		gap: $tsc-space-4;
		justify-content: space-between;
		padding: 18px $tsc-space-5 14px;
	}

	&__header-actions {
		flex-shrink: 0;
	}

	&__title {
		font-size: 14px;
		font-weight: 600;
		line-height: 20px;
		margin: 0;
	}

	&__description {
		color: $tsc-ink-muted;
		margin: 2px 0 0;
	}

	&__rows {
		list-style: none;
		margin: 0;
		padding: 0;
	}

	&__row {
		align-items: center;
		background: $tsc-surface;
		border-top: 1px solid $tsc-hairline;
		display: grid;
		gap: $tsc-space-2;
		grid-template-columns: 36px 28px minmax(0, 1fr) auto;
		margin: 0;
		min-height: 56px;
		// The handle's dots sit 14 px into it, so they start on the title's 20 px line.
		padding: $tsc-space-3 $tsc-space-2 $tsc-space-3 6px;
		position: relative;

		&.is-dragging {
			border-radius: $tsc-radius-md;
			box-shadow: $tsc-shadow-drag;
			z-index: 2;
		}
	}

	&__handle {
		align-items: center;
		background: none;
		border: 0;
		border-radius: 2px;
		color: $tsc-ink;
		cursor: grab;
		display: flex;
		height: 36px;
		justify-content: center;
		padding: 0;

		// The pointer sensor needs it, or a vertical drag on a touch screen scrolls the page instead.
		touch-action: none;
		width: 36px;

		svg {
			fill: currentColor;
		}

		&:focus-visible {
			box-shadow: 0 0 0 2px $tsc-accent;
			outline: 2px solid transparent;
		}
	}

	&__number {
		color: $tsc-ink-muted;
		font-variant-numeric: tabular-nums;
	}

	&__content {
		min-width: 0;
	}

	// A row's content as callers lay it out: the item's name as a link that opens it, with its summary lines under it.
	&__item {
		display: flex;
		flex-direction: column;
		gap: 2px;
		min-width: 0;
	}

	&__item-name.components-button.is-link {
		color: $tsc-ink;
		font-weight: 600;
		text-align: left;
		text-decoration: none;

		&:hover,
		&:focus {
			color: $tsc-accent;
			text-decoration: underline;
		}
	}

	&__summary {
		align-items: center;
		background: none;
		border: 0;
		border-radius: 2px;
		color: inherit;
		cursor: pointer;
		display: flex;
		font: inherit;
		gap: $tsc-space-2;
		justify-content: space-between;
		min-height: 36px;
		padding: $tsc-space-1 0;
		text-align: start;
		width: 100%;

		&:focus-visible {
			box-shadow: 0 0 0 2px $tsc-accent;
			outline: 2px solid transparent;
		}
	}

	&__summary-content {
		min-width: 0;
	}

	&__summary-icon {
		color: $tsc-ink;
		fill: currentColor;
		flex-shrink: 0;
	}

	&__details {
		grid-column: 1 / -1;
		padding: $tsc-space-2 $tsc-space-2 $tsc-space-2 $tsc-space-3;

		&[hidden] {
			display: none;
		}
	}

	&__rows:empty {
		display: none;
	}

	&__footer {
		border-top: 1px solid $tsc-hairline;
		color: $tsc-ink-muted;
		font-size: 12px;
		padding: $tsc-space-3 $tsc-space-5;
	}

	&__status {
		font-size: 12px;
		margin: 0;
		padding: 0 $tsc-space-5;

		&:not(:empty) {
			padding-bottom: $tsc-space-3;
		}
	}

	@media (max-width: $tsc-narrow-breakpoint) {
		&__handle {
			height: $tsc-touch-target;
			width: $tsc-touch-target;
		}

		&__row {
			grid-template-columns: $tsc-touch-target 24px minmax(0, 1fr) auto;
			padding-left: 2px;
		}
	}

	/**
	 * Compact: no header and no numbers, with the actions at the end, for a narrow column
	 */
	&--compact {
		.tsc-ordered-list__row {
			grid-template-columns: 36px minmax(0, 1fr) auto;

			// 6 px above and below the 36 px controls make the 48 px row, so they stay put when the row expands.
			min-height: 48px;
			padding: 6px $tsc-space-1 6px 2px;

			// The first row's tint stays inside the list's rounded corners.
			&:first-child {
				border-start-end-radius: calc(#{$tsc-radius-lg} - 1px);
				border-start-start-radius: calc(#{$tsc-radius-lg} - 1px);
				border-top: 0;
			}
		}

		.tsc-ordered-list__actions {
			border-top: 1px solid $tsc-hairline;
			display: flex;
			justify-content: flex-start;
			padding: $tsc-space-3;
		}

		// The moved row shows the move, so in a narrow column the line is left to screen readers.
		.tsc-ordered-list__status {
			clip-path: inset(50%);
			height: 1px;
			overflow: hidden;
			padding: 0;
			position: absolute;
			white-space: nowrap;
			width: 1px;
		}

		@media (max-width: $tsc-narrow-breakpoint) {
			.tsc-ordered-list__row {
				grid-template-columns: $tsc-touch-target minmax(0, 1fr) auto;
			}
		}
	}

	/**
	 * Empty: a dashed box with the note and the actions in its middle
	 */
	&--empty {
		border-color: $tsc-field-border;
		border-style: dashed;
		padding: $tsc-space-5 $tsc-space-4;

		.tsc-ordered-list__empty {
			color: $tsc-ink-muted;
			text-align: center;

			p {
				margin: 0;
			}
		}

		.tsc-ordered-list__actions {
			border-top: 0;
			justify-content: center;
			padding: $tsc-space-3 0 0;
		}
	}
}
