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

/**
 * The admin screen around the frame
 *
 * The server hides every admin notice and the admin footer on an opted-in screen, so nothing
 * flashes before this stylesheet loads; the rules below only lay the frame out.
 */
body.teydeastudio-settings-frame {
	@include admin-menu-width-variable;
	@include disabled-primary-buttons;

	#wpcontent {
		padding-left: 0;
	}

	#wpbody-content {
		padding-bottom: 0;
	}

	#wpfooter {
		display: none;
	}
}

/**
 * Settings frame
 */
.tsc-settings-frame {
	background: $tsc-surface;
	border-radius: $tsc-radius-panel;
	box-sizing: border-box;
	color: $tsc-ink;
	font-size: 13px;
	line-height: 20px;
	margin: 0 $tsc-space-2 $tsc-space-2 0;
	min-height: calc(100vh - var(--wp-admin--admin-bar--height, 32px) - #{$tsc-space-2});

	/**
	 * Above the narrow layout the panel fills the window, as the Site Editor's does: the header
	 * and the tabs stay put and only the tab's content scrolls, so the rounded corners and the
	 * admin frame around them stay in view. It is fixed to the window rather than placed in the
	 * page, because an admin menu taller than the window makes the page scroll, and a panel in
	 * the page would scroll up with it and leave the empty admin background below. The content
	 * is a size container, so a card that stays in view inside it can be capped at its height
	 * (`100cqh`), and what sticks inside it with `top: 0` stops at its 24 px padding.
	 */
	@media (min-width: #{$tsc-narrow-breakpoint + 1}) {
		display: flex;
		flex-direction: column;
		inset-block: var(--wp-admin--admin-bar--height, 32px) $tsc-space-2;
		inset-inline: var(--tsc-admin-menu-width, 160px) $tsc-space-2;
		margin: 0;
		min-height: 0;
		overflow: hidden;
		position: fixed;

		&__header,
		&__notices,
		&__tabs > .components-tab-panel__tabs {
			flex: none;
		}

		// Messages taller than this would push the tab's content out of the panel, which clips them.
		&__notices {
			max-height: 40%;
			overflow-y: auto;
			overscroll-behavior: contain;
		}

		&__body,
		&__tabs {
			display: flex;
			flex: 1;
			flex-direction: column;
			min-height: 0;
		}

		&__content,
		&__tabs > .components-tab-panel__tab-content {
			container-type: size;
			flex: 1;
			min-height: 0;
			overflow-y: auto;

			// A long admin menu makes the page itself scrollable, and the wheel would move on to it, and the whole panel with it, once the content reaches its end.
			overscroll-behavior: contain;
		}
	}

	/**
	 * Header
	 */
	&__header {
		align-items: center;
		display: flex;
		flex-wrap: wrap;
		gap: $tsc-space-3 $tsc-space-4;
		justify-content: space-between;
		padding: $tsc-space-5 $tsc-space-6 $tsc-space-4;
	}

	&__identity {
		align-items: center;
		display: flex;
		flex: 1 1 auto;
		gap: $tsc-space-3;
		min-width: 0;
	}

	&__heading {
		min-width: 0;
	}

	&__title-row {
		align-items: center;
		display: flex;
		flex-wrap: wrap;
		gap: $tsc-space-1 $tsc-space-2;

		// The label sets itself at the top of a row, above the middle of the title.
		.tsc-status-label {
			align-self: center;
		}
	}

	&__title {
		color: $tsc-ink;
		font-size: 20px;
		font-weight: 600;
		line-height: 26px;
		margin: 0;
		padding: 0;
		white-space: nowrap;
	}

	// Core's 1.5 line height comes to 19.5 px here; that half pixel would shift everything under the
	// header off the pixel grid, where 1x screens draw icons and text half a pixel apart.
	&__description {
		color: $tsc-ink-muted;
		line-height: 20px;
		margin: 2px 0 0;
	}

	&__actions {
		align-items: center;
		display: flex;
		flex-wrap: wrap;
		gap: $tsc-space-2;
	}

	// The ⋯ menu stands in for Help, History, the status and Discard below 1,200 px only.
	&__menu {
		display: none;
	}

	/**
	 * Below 1,200 px Help, History, the status and Discard go into the ⋯ menu, to the left of
	 * Save, and Save and ⋯ stay on the title row.
	 */
	@media (max-width: 1199px) {
		&__header {
			flex-wrap: nowrap;
		}

		&__actions {
			flex: none;
			flex-wrap: nowrap;
		}

		&__menu {
			display: block;
		}

		.tsc-help-panel__button,
		.tsc-settings-history__button,
		.tsc-save-status {
			display: none;
		}
	}

	// The dot on ⋯ says something is unsaved while the menu is closed.
	&__menu-toggle {
		position: relative;
	}

	&__menu-dot {
		background: $tsc-accent;
		border: 2px solid $tsc-surface;
		border-radius: 50%;
		height: 8px;
		position: absolute;
		right: 5px;
		top: 5px;
		width: 8px;
	}

	/**
	 * Body
	 */
	&__notices {
		display: flex;
		flex-direction: column;
		gap: $tsc-space-3;
		padding: 0 $tsc-space-6 $tsc-space-4;

		.components-notice {
			margin: 0;
		}
	}

	&__content {
		border-top: 1px solid $tsc-hairline;
		padding: $tsc-space-6;
	}

	/**
	 * External links hover like every other link in the admin, in the color scheme's darker
	 * accent, rather than in the components' own mix of the accent with black
	 */
	.components-external-link:hover,
	.components-external-link:focus {
		color: $tsc-accent-hover;
	}

	/**
	 * Notices: the notice's own padding is the only space inside it, so paragraphs drop the
	 * admin's 13 px margins. The space around a notice is the gap of the column it sits in.
	 */
	.components-notice__content {
		p {
			margin: 0;
		}

		p + p {
			margin-top: $tsc-space-1;
		}
	}

	/**
	 * Tabs, on core's TabPanel
	 */
	&__tabs {
		> .components-tab-panel__tabs {
			border-bottom: 1px solid $tsc-hairline;
			gap: $tsc-space-6;
			padding: 0 $tsc-space-6;
		}

		> .components-tab-panel__tabs .components-tab-panel__tabs-item {
			padding-left: 0;
			padding-right: 0;
		}

		> .components-tab-panel__tab-content {
			padding: $tsc-space-6;
		}
	}

	// A tab that asks for it through `useFullWidthFrameTab()` runs to the panel's edges, and leaves the scrolling to its content.
	@media (min-width: #{$tsc-narrow-breakpoint + 1}) {
		&__tabs--full-width > .components-tab-panel__tab-content {
			overflow: hidden;
			padding: 0;
		}
	}

	// A bottom sheet's bar in a tab runs to the panel's edges, and stays at the bottom of the screen.
	&__tabs > .components-tab-panel__tab-content .tsc-bottom-sheet-bar {
		margin: 0 (-$tsc-space-6) (-$tsc-space-6);
	}

	/**
	 * Narrow screens: full bleed, 44 px targets, no description, so the title row fits
	 */
	@media (max-width: $tsc-narrow-breakpoint) {
		border-radius: 0;
		margin: 0;

		&__header {
			gap: $tsc-space-2;
			padding: 14px $tsc-space-4;
		}

		&__title {
			font-size: 18px;
		}

		&__description {
			display: none;
		}

		&__notices {
			padding: 0 $tsc-space-4 $tsc-space-4;
		}

		&__content,
		&__tabs > .components-tab-panel__tab-content {
			padding: $tsc-space-4;
		}

		&__tabs > .components-tab-panel__tab-content .tsc-bottom-sheet-bar {
			margin: 0 (-$tsc-space-4) (-$tsc-space-4);
		}

		&__tabs > .components-tab-panel__tabs {
			overflow-x: auto;
			padding: 0 $tsc-space-4;
		}

		.tsc-product-icon {
			height: 32px;
			width: 32px;
		}

		&__actions .components-button.has-icon {
			min-width: $tsc-touch-target;
		}

		.components-button:not(.is-link),
		.components-text-control__input,
		.components-select-control__input,
		input[type="text"],
		input[type="number"],
		select {
			min-height: $tsc-touch-target;
		}
	}
}

/**
 * What is unsaved, the first line of the ⋯ menu, which opens outside the frame
 */
.tsc-settings-frame__menu-status {
	border-bottom: 1px solid $tsc-hairline;
	padding: 10px $tsc-space-3 $tsc-space-2;
}

.tsc-save-status {
	align-items: center;
	display: flex;
	gap: 6px;

	&__text {
		align-items: center;
		color: $tsc-ink;
		display: inline-flex;
		gap: 6px;
		margin-right: 6px;

		&--muted {
			color: $tsc-ink-muted;
		}

		&--success {
			color: $tsc-success;
			font-weight: 500;

			svg {
				fill: currentColor;
			}
		}
	}

	&__dot {
		background: $tsc-accent;
		border-radius: 50%;
		display: inline-block;
		flex: none;
		height: 6px;
		width: 6px;
	}
}

.tsc-settings-frame__menu-status .tsc-save-status__text {
	gap: $tsc-space-2;
	margin-right: 0;
}

/**
 * The notice about a failed save, inside the panel
 */
.tsc-save-error-notice {
	p {
		margin: 0;
	}

	p + p {
		margin-top: $tsc-space-1;
	}

	&__actions {
		display: flex;
		flex-wrap: wrap;
		gap: $tsc-space-2;
		margin-top: 10px;
	}
}
