<script setup lang="ts">
import { Separator } from '@/components/ui/separator';
import CreateDirectoryDialog from '~/components/actions/CreateDirectoryDialog.vue';
import UploadDialog from '~/components/actions/UploadDialog.vue';
import { getWarrens } from '~/lib/api/warrens';
const uploadStore = useUploadStore();

const route = useRoute();
const store = useWarrenStore();

store.warrens = await getWarrens();
</script>

<template>
    <SidebarProvider>
        <AppSidebar />
        <main class="flex w-full grow flex-col overflow-hidden">
            <header
                class="flex h-16 items-center gap-2 transition-[width,height] ease-linear group-has-[[data-collapsible=icon]]/sidebar-wrapper:h-12"
            >
                <div class="flex w-full items-center gap-2 px-4">
                    <SidebarTrigger class="[&_svg]:size-4" />
                    <Separator orientation="vertical" class="mr-2 !h-4" />
                    <AppBreadcrumbs />

                    <div
                        class="ml-auto flex flex-row-reverse items-center gap-2"
                    >
                        <CreateDirectoryDialog>
                            <Button
                                v-if="route.path.startsWith('/warrens/')"
                                variant="outline"
                                size="icon"
                            >
                                <Icon name="lucide:folder-plus" />
                            </Button>
                        </CreateDirectoryDialog>
                        <UploadDialog>
                            <Button
                                class="relative"
                                variant="outline"
                                size="icon"
                            >
                                <Icon name="lucide:upload" />
                                <div
                                    v-if="uploadStore.progress != null"
                                    class="bg-primary absolute top-1 right-1 h-1.5 w-1.5 animate-pulse rounded-full"
                                ></div>
                            </Button>
                        </UploadDialog>
                    </div>
                </div>
            </header>

            <div class="flex flex-1 flex-col p-4 pt-0">
                <slot />
            </div>
        </main>
    </SidebarProvider>
</template>
