<template>
	<AppContent>
		<NcEmptyContent
			v-if="!favs.length"
			class="empty"
			:description="
				t('repod', 'Pin some subscriptions to see their latest updates')
			"
			:name="t('repod', 'No favorites')">
			<template #icon>
				<StarOffIcon :size="20" />
			</template>
		</NcEmptyContent>
		<ul v-if="favs.length">
			<li
				v-for="url in favs.sort((fav) => fav.lastPub).map((fav) => fav.url)"
				:key="url">
				<Favorites :url="url" />
			</li>
		</ul>
	</AppContent>
</template>

<script>
import AppContent from '../components/Atoms/AppContent.vue'
import Favorites from '../components/Home/Favorites.vue'
import { NcEmptyContent } from '@nextcloud/vue'
import StarOffIcon from 'vue-material-design-icons/StarOff.vue'
import { mapState } from 'pinia'
import { useSubscriptions } from '../store/subscriptions.js'

export default {
	name: 'Home',
	components: {
		AppContent,
		Favorites,
		NcEmptyContent,
		StarOffIcon,
	},
	computed: {
		...mapState(useSubscriptions, ['favs']),
	},
}
</script>

<style scoped>
.empty {
	height: 100%;
}
</style>
