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

.block-library-html__edit {
	.block-library-html__preview-overlay {
		position: absolute;
		width: 100%;
		height: 100%;
		top: 0;
		left: 0;
	}
}

// Shown when the block's markup renders nothing in the canvas. The block keeps
// its zero size, as on the front end, and the marker floats in the start
// gutter. A zero-height block's margins collapse into the gap above it, which
// puts the block on the next one's top edge, so the marker sits just above
// that edge, between the two neighbors.
.block-library-html__no-output-marker {
	position: absolute;
	top: -$grid-unit-05;
	right: 100%;
	z-index: 1;
	display: flex;
	align-items: center;
	justify-content: center;
	width: $grid-unit-30;
	height: $grid-unit-30;
	margin-right: $grid-unit-05;
	transform: translateY(-100%);
	// Match the placeholder material the block shows when it's empty.
	border-radius: $radius-small;
	background: $white;
	box-shadow: inset 0 0 0 $border-width $gray-900;
	outline: 1px solid transparent; // Shown for Windows 10 High Contrast mode.
	color: $gray-900;
	cursor: default;

	.block-library-html__edit:hover > &,
	.block-library-html__edit.is-selected > & {
		background: var(--wp-admin-theme-color);
		box-shadow: none;
		color: $white;
	}

	// In a flex layout, margins don't collapse and the gap surrounds the block,
	// so the marker is centered on it: vertically, and in a row, where the
	// start gutter would overlap the previous item, horizontally too.
	.is-layout-flex > .block-library-html__edit > & {
		top: 50%;
		transform: translateY(-50%);
	}

	.is-layout-flex:not(.is-vertical) > .block-library-html__edit > & {
		right: auto;
		left: 50%;
		margin: 0;
		transform: translate(-50%, -50%);
	}
}

// Consecutive blocks without output share the same position, so each marker
// after the first in a run moves one step further into the gutter, and the
// markers line up side by side instead of covering each other. Past five
// blocks, the remaining markers share the last step; those blocks stay
// reachable with the arrow keys and from the List View.
$no-output-block: ".block-library-html__edit.has-no-output";
$no-output-run: $no-output-block;

@for $index from 1 through 4 {
	$no-output-run: "#{$no-output-run} + #{$no-output-block}";

	#{$no-output-run} > .block-library-html__no-output-marker {
		margin-right: $grid-unit-05 + $index * ($grid-unit-30 + $grid-unit-05);
	}
}

// The "Edit code" button in the inspector renders inside the tabs panel, so
// it needs spacing on all sides, including against the tab list above it.
.block-library-html__edit-code {
	margin: $grid-unit-20;

	.block-library-html__edit-code-button {
		justify-content: center;
	}
}

// Modal styles
.block-library-html__modal {

	// On medium and large screens, the modal component sets a max-height.
	// We want the modal to be as tall as possible also when the content is short.
	@include break-small() {
		&:not(.is-full-screen) {
			height: 9999rem;
		}
	}

	.components-modal__children-container {
		height: 100%;
	}
}

.block-library-html__modal-tabs {
	flex: 1;
}

.block-library-html__modal-content {
	flex: 1;
}

.block-library-html__modal-tab {
	height: 100%;
	display: flex;
	flex-direction: column;
	margin: 0;
	box-sizing: border-box;
	border: 1px solid $gray-200;
	border-radius: 2px;
	padding: $grid-unit-20;
	font-family: $editor-html-font;
}

.block-library-html__modal-editor {
	width: 100%;
	height: 100%;
	flex: 1;
	// Reset textarea styles to inherit from pre
	border: none;
	background: transparent;
	padding: 0;
	font-family: inherit;
	font-size: inherit;
	line-height: inherit;
	color: inherit;
	resize: none;
	// HTML input is always LTR regardless of language.
	/*rtl:ignore*/
	direction: ltr;
	overflow-x: auto;
	box-sizing: border-box;

	&:focus {
		outline: none;
		box-shadow: none;
	}
}

.block-library-html__preview {
	display: flex;
	align-items: center;
	justify-content: center;
	min-height: 0;
	overflow-y: auto;
	flex: 1;

	iframe {
		height: 100%;
	}
}
