import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
// packages/ui/src/components/layout/components/Breadcrumbs.tsx
/**
 * @fileoverview Breadcrumbs Component
 * @description Professional breadcrumb navigation with route discovery
 *
 * Features:
 * - Automatic route discovery and breadcrumb generation
 * - Clickable navigation
 * - Professional styling with icons
 * - Responsive design
 * - Customizable separator
 * - Active state management
 *
 * @version 0.0.1
 * @since 0.0.1
 * @author AMBROISE PARK Consulting
 */
import { ChevronRight } from 'lucide-react';
import { useMemo } from 'react';
import { cn } from '@donotdev/components';
import { useTranslation } from '@donotdev/core';
// Platform-specific hooks via conditional exports
import { useLocation } from '@donotdev/ui/routing/hooks';
import { Link } from '../../../routing/Link';
import { useAllRoutes } from '../../../routing/useRouteDiscovery';
/**
 * Breadcrumbs component for navigation
 *
 * @version 0.0.1
 * @since 0.0.1
 * @author AMBROISE PARK Consulting
 *
 * Automatically generates breadcrumbs from current route or accepts custom items
 */
const Breadcrumbs = ({ items, separator: Separator = ChevronRight, showHome = true, homeHref = '/', variant = 'default', className, }) => {
    const { t } = useTranslation('dndev');
    const location = useLocation();
    const allRoutes = useAllRoutes();
    // Build set of valid route paths for existence checking
    const validRoutes = useMemo(() => {
        return new Set(allRoutes.map((route) => route.path));
    }, [allRoutes]);
    // Auto-generate breadcrumbs from current path if not provided
    const breadcrumbItems = items
        ? items
        : (() => {
            const pathSegments = location.pathname.split('/').filter(Boolean);
            const breadcrumbs = [];
            let currentPath = '';
            pathSegments.forEach((segment) => {
                currentPath += `/${segment}`;
                const label = segment
                    .split('-')
                    .map((word) => word.charAt(0).toUpperCase() + word.slice(1))
                    .join(' ');
                // Only add href if route actually exists
                const href = validRoutes.has(currentPath) ? currentPath : undefined;
                breadcrumbs.push({ label, href });
            });
            return breadcrumbs;
        })();
    // Add home item if enabled
    const allItems = showHome
        ? [
            { label: t('navigation.home', 'Home'), href: homeHref },
            ...breadcrumbItems,
        ]
        : breadcrumbItems;
    // Smart variant: Hide breadcrumbs on simple pages (root or single segment)
    if (variant === 'smart') {
        const segments = location.pathname.split('/').filter(Boolean);
        if (segments.length < 2) {
            return null; // Don't render breadcrumbs on simple pages
        }
    }
    return (_jsx("nav", { role: "navigation", "aria-label": "Breadcrumb navigation", className: cn('breadcrumbs', className), children: allItems.map((item, index) => {
            const isLast = index === allItems.length - 1;
            const isActive = isLast || !item.href;
            return (_jsxs("span", { className: "breadcrumb-item", children: [index > 0 && _jsx(Separator, { className: "dndev-size-md separator" }), item.icon && _jsx(item.icon, { className: "dndev-size-md icon" }), item.href && !isActive ? (_jsx(Link, { path: item.href, className: "breadcrumb-link", children: item.label })) : (_jsx("span", { className: "breadcrumb-label", children: item.label }))] }, index));
        }) }));
};
export default Breadcrumbs;
