@use 'mixins' as *;

$ng-select-highlight: #3f51b5 !default;
$ng-select-primary-text: rgba(0, 0, 0, 0.87) !default;
$ng-select-primary-light-text: rgba(255, 255, 255, 0.87) !default;
$ng-select-secondary-text: rgba(0, 0, 0, 0.54) !default;
$ng-select-secondary-light-text: rgba(255, 255, 255, 0.54) !default;
$ng-select-disabled-text: rgba(0, 0, 0, 0.38) !default;
$ng-select-divider: rgba(0, 0, 0, 0.12) !default;
$ng-select-bg: #ffffff !default;

// Values that used to be hard-coded in the rules below, lifted so they can be themed too.
$ng-select-underline: rgba(0, 0, 0, 0.42) !default;
$ng-select-marked: rgba(0, 0, 0, 0.04) !default;
$ng-select-disabled-value-text: rgba(0, 0, 0, 0.26) !default;
$ng-select-fill-bg: rgba(0, 0, 0, 0.06) !default;
$ng-select-fill-disabled-bg: rgba(0, 0, 0, 0.02) !default;

// Every theme value is exposed as a custom property so it can be changed at runtime
// (dark mode, Tailwind, per-section themes) without recompiling Sass. The Sass variables
// above still seed these defaults, so overriding them before importing keeps working.
:root {
	--ng-select-highlight: #{$ng-select-highlight};
	--ng-select-primary-text: #{$ng-select-primary-text};
	--ng-select-primary-light-text: #{$ng-select-primary-light-text};
	--ng-select-secondary-text: #{$ng-select-secondary-text};
	--ng-select-secondary-light-text: #{$ng-select-secondary-light-text};
	--ng-select-disabled-text: #{$ng-select-disabled-text};
	--ng-select-divider: #{$ng-select-divider};
	--ng-select-bg: #{$ng-select-bg};
	--ng-select-underline: #{$ng-select-underline};
	--ng-select-marked: #{$ng-select-marked};
	--ng-select-disabled-value-text: #{$ng-select-disabled-value-text};
	--ng-select-fill-bg: #{$ng-select-fill-bg};
	--ng-select-fill-disabled-bg: #{$ng-select-fill-disabled-bg};
}

.ng-select {
	padding-bottom: 1.25em;
	&.ng-select-disabled {
		.ng-select-container {
			&:after {
				border-bottom-color: transparent;
				background-image: linear-gradient(
					to right,
					var(--ng-select-underline, #{$ng-select-underline}) 0%,
					var(--ng-select-underline, #{$ng-select-underline}) 33%,
					transparent 0%
				);
				background-size: 4px 1px;
				background-repeat: repeat-x;
			}
			&.ng-appearance-fill {
				background-color: var(--ng-select-fill-disabled-bg, #{$ng-select-fill-disabled-bg});
				&:after {
					background-image: linear-gradient(
						to right,
						var(--ng-select-underline, #{$ng-select-underline}) 0%,
						var(--ng-select-underline, #{$ng-select-underline}) 33%,
						transparent 0%
					);
					background-size: 4px 1px;
					background-repeat: repeat-x;
					border-bottom: none;
				}
			}
			&.ng-appearance-outline {
				.ng-notched-outline,
				&:hover .ng-notched-outline {
					--ng-select-outline-width: 1px;
					color: var(--ng-select-divider, #{$ng-select-divider});
				}
				.ng-notched-outline-leading,
				.ng-notched-outline-notch,
				.ng-notched-outline-trailing {
					border-style: dotted;
				}
			}
			.ng-value-container {
				.ng-value {
					color: var(--ng-select-disabled-text, #{$ng-select-disabled-text});
				}
				.ng-placeholder {
					color: var(--ng-select-disabled-text, #{$ng-select-disabled-text});
				}
			}
		}
		.ng-arrow-wrapper .ng-arrow,
		.ng-clear-wrapper {
			color: var(--ng-select-disabled-text, #{$ng-select-disabled-text});
		}
	}
	&.ng-select-focused {
		.ng-select-container {
			&:after {
				border-color: var(--ng-select-highlight, #{$ng-select-highlight});
				border-width: 2px;
			}
			&.ng-appearance-outline {
				.ng-notched-outline,
				&:hover .ng-notched-outline {
					--ng-select-outline-width: 2px;
					color: var(--ng-select-highlight, #{$ng-select-highlight});
				}
			}
			&.ng-appearance-fill {
				&:after {
					border-color: var(--ng-select-highlight, #{$ng-select-highlight});
					border-width: 0 0 2px;
				}
			}
			.ng-value-container .ng-placeholder {
				transform: translateY(-1.28125em) scale(0.75) perspective(100px) translateZ(0.001px);
				color: var(--ng-select-highlight, #{$ng-select-highlight});
			}
			.ng-arrow-wrapper .ng-arrow {
				color: var(--ng-select-highlight, #{$ng-select-highlight});
			}
		}
	}
	.ng-has-value,
	&.ng-select-filtered .ng-select-container {
		.ng-placeholder {
			display: initial;
		}
	}
	.ng-has-value,
	&.ng-select-opened {
		.ng-placeholder {
			transform: translateY(-1.28125em) scale(0.75) perspective(100px) translateZ(0.001px);
		}
	}
	&.ng-select-opened .ng-select-container.ng-appearance-outline .ng-notched-outline-notch {
		border-top-width: 0;
	}
	.ng-select-container {
		color: var(--ng-select-primary-text, #{$ng-select-primary-text});
		align-items: baseline;
		min-height: 51.5px;
		&:after {
			border-bottom: thin solid var(--ng-select-underline, #{$ng-select-underline});
			content: '';
			bottom: 0;
			left: 0;
			right: 0;
			position: absolute;
			transition: border-color 0.3s cubic-bezier(0.55, 0, 0.55, 0.2);
		}
		&.ng-appearance-outline {
			padding: 0 0.5em;
			min-height: 60px;
			// The outline is drawn by .ng-notched-outline segments so the floated label
			// sits in a real border gap and works on any page background.
			&:after {
				display: none;
			}
			&:hover .ng-notched-outline {
				--ng-select-outline-width: 2px;
				color: var(--ng-select-primary-text, #{$ng-select-primary-text});
			}
			.ng-notched-outline {
				--ng-select-outline-width: 1px;
				position: absolute;
				bottom: 0;
				left: 0;
				right: 0;
				height: calc(100% - 0.5em);
				display: flex;
				pointer-events: none;
				color: var(--ng-select-divider, #{$ng-select-divider});
				transition: color 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
			}
			.ng-notched-outline-leading,
			.ng-notched-outline-notch,
			.ng-notched-outline-trailing {
				box-sizing: border-box;
				height: 100%;
				border: 0 solid currentColor;
				transition: border-width 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
			}
			.ng-notched-outline-leading {
				border-width: var(--ng-select-outline-width) 0 var(--ng-select-outline-width) var(--ng-select-outline-width);
				border-radius: 5px 0 0 5px;
				width: 0.5em;
				flex-shrink: 0;
				@include rtl {
					border-width: var(--ng-select-outline-width) var(--ng-select-outline-width) var(--ng-select-outline-width) 0;
					border-radius: 0 5px 5px 0;
				}
			}
			.ng-notched-outline-notch {
				border-width: var(--ng-select-outline-width) 0;
				flex-shrink: 0;
				max-width: calc(100% - 1em);
			}
			.ng-notched-outline-trailing {
				border-width: var(--ng-select-outline-width) var(--ng-select-outline-width) var(--ng-select-outline-width) 0;
				border-radius: 0 5px 5px 0;
				flex-grow: 1;
				@include rtl {
					border-width: var(--ng-select-outline-width) 0 var(--ng-select-outline-width) var(--ng-select-outline-width);
					border-radius: 5px 0 0 5px;
				}
			}
			&.ng-has-value .ng-notched-outline-notch {
				border-top-width: 0;
			}
			.ng-placeholder {
				padding: 0 0.25em;
				z-index: 1;
			}
			.ng-value {
				padding-left: 0.25em;
			}
			// Outline min-height (60px) is taller than the default control; pin the absolute
			// search input to the value content offset instead of bottom: 0.4375em.
			.ng-value-container .ng-input {
				top: calc(0.84375em + 0.4375em);
				bottom: auto;
			}
		}
		&.ng-appearance-fill {
			background-color: var(--ng-select-fill-bg, #{$ng-select-fill-bg});
			border-radius: 4px 4px 0 0;
			padding: 0 0.75em;
			min-height: 56px;
			&:after {
				border-bottom: thin solid var(--ng-select-underline, #{$ng-select-underline});
				content: '';
				bottom: 0;
				left: 0;
				right: 0;
				position: absolute;
				transition: border-color 0.3s cubic-bezier(0.55, 0, 0.55, 0.2);
			}
			&:hover:after {
				border-bottom-color: var(--ng-select-primary-text, #{$ng-select-primary-text});
			}
			.ng-placeholder {
				padding: 0 0.25em;
				background-color: transparent;
				z-index: 1;
			}
			.ng-value-container {
				// Add extra headroom so the floating label matches Material filled spacing better.
				padding-top: 0.5625em;
				border-top-width: 1.09375em;
			}
			.ng-value {
				padding-left: 0.25em;
			}
		}
		.ng-value-container {
			align-items: stretch;
			padding: 0.4375em 0;
			border-top: 0.84375em solid transparent;
			.ng-placeholder {
				position: absolute;
				color: var(--ng-select-secondary-text, #{$ng-select-secondary-text});
				transform-origin: left 0;
				transition:
					transform 0.4s cubic-bezier(0.25, 0.8, 0.25, 1),
					color 0.4s cubic-bezier(0.25, 0.8, 0.25, 1),
					width 0.4s cubic-bezier(0.25, 0.8, 0.25, 1);
				@include rtl {
					transform-origin: right 0;
				}
			}
			.ng-input {
				bottom: 0.4375em;
			}
		}
	}
	&.ng-select-single {
		.ng-select-container {
			&.ng-appearance-fill {
				.ng-arrow-wrapper {
					bottom: 15px;
				}
				.ng-clear-wrapper {
					bottom: 12px;
				}
			}
			&.ng-appearance-outline {
				.ng-arrow-wrapper {
					bottom: 17px;
				}
				.ng-clear-wrapper {
					bottom: 14px;
				}
			}
			.ng-arrow-wrapper {
				align-self: flex-end;
				bottom: 9px;
			}
			.ng-clear-wrapper {
				align-self: flex-end;
				bottom: 7px;
			}
		}
	}
	&.ng-select-multiple {
		&.ng-select-disabled {
			.ng-select-container .ng-value-container .ng-value {
				background-color: var(--ng-select-divider, #{$ng-select-divider});
				color: var(--ng-select-disabled-value-text, #{$ng-select-disabled-value-text});
			}
			.ng-appearance-fill {
				&:after,
				&:hover:after {
					background-image: linear-gradient(
						to right,
						var(--ng-select-underline, #{$ng-select-underline}) 0%,
						var(--ng-select-underline, #{$ng-select-underline}) 33%,
						transparent 0%
					);
					background-size: 4px 1px;
					background-repeat: repeat-x;
					border-bottom: none;
				}
			}
			.ng-appearance-outline {
				.ng-notched-outline,
				&:hover .ng-notched-outline {
					--ng-select-outline-width: 1px;
					color: var(--ng-select-divider, #{$ng-select-divider});
				}
				.ng-notched-outline-leading,
				.ng-notched-outline-notch,
				.ng-notched-outline-trailing {
					border-style: dotted;
				}
			}
		}
		.ng-select-container {
			&.ng-appearance-fill {
				&.ng-has-value {
					.ng-arrow-wrapper,
					.ng-clear-wrapper {
						border-top: none;
					}
				}
				.ng-arrow-wrapper {
					top: 2px;
				}
				.ng-clear-wrapper {
					top: 6px;
				}
			}
			&.ng-appearance-outline {
				&.ng-has-value {
					.ng-arrow-wrapper,
					.ng-clear-wrapper {
						border-top: none;
					}
				}
				.ng-arrow-wrapper {
					top: 0;
				}
				.ng-clear-wrapper {
					top: 4px;
				}
			}
			.ng-value-container {
				.ng-value {
					background-color: var(--ng-select-highlight, #{$ng-select-highlight});
					border-radius: 2px;
					color: var(--ng-select-bg, #{$ng-select-bg});
					padding: 2px 5px;
					margin: 0 0.4375em 0.4375em 0;
					@include rtl {
						margin: 0 0 0.4375em 0.4375em;
					}
					&.ng-value-disabled {
						background-color: var(--ng-select-divider, #{$ng-select-divider});
						color: var(--ng-select-disabled-value-text, #{$ng-select-disabled-value-text});
					}
					.ng-value-label {
						font-size: 14px;
						font-weight: 500;
					}
					.ng-value-icon {
						color: var(--ng-select-secondary-light-text, #{$ng-select-secondary-light-text});
						padding-right: 5px;
						@include rtl {
							padding-left: 5px;
							padding-right: 0;
						}
						&:hover {
							color: var(--ng-select-primary-light-text, #{$ng-select-primary-light-text});
						}
					}
				}
				.ng-input {
					line-height: 1.375em;
				}
			}
			&.ng-has-value {
				align-items: center;
				.ng-value-container {
					padding-bottom: 0;
					padding-top: 0.1875em;
				}
				.ng-clear-wrapper,
				.ng-arrow-wrapper {
					border-top: 0.84375em solid transparent;
				}
			}
		}
	}
	.ng-clear-wrapper {
		color: var(--ng-select-secondary-text, #{$ng-select-secondary-text});
		&:hover {
			color: var(--ng-select-primary-text, #{$ng-select-primary-text});
		}
		&:focus {
			color: var(--ng-select-primary-text, #{$ng-select-primary-text});
			outline: none;
		}
	}
	.ng-arrow-wrapper {
		bottom: 2px;
		.ng-arrow {
			border-left: 5px solid transparent;
			border-right: 5px solid transparent;
			border-top: 5px solid;
			margin: 0 4px;
			color: var(--ng-select-secondary-text, #{$ng-select-secondary-text});
		}
	}
	.ng-spinner-zone {
		top: 3px;
	}
}

// Positioning is handled by the CDK overlay; the position classes only carry the
// elevation shadows and the gap margins for the adjacent placements.
.ng-dropdown-panel {
	background: var(--ng-select-bg, #{$ng-select-bg});
	&.ng-select-top {
		box-shadow:
			0 -5px 5px -3px rgba(0, 0, 0, 0.2),
			0 -8px 10px 1px rgba(0, 0, 0, 0.14),
			0 -3px 14px 2px var(--ng-select-divider, #{$ng-select-divider});
	}
	&.ng-select-right {
		box-shadow:
			0 -5px 5px -3px rgba(0, 0, 0, 0.2),
			0 -8px 10px 1px rgba(0, 0, 0, 0.14),
			0 -3px 14px 2px var(--ng-select-divider, #{$ng-select-divider});
		margin-left: 4px;
	}
	&.ng-select-bottom {
		box-shadow:
			0 5px 5px -3px rgba(0, 0, 0, 0.2),
			0 8px 10px 1px rgba(0, 0, 0, 0.14),
			0 3px 14px 2px var(--ng-select-divider, #{$ng-select-divider});
	}
	&.ng-select-left {
		box-shadow:
			0 -5px 5px -3px rgba(0, 0, 0, 0.2),
			0 -8px 10px 1px rgba(0, 0, 0, 0.14),
			0 -3px 14px 2px var(--ng-select-divider, #{$ng-select-divider});
		margin-right: 4px;
	}
	&.multiple {
		.ng-option {
			&.selected {
				background: var(--ng-select-bg, #{$ng-select-bg});
			}
			&.marked {
				background: var(--ng-select-marked, #{$ng-select-marked});
			}
		}
	}
	.ng-dropdown-header {
		border-bottom: 1px solid var(--ng-select-divider, #{$ng-select-divider});
		padding: 0 16px;
		line-height: 3em;
		min-height: 3em;
	}
	.ng-dropdown-footer {
		border-top: 1px solid var(--ng-select-divider, #{$ng-select-divider});
		padding: 0 16px;
		line-height: 3em;
		min-height: 3em;
	}
	.ng-dropdown-panel-items {
		.ng-optgroup {
			user-select: none;
			cursor: pointer;
			line-height: 3em;
			height: 3em;
			padding: 0 16px;
			color: var(--ng-select-secondary-text, #{$ng-select-secondary-text});
			font-weight: 500;
			&.ng-option-marked {
				background: var(--ng-select-marked, #{$ng-select-marked});
			}
			&.ng-option-disabled {
				cursor: default;
			}
			&.ng-option-selected {
				background: var(--ng-select-divider, #{$ng-select-divider});
				color: var(--ng-select-highlight, #{$ng-select-highlight});
			}
		}
		.ng-option {
			line-height: 3em;
			min-height: 3em;
			white-space: nowrap;
			overflow: hidden;
			text-overflow: ellipsis;
			padding: 0 16px;
			text-decoration: none;
			position: relative;
			color: var(--ng-select-primary-text, #{$ng-select-primary-text});
			text-align: left;
			@include rtl {
				text-align: right;
			}
			&.ng-option-marked {
				background: var(--ng-select-marked, #{$ng-select-marked});
				color: var(--ng-select-primary-text, #{$ng-select-primary-text});
			}
			&.ng-option-selected {
				background: var(--ng-select-divider, #{$ng-select-divider});
				color: var(--ng-select-highlight, #{$ng-select-highlight});
			}
			&.ng-option-disabled {
				color: var(--ng-select-disabled-text, #{$ng-select-disabled-text});
			}
			&.ng-option-child {
				padding-left: 32px;
				@include rtl {
					padding-right: 32px;
					padding-left: 0;
				}
			}
			.ng-tag-label {
				padding-right: 5px;
				@include rtl {
					padding-left: 5px;
					padding-right: 0;
				}
				font-size: 80%;
				font-weight: 400;
				color: var(--ng-select-disabled-text, #{$ng-select-disabled-text});
			}
		}
	}
}
