// Chart
// Life is a statistical anomaly

@use "sass:color";
@use "../../scss/z-index";
@use "../../scss/calypso-colors";
@use "../../scss/layout";
@use "../../scss/mixins/clear-fix";
@use "../../scss/mixins/icons";

.dops-chart {
	position: relative;
	box-sizing: border-box;
	background-color: calypso-colors.$white;
	padding: 8px 0 0 20px;
}

// Y-axis

// Y-axis markers (lines)
// 1: Corresponds to padding of chart

.dops-chart .dops-chart__y-axis-markers {
	position: absolute;
	top: 8px; // 1
	left: 0;
	right: 0;
	height: 200px;
}

.dops-chart .dops-chart__y-axis-marker {
	position: absolute;
	top: 0;
	width: 100%;
	height: 1px;
	border-top: 1px solid color.adjust(calypso-colors.$gray, $lightness: 30%);
}

// Y-axis marker lines inside each chart__bar
// (This is needed so that bars overlap correctly)
.dops-chart__bar-marker {
	z-index: z-index.z-index("root", ".dops-chart__bar-marker");
	position: absolute;
	top: 0;
	width: 100%;
	height: 1px;
	border-top: 1px solid rgba(color.adjust(calypso-colors.$gray, $lightness: 30%), 0.1);
}

.dops-chart__bar-marker,
.dops-chart__y-axis-label,
.dops-chart .dops-chart__y-axis-marker {

	&.is-fifty {
		top: 50%;
	}

	&.is-zero {
		top: 100%;
	}
}

// Y-axis labels
// 1: matches Y-axis padding

.dops-chart__y-axis {
	position: relative;
	float: right;
	height: 200px;
	padding: 0 20px 0 10px;
	font-size: 11px;
	color: calypso-colors.$gray-80;
	margin-bottom: 30px;
}

.dops-chart__y-axis-label {
	position: absolute;
	top: 0;
	right: 20px; // 1
	text-align: right;
}

// For forcing the width of y-axis to the width of the label
.dops-chart__y-axis-width-fix {
	color: calypso-colors.$transparent;
}

// X-axis
// 1: hides spaces between elements

.dops-chart__x-axis {
	position: relative;
	font-size: 0; // 1
	padding: 5px 0 0;
	min-height: 18px;
	color: calypso-colors.$black;
}

.dops-chart__x-axis-label {
	position: absolute;
	display: inline-block;
	vertical-align: top;
	font-size: 11px;
	text-align: center;
}

// X-axis label indicator
// (vertical thin grey bar)

.dops-chart__x-axis-label::before {
	content: "";
	display: block;
	position: absolute;
	top: -4px;
	left: 50%;
	margin-left: -0.5px;
	width: 1px;
	height: 5px;
	background: calypso-colors.$gray-light;
	background-image: linear-gradient(to bottom, calypso-colors.$gray-light 0%, color.adjust(calypso-colors.$gray, $lightness: 20%) 100%);
}

// Bar wrapper
// 1: hides spaces between elements

.dops-chart__bars {
	position: relative;
	font-size: 0; // 1
	height: 200px;
	text-align: center;
	overflow: hidden;
	display: flex;
}

// Individual bar
// 1: Needs to be relative so that the contained graphic bar has boundaries

.dops-chart__bar {
	text-align: center;
	display: inline-block;
	position: relative; // 1
	height: 200px;
	flex-grow: 1;
	flex-shrink: 1;


	&.is-weekend {
		background-color: rgba(color.adjust(calypso-colors.$gray, $lightness: 30%), 0.5);
	}

	&:focus {
		background-color: rgba(calypso-colors.$orange-jazzy, 0.1);
	}

	&:hover {
		cursor: pointer;
		background-color: rgba(color.adjust(calypso-colors.$gray, $lightness: 30%), 0.25);
	}

	&.is-selected {
		cursor: default;
		background-color: rgba(calypso-colors.$orange-jazzy, 0.1);
	}
}

// Individual bar wrapper & misc
// 1: Positions the bar in the space as defined by .bar
// 2: Default value for top so bars grow when they get a new value
//   (doesn't function correctly for period switching right now, not sure why)
//   (also doesn't work since updating DOM is so heavy it stalls all animations)

.dops-chart__bar-section {
	display: inline-block;
	background-color: calypso-colors.$black;
	position: absolute;
	top: 0; // 2
	right: 16%; // 1
	bottom: 0; // 1
	left: 16%; // 1
	z-index: z-index.z-index("root", ".dops-chart__bar-section");

	.dops-chart__bar:hover &.is-bar {
		background-color: var(--jp-green-40);
	}

	.dops-chart__bar.is-selected &.is-bar {
		background-color: calypso-colors.$orange-jazzy;
	}

	&.is-spacer {
		z-index: z-index.z-index("root", ".dops-chart__bar-section.is-spacer");
		background-color: calypso-colors.$transparent;
	}

	&.is-ghost::after {
		content: "";
		display: block;
		position: absolute;
		top: 160px;
		bottom: 0;
		left: 0;
		z-index: z-index.z-index("root", ".dops-chart__bar-section.is-ghost::after");
		width: 100%;
		height: 40px;
		background-image: linear-gradient(to bottom, calypso-colors.$transparent, rgba(color.adjust(calypso-colors.$gray, $lightness: 30%), 0.5)); // TODO: needs to use default color for gradient

		.dops-chart__bar:hover & {
			display: none;
		}
	}
}

.dops-chart__bar-section-inner {
	background: color.adjust(calypso-colors.$blue-dark, $lightness: -5%);
	position: absolute;
	right: 23.33%;
	bottom: 0;
	left: 23.33%;

	.dops-chart__bar.is-selected & {
		background-color: calypso-colors.$orange-fire;
	}
}

// Chart legend (wrapper)
// 1: L/R matches padding of y-axis labels in chart

.dops-chart__legend {

	@include clear-fix.clear-fix;
	margin-bottom: -8px;
}

// Chart legend options (list)

.dops-chart__legend .dops-chart__legend-options {
	float: right;
	color: color.adjust(calypso-colors.$gray-dark, $lightness: 20%);
	list-style-type: none;
	margin: 0;
	font-size: 11px;
	text-transform: uppercase;
	letter-spacing: 0.1em;

	@include layout.breakpoint( "<480px" ) {
		width: 100%;
	}

}

// Chart legend option (list item)

.dops-chart__legend-option {
	display: inline;
	text-align: left;

	// Expand labels to create bigger touch targets
	@include layout.breakpoint( "<480px") {
		width: 50%;
		display: inline-block;
	}
}

// Chart legend label
// 1: 19/10px instead of 20/12px because it aligns better optically

.dops-chart__legend-label {
	display: inline-block;
	padding: 12px 19px 10px 20px; // 1

	&.is-selectable {
		cursor: pointer;

		&:focus,
		&:hover {
			color: calypso-colors.$link-highlight;
		}
	}

	@include layout.breakpoint( "<480px" ) {
		display: block;
	}
}

// Chart legend color
// 1: Needed to overvwrite form styles in main stylesheets
// 2: Make leftmost legend fit snugly up against the leftmost bars

.dops-chart__legend-option .dops-chart__legend-color {
	width: 10px;
	height: 10px;
	background: calypso-colors.$blue-wordpress;
	display: inline-block;
	border-radius: 1px;
	vertical-align: top;
	margin: 3px 5px 3px 8px; // 1
}

@include layout.breakpoint( "<480px" ) {

	.dops-chart__legend-option:first-child .dops-chart__legend-color {
		margin-left: 2px; // 2
	}
}

.dops-chart__legend-color.is-dark-blue {
	background: color.adjust(calypso-colors.$blue-dark, $lightness: -5%);
}

// Chart legend checkbox

.dops-chart__legend-option .dops-chart__legend-checkbox {
	margin: 0;
	float: none;
	vertical-align: top;
}

// Chart empty (message)
// A message displayed when there's absolutely no data to chart

.dops-chart__empty {
	position: absolute;
	top: 0;
	right: 0;
	bottom: 0;
	left: 0;
	text-align: center;
	font-size: 14px;
	line-height: 24px;
	clear: both;
	z-index: z-index.z-index("root", ".dops-chart__empty");
}

.dops-chart__empty_notice {
	position: relative;
	top: 97px;
	padding: 11px 24px;
	margin-bottom: 24px;
	border-radius: 1px;
	background: #fff;
	box-sizing: border-box;
	font-size: 14px;
	line-height: 1.4285;
	animation: appear 0.3s ease-in-out;
	box-shadow:
		0 0 0 1px color.adjust(calypso-colors.$gray, $lightness: 20%, $alpha: -0.5),
		0 1px 2px color.adjust(calypso-colors.$gray, $lightness: 30%);

	@include layout.breakpoint( ">660px" ) {
		padding: 13px 48px;
		font-size: inherit;

		&::before {

			@include icons.noticons;
			content: "\f456";
			position: absolute;
			top: 23px;
			left: 20px;
			margin: -12px 0 0 -8px;
			font-size: 24px;
			line-height: 1;
		}
	}
}

// Chart tooltip

.dops-chart__tooltip.dops-chart__tooltip {

	.dops-popover__inner {
		color: var(--color-text-inverted);
		background: var(--color-neutral-100);

		width: 230px;
		text-align: left;

		ul {

			@include clear-fix.clear-fix;
			list-style: none;
			margin: 0;
			padding: 0;

			li {
				font-size: 11px;
				text-transform: uppercase;
				font-weight: 500;
				height: 24px;
				letter-spacing: 0.1em;
				border: 0;
				margin-bottom: 0;

				.dops-wrapper {
					display: block;
					line-height: 24px;
					clear: both;
				}

				.value {
					text-align: right;
					float: right;
					min-width: 22px;
					color: inherit;
				}

				.label {
					display: block;
					overflow: hidden;
					word-break: break-all;
					vertical-align: baseline;
				}

				.gridicon {
					vertical-align: middle;
					margin-right: 6px;
					margin-top: -3px;
				}
			}
		}
	}

	&.is-streak {
		margin-top: -5px;
		height: 35px;

		.dops-popover__arrow::before {
			left: 85px;
			top: 30px;
		}

		.dops-popover__inner {
			width: 160px;
			position: relative;
			top: -10px;

			li {
				height: 14px;

				.label {
					width: 100%;
					float: left;
					text-align: center;

					.rtl & {
						font-size: 11px;
					}

					.post-count {
						font-weight: 700;
					}
				}

				.value {
					float: none;
				}
			}
		}
	}
}

.dops-chart__tooltip .dops-module-content-list-item {

	&.is-date-label {
		font-size: 11px;
		margin-bottom: 2px;
		text-transform: uppercase;
		font-weight: 700;
		border-bottom: 1px solid color.adjust(calypso-colors.$gray, $lightness: -27%);
		padding-bottom: 2px;
	}

	&.is-published-item {

		height: 19px;

		.label {
			text-transform: none;
			color: color.adjust(calypso-colors.$gray, $lightness: 20%);
			overflow: hidden;
			letter-spacing: 0;
			height: 19px;
		}

		.value {
			width: 0;
			min-width: 0;

			&::before {
				content: "";
				position: relative;
				background-image: linear-gradient(to right, rgba(61, 89, 109, 0) 0%, rgba(61, 89, 109, 0.5), rgba(61, 89, 109, 1));
				left: -30px;
				width: 30px;
				height: 24px;
				display: block;
			}
		}
	}
}
