import { getTranslation } from '@payloadcms/translations';
import LinkWithDefault from 'next/link.js';
import { isEntityHidden } from 'payload/utilities';
import React from 'react';
import { Chevron } from '../../icons/Chevron/index.js';
import { EntityType, groupNavItems } from '../../utilities/groupNavItems.js';
import Logout from '../Logout/index.js';
import NavGroup from '../NavGroup/index.js';
import { NavHamburger } from './NavHamburger/index.js';
import { NavWrapper } from './NavWrapper/index.js';
const baseClass = 'nav';
export const DefaultNav = (props)=>{
    const { config, i18n, permissions, user } = props;
    const { admin: { components: { afterNavLinks, beforeNavLinks } }, collections, globals, routes: { admin } } = config;
    const groups = groupNavItems([
        ...collections.filter(({ admin: { hidden } })=>!isEntityHidden({
                hidden,
                user
            })).map((collection)=>{
            const entityToGroup = {
                type: EntityType.collection,
                entity: collection
            };
            return entityToGroup;
        }),
        ...globals.filter(({ admin: { hidden } })=>!isEntityHidden({
                hidden,
                user
            })).map((global)=>{
            const entityToGroup = {
                type: EntityType.global,
                entity: global
            };
            return entityToGroup;
        })
    ], permissions, i18n);
    return /*#__PURE__*/ React.createElement(NavWrapper, {
        baseClass: baseClass
    }, /*#__PURE__*/ React.createElement("nav", {
        className: `${baseClass}__wrap`
    }, Array.isArray(beforeNavLinks) && beforeNavLinks.map((Component, i)=>/*#__PURE__*/ React.createElement(Component, {
            key: i
        })), groups.map(({ entities, label }, key)=>{
        return /*#__PURE__*/ React.createElement(NavGroup, {
            key: key,
            label: label
        }, entities.map(({ type, entity }, i)=>{
            let entityLabel;
            let href;
            let id;
            if (type === EntityType.collection) {
                href = `${admin}/collections/${entity.slug}`;
                entityLabel = getTranslation(entity.labels.plural, i18n);
                id = `nav-${entity.slug}`;
            }
            if (type === EntityType.global) {
                href = `${admin}/globals/${entity.slug}`;
                entityLabel = getTranslation(entity.label, i18n);
                id = `nav-global-${entity.slug}`;
            }
            const Link = LinkWithDefault.default || LinkWithDefault;
            const LinkElement = Link || 'a';
            return /*#__PURE__*/ React.createElement(LinkElement, {
                // activeClassName="active"
                className: `${baseClass}__link`,
                href: href,
                id: id,
                // tabIndex={!navOpen ? -1 : undefined}
                key: i
            }, /*#__PURE__*/ React.createElement("span", {
                className: `${baseClass}__link-icon`
            }, /*#__PURE__*/ React.createElement(Chevron, {
                direction: "right"
            })), /*#__PURE__*/ React.createElement("span", {
                className: `${baseClass}__link-label`
            }, entityLabel));
        }));
    }), Array.isArray(afterNavLinks) && afterNavLinks.map((Component, i)=>/*#__PURE__*/ React.createElement(Component, {
            key: i
        })), /*#__PURE__*/ React.createElement("div", {
        className: `${baseClass}__controls`
    }, /*#__PURE__*/ React.createElement(Logout, null))), /*#__PURE__*/ React.createElement("div", {
        className: `${baseClass}__header`
    }, /*#__PURE__*/ React.createElement("div", {
        className: `${baseClass}__header-content`
    }, /*#__PURE__*/ React.createElement(NavHamburger, {
        baseClass: baseClass
    }))));
};

//# sourceMappingURL=index.js.map