<template>
  <LayoutContainer>
    <v-row class="center-90">
      <v-col cols="12" lg="3">
        <div class="controls-section">
          <h3>Ce sont eux qui en parlent le mieux</h3>

          <div class="carousel-controls">
            <v-btn icon="fas fa-chevron-left" @click="goPrevious" />
            <v-btn icon="fas fa-chevron-right" @click="goNext" />
          </div>
        </div>
      </v-col>

      <v-col cols="12" lg="9">
        <Carousel
          ref="carousel"
          :items-to-show="lgAndUp ? 3 : 1"
          :wrap-around="true"
          :show-arrows="false"
          snap-align="center"
          class="carousel"
        >
          <Slide v-for="(card, index) in cards" :key="index" class="card">
            <v-container>
              <v-card class="inv-theme">
                <v-card-item>
                  <v-card-text>
                    <i>"{{ card.review }}"</i>
                  </v-card-text>
                </v-card-item>

                <v-card-actions>
                  <p class="reviewer-name">
                    {{ card.name }}
                  </p>

                  <p class="reviewer-status">
                    {{ card.status }}
                  </p>
                  <p class="reviewer-structure">
                    {{ card.structure }}
                  </p>
                </v-card-actions>
              </v-card>
            </v-container>
          </Slide>
        </Carousel>
      </v-col>
    </v-row>
  </LayoutContainer>
</template>

<script setup lang="ts">
import { Carousel, Slide } from 'vue3-carousel'
import 'vue3-carousel/dist/carousel.css'
import type { PropType, Ref } from 'vue'
import { useDisplay } from 'vuetify'
import type { Review } from '~/types/interface'

defineProps({
  cards: {
    type: Array as PropType<Array<Review>>,
    required: true,
  },
})

const { lgAndUp } = useDisplay()

const carousel: Ref<typeof Carousel | null> = ref(null)

const goPrevious = () => {
  carousel.value!.prev()
}

const goNext = () => {
  carousel.value!.next()
}
</script>

<style scoped lang="scss">
.v-container {
  padding: 0 0 48px 0 !important;
}

.controls-section {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  height: 100%;

  h3 {
    font-weight: 600;
    font-size: 42px;
    line-height: 42px;
    margin-left: 1rem;
    margin-right: 1rem;
    margin-top: 3rem;
    text-align: center;
  }

  .carousel-controls {
    display: flex;
    flex-direction: row;
    justify-content: center;
    align-items: center;
  }

  .v-btn {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 60px;
    height: 60px;
    background-color: transparent;
    border: 2px solid var(--on-standard-theme);
    cursor: pointer;
    margin-right: 1rem;
    margin-bottom: 2rem;
    border-radius: 0;

    @media (max-width: 1240px) {
      margin-top: 2rem;
      margin-bottom: 1rem;
    }
  }
}

.carousel {
  @media (max-width: 1240px) {
    left: -36px;
  }

  .v-container {
    height: 100%;
  }

  .v-card {
    display: flex;
    flex-direction: column;
    padding: 0 0.5rem;
    border-radius: 1rem;
    margin-top: 2rem;
    margin-bottom: 0.6rem;
    height: 100%;

    @media (max-width: 1240px) {
      max-width: 70%;
      margin: 0 auto 48px auto;
    }
  }

  .v-card-item {
    flex: 1;
  }

  .v-card-text {
    min-height: 120px;
    overflow: auto;
    font-size: 1rem;
    flex: 1;
  }

  .v-card-actions {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
  }

  .reviewer-name {
    font-weight: 500;
    font-size: 20px;
    line-height: 24px;
    color: var(--on-primary-color-alt) !important;
    text-align: justify !important;
  }

  .reviewer-status {
    font-weight: 600;
    font-size: 12px;
    line-height: 16px;
    display: flex;
    align-items: center;
    letter-spacing: 0.18em;
    text-transform: uppercase;

    @media (min-width: 600px) {
      text-align: justify !important;
    }

    @media (max-width: 600px) {
      margin: 12px auto;
      text-align: center !important;
    }
  }

  .reviewer-structure {
    font-weight: 300;
    font-size: 0.8rem;
    line-height: 14px;
    display: flex;
    align-items: center;
    margin-bottom: 1rem;
  }

  @media (max-width: 1240px) {
  }
}

.card {
  margin-left: 0.5rem;
  border-radius: 1rem;
}

.v-card-item {
  display: block;
  padding-top: 16px;
}

@media (max-width: 600px) {
  :deep(.v-carousel__controls) {
    color: var(--on-neutral-color);
    background-color: var(--neutral-color);
  }
}
</style>
