'use strict';

var tslib_es6 = require('../node_modules/.pnpm/@rollup_plugin-typescript@12.1.4_rollup@4.46.2_tslib@2.8.1_typescript@5.9.3/node_modules/tslib/tslib.es6.js');
var jsxRuntime = require('react/jsx-runtime');
var page = require('fumadocs-ui/page');
var React = require('react');
var tocFooterWrapper = require('./mdx/toc-footer-wrapper.js');

function createFumaPage({ sourceKey, mdxContentSource, getMDXComponents, mdxSourceDir, githubBaseUrl, copyButtonComponent, siteIcon, FallbackPage, supportedLocales = ['en'], showBreadcrumb = true, showTableOfContent = true, showTableOfContentPopover = false, }) {
    const Page = function Page(_a) {
        return tslib_es6.__awaiter(this, arguments, void 0, function* ({ params }) {
            const { slug, locale } = yield params;
            const page$1 = mdxContentSource.getPage(slug, locale);
            if (!page$1) {
                return jsxRuntime.jsx(FallbackPage, { siteIcon: siteIcon });
            }
            const path = githubBaseUrl ? `${mdxSourceDir}/${page$1.path}` : undefined;
            const tocFooterElement = (jsxRuntime.jsx(tocFooterWrapper.TocFooterWrapper, { lastModified: page$1.data.date, copyButtonComponent: copyButtonComponent
                    ? React.cloneElement(copyButtonComponent, { sourceKey })
                    : undefined, editPath: path, githubBaseUrl: githubBaseUrl }));
            const MDX = page$1.data.body;
            return (jsxRuntime.jsxs(page.DocsPage, { breadcrumb: { enabled: showBreadcrumb }, tableOfContent: {
                    enabled: showTableOfContent,
                    style: 'clerk',
                    single: false,
                    footer: tocFooterElement,
                }, tableOfContentPopover: {
                    enabled: showTableOfContentPopover,
                    footer: tocFooterElement,
                }, toc: page$1.data.toc, article: { className: 'max-sm:pb-16' }, children: [jsxRuntime.jsx(page.DocsTitle, { children: page$1.title }), jsxRuntime.jsx(page.DocsDescription, { className: "mb-2", children: page$1.description }), jsxRuntime.jsx(page.DocsBody, { className: "text-fd-foreground/80", children: jsxRuntime.jsx(MDX, { components: getMDXComponents() }) })] }));
        });
    };
    function generateStaticParams() {
        return mdxContentSource.generateParams('slug', 'locale');
    }
    function generateMetadata(props) {
        return tslib_es6.__awaiter(this, void 0, void 0, function* () {
            const { slug, locale } = yield props.params;
            const page = mdxContentSource.getPage(slug, locale);
            if (!page) {
                return {
                    title: '404 - Page Not Found',
                    description: 'This page could not be found.',
                };
            }
            const baseUrl = process.env.NEXT_PUBLIC_BASE_URL;
            const baseRoute = mdxSourceDir.replace('src/mdx/', '');
            // build the current page path
            const currentPath = slug ? slug.join('/') : '';
            const currentUrl = `${baseUrl}/${locale}/${baseRoute}${currentPath ? `/${currentPath}` : ''}`;
            // generate the seo language map
            const seoLanguageMap = {};
            supportedLocales.forEach(loc => {
                seoLanguageMap[loc] = `${baseUrl}/${loc}/${baseRoute}${currentPath ? `/${currentPath}` : ''}`;
            });
            return {
                metadataBase: new URL(baseUrl),
                title: page.title,
                description: page.description,
                alternates: {
                    canonical: currentUrl,
                    languages: seoLanguageMap
                },
            };
        });
    }
    return {
        Page,
        generateStaticParams,
        generateMetadata,
    };
}

exports.createFumaPage = createFumaPage;
