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,
    },
    {
        title: "Bulk orders",
        url: "#",
        icon: Truck,
        role: ["systemAdmin"],
        module: "logistics",
        active: true,
    },
    {
        title: "Forecast",
        url: "#",
        icon: Truck,
        role: ["systemAdmin"],
        module: "logistics",
        active: true,
    },
    {
        title: "Ocme cycle counts",
        url: "#",
        icon: Package,
        role: ["technician", "supervisor", "manager", "admin", "systemAdmin"],
        module: "logistics",
        active: false,
    },
    {
        title: "Material Helper",
        url: "/materialHelper/consumption",
        icon: Package,
        role: ["technician", "supervisor", "manager", "admin", "systemAdmin"],
        module: "logistics",
        active: true,
    },
    {
        title: "Ocme Cyclecount",
        url: "/cyclecount",
        icon: Package,
        role: ["technician", "supervisor", "manager", "admin", "systemAdmin"],
        module: "logistics",
        active: true,
    },
];

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>
    );
}
