@import '../../assets/stylesheets/shared/mixins/breakpoints';
@import '@automattic/typography/styles/variables';

@keyframes notice-loading-pulse {
	0%,
	100% {
		opacity: 0.75;
	}
	50% {
		opacity: 1;
	}
}

.calypso-notice {
	display: flex;
	position: relative;
	width: 100%;
	margin-bottom: 12px;
	box-sizing: border-box;
	animation: appear 0.3s ease-in-out;
	background: var( --color-neutral-80 );
	color: var( --color-text-inverted );
	line-height: 1.5;
	align-items: center;

	@include breakpoint-deprecated( '>660px' ) {
		margin-bottom: 24px;
	}

	// Success!
	&.is-success {
		.calypso-notice__icon-wrapper {
			background: var( --color-success-40 );
		}

		.calypso-notice__icon-wrapper-drop {
			background: var( --color-success );
		}
	}

	// Warning
	&.is-warning {
		.calypso-notice__icon-wrapper {
			background: var( --color-warning-30 );
		}

		.calypso-notice__icon-wrapper-drop {
			background: var( --color-warning );
		}
	}

	// Error! OHNO!
	&.is-error {
		.calypso-notice__icon-wrapper {
			background: var( --color-error-40 );
		}

		.calypso-notice__icon-wrapper-drop {
			background: var( --color-error );
		}
	}

	// General notice
	&.is-info {
		.calypso-notice__icon-wrapper {
			background: var( --color-accent-40 );
		}

		.calypso-notice__icon-wrapper-drop {
			background: var( --color-accent );
		}
	}

	// General notice, but without background
	&.is-transparent-info {
		background: unset;
		color: var( --color-error-40 );
		margin-bottom: 0;

		&.is-compact {
			.calypso-notice__icon-wrapper-drop {
				width: 18px;
				height: 18px;
				top: unset;
				left: unset;
			}

			.calypso-notice__icon-wrapper {
				align-items: center;
				padding-top: 0;
			}
		}

		.calypso-notice__text a {
			color: var( --color-link );
		}

		.calypso-notice__icon-wrapper {
			background: transparent;
			align-items: center;
			padding: 0;
		}
		.calypso-notice__icon-wrapper-drop {
			background: var( --color-error );
			border-radius: 50%;
			width: 24px;
			height: 24px;
			top: unset;
			left: unset;
		}
	}

	&.is-loading {
		.calypso-notice__icon-wrapper {
			animation: notice-loading-pulse 0.8s ease-in-out infinite;
		}
	}

	.calypso-notice__dismiss,
	.calypso-notice__link {
		overflow: hidden;
		color: var( --color-neutral-20 );

		&:hover,
		&:focus {
			color: var( --color-text-inverted );
		}
	}

	.calypso-notice__link {
		// This matches the gridicon size, since we will not be using it with links
		margin-right: 18px;
	}

	&.is-success,
	&.is-error,
	&.is-warning,
	&.is-info {
		.calypso-notice__dismiss,
		.calypso-notice__link {
			overflow: hidden;
		}
	}
}

.calypso-notice__icon-wrapper {
	position: relative;
	background: var( --color-neutral-40 );
	color: var( --color-text-inverted );
	display: flex;
	align-items: center;
	width: 47px;
	justify-content: center;
	flex-shrink: 0;
	align-self: stretch;
}

// Accessible background drop for icons enclosed in a circle
// to emphasize the glyph inside
.calypso-notice__icon-wrapper-drop {
	position: absolute;
	top: calc( 50% - 8px );
	left: calc( 50% - 8px );
	width: 16px;
	height: 16px;
	border-radius: 8px;
	background: var( --color-neutral );

	& + .calypso-notice__icon {
		position: relative;
	}
}

.calypso-notice__content {
	padding: 13px;
	font-size: $font-body-extra-small;
	flex-grow: 1;
	text-wrap: pretty;

	.calypso-notice__text {
		a,
		a:visited,
		button.is-link {
			color: var( --color-text-inverted );
			line-height: inherit;

			&:hover {
				color: var( --color-text-inverted );
			}

			.is-transparent-info & {
				color: var( --color-link );

				&:hover {
					color: var( --color-link-dark );
				}
			}
		}

		ul {
			margin-bottom: 0;
			margin-left: 0;
		}

		li {
			margin-left: 2em;
			margin-top: 0.5em;
		}

		p {
			margin-bottom: 0;
			margin-top: 0.5em;

			&:first-child {
				margin-top: 0;
			}
		}
	}

	@include breakpoint-deprecated( '>480px' ) {
		font-size: $font-body-small;
	}
}

.calypso-notice__button {
	cursor: pointer;
	margin-left: 0.428em;
}

// "X" for dismissing a notice
.calypso-notice__dismiss,
.calypso-notice__link {
	display: flex;
	flex-shrink: 0;
	padding: 12px;
	cursor: pointer;

	.gridicon {
		width: 18px;
		height: 18px;
	}

	@include breakpoint-deprecated( '>480px' ) {
		padding: 11px;

		.gridicon {
			width: 24px;
			height: 24px;
		}
	}
}

// specificity for general `a` elements within notice is too great
a.calypso-notice__action {
	cursor: pointer;
	font-size: $font-body-extra-small;
	font-weight: 400;
	text-decoration: none;
	white-space: nowrap;
	color: var( --color-neutral-20 );
	padding: 13px;
	display: flex;
	align-items: center;

	@include breakpoint-deprecated( '>480px' ) {
		flex-shrink: 1;
		flex-grow: 0;
		align-items: center;
		font-size: $font-body-small;
		margin: 0 0 0 auto; // forces the element to the right;
		padding: 13px 16px;

		.gridicon {
			width: 24px;
			height: 24px;
		}
	}

	&:visited {
		color: var( --color-neutral-20 );
	}

	&:hover {
		color: var( --color-text-inverted );
	}

	.gridicon {
		margin-left: 8px;
		opacity: 0.7;
		width: 18px;
		height: 18px;
	}
}

// Compact notices
.calypso-notice.is-compact {
	display: inline-flex;
	flex-wrap: nowrap;
	flex-direction: row;
	width: auto;
	min-height: 20px;
	margin: 0;
	padding: 0;
	text-decoration: none;
	text-transform: none;
	vertical-align: middle;
	line-height: 1.5;

	&.is-full-width {
		width: 100%;
	}

	.calypso-notice__content {
		font-size: $font-body-extra-small;
		padding: 6px 10px;
	}

	.calypso-notice__icon-wrapper {
		width: 28px;

		.calypso-notice__icon {
			width: 18px;
			height: 18px;
			margin: 0;
		}
	}

	.calypso-notice__icon-wrapper-drop {
		top: calc( 50% - 6px );
		left: calc( 50% - 6px );
		width: 12px;
		height: 12px;
	}

	.calypso-notice__dismiss,
	.calypso-notice__link {
		position: relative;
		align-self: center;
		flex: none;
		margin: 0 8px 0 0;
		padding: 0;

		.gridicon {
			width: 18px;
			height: 18px;
		}
	}

	a.calypso-notice__action {
		background: transparent;
		display: inline-block;
		margin: 0;
		font-size: $font-body-extra-small;
		align-self: center;
		margin-left: 16px;
		padding: 0 10px;

		&:hover,
		&:active,
		&:focus {
			background: transparent;
		}

		.gridicon {
			margin-left: 8px;
			width: 14px;
			height: 14px;
			vertical-align: sub;
			opacity: 1;
		}
	}
}

.calypso-notice.is-light {
	background: var( --studio-gray-0 );
	color: inherit;
	border-radius: 4px;

	.calypso-notice__content {
		padding: 13px 0;
		.calypso-notice__text {
			a,
			a:visited,
			button.is-link {
				color: var( --color-link-dark );

				&:hover {
					color: var( --color-link-dark );
				}
			}
		}
	}

	.calypso-notice__icon-wrapper {
		border-top-left-radius: 4px;
		border-bottom-left-radius: 4px;
		background: var( --studio-gray-0 );
		padding: 16px;
		align-items: flex-start;
		width: unset;
	}

	&.is-info,
	&.is-success {
		.calypso-notice__icon-wrapper {
			color: var( --studio-green-40 );
			background: var( --studio-gray-0 );
			.calypso-notice__icon-wrapper-drop {
				background: var( --color-text-inverted );
			}
		}
	}
	&.is-warning {
		.calypso-notice__icon-wrapper {
			color: var( --studio-orange-40 );
			background: var( --studio-gray-0 );
			.calypso-notice__icon-wrapper-drop {
				background: var( --color-text-inverted );
			}
		}
	}
	&.is-error {
		.calypso-notice__icon-wrapper {
			color: var( --studio-red-40 );
			background: var( --studio-gray-0 );
			.calypso-notice__icon-wrapper-drop {
				background: var( --color-text-inverted );
			}
		}
	}
	&.is-plain {
		.calypso-notice__icon-wrapper {
			color: inherit;
			background: var( --studio-gray-0 );
			.calypso-notice__icon-wrapper-drop {
				background: var( --color-text-inverted );
			}
		}
	}

	// "X" for dismissing a notice
	.calypso-notice__dismiss,
	.calypso-notice__link {
		display: flex;
		flex-shrink: 0;
		padding: 16px;
		cursor: pointer;
		&:hover,
		&:focus {
			color: var( --color-text );
		}
		.gridicon {
			width: 18px;
			height: 18px;
		}
	}
}
