@import '../../../mixins.scss';

%gallery-item-common {
  position: relative;
  overflow: hidden;
  border-radius: var(--gallery-column-border-radius, 0px);
  box-sizing: border-box;
}

.gallery-column {
  position: relative;
  overflow: hidden;
  margin-top: var(--gallery-column-padding);
  display: flex;
  flex-wrap: wrap;

  &.full-screen {
    margin-left: calc(var(--pp-imagetext-padding-left) * -1);
    margin-right: calc(var(--pp-imagetext-padding-right) * -1);
  }

  .more {
    position: absolute;
    right: 10rpx;
    bottom: 10rpx;
    padding: 8rpx 12rpx;
    line-height: 1em;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: bold;
    font-size: 24rpx;
    z-index: 10;
    border-radius: 10rpx;
    overflow: hidden;
    background-color: rgba($color: #000, $alpha: 0.7);
    pointer-events: none;
  }

  $parent: &;

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

  &__item {
    height: 100%;
    width: 100%;
    @extend %gallery-item-common;
    @include flex;
    
    .img {
      width: 100%;
      height: 100%;
    }
  }

  $mini: calc((var(--pp-imagetext-width, 100vw) - var(--gallery-column-padding) * 2) / 4);
  $small: calc((var(--pp-imagetext-width, 100vw) - var(--gallery-column-padding) * 2) / 3);
  $medium: calc((var(--pp-imagetext-width, 100vw) - var(--gallery-column-padding)) / 2);
  $large: var(--pp-imagetext-width, 100vw);

  &__1 {
    // height: $height;
    #{$parent}__item {
      @extend %gallery-item-common;
      margin-top: var(--gallery-column-padding);

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

  &__2 {
    &.child-1 {
      #{$parent}__item {
        @extend %gallery-item-common;
        width: $medium;
        height: $medium;
      }

      // #{$parent}__item-1 {
      //   left: 0;
      //   top: 0;
      // }

      #{$parent}__item-2 {
        margin-left: var(--gallery-column-padding);
      }
    }
  }

  &__3 {
    &.child-1 {
      #{$parent}__item {
        width: $small;
        height: $small;
        @extend %gallery-item-common;
      }

      @for $i from 1 through 3 {
        #{$parent}__item-#{$i} {
          @if $i!=1 {
            margin-left: var(--gallery-column-padding);
          }
        }
      }
    }

    &.child-2 {
      #{$parent}__item {
        width: $medium;
        height: $medium;
        @extend %gallery-item-common;
        position: absolute;
      }

      @for $i from 1 through 3 {
        #{$parent}__item-#{$i} {
          @if $i==1 {
            height: $large;
            position: relative;
          } @else if $i==2 {
            top: 0;
            right: 0;
          } @else if $i==3 {
            bottom: 0;
            right: 0;
          }
        }
      }
    }

    &.child-3 {
      #{$parent}__item {
        width: $medium;
        height: $medium;
        @extend %gallery-item-common;
      }

      @for $i from 1 through 3 {
        #{$parent}__item-#{$i} {
          @if $i==1 {
            width: $large;
            margin-bottom: var(--gallery-column-padding);
          } @else if $i==3 {
            margin-left: var(--gallery-column-padding);
          }
        }
      }
    }

    &.child-4 {
      #{$parent}__item {
        width: $medium;
        height: $medium;
        @extend %gallery-item-common;
        position: absolute;
        left: 0;
      }

      @for $i from 1 through 3 {
        #{$parent}__item-#{$i} {
          @if $i==1 {
            top: 0;
          } @else if $i==2 {
            bottom: 0;
          } @else if $i==3 {
            height: $large;
            position: relative;
            margin-left: calc($medium + var(--gallery-column-padding));
          }
        }
      }
    }

    &.child-5 {
      #{$parent}__item {
        width: $medium;
        height: $medium;
        @extend %gallery-item-common;
      }

      @for $i from 1 through 3 {
        #{$parent}__item-#{$i} {
          @if $i==1 {
          } @else if $i ==2 {
            margin-left: var(--gallery-column-padding);
          } @else if $i==3 {
            width: $large;
            margin-top: var(--gallery-column-padding);
          }
        }
      }
    }
  }

  &__4 {
    &.child-1 {
      #{$parent}__item {
        width: $medium;
        height: $medium;
        @extend %gallery-item-common;
      }

      @for $i from 1 through 4 {
        #{$parent}__item-#{$i} {
          @if $i==1 {
            margin-bottom: var(--gallery-column-padding);
          } @else if $i==2 {
            margin-bottom: var(--gallery-column-padding);
            margin-left: var(--gallery-column-padding);
          } @else if $i==3 {
          } @else if $i==4 {
            margin-left: var(--gallery-column-padding);
          }
        }
      }
    }

    &.child-2 {
      #{$parent}__item {
        width: $small;
        height: $small;
        margin-bottom: var(--gallery-column-padding);
        @extend %gallery-item-common;
      }
      @for $i from 1 through 4 {
        #{$parent}__item-#{$i} {
          @if $i<=3 and $i > 1 {
            margin-left: var(--gallery-column-padding);
          } @else if $i==4 {
            width: $large;
            height: $large;
            margin-bottom: 0;
          }
        }
      }
    }

    &.child-3 {
      display: block;

      &:after {
        content: '';
        display: block;
        clear: both;
      }

      #{$parent}__item {
        width: $small;
        height: $small;
        margin-bottom: var(--gallery-column-padding);
        @extend %gallery-item-common;
      }

      @for $i from 1 through 4 {
        #{$parent}__item-#{$i} {
          @if $i==1 {
            width: calc($large - $small - var(--gallery-column-padding));
            height: $large;
            margin-bottom: 0;
            float: left;
          } @if $i==4 {
            float: right;
            margin-bottom: 0;
          } @if $i>1 {
            float: right;
          } 
        }
      }
    }

    &.child-4 {
      display: block;

      &:after {
        content: '';
        display: block;
        clear: both;
      }

      #{$parent}__item {
        width: $small;
        height: $small;
        margin-bottom: var(--gallery-column-padding);
        @extend %gallery-item-common;
        float: left;
      }
      
      @for $i from 1 through 4 {
        #{$parent}__item-#{$i} {
          @if $i==1 {
            width: calc($large - $small - var(--gallery-column-padding));
            height: $large;
            margin-bottom: 0;
            float: right;
          } @if $i==4 {
            margin-bottom: 0;
          } 
        }
      }
    }
  }

  &__5 {
    &.child-1 {
      &:after {
        content: '';
        display: block;
        clear: both;
      }

      #{$parent}__item {
        width: $small;
        height: $small;
        @extend %gallery-item-common;
      }

      @for $i from 1 through 5 {
        #{$parent}__item-#{$i} {
          @if $i==1 {
            width: $medium;
            height: $medium;
            margin-bottom: var(--gallery-column-padding);
          } @else if $i==2 {
            width: $medium;
            height: $medium;
            margin-bottom: var(--gallery-column-padding);
            margin-left: var(--gallery-column-padding);
          } @else if $i>3 {
            margin-left: var(--gallery-column-padding);
          }
        }
      }
    }
  }

  &__6 {
    &.child-1 {
      &:after {
        content: '';
        display: block;
        clear: both;
      }

      #{$parent}__item {
        width: $small;
        height: $small;
        @extend %gallery-item-common;
      }

      @for $i from 1 through 6 {
        #{$parent}__item-#{$i} {
          @if $i==1 {
            width: calc($small * 2 + var(--gallery-column-padding));
            height: calc($small * 2 + var(--gallery-column-padding));
            float: left;
            margin-right: $mini;
            margin-bottom: var(--gallery-column-padding);
          } @else if $i>1 and $i<4 {
            position: absolute;
            right: 0;
            top: 0;

            @if $i>2 {
              top: calc(($i - 2) * $small + var(--gallery-column-padding));
            }
          } @else if $i>4 {
            margin-left: var(--gallery-column-padding);
          }
        }
      }
    }
  }
}

.gallery-swipe {
  position: relative;
  opacity: 0;
  margin-left: calc(var(--pp-imagetext-padding-left) * -1);
  margin-right: calc(var(--pp-imagetext-padding-right) * -1);

  &.first {
    margin-top: -0.5em;
  }

  &.show {
    opacity: 1;
  }

  &__wrap {
    width: 100%;
    min-height: 400rpx;
    max-height: 1200rpx;
  }

  &__item {
    @include flex;
    height: 100%;
    // background-color: #fff;
    
    .img {
      width: 100%;
      height: 100%;
    }
  }

  &__index {
    position: absolute;
    right: 10rpx;
    top: 10rpx;
    padding: 12rpx;
    line-height: 1em;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: bold;
    font-size: 24rpx;
    z-index: 10;
    border-radius: 10rpx;
    overflow: hidden;
    background-color: rgba($color: #000, $alpha: 0.7);
    pointer-events: none;
    text-align: center;
  }

  &__indicators {
    padding: 20rpx 0;
    @include flex;

    .dot {
      display: block;
      width: 10rpx;
      height: 10rpx;
      margin: 0 1px;
      border-radius: 10rpx;
      transition: all .5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
      background-color: rgba($color: #000, $alpha: 0.2);
      transform: scale(0.8);

      &.active {
        width: 16rpx;
        background-color: var(--pp-color-primary);
      }
    }
  }
}
