//------------------------------------------------------------------------------------------------
// CHECKBOX
//------------------------------------------------------------------------------------------------

/*
Common tick elements. Can be either a radio or checkbox element,
depending on business context.
*/

// COMPONENT COLOURS
//------------------------------------------------------------------------------------------------

/*
Easily assign colours to the button component without having to
find/replace variables.
*/

$component-checkbox-color: 'very-light' !default;
$component-checkbox-accent-color: 'primary' !default;


// BLOCK & ELEMENTS
//------------------------------------------------------------------------------------------------

.c-checkbox {
	display: flex;
	background-color: color($component-checkbox-color);
	border: rem(1px) solid color('light');
	font-weight: bold;
	padding: 0 rem(10px);
	align-items: center;
	cursor: pointer;
	position: relative;
	transition: box-shadow $global-transition-duration, background-color $global-transition-duration, border-color $global-transition-duration, color $global-transition-duration;
	border-radius: $global-border-radius;
	height: rem(35px);
	input {
		position: absolute;
		opacity: 0;
		width: 100%;
		height: 100%;
	}
	user-select: none;
	&:focus {
		outline: none;
		box-shadow: 0 rem(1px) rem(3px) rgba(0,0,0, 0.25), 0 0 rem(15px) rem(3px) rgba(color($component-checkbox-accent-color), 0.5);
	}
}

.c-checkbox__box {
	display: inline-block;
	width: rem(18px);
	height: rem(18px);
	background-color: color('white');
	border: rem(2px) solid color($component-checkbox-accent-color);
	border-radius: rem(5px);
	margin-right: rem(7px);
	flex-shrink: 0;
	position: relative;
	transition: border-color 0.5s;
}

.c-checkbox__label {
	position: relative;
}

.c-checkbox__box-icon {
	display: none;
	width: rem(12px);
	height: rem(10px);
	fill: color('black');
	position: relative;
	top: rem(2px);
	left: rem(1px);
}

.c-checkbox__cover {
	opacity: 0;
	position: absolute;
	width: calc(100% + 2px);
	height: calc(100% + 2px);
	top: rem(-1px);
	left: rem(-1px);
	overflow: hidden;
	transition: opacity 0.1s;
	background-color: color('white');
	border-radius: rem($global-border-radius);
	border: rem(1px) solid color($component-checkbox-accent-color);
	&:before {
		content: '';
		display: block;
		width: rem(5px);
		height: 100%;
		position: relative;
		top: 0;
		left: rem(-5px);
		transition: left 0.1s;
		background-color: color($component-checkbox-accent-color);
	}
}

@keyframes scale {
	from {
		transform: scale(1.5);
		opacity: 0;
	}
	to {
		transform: scale(1);
		opacity: 1;
	}
}

.c-checkbox input:checked {
	& ~ .c-checkbox__box {
		animation: scale 0.25s;
	}
	& ~ .c-checkbox__box .c-checkbox__box-icon {
		display: block;
	}
	& ~ .c-checkbox__cover {
		opacity: 1;
		&:before {
			left: 0;
		}
	}
}

.c-checkbox input[type='radio'] ~ .c-checkbox__box {
	border-radius: 50%;
}

.c-checkbox input[type='radio']:checked {
	& ~ .c-checkbox__box:before {
		content: '';
		display: block;
		background-color: color('black');
		width: rem(10px);
		height: rem(10px);
		border-radius: 50%;
		position: relative;
		left: rem(2px);
		top: rem(2px);
	}
	& ~ .c-checkbox__box .c-checkbox__box-icon {
		display: none;
	}	
}


// SIZE MODIFIERS
//------------------------------------------------------------------------------------------------

.c-checkbox--large {
	padding: rem(11px) rem(20px) rem(12px) rem(20px);
	height: rem(50px);
	.c-checkbox__box {
		margin-right: rem(15px);
		width: rem(22px);
		height: rem(22px);
	}

	& input[type='radio']:checked {
		& ~ .c-checkbox__box:before {
			width: rem(12px);
			height: rem(12px);
			left: rem(3px);
			top: rem(3px);
		}
	}

	.c-checkbox__box-icon {
		width: rem(15px);
		height: rem(12px);
		top: rem(3px);
		left: rem(2px);
	}
}

.c-checkbox--small {
	padding: 0 rem(9px);
	height: rem(28px);
	.c-checkbox__box {
		margin-right: rem(5px);
		width: rem(15px);
		height: rem(15px);
	}

	& input[type='radio']:checked {
		& ~ .c-checkbox__box:before {
			width: rem(12px);
			height: rem(12px);
			left: rem(3px);
			top: rem(3px);
		}
	}

	.c-checkbox__box-icon {
		width: rem(9px);
		height: rem(11px);
		top: 0;
		left: rem(1px);
	}
}


// INLINE MODIFIER
//------------------------------------------------------------------------------------------------

.c-checkbox--inline {
	display: inline-flex;
}


// BARE MODIFIER
//------------------------------------------------------------------------------------------------

.c-checkbox--bare {
	padding: 0;
	background-color: transparent;
	border-width: 0;
	font-weight: normal;
	&:focus {
		box-shadow: none;
		& .c-checkbox__box {
			box-shadow: 0 rem(1px) rem(3px) rgba(0,0,0, 0.25), 0 0 rem(15px) rem(3px) rgba(color($component-checkbox-accent-color), 0.5);
		}
	}
	& input:checked ~ .c-checkbox__cover {
		opacity: 0;
	}
}


// STATE MODIFIERS
//------------------------------------------------------------------------------------------------

.c-checkbox.is-disabled,
*[disabled] .c-checkbox:not(.c-checkbox--disable-state-inheritance),
.is-disabled .c-checkbox:not(.c-checkbox--disable-state-inheritance) {
	pointer-events: none;
	background-color: color($component-checkbox-color);
	color: rgba(#000000, 0.5);
	cursor: not-allowed;
	.c-checkbox__box {
		border-color: rgba(#000000, 0.5);
	}
	.c-checkbox__cover {
		border-color: rgba(#000000, 0.5);
		&:before {
			background-color: rgba(#000000, 0.5);
		}
	}
}


// CHECKBOX GROUP
//------------------------------------------------------------------------------------------------

/*
Wrapper for a group of checkbox elements. Allows for things like validation
error messages.
*/


// BLOCK & ELEMENTS
//------------------------------------------------------------------------------------------------

.c-checkbox-group__text {
	flex-basis: 100%;
}

.c-checkbox-group__text--error {
	color: color('negative');
	display: none;
}

.c-checkbox-group.is-negative {
	.c-checkbox-group__text--error {
		display: block;
	}
}