@use "../../shared/styles/jetpack-variables";
@use "variables";
@use "css-gram";

$tiled-gallery-max-column-count: 20;
$tiled-gallery-max-rounded-corners: 20; // See constants.js for JS counterpart

.wp-block-jetpack-tiled-gallery {

	&.is-style-circle,
	.is-style-circle {

		.tiled-gallery__item img {
			border-radius: 50%;
		}
	}

	&.is-style-square,
	&.is-style-circle,
	.is-style-square,
	.is-style-circle {

		.tiled-gallery__row {
			flex-grow: 1;
			width: 100%;

			@for $cols from 1 through $tiled-gallery-max-column-count {
				&.columns-#{$cols} {

					.tiled-gallery__col {
						width: calc(( 100% - #{ variables.$tiled-gallery-gutter * ( $cols - 1 ) } ) / #{$cols});
					}
				}
			}
		}

		.tiled-gallery__item img {
			aspect-ratio: 1;
		}
	}

	&.is-style-columns,
	&.is-style-rectangular,
	.is-style-columns,
	.is-style-rectangular {

		.tiled-gallery__item {
			display: flex;
		}
	}

	@for $i from 1 through $tiled-gallery-max-rounded-corners {
		.has-rounded-corners-#{$i} .tiled-gallery__item img {
			border-radius: #{$i}px;
		}
	}
}

.tiled-gallery__gallery {
	width: 100%;
	display: flex;
	padding: 0;
	flex-wrap: wrap;
}

.tiled-gallery__row {
	width: 100%;
	display: flex;
	flex-direction: row;
	justify-content: center;
	margin: 0;

	& + & {
		margin-top: variables.$tiled-gallery-gutter;
	}
}

.tiled-gallery__col {
	display: flex;
	flex-direction: column;
	justify-content: center;
	margin: 0;

	& + & {
		margin-inline-start: variables.$tiled-gallery-gutter;
	}
}

.tiled-gallery__item {
	justify-content: center;
	margin: 0;
	overflow: hidden;
	padding: 0;
	position: relative;
	flex-grow: 1;

	&.filter__black-and-white {
		filter: grayscale(100%);
	}

	&.filter__sepia {
		filter: sepia(100%);
	}

	&.filter__1977 {

		@include css-gram.gram1977;
	}

	&.filter__clarendon {

		@include css-gram.clarendon;
	}

	&.filter__gingham {

		@include css-gram.gingham;
	}

	& + & {
		margin-top: variables.$tiled-gallery-gutter;
	}

	&:focus-within {
		overflow: visible;
		box-shadow: 0 0 0 2px  var(--wp-admin-theme-color);
	}

	> img {
		background-color: rgba(0, 0, 0, 0.1);
	}

	> a,
	> a > img,
	> img {
		display: block;
		height: auto;
		margin: 0;
		max-width: 100%;
		object-fit: cover;
		object-position: center;
		padding: 0;
		width: 100%;
	}
}

.is-email {

	.tiled-gallery__gallery {
		display: block;
	}
}
