<script setup lang="ts">
import { Separator } from '@/components/ui/separator';
import {
    Breadcrumb,
    BreadcrumbList,
    BreadcrumbItem,
    BreadcrumbLink,
    BreadcrumbPage,
    BreadcrumbSeparator,
} from '@/components/ui/breadcrumb';
import CreateDirectoryDialog from '~/components/actions/CreateDirectoryDialog.vue';
import UploadDialog from '~/components/actions/UploadDialog.vue';
const uploadStore = useUploadStore();

const route = useRoute();

const breadcrumbs = computed(() => getBreadcrumbs(route.path));
</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" />
                    <Breadcrumb>
                        <BreadcrumbList>
                            <template
                                v-for="(crumb, i) in breadcrumbs"
                                :key="i"
                            >
                                <BreadcrumbItem>
                                    <NuxtLink
                                        v-if="i < breadcrumbs.length - 1"
                                        :to="crumb.href"
                                        as-child
                                    >
                                        <BreadcrumbLink>
                                            {{ crumb.name }}
                                        </BreadcrumbLink>
                                    </NuxtLink>
                                    <BreadcrumbPage v-else>{{
                                        crumb.name
                                    }}</BreadcrumbPage>
                                </BreadcrumbItem>
                                <BreadcrumbSeparator
                                    v-if="i < breadcrumbs.length - 1"
                                    class="hidden md:block"
                                />
                            </template>
                        </BreadcrumbList>
                    </Breadcrumb>

                    <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>

<style>
* {
    font-family: 'TikTok Sans', sans-serif;
}
</style>
