<template>
    <div class="flex flex-col overflow-hidden group">
        <div class="flex justify-between">
            <UButton
                class="flex-grow cursor-default"
                leading-icon="i-heroicons-magnifying-glass"
                color="gray"
                variant="ghost"
                size="md"
                label="搜索记录"
            />
            <UButton
                class="hidden group-hover:flex"
                label="清空"
                size="md"
                variant="link"
                @click="handleClear"
            />
        </div>
        <ClientOnly>
            <div class="flex overflow-y-auto flex-col gap-1 border-l border-gray-200 dark:border-gray-800 pl-2 ml-5">
                <template v-for="(item, index) in $searchHistory" :key="index">
                    <UButton
                        class="flex text-gray-400"
                        color="gray"
                        variant="ghost"
                        size="xs"
                        long
                        :to="`/search/${item.c_id}`"
                        @click="handleClickItem"
                    >
                        <div class="flex-grow truncate">{{ item.title }}</div>
                    </UButton>
                </template>
            </div>
        </ClientOnly>
    </div>
</template>
<script setup>
const emits = defineEmits(['sign', 'clear'])
const Layout = inject('Layout')
const modal = useModal()
const { $searchHistory } = storeToRefs(useSearchStore())
const { $clearSearchHistory } = useSearchStore()
const query = ref('')
function handleClear () {
    $clearSearchHistory()
}
function handleClickItem () {
    Layout.handleCloseAside()
}
</script>
