import {NavLink} from "react-router-dom";
import {useMemo} from "react";
import {useTranslation} from "react-i18next";

import useAuth from "@/hooks/useAuth.ts";
import {IconPermission, IconQRCode, IconQuery, IconReconciliation} from "@/components/logo";

export const AllDashboardMenu = [
    {
        key: 'manual',
        icon: <IconQRCode/>,
        path: '/dashboard/manual',
    },
    {
        key: 'bill',
        icon: <IconQuery/>,
        path: '/dashboard/bill',
        role: ['root', 'ro', 'fo']
    },
    {
        key: 'check',
        icon: <IconReconciliation/>,
        path: '/dashboard/reconciliation',
        role: ['root', 'fo']
    },
    {
        key: 'permission',
        icon: <IconPermission/>,
        path: '/dashboard/permission',
        role: ['root']
    }
]

export function DashboardNavigation() {
    const {t} = useTranslation()

    const {user} = useAuth();
    const navItems = useMemo(() => {
        if (!user) return [];

        return AllDashboardMenu.filter(it => {
            return !it.role || it.role.includes(user.role)
        });
    }, [user])
    return (<div className={'dashboard-menu-container'}>
            {navItems.map((it) => (
                <NavLink to={it.path} key={it.key} className={'nav-item'}>
                    {it.icon}
                    <span className="menu-text">{t(`layout.menu.${it.key}`)}</span>
                </NavLink>
            ))}
        </div>
    );
}