@import "@wordpress/base-styles/breakpoints";
@import "@wordpress/base-styles/mixins";
@import "../../style";

$post-item-background-color: var(--color-surface);
body.is-section-promote-post-i2 {
	background-color: $post-item-background-color;
}

.promote-post-i2 {
	@include promote-post-i2-font;

	.posts-list__header-column {
		font-weight: normal;
		padding-bottom: 8px;
	}

	.post-item__row {
		width: 100%;
	}

	.post-item__post {
		&-data,
		&-type,
		&-publish-date,
		&-views,
		&-likes,
		&-comments,
		&-view,
		&-promote,
		&-sku,
		&-price {
			vertical-align: middle;
		}

		&-views,
		&-likes,
		&-comments {
			text-align: center;
		}

		&-data {
			flex-direction: column;

			.post-item__post {
				&- {
					@include blazepress-data-row;
				}

				&-data-row {
					.post-item__post-title {
						display: flex;
						justify-content: flex-start;
						.post-item__post-subheading-mobile,
						.post-item__post-subtitle-mobile {
							display: none;
						}
					}
				}
			}
		}

		&-type {
			font-size: 0.875rem;
			width: 11%;
		}

		&-publish-date {
			width: 12.8%;
		}

		&-visitors {
			width: 10%;
		}

		&-likes {
			width: 10%;
		}

		&-comments {
			width: 10%;
		}

		&-view {
			width: 7%;
		}

		&-promote {
			color: $studio-simplenote-blue-50;
			text-decoration-line: underline;
			width: 5.4%;
		}

		&-price {
			font-size: 0.875rem;
			width: 10%;
		}

		&-sku {
			font-size: 0.875rem;
			width: 10%;
		}
	}

	// View link
	.post-item__post-view a.post-item__view-link,
	.post-item__post-view a.post-item__view-link:visited,
	.post-item__post-data .post-item__post-data-row-mobile .post-item__actions-mobile a.post-item__view-link,
	.post-item__post-data .post-item__post-data-row-mobile .post-item__actions-mobile a.post-item__view-link:visited {
		color: var(--studio-gray-60);
		text-decoration-line: underline;

		&:hover {
			color: var(--studio-gray-60);
			text-decoration-line: none;
		}
	}

	.post-item {
		&__row .post-item__post-data {
			align-items: center;
			display: flex;
			font-weight: 500;
		}

		&__post-promote-button {
			border-radius: 4px;
			border: 1.5px solid var(--color-accent);
			color: var(--color-accent);
			background-color: var(--color-surface);
			box-shadow: none;

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

		&__post-promote-button:hover {
			text-decoration: underline;
			color: var(--color-accent) !important;
		}

		&__view-button {
			@include blazepress-data-row-font-buttons-mobile;
			background-color: #f6f7f7;
			border-radius: 4px;
			border: none;
			flex-grow: 1;
			height: 28px;
			width: 53px;
			max-width: 53px;
			line-height: 30px;
			margin-right: 12px;
			text-decoration: none;
			text-align: center;
			align-items: center;
		}

		&__view-button:hover {
			text-decoration: underline;
		}

		&__post-promote-button-mobile {
			border-radius: 4px;
			border: 1.5px solid var(--color-accent);
			color: var(--color-accent);
			background-color: var(--color-surface);
			box-shadow: none;
			height: 28px;
		}

		&__post-promote-button-mobile:hover {
			text-decoration: underline;
			color: var(--color-accent);
			background-color: var(--color-surface);
		}
	}

	.post-item__post-title {
		color: $studio-gray-100;
		margin-left: 16px;
		max-width: 180px;

		&-content {
			display: flex;
			align-items: center;

			.info-popover {
				height: 18px
			}
		}
	}

	.post-item__post-thumbnail-wrapper {
		align-self: stretch;
		background-position: 50% 50%;
		background-repeat: no-repeat;
		background-size: cover;
		border: 1px solid #eee;
		border-radius: 4px;
		display: block;
		height: 78px;
		min-width: 108px;
		overflow: hidden;
		position: relative;
		width: 108px;

		&_no-image {
			align-items: center;
			background: $studio-gray-0;
			border-radius: 4px;
			display: flex;
			justify-content: center;
		}

		img {
			height: 100%;
			width: 100%;
			object-fit: cover;
			display: block;
		}
	}
}

.popover-title {
	color: $studio-gray-100;
}

.blazepress-mobile-stats-mid-dot {
	padding: 0 6px;
}

@mixin blazepress-post-item-mobile {
	.promote-post-i2 {
		.posts-list__table {
			width: calc(100% - 32px);
		}

		th.posts-list__header-column {
			display: none;
		}

		.post-item__post {
			// Do not show the rest of columns on mobiles
			&-type,
			&-publish-date,
			&-views,
			&-likes,
			&-comments,
			&-view,
			&-sku,
			&-price,
			&-visitors,
			&-promote {
				display: none;
			}

			&-data {
				.post-item__post {
					&-data-row {
						&-mobile {
							display: flex;
							justify-content: space-between;
							flex-direction: column;
						}

						.post-item__post-title {
							flex-direction: column;
							max-width: unset;

							.post-item__post-subheading-mobile {
								@include blazepress-data-row-font-mobile;
								display: block;
								margin-bottom: 4px;
							}

							.post-item__post-subtitle-mobile {
								@include blazepress-data-row-font-mobile;
								display: block;
								margin-top: 4px;
							}

							.post-item__post-title-content {
								font-size: 0.875rem;
								font-weight: 600;
								line-height: 1.4285;
							}
						}
					}
				}
			}
		}

		// View link
		.post-item__post-view a.post-item__view-link,
		.post-item__post-view a.post-item__view-link:visited,
		.post-item__post-data .post-item__post-data-row-mobile .post-item__actions-mobile a.post-item__view-link,
		.post-item__post-data .post-item__post-data-row-mobile .post-item__actions-mobile a.post-item__view-link:visited {
			@include blazepress-data-row-font-mobile;
			border-radius: 4px;
			display: inline-block;
			flex-grow: 1;
			height: 40px;
			line-height: 22px;
			margin-right: 8px;
			text-decoration: none;
		}

		// Promote link
		.post-item__post-data .post-item__post-data-row-mobile .post-item__actions-mobile button.post-item__post-promote-button {
			display: inline-block;
			flex-grow: 1;
			height: 40px;
			margin-left: 8px;
		}

		.post-item__post-thumbnail-wrapper {
			align-self: stretch;
			background-position: 50% 50%;
			background-repeat: no-repeat;
			background-size: cover;
			border: 1px solid #eee;
			border-radius: 4px;
			display: block;
			height: 76px;
			min-width: 76px;
			overflow: hidden;
			position: relative;
			width: 76px;
			&_no-image {
				align-items: center;
				background: $studio-gray-0;
				border-radius: 4px;
				display: flex;
				justify-content: center;
			}

			img {
				height: 100%;
				width: 100%;
				object-fit: cover;
				display: block;
			}
		}
	}
}

.accessible-focus .promote-post-i2 .post-item {
	&__post-promote-button:focus {
		color: var(--color-surface) !important; // for jetpack that has important color values
		background-color:var(--color-accent)
	}
	&__view-link:focus {
		box-shadow: 0 0 0 2px var(--color-primary-light);
		color: var(--color-primary);
	}
	&__post-title-content .info-popover:focus{
		position: relative;

		&::before {
			display: block;
			position: absolute;
			border: 2px solid var(--color-primary);
			border-radius: 50%;
			top: calc(50% - 12.5px);
			left: calc(50% - 12.5px);
			content: "";
			width: 22px;
			height: 22px;
		}

		.gridicon {
			color: var(--color-primary);
		}

	}
}

// Show Mobile view for screens if window width <= 782px
@media screen and (max-width: $break-medium) {
	@include blazepress-post-item-mobile;
}

// Show Mobile view if sidebar is collapsed and main content width <= 782px
$break-medium-collapsed-menu: $break-medium + 36px;
@media screen and (max-width: $break-medium-collapsed-menu) {
	body.is-section-promote-post-i2.is-sidebar-collapsed {
		@include blazepress-post-item-mobile;
	}
}

// Show Mobile view if sidebar is expanded and main content width <= 782px
$break-medium-expanded-menu: $break-medium + 272px;
@media screen and (max-width: $break-medium-expanded-menu) {
	body.is-section-promote-post-i2:not(.is-sidebar-collapsed) {
		@include blazepress-post-item-mobile;
	}
}
