<template>
  <LayoutContainer>
    <div class="premium-container">
      <v-row class="center-90">
        <table v-if="mdAndUp">
          <thead>
            <tr>
              <th />

              <th>
                <p class="standard">Standard</p>
                <p v-if="showFrom" class="from">À partir de</p>
                <p class="price">
                  {{ standardPrice }} <span class="ttc">ttc</span>
                </p>
                <p class="month">/mois *</p>
              </th>

              <th class="premium-column">
                <p class="standard">Premium</p>
                <p v-if="showFrom" class="from">À partir de</p>
                <p class="price">
                  {{ premiumPrice }} <span class="ttc">ttc</span>
                </p>
                <p class="month">/mois *</p>
              </th>
            </tr>
          </thead>

          <tbody>
            <tr v-for="item in items" :key="item.label">
              <td class="label-column">
                {{ item.label }}
              </td>

              <td>
                <v-icon
                  v-if="item.includedInStandard === true"
                  icon="far fa-check-circle"
                  size="18"
                />

                <v-icon
                  v-else-if="item.includedInStandard === false"
                  icon="far fa-times-circle"
                  size="18"
                  color="red"
                />

                <span v-else>
                  {{ item.includedInStandard }}
                </span>
              </td>

              <td>
                <v-icon
                  v-if="item.includedInPremium === true"
                  icon="far fa-check-circle"
                  size="18"
                />

                <v-icon
                  v-else-if="item.includedInPremium === false"
                  icon="far fa-times-circle"
                  size="18"
                  color="red"
                />

                <span v-else>
                  {{ item.includedInPremium }}
                </span>
              </td>
            </tr>
          </tbody>
        </table>

        <div v-else>
          <div class="d-flex flex-row flex-grow-1 justify-center mt-2">
            <v-btn
              :disabled="carouselPos === 0"
              icon="fas fa-chevron-left"
              class="mr-6"
              aria-label="Précédent"
              @click="goToPrevious"
            />
            <v-btn
              :disabled="carouselPos === 1"
              icon="fas fa-chevron-right"
              aria-label="Suivant"
              @click="goToNext"
            />
          </div>

          <v-carousel
            v-model="carouselPos"
            :hide-delimiters="true"
            :show-arrows="false"
            :height="height"
          >
            <v-carousel-item>
              <h4>Standard</h4>
              <div>
                <p class="from">À partir de</p>
                <p class="price">
                  {{ standardPrice }} <span class="ttc">ttc</span>
                  <span class="month">/mois</span>
                </p>
              </div>

              <table>
                <tbody>
                  <tr v-for="item in items" :key="item.label">
                    <td class="label-column">
                      {{ item.label }}
                    </td>

                    <td>
                      <v-icon
                        v-if="item.includedInStandard === true"
                        icon="far fa-check-circle"
                        size="18"
                      />

                      <v-icon
                        v-else-if="item.includedInStandard === false"
                        icon="far fa-times-circle"
                        size="18"
                        color="red"
                      />

                      <span v-else>
                        {{ item.includedInStandard }}
                      </span>
                    </td>
                  </tr>
                </tbody>
              </table>
            </v-carousel-item>

            <v-carousel-item>
              <h4>Premium</h4>

              <div>
                <p class="from">À partir de</p>
                <p class="price">
                  {{ premiumPrice }} <span class="ttc">ttc</span>
                  <span class="month">/mois</span>
                </p>
              </div>

              <table>
                <tbody>
                  <tr v-for="item in items" :key="item.label">
                    <td class="label-column">
                      {{ item.label }}
                    </td>

                    <td>
                      <v-icon
                        v-if="item.includedInPremium === true"
                        icon="far fa-check-circle"
                        size="18"
                      />

                      <v-icon
                        v-else-if="item.includedInPremium === false"
                        icon="far fa-times-circle"
                        size="18"
                        color="red"
                      />

                      <span v-else>
                        {{ item.includedInPremium }}
                      </span>
                    </td>
                  </tr>
                </tbody>
              </table>
            </v-carousel-item>
          </v-carousel>
        </div>

        <div class="asterisk">
          <span>
            * Tarif valable selon la taille de la structure et la version de
            produit choisi (Standard ou Premium). Prix public 2024 en fonction
            de la taille de la structure sur la version Premium. Abonnement
            payable annuellement.
          </span>
        </div>
      </v-row>
    </div>
  </LayoutContainer>
</template>

<script setup lang="ts">
import { useDisplay } from 'vuetify'
import type { PropType } from 'vue'
import type { ComparisonItem } from '~/types/interface'

const { mdAndUp } = useDisplay()

const props = defineProps({
  standardPrice: {
    type: String,
    required: true,
  },
  premiumPrice: {
    type: String,
    required: true,
  },
  items: {
    type: Array as PropType<Array<ComparisonItem>>,
    required: true,
  },
  showFrom: {
    type: Boolean,
    required: false,
    default: false,
  },
})

const height = computed(() => 150 + props.items.length * 48)

const carouselPos = ref(0)

const goToPrevious = () => {
  carouselPos.value = 0
}

const goToNext = () => {
  carouselPos.value = 1
}
</script>

<style scoped lang="scss">
.v-row {
  align-items: center;
  display: flex;
  flex-direction: row;
  justify-content: center;
}

table {
  width: 70%;
  margin-top: 1rem;
  margin-right: auto;
  margin-left: auto;
  border: none;
  border-collapse: collapse;

  @media (max-width: 940px) {
    width: 100%;
  }
}

th {
  height: 8rem;
  font-weight: 400;
  font-size: 30px;
  line-height: 34px;

  @media (max-width: 600px) {
    font-size: 18px;
  }
}

tr {
  height: 3rem;
  text-align: center;
}

tbody tr:nth-child(even) {
  background-color: var(--secondary-color);
}

td {
  padding-right: 5rem;

  @media (max-width: 600px) {
    padding-right: 0;
  }
}

td:first-child {
  text-align: left;
  padding-left: 20px;
  font-weight: 600;
  font-size: 12px;
  line-height: 16px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--on-neutral-color-alt);

  @media (max-width: 600px) {
    padding-left: 5px;
  }
}

.standard {
  font-weight: 600;
  font-size: 12px;
  line-height: 16px;
  text-align: center;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  padding-right: 5rem;
  margin-bottom: 1rem;
}

.from,
.ttc {
  font-weight: 300;
  font-size: 12px;
  line-height: 14px;
  text-align: center;
  color: var(--on-neutral-color-alt);
  padding-right: 5rem;
}

.ttc {
  text-transform: uppercase;
}

.price,
.month {
  font-size: 30px;
  line-height: 34px;
  text-align: center;
  color: var(--on-neutral-color-alt);
}

.month {
  padding-right: 5rem;

  @media (max-width: 600px) {
    padding-right: 0;
  }
}

.v-carousel {
  h4 {
    text-align: center;
    margin: 24px auto 12px auto;
    text-transform: uppercase;
    letter-spacing: 0.25em;
  }

  p {
    padding-right: 0;
  }

  .price {
    margin-top: 12px;
  }

  .ttc {
    padding-right: 10px;
  }
}

.asterisk {
  display: flex;
  margin: 4px auto 0 auto;
  width: 70%;
  justify-content: flex-end;
  font-style: italic;
}

table tr th:nth-child(3),
table tr td:nth-child(3) {
  border-left: 2px solid black;
  border-right: 2px solid black;
  width: 15rem;
  padding: 1rem;
  position: relative;
}
table tr:nth-child(1) th:nth-child(3) {
  border-bottom: none !important;
}

.premium-column {
  position: relative;
  z-index: 10;
  border-radius: 0 15px 15px 0;
}

.premium-column p,
.premium-column .month,
.premium-column .price {
  border: none !important;
}

thead th:nth-child(3) {
  border-top: 2px solid black;
}

tbody tr:last-child td:nth-child(3) {
  border-bottom: 2px solid black;
  border-radius: 0 0 15px 0;
}

.premium-column p,
.premium-column .month,
.premium-column .price,
.premium-column .ttc {
  margin: 0;
  padding: 0;
}
</style>
