@import "@wordpress/base-styles/breakpoints";
@import "@wordpress/base-styles/mixins";

/**
 * @component Search
 */

.filterbar.is-loading {
	height: 50px;
	background-color: var(--color-neutral-10);
	animation: loading-fade 1.6s ease-in-out infinite;
}

.filterbar .filterbar__wrap.card {
	display: flex;
	flex-direction: row;

	@include breakpoint-deprecated( "<660px" ) {
		display: block;
		height: auto;
		margin-bottom: 1.5rem;

		.filterbar__text-control,
		.filterbar__label {
			margin: 0;
		}

		.filterbar__text-control {
			margin-bottom: 5px;
		}
	}
}

.filterbar__wrap.card {
	position: relative;
	display: flex;
	flex: 1 1 auto;
	align-items: center;
	width: 100%;
	height: 51px;
	padding: 0;
	margin: 0;

	.back-button {
		position: static;
	}

	.filterbar__icon-reset {
		width: 48px;
		padding: 0;
		margin: 0;
	}

	.filterbar__label {
		margin: 0 2px 0 10px;
		color: var(--color-neutral);
		white-space: nowrap;

		@include breakpoint-deprecated( ">660px" ) {
			margin: 0 8px 0 16px;
		}
	}

	.filterbar__control-list {
		display: flex;

		margin: 0 0 0 4px;
		padding: 0;

		list-style-type: none;

		> li {
			margin: 4px;
		}
	}

	.filterbar__selection.button {
		padding: 8px;
		border: 1px solid var(--color-neutral-20);
		overflow: hidden;
		white-space: nowrap;
		background: #fff;
	}

	.filterbar__selection.is-selected,
	.filterbar__selection.is-selected:focus,
	.filterbar__selection.is-selected:hover {
		border-radius: 2px;
		border: 1px solid var(--color-neutral-60);
		background: var(--color-neutral-60);
		color: var(--color-text-inverted);

		@include breakpoint-deprecated( ">660px" ) {
			border-top-right-radius: 0;
			border-bottom-right-radius: 0;
		}
	}

	.filterbar__selection.is-active,
	.filterbar__selection.is-active:focus,
	.filterbar__selection.is-active:hover,
	.date-range.toggle-visible .filterbar__selection.button:not(.is-selected) {
		border: 1px solid var(--color-neutral-60);
		background: var(--color-neutral-60);
		color: var(--color-text-inverted);
	}

	.filterbar__selection-close.button,
	.type-selector__selection-close.button {
		padding: 8px 8px 8px 0;
		background-color: var(--color-neutral-60);
		color: var(--color-text-inverted);
		border-radius: 0;
		border-top-right-radius: 2px;
		border-bottom-right-radius: 2px;
		border: 1px solid var(--color-neutral-60);
		display: none;
		text-overflow: initial;

		@include breakpoint-deprecated( ">660px" ) {
			display: inline;
		}
	}

	.filterbar__selection-close.button:hover,
	.type-selector__selection-close.button:hover {
		color: var(--color-text-inverted);
		background-color: var(--color-neutral-60);
	}

	.filterbar__text-control {
		flex-grow: 1;
		margin: 0 8px 0 16px;

		.search {
			margin-bottom: 0;

			border: 1px solid var(--color-neutral-20);
			font-size: 0.75rem;
			width: 100%;

			@include break-xlarge {
				width: 65%;
			}
		}
	}
}

.type-selector__activity-types-selection-wrap {
	min-width: 200px;
	padding: 0;

	@include breakpoint-deprecated( ">660px" ) {
		padding: 24px 24px 18px;
	}

	label {
		margin-bottom: 7px;
		font-size: $font-body;
		text-align: left;
		cursor: pointer;

		@include breakpoint-deprecated( ">660px" ) {
			margin-bottom: 5px;
			font-size: $font-body-small;
		}
	}

	input[type="checkbox"] {
		margin-top: 3px;
		margin-right: 10px;
	}
}

.type-selector__activity-types-selection-granular {
	label {
		font-weight: 400;
	}
}

.type-selector__activity-types-selection-placeholder {
	@include placeholder();
	height: 24px;
	margin: 16px 0;
}

.filterbar__date-range-selection-info,
.type-selector__activity-types-selection-info {
	display: flex;
	flex-flow: row nowrap;
	justify-content: space-between;
	margin-top: 16px;
	padding-top: 14px;
	border-top: 1px solid var(--color-neutral-5);
}

.filterbar__date-range-wrap {
	width: 280px;
	margin: 0 auto;

	@include breakpoint-deprecated( ">660px" ) {
		padding: 16px;
	}

	.DayPicker-Day {
		cursor: pointer;

		.date-picker__day {
			padding: 0 7px;
			&:hover,
			&:focus {
				padding: 0;
			}
		}
	}

	.filterbar__date-range-selection-info {
		display: flex;
		flex-flow: row nowrap;
		justify-content: space-between;
		margin-top: 16px;
		padding-top: 14px;
		border-top: 1px solid var(--color-neutral-5);
	}

	.type-selector__date-range-info {
		font-size: $font-body-extra-small;

		.button.is-borderless {
			margin-top: 2px;
		}
	}

	.DayPicker-Day.DayPicker-Day--start {
		background-color: var(--color-primary-light);
		border-radius: 0;
		border-top-left-radius: 50%;
		border-bottom-left-radius: 50%;
	}

	.DayPicker-Day.DayPicker-Day--end {
		background-color: var(--color-primary-light);
		border-radius: 0;
		border-top-right-radius: 50%;
		border-bottom-right-radius: 50%;
	}

	.DayPicker-Day.DayPicker-Day--today .date-picker__day {
		color: var(--color-text-inverted);
		position: relative;
		display: block;
		z-index: 0;
		background: transparent;
		&:hover,
		&:focus {
			padding: 0 7px;
		}
	}

	.DayPicker-Day--today .date-picker__day::before {
		content: "";
		position: absolute;
		display: block;
		background-color: var(--color-neutral-70);
		border-radius: 50%;
		width: 26px;
		height: 26px;
		left: 6px;
		top: -1px;
		z-index: -2;
	}

	.DayPicker-Day.DayPicker-Day--selected .date-picker__day {
		background-color: var(--color-primary-light);
		border-radius: 0;
		color: var(--color-text-inverted);
		&:hover,
		&:focus {
			padding: 0 7px;
		}
	}

	.DayPicker-Day.DayPicker-Day--start .date-picker__day,
	.DayPicker-Day.DayPicker-Day--end .date-picker__day {
		border-radius: 50%;
		color: var(--color-text-inverted);
		padding: 0;
		position: relative;
		display: block;
		z-index: 0;
		&:hover,
		&:focus {
			padding: 0;
		}
	}

	.DayPicker-Day--start .date-picker__day::before,
	.DayPicker-Day--end .date-picker__day::before,
	.DayPicker-Day--start .date-picker__day::after,
	.DayPicker-Day--end .date-picker__day::after {
		content: "";
		display: block;
		position: absolute;
		z-index: -2;
		top: -1px;
		right: 12px;
		width: 20px;
		height: 26px;
		background-color: var(--color-primary-light);
	}

	.DayPicker-Day--start .date-picker__day::after {
		top: -1px;
		left: 12px;
	}

	.DayPicker-Day--start .date-picker__day::before,
	.DayPicker-Day--end .date-picker__day::before {
		width: 26px;
		left: -1px;
		right: auto;
		z-index: -1;
		background-color: var(--color-primary);
		border-radius: 50%;
	}

	.DayPicker-Day--start:hover .date-picker__day::after,
	.DayPicker-Day--start.DayPicker-Day--end .date-picker__day::after {
		background: transparent;
	}
	.DayPicker-Day.DayPicker-Day--disabled,
	.DayPicker-Day--disabled .date-picker__day {
		cursor: default;
		&:hover {
			background: transparent;
		}
	}

	.gridicons-info {
		margin: 3px 6px -8px 0;
		fill: var(--color-neutral);
	}
}

.color-scheme.is-dark {
	.filterbar__selection.button.is-borderless {
		color: var(--color-text-subtle);

		&:hover,
		&:focus {
			color: var(--color-neutral-70);
		}

		&.is-selected {
			color: var(--color-text-inverted);
		}
	}
}

.type-selector__nested-checkbox {
	margin-left: 0;
	li {
		list-style: none;
	}
}

.filterbar {
	margin: 0 16px;

	@include breakpoint-deprecated( ">660px" ) {
		margin: 0;
	}
}

.filterbar--compact .filterbar__wrap.card {
	background-color: initial;
	box-shadow: initial;
	height: auto;

	.filterbar__text-control {
		flex-grow: initial;
		margin: 0 0 5px 0;

		.search {
			box-sizing: border-box;
			width: 100%;
		}

		.search.is-compact .search__open-icon {
			margin: 0 4px;
			width: 24px;
		}

		@include breakpoint-deprecated( ">660px" ) {
			margin-bottom: 0;
			width: 240px;
		}
	}

	.filterbar__control-list {
		display: flex;
		margin: 0;
		gap: 5px;

		@include breakpoint-deprecated( ">660px" ) {
			margin: 0 0 0 8px;
			gap: 8px;
		}
	}

	.filterbar__control-list > li {
		display: flex;
		margin: 0;
		width: calc(50% - 2.5px);

		@include breakpoint-deprecated( ">660px" ) {
			flex-grow: 0;
			width: auto;
		}
	}

	.filterbar__control-list li .date-range {
		width: 100%;

		@include break-xlarge {
			width: auto;
		}
	}

	.filterbar__selection {
		align-items: center;
		color: #000;
		display: flex;
		height: 36px;
		padding: 8px 8px 8px 12px;
		width: 100%;

		@include break-xlarge {
			width: auto;
		}

		span.button-label {
			height: 100%;
			line-height: 18px;
			max-width: 180px;
			overflow: hidden;
			text-overflow: ellipsis;

			@include break-xlarge {
				max-width: 210px;
			}
		}

		&.is-active,
		&.is-selected,
		&.is-selected:focus,
		&.is-selected:hover {
			color: var(--color-text-inverted);
		}

		svg {
			padding-left: 4px;
		}
	}

	.filterbar__selection-close {
		height: 36px;
	}

	.filterbar__selection-expand-icon {
		margin-left: 4px;
		fill: currentColor;
		color: var(--color-text-subtle);
	}

	.filterbar__selection-close.button,
	.type-selector__selection-close.button {
		border-left: 1px solid var(--color-border);
		padding: 8px;
	}
}
