<template>
  <div>
    <div
      v-if="isAlive(brands, ['data', 0, 'title'])"
      class="infos__content infos__content--brands"
    >
      <div>
        <Title tag="h4" class="title">
          {{ $_tr('listing.DEFAULT.HEADER.brands') }}
        </Title>

        <div class="df-center-y infos__content__brands">
          <component-listing
            id="infos-content-listing"
            :static-data="brands.data"
            :fractions="4"
            :grid-gap="$_theme('spacingS')"
            :pagination="false"
            empty-size="m"
            direction="horizontal"
            class="mt-s brand-img"
          >
            <template #default="{ item }">
              <img
                :src="$_getContentImage(item.menu_icon, 'avatar')"
                :alt="item.title"
                v-bind="item"
              />
            </template>
          </component-listing>
        </div>
      </div>
    </div>

    <div
      v-if="isAlive(countries, ['data', 0, 'title'])"
      class="infos__content infos__content--countries"
    >
      <div>
        <Title tag="h4">
          {{ $_tr('listing.DEFAULT.HEADER.countries') }}
        </Title>

        <div class="df-center-y infos__content__countries mt-s">
          <FormattedReferences
            :listData="countries.data"
            :limit="2"
            :total="countries.total"
          />
        </div>
      </div>
    </div>

    <div
      v-if="isAlive(users, ['data', 0, 'email'])"
      class="infos__content infos__content__contact"
    >
      <Title tag="h4" class="title mb-s">
        {{ $_tr('contact') }}
      </Title>

      <component-listing
        id="infos-content-contacts-listing"
        :static-data="users.data"
        :fractions="1"
        :grid-gap="$_theme('spacingS')"
        :pagination="false"
        class="mt-s"
      >
        <template #default="{ item }">
          <p>{{ $_username(item) }}</p>

          <a :href="`mailto:${item.email}`" class="email">
            {{ item.email }}
          </a>
        </template>
      </component-listing>
    </div>

    <div
      v-if="isAlive(managementModes, ['data'])"
      class="infos__content infos__content--management-modes"
    >
      <div>
        <Title tag="h4" class="title">
          {{ $_tr('managementModes') }}
        </Title>

        <FormattedReferences
          :listData="managementModes.data"
          :limit="2"
          :total="managementModes.total"
          class="mt-s"
        />
      </div>
    </div>
  </div>
</template>

<script>
import { Title } from 'inside-collection/atoms'

import FormattedReferences from '../../../../../inside-customs/components/FormattedReferences'

export default {
  name: 'Infos',
  $_i18nRootPath: 'customs.GED.docGed',
  components: { Title, FormattedReferences },
  props: {
    countries: {
      type: Object
    },
    users: {
      type: Object
    },
    managementModes: {
      type: Object
    },
    brands: {
      type: Object
    }
  }
}
</script>

<style lang="scss">
@use '@inside-library/styles/mixins/partials/common-mixin' as *;

.modal__body--infos {
  display: flex;
  justify-content: space-between;
  background-color: var(--color-grey-light);
  padding: var(--spacing-xl);
  border-radius: var(--radius-m);

  @include mobile {
    padding: var(--spacing-l);
    flex-direction: column;
  }

  .infos__content {
    position: relative;
    display: flex;
    justify-content: center;
    width: 100%;
    padding-left: var(--spacing-m);
    padding-right: var(--spacing-m);
    text-align: left;
    border-left: solid 2px;

    .title {
      text-align: center;
    }

    p {
      line-height: var(--spacing-l);
      font-size: var(--font-size-h5);
    }

    @include mobile {
      text-align: center;
      padding: 0 var(--spacing-s);
      border-left: none;
      margin-bottom: var(--spacing-m);
      padding-bottom: var(--spacing-m);

      &::after {
        content: '';
        position: absolute;
        bottom: 0;
        width: 50%;
        height: 2px;
        background-color: var(--color-grey-700);
      }

      &:last-child {
        margin-bottom: 0;
        padding-bottom: 0;

        &::after {
          height: 0;
        }
      }
    }

    &:nth-child(1) {
      padding-left: 0;
      border-left: none;
    }

    &__countries {
      flex-wrap: wrap;
    }

    &__country {
      p {
        margin-left: var(--spacing-xs);
      }
    }

    &__countries,
    &__brands {
      .component-listing.use-grid > .listing-container > .data-container {
        grid-template-columns: repeat(auto-fill, minmax(20px, 1fr)) !important;
      }
    }

    &__contact {
      display: flex;
      flex-direction: column;
      justify-content: flex-start;
      align-items: left;
    }

    :deep(.formatted-references ul) {
      top: inherit;
      bottom: var(--spacing-l);
    }

    .brand-img {
      width: 125px;
      height: auto;
    }
  }
}
</style>
