/**
 * Gallery print
 * @define gallery
*/

@use 'sass:map';

// Exposed variables
$theme: null !default;
$gallery: null !default;

.ecl-gallery {
  margin: 0;
}

.ecl-gallery__list {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  list-style: none;
  margin-bottom: 0;
  margin-top: -#{map.get($theme, 'spacing-print', 'xs')};
  padding-inline-start: 0;
}

.ecl-gallery__item {
  display: block;
  flex-grow: 1;
  height: 5cm;
  margin-bottom: 0;
  margin-inline-start: map.get($theme, 'spacing-print', 'xs');
  margin-top: map.get($theme, 'spacing-print', 'xs');
  min-width: 7cm;
  position: relative;
}

.ecl-gallery__item-icon {
  display: none;
}

.ecl-gallery__image-container {
  display: flex;
  height: 5cm;
  position: relative;
  flex-grow: 1;
  margin: 0;
}

.ecl-gallery__thumbnail {
  display: none;
  height: 100%;

  &:not(.ecl-gallery__slider-image) {
    display: flex;
    flex-grow: 1;
  }
}

.ecl-gallery__picture {
  display: flex;
  height: 100%;

  &:not(.ecl-gallery__slider-image) {
    display: none;
    flex-grow: 1;
  }
}

@supports (object-fit: cover) {
  .ecl-gallery__image {
    display: block;
    min-width: 5cm;
    flex-grow: 1;
    object-fit: cover;
  }
}

.ecl-gallery__description {
  align-items: center;
  background-color: rgba(0, 0, 0, 0.7);
  color: map.get($theme, 'color', 'white');
  font: map.get($theme, 'font-print', 's');
  padding: map.get($theme, 'spacing-print', '2xs')
    map.get($theme, 'spacing-print', 'xs');
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: text-bottom;
  width: calc(100% - (#{map.get($theme, 'spacing-print', 'xs')} * 2));
  bottom: 0;
  left: 0;
  position: absolute;
}

.ecl-gallery--no-hover .ecl-gallery__description {
  display: none;
}

.ecl-gallery__description-icon {
  display: none;
}

.ecl-gallery__list .ecl-gallery__caption,
.ecl-gallery__list .ecl-gallery__meta,
.ecl-gallery__video-title {
  display: none;
}

.ecl-gallery__footer {
  display: none;
}

// Overlay

.ecl-gallery__overlay {
  background-color: map.get($gallery, 'overlay-background');
  backdrop-filter: blur(25px);
  border-width: 0;
  display: none;
  flex-direction: column;
  height: 100%;
  left: 0;
  margin: 0;
  max-height: 100vh;
  max-width: 100%;
  padding: 0;
  position: fixed;
  top: 0;
  width: 100%;
  z-index: map.get($theme, 'z-index', 'overlay');

  .ecl-gallery__close,
  .ecl-gallery__slider-previous,
  .ecl-gallery__slider-next,
  .ecl-gallery__detail-actions {
    display: none;
  }

  .ecl-gallery__slider {
    align-items: center;
    display: flex;
    flex-direction: row;
    flex-grow: 1;
    justify-content: center;
    overflow: hidden;
    position: relative;
  }

  .ecl-gallery__slider-image *,
  .ecl-gallery__slider-video {
    display: flex;
    flex-basis: auto;
    flex-grow: 0;
    flex-shrink: 0;
    height: 100%;
    margin: 0;
    object-fit: contain;
    width: 100%;
  }

  .ecl-gallery__detail {
    padding: map.get($theme, 'spacing-print', 'm');

    * {
      color: map.get($theme, 'color', 'white');
    }
  }

  .ecl-gallery__detail-counter {
    display: none;
  }

  .ecl-gallery__meta,
  .ecl-gallery__title {
    height: 1px;
    left: -10000px;
    overflow: hidden;
    position: absolute;
    top: auto;
    width: 1px;
  }

  .ecl-gallery__detail-meta {
    margin-top: map.get($theme, 'spacing-print', 'xs');
  }

  .ecl-gallery__slider-embed-audio {
    display: none;
  }

  .ecl-gallery__pager {
    display: flex;
    flex-direction: row-reverse;
    margin-top: map.get($theme, 'spacing-print', 'xs');

    * {
      align-self: flex-end;
      font: map.get($theme, 'font-print', 's');
    }
  }
}

.ecl-gallery__overlay[open] {
  display: flex;
  overflow: auto;
}

.ecl-gallery--ratio-3-1 {
  .ecl-gallery__item,
  .ecl-gallery__image {
    aspect-ratio: 3/1;
  }
}

// Variant: grid
.ecl-gallery--grid {
  .ecl-gallery__item {
    aspect-ratio: 3/2;
    flex-grow: 0;
    height: auto;
    margin-inline-start: 0;
    margin-top: 0;
    min-width: auto;
  }

  .ecl-gallery__image {
    aspect-ratio: 3/2;
    height: auto;
    min-width: auto;
    width: 100%;
  }

  .ecl-gallery__list {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    row-gap: 1rem;
    column-gap: 1rem;
    margin-inline-start: 0;
  }

  .ecl-gallery__image-container {
    height: auto;
  }

  &.ecl-gallery--template-1 {
    .ecl-gallery__list {
      grid-template-columns: repeat(12, 1fr);

      .ecl-gallery__item:nth-child(9n + 1),
      .ecl-gallery__item:nth-child(9n + 2) {
        grid-area: span 6 / span 6;
      }

      .ecl-gallery__item:nth-child(9n + 3),
      .ecl-gallery__item:nth-child(9n + 4),
      .ecl-gallery__item:nth-child(9n + 5) {
        grid-area: span 4 / span 4;
      }

      .ecl-gallery__item:nth-child(9n + 6),
      .ecl-gallery__item:nth-child(9n + 7),
      .ecl-gallery__item:nth-child(9n + 8),
      .ecl-gallery__item:nth-child(9n + 9) {
        grid-area: span 3 / span 3;
      }
    }
  }

  &.ecl-gallery--template-2 {
    .ecl-gallery__list {
      grid-auto-flow: dense;
      grid-auto-columns: 1fr;

      .ecl-gallery__item:nth-child(10n + 1),
      .ecl-gallery__item:nth-child(10n + 10) {
        aspect-ratio: auto;
        grid-area: span 2 / span 2;
        height: 100%;

        .ecl-gallery__image-container {
          height: 100%;
        }
      }

      .ecl-gallery__item:nth-child(10n + 2) {
        grid-column: 3;
      }

      .ecl-gallery__item:nth-child(10n + 3) {
        grid-column: 4;
      }

      .ecl-gallery__item:nth-child(10n + 8) {
        grid-column: 1;
      }

      .ecl-gallery__item:nth-child(10n + 9) {
        grid-column: 2;
      }
    }
  }

  &.ecl-gallery--template-3 {
    .ecl-gallery__list {
      grid-auto-flow: dense;
      grid-auto-columns: 1fr;

      .ecl-gallery__item:nth-child(9n + 2) {
        grid-column: 1;
      }

      .ecl-gallery__item:nth-child(9n + 3) {
        aspect-ratio: auto;
        grid-area: span 2 / span 2;
        height: 100%;

        .ecl-gallery__image-container {
          height: 100%;
        }
      }

      .ecl-gallery__item:nth-child(9n + 5) {
        grid-column: 4;
      }
    }
  }

  &.ecl-gallery--template-4 {
    .ecl-gallery__list {
      grid-template-columns: repeat(4, 1fr);

      .ecl-gallery__item:nth-child(8n + 1) {
        aspect-ratio: auto;
        grid-area: span 3 / span 3;
        height: 100%;

        .ecl-gallery__image-container {
          height: 100%;
        }
      }
    }
  }

  &.ecl-gallery--template-0 {
    &.ecl-gallery--col-2 {
      .ecl-gallery__list {
        grid-template-columns: repeat(2, 1fr);
      }
    }

    &.ecl-gallery--col-3 {
      .ecl-gallery__list {
        grid-template-columns: repeat(3, 1fr);
      }
    }

    &.ecl-gallery--col-4 {
      .ecl-gallery__list {
        grid-template-columns: repeat(4, 1fr);
      }
    }
  }
}
