//@import "../../../abstracts/abstracts";

// Knowledge base search bar with the document tag filter (DbqKnowledgeBaseFilterControl)
// Class prefix: dbqkbfc-
// One line with the search input and the Filters button, the selected tags as chips on a second line (only when there are any).
// The Filters button opens a panel with all tag categories as collapsible groups, so the bar stays compact with many categories.

// (Also overrules the padding of the old knowledge base, .dbqkbc-container .dbqkbc-filters-container)
.dbqkbe-container .dbqkbe-detail-pane > .dbqkbe-filters-container {
	float: none;
	margin: 0;
	padding: $global-padding $global-padding ($global-padding / 2) $global-padding;
	position: relative;
	z-index: 5;
}

.dbqkbfc-bar {
	display: flex;
	flex-direction: column;
	gap: 8px;
	width: 100%;
}

.dbqkbfc-bar-row {
	display: flex;
	flex-direction: row;
	align-items: center;
	gap: 10px;
	width: 100%;
}

// Search input over the full width
.dbqkbfc-search {
	position: relative;
	flex: 1 1 auto;
	min-width: 0;

	> svg {
		position: absolute;
		top: 50%;
		left: 12px;
		width: 18px;
		height: 18px;
		margin-top: -9px;
		fill: color(text-color-default);
		opacity: 0.5;
		pointer-events: none;
	}

	.dbqkbfc-input-search {
		width: 100%;
		height: 38px;
		padding: 0 12px 0 38px;
		border: 1px solid $global-border-color;
		border-radius: 19px;
		background: $color-layer-1;
		color: color(text-color-default);
		font-size: 14px;
		outline: none;

		&:focus {
			border-color: $color-primary;
		}
	}
}

// Filters button (with the panel anchored below it)
.dbqkbfc-filter-anchor {
	position: relative;
	flex: 0 0 auto;
}

.dbqkbfc-filter-button {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	height: 38px;
	padding: 0 14px;
	border: 1px solid $global-border-color;
	border-radius: 19px;
	background: $color-layer-1;
	color: color(text-color-default);
	font-size: 14px;
	font-weight: 500;
	cursor: pointer;

	svg {
		width: 18px;
		height: 18px;
		fill: color(text-color-default);
	}

	&:hover {
		border-color: $color-primary;
	}

	.dbqkbfc-filter-count:empty {
		display: none;
	}

	.dbqkbfc-filter-count {
		min-width: 20px;
		height: 20px;
		padding: 0 6px;
		border-radius: 10px;
		background: #fff;
		color: $color-primary;
		font-size: 12px;
		font-weight: 600;
		line-height: 20px;
		text-align: center;
	}

	// Tags selected
	&.dbqkbfc-filter-button-active {
		border-color: $color-primary;
		background: $color-primary;
		color: #fff;

		svg {
			fill: #fff;
		}
	}

	// No Bootstrap caret on the dropdown toggle
	&.dropdown-toggle::after {
		display: none;
	}
}

// The panel with the tag categories: a Bootstrap dropdown menu, positioned by Bootstrap (Popper) and moved to the body
// by DbqBootstrapDropdownExtension while it's open. So these styles can't depend on the filter bar around it.
.dbqkbfc-panel.dropdown-menu {
	width: 360px !important; // overrules width: min-content of body .dropdown-menu (that rule also sets the z-index)
	min-width: 0;
	max-width: calc(100vw - 30px);
	max-height: min(70vh, 560px);
	margin-top: 6px;
	padding: 0;
	flex-direction: column;
	border: 1px solid $global-border-color;
	border-radius: $global-border-radius;
	background: $dropdown-background-color;
	box-shadow: 0 6px 24px rgba(0, 0, 0, 0.18);
	overflow: hidden;

	&.show {
		display: flex;
	}
}

.dbqkbfc-panel-search {
	position: relative;
	flex: 0 0 auto;
	padding: 10px;
	border-bottom: 1px solid $global-border-color;

	> svg {
		position: absolute;
		top: 50%;
		left: 20px;
		width: 16px;
		height: 16px;
		margin-top: -8px;
		fill: color(text-color-default);
		opacity: 0.5;
		pointer-events: none;
	}

	.dbqkbfc-tag-search-input {
		width: 100%;
		height: 32px;
		padding: 0 10px 0 32px;
		border: 1px solid $global-border-color;
		border-radius: 16px;
		background: $color-layer-1;
		color: color(text-color-default);
		font-size: 13px;
		outline: none;

		&:focus {
			border-color: $color-primary;
		}
	}
}

.dbqkbfc-categories {
	flex: 1 1 auto;
	min-height: 0;
	overflow-y: auto;
	padding: 4px 0;
	@include scrollbar;
}

.dbqkbfc-category-header {
	display: flex;
	flex-direction: row;
	align-items: center;
	gap: 4px;
	padding: 6px 10px 6px 6px;
	cursor: pointer;
	user-select: none;

	&:hover {
		background: $color-layer-2;
	}

	.dbqkbfc-category-chevron {
		display: inline-flex;
		flex: 0 0 20px;
		transition: transform 0.15s ease;

		svg {
			width: 20px;
			height: 20px;
			fill: color(text-color-default);
		}
	}

	.dbqkbfc-category-name {
		flex: 0 1 auto;
		min-width: 0;
		overflow: hidden;
		white-space: nowrap;
		text-overflow: ellipsis;
		font-size: 14px;
		font-weight: 500;
		color: color(text-color-default);
	}

	.dbqkbfc-category-count {
		flex: 1 1 auto;
		font-size: 13px;
		font-weight: 600;
		color: $color-primary;
	}

	.dbqkbfc-category-clear-button {
		display: none;
		flex: 0 0 auto;
		padding: 0 4px;
		border: 0;
		background: none;
		color: $color-primary;
		font-size: 12px;
		cursor: pointer;

		&:hover {
			text-decoration: underline;
		}
	}
}

.dbqkbfc-category-tags {
	display: none;
	padding: 0 10px 6px 30px;
}

.dbqkbfc-category.dbqkbfc-category-expanded {
	.dbqkbfc-category-chevron {
		transform: rotate(90deg);
	}

	.dbqkbfc-category-tags {
		display: block;
	}
}

.dbqkbfc-category.dbqkbfc-category-has-selection {
	.dbqkbfc-category-clear-button {
		display: inline-block;
	}
}

// A tag: same selection style as DbqSelectTypePopup (a highlighted row with a checkmark on the right, no checkbox)
.dbqkbfc-tag {
	display: flex;
	flex-direction: row;
	align-items: center;
	justify-content: space-between;
	gap: 8px;
	width: 100%;
	margin: 1px 0;
	padding: 6px 8px;
	border-radius: 6px;
	font-size: 14px;
	font-weight: 400;
	color: color(text-color-default);
	cursor: pointer;
	outline: none;
	user-select: none;

	.dbqkbfc-tag-name {
		min-width: 0;
		overflow: hidden;
		white-space: nowrap;
		text-overflow: ellipsis;
	}

	.dbqkbfc-tag-checkmark {
		display: none;
		flex: 0 0 auto;

		svg {
			width: 16px;
			height: 16px;
			fill: color(text-color-default);
		}
	}

	&:hover,
	&.dbqkbfc-tag-selected {
		background: $background-item-color-default;
	}

	&:focus-visible {
		box-shadow: inset 0 0 0 2px $color-primary;
	}

	&.dbqkbfc-tag-selected {
		font-weight: 500;

		.dbqkbfc-tag-checkmark {
			display: inline-flex;
		}
	}
}

.dbqkbfc-no-tags {
	padding: 16px 10px;
	font-size: 13px;
	color: color(text-color-default);
	opacity: 0.6;
	text-align: center;
}

.dbqkbfc-panel-footer {
	display: flex;
	flex-direction: row;
	justify-content: space-between;
	flex: 0 0 auto;
	padding: 8px 10px;
	border-top: 1px solid $global-border-color;

	button {
		padding: 4px 8px;
		border: 0;
		border-radius: 4px;
		background: none;
		color: color(text-color-default);
		font-size: 13px;
		cursor: pointer;

		&:hover {
			background: $color-layer-2;
		}
	}

	.dbqkbfc-clear-all-button {
		color: $color-primary;
	}
}

// The selected tags as chips, on one line (DbqKnowledgeBaseFilterControl.layoutActiveTags hides the chips that don't fit)
.dbqkbfc-active-tags {
	display: none;
	flex-direction: row;
	flex-wrap: wrap;
	align-items: center;
	gap: 6px;
	height: 28px;
	overflow: hidden;

	.dbqkbfc-has-active-tags & {
		display: flex;
	}
}

.dbqkbfc-active-tag {
	display: inline-flex;
	align-items: center;
	gap: 2px;
	height: 28px;
	max-width: 240px;
	padding: 0 4px 0 10px;
	border: 1px solid $color-primary;
	border-radius: 14px;
	color: $color-primary;
	font-size: 13px;
	font-weight: 500;
	transition: background-color 0.15s ease;

	&:hover {
		background: rgba($color-primary, 0.1);
	}

	.dbqkbfc-active-tag-name {
		min-width: 0;
		overflow: hidden;
		white-space: nowrap;
		text-overflow: ellipsis;
	}

	.dbqkbfc-active-tag-remove {
		display: inline-flex;
		align-items: center;
		justify-content: center;
		flex: 0 0 20px;
		width: 20px;
		height: 20px;
		padding: 0;
		border: 0;
		border-radius: 10px;
		background: none;
		cursor: pointer;

		svg {
			width: 14px;
			height: 14px;
			fill: $color-primary;
		}

		&:hover {
			background: $color-primary;

			svg {
				fill: #fff;
			}
		}
	}
}

.dbqkbfc-more-tags-button,
.dbqkbfc-clear-tags-button {
	height: 28px;
	padding: 0 8px;
	border: 0;
	border-radius: 14px;
	background: none;
	color: color(text-color-default);
	font-size: 13px;
	cursor: pointer;
	transition: background-color 0.15s ease;

	&:hover {
		background: rgba($color-primary, 0.1);
	}
}

.dbqkbfc-more-tags-button {
	font-weight: 600;
}

.dbqkbfc-clear-tags-button {
	color: $color-primary;
}

// No browser focus outline on the buttons of the bar (it is cut off by the chip row). Keyboard focus gets a ring inside the button.
.dbqkbfc-bar button {
	outline: none;

	&:focus-visible {
		box-shadow: inset 0 0 0 2px $color-primary;
	}
}

// Tags in the list and in an article can be clicked to filter on them
.dbqkbe-container.dbqkbe-has-tag-filter .dbqkbe-detail-pane-body .dbqkba-document-tag {
	cursor: pointer;

	&:hover {
		filter: brightness(0.92);
	}
}
