<template>
  <div class="w-full flex-1 mb-3">
    <div v-for="item in themeDTOList" :key="item.title">
      <RecommendPostsList :recommendTheme="item" />
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted, nextTick } from "vue";
import { emitter } from '@/utils/events'
import { SCROLL_TO_BOTTOM } from "@/constants/constant";
import { discoveryCradComponent } from "@/api/home";
import RecommendPostsList from "../RecommendPostsList/index.vue";

const themeDTOList = ref([]);

const loadDiscoveryCradComponent = async () => {
  const res = await discoveryCradComponent();
  if (res.code === 0 && res.data) {
    themeDTOList.value = res.data.themeDTOList;

    nextTick(() => {
      setTimeout(() => {
        emitter.emit(SCROLL_TO_BOTTOM, true);
      }, 300);
    });
  }
};

onMounted(() => {
  loadDiscoveryCradComponent();
});
</script>
