<template>
  <tabs-music />
  <content-with-heading>
    <template #heading>
      <pane-title :content="{ title: $t('page.music.recently-added.title') }" />
    </template>
    <template #content>
      <list-albums :items="albums" />
    </template>
  </content-with-heading>
</template>

<script setup>
import { onMounted, ref } from 'vue'
import ContentWithHeading from '@/templates/ContentWithHeading.vue'
import { GroupedList } from '@/lib/GroupedList'
import ListAlbums from '@/components/ListAlbums.vue'
import PaneTitle from '@/components/PaneTitle.vue'
import TabsMusic from '@/components/TabsMusic.vue'
import library from '@/api/library'
import { useSettingsStore } from '@/stores/settings'

const settingsStore = useSettingsStore()

const albums = ref(new GroupedList())

onMounted(async () => {
  const limit = settingsStore.recentlyAddedLimit
  const data = await library.search({
    expression:
      'media_kind is music having track_count > 3 order by time_added desc',
    limit,
    type: 'album'
  })
  albums.value = new GroupedList(data.albums, {
    criteria: [{ field: 'time_added', order: -1, type: Date }],
    index: { field: 'time_added', type: Date }
  })
})
</script>
