@import "../common/mixin.scss";
@import "../common/utils.scss";

@mixin sizeMixin(
	$switch-width,
	$switch-height,
	$switch-button-padding,
	$switch-button-size,
	$switch-font-size,
	$switch-label-padding
) {
	@include e(input) {
		@include e(core) {
			width: $switch-width;
			height: $switch-height;

			&::after {
				top: $switch-button-padding;
				left: $switch-button-padding;
				width: $switch-button-size;
				height: $switch-button-size;
			}
		}

		@include e(label) {
			font-size: $switch-font-size;

			@include m(active) {
				left: $switch-label-padding;
			}

			@include m(inactive) {
				right: $switch-label-padding;
			}
		}
	}

	@include when(checked) {
		@include e(core) {
			&::after {
				left: 100%;
				margin-left: -$switch-button-size - $switch-button-padding;
			}
		}
	}
}

@include b(switch) {
	display: inline-flex;
	align-items: center;
	position: relative;
	font-size: $--switch-font-size;
	line-height: $--switch-height;
	vertical-align: middle;

	@include when(disabled) {
		@include e(core) {
			cursor: not-allowed;

			&::before {
				background: $--color-primary-light;
				box-shadow: inset 2px 2px 4px $--color-primary, inset -2px -2px 4px $--color-primary-light;
			}

			&::after {
				background-color: $--color-text-disabled;
			}
		}

		&.is-checked {
			.tu-switch-core::after {
				box-shadow: 1px 1px 3px $--color-primary, -2px -2px 4px $--color-primary-light;
			}
		}
	}

	@include e(input) {
		display: inline-flex;
		align-items: center;

		@include e(core) {
			display: inline-flex;
			align-items: center;
			width: $--switch-width;
			height: $--switch-height;
			border-radius: 40px;
			position: relative;
			cursor: pointer;
			box-shadow: $--box-shadow-border;

			&::before {
				content: "";
				position: absolute;
				width: 100%;
				height: 100%;
				top: 0;
				left: 0;
				border-radius: 20px;
				background: $--color-primary;
				box-shadow: inset 2px 2px 4px $--color-primary-dark,
					inset -2px -2px 4px $--color-primary-light;

				transition: all 0.4s ease;
				opacity: 0;
			}

			&::after {
				content: "";
				position: absolute;
				top: $--switch-button-padding;
				left: $--switch-button-padding;
				border-radius: 50%;
				transition: all 0.4s ease;
				width: $--switch-button-size;
				height: $--switch-button-size;
				background-color: $--color-text-primary;
			}
		}

		@include e(label) {
			position: absolute;
			font-size: $--switch-font-size;
			cursor: pointer;
			background: transparent;
			width: 20px;
			text-align: center;
			transition: all 0.4s;

			@include m(active) {
				left: $--switch-label-padding;
				color: $--switch-on-font-color;
			}

			@include m(inactive) {
				right: $--switch-label-padding;
				color: $--switch-off-font-color;
			}
		}

		@include e(original) {
			position: absolute;
			width: 0;
			height: 0;
			opacity: 0;
			margin: 0;
		}
	}

	@include when(checked) {
		@include e(core) {
			&::before {
				opacity: 1;
			}

			&::after {
				left: 100%;
				margin-left: -$--switch-button-size - $--switch-button-padding;
				background: $--color-white;
				box-shadow: 1px 1px 3px $--color-primary-dark, -2px -2px 4px $--color-primary;
			}
		}
	}

	@include m(small) {
		@include sizeMixin(
			$--switch-small-width,
			$--switch-small-height,
			$--switch-small-button-padding,
			$--switch-small-button-size,
			$--switch-small-font-size,
			$--switch-small-label-padding
		);
	}

	@include m(large) {
		@include sizeMixin(
			$--switch-large-width,
			$--switch-large-height,
			$--switch-large-button-padding,
			$--switch-large-button-size,
			$--switch-large-font-size,
			$--switch-large-label-padding
		);
	}
}
