<script setup lang="ts">
import NavFooter from "@/components/NavFooter.vue";
import NavMain from "@/components/NavMain.vue";
import NavUser from "@/components/NavUser.vue";
import {
    Sidebar,
    SidebarContent,
    SidebarFooter,
    SidebarHeader,
    SidebarMenu,
    SidebarMenuButton,
    SidebarMenuItem,
} from "@/components/ui/sidebar";
import { type NavItem } from "@/types";
import { Link, usePage } from "@inertiajs/vue3";
import { AppWindow, Boxes, ClipboardList, LayoutGrid, Server, Workflow } from "lucide-vue-next";
import AppLogo from "./AppLogo.vue";

const mainNavItems: NavItem[] = [
    {
        title: "Dashboard",
        href: "/dashboard",
        icon: LayoutGrid,
    },
];

const organisation = usePage().props.organisation;

if (organisation) {
    mainNavItems.push({
        title: "Environments",
        href: route("environments.index", {
            organisation: organisation.id,
        }),
        icon: Boxes,
    });
    mainNavItems.push({
        title: "Applications",
        href: route("applications.index", {
            organisation: organisation.id,
        }),
        icon: AppWindow,
    });
    mainNavItems.push({
        title: "Servers",
        href: route("servers.index", {
            organisation: organisation.id,
        }),
        icon: Server,
    });
    mainNavItems.push({
        title: "Operations",
        href: route("operations.index", {
            organisation: organisation.id,
        }),
        icon: Workflow,
    });

    if (
        organisation.providers_count === 0 ||
        organisation.source_providers_count === 0 ||
        organisation.registries_count === 0 ||
        organisation.servers_count === 0 ||
        organisation.applications_count === 0
    ) {
        mainNavItems.push({
            title: "Onboarding",
            href: route("onboarding.show", {
                organisation: organisation.id,
            }),
            icon: ClipboardList,
        });
    }
}

const footerNavItems: NavItem[] = [];
</script>

<template>
    <Sidebar collapsible="icon" variant="inset">
        <SidebarHeader>
            <SidebarMenu>
                <SidebarMenuItem>
                    <SidebarMenuButton size="lg" as-child>
                        <Link :href="route('dashboard')">
                            <AppLogo />
                        </Link>
                    </SidebarMenuButton>
                </SidebarMenuItem>
            </SidebarMenu>
        </SidebarHeader>

        <SidebarContent>
            <NavMain :items="mainNavItems" />
        </SidebarContent>

        <SidebarFooter>
            <NavFooter :items="footerNavItems" />
            <NavUser />
        </SidebarFooter>
    </Sidebar>
    <slot />
</template>
