import React from 'react';
import { ShouldRenderTabs } from './ShouldRenderTabs.js';
import { DocumentTab } from './Tab/index.js';
import { getCustomViews } from './getCustomViews.js';
import { getViewConfig } from './getViewConfig.js';
import { tabs as defaultTabs } from './tabs/index.js';
const baseClass = 'doc-tabs';
export const DocumentTabs = (props)=>{
    const { collectionConfig, config, globalConfig } = props;
    const customViews = getCustomViews({
        collectionConfig,
        globalConfig
    });
    return /*#__PURE__*/ React.createElement(ShouldRenderTabs, null, /*#__PURE__*/ React.createElement("div", {
        className: baseClass
    }, /*#__PURE__*/ React.createElement("div", {
        className: `${baseClass}__tabs-container`
    }, /*#__PURE__*/ React.createElement("ul", {
        className: `${baseClass}__tabs`
    }, Object.entries(defaultTabs)?.sort(([, a], [, b])=>{
        if (a.order === undefined && b.order === undefined) return 0;
        else if (a.order === undefined) return 1;
        else if (b.order === undefined) return -1;
        return a.order - b.order;
    })?.map(([name, tab], index)=>{
        const viewConfig = getViewConfig({
            name,
            collectionConfig,
            globalConfig
        });
        const tabFromConfig = viewConfig && 'Tab' in viewConfig ? viewConfig.Tab : undefined;
        const tabConfig = typeof tabFromConfig === 'object' ? tabFromConfig : undefined;
        const { condition } = tabConfig || {};
        const meetsCondition = !condition || condition && Boolean(condition({
            collectionConfig,
            config,
            globalConfig
        }));
        if (meetsCondition) {
            return /*#__PURE__*/ React.createElement(DocumentTab, {
                key: `tab-${index}`,
                ...props,
                ...tab || {},
                ...tabFromConfig || {}
            });
        }
        return null;
    }), customViews?.map((CustomView, index)=>{
        if ('Tab' in CustomView) {
            const { Tab, path } = CustomView;
            if (typeof Tab === 'function') {
                return /*#__PURE__*/ React.createElement(Tab, {
                    path: path,
                    ...props,
                    key: `tab-custom-${index}`
                });
            }
            return /*#__PURE__*/ React.createElement(DocumentTab, {
                key: `tab-custom-${index}`,
                ...props,
                ...Tab
            });
        }
        return null;
    })))));
};

//# sourceMappingURL=index.js.map