/*!
 * Copyright 2024 Adobe. All rights reserved.
 *
 * This file is licensed to you under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License. You may obtain a copy
 * of the License at <http://www.apache.org/licenses/LICENSE-2.0>
 *
 * Unless required by applicable law or agreed to in writing, software distributed under
 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
 * OF ANY KIND, either express or implied. See the License for the specific language
 * governing permissions and limitations under the License.
 */

@import "./themes/spectrum-two.css";

@media (forced-colors: active) {
	.spectrum-TreeView {
		--highcontrast-treeview-item-background-color-selected: Highlight;
		--highcontrast-treeview-item-border-color-selected: Highlight;
		--highcontrast-treeview-item-text-color-selected: HighlightText;
		--highcontrast-treeview-item-icon-color-selected: HighlightText;

		--highcontrast-treeview-item-icon-color: LinkText;
		--highcontrast-treeview-item-text-color: LinkText;

		--highcontrast-treeview-item-background-color-focus: Highlight;
		--highcontrast-treeview-item-text-color-focus: HighlightText;
		--highcontrast-treeview-item-border-color-focus: CanvasText;
		--highcontrast-treeview-item-icon-color-focus: HighlightText;

		--highcontrast-treeview-item-background-color-disabled: Canvas;
		--highcontrast-treeview-item-text-color-disabled: GrayText;
		--highcontrast-treeview-item-icon-color-disabled: GrayText;

		--highcontrast-treeview-heading-color: CanvasText;
	}

	@supports (color: SelectedItem) {
		.spectrum-TreeView {
			--highcontrast-treeview-item-background-color-selected: SelectedItem;
			--highcontrast-treeview-item-border-color-selected: SelectedItem;
			--highcontrast-treeview-item-text-color-selected: SelectedItemText;
			--highcontrast-treeview-item-icon-color-selected: SelectedItemText;
		}
	}

	.spectrum-TreeView-itemLabel {
		forced-color-adjust: none;
		background: transparent;
	}

	.spectrum-TreeView-itemLink::before {
		forced-color-adjust: none;
	}
}

.spectrum-TreeView,
.spectrum-TreeView--sizeM {
	--spectrum-treeview-font-size: var(--mod-treeview-font-size, var(--spectrum-font-size-100));

	--spectrum-treeview-item-sized-min-block-size: var(--mod-treeview-item-min-block-size, var(--spectrum-component-height-100));
	--spectrum-treeview-item-sized-indentation: var(--spectrum-treeview-item-indentation-medium);
	--spectrum-treeview-heading-bottom-to-text: var(--mod-treeview-heading-bottom-to-text, var(--spectrum-component-edge-to-text-100));

	--spectrum-treeview-item-padding-inline-start: var(--mod-treeview-item-padding-inline-start, var(--spectrum-component-height-100));
	--spectrum-treeview-item-padding-inline-end: var(--mod-treeview-item-padding-inline-end, var(--spectrum-component-edge-to-text-100));
	--spectrum-treeview-indicator-margin-inline-start: var(--mod-treeview-indicator-margin-inline-start, calc(-1 * var(--spectrum-component-height-100)));
	--spectrum-treeview-indicator-padding: var(--spectrum-disclosure-indicator-top-to-disclosure-icon-medium);

	--spectrum-treeview-item-min-block-size-thumbnail-offset: var(--spectrum-treeview-item-min-block-size-thumbnail-offset-medium, 0);
}

.spectrum-TreeView--sizeS {
	--spectrum-treeview-font-size: var(--mod-treeview-font-size, var(--spectrum-font-size-75));

	--spectrum-treeview-item-sized-min-block-size: var(--mod-treeview-item-min-block-size, var(--spectrum-component-height-75));
	--spectrum-treeview-item-sized-indentation: var(--spectrum-treeview-item-indentation-small);
	--spectrum-treeview-heading-bottom-to-text: var(--mod-treeview-heading-bottom-to-text, var(--spectrum-component-edge-to-text-75));

	--spectrum-treeview-item-padding-inline-start: var(--mod-treeview-item-padding-inline-start, var(--spectrum-component-height-75));
	--spectrum-treeview-item-padding-inline-end: var(--mod-treeview-item-padding-inline-end, var(--spectrum-component-edge-to-text-75));
	--spectrum-treeview-indicator-margin-inline-start: var(--mod-treeview-indicator-margin-inline-start, calc(-1 * var(--spectrum-component-height-75)));
	--spectrum-treeview-indicator-padding: var(--spectrum-disclosure-indicator-top-to-disclosure-icon-small);

	--spectrum-treeview-item-min-block-size-thumbnail-offset: 6px;
}

.spectrum-TreeView--sizeL {
	--spectrum-treeview-font-size: var(--mod-treeview-font-size, var(--spectrum-font-size-200));

	--spectrum-treeview-item-sized-indentation: var(--spectrum-treeview-item-indentation-large);
	--spectrum-treeview-item-sized-min-block-size: var(--mod-treeview-item-min-block-size, var(--spectrum-component-height-200));
	--spectrum-treeview-heading-bottom-to-text: var(--mod-treeview-heading-bottom-to-text, var(--spectrum-component-edge-to-text-200));

	--spectrum-treeview-item-padding-inline-start: var(--mod-treeview-item-padding-inline-start, var(--spectrum-component-height-200));
	--spectrum-treeview-item-padding-inline-end: var(--mod-treeview-item-padding-inline-end, var(--spectrum-component-edge-to-text-200));
	--spectrum-treeview-indicator-margin-inline-start: var(--mod-treeview-indicator-margin-inline-start, calc(-1 * var(--spectrum-component-height-200)));
	--spectrum-treeview-indicator-padding: var(--spectrum-disclosure-indicator-top-to-disclosure-icon-large);

	--spectrum-treeview-item-min-block-size-thumbnail-offset: 0;
}

.spectrum-TreeView--sizeXL {
	--spectrum-treeview-font-size: var(--mod-treeview-font-size, var(--spectrum-font-size-300));

	--spectrum-treeview-item-sized-indentation: var(--spectrum-treeview-item-indentation-extra-large);
	--spectrum-treeview-item-sized-min-block-size: var(--mod-treeview-item-min-block-size, var(--spectrum-component-height-300));
	--spectrum-treeview-heading-bottom-to-text: var(--mod-treeview-heading-bottom-to-text, var(--spectrum-component-edge-to-text-300));

	--spectrum-treeview-item-padding-inline-start: var(--mod-treeview-item-padding-inline-start, var(--spectrum-component-height-300));
	--spectrum-treeview-item-padding-inline-end: var(--mod-treeview-item-padding-inline-end, var(--spectrum-component-edge-to-text-300));
	--spectrum-treeview-indicator-margin-inline-start: var(--mod-treeview-indicator-margin-inline-start, calc(-1 * var(--spectrum-component-height-300)));
	--spectrum-treeview-indicator-padding: var(--spectrum-disclosure-indicator-top-to-disclosure-icon-extra-large);

	--spectrum-treeview-item-min-block-size-thumbnail-offset: 0;
}

.spectrum-TreeView {
	--spectrum-treeview-item-indentation: var(--mod-treeview-item-indentation, var(--spectrum-treeview-item-sized-indentation));
	--spectrum-treeview-section-spacing: var(--mod-treeview-section-spacing, var(--spectrum-treeview-item-indentation));
	--spectrum-treeview-heading-color: var(--highcontrast-treeview-heading-color, var(--mod-treeview-heading-color, var(--spectrum-heading-color)));

	--spectrum-treeview-item-border-size: var(--mod-treeview-item-border-size, var(--spectrum-border-width-200));
	--spectrum-treeview-item-border-size-selected: var(--mod-treeview-item-border-size-selected, 1px);
	--spectrum-treeview-item-border-radius: var(--mod-treeview-item-border-radius, 0px);

	--spectrum-treeview-item-border-color-selected: var(--highcontrast-treeview-item-border-color-selected, var(--mod-treeview-item-border-color-selected, var(--spectrum-blue-800)));
	--spectrum-treeview-item-border-color-focus: var(--highcontrast-treeview-item-border-color-focus, var(--mod-treeview-item-border-color-focus, var(--spectrum-blue-700)));

	--spectrum-treeview-item-border-color-quiet-selected: var(--highcontrast-treeview-item-border-color-selected, var(--mod-treeview-item-border-color-selected-quiet, transparent));

	--spectrum-treeview-item-icon-gap: var(--mod-treeview-item-icon-gap, var(--spectrum-text-to-visual-75));
	--spectrum-treeview-item-icon-color: var(--highcontrast-treeview-item-icon-color, var(--mod-treeview-item-icon-color, var(--spectrum-gray-700)));
	--spectrum-treeview-item-icon-color-hover: var(--highcontrast-treeview-item-text-color-focus, var(--mod-treeview-item-icon-color-hover, var(--spectrum-gray-900)));
	--spectrum-treeview-item-icon-color-focus: var(--highcontrast-treeview-item-icon-color-focus, var(--mod-treeview-item-icon-color-focus, var(--spectrum-gray-900)));
	--spectrum-treeview-item-icon-color-selected: var(--highcontrast-treeview-item-icon-color-selected, var(--mod-treeview-item-icon-color-selected, var(--spectrum-gray-900)));
	--spectrum-treeview-item-icon-color-disabled: var(--highcontrast-treeview-item-icon-color-disabled, var(--mod-treeview-item-icon-color-disabled, var(--spectrum-disabled-content-color)));

	--spectrum-treeview-item-text-color: var(--highcontrast-treeview-item-text-color, var(--mod-treeview-item-text-color, var(--spectrum-neutral-content-color-default)));
	--spectrum-treeview-item-text-color-selected: var(--highcontrast-treeview-item-text-color-selected, var(--mod-treeview-item-text-color-selected, var(--spectrum-gray-900)));
	--spectrum-treeview-item-text-color-disabled: var(--highcontrast-treeview-item-text-color-disabled, var(--mod-treeview-item-text-color-disabled, var(--spectrum-gray-500)));
	--spectrum-treeview-item-text-color-focus: var(--highcontrast-treeview-item-text-color-focus, var(--mod-treeview-item-text-color-focus, var(--spectrum-gray-900)));
	--spectrum-treeview-item-text-color-hover: var(--highcontrast-treeview-item-text-color-focus, var(--mod-treeview-item-text-color-hover, var(--spectrum-gray-900)));

	--spectrum-treeview-indicator-animation-duration: var(--mod-treeview-indicator-animation-duration, var(--spectrum-animation-duration-100));

	--spectrum-treeview-item-min-block-size: var(--mod-treeview-item-min-block-size, var(--spectrum-treeview-item-sized-min-block-size));

	&.spectrum-TreeView--quiet {
		--mod-treeview-item-background-color-selected: var(--highcontrast-treeview-item-background-color-selected, var(--mod-treeview-item-background-color-quiet-selected, var(--spectrum-treeview-item-background-color-quiet-selected)));
		--mod-treeview-item-border-color-selected: var(--spectrum-treeview-item-border-color-quiet-selected);
	}

	&.spectrum-TreeView--thumbnail {
		--spectrum-treeview-item-min-block-size: var(--mod-treeview-item-min-block-size-thumbnail, calc(var(--spectrum-treeview-item-sized-min-block-size) + var(--spectrum-treeview-item-min-block-size-thumbnail-offset)));
	}

	&.spectrum-TreeView--detached {
		--mod-treeview-item-border-radius: var(--mod-treeview-item-border-radius-detached, var(--spectrum-corner-radius-100));
	}

	display: block;
	position: relative;
	padding: 0;
	list-style: none;
	outline: none;
	user-select: none;
	line-height: var(--mod-treeview-line-height, var(--spectrum-line-height-200));
	margin-block: var(--mod-treeview-margin-block, 1em);
	font-size: var(--spectrum-treeview-font-size);

	&:dir(rtl) {
		--spectrum-logical-rotation: matrix(-1, 0, 0, 1, 0, 0);
	}

	/* Close (hide) nested treeviews by default. */
	.spectrum-TreeView {
		position: static;
		block-size: 0;
		display: none;
		padding-inline-start: var(--spectrum-treeview-item-indentation);
		margin-block: 0;
	}
}

.spectrum-TreeView-item {
	/* Don't let child treeviews that are open spill out */
	overflow: hidden;

	&.is-open {
		& > .spectrum-TreeView-itemLink > .spectrum-TreeView-itemIndicator {
			/* Rotate the chevron */
			transform: var(--spectrum-logical-rotation,) rotate(90deg);
		}

		& > .spectrum-TreeView {
			/* Open the treeview */
			block-size: auto;
			display: block;
		}
	}

	&.is-selected,
	&.is-drop-target {
		& > .spectrum-TreeView-itemLink {
			color: var(--spectrum-treeview-item-text-color-selected);

			&::before {
				background-color: var(--highcontrast-treeview-item-background-color-selected, var(--mod-treeview-item-background-color-selected, var(--spectrum-treeview-item-background-color-selected)));
			}

			& .spectrum-TreeView-itemIcon {
				color: var(--spectrum-treeview-item-icon-color-selected);
			}
		}

		& > .spectrum-TreeView-itemLink:not(:focus-visible)::before {
			border-color: var(--spectrum-treeview-item-border-color-selected);
		}
	}

	&.is-selected > .spectrum-TreeView-itemLink:not(:focus-visible)::before {
		border-width: var(--spectrum-treeview-item-border-size-selected);
	}

	&.is-drop-target > .spectrum-TreeView-itemLink::before {
		border-width: var(--spectrum-treeview-item-border-size);
	}

	&.is-disabled > .spectrum-TreeView-itemLink {
		color: var(--spectrum-treeview-item-text-color-disabled);

		&::before {
			background-color: var(--highcontrast-treeview-item-background-color-disabled, transparent);
		}

		& .spectrum-Icon {
			color: var(--spectrum-treeview-item-icon-color-disabled);
		}
	}
}

.spectrum-TreeView-itemLabel {
	overflow: hidden;
	text-overflow: ellipsis;
	position: relative;
}

.spectrum-TreeView-itemLink {
	box-sizing: border-box;
	display: flex;
	flex-flow: row nowrap;
	align-items: center;

	min-block-size: var(--spectrum-treeview-item-min-block-size);
	padding-inline-start: var(--spectrum-treeview-item-padding-inline-start);
	padding-inline-end: var(--spectrum-treeview-item-padding-inline-end);

	color: var(--spectrum-treeview-item-text-color);

	text-decoration: none;
	outline: none;
	cursor: pointer;

	/* Prevent weirdness that can cause the vertical bar to fall down. */
	white-space: nowrap;
	overflow: hidden;

	/* Background for hover, focus, and selection, that extends the full width of the list. */
	&::before {
		content: "\00a0";
		box-sizing: border-box;
		position: absolute;
		inset-inline: 0;
		min-block-size: var(--spectrum-treeview-item-min-block-size);

		border-style: solid;
		border-color: transparent;
		border-width: var(--spectrum-treeview-item-border-size) 0;
		border-radius: var(--spectrum-treeview-item-border-radius);
		background-color: transparent;
		color: transparent;
	}

	&:focus-visible {
		color: var(--spectrum-treeview-item-text-color-focus);

		&::before {
			background-color: var(--highcontrast-treeview-item-background-color-focus, var(--mod-treeview-item-background-color-focus, var(--spectrum-treeview-item-background-color-focus)));
			border-width: var(--spectrum-treeview-item-border-size);
			border-color: var(--spectrum-treeview-item-border-color-focus);
		}

		& .spectrum-TreeView-itemIcon {
			color: var(--spectrum-treeview-item-icon-color-focus);
		}
	}

	&:hover {
		color: var(--spectrum-treeview-item-text-color-hover);

		&::before {
			background-color: var(--highcontrast-treeview-item-background-color-focus, var(--mod-treeview-item-background-color-hover, var(--spectrum-treeview-item-background-color-hover)));
		}

		& .spectrum-TreeView-itemIcon {
			color: var(--spectrum-treeview-item-icon-color-hover);
		}
	}
}

.spectrum-TreeView-itemIcon {
	position: relative;
	vertical-align: top;
	flex-shrink: 0;
	margin-inline-end: var(--spectrum-treeview-item-icon-gap);
	color: var(--spectrum-treeview-item-icon-color);
}

.spectrum-TreeView-itemIndicator {
	display: block;
	box-sizing: content-box;
	position: relative;
	flex-shrink: 0;

	/* Make sure the hover background pseudo element doesn't block clicks on the chevron. */
	z-index: 1;

	padding-inline: var(--mod-treeview-indicator-padding-inline, var(--spectrum-treeview-indicator-padding));
	padding-block: var(--mod-treeview-indicator-padding-block, var(--spectrum-treeview-indicator-padding));
	margin-inline-start: var(--spectrum-treeview-indicator-margin-inline-start);

	transition: transform ease var(--spectrum-treeview-indicator-animation-duration);
	pointer-events: all;
	transform: var(--spectrum-logical-rotation,);
}

/* Section headings */
.spectrum-TreeView-section > .spectrum-TreeView {
	display: block;
	block-size: auto;
	padding-inline-start: 0;
}

.spectrum-TreeView-section:not(:first-child) {
	margin-block-start: var(--spectrum-treeview-section-spacing);
}

.spectrum-TreeView-heading {
	padding-block-end: var(--spectrum-treeview-heading-bottom-to-text);
	font-weight: var(--mod-treeview-heading-font-weight, var(--spectrum-bold-font-weight));
	color: var(--spectrum-treeview-heading-color);
}

/* Indentation levels used with Flat structure variant. */
.spectrum-TreeView-item--indent1 {
	padding-inline-start: calc(1 * var(--spectrum-treeview-item-indentation));
}

.spectrum-TreeView-item--indent2 {
	padding-inline-start: calc(2 * var(--spectrum-treeview-item-indentation));
}

.spectrum-TreeView-item--indent3 {
	padding-inline-start: calc(3 * var(--spectrum-treeview-item-indentation));
}

.spectrum-TreeView-item--indent4 {
	padding-inline-start: calc(4 * var(--spectrum-treeview-item-indentation));
}

.spectrum-TreeView-item--indent5 {
	padding-inline-start: calc(5 * var(--spectrum-treeview-item-indentation));
}

.spectrum-TreeView-item--indent6 {
	padding-inline-start: calc(6 * var(--spectrum-treeview-item-indentation));
}

.spectrum-TreeView-item--indent7 {
	padding-inline-start: calc(7 * var(--spectrum-treeview-item-indentation));
}

.spectrum-TreeView-item--indent8 {
	padding-inline-start: calc(8 * var(--spectrum-treeview-item-indentation));
}

.spectrum-TreeView-item--indent9 {
	padding-inline-start: calc(9 * var(--spectrum-treeview-item-indentation));
}

.spectrum-TreeView-item--indent10 {
	padding-inline-start: calc(10 * var(--spectrum-treeview-item-indentation));
}

/* ***** VARIANTS ***** */
.spectrum-TreeView--thumbnail .spectrum-TreeView-itemThumbnail {
	flex-shrink: 0;
	margin-inline-end: var(--spectrum-treeview-item-icon-gap);
}
