@use "sass:math";
@import "@wordpress/base-styles/breakpoints";
@import "@automattic/typography/styles/fonts";
@import "@automattic/components/src/styles/mixins";
@import "@automattic/components/src/styles/typography";
@import "calypso/my-sites/stats/components/highlight-cards/variables";

$card-padding: 24px;
$border-radius: 5px; // stylelint-disable-line scales/radii

@keyframes shine {
	to {
		background-position-x: -200%;
	}
}

.post-stats-card {
	border-color: var(--studio-gray-5);
	border-radius: $border-radius;
	display: grid;
	font-family: $font-sf-pro-text;
	font-size: $font-body-small;
	grid-template-columns: minmax(10px, 1.5fr) minmax(0, auto);
	// 26px is the height of the heading, the remaining should be auto.
	grid-template-rows: 26px auto auto;
	grid-template-areas:
		"heading thumbnail"
		"post thumbnail"
		"counts thumbnail";
	margin-bottom: 0;
	max-width: 100%;
	max-height: 255px;
	padding: $card-padding;
	gap: $card-padding;

	// Eliminate the `::after` pseudo-element from frequently accompanied .card
	&.card::after {
		display: none;
	}

	&.is-loading {
		.post-stats-card__heading,
		.post-stats-card__post-info,
		.post-stats-card__upload {
			position: relative;

			&::after {
				content: "";
				position: absolute;
				top: 0;
				left: 0;
				width: 100%;
				height: 100%;
				background: linear-gradient(94deg, #ececec 8%, #f5f5f5 18%, #ececec 33%);
				border-radius: 4px;
				background-size: 200% 100%;
				animation: 1.5s shine linear infinite;
			}
		}
	}
}

.post-stats-card__heading {
	color: var(--studio-gray-100);
	font-family: $font-sf-pro-display;
	font-size: $font-size-header-small;
	font-weight: 500;
	grid-area: heading;
	line-height: 1.3;
}

.post-stats-card__post-info {
	grid-area: post;

	.post-stats-card__post-title {
		@include stats-section-header;
		display: block;
		margin-bottom: 4px;
		// For loading placeholder
		min-height: 80px;
	
		&:visited {
			color: var(--studio-gray-100);
		}
	}
}

.post-stats-card__post-date {
	color: var(--studio-gray-60);
	font-weight: 400;
	line-height: 1.5;
}

.post-stats-card__counts {
	grid-area: counts;
	display: flex;
	align-self: flex-end;
	flex-flow: row;
	flex-wrap: wrap;
	column-gap: 64px;
	row-gap: 24px;
}

.post-stats-card__count {
	.gridicon {
		display: none;
	}
}

.post-stats-card__count-header {
	color: var(--studio-gray-100);
	font-weight: 500;
	line-height: 1.5;
	margin-bottom: 8px;
}

.post-stats-card__count-value {
	@include stats-section-header;
	color: var(--studio-gray-100);
}

.post-stats-card__thumbnail,
.post-stats-card__upload {
	border-radius: 0 $border-radius $border-radius 0;
	grid-area: thumbnail;
	height: calc(100% + #{$card-padding * 2});
	margin: -1 * $card-padding -1 * $card-padding -1 * $card-padding 0;
	max-width: 300px;
	object-fit: cover;
	width: calc(100% + #{$card-padding});
}

.post-stats-card__upload {
	max-width: 500px;
	padding: 0 8px;
	display: flex;
	align-items: center;
	justify-content: center;
	background-color: var(--studio-gray-0);
	border-left: 1px solid var(--studio-gray-5);
	box-sizing: border-box;
}

.post-stats-card__upload-btn {
	color: var(--studio-gray-100);
	font-family: $font-sf-pro-display;
	font-size: $font-body-small;
	font-weight: 500;
	line-height: 20px;
	letter-spacing: 0.32px;
	border: 1px solid var(--studio-gray-5);
	border-radius: 4px;
	box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

@media (max-width: $break-large) {
	.post-stats-card__upload {
		display: none;
	}
}

@media (max-width: $custom-mobile-breakpoint) {
	.post-stats-card {
		border-bottom: 1px solid var(--color-border-subtle);
		border-radius: 0;
		border-top: 1px solid var(--color-border-subtle);
		box-shadow: none;
		gap: math.div($card-padding, 2) 0;
		grid-template-areas:
			"heading heading"
			"post thumbnail"
			"counts counts";
		max-height: initial;
		padding: $card-padding 0;
	}
	.post-stats-card__thumbnail {
		height: 84px;
		margin: 0;
		width: 84px;
		max-width: initial;
		border-radius: $border-radius;
	}
}

@media (max-width: $break-wpcom-smallest) {
	.post-stats-card {
		grid-template-areas:
			"heading"
			"thumbnail"
			"post "
			"counts";

		border-bottom: 0;
	}

	.post-stats-card__thumbnail {
		height: 100%;
		width: 100%;
	}

	.post-stats-card__counts {
		display: block;
	}
	.post-stats-card__count {
		display: flex;
		flex-flow: row;
		justify-content: space-between;
		align-items: center;
		border-bottom: 1px solid var(--color-neutral-5);
		height: 60px;

		.gridicon {
			display: block;
		}
	}

	.post-stats-card__count-header {
		font-size: $font-body-small;
		font-weight: 400;
		line-height: 20px;
		margin: 0 auto 0 8px;
	}

	.post-stats-card__count-value {
		font-family: inherit;
		font-size: $font-body-small;
		font-weight: 500;
		line-height: 30px;
	}
}
