<template>
<div class="civpbkhh">
	<div ref="scroll" class="scrollbox" :class="{ scroll: isScrolling }">
		<div v-for="note in notes" :key="note.id" class="note">
			<div class="content _panel">
				<div class="body">
					<MkA v-if="note.replyId" class="reply" :to="`/notes/${note.replyId}`"><i class="fas fa-reply"></i></MkA>
					<Mfm v-if="note.text" :text="note.text" :author="note.user" :i="$i" :custom-emojis="note.emojis"/>
					<MkA v-if="note.renoteId" class="rp" :to="`/notes/${note.renoteId}`">RN: ...</MkA>
				</div>
				<div v-if="note.files.length > 0" class="richcontent">
					<XMediaList :media-list="note.files"/>
				</div>
				<div v-if="note.poll">
					<XPoll :note="note" :read-only="true"/>
				</div>
			</div>
			<XReactionsViewer ref="reactionsViewer" :note="note"/>
		</div>
	</div>
</div>
</template>

<script lang="ts" setup>
import { onUpdated, ref, Ref } from 'vue';
import { Note } from 'foundkey-js/built/entities';
import XReactionsViewer from '@/components/reactions-viewer.vue';
import XMediaList from '@/components/media-list.vue';
import XPoll from '@/components/poll.vue';
import * as os from '@/os';
import { $i } from '@/account';

const notes: Ref<Note[]> = ref([]);
const isScrolling = ref(false);
const scroll: Ref<HTMLElement | null> = ref(null);

os.api('notes/featured').then(newNotes => {
	notes.value = newNotes;
});

onUpdated(() => {
	if (scroll.value && scroll.value.clientHeight > window.innerHeight) {
		isScrolling.value = true;
	}
});
</script>

<style lang="scss" scoped>
@keyframes scroll {
	0% {
		transform: translate3d(0, 0, 0);
	}
	5% {
		transform: translate3d(0, 0, 0);
	}
	75% {
		transform: translate3d(0, calc(-100% + 90vh), 0);
	}
	90% {
		transform: translate3d(0, calc(-100% + 90vh), 0);
	}
}

.civpbkhh {
	text-align: right;

	> .scrollbox {
		&.scroll {
			animation: scroll 45s linear infinite;
		}

		> .note {
			margin: 16px 0 16px auto;

			> .content {
				padding: 16px;
				margin: 0 0 0 auto;
				max-width: max-content;
				border-radius: 16px;

				> .richcontent {
					min-width: 250px;
				}
			}
		}
	}
}
</style>
