/**
 * List with illustration
 * @define list-illustration
 */

@use 'sass:map';
@use '@ecl/vanilla-layout-grid/mixins/breakpoints';

// Exposed variables
$theme: null !default;
$list-illustration: null !default;

.ecl-list-illustration {
  list-style: none;
  margin: 0;
  padding: 0;
}

.ecl-list-illustration__item {
  display: flex;
  flex-direction: column;
  padding: map.get($list-illustration, 'item-padding-mobile');

  &:first-of-type {
    padding-top: 0;
  }

  &:last-of-type {
    padding-bottom: 0;
  }
}

.ecl-list-illustration__picture {
  flex-shrink: 0;
}

.ecl-list-illustration__image {
  aspect-ratio: 3/2;
  display: block;
  height: auto;
  margin-bottom: var(--s-l);
  max-width: 100%;
  object-fit: contain;
}

// manage ratio 1:1
.ecl-list-illustration__image--square {
  aspect-ratio: 1/1;
  object-fit: cover;
  width: 100px;

  &.ecl-list-illustration__image--s {
    width: 48px;
  }

  &.ecl-list-illustration__image--l {
    width: 150px;
  }
}

.ecl-list-illustration__title-container {
  display: flex;
  flex-direction: column;
  max-width: var(--max-w);
}

.ecl-list-illustration__icon {
  color: map.get($list-illustration, 'icon-color');
  margin-bottom: var(--s-s);
}

.ecl-list-illustration__value {
  color: map.get($list-illustration, 'title-color');
  font: map.get($list-illustration, 'value-font-mobile-l');

  .ecl-list-illustration--font-m & {
    font: map.get($list-illustration, 'value-font-mobile-m');
  }
}

.ecl-list-illustration__title {
  color: map.get($list-illustration, 'title-color');
  font: map.get($list-illustration, 'title-font');
}

.ecl-list-illustration__value + .ecl-list-illustration__title {
  margin-top: map.get($list-illustration, 'title-margin');
}

.ecl-list-illustration__description {
  color: map.get($list-illustration, 'description-color');
  font: var(--f-m);
  max-width: var(--max-w);
}

.ecl-list-illustration__title-container + .ecl-list-illustration__description {
  margin-top: map.get($list-illustration, 'description-margin');
}

@include breakpoints.up('m') {
  .ecl-list-illustration__item {
    flex-direction: row;
    margin-bottom: 0;
    padding: map.get($list-illustration, 'item-padding-desktop');
  }

  .ecl-list-illustration--zebra {
    left: auto;
    margin-inline-start: 0;
    width: auto;
  }

  .ecl-list-illustration__image {
    margin-bottom: 0;
    margin-inline-end: var(--s-xl);

    &:not(.ecl-list-illustration__image--square) {
      width: 15.875rem;
    }
  }
}

@include breakpoints.up('l') {
  .ecl-list-illustration__value {
    font: map.get($list-illustration, 'value-font-desktop-l');

    .ecl-list-illustration--font-m & {
      font: map.get($list-illustration, 'value-font-desktop-m');
    }
  }
}

// Horizontal list
.ecl-list-illustration--col-2,
.ecl-list-illustration--col-3,
.ecl-list-illustration--col-4 {
  .ecl-list-illustration__item {
    margin-bottom: map.get($list-illustration, 'item-margin-mobile');
    padding-bottom: 0;
    padding-top: 0;

    .ecl-list-illustration__description,
    .ecl-list-illustration__title-container {
      max-width: 100%;
    }

    &:last-of-type {
      margin-bottom: 0;
    }
  }
}

@include breakpoints.up('m') {
  .ecl-list-illustration--col-2,
  .ecl-list-illustration--col-3,
  .ecl-list-illustration--col-4 {
    display: grid;
    grid-auto-rows: auto;
    grid-column-gap: 2.5rem;
    grid-row-gap: var(--s-3xl);
    width: 100%;

    .ecl-list-illustration__item {
      flex-direction: column;
      margin-bottom: 0;
      padding: 0;
    }

    .ecl-list-illustration__picture:not(
      .ecl-list-illustration__picture--square
    ) {
      width: 100%;
    }

    .ecl-list-illustration__image {
      margin-inline-end: 0;
      margin-bottom: var(--s-l);

      &:not(.ecl-list-illustration__image--square) {
        width: 100%;
      }
    }
  }

  .ecl-list-illustration--col-2 {
    grid-template-columns: repeat(2, 1fr);
  }

  .ecl-list-illustration--col-3 {
    grid-template-columns: repeat(3, 1fr);
  }

  .ecl-list-illustration--col-4 {
    grid-template-columns: repeat(4, 1fr);
  }
}

// Zebra
.ecl-list-illustration--zebra {
  left: 50%;
  margin-inline-start: -50vw;
  position: relative;
  width: 100vw;

  // stylelint-disable-next-line no-descending-specificity
  .ecl-list-illustration__item {
    padding: map.get($list-illustration, 'item-padding-zebra-mobile');

    &:nth-child(even) {
      background-color: map.get($list-illustration, 'background-color');
    }

    &:first-of-type {
      padding-top: 0;
    }

    &:last-of-type:not(:nth-child(even)) {
      padding-bottom: 0;
    }
  }
}

@include breakpoints.up('s') {
  .ecl-list-illustration--zebra {
    left: auto;
    margin-inline-start: 0;
    width: auto;
  }
}

@include breakpoints.up('m') {
  .ecl-list-illustration--zebra {
    .ecl-list-illustration__item {
      padding: map.get($list-illustration, 'item-padding-zebra-desktop');
    }
  }
}

// Centered items
.ecl-list-illustration--centered {
  &.ecl-list-illustration--col-2,
  &.ecl-list-illustration--col-3,
  &.ecl-list-illustration--col-4 {
    align-items: flex-start;

    // stylelint-disable-next-line no-descending-specificity
    .ecl-list-illustration__item {
      text-align: center;
    }

    .ecl-list-illustration__icon {
      margin-left: auto;
      margin-right: auto;
    }
  }

  .ecl-list-illustration__image {
    margin-bottom: var(--s-m);
  }

  // stylelint-disable-next-line no-descending-specificity
  .ecl-list-illustration__item {
    display: flex;
    flex-direction: column;
    text-align: center;

    .ecl-list-illustration__detail {
      align-items: center;
      display: flex;
      flex-direction: column;
    }

    .ecl-list-illustration__description {
      align-self: center;
      display: inline-block;
    }

    * {
      text-align: center;
    }

    .ecl-list-illustration__icon,
    .ecl-list-illustration__picture {
      align-self: center;
    }
  }
}
