'use strict';

var jsxRuntime = require('../../node_modules/.pnpm/react@18.2.0/node_modules/react/jsx-runtime.cjs');
var reactIcons_esm = require('../../node_modules/.pnpm/@radix-ui_react-icons@1.3.0_react@18.2.0/node_modules/@radix-ui/react-icons/dist/react-icons.esm.cjs');
var index = require('../../node_modules/.pnpm/class-variance-authority@0.7.1/node_modules/class-variance-authority/dist/index.cjs');
var React = require('react');
var dropdownMenu = require('../dropdown-menu/dropdown-menu.cjs');
var breadcrumb_module = require('./breadcrumb.module.css.cjs');

const BreadcrumbItem = ({ as = jsxRuntime.jsxRuntimeExports.jsx("a", {}), onItemClick, ...props }) => {
    const { label, href, icon, dropdownItems, isActive } = props;
    if (label === 'ellipsis') {
        return (jsxRuntime.jsxRuntimeExports.jsx("span", { className: breadcrumb_module.default['breadcrumb-ellipsis'], children: jsxRuntime.jsxRuntimeExports.jsx(reactIcons_esm.DotsHorizontalIcon, {}) }));
    }
    if (dropdownItems) {
        return (jsxRuntime.jsxRuntimeExports.jsxs(dropdownMenu.DropdownMenu, { children: [jsxRuntime.jsxRuntimeExports.jsxs(dropdownMenu.DropdownMenu.Trigger, { className: breadcrumb_module.default['breadcrumb-dropdown-trigger'], children: [icon && jsxRuntime.jsxRuntimeExports.jsx("span", { className: breadcrumb_module.default['breadcrumb-icon'], children: icon }), jsxRuntime.jsxRuntimeExports.jsx("span", { children: label }), jsxRuntime.jsxRuntimeExports.jsx(reactIcons_esm.ChevronDownIcon, { className: breadcrumb_module.default['breadcrumb-dropdown-icon'] })] }), jsxRuntime.jsxRuntimeExports.jsx(dropdownMenu.DropdownMenu.Content, { className: breadcrumb_module.default['breadcrumb-dropdown-content'], children: dropdownItems.map((dropdownItem, dropdownIndex) => (jsxRuntime.jsxRuntimeExports.jsx(dropdownMenu.DropdownMenu.Item, { className: breadcrumb_module.default['breadcrumb-dropdown-item'], onSelect: () => onItemClick?.(dropdownItem), children: dropdownItem.label }, dropdownIndex))) })] }));
    }
    return React.cloneElement(as, {
        className: index.cx(breadcrumb_module.default['breadcrumb-link'], isActive && breadcrumb_module.default['breadcrumb-link-active']),
        onClick: (e) => {
            if (onItemClick && href !== '#') {
                e.preventDefault();
                onItemClick(props);
            }
        },
        href,
        ...as.props
    }, jsxRuntime.jsxRuntimeExports.jsxs(jsxRuntime.jsxRuntimeExports.Fragment, { children: [icon && jsxRuntime.jsxRuntimeExports.jsx("span", { className: breadcrumb_module.default['breadcrumb-icon'], children: icon }), jsxRuntime.jsxRuntimeExports.jsx("span", { children: label })] }));
};
const breadcrumbVariants = index.cva(breadcrumb_module.default['breadcrumb'], {
    variants: {
        size: {
            small: breadcrumb_module.default['breadcrumb-small'],
            medium: breadcrumb_module.default['breadcrumb-medium']
        }
    },
    defaultVariants: {
        size: 'medium'
    }
});
const Breadcrumb = React.forwardRef(({ className, size = 'medium', items, maxVisibleItems, separator = '/', onItemClick, ...props }, ref) => {
    const visibleItems = React.useMemo(() => {
        if (maxVisibleItems && items.length > maxVisibleItems) {
            return [
                ...items.slice(0, 1),
                { label: 'ellipsis', href: '#' },
                ...items.slice(-Math.min(maxVisibleItems - 1, items.length - 1))
            ];
        }
        return items;
    }, [maxVisibleItems, items]);
    return (jsxRuntime.jsxRuntimeExports.jsx("nav", { className: breadcrumbVariants({ size, className }), ref: ref, ...props, children: jsxRuntime.jsxRuntimeExports.jsx("ol", { className: breadcrumb_module.default['breadcrumb-list'], children: visibleItems.map((item, index) => {
                const isLast = index === visibleItems.length - 1;
                return (jsxRuntime.jsxRuntimeExports.jsxs("li", { className: breadcrumb_module.default['breadcrumb-item'], children: [jsxRuntime.jsxRuntimeExports.jsx(BreadcrumbItem, { ...item, isActive: isLast, onItemClick: onItemClick }), !isLast && (jsxRuntime.jsxRuntimeExports.jsx("span", { className: breadcrumb_module.default['breadcrumb-separator'], children: separator }))] }, index));
            }) }) }));
});
Breadcrumb.displayName = 'Breadcrumb';

exports.Breadcrumb = Breadcrumb;
//# sourceMappingURL=breadcrumb.cjs.map
