@use "sass:color";
@use "../../scss/z-index";
@use "../../scss/calypso-colors";
@use "../../scss/mixins/breakpoints";
@use "../../scss/mixins/icons";
@use "../../scss/typography";

/**
 * Section Nav
 */

// -------- Main Component --------
.dops-section-nav {
	position: relative;
	width: 100%;
	padding: 0;
	margin: 0 0 17px 0;
	background: calypso-colors.$white;
	box-sizing: border-box;

	&.is-empty .dops-section-nav__panel {
		visibility: hidden;
	}

	@include breakpoints.breakpoint( "<660px" ) {
		box-shadow:
			0 0 0 1px calypso-colors.$light-gray-700,
			0 1px 1px 1px  rgba(0, 0, 0, 0.04);

		&.is-open {
			box-shadow:
				0 0 0 1px calypso-colors.$gray,
				0 2px 4px color.adjust(calypso-colors.$gray, $lightness: 20%);
		}
	}

	@include breakpoints.breakpoint( ">660px" ) {

		&.has-pinned-items {
			padding-right: 60px;
		}
	}

	@include breakpoints.breakpoint( "660px-660px" ) {

		&.has-pinned-items {
			padding-right: 50px;
		}
	}

	@include breakpoints.breakpoint( "<660px" ) {
		margin-bottom: 9px;
	}
}

// -------- Mobile Specific Header / Panel --------
.dops-section-nav__mobile-header {
	display: flex;
	padding: 15px;
	font-size: 14px;
	line-height: 16px;
	color: calypso-colors.$gray-dark;
	font-weight: 600;
	cursor: pointer;

	&::after {

		@include icons.dashicons;
		content: "\f347";
		line-height: 16px;
		color: rgba(calypso-colors.$gray, 0.5);
	}

	.dops-section-nav.is-open & {

		&::after {

			@include icons.dashicons;
			content: "\f343";
		}
	}

	.dops-section-nav.has-pinned-items & {
		padding-right: 50px;

		&::after {
			margin-left: 8px;
		}
	}

	@include breakpoints.breakpoint( ">660px" ) {
		display: none;
	}
}

.dops-section-nav__mobile-header-text {
	width: 0;
	flex: 1 0 auto;
	overflow: hidden;
	white-space: nowrap;
	text-overflow: ellipsis;

	small {
		margin-left: 5px;
		font-size: 11px;
		color: calypso-colors.$gray;
		font-weight: 600;
		text-transform: uppercase;
	}

	.dops-section-nav.has-pinned-items & {
		width: auto;
		flex: 0 1 auto;
	}
}

.dops-section-nav__panel {
	box-sizing: border-box;
	width: 100%;

	@include breakpoints.breakpoint( "<660px" ) {

		.dops-section-nav.is-open & {
			padding-bottom: 15px;
			border-top: solid 1px color.adjust(calypso-colors.$gray, $lightness: 20%);
			background: linear-gradient(to bottom, calypso-colors.$gray-light 0%, calypso-colors.$white 4px);
		}
	}

	@include breakpoints.breakpoint( ">660px" ) {
		display: flex;
		align-items: center;

		&:first-child {
			width: 0;
			flex: 1 0 auto;
		}
	}
}

.dops-section-nav-group {
	position: relative;
	margin-top: 16px;
	padding-top: 16px;
	border-top: solid 1px color.adjust(calypso-colors.$gray, $lightness: 20%);

	&:first-child {
		padding-top: 0;
		border-top: none;
	}

	@include breakpoints.breakpoint( "<660px" ) {
		display: none;

		.dops-section-nav.is-open & {
			display: block;
		}
	}

	@include breakpoints.breakpoint( ">660px" ) {
		margin-top: 0;
		padding-top: 0;
		border-top: none;

		&:first-child {
			display: flex;
			width: 0;
			flex: 1 0 auto;
		}
	}
}

.dops-section-nav__button {
	width: 100%;
	margin-top: 24px;
}

.dops-section-nav__hr {
	background: color.adjust(calypso-colors.$gray, $lightness: 30%);
}

// -------- Labels --------
// used above nav group < 660px with sibling control groups
.dops-section-nav-group__label {
	display: none;
	margin-bottom: 8px;
	padding: 0 15px;
	font-size: 11px;
	color: calypso-colors.$black;
	font-weight: 600;
	text-transform: uppercase;
	line-height: 12px;

	@include breakpoints.breakpoint( "<660px" ) {

		.has-siblings & {
			display: block;
		}
	}
}

.dops-section-nav-group__label-text {
	white-space: nowrap;
	text-overflow: ellipsis;
	overflow: hidden;
}

// -------- Nav Items --------
.dops-section-nav-tab .count {
	margin-left: 8px;
}

// -------- Nav Tabs --------
// which contain items
.dops-section-nav-tabs {

	@include breakpoints.breakpoint( ">660px" ) {
		width: 0;
		flex: 1 0 auto;

		&.is-dropdown {
			position: relative;
			width: auto;
			flex: 0 1 auto;
			margin: 8px;
		}
	}
}

// -------- Nav Tabs - inline list --------
.dops-section-nav-tabs__list {
	margin: 0;
	list-style: none;

	@include breakpoints.breakpoint( ">660px" ) {
		display: flex;
		width: 100%;
		overflow: hidden;

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

// -------- Nav Tabs - individual tab --------
.dops-section-nav-tab {
	margin-bottom: 0;

	a.dops-section-nav-tab__link {

		span.components-external-link__contents {
			text-decoration: none;
		}
	}

	@include breakpoints.breakpoint( ">660px" ) {
		width: auto;
		flex: none;
		border-bottom: 2px solid transparent;
		border-top: none;
		text-align: center;
		margin: 0 16px;

		&:first-of-type {
			margin-left: 0;
		}

		&:last-of-type {
			margin-right: 0;
		}

		&.is-selected {
			box-shadow: inset 0 -1px 0 calypso-colors.$black;
		}
	}
}

.dops-section-nav-tab__link,
.dops-section-nav-tab__text {
	overflow: hidden;
	white-space: nowrap;
	text-overflow: ellipsis;
}

.dops-section-nav-tab__link {
	display: flex;
	align-items: center;
	box-sizing: border-box;
	padding: 15px;
	width: 100%;
	font-size: typography.$font-body;
	font-weight: 400;
	line-height: 24px;
	color: calypso-colors.$black;
	cursor: pointer;

	&[disabled],
	.notouch &[disabled]:hover {
		color: color.adjust(calypso-colors.$black, $lightness: 30%);
		cursor: default;
	}

	.is-selected & {
		color: calypso-colors.$white;
		background-color: calypso-colors.$blue-medium-dark;
	}

	&:focus {
		outline: none;
		box-shadow: none;

		.dops-accessible-focus & {
			outline: solid calypso-colors.$gray 1px;
		}
	}

	.is-external & {

		svg {
			color: currentColor;
		}

		&::after {
			// @include noticon('\f442');
			font-size: 18px;
			padding-left: 2px;
		}
	}

	.notouch .is-selected & {

		&:hover {
			color: calypso-colors.$white;
		}
	}

	@include breakpoints.breakpoint( ">660px" ) {
		display: block;
		width: auto;
		padding: 8px 0;
		font-weight: 400;

		&:hover {
			color: calypso-colors.$black;
			box-shadow: inset 0 -1px 0 calypso-colors.$black;
		}

		.is-selected & {
			color: calypso-colors.$black;
			background-color: transparent;

			&::after {
				display: none;
			}
		}

		.notouch .is-selected & {

			&:hover {
				color: calypso-colors.$black;
			}
		}
	}
}

// Mimic style of WP plugin update badge
.dops-section-nav-tab__update-badge {
	display: inline-block;
	vertical-align: middle;
	box-sizing: border-box;
	margin-block-start: 2px;
	margin-top: -1px;
	margin-left: 5px;
	padding: 0 5px;
	min-width: 20px;
	height: 20px;
	border-radius: 10px;
	background-color: calypso-colors.$orange-fire;
	color: #fff;
	font-size: 12px;
	line-height: 1.6;
	text-align: center;

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

.dops-section-nav-tab__text {
	color: inherit;
	display: inline;
	flex: none;
	width: auto;
}

// -------- Nav Tabs - dropdowns --------
.dops-section-nav-tabs__dropdown {
	position: relative;
	z-index: z-index.z-index("dops-section-nav-tabs__dropdown-parent", ".dops-section-nav-tabs__dropdown");
	width: 100%;

	&.is-open {
		z-index: z-index.z-index("dops-section-nav-tabs__dropdown-parent", ".dops-section-nav-tabs__dropdown.is-open");
	}

	.dops-select-dropdown__container {
		position: static;
	}
}

// -------- Search --------
// stylelint-disable-next-line no-duplicate-selectors
// -- This is a styling section for a distinct purpose.
.dops-section-nav {

	@include breakpoints.breakpoint( "<660px" ) {

		.dops-search.is-pinned {
			height: 46px;
		}
	}
}
