@use '../../_global/styles/mixins' as *;
@use '../../_global/styles/vars' as *;

.gallery {
  --gallery-spacing: 8px;
  margin: var(--section-margin) 0;
  width: 100%;
  max-width: 880px;

  @media(min-width: 568px) {
    &.content-media-right {
      max-width: calc(50% - 15px);
      float: right;
      margin: 18px 0 20px 30px;

      @media(max-width: 767px) {
        max-width: calc(50% - 10px);
        margin: 14px 0 15px 20px;
      }

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

    &.content-media-left {
      max-width: calc(50% - 15px);
      float: left;
      margin: 18px 30px 20px 0;

      @media(max-width: 767px) {
        max-width: calc(50% - 10px);
        margin: 14px 20px 15px 0;
      }

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

  .gallery-wrapper {
    display: flex;
    flex-wrap: wrap;
    margin: calc(var(--gallery-spacing) / -2);
  }

  .image {
    padding: calc(var(--gallery-spacing) / 2);
    flex: 1 1 100%;
    transition: 0.3s ease;
    transform: translate3d(0, 0, 0) scale(1);

    &.loading {
      opacity: 0;
      transform: translate3d(0, 0, 0) scale(0.9);
    }

    a {
      position: relative;
      display: block;
      background-color: var(--color-background);
      @include focus-visible;
      transition: 0.2s ease;

      &::before {
        content: '';
        position: relative;
        display: block;
        padding-top: 66.666667%;
      }

      &:after {
        content: "";
        @include full-size;
        opacity: 0;
        transition: 0.3s ease;
      }
    }

    img {
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      object-fit: cover;
    }

    .copyright {
      @include copyright;
      opacity: 1 !important;
    }
  }

  &[data-type="grid"] {
    .image {
      flex: 1 1 33.3333%;
      max-width: 33.3334%;

      @media(max-width: 567px) {
        flex: 1 1 50%;
        max-width: 50%;
      }
    }
  }

  &[data-type="first-image"], &[data-type="sinlge-image"] {
    .image a::after {
      display: none;
    }

    .btn {
      position: absolute;
      top: 0;
      right: 0;
      margin: 20px;
    }

    .image {
      transform: none;
      opacity: 1;
      position: relative;

      a {
        background-image: url('../../assets/img/preload.svg');
        background-size: 80px;
        background-position: center;
        background-repeat: no-repeat;
        display: block;
      }

      + .image {
        display: none;
      }
    }

    img {
      opacity: 0;
      transition: 0.3s ease;
    }

    &.loaded {
      img, .image-description, .image .copyright {
        opacity: 1;
      }
    }

    .gallery-wrapper {
      padding: 5px;

      > .image-description {
        font-weight: 400;
        font-size: 18px;
        line-height: 1.2;
        margin-top: 12px;
      }
    }

    img, .copyright, .image-description {
      opacity: 0;
      transition: 0.4s ease;
    }
  }

  &[data-type="masonry"] {
    .gallery-wrapper {
      flex-wrap: nowrap;
      align-items: flex-start;
    }

    .column {
      flex: 1 1 100%;
    }

    .image {
      a::before {
        @include full-size;
        padding: 0;
      }

      img {
        transition: 0.3s ease;
        opacity: 0;
      }

      &.loaded img {
        opacity: 1;
      }
    }
  }

  &[data-type='grid'] {
    .image:not(.loading):not(.loaded) {
      position: absolute;
      opacity: 0;
      pointer-events: none;
    }
  }

  &[data-type="masonry"], &[data-type="grid"] {
    .image-description {
      display: none !important;
    }

    .image a {
      overflow: hidden;

      &::after {
        @include icon-zoom;
        font-family: "Icons", sans-serif;
        display: flex;
        align-items: center;
        justify-content: center;
        z-index: 1;
        font-size: var(--icon-size);
        line-height: 1;
        color: var(--swatches-neutrals-white);
        opacity: 0;
        transition: 0.3s ease;
      }

      &::before {
        background-color: var(--color-text);
        opacity: 0;
        z-index: 1;
        transition: 0.3s ease;
      }

      img {
        transition: 0.3s ease;
      }

      &:hover, &.focus-visible:focus, &:focus-visible, &.-moz-focusring {
        &:before {
          opacity: 0.5;
        }
        &:after {
          opacity: 1;
        }
        img {
          transform: translate3d(0, 0, 0) scale(1.04);
        }
      }
    }
  }

  .button-wrapper {
    text-align: center;

    .btn {
      margin: 40px 0 0;

      @media(max-width: 767px) {
        margin-top: 24px;
      }
    }
  }

  &[data-infinite-scroll="true"] {
    .button-wrapper .btn {
      position: absolute;
      visibility: hidden;
    }
  }
}

.gallery-popup {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: calc(var(--viewport-height, 1vh) * 100);
  background-color: rgba(#0F1C28, 0.95);
  color: var(--swatches-neutrals-white);
  z-index: 100;
  @include hide;

  &.open {
    @include show;
  }

  .slide {
    &::before {
      content: '';
      position: absolute;
      width: 60px;
      height: 60px;
      top: 50%;
      left: 50%;
      margin: -30px;
      background-image: url('../../assets/img/preload.svg');
      background-size: 60px;
      filter: saturate(0) brightness(100);
    }
  }

  .image-box {
    position: relative;
    display: block;
    opacity: 1;
    max-width: 90%;
    transition: 0.3s ease;

    img {
      max-height: calc(var(--viewport-height, 1vh) * 74);
      @media(min-width: 1000px) {
        max-width: calc(100vw - 200px);
      }
    }
    .copyright {
      @include copyright;
    }
  }

  .text-box {
    color: var(--swatches-neutrals-white);
    font-size: 18px;
    display: flex;
    flex-direction: column;
    margin: 20px 20px -10px;

    .copyright {
      order: 1;
      font-size: 14px;
      font-style: italic;
    }

    @media(max-width: 767px) {
      font-size: 16px;
    }
  }

  .controls {
    .prev, .next {
      position: absolute;
      top: 50%;
      right: 0;
      display: block;
      width: 50px;
      height: 50px;

      font-size: 0;
      line-height: 0;
      text-align: center;
      padding: 10px 0;
      margin: -25px 15px;
      border: 0;
      background-color: transparent;
      color: var(--swatches-neutrals-white);
      cursor: pointer;

      &:before {
        @include icon-pfeil-rechts;
        font-family: "Icons", sans-serif;
        font-size: 30px;
        line-height: 1;
      }

      @media(max-width: 999px) {
        display: none;
      }
    }

    .prev {
      left: 0;
      transform: rotate(180deg);
    }

    .tabs {
      display: none;
    }

    .count {
      position: absolute;
      top: 25px;
      left: 50%;
      width: 120px;
      margin-left: -60px;
      text-align: center;
      font-size: 18px;

      span {
        margin: 0 5px;
      }
    }
  }

  .slide {
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    height: calc(var(--viewport-height, 1vh) * 100);
    transition: 0.4s linear;
    opacity: 1;

    &.preload .image-box {
      opacity: 0;
    }
  }

  .closer, .download {
    position: absolute;
    top: 0;
    width: 50px;
    height: 50px;
    font-size: 30px;
    line-height: 1;
    padding: 10px 0;
    color: var(--swatches-neutrals-white);
    background-color: transparent;
    margin: 15px;
    border: 0;
    cursor: pointer;
    z-index: 1;

    &:before {
      font-family: "Icons", sans-serif;
    }
  }

  .closer {
    right: 0;

    &::before {
      @include icon-schliessen;
    }
  }

  .download {
    left: 0;
    text-decoration: none;
    text-align: center;

    &::before {
      @include icon-download;
    }
  }

  a, button {
    @include focus-visible;
  }
}

.teaser, .slider {
  .gallery[data-type="first-image"] .image:before {
    padding-top: 66.6666%;
  }
}
