<template>
    <div class="bg-zinc-100 dark:bg-zinc-900 rounded-lg p-2">
        <!-- activity info -->
        <div class="flex items-center text-sm font-bold tracking-tight text-zinc-950 dark:text-white">
            <h5 class="">
                {{ instance.title }}
            </h5>
            <button @click="go_to_activity_page(instance)">
                <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5"
                    stroke="currentColor" class="size-5 mr-2 ">
                    <path stroke-linecap="round" stroke-linejoin="round"
                        d="M21 16.811c0 .864-.933 1.406-1.683.977l-7.108-4.061a1.125 1.125 0 0 1 0-1.954l7.108-4.061A1.125 1.125 0 0 1 21 8.689v8.122ZM11.25 16.811c0 .864-.933 1.406-1.683.977l-7.108-4.061a1.125 1.125 0 0 1 0-1.954l7.108-4.061a1.125 1.125 0 0 1 1.683.977v8.122Z" />
                </svg>
            </button>
        </div>
        <p class="mb-1 font-normal text-zinc-700 dark:text-zinc-400">
            {{ instance.abstract }}
        </p>
        <!-- user profile -->
        <UserProfile :user="instance.user" />
        <div class="flex justify-between items-end mt-1">
            <ActivityStatus v-if="instance.work" :instance="instance" />
            <div v-else></div>
            <div class="flex flex-col items-end">
                <p class="mt-1 text-xs text-left font-normal text-zinc-500 dark:text-zinc-400">
                    {{ toPersianNumbers(instance.persian_date) }}
                </p>
                <ActivityStatistics :instance="instance" />
            </div>
        </div>
    </div>
</template>

<script setup>
import { useMaghaleStore } from '~/store'

const store = useMaghaleStore()
const { $toPersianNumbers } = useNuxtApp();
const toPersianNumbers = $toPersianNumbers;
const props = defineProps(['instance'])
const instance = props.instance
const router = useRouter()

function go_to_activity_page(obj) {
    switch (obj.type) {
        case 'paper':
            store.setPaper({ get_title: obj.title, id: obj.content, activity: { id: obj.id } })
            router.push(useRuntimeConfig().public.router.Paper + obj.content)
            break
        case 'code':
            store.setCode({ get_title: obj.title, id: obj.content, activity: { id: obj.id } })
            router.push(useRuntimeConfig().public.router.Code + obj.content)
            break
        case 'book':
            store.setBook({ get_title: obj.title, id: obj.content, activity: { id: obj.id } })
            router.push(useRuntimeConfig().public.router.Book + obj.content)
            break
        case 'chapter':
            store.setChapter({ get_title: obj.title, id: obj.content, activity: { id: obj.id } })
            router.push(useRuntimeConfig().public.router.Chapter + obj.content)
            break
        case 'section':
            store.setSection({ get_title: obj.title, id: obj.content, activity: { id: obj.id } })
            router.push(useRuntimeConfig().public.router.Section + obj.content)
            break
    }
}

</script>