/*
Components Boxes

Styleguide 2.8
*/

@use "sass:math";

// Color variables used in this paragraph.
$d-p-single-box-line-color: $color-agamemnon !default;
$d-p-single-box-line-color-inverted: $color-nestor !default;
$d-p-text-blocks-line-color: $color-agamemnon !default;
$d-p-text-blocks-line-color-inverted: $color-nestor !default;

// Margins, paddings and sizing.
$d-p-text-blocks-group-padding-y: 3.875rem !default;
$d-p-text-blocks-group-mobile-padding-y: 2rem !default;
$d-p-text-blocks-group-margin: 0 0 5.5rem 0 !default;
$d-p-text-blocks-mobile-group-margin: 0 0 2.8rem 0 !default;
$d-p-single-box-padding-x: 5% !default;
$d-p-single-box-mobile-padding-x: 10% !default;
$d-p-single-box-long-text-margin-bottom: 0 !default;

$d-p-text-blocks-tiles-padding: 20px !default;
$d-p-text-blocks-tiles-spacing: 5px !default;

// Other settings.
$d-p-single-text-box-grid-image-padding-bottom: math.div($grid-gutter-width, 2) !default;
$d-p-single-text-box-grid-large-padding: $grid-gutter-width !default;

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

// Group of text blocks with header and CTA
.d-p-group-of-text-blocks {
  > .container {
    > .field--name-field-d-media-icon {
      text-align: center;
    }

    > .field--name-field-d-main-title {
      @include font-main-header;

      @include media-breakpoint-down(md) {
        margin: $d-p-text-blocks-mobile-group-margin;
      }

      @at-root section.header-margin-none & {
        margin-bottom: inherit;
      }
    }
    > .field--type-link {
      text-align: center;
    }
  }

  .d-p-group-of-text-blocks-header-wrapper {
    text-align: center;

    .field--name-field-d-main-title {
      &::after {
        @include decoration-header-line-main-center($d-p-text-blocks-line-color, $d-p-text-blocks-line-color-inverted);
      }
    }
  }

  &.with-long-text {
    .d-p-group-of-text-blocks-header-wrapper {
      .field--name-field-d-main-title {
        margin-bottom: 0;
      }
    }
    .d-p-tiles-wrapper {
      margin-top: $d-p-text-blocks-group-padding-y;

      &:last-child {
        margin-bottom: inherit;
      }
    }
  }

  .d-media-background-wrapper {
    opacity: 0.5;
  }
  .content-wrapper {
    position: relative;
    z-index: 2;
    hyphens: manual;
  }

  .d-p-text-block {
    position: relative;
    padding-left: $d-p-single-box-padding-x;
    padding-right: $d-p-single-box-padding-x;

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

  .theme-default.user-image-background {
    .paragraph.d-p-text-block {
      background-color: black;

      &, .field {
        color: white;
      }

      .field--name-field-d-main-title {
        &::after {
          @include decoration-header-line-main-center($d-p-text-blocks-line-color-inverted, $d-p-text-blocks-line-color);
        }
      }
    }
  }
}

.with-tiles {
  @include media-breakpoint-down(md) {
    .single-boxes-wrapper {
      padding: 0 0 0 $d-p-text-blocks-tiles-spacing;
    }
  }

  .list-item-wrapper {
    padding: 0 $d-p-text-blocks-tiles-spacing $d-p-text-blocks-tiles-spacing 0;

    .d-p-text-block {
      padding-left: 2* $d-p-text-blocks-tiles-padding;
      padding-right: 2* $d-p-text-blocks-tiles-padding;
      margin-bottom: 0;
      width: 100%;
      height: 100%;
      display: flex;
      align-items: center;
      justify-content: center;

      .content-wrapper {
        padding: $d-p-text-blocks-tiles-padding 0;
        .field--name-field-d-main-title {
          text-align: center;
        }
      }
    }

    > div {
      display: block;
      height: 100%;
      width: 100%;
    }

    @include media-breakpoint-down(lg) {
      .d-p-text-block {
        padding-left: $d-p-text-blocks-tiles-padding;
        padding-right: $d-p-text-blocks-tiles-padding;
      }
    }

    @include media-breakpoint-up(lg) {
      padding-top: $d-p-text-blocks-tiles-spacing;
      padding-bottom: 0;

      &:first-child {
        padding-left: 0;
      }

      $cols: 1, 2, 3, 4, 6, 12;
      @each $col in $cols {
        &.col-md-#{$col} {
          &:nth-child(#{math.div(12, $col)}n) {
            padding-right: 0;
          }
          &:nth-child(-n+#{math.div(12, $col)}) {
            padding-top: 0;
          }
        }
      }
    }
  }
}

// Single box
.d-p-text-block {
  .field--name-field-d-main-title {
    @include font-title-single-box;

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

    &:last-child::after {
      display: none;
    }
  }

  .field--name-field-d-long-text {
    margin-bottom: $d-p-single-box-long-text-margin-bottom;
  }

  p {
    @include font-body-standard;
  }
}

.with-grid {
  .geysir-field-paragraph-wrapper,
  .wrapper-d_p_single_text_block {
    height: 100%;
  }

  .single-box-wrapper {
    padding: 0;

    .d-p-text-block {
      margin-bottom: 0;
      padding: $d-p-single-text-box-grid-large-padding;
      text-align: center;

      .field--name-field-d-media-icon {
        padding-bottom: $d-p-single-text-box-grid-image-padding-bottom;

        img {
          margin-bottom: 0;
        }
      }

      .field--name-field-d-main-title {
        @include font-small-box-title();

        &::after {
          display: none;
        }
      }

      a {
        @include font-subtitle-small-link();
      }
    }
  }
}
