<template>
  <div class="loyalty-suite-wallets-block">
    <div class="loyalty-suite-wallets-block__header">
      <div class="loyalty-suite-wallets-block__title">
        {{ wallets.length > 1 ? $t('myWallets') : $t('myWallet') }}
      </div>
    </div>
    <div class="loyalty-suite-wallets-block__wrapper" :class="{ 'loyalty-suite-swiper-ready': isSwiperReady }">
      <swiper :slidesPerView="1" :spaceBetween="20" :modules="modules" @init="onSwiperInit"
        :navigation="navigationOptions" class="loyalty-suite-wallets-block__slider">
        <swiper-slide class="loyalty-suite-wallets-block__slide" v-for="(wallet, index) in wallets" :key="index">
          <Wallet :wallet="wallet" :currency="currency" />
        </swiper-slide>
      </swiper>

      <div v-if="wallets.length" class="loyalty-suite-wallets-block__prev">
        <div class="loyalty-suite-wallets-block__prev-arrow">
          <span class="loyalty-suite-material-icons">chevron_left</span>
        </div>
      </div>
      <div v-if="wallets.length" class="loyalty-suite-wallets-block__next">
        <div class="loyalty-suite-wallets-block__next-arrow">
          <span class="loyalty-suite-material-icons">chevron_right</span>
        </div>
      </div>
    </div>
  </div>
</template>

<script lang="ts">
import { ref, defineComponent } from 'vue';
import { Swiper, SwiperSlide } from 'swiper/vue';
import 'swiper/css';
import 'swiper/css/navigation';
import { Navigation } from 'swiper/modules';
import type { Swiper as SwiperInstance } from 'swiper/types';
import Wallet from './Wallet.vue';

export default defineComponent({
  components: {
    Swiper,
    SwiperSlide,
    Wallet
  },
  props: {
    wallets: {
      type: Array as PropType<Record<string, any>[]>,
      required: true,
    },
    currency: {
      type: Array,
      required: true,
    }
  },
  setup(props) {
    const navigationOptions = {
      nextEl: '.loyalty-suite-wallets-block__next',
      prevEl: '.loyalty-suite-wallets-block__prev',
    };

    const isSwiperReady = ref(false);

    const onSwiperInit = (swiper: SwiperInstance) => {
      isSwiperReady.value = true;
    };

    return {
      navigationOptions,
      modules: [Navigation],
      isSwiperReady,
      onSwiperInit
    };
  }
});
</script>

<style lang="scss" scoped>
.loyalty-suite-wallets-block {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;

  &__wrapper {
    display: flex;
    width: 100%;
    height: 100%;
    align-items: center;
    justify-content: center;
    position: relative;
  }

  &__header {
    display: flex;
    align-items: center;
    flex-shrink: 0;
    min-height: 50px;
    padding: 10px;
  }

  &__title {
    display: flex;
    font-size: 14px;
    font-weight: 700;
    margin-right: 5px;
  }

  &__slider {
    width: 100%;
    height: 100%;
    padding: 10px;
    margin: 0;
  }

  &__slide {
    width: 100%;
    height: 100%;
  }

  &__prev {
    display: none;
    flex-shrink: 0;
    width: 35px;
    height: 35px;
    position: absolute;
    z-index: 2;
    top: 50%;
    left: 0;
    transform: translateY(-50%);
    align-items: center;
    justify-content: center;

    &-arrow {
      display: flex;
      flex-shrink: 0;
      width: 35px;
      height: 35px;
      border-radius: 50%;
      justify-content: center;
      align-items: center;
      transition: 0.3s;
      background: var(--loyalty-suite-primary-80);

      &:hover {
        cursor: pointer;
        background: var(--loyalty-suite-primary-90);
      }
    }

    .loyalty-suite-material-icons {
      font-size: 26px;
      color: var(--loyalty-suite-light);
      margin-right: 2px;
    }

    &.swiper-button-disabled {
      display: none !important;
    }
  }

  &__next {
    display: none;
    flex-shrink: 0;
    width: 35px;
    height: 35px;
    position: absolute;
    z-index: 2;
    top: 50%;
    right: 0;
    transform: translateY(-50%);
    align-items: center;
    justify-content: center;

    &-arrow {
      display: flex;
      flex-shrink: 0;
      width: 35px;
      height: 35px;
      border-radius: 50%;
      justify-content: center;
      align-items: center;
      transition: 0.3s;
      background: var(--loyalty-suite-primary-80);

      &:hover {
        cursor: pointer;
        background: var(--loyalty-suite-primary-90);
      }
    }

    .loyalty-suite-material-icons {
      font-size: 26px;
      color: var(--loyalty-suite-light);
    }

    &.swiper-button-disabled {
      display: none !important;
    }
  }
}

.loyalty-suite-swiper-ready .loyalty-suite-wallets-block__prev,
.loyalty-suite-swiper-ready .loyalty-suite-wallets-block__next {
  display: flex;
}

@media (max-width: 576px) {
  .loyalty-suite-wallets-block {
    &__slider {
      width: 100%;
    }

    &__slide {
      width: 100%;
    }
  }
}
</style>
