import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
import { memo, useMemo } from 'react';
import { Navigate, Route, Routes } from 'react-router-dom';
import { getFirstPageLink, getItemsByType } from './helpers.js';
import { SectionContent } from '../SectionContent/index.js';
function ContentItemsComponent({ items, root = false }) {
    const defaultRootLink = '/';
    const { rootItem } = getItemsByType(items);
    const firstPageLink = !root || rootItem ? defaultRootLink : getFirstPageLink(items, defaultRootLink);
    const renderRoutes = useMemo(() => (_jsxs(Routes, { children: [rootItem && (_jsx(Route, { path: `${rootItem.href || defaultRootLink}*`, element: _jsx(SectionContent, { items: items }) })), _jsx(Route, { path: "*", element: _jsx(Navigate, { to: firstPageLink, replace: true }) })] })), [rootItem, defaultRootLink, items, firstPageLink]);
    if (root && !items.length) {
        return (_jsx(Routes, { children: _jsx(Route, { path: "*", element: _jsx(SectionContent, { items: items }) }) }));
    }
    if (!items.length)
        return null;
    return _jsx(_Fragment, { children: renderRoutes });
}
export const ContentItems = memo(ContentItemsComponent);
//# sourceMappingURL=ContentItems.js.map