import type { CSSProperties } from "react";

import { CollectionsManager } from "@/components/admin/collections/CollectionsManager";
import { AppSidebar } from "@/components/app-sidebar";
import {
    SidebarInset,
    SidebarProvider,
    SidebarTrigger,
} from "@/components/ui/sidebar";
import {
    listAdminPhotoCollections,
    listPickedPhotosForCollections,
} from "@/server/admin/photo-collections";

export const dynamic = "force-dynamic";

export default async function CollectionsPage() {
    const [collections, pickedPhotos] = await Promise.all([
        listAdminPhotoCollections(),
        listPickedPhotosForCollections(),
    ]);

    return (
        <SidebarProvider
            style={
                {
                    "--sidebar-width": "calc(var(--spacing) * 72)",
                    "--header-height": "calc(var(--spacing) * 12)",
                } as CSSProperties
            }
        >
            <AppSidebar variant="inset" />
            <SidebarInset>
                <header className="flex h-(--header-height) shrink-0 items-center gap-2 border-b transition-[width,height] ease-linear group-has-data-[collapsible=icon]/sidebar-wrapper:h-(--header-height)">
                    <div className="flex w-full items-center gap-1 px-4 lg:gap-2 lg:px-6">
                        <SidebarTrigger className="-ml-1" />
                        <h1 className="text-base font-medium">Collections</h1>
                    </div>
                </header>
                <CollectionsManager
                    initialCollections={collections}
                    initialPickedPhotos={pickedPhotos}
                />
            </SidebarInset>
        </SidebarProvider>
    );
}
