/* 
MIT LICENSE
Copyright (c) 2020-present Alibaba Cloud Design
Copied from 'antd/lib/tree/style/mixin.less';
Copyright (c) 2015-present Ant UED, https://xtech.antfin.com/

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
// @import url(~antd/lib/style/mixins/index';
@import '../../style/themes/index';
@import '../../style/mixins/index.less';

@tree-prefix-cls: ~'@{ant-prefix}-tree';
@select-tree-prefix-cls: ~'@{ant-prefix}-select-tree';
@tree-motion: ~'@{ant-prefix}-motion-collapse';
@tree-node-padding: (@padding-xs / 2);
@tree-node-hightlight-color: inherit;

@tree-switch-icon-size: @font-size-base;
@tree-switch-icon-margin-right: 8px;

.antTreeSwitcherIcon(@type: 'tree-default-open-icon') {
	.@{tree-prefix-cls}-switcher-icon,
	.@{select-tree-prefix-cls}-switcher-icon {
		display: inline-block;
		font-size: @tree-switch-icon-size;
		vertical-align: baseline;

		svg {
			transition: transform 0.3s;
		}
	}
}

.drop-indicator() {
	.@{tree-prefix-cls}-drop-indicator {
		position: absolute;
		// it should displayed over the following node
		z-index: 1;
		height: 2px;
		background-color: @primary-color;
		border-radius: 1px;
		pointer-events: none;

		&::after {
			position: absolute;
			top: -3px;
			left: -6px;
			width: 8px;
			height: 8px;
			background-color: transparent;
			border: 2px solid @primary-color;
			border-radius: 50%;
			content: '';
		}
	}
}

.antTreeFn(@custom-tree-prefix-cls) {
	@custom-tree-node-prefix-cls: ~'@{custom-tree-prefix-cls}-treenode';
	.reset-component();
	background: @tree-bg;
	border-radius: @border-radius-base;
	font-size: @font-size-sm;
	line-height: @layout-height-2;
	transition: background-color 0.3s;
	color: @text-color;
	font-size:@font-size-md;
	
	&-focused:not(:hover):not(&-active-focused) {
		background: @primary-10;
	}

	&-title {
		font-size: inherit;
		line-height: inherit;
		margin-left: @margin-xss;
	}

	// =================== Virtual List ===================
	&-list-holder-inner {
		align-items: flex-start;
	}

	&.@{custom-tree-prefix-cls}-block-node {
		.@{custom-tree-prefix-cls}-list-holder-inner {
			align-items: stretch;

			// >>> Title
			.@{custom-tree-prefix-cls}-node-content-wrapper {
				flex: auto;
				display: flex;
				align-items: center;
			}
		}
	}

	// ===================== TreeNode =====================
	.@{custom-tree-node-prefix-cls} {
		display: flex;
		align-items: flex-start;
		padding: 0 @padding-md;
		outline: none;
		width: 100%;
		border-radius:@border-radius-base;
		
		// Disabled
		&-disabled {
			// >>> Title
			.@{custom-tree-prefix-cls}-node-content-wrapper {
				color: @tree-disabled-color;
				cursor: not-allowed;

				&:hover {
					background: transparent;
					color: @tree-disabled-color;
					.@{custom-tree-prefix-cls}-iconEle {
						color: @tree-disabled-color;
					}
				}

				.@{custom-tree-prefix-cls}-iconEle {
					color: @tree-disabled-color;
				}
			}

			// >>> Icon
			.@{custom-tree-prefix-cls}-switcher-icon {
				color: @tree-disabled-color;
			}
		}

		&-active .@{custom-tree-prefix-cls}-node-content-wrapper {
			background: @tree-node-hover-bg;
		}

		&:not(&-disabled).filter-node .@{custom-tree-prefix-cls}-title {
			color: @tree-node-hightlight-color;
			font-weight: 500;
		}
	}


	//// =====================checkable hover时出现背景色=====================
	&-checkable{
		.@{custom-tree-node-prefix-cls} {
			transition: all @animation-duration-slow @ease-in-out;
			&:not(&-disabled):hover  {
			background: @component-background-hover;
			}
		}
	}
	// >>> Indent
	&-indent {
		align-self: stretch;
		white-space: nowrap;
		user-select: none;

		&-unit {
			display: inline-block;
			width: calc(@tree-switch-icon-margin-right + @tree-switch-icon-size);
		}
	}

	// >>> Switcher
	&-switcher {
		.antTreeSwitcherIcon();
		position: relative;
		font-size: @tree-switch-icon-size;
		display: flex;
		align-items: center;
		align-self: stretch;
		color: @gray-60;
		width: @tree-switch-icon-size;
		justify-content: center;
		margin: 0;
		margin-right: 8px;
		line-height: @layout-height-1;
		text-align: center;
		cursor: pointer;
		user-select: none;

		&-noop {
			cursor: default;
			width: calc(@tree-switch-icon-size + @tree-switch-icon-margin-right);
			margin: 0;
		}

		&_close {
			.@{custom-tree-prefix-cls}-switcher-icon {
				svg {
					transform: rotate(-90deg);
				}
			}
		}

		&-loading-icon {
			color: @primary-color;
		}

		&-leaf-line {
			position: relative;
			z-index: 1;
			display: inline-block;
			width: 100%;
			height: 100%;

			&::before {
				position: absolute;
				top: 0;
				bottom: -@tree-node-padding + 4px;
				right: (@tree-switch-icon-margin-right + @tree-switch-icon-size / 2);
				border-left: 1px solid @gray-20;
				content: ' ';
			}

			&::after {
				position: absolute;
				right: (@tree-switch-icon-margin-right / 2 + 1px);
				width: calc(@tree-switch-icon-size / 2 + @tree-switch-icon-margin-right / 2);
				height: 50%;
				border-bottom-left-radius: @border-radius-base;
				border: 1px solid @gray-20;
				border-right: none;
				border-top: none;
				content: ' ';
			}
		}
	}

	// >>> Checkbox
	&-checkbox {
		top: initial;
		margin-top: calc((@tree-title-height - @checkbox-size-sm) / 2);
		margin-right: calc((@tree-switch-icon-size - @checkbox-size-sm) / 2 + @tree-switch-icon-margin-right);
		margin-left: calc((@tree-switch-icon-size - @checkbox-size-sm) / 2);

		&-inner {
			width: @checkbox-size-sm;
			height: @checkbox-size-sm;
		}
	}

	// >>> Title
	& &-node-content-wrapper {
		position: relative;
		z-index: auto;
		min-height: @tree-title-height;
		margin: 0;
		padding: 6px 0;
		color: inherit;
		line-height: 20px;
		display: inline-flex;
		align-items: center;
		background: transparent;
		border-radius: @border-radius-base;
		cursor: pointer;
		transition: all 0.3s, border 0s, line-height 0s, box-shadow 0s;

		&:not(.@{custom-tree-node-prefix-cls}-disabled .@{custom-tree-prefix-cls}-node-content-wrapper):not(.@{custom-tree-prefix-cls}-checkable .@{custom-tree-prefix-cls}-node-content-wrapper):hover {
			background-color: @tree-node-hover-bg;
			color: @primary-color;
			.@{tree-prefix-cls}-iconEle {
				color: @primary-color;
			}
		}

		&.@{custom-tree-prefix-cls}-node-selected {
			background-color: @tree-node-selected-bg;
			color: @primary-color;

			.@{tree-prefix-cls}-iconEle {
				color: @primary-color;
			}
		}

		// Icon
		.@{custom-tree-prefix-cls}-iconEle {
			display: inline-block;
			color: @font-color-caption;
			width: initial;
			height: @tree-switch-icon-size;
			line-height: 1;
			text-align: center;
			vertical-align: top;
			margin-right: @tree-switch-icon-margin-right;
			font-size: @iconfont-size-xs;

			&:empty {
				display: none;
			}
		}
	}

	// https://github.com/ant-design/ant-design/issues/28217
	&-unselectable &-node-content-wrapper:hover {
		background-color: transparent;
	}

	// ==================== Draggable =====================
	&-node-content-wrapper[draggable='true'] {
		line-height: @layout-height-2;
		user-select: none;

		.drop-indicator();
	}

	.@{custom-tree-node-prefix-cls}.drop-container {
		> [draggable] {
			box-shadow: 0 0 0 2px @primary-color;
		}
	}

	// ==================== Show Line =====================
	&-show-line {
		// ================ Indent lines ==================
		.@{custom-tree-prefix-cls}-indent {
			&-unit {
				position: relative;
				height: 100%;

				&::before {
					position: absolute;
					top: 0;
					right: (@tree-switch-icon-margin-right + @tree-switch-icon-size / 2);
					bottom: -@tree-node-padding;
					border-right: 1px solid @gray-20;
					content: '';
				}

				&-end {
					&::before {
						display: none;
					}
				}
			}
		}

		// ============== Cover Background ==============
		.@{custom-tree-prefix-cls}-switcher {
			&-line-icon {
				vertical-align: -0.225em;
			}
		}
		// ===================== TreeNode =====================
		.@{custom-tree-prefix-cls}-treenode{
			
			&:not(&-disabled):hover,
			&-selected {
				.@{custom-tree-prefix-cls}-switcher {
					color: @primary-color;
				}
			}
			
		}
	}

	.@{custom-tree-node-prefix-cls}-leaf-last {
		.@{custom-tree-prefix-cls}-switcher {
			&-leaf-line {
				&::before {
					top: auto !important;
					bottom: auto !important;
					height: 50% - @border-radius-base * 2 !important;
				}
			}
		}
	}

	// ==================== large size =====================
	&-large {
		font-size:@font-size-base;
	}

	&&-large &-node-content-wrapper {
		padding: 8px 0;
	}

	&-large &-checkbox {
		margin-top: calc((@tree-title-height + 4px - @checkbox-size-sm) / 2);
	}
}

// B-Design
.tree-line() {
	&::before {
		position: absolute;
		top: 0;
		left: 50%;
		bottom: -@tree-node-padding;
		border-right: 1px solid @border-color-base;
		content: '';
		transition: none;
	}
}

.tree-line-radius() {
	&::after {
		content: '';
		display: block;
		position: absolute;
		top: -4px;
		bottom: 50%;
		right: 0;
		left: 50%;
		border-bottom-left-radius: 4px;
		border: solid 1px @gray-20;
		border-right: none;
		border-top: none;
		box-sizing: border-box;
		transition: none;
	}
}
