@use "~@wordpress/base-styles/colors" as wp-colors;

// Modal
.newspack-newsletters-modal {
	&__screen-overlay {
		animation: none;
		background: white;
		top: 46px;

		@media only screen and (min-width: 783px) {
			left: 36px;
			top: 32px;

			// Fullscreen mode
			.is-fullscreen-mode & {
				left: 60px;
				top: 0;
			}
		}

		@media only screen and (min-width: 961px) {
			// Not folded sidebar
			body:not(.folded, .is-fullscreen-mode) & {
				left: 160px;
			}
		}

		.components-modal__header {
			border-color: wp-colors.$gray-300;
			height: 60px;
			padding: 0 24px;
		}

		.components-modal__content {
			justify-content: start;
			margin-top: 60px;
			padding: 0;

			@media only screen and (min-width: 783px) {
				.is-fullscreen-mode & {
					margin-left: -60px;
					width: calc(100% + 60px);
				}
			}
		}
	}

	&__frame {
		animation: none;
		border: 0;
		box-shadow: none;
		height: 100%;
		margin: 0;
		max-height: 100%;
		max-width: 100%;
		min-height: 100%;
		min-width: 100%;
		overflow-y: hidden;
		transform: none;
		width: 100%;
		inset: 0;

		@media only screen and (min-width: 783px) {
			.is-fullscreen-mode & {
				overflow: visible;
			}
		}

		.components-modal__header-heading {
			display: none;
			font-size: 0.8rem;
			line-height: 1.25;

			@media only screen and (min-width: 600px) {
				display: block;
			}

			@media only screen and (min-width: 783px) {
				font-size: 1rem;
				line-height: 1;
			}
		}

		.components-modal__header + div:not([class]) {
			height: 100%;
		}
	}

	&__content {
		background: white;
		height: 100%;
		left: 0;
		margin: 0;
		width: 100%;

		@media only screen and (min-width: 783px) {
			display: grid;
			gap: 0;
			grid-template-columns: 280px 1fr;
			grid-template-rows: 1fr;
		}

		&__sidebar {
			background: wp-colors.$gray-100;
			border-bottom: 1px solid wp-colors.$gray-300;

			@media only screen and (min-width: 783px) {
				border-bottom: none;
				border-right: 1px solid wp-colors.$gray-300;
			}

			&-wrapper {
				padding: 24px;
				position: sticky;
				top: 0;
			}

			p {
				margin: 0;
			}
		}

		&__layout-buttons {
			display: grid;
			grid-gap: 4px;
			grid-template-columns: repeat(2, 1fr);
			padding: 24px 0 0;

			@media only screen and (min-width: 783px) {
				grid-template-columns: 1fr;
			}
		}
	}

	&__action-buttons {
		align-items: center;
		display: flex;
		flex-wrap: wrap;
		justify-content: flex-end;
		position: absolute;
		right: 24px;
		top: 12px;
		z-index: 11;

		.components-button + .components-button {
			margin-left: 8px;
		}
	}

	&__settings {
		align-items: flex-start;
		display: flex;
		justify-content: center;

		@media only screen and (min-width: 600px) {
			display: flex;
		}

		&-wrapper {
			flex: 0 0 100%;
			max-width: 600px;
			padding-left: 24px;
			padding-right: 24px;
			position: relative;

			@media only screen and (min-width: 648px) {
				max-width: 648px;
			}
		}

		.components-spinner {
			left: 50%;
			margin: -9px 0 0 -9px;
			margin-left: -9px;
			position: absolute;
			top: 50%;
		}

		.error {
			color: wp-colors.$alert-red;
		}

		.components-base-control {
			&.has-error {
				input[type="text"] {
					border-color: wp-colors.$alert-red;
				}
			}
		}

		.components-text-control__input,
		.components-select-control__input {
			margin: 0;
			max-width: 100%;
			width: 100%;
		}
	}

	&__in-flight {
		pointer-events: none;

		> div > *:not(.components-spinner) {
			opacity: 0.3;
		}
	}

	&__layouts {
		max-height: 100%;
		padding: 24px;

		@media only screen and (min-width: 783px) {
			overflow-y: scroll;
		}

		&--loading {
			display: flex;
			justify-content: center;
			align-items: center;
		}

		.newspack-newsletters-layouts {
			display: grid;
			gap: 16px;
			grid-template-columns: repeat(2, 1fr);
			grid-auto-rows: minmax(min-content, max-content);
			overflow: hidden;
			padding: 0;

			@media only screen and (min-width: 600px) {
				grid-template-columns: 1fr;
			}

			@media only screen and (min-width: 783px) {
				grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
			}

			&__item {
				cursor: pointer;
				margin: 0;
				width: 100%;
				text-align: center;

				&.is-active {
					.newspack-newsletters-layouts__item-preview {
						pointer-events: none;
						border-color: currentcolor;
						position: relative;

						&::before {
							border: 1px solid;
							content: "";
							display: block;
							position: absolute;
							inset: 0;
							z-index: 1;
						}
					}
				}

				button {
					margin: 0;
					height: 20px;
					&.is-destructive {
						color: wp-colors.$alert-red;
						height: auto;
					}
				}
			}

			&__item-preview {
				background: white;
				border: 1px solid wp-colors.$gray-300;
				border-radius: 2px;
				overflow: hidden;
				padding: 0 0 75%;
				position: relative;
				width: 100%;

				&::before {
					border: 2px solid white;
					content: "";
					display: block;
					position: absolute;
					inset: 0;
					z-index: 1;
				}

				&:hover,
				&:focus {
					border-color: var(--wp-admin-theme-color);
				}

				&:hover {
					.block-editor-block-preview__container {
						margin-top: -25%;
					}
				}

				.block-editor-block-preview__container,
				.block-editor-block-preview__content-iframe {
					cursor: pointer;
					position: absolute;
					inset: 0 auto auto;
				}

				.block-editor-block-preview__container {
					transition: margin 500ms ease-in-out;
				}
			}

			&__item-label {
				padding: 4px 2px;
				text-align: center;

				&:empty {
					display: none;
				}
			}

			&--empty {
				> * {
					&:first-child {
						margin-top: 0;
					}

					&:last-child {
						margin-bottom: 0;
					}
				}
			}
		}
	}

	&__preview {
		grid-column-start: 2;
		grid-row-start: 1;
		// stylelint-disable-next-line
		grid-row-end: 3;
		align-items: center;
		background: white;
		border: 1px solid wp-colors.$gray-300;
		border-top: none;
		display: none;
		justify-content: center;
		overflow: hidden;
		position: relative;

		@media only screen and (min-width: 600px) {
			display: flex;
		}

		.block-editor-block-preview {
			&__container {
				align-self: flex-start;
				margin: 0 auto;
				max-width: 600px;
			}
		}
	}
}

// Posts Inserter - Preview
.block-editor-block-preview__container,
.block-editor-block-preview__content-iframe {
	background: transparent;

	.wp-block[data-type="newspack-newsletters/posts-inserter"] {
		padding: 0;
	}

	.newspack-posts-inserter {
		border: 0;
		padding: 0;

		&__header,
		&__footer {
			display: none;
		}

		&__preview {
			border: 0;
			margin: 0;
		}

		.block-editor-block-preview__container {
			height: 100% !important;
			max-height: 100%;
			overflow: hidden;

			.newspack-newsletters-modal__layouts & {
				position: relative;
			}
		}

		.block-editor-block-preview__content {
			transform: scale(1) !important;
			width: 600px !important;
		}
	}
}
