// The select menu (src/admin/components/settings/SelectMenu.js): the campaign
// builder's currency dropdown without its search box. A button that names the
// choice over a listbox.
//
// A mixin, because two stylesheets draw it under two roots: the React admin
// (`.better-payment`, admin.scss) and the Quick Setup wizard
// (`#better-payment-quick-setup-wizard-container`, quick-setup.scss), which is
// a bundle of its own and loads no admin.scss. Include it inside the root:
//
//     .better-payment { @include bp-select-menu; }
//
// Dark mode is admin.scss's (the wizard has none).
@mixin bp-select-menu {
	$border: #dfe2ed;
	$soft: #5b6275;
	$accent: #6b59ee;
	$text: #222b3d;
	$placeholder: #6a758c;

	.bp-select-menu {
		position: relative;
		width: 100%;

		// wp-admin and the plugin's own base rules style a bare `button`: answer
		// each property they set.
		.bp-select-menu__trigger {
			appearance: none;
			display: flex;
			align-items: center;
			gap: 10px;
			width: 100%;
			min-height: 42px;
			margin: 0;
			padding: 6px 14px 6px 10px;
			border: 1px solid $border;
			border-radius: 8px;
			background: #fff;
			box-shadow: none;
			font-size: 14px;
			font-weight: 400;
			line-height: 1.5;
			color: $text;
			text-align: left;
			cursor: pointer;
			transition:
				border-color 0.15s ease,
				box-shadow 0.15s ease;

			&:hover:not(:disabled) {
				border-color: #bfc4d1;
			}

			&:focus {
				outline: none;
			}

			&:focus-visible {
				border-color: $accent;
				box-shadow: 0 0 0 3px rgba($accent, 0.16);
			}

			&:disabled {
				background: #f6f7f9;
				color: $soft;
				cursor: not-allowed;
			}
		}

		&.is-open .bp-select-menu__trigger {
			border-color: $accent;
			box-shadow: 0 0 0 3px rgba($accent, 0.16);
		}

		// The button stays one line: a long choice is cut with an ellipsis (its
		// `title` holds the whole name).
		.bp-select-menu__value {
			flex: 1;
			min-width: 0;
			overflow: hidden;
			text-overflow: ellipsis;
			white-space: nowrap;
		}

		// In the list a long name takes a second line and is read whole
		// ("Bosnia and Herzegovina Convertible Mark").
		.bp-select-menu__label {
			flex: 1;
			min-width: 0;
			overflow-wrap: anywhere;
		}

		// No badge before it: line the text up with a text input's.
		.bp-select-menu__value:first-child {
			padding-left: 6px;
		}

		.bp-select-menu__value.is-placeholder {
			color: $placeholder;
		}

		.bp-select-menu__badge {
			flex-shrink: 0;
			min-width: 44px;
			padding: 2px 6px;
			border-radius: 6px;
			background: #eef0f4;
			font-size: 12px;
			font-weight: 600;
			font-variant-numeric: tabular-nums;
			letter-spacing: 0.02em;
			line-height: 1.5;
			color: $soft;
			text-align: center;
			box-sizing: border-box;
		}

		.bp-select-menu__chevron {
			flex-shrink: 0;
			color: #8a8fa6;
			transition: transform 0.15s ease;
		}

		&.is-open .bp-select-menu__chevron {
			transform: rotate(180deg);
		}

		.bp-select-menu__panel {
			position: absolute;
			top: calc(100% + 6px);
			left: 0;
			right: 0;
			// Over the "See Documentation" / "Get API key" links in the rows under
			// it (`.email-notification_link`, z-index 998).
			z-index: 1000;
			padding: 6px;
			border: 1px solid #e2e4e9;
			border-radius: 12px;
			background: #fff;
			box-shadow:
				0 12px 32px -8px rgba(15, 23, 42, 0.22),
				0 4px 10px -4px rgba(15, 23, 42, 0.12);
		}

		&.is-above .bp-select-menu__panel {
			top: auto;
			bottom: calc(100% + 6px);
		}

		.bp-select-menu__list {
			// The highlight is placed with offsetTop.
			position: relative;
			max-height: 264px;
			margin: 0;
			padding: 0;
			overflow-y: auto;
			list-style: none;
			outline: none;
		}

		.bp-select-menu__option {
			display: flex;
			align-items: center;
			gap: 10px;
			margin: 0;
			padding: 8px 10px;
			border-radius: 6px;
			font-size: 14px;
			line-height: 1.5;
			color: $text;
			cursor: pointer;

			&.is-active {
				background: rgba($accent, 0.08);
			}

			&.is-selected {
				color: $accent;
				font-weight: 600;

				.bp-select-menu__badge {
					background: rgba($accent, 0.14);
					color: $accent;
				}
			}
		}
	}
}
