@use '../../shared/styles/details-base';
@use '../../shared/styles/utils';

body {
	--gl-patch-ghost-color: var(--color-foreground--50);
	--gitlens-tree-foreground: var(--vscode-sideBar-foreground, var(--vscode-foreground));
}

// When menu-list is inside a popover, the popover body provides the visual
// container (border, background, shadow). Strip menu-list's own chrome to avoid doubling.
gl-popover[appearance='menu'] menu-list {
	padding-bottom: 0;
	background: none;
	border: none;
}

// Make gl-popover a proper flex child inside button groups
.button-group > gl-popover {
	display: inline-flex;
	align-self: stretch;
}

.button-group > gl-popover > gl-button {
	height: 100%;
}

.commit-action {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	height: 21px;
	padding: var(--gl-space-2);
	vertical-align: text-bottom;
	color: inherit;
	text-decoration: none;
	border-radius: 0.25em;

	> * {
		pointer-events: none;
	}

	&:focus {
		outline: var(--gl-border-width) solid var(--vscode-focusBorder);
		outline-offset: -1px;
	}

	&:hover {
		color: var(--vscode-foreground);
		text-decoration: none;

		@include utils.dark-theme($selectorPostfix: ' &') {
			background-color: var(--color-background--lighten-15);
		}

		@include utils.light-theme($selectorPostfix: ' &') {
			background-color: var(--color-background--darken-15);
		}
	}

	&.is-active {
		@include utils.dark-theme($selectorPostfix: ' &') {
			background-color: var(--color-background--lighten-10);
		}

		@include utils.light-theme($selectorPostfix: ' &') {
			background-color: var(--color-background--darken-10);
		}
	}

	&.is-disabled {
		pointer-events: none;
		opacity: 0.5;
	}

	&.is-hidden {
		display: none;
	}
}

.top-details {
	position: sticky;
	top: 0;
	z-index: var(--gl-z-sticky);
	padding: {
		inset: 0.1rem var(--gitlens-scrollbar-gutter-width) 0.5rem var(--gitlens-gutter-width);
	}

	background-color: var(--vscode-sideBar-background);

	&__actionbar {
		display: flex;
		flex-flow: row wrap;
		align-items: center;
		justify-content: space-between;

		&-group {
			display: flex;
			flex: none;
			flex-direction: row;
			max-width: 100%;
		}

		&--highlight {
			padding: 0 var(--gl-space-4) var(--gl-space-2);
			overflow: hidden;
			text-overflow: ellipsis;
			font-family: var(--vscode-editor-font-family);
			white-space: nowrap;
			border: var(--gl-border-width) solid var(--color-background--level-15);
			border-radius: var(--gl-radius-sm);
		}

		&.is-pinned {
			background-color: var(--color-alert-warningBackground);
			border-radius: var(--gl-radius-sm);
			box-shadow: 0 0 0 0.1rem var(--color-alert-warningBorder);

			.commit-action:hover,
			.commit-action.is-active {
				background-color: var(--color-alert-warningHoverBackground);
			}
		}
	}

	&__sha {
		margin: 0 0.5rem 0 0.25rem;
	}

	&__authors {
		flex-basis: 100%;
		padding-top: 0.5rem;
	}

	&__author {
		& + & {
			margin-top: 0.5rem;
		}
	}
}

.title {
	margin: var(--gl-space-2) 0 var(--gl-space-8);
	font-size: 1.6rem;
	font-weight: 600;

	&__badge {
		float: right;
	}
}

.message-block__text strong:not(:only-child) {
	display: inline-block;
	margin-bottom: 0.52rem;
}

.patch-base {
	display: flex;
	flex-direction: row;
	gap: var(--gl-space-4);
	align-items: center;
	justify-content: flex-end;
	padding: {
		top: 0.1rem;
		bottom: 0.1rem;
	}

	:first-child {
		margin-right: auto;
	}
}

.section--action {
	border-top: var(--gl-border-width) solid var(--vscode-sideBarSectionHeader-border);
	padding: {
		top: 1.5rem;
		bottom: 1.5rem;
	}

	> :first-child {
		padding-top: 0;
	}
}

.change-list {
	display: flex;
	flex: 1;
	flex-direction: column;
	min-height: 0;
	margin-bottom: var(--gl-space-10);
}

// TODO: these form styles should be moved to a common location
.message-input {
	padding-top: var(--gl-space-8);

	&__control {
		flex: 1;
		width: 100%;
		padding: 0.5rem;
		font-family: inherit;
		font-size: var(--gl-font-base);
		line-height: 1.4;
		color: var(--vscode-input-foreground);
		background: var(--vscode-input-background);
		border: var(--gl-border-width) solid var(--vscode-input-border, transparent);
		border-radius: var(--gl-input-border-radius);

		&::placeholder {
			color: var(--vscode-input-placeholderForeground);
		}

		&:invalid {
			background-color: var(--vscode-inputValidation-errorBackground);
			border-color: var(--vscode-inputValidation-errorBorder);
		}

		&:focus {
			outline: var(--gl-border-width) solid var(--vscode-focusBorder);
			outline-offset: -1px;
		}

		&:disabled {
			pointer-events: none;
			cursor: not-allowed;
			opacity: 0.4;
		}

		&--text {
			overflow: hidden;
			white-space: nowrap;
			opacity: 0.7;
		}
	}

	&__action {
		flex: none;
	}

	&__select {
		position: relative;
		display: flex;
		flex: 1;
		align-items: stretch;

		&-icon {
			position: absolute;
			top: 0;
			left: 0;
			display: flex;
			align-items: center;
			justify-content: center;
			width: 2.4rem;
			height: 100%;
			color: var(--vscode-foreground);
			pointer-events: none;
		}

		&-caret {
			position: absolute;
			top: 0;
			right: 0;
			display: flex;
			align-items: center;
			justify-content: center;
			width: 2.4rem;
			height: 100%;
			color: var(--vscode-foreground);
			pointer-events: none;
		}
	}

	&__select &__control {
		box-sizing: border-box;
		padding-right: var(--gl-space-24);
		padding-left: var(--gl-space-24);
		appearance: none;
	}

	&__menu {
		position: absolute;
		top: 0.8rem;
		right: 0;
	}

	&--group {
		display: flex;
		flex-direction: row;
		gap: var(--gl-space-6);
		align-items: stretch;
	}

	&--with-menu {
		position: relative;
	}
}

textarea.message-input__control {
	min-height: 4rem;
	max-height: 40rem;
	resize: vertical;
}

.user-selection-container {
	max-height: (2.4rem * 4);
	overflow: auto;
}

.user-selection {
	--gl-avatar-size: 2rem;

	display: flex;
	flex-direction: row;
	gap: var(--gl-space-4);
	align-items: center;
	height: 2.4rem;

	&__avatar {
		flex: none;
	}

	&__info {
		flex: 1;
		min-width: 0;
		white-space: nowrap;
	}

	&__name {
		overflow: hidden;
		text-overflow: ellipsis;
	}

	&__actions {
		flex: none;
		color: var(--gl-patch-ghost-color);

		gl-button::part(base) {
			padding-block: var(--gl-space-4);
			padding-right: 0;
		}

		gl-button code-icon {
			pointer-events: none;
		}
	}

	&__check:not(.is-active) {
		opacity: 0;
	}
}

.h {
	&-spacing {
		margin-bottom: 1.5rem;
	}

	&-deemphasize {
		margin: var(--gl-space-8) 0 var(--gl-space-4);
		opacity: 0.7;
	}

	&-no-border {
		--vscode-sideBarSectionHeader-border: transparent;
	}
}

.alert {
	display: flex;
	flex-direction: row;
	align-items: center;
	padding: var(--gl-space-8) var(--gl-space-12);
	line-height: 1.2;
	color: var(--color-alert-foreground);
	background-color: var(--color-alert-errorBackground);
	border-left: 0.3rem solid var(--color-alert-errorBorder);

	code-icon {
		margin-right: var(--gl-space-4);
		vertical-align: baseline;
	}

	&__content {
		margin: 0;
		font-size: var(--gl-font-md);
		line-height: 1.2;
		text-align: left;
	}
}

.commit-detail-panel {
	display: flex;
	flex-direction: column;
	height: 100vh;
	overflow: hidden;
}

main {
	flex: 1 1 auto;
	overflow: hidden;
}

gl-patch-create {
	display: contents;
}

.pane-groups {
	display: flex;
	flex-direction: column;
	height: 100%;

	&__group {
		display: flex;
		flex: 1 1 auto;
		flex-direction: column;
		min-height: 0;
		overflow: hidden;

		webview-pane {
			flex: none;

			&[expanded] {
				flex: 1;
				min-height: 0;
			}
		}
	}

	&__group-fixed {
		flex: none;

		webview-pane::part(content) {
			overflow: visible;
		}
	}
}
