<template>
    <div class="w-full items-center flex flex-col">
        <ILibraryHeader />
        <div class="container max-w-screen-lg flex flex-col p-6">
            <div class="flex gap-10">
                <div class="flex flex-col flex-grow">
                    <div class="flex flex-col gap-4">
                        <ILibraryThread
                            v-for="item in threads"
                            :item="item"
                            :key="item.c_id"
                        />
                    </div>
                </div>
                <div class="flex flex-col flex-shrink-0 w-56">
                    <div class="flex justify-between items-center">
                        <div class="flex items-center text-lg gap-2">
                            <UIcon name="i-heroicons-squares-2x2" />
                            <div>合集</div>
                        </div>
                        <UButton
                            icon="i-heroicons-plus-20-solid"
                            variant="soft"
                            @click="handleOpenCreateLibrary"
                        />
                    </div>
                    <div class="flex flex-col gap-4 mt-4">
                        <ILibraryCollect
                            v-for="item in $collection"
                            :item="item"
                            :key="item.id"
                        />
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>
<script setup>
const { $collection } = storeToRefs(useLibraryStore())
const { $openLibraryCreate, $getCollection } = useLibraryStore()
const { getThreadsList } = useLibraryRequest()

function handleOpenCreateLibrary () {
    $openLibraryCreate()
}
// 主题列表
const threads = ref([])
async function getThreadData() {
    threads.value  = await getThreadsList()
}
await getThreadData()
await $getCollection()
</script>
