/* 
MIT LICENSE
Copyright (c) 2020-present Alibaba Cloud Design
Copied from antd/components/input/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 '../../style/themes/index';
@import '../../style/mixins/index.less';

@input-prefix-cls: ~'@{ant-prefix}-input';
@icon-prefix-cls: ~'@{ant-prefix}-icon';

// size mixins for input
.bd-input-lg() {
	padding: @input-padding-vertical-lg @input-padding-horizontal-lg;
	font-size: @font-size-base;
	line-height: @layout-height-3;

	.@{icon-prefix-cls} {
		font-size: @input-icon-size-lg;
	}

	//loading-icon-size
	.@{icon-prefix-cls}-loading {
		height: 24px;
		svg {
			width: @input-icon-size-lg;
			height: @input-icon-size-lg;
		}
	}
}

.bd-input-md() {
	padding: @input-padding-vertical @input-padding-horizontal;
	font-size: @font-size-md;
	line-height: @layout-height-2;

	.@{icon-prefix-cls} {
		font-size: @input-icon-size-md;
	}

	//loading-icon-size
	.@{icon-prefix-cls}-loading {
		height: 18px;
		svg {
			width: @input-icon-size-md;
			height: @input-icon-size-md;
		}
	}
}

.bd-input-sm() {
	padding: @input-padding-vertical-sm @input-padding-horizontal-base;
	font-size: @font-size-sm;

	.@{icon-prefix-cls} {
		font-size: @input-icon-size-sm;
	}

	//loading-icon-size
	.@{icon-prefix-cls}-loading {
		svg {
			width: @input-icon-size-sm;
			height: @input-icon-size-sm;
		}
	}
}

.bd-input-xs() {
	padding: @input-padding-vertical-xs @input-padding-horizontal-sm;
	font-size: @font-size-sm;

	.@{icon-prefix-cls} {
		font-size: @input-icon-size-sm;
	}
	//loading-icon-size
	.@{icon-prefix-cls}-loading {
		svg {
			width: @input-icon-size-sm;
			height: @input-icon-size-sm;
		}
	}
}

// input status
// == when focus or active

.bd-active(@color: @input-focus-border-color) {
	border-color: @color;
	outline: 0;
	box-shadow: none;

	// gradient border
	.gradient-border(@gradient-border);
	// .@{icon-prefix-cls} {
	// 	color: @text-color;
	// }
}

// == when hover
.bd-hover(@color: @input-hover-border-color) {
	border-color: @color;
	// .@{icon-prefix-cls} {
	// 	color: @text-color;
	// }
}

.bd-disabled() {
	color: @input-disabled-color;
	background-color: @input-disabled-bg;
	border-color: @input-border-color;
	box-shadow: none;
	cursor: not-allowed;
	opacity: 1;
	.@{icon-prefix-cls} {
		color: @input-disabled-color!important;
	}
	&:hover {
		.bd-hover(@input-border-color);
		.@{icon-prefix-cls} {
			color: @input-disabled-color!important;
		}
	}
	&::placeholder {
		color: @input-disabled-color;
	}
}

.error(@bgColor:@component-background,@borderColor:@danger-color) {
	border-color: @borderColor;
	background-color: @bgColor;

	&:hover:not(&-disabled) {
		border-color: @borderColor;
		background-color: @bgColor;
	}

	&:focus:not(&-disabled) {
		border-color: @borderColor;
		background-color: @bgColor;
	}
}
.warning(@bgColor:@component-background,@borderColor:@warning-color) {
	border-color: @borderColor;
	background-color: @bgColor;

	&:hover:not(&-disabled) {
		border-color: @borderColor;
		background-color: @bgColor;
	}

	&:focus:not(&-disabled) {
		border-color: @borderColor;
		background-color: @bgColor;
	}
}

.input-base() {
	position: relative;
	display: inline-block;
	width: 100%;
	min-width: 0;
	color: @input-color;
	background: @input-bg;
	background-size: 100%;
	background-image: none;
	border: @border-width-base @border-style-base @input-border-color;
	border-radius: @border-radius-base;
	transition: all @animation-duration-slow @ease-in-out;
	.placeholder(); // Reset placeholder

	// &:not(textarea) {
	// 	padding-right: @padding-xs;
	// }

	&:hover {
		.bd-hover();
	}

	&:focus,
	&-focused {
		box-shadow: none;
	}

	&:not(&-error):not(&-warning):focus,
	&-focused:not(&-error):not(&-warning) {
		&,
		&:hover {
			.bd-active();
		}
	}

	&-breathing:focus,
	&-breathing&-focused {
		&,
		&:hover {
			.gradient-breathing-animation();
			animation-duration: 5s;
		}
	}

	&-disabled {
		.bd-disabled();
	}

	&[disabled] {
		.bd-disabled();
	}

	&-error {
		.error() !important;
		//icon也变红
		.@{input-prefix-cls}-suffix {
			.@{icon-prefix-cls} {
				color: @danger-color!important;
			}
		}
	}
	&-warning {
		.warning() !important;
		.@{input-prefix-cls}-suffix {
			.@{icon-prefix-cls} {
				color: @warning-color!important;
			}
		}
	}

	// Reset height for `textarea`s
	textarea& {
		max-width: 100%; // prevent textearea resize from coming out of its container
		height: auto;
		min-height: @input-height-base;
		line-height: @layout-height-2;
		vertical-align: bottom;
		transition: all 0.3s, height 0s;
	}

	textarea&&-lg {
		.bd-input-lg();
	}

	.bd-input-md();

	// Size
	&-lg {
		.bd-input-lg();
	}

	&-sm {
		.bd-input-sm();
	}

	&-xs {
		.bd-input-xs();
	}
}

// Group
.addon(@bgcolor,@border-color) {
	background-color: @bgcolor;
	border: @border-width-base @border-style-base @border-color;
}

// Group
// label input
.input-group(@inputClass) {
	position: relative;
	display: table;
	width: 100%;
	border-collapse: separate;
	border-spacing: 0;
	.@{input-prefix-cls}:hover {
		z-index: 2;
		& + &-addon {
			z-index: -1;
		}
	}
	// Undo padding and float of grid classes
	&[class*='col-'] {
		float: none;
		padding-right: 0;
		padding-left: 0;
	}

	> [class*='col-'] {
		padding-right: 8px;

		&:last-child {
			padding-right: 0;
		}
	}

	&-wrapper {
		border-radius: @border-radius-base;
	}

	&-wrapper.@{input-prefix-cls}-error {
		.@{input-prefix-cls} {
			.error();
		}

		// Remove the Separator in error state.
		.@{input-prefix-cls}-group-addon::after,
		.@{input-prefix-cls}-group-addon::before {
			content: none;
		}
	}
	&-wrapper.@{input-prefix-cls}-warning {
		.@{input-prefix-cls} {
			.warning();
		}
	}
	&-wrapper.@{input-prefix-cls}-breathing {
		.@{input-prefix-cls}:focus {
			&,
			&:hover {
				.gradient-breathing-animation();
				animation-duration: 5s;
			}
		}
	}

	&-addon {
		position: relative;
		padding: 0 @input-padding-horizontal-base;
		color: @input-color;
		font-weight: normal;
		font-size: @font-size-base;
		text-align: center;
		border-radius: @border-radius-base;
		transition: all 0.3s;
		line-height: 18px;
		border: @border-width-base @border-style-base @input-border-color;
		background-color: @background-color-base;

		// Reset Select's style in addon
		.@{ant-prefix}-select {
			z-index: 1;
			margin: -(@input-padding-vertical-base + 1px) (-@input-padding-horizontal-base);

			&.@{ant-prefix}-select-single:not(.@{ant-prefix}-select-customize-input) .@{ant-prefix}-select-selector {
				background-color: @white;
				// border: @border-width-base @border-style-base transparent;
				border-color: @input-border-color;
				box-shadow: none;
				margin-left: -1px;
				width: calc(100% + 2px);
			}

			&-open,
			&-focused {
				.@{ant-prefix}-select-selector {
					color: @primary-color;
				}
			}
		}

		// https://github.com/ant-design/ant-design/issues/31333
		.@{ant-prefix}-cascader-picker {
			margin: -9px (-@control-padding-horizontal);
			background-color: transparent;
			.@{ant-prefix}-cascader-input {
				text-align: left;
				border: 0;
				box-shadow: none;
			}
		}
	}

	&-addon:first-child {
		border-right: 0 !important;
	}

	&-addon:last-child {
		border-left: 0 !important;
	}

	> .@{inputClass}-affix-wrapper {
		&:not(:first-child) .@{inputClass} {
			border-top-left-radius: 0;
			border-bottom-left-radius: 0;
		}

		&:not(:last-child) .@{inputClass} {
			border-top-right-radius: 0;
			border-bottom-right-radius: 0;
		}
	}

	// Sizing options
	&-lg .@{inputClass},
	&-wrapper-lg .@{inputClass},
	&-wrapper-lg &-addon {
		.bd-input-lg();
	}
	&-sm .@{inputClass},
	&-wrapper-sm .@{inputClass},
	&-wrapper-sm &-addon {
		.bd-input-sm();
	}
	&-xs .@{inputClass},
	&-wrapper-xs .@{inputClass},
	&-wrapper-xs &-addon {
		.bd-input-xs();
	}

	//search时xs样式
	&-wrapper &-addon {
		.@{ant-prefix}-btn.@{ant-prefix}-input-search-button {
			border-color: @input-border-color;
			height: calc(@btn-height-base - 2px);
		}
	}
	&-wrapper-sm &-addon {
		.@{ant-prefix}-btn.@{ant-prefix}-input-search-button {
			height: calc(@btn-height-sm - 2px);
			.@{icon-prefix-cls} {
				vertical-align: middle;
				font-size: @input-icon-size-sm;
			}
		}
	}
	&-wrapper-xs &-addon {
		.@{ant-prefix}-btn.@{ant-prefix}-input-search-button {
			height: calc(@btn-height-xs - 2px);
			padding: 0 8px;

			.@{icon-prefix-cls} {
				vertical-align: middle;
				font-size: @input-icon-size-sm;
			}
		}
	}

	&-wrapper-lg &-addon {
		.@{ant-prefix}-btn.@{ant-prefix}-input-search-button {
			height: calc(@btn-height-lg - 2px);
			.@{icon-prefix-cls} {
				font-size: @input-icon-size-lg;
			}
		}
	}

	.@{inputClass}-affix-wrapper {
		&:not(:first-child) {
			border-top-left-radius: 0;
			border-bottom-left-radius: 0;
		}

		&:not(:last-child) {
			border-top-right-radius: 0;
			border-bottom-right-radius: 0;
			.@{ant-prefix}-input-search & {
				border-top-left-radius: @border-radius-base;
				border-bottom-left-radius: @border-radius-base;
			}
		}
	}

	&&-compact {
		display: block;
		white-space: nowrap;
		.clearfix();

		&-addon,
		&-wrap,
		> .@{inputClass} {
			&:not(:first-child):not(:last-child) {
				border-right-width: @border-width-base;

				&:hover {
					z-index: 1;
				}

				&:focus {
					z-index: 1;
				}
			}
		}

		& > * {
			display: inline-block;
			float: none;
			vertical-align: top; // https://github.com/ant-design/ant-design-pro/issues/139
			border-radius: 0;
		}

		& > .@{inputClass}-affix-wrapper {
			display: inline-flex;
		}

		& > .@{ant-prefix}-picker-range {
			display: inline-flex;
		}

		& > *:not(:last-child) {
			margin-right: -@border-width-base;
			border-right-width: @border-width-base;
		}

		// Undo float for .ant-input-group .ant-input
		.@{inputClass} {
			float: none;
		}

		// reset border for Select, DatePicker, AutoComplete, Cascader, Mention, TimePicker, Input
		& > .@{ant-prefix}-select > .@{ant-prefix}-select-selector,
		& > .@{ant-prefix}-select-auto-complete .@{ant-prefix}-input,
		& > .@{ant-prefix}-cascader-picker .@{ant-prefix}-input,
		& > .@{ant-prefix}-input-group-wrapper .@{ant-prefix}-input {
			border-right-width: @border-width-base;
			border-radius: 0;

			&:hover {
				z-index: 1;
			}

			&:focus {
				z-index: 1;
			}
		}

		& > .@{ant-prefix}-select-focused {
			z-index: 1;
		}

		// update z-index for arrow icon
		& > .@{ant-prefix}-select > .@{ant-prefix}-select-arrow {
			z-index: 1; // https://github.com/ant-design/ant-design/issues/20371
		}

		& > *:first-child,
		& > .@{ant-prefix}-select:first-child > .@{ant-prefix}-select-selector,
		& > .@{ant-prefix}-select-auto-complete:first-child .@{ant-prefix}-input,
		& > .@{ant-prefix}-cascader-picker:first-child .@{ant-prefix}-input {
			border-top-left-radius: @border-radius-base;
			border-bottom-left-radius: @border-radius-base;
		}

		& > *:last-child,
		& > .@{ant-prefix}-select:last-child > .@{ant-prefix}-select-selector,
		& > .@{ant-prefix}-cascader-picker:last-child .@{ant-prefix}-input,
		& > .@{ant-prefix}-cascader-picker-focused:last-child .@{ant-prefix}-input {
			border-right-width: @border-width-base;
			border-top-right-radius: @border-radius-base;
			border-bottom-right-radius: @border-radius-base;
		}

		// https://github.com/ant-design/ant-design/issues/12493
		& > .@{ant-prefix}-select-auto-complete .@{ant-prefix}-input {
			vertical-align: top;
		}

		.@{ant-prefix}-input-group-wrapper + .@{ant-prefix}-input-group-wrapper {
			margin-left: -1px;
			.@{ant-prefix}-input-affix-wrapper {
				border-radius: 0;
			}
		}

		.@{ant-prefix}-input-group-wrapper:not(:last-child) {
			&.@{ant-prefix}-input-search > .@{ant-prefix}-input-group {
				& > .@{ant-prefix}-input-group-addon > .@{ant-prefix}-input-search-button {
					border-radius: 0;
					border: 1px solid transparent;
					border-left: 0px;
				}

				& > .@{ant-prefix}-input {
					border-radius: @border-radius-base 0 0 @border-radius-base;
				}
			}
		}
	}
}
