<script setup>
import { onMounted, ref } from 'vue'
import { useChartsApi } from '@/api/charts.js'
import ChartsCard from '@/views/ChartsView/ChartsCard.vue'

const { getChartsPrices } = useChartsApi()

const pricesList = ref(null)
const loading = ref(true)
const error = ref(null)

const fetchPrices = async () => {
  try {
    const response = await getChartsPrices(7)
    pricesList.value = response.data
    if (!response.status === 400) {
      router.push({ name: 'collection' })
    }
  } catch (err) {
    error.value = err.message
  } finally {
    loading.value = false
  }
}

onMounted(() => {
  fetchPrices()
})
</script>

<template>
  <n-grid responsive="screen" cols="1 s:1 m:2 l:2 xl:2 2xl:2" class="grid-main">
    <n-gi class="grid-item" v-for="item in pricesList" :key="item.merch_uuid">
      <router-link :to="`/details/${item.merch_uuid}`" class="card-link">
        <ChartsCard :chartsData="item" />
      </router-link>
    </n-gi>
  </n-grid>
</template>

<style scoped>

</style>
