import { Cylinder, Package, Truck } from "lucide-react";
import {
    SidebarGroup,
    SidebarGroupContent,
    SidebarGroupLabel,
    SidebarMenu,
    SidebarMenuButton,
    SidebarMenuItem,
} from "../../ui/sidebar";
import { hasPageAccess } from "@/utils/userAccess";
import { User } from "@/types/users";
// this will need to be moved to a links section the db to make it more easy to remove and add
const items = [
    {
        title: "Silo Adjustments",
        url: "#",
        icon: Cylinder,
        role: ["admin", "systemAdmin"],
        module: "logistics",
        active: true,
    },
    {
        name: "Bulk orders",
        moduleName: "logistics",
        description: "",
        link: "#",
        icon: Truck,
        role: ["systemAdmin"],
        active: true,
        subSubModule: [],
    },
    {
        name: "Forecast",
        moduleName: "logistics",
        description: "",
        link: "#",
        icon: Truck,
        role: ["systemAdmin"],
        active: true,
        subSubModule: [],
    },
    {
        name: "Ocme cycle counts",
        moduleName: "logistics",
        description: "",
        link: "#",
        icon: Package,
        role: ["technician", "supervisor", "manager", "admin", "systemAdmin"],
        active: false,
        subSubModule: [],
    },
    {
        name: "Material Helper",
        moduleName: "logistics",
        description: "",
        link: "/materialHelper/consumption",
        icon: Package,
        role: ["technician", "supervisor", "manager", "admin", "systemAdmin"],
        active: true,
        subSubModule: [],
    },
    {
        name: "Ocme Cyclecount",
        moduleName: "logistics",
        description: "",
        link: "/cyclecount",
        icon: Package,
        role: ["technician", "supervisor", "manager", "admin", "systemAdmin"],
        active: true,
        subSubModule: [],
    },
];

export function LogisticsSideBar({
    user,
    moduleID,
}: {
    user: User | null;
    moduleID: string;
}) {
    return (
        <SidebarGroup>
            <SidebarGroupLabel>Logistics</SidebarGroupLabel>
            <SidebarGroupContent>
                <SidebarMenu>
                    {items.map((item) => (
                        <SidebarMenuItem key={item.title}>
                            <>
                                {hasPageAccess(user, item.role, moduleID) &&
                                    item.active && (
                                        <SidebarMenuButton asChild>
                                            <a href={item.url}>
                                                <item.icon />
                                                <span>{item.title}</span>
                                            </a>
                                        </SidebarMenuButton>
                                    )}
                            </>
                        </SidebarMenuItem>
                    ))}
                </SidebarMenu>
            </SidebarGroupContent>
        </SidebarGroup>
    );
}
