@use "sass:math";

$bar_height: 42px;
$label_z_index: 50;
$score_pointer_size: 6px;
$no_boost_score_size: 28px;

%score-pill {
	background-color: #fff;
	border-radius: $bar_height;
	height: $bar_height;
	display: flex;
	align-items: center;
	border: 2px solid transparent;
}

.jb-score-bar {
	width: 100%;
	display: flex;
	color: var(--jp-gray-70);

	&--mobile { // .jb-score-bar--mobile
		margin-bottom: 1.5rem;
	}

	@media (max-width: 767px) {
		flex-direction: column;

		&__label {
			background-color: transparent;
		}
	}


	&__loading {

		@extend %score-pill;
		width: $bar_height;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	&__label {

		@extend %score-pill;
		display: grid;
		grid-template-columns: 24px 1fr;
		grid-column-gap: 10px;
		justify-content: center;
		font-size: 14px;
		position: relative;

		@media (min-width: 768px) {
			padding-left: 15px;
			padding-right: 15px;
			width: 200px;
			z-index: $label_z_index;
		}
	}

	&__score {

		@extend %score-pill;
		border-radius: 100%;
		font-weight: 700;
		width: $bar_height;
		justify-content: center;
		position: absolute;
		right: -1px;
		height: $bar_height;
	}

	&__bounds {
		background-color: #f1f1f1;
		border-radius: math.div($bar-height, 2);
		display: flex;
		height: $bar_height;
		width: 100%;
		max-width: 100%;
		position: relative;
		z-index: $label_z_index - 10;

		@media (min-width: 768px) {
			width: calc(100% + #{math.div($bar-height, 2)});
			margin-left: math.div(-$bar_height, 2);
		}
	}

	&__filler {
		display: flex;
		min-width: 1px + $bar_height * 2;
		justify-content: flex-end;
		border-radius: 0 $bar_height $bar_height 0;
		transition: width 300ms ease-in-out;
		will-change: width;
		width: 0;
		position: relative;

		@media (max-width: 767px) {
			min-width: $bar_height + 1px;
			border-radius: inherit;
		}
	}

	&__no_boost_score {

		--clearance-space: #{$bar_height + $no_boost_score_size + 4px};

		position: absolute;
		background: #fff;
		border-radius: 50%;
		padding: 3px;
		top: $score_pointer_size;
		width: $no_boost_score_size;
		height: $no_boost_score_size;
		line-height: 1.625;
		font-size: 0.7em;
		text-align: center;
		cursor: pointer;
		z-index: 2;
		border: 2px solid transparent;
		background-clip: padding-box;

		&:hover {
			border: 2px solid rgba(255, 255, 255, 0.5);
		}

		&::after {
			content: " ";
			width: 0;
			height: 0;
			border-left: $score_pointer_size solid transparent;
			border-right: $score_pointer_size solid transparent;
			border-bottom: $score_pointer_size solid #fff;

			position: absolute;
			top: $bar_height - $score_pointer_size * 2 - 2px;
			left: $score_pointer_size;
		}
	}

	&__no_boost_score_tooltip {
		box-shadow: 0 0 20px 0 rgb(170 170 170 / 28%);
		position: absolute;
		top: -62px;
		left: -10em;
		width: 20em;
		background: #fff;
		padding: 16px;
		border-radius: 4px;
		margin: 0 16px;
		display: none;

		&::after {
			content: " ";
			width: 0;
			height: 0;
			border-left: $score_pointer_size solid transparent;
			border-right: $score_pointer_size solid transparent;
			border-top: $score_pointer_size solid #fff;

			position: absolute;
			bottom: -$score_pointer_size;
			left: 10em;
			margin: 0 -10px;
		}
	}

	&__no_boost_score:hover &__no_boost_score_tooltip {
		display: block;
	}

	.fill-loading {
		background-color: var(--jp-white);
	}

	.fill-good {
		background-color: var(--jp-green);
	}

	.fill-mediocre {
		background-color: var(--jp-orange-20);
	}

	.fill-bad {
		background-color: var(--jp-red-50);
	}
}
