<template>
  <div v-if="fetchedData.length">
    <ListingSeparator :title="$_tr('title')" />

    <div class="home-project-news-listing-container">
      <component-listing
        v-if="!getTablet"
        id="homepage-project-news-listing"
        :static-data="fetchedData"
        :pagination="false"
        :use-grid="getTablet || getMobile"
        :fractions="getTablet || getMobile ? 1 : 3"
        direction="horizontal"
        class="homepage-project-news-listing mr-xl"
      >
        <template #default="{ item }">
          <ProjectNewsCard v-bind="item" :key="item.uuid" />
        </template>
      </component-listing>

      <ActionCard
        v-if="!getTablet"
        :title="$_tr('link')"
        :to="{ name: 'ProjectNewsListingPage' }"
        icon-name="I-discover-the-news-of-the-subsidiaries"
      />

      <Slider v-if="getTablet" :data="sliderNewsList">
        <template #default="{ item, index }">
          <ProjectNewsCard
            v-if="index < sliderNewsList.length - 1"
            v-bind="item"
            :key="item.uuid"
            class="my-m"
          />

          <ActionCard
            v-else
            :title="$_tr('link')"
            :to="{ name: 'ProjectNewsListingPage' }"
            icon-name="I-discover-the-news-of-the-subsidiaries"
          />
        </template>
      </Slider>
    </div>
  </div>
</template>

<script>
import ListingSeparator from './sub-components/ListingSeparator'
import ActionCard from './sub-components/ActionCard'

import ProjectNewsCard from './cards/ProjectNewsCard'

import Slider from '@inside-slideshow/components/lib/Slider'

export default {
  name: 'HomeProjectNews',
  $_i18nRootPath: 'customs.HOMEPAGE.newsRss',
  components: { ListingSeparator, ActionCard, ProjectNewsCard, Slider },
  props: {
    fetchedData: {
      type: Array
    }
  },
  computed: {
    sliderNewsList() {
      return this.fetchedData.concat({})
    }
  }
}
</script>

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

.home-project-news-listing-container {
  @include desktop-only {
    display: flex;

    .homepage-project-news-listing {
      width: 75%;

      .data-container {
        justify-content: space-between;
      }
    }
  }

  @include tablet {
    .slider-container {
      margin-top: 0;
      padding-top: 0;
      padding-bottom: var(--spacing-l);

      .swiper-container {
        .swiper-pagination {
          text-align: center;
          height: 22px;
          margin-top: var(--spacing-xs);
        }

        .swiper-slide {
          padding: 0 var(--spacing-s);
        }

        .swiper-button-prev,
        .swiper-button-next {
          top: initial;
          bottom: 7px;
        }

        .swiper-button-prev::after,
        .swiper-button-next::after {
          bottom: 0;
        }
      }
    }
  }
}
</style>
