@use "sass:color";
@use "../../scss/z-index";
@use "../../scss/calypso-colors";
@use "../../scss/mixins/breakpoints";
@use "../../scss/mixins/long-content-fade";

/**
 * @component Search
 */
.dops-search {
	display: flex;
	flex: 1 1 auto;
	margin-bottom: 24px;
	width: 60px;
	height: 51px;
	position: relative;
	align-items: center;
	// places search above filters
	z-index: z-index.z-index("root", ".dops-search");
	transition: all 0.15s ease-in-out;

	.dops-search__icon-navigation {
		flex: 0 0 auto;
		display: flex;
		align-items: center;
		background-color: calypso-colors.$white;
		border-radius: inherit;
		height: 100%;

		&:focus-visible {
			outline-offset: -2px;
		}
	}

	.dops-search__clear-btn {
		min-width: 48px;
		padding: 0.25em;

		background: none;
		border: solid 1px currentColor;
		border-radius: 4px;
		color: var(--jp-gray-50);

		&:focus-visible {
			outline-offset: 2px;
		}
	}

	.dops-search__icon-navigation,
	.dops-search__clear-btn {

		&:focus-visible {
			outline: solid 2px var(--jp-green-50);
		}
	}

	.dops-search__open-icon,
	.dops-search__close-icon {
		flex: 0 0 auto;
		width: 50px;
		z-index: z-index.z-index(".dops-search", ".dops-search .dops-search__open-icon");
		color: var(--jp-black-80);
		cursor: pointer;

		.accessible-focus &:focus {
			outline: dotted 1px var(--jp-green);
		}
	}

	.dops-search__open-icon:hover {
		color: var(--jp-black);
	}

	.dops-search__close-icon {
		color: var(--jp-black);
		opacity: 0;
		transition: opacity 0.2s ease-in;
	}

	.accessible-focus &.has-focus {
		box-shadow: 0 0 0 1px  var(--jp-black), 0 0 0 4px var(--jp-green);
	}
}

// Position collapsed search-button to the right
// of the container element
.dops-search.is-expanded-to-container {
	margin-bottom: 0;
	position: absolute;
	display: flex;
	height: 100%;
	width: 50px;
	top: 0;
	right: 0;
	overflow: hidden;
	gap: 0.25rem;
	background-color: var(--jp-white);

	.dops-search__input-fade {
		position: relative;
		flex: 1 1 auto;
		display: flex;
	}

	.dops-search__input[type="search"] {
		flex: 1 1 auto;
		display: flex;
		margin: 0;
		box-shadow: none;
	}
}

.dops-search__input[type="search"] {
	flex: 1 1 auto;
	display: none;
	z-index: z-index.z-index(".dops-search", ".dops-search__input");
	top: 0;
	border: none;
	border-radius: inherit;
	height: 100%;
	background: calypso-colors.$white;
	appearance: none;
	box-sizing: border-box;
	padding: 0;
	-webkit-appearance: none;

	&::-webkit-search-cancel-button {
		-webkit-appearance: none;
	}

	&:focus {
		box-shadow: none;
		border: none;
	}
}

// When search input is opened
.dops-search.is-open {
	width: 100%;

	.dops-search__open-icon {
		color: color.adjust(calypso-colors.$gray, $lightness: -30%);
	}

	.dops-search__close-icon {
		display: inline-block;
	}

	.dops-search__input,
	.dops-search__close-icon {
		opacity: 1;
	}

	.dops-search__input {
		display: block;
	}

	.dops-search__input-fade {
		flex: 1 1 auto;
		height: 100%;
		position: relative;
		font-size: 16px;
		border-radius: inherit;

		&::before {

			@include long-content-fade.long-content-fade( $size: 32px, $color: calypso-colors.$white, $z-index: z-index.z-index( ".dops-search", ".dops-search__input" ) + 2 );
			border-radius: inherit;
		}

		&.ltr { /*rtl:ignore*/
			&::before {

				@include long-content-fade.long-content-fade( $direction: right, $size: 32px, $color: calypso-colors.$white, $z-index: z-index.z-index( ".dops-search", ".dops-search__input" ) + 2 );
				border-radius: inherit;
			}
		}
	}
}

.dops-search__input-fade .dops-search__text-overlay {
	color: transparent;
	position: absolute;
	pointer-events: none;
	white-space: nowrap;
	display: flex;
	align-items: center;
	flex: 1 1 auto;
	overflow: hidden;
	font: inherit;
	width: 100%;
	height: 100%;
	top: 0;
	left: 0;
	z-index: z-index.z-index(".dops-search", ".dops-search__input") + 1;
}

.dops-search.is-searching .dops-search__open-icon {
	display: none;
}

.animating.dops-search-opening .dops-search input {
	opacity: 1;
}
