/*
Components Carousel
*/

@use "sass:math";

// Colour variables used in this paragraph.
$d-p-carousel-item-line-color: $color-agamemnon !default;
$d-p-carousel-item-line-color-inverted: $color-nestor !default;
$d-p-carousel-line-color: $color-agamemnon !default;
$d-p-carousel-line-color-inverted: $color-nestor !default;
$d-p-carousel-arrow-color: $color-cassandra !default;
$d-p-carousel-background-theme-invert: $color-agamemnon !default;
$d-p-carousel-theme-invert-text-color: $color-odysseus !default;

// Margins, paddings and sizing.
$d-p-carousel-items-margin-top: 2% !default;
$d-p-carousel-mobile-items-margin-top: 3rem !default;
$d-p-carousel-item-image-margin-bottom: 1rem !default;
$d-p-carousel-item-image-height: 200px !default;
$d-p-carousel-item-mobile-image-height: 150px !default;
$d-p-carousel-item-padding-x: 5% !default;
$d-p-carousel-item-mobile-padding-x: 10% !default;
$d-p-carousel-item-long-text-margin-bottom: 0 !default;
$d-p-carousel-arrow-size: 40px !default;
$d-p-carousel-arrow-opacity: 0.2 !default;
$d-p-carousel-arrow-hover-opacity: 0.3 !default;

// Font mixins
@mixin font-title-carousel-item {
  font-size: $font-size-lg;
  font-weight: bold;
  text-align: left;
  @include media-breakpoint-down(sm) {
    font-size: $font-size-mdlg;
  }
}

// Group of carousel items.
.paragraph--type--d-p-carousel {
  text-align: center;

  .field--name-field-d-media-icon {
    text-align: center;
  }

  .content > .field--name-field-d-main-title {
    @include font-main-header;
    text-align: center;

    &::after {
      @include decoration-header-line-main-center($d-p-carousel-line-color, $d-p-carousel-line-color-inverted);
    }
  }

  .content > .field--name-field-d-long-text {
    p {
      word-wrap: break-word;
      hyphens: auto;
    }
  }

  .field--name-field-d-main-title + .field--name-field-d-p-cs-item-reference,
  .field--name-field-d-long-text + .field--name-field-d-p-cs-item-reference {
    margin-top: $d-p-carousel-items-margin-top;
    @include media-breakpoint-down(md) {
      margin-top: $d-p-carousel-mobile-items-margin-top;
    }
  }

  .field--name-field-d-p-cs-item-reference {
    margin-left: math.div($d-p-carousel-arrow-size, 2);
    margin-right: math.div($d-p-carousel-arrow-size, 2);
    @include media-breakpoint-up(sm) {
      margin-left: 0;
      margin-right: 0;
    }

    .slick-list {
      width: 100%;
    }

    .slick-prev {
      left: (-1 * $d-p-carousel-arrow-size) - 5px;
      z-index: 2;
    }

    .slick-next {
      right: (-1 * $d-p-carousel-arrow-size) - 5px;
      z-index: 2;
    }

    .slick-arrow {
      width: $d-p-carousel-arrow-size;
      height: $d-p-carousel-arrow-size;

      &::before {
        color: $d-p-carousel-arrow-color;
        font-size: $d-p-carousel-arrow-size;
        opacity: $d-p-carousel-arrow-opacity;
      }

      &:hover {
        &::before {
          opacity: $d-p-carousel-arrow-hover-opacity;
        }
      }
    }

    // Single carousel item
    .carousel-item-wrapper {
      overflow: hidden;
      position: relative;

      &:focus {
        outline: 0;
      }

      .d-p-carousel-item {
        display: block;
        padding-left:  $d-p-carousel-item-padding-x;
        padding-right: $d-p-carousel-item-padding-x;

        @include media-breakpoint-down(sm) {
          padding-left:  $d-p-carousel-item-mobile-padding-x;
          padding-right: $d-p-carousel-item-mobile-padding-x;
        }

        &:focus,
        &:focus * {
          outline: 0;
        }

        &:hover {
          text-decoration: none;
        }

        .field--name-field-d-main-title {
          @include font-title-carousel-item;
          text-align: center;

          &::after {
            @include decoration-header-line-main-center($d-p-carousel-item-line-color, $d-p-carousel-item-line-color-inverted);
          }

          &:last-child::after {
            display: none;
          }
        }
        .field--name-field-d-long-text {
          margin-bottom: $d-p-carousel-item-long-text-margin-bottom;

          p {
            @include font-body-standard;
            text-align: center;
          }
        }
        .field--type-image {
          float: none;
          margin: 0 0 $d-p-carousel-item-image-margin-bottom 0;
          height: $d-p-carousel-item-image-height;
          display: flex;
          align-items: center;
          justify-content: center;

          @include media-breakpoint-down(sm) {
            max-height: $d-p-carousel-item-mobile-image-height;
          }

          img {
            max-width: 100%;
            max-height: $d-p-carousel-item-image-height;
            height: auto;
            width: auto;
            display: block;
            margin: 0;

            @include media-breakpoint-down(md) {
              max-height: $d-p-carousel-item-mobile-image-height;
            }
          }
        }
        .field--name-field-media-oembed-video {
          margin: 0 0 $d-p-carousel-item-image-margin-bottom 0;
          overflow: hidden;
          height: $d-p-carousel-item-image-height;
          @include media-breakpoint-down(md) {
            height: $d-p-carousel-item-mobile-image-height;
          }
          .video-embed {
            position: relative;
            width: 100%;
            height: 100%;
            &--cover {
              top: 50%;
              left: 50%;
              transform: translate(-50%, -50%);
            }
          }
        }
      }
    }
  }
}

.full-width {

  .field--name-field-d-p-cs-item-reference {
    @include make-row();
    .slick-prev {
      left: $d-p-carousel-arrow-size + 5px;
    }
    .slick-next {
      right: $d-p-carousel-arrow-size + 5px;
    }
  }
}
