<template>
  <div class="cart">
    <div class="cart__top">
      <div class="cart__top-left">
        <p><span>{{ t('profile.cart.quantity') }}</span> {{ productsInCartQuantity }}</p>
        <p><span>{{ t('profile.cart.total') }}</span> {{ totalPrice }}</p>
      </div>
      <ui-button class="cart__top-button">{{ t('buttons.checkout') }}</ui-button>
    </div>
    <div class="cart__list">
      <cards-product
          v-for="product in productsInCart"
          :key="product.node.uuid"
          :product="product.node.product"
          :isList="true"
      />
    </div>
  </div>
</template>

<script setup>
import {usePageTitle} from "~/composables/utils/index.js";

const {t} = useI18n();
const cartStore = useCartStore();

const productsInCart = computed(() => {
  return cartStore.currentOrder.orderProducts ? cartStore.currentOrder.orderProducts.edges : [];
});
const totalPrice = computed(() => {
  return cartStore.currentOrder.totalPrice ? cartStore.currentOrder.totalPrice : [];
});
const productsInCartQuantity = computed(() => {
  let count = 0;
  cartStore.currentOrder.orderProducts?.edges.forEach((el) => {
    count = count + el.node.quantity;
  });

  return count;
});

const { setPageTitle } = usePageTitle();

setPageTitle(t('breadcrumbs.cart'));
</script>

<style lang="scss" scoped>
.cart {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 50px;
  flex: 1;
  min-height: 0;

  &__top {
    width: 100%;
    background-color: $white;
    padding: 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 0 20px 2px rgba(0, 0, 0, 0.2);

    & p {
      font-weight: 600;
    }
    
    &-button {
      width: fit-content;
      padding-inline: 20px;
    }
  }

  &__list {
    width: 100%;
    padding: 20px;
    background-color: $white;
    display: flex;
    flex-direction: column;
    gap: 20px;
    box-shadow: 0 0 20px 2px rgba(0, 0, 0, 0.2);
    flex: 1;
    overflow-y: auto;
  }
}
</style>