import "./Breadcrumbs.css";
import {ActionButton as $da878a05ab4a403e$export$cfc7921d29ef7b80} from "./ActionButton.mjs";
import $4b69f02ec06b9226$export$2e2bcd8739ae039 from "./Chevron.mjs";
import $8b0a29919990739e$export$2e2bcd8739ae039 from "../icons/FolderBreadcrumb.mjs";
import $a1dfd$intlStringsmjs from "./intlStrings.mjs";
import {Menu as $13afb0ea5f0ed767$export$d9b273488cd8ce6f, MenuItem as $13afb0ea5f0ed767$export$2ce376c2cc3355c8, MenuTrigger as $13afb0ea5f0ed767$export$27d2ad3c5815583e} from "./Menu.mjs";
import {Text as $8e847109a6ab556d$export$5f1af8db9871e1d6} from "./Content.mjs";
import {useSpectrumContextProps as $5ce63c423902f47d$export$764f6146fadd77f7} from "../icons/useSpectrumContextProps.mjs";
import {jsx as $a1dfd$jsx, jsxs as $a1dfd$jsxs, Fragment as $a1dfd$Fragment} from "react/jsx-runtime";
import {createContext as $a1dfd$createContext, forwardRef as $a1dfd$forwardRef, useContext as $a1dfd$useContext, createElement as $a1dfd$createElement, useState as $a1dfd$useState, useMemo as $a1dfd$useMemo, useRef as $a1dfd$useRef, useCallback as $a1dfd$useCallback, useEffect as $a1dfd$useEffect, Fragment as $a1dfd$Fragment1} from "react";
import {Provider as $a1dfd$Provider, Breadcrumbs as $a1dfd$Breadcrumbs, CollectionRendererContext as $a1dfd$CollectionRendererContext, DefaultCollectionRenderer as $a1dfd$DefaultCollectionRenderer, Breadcrumb as $a1dfd$Breadcrumb, HeadingContext as $a1dfd$HeadingContext, Link as $a1dfd$Link} from "react-aria-components";
import {inertValue as $a1dfd$inertValue, useLayoutEffect as $a1dfd$useLayoutEffect} from "@react-aria/utils";
import {useDOMRef as $a1dfd$useDOMRef, useResizeObserver as $a1dfd$useResizeObserver} from "@react-spectrum/utils";
import {useLocale as $a1dfd$useLocale} from "react-aria";
import {useLocalizedStringFormatter as $a1dfd$useLocalizedStringFormatter} from "@react-aria/i18n";


function $parcel$interopDefault(a) {
  return a && a.__esModule ? a.default : a;
}
/*
 * Copyright 2024 Adobe. All rights reserved.
 * This file is licensed to you under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License. You may obtain a copy
 * of the License at http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under
 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
 * OF ANY KIND, either express or implied. See the License for the specific language
 * governing permissions and limitations under the License.
 */ 













const $f329dd4f2aa58cd0$var$MIN_VISIBLE_ITEMS = 1;
const $f329dd4f2aa58cd0$var$MAX_VISIBLE_ITEMS = 4;
const $f329dd4f2aa58cd0$export$65596d3621b0a4a0 = /*#__PURE__*/ (0, $a1dfd$createContext)(null);
const $f329dd4f2aa58cd0$var$wrapper = function anonymous(props, overrides) {
    let rules = " ";
    let position = false;
    let flexGrow = false;
    let flexShrink = false;
    let flexBasis = false;
    let marginTop = false;
    let marginBottom = false;
    let marginInlineStart = false;
    let matches = String(overrides || '').matchAll(/(?:^|\s)(J|G|I|H|_u|_v|_s|__A|_d|_J|z|y|B|A|_P|_9|W|_l|_A|_z|_6|Z|N|L)[^\s]+/g);
    for (let p of matches){
        if (p[1] === "_P") position = true;
        if (p[1] === "_u") flexGrow = true;
        if (p[1] === "_v") flexShrink = true;
        if (p[1] === "_s") flexBasis = true;
        if (p[1] === "J") marginTop = true;
        if (p[1] === "G") marginBottom = true;
        if (p[1] === "I") marginInlineStart = true;
        rules += p[0];
    }
    if (!position) rules += ' _Pc11';
    rules += ' sd11';
    rules += ' _Cg11';
    rules += ' _Gc11';
    rules += ' _wa11';
    if (!flexGrow) rules += ' _ub11';
    if (!flexShrink) rules += ' _va11';
    if (!flexBasis) rules += ' _sb11';
    if (props.size === "L") rules += ' Urun3rd11';
    else if (props.size === "M") rules += ' UssxDec11';
    if (props.size === "L") rules += ' qrun3rd11';
    else if (props.size === "M") rules += ' qssxDec11';
    rules += ' Td11';
    rules += ' Qd11';
    rules += ' Sd11';
    rules += ' Rd11';
    rules += ' Yd11';
    rules += ' Xb11';
    rules += ' _2b11';
    if (!marginTop) rules += ' Jy11';
    if (!marginBottom) rules += ' Gy11';
    if (props.size === "L") {
        if (!marginInlineStart) rules += ' Irun3rd11';
    } else if (props.size === "M") {
        if (!marginInlineStart) rules += ' IssxDec11';
    }
    return rules;
};
const $f329dd4f2aa58cd0$var$InternalBreadcrumbsContext = /*#__PURE__*/ (0, $a1dfd$createContext)({});
const $f329dd4f2aa58cd0$export$2dc68d50d56fbbd = /*#__PURE__*/ (0, $a1dfd$forwardRef)(function Breadcrumbs(props, ref) {
    [props, ref] = (0, $5ce63c423902f47d$export$764f6146fadd77f7)(props, ref, $f329dd4f2aa58cd0$export$65596d3621b0a4a0);
    let domRef = (0, $a1dfd$useDOMRef)(ref);
    let { UNSAFE_className: UNSAFE_className = '', UNSAFE_style: UNSAFE_style, styles: styles, size: size = 'M', children: children, isDisabled: isDisabled, ...otherProps } = props;
    return /*#__PURE__*/ (0, $a1dfd$jsx)((0, $a1dfd$Provider), {
        values: [
            [
                $f329dd4f2aa58cd0$var$InternalBreadcrumbsContext,
                {
                    size: size,
                    isDisabled: isDisabled
                }
            ]
        ],
        children: /*#__PURE__*/ (0, $a1dfd$jsx)($f329dd4f2aa58cd0$var$CollapsingCollection, {
            containerRef: domRef,
            onAction: props.onAction,
            children: /*#__PURE__*/ (0, $a1dfd$jsx)((0, $a1dfd$Breadcrumbs), {
                ...otherProps,
                isDisabled: isDisabled,
                ref: domRef,
                style: UNSAFE_style,
                className: UNSAFE_className + $f329dd4f2aa58cd0$var$wrapper({
                    size: size
                }, styles),
                children: children
            })
        })
    });
});
let $f329dd4f2aa58cd0$var$BreadcrumbMenu = (props)=>{
    let stringFormatter = (0, $a1dfd$useLocalizedStringFormatter)((0, ($parcel$interopDefault($a1dfd$intlStringsmjs))), '@react-spectrum/s2');
    let { items: items, onAction: onAction } = props;
    let { direction: direction } = (0, $a1dfd$useLocale)();
    let { size: size, isDisabled: isDisabled } = (0, $a1dfd$useContext)($f329dd4f2aa58cd0$var$InternalBreadcrumbsContext);
    let label = stringFormatter.format('breadcrumbs.more');
    return /*#__PURE__*/ (0, $a1dfd$jsx)((0, $a1dfd$CollectionRendererContext).Provider, {
        value: (0, $a1dfd$DefaultCollectionRenderer),
        children: /*#__PURE__*/ (0, $a1dfd$jsxs)("li", {
            className: $f329dd4f2aa58cd0$var$breadcrumbStyles({
                size: size,
                isDisabled: isDisabled,
                isMenu: true
            }),
            children: [
                /*#__PURE__*/ (0, $a1dfd$jsxs)((0, $13afb0ea5f0ed767$export$27d2ad3c5815583e), {
                    children: [
                        /*#__PURE__*/ (0, $a1dfd$jsx)((0, $da878a05ab4a403e$export$cfc7921d29ef7b80), {
                            isDisabled: isDisabled,
                            isQuiet: true,
                            "aria-label": label,
                            children: /*#__PURE__*/ (0, $a1dfd$jsx)((0, $8b0a29919990739e$export$2e2bcd8739ae039), {})
                        }),
                        /*#__PURE__*/ (0, $a1dfd$jsx)((0, $13afb0ea5f0ed767$export$d9b273488cd8ce6f), {
                            items: items,
                            onAction: onAction,
                            children: (item)=>/*#__PURE__*/ (0, $a1dfd$createElement)((0, $13afb0ea5f0ed767$export$2ce376c2cc3355c8), {
                                    ...item.props.originalProps,
                                    key: item.key
                                }, /*#__PURE__*/ (0, $a1dfd$jsx)((0, $8e847109a6ab556d$export$5f1af8db9871e1d6), {
                                    slot: "label",
                                    children: item.props.children({
                                        size: size,
                                        isCurrent: false,
                                        isMenu: true
                                    })
                                }))
                        })
                    ]
                }),
                /*#__PURE__*/ (0, $a1dfd$jsx)((0, $4b69f02ec06b9226$export$2e2bcd8739ae039), {
                    size: size,
                    className: $f329dd4f2aa58cd0$var$chevronStyles({
                        direction: direction,
                        isMenu: true
                    })
                })
            ]
        })
    });
};
let $f329dd4f2aa58cd0$var$HiddenBreadcrumbs = function(props) {
    let { listRef: listRef, items: items, size: size } = props;
    return /*#__PURE__*/ (0, $a1dfd$jsxs)("div", {
        // @ts-ignore
        inert: (0, $a1dfd$inertValue)(true),
        ref: listRef,
        className: " s40ub4c11 U40ub4c11 q40ub4c11 _w40ub4c11 _Pa11 Wr11 _lr11 _6b11 _Nc11 Pc11 _Ia11",
        children: [
            items.map((item, idx)=>{
                // pull off individual props as an allow list, don't want refs or other props getting through
                return /*#__PURE__*/ (0, $a1dfd$jsx)("div", {
                    "data-hidden-breadcrumb": true,
                    style: item.props.UNSAFE_style,
                    className: item.props.className({
                        size: size,
                        isCurrent: idx === items.length - 1
                    }),
                    children: item.props.children({
                        size: size,
                        isCurrent: idx === items.length - 1
                    })
                }, item.key);
            }),
            /*#__PURE__*/ (0, $a1dfd$jsx)((0, $da878a05ab4a403e$export$cfc7921d29ef7b80), {
                "data-hidden-button": true,
                isQuiet: true,
                children: /*#__PURE__*/ (0, $a1dfd$jsx)((0, $8b0a29919990739e$export$2e2bcd8739ae039), {})
            })
        ]
    });
};
const $f329dd4f2aa58cd0$var$breadcrumbStyles = function anonymous(props) {
    let rules = " ";
    rules += ' sd11';
    rules += ' eb11';
    rules += ' _Cg11';
    if (props.size === "XL") rules += ' Fz11';
    else if (props.size === "L") rules += ' Fv11';
    else if (props.size === "S") rules += ' Fp11';
    else if (props.size === "XS") rules += ' Fn11';
    else rules += ' Fx11';
    rules += ' Yd11';
    rules += ' Xb11';
    rules += ' _2b11';
    rules += ' _Pc11';
    rules += ' _va11';
    if (props.isDisabled) rules += ' pp11';
    else rules += ' pt11';
    if (props.isDisabled) rules += ' plc11';
    else rules += ' plb11';
    rules += ' _je11';
    if (props.isMenu) rules += ' I34mdr11';
    return rules;
};
const $f329dd4f2aa58cd0$var$chevronStyles = function anonymous(props) {
    let rules = " ";
    if (props.direction === "rtl") {
        rules += ' -Z4Pn4c-a11';
        rules += ' __Ha11';
    }
    if (props.direction === "rtl") {
        rules += ' -_04Pn4c-a11';
        rules += ' __Ha11';
    }
    if (props.isMenu) rules += ' Iy11';
    else {
        rules += ' It11';
        rules += ' Isu11';
    }
    rules += ' pt11';
    rules += ' plf11';
    rules += ' -_8sjo0b-t5ZbAob11';
    return rules;
};
const $f329dd4f2aa58cd0$var$linkStyles = function anonymous(props) {
    let rules = " ";
    if (props.isFocusVisible) rules += ' _Lf11';
    else rules += ' _Le11';
    rules += ' Oh11';
    rules += ' Olc11';
    rules += ' _Mc11';
    rules += ' _Kd11';
    rules += ' oa11';
    rules += ' na11';
    rules += ' ka11';
    rules += ' ja11';
    if (props.size === "XL") {
        rules += ' uk11';
        rules += ' ucJ9TBTb11';
        rules += ' ud3Euai11';
        rules += ' uea11';
        rules += ' ugb11';
        rules += ' uhd11';
        rules += ' uje11';
        rules += ' u2NhKxcl11';
        rules += ' uic11';
    } else if (props.size === "L") {
        rules += ' uk11';
        rules += ' ucJ9TBTb11';
        rules += ' ud3Euai11';
        rules += ' uea11';
        rules += ' ugb11';
        rules += ' uhd11';
        rules += ' uje11';
        rules += ' u2NhKxcl11';
        rules += ' uic11';
    } else if (props.size === "S") {
        rules += ' uk11';
        rules += ' ucJ9TBTb11';
        rules += ' ud3Euai11';
        rules += ' uea11';
        rules += ' ugb11';
        rules += ' uhd11';
        rules += ' uje11';
        rules += ' u2NhKxcl11';
        rules += ' uic11';
    } else if (props.size === "XS") {
        rules += ' uk11';
        rules += ' ucJ9TBTb11';
        rules += ' ud3Euai11';
        rules += ' uea11';
        rules += ' ugb11';
        rules += ' uhd11';
        rules += ' uje11';
        rules += ' u2NhKxcl11';
        rules += ' uic11';
    } else {
        rules += ' uk11';
        rules += ' ucJ9TBTb11';
        rules += ' ud3Euai11';
        rules += ' uea11';
        rules += ' ugb11';
        rules += ' uhd11';
        rules += ' uje11';
        rules += ' u2NhKxcl11';
        rules += ' uic11';
    }
    if (props.size === "XL") {
        rules += ' -_6BNtrc-e11';
        rules += ' vx11';
    } else if (props.size === "L") {
        rules += ' -_6BNtrc-d11';
        rules += ' vx11';
    } else if (props.size === "S") {
        rules += ' -_6BNtrc-b11';
        rules += ' vx11';
    } else if (props.size === "XS") {
        rules += ' -_6BNtrc-a11';
        rules += ' vx11';
    } else {
        rules += ' -_6BNtrc-c11';
        rules += ' vx11';
    }
    if (props.size === "XL") {
        rules += ' xb11';
        rules += ' _xa11';
    } else if (props.size === "L") {
        rules += ' xb11';
        rules += ' _xa11';
    } else if (props.size === "S") {
        rules += ' xb11';
        rules += ' _xa11';
    } else if (props.size === "XS") {
        rules += ' xb11';
        rules += ' _xa11';
    } else {
        rules += ' xb11';
        rules += ' _xa11';
    }
    if (props.size === "XL") {
        rules += ' _Fd11';
        rules += ' _FnuYUweb11';
    } else if (props.size === "L") {
        rules += ' _Fd11';
        rules += ' _FnuYUweb11';
    } else if (props.size === "S") {
        rules += ' _Fd11';
        rules += ' _FnuYUweb11';
    } else if (props.size === "XS") {
        rules += ' _Fd11';
        rules += ' _FnuYUweb11';
    } else {
        rules += ' _Fd11';
        rules += ' _FnuYUweb11';
    }
    if (props.isCurrent) {
        if (props.isPressed) rules += ' po11';
        else if (props.isFocusVisible) rules += ' po11';
        else if (props.isHovered) rules += ' po11';
        else rules += ' pt11';
    } else if (props.isDisabled) rules += ' pp11';
    else {
        if (props.isPressed) rules += ' pt11';
        else if (props.isFocusVisible) rules += ' pt11';
        else if (props.isHovered) rules += ' pt11';
        else rules += ' pv11';
    }
    if (props.isCurrent) rules += ' plc11';
    else if (props.isDisabled) rules += ' plc11';
    else rules += ' plf11';
    rules += ' Yd11';
    rules += ' Xb11';
    rules += ' _2b11';
    if (props.isDisabled) rules += ' _Xa11';
    else if (props.isFocusVisible) {
        rules += ' _Xb11';
        rules += ' __Va11';
    } else if (props.isHovered) {
        rules += ' _Xb11';
        rules += ' __Va11';
    } else rules += ' _Xa11';
    if (props.isDisabled) rules += ' ri11';
    else rules += ' ry11';
    rules += ' __ca11';
    return rules;
};
const $f329dd4f2aa58cd0$var$currentStyles = function anonymous(props) {
    let rules = " ";
    if (props.size === "XL") {
        rules += ' uk11';
        rules += ' ucJ9TBTb11';
        rules += ' ud3Euai11';
        rules += ' uea11';
        rules += ' ugb11';
        rules += ' uhd11';
        rules += ' uje11';
        rules += ' u2NhKxcl11';
        rules += ' uic11';
    } else if (props.size === "L") {
        rules += ' uk11';
        rules += ' ucJ9TBTb11';
        rules += ' ud3Euai11';
        rules += ' uea11';
        rules += ' ugb11';
        rules += ' uhd11';
        rules += ' uje11';
        rules += ' u2NhKxcl11';
        rules += ' uic11';
    } else if (props.size === "S") {
        rules += ' uk11';
        rules += ' ucJ9TBTb11';
        rules += ' ud3Euai11';
        rules += ' uea11';
        rules += ' ugb11';
        rules += ' uhd11';
        rules += ' uje11';
        rules += ' u2NhKxcl11';
        rules += ' uic11';
    } else if (props.size === "XS") {
        rules += ' uk11';
        rules += ' ucJ9TBTb11';
        rules += ' ud3Euai11';
        rules += ' uea11';
        rules += ' ugb11';
        rules += ' uhd11';
        rules += ' uje11';
        rules += ' u2NhKxcl11';
        rules += ' uic11';
    } else {
        rules += ' uk11';
        rules += ' ucJ9TBTb11';
        rules += ' ud3Euai11';
        rules += ' uea11';
        rules += ' ugb11';
        rules += ' uhd11';
        rules += ' uje11';
        rules += ' u2NhKxcl11';
        rules += ' uic11';
    }
    if (props.size === "XL") {
        rules += ' -_6BNtrc-e11';
        rules += ' vx11';
    } else if (props.size === "L") {
        rules += ' -_6BNtrc-d11';
        rules += ' vx11';
    } else if (props.size === "S") {
        rules += ' -_6BNtrc-b11';
        rules += ' vx11';
    } else if (props.size === "XS") {
        rules += ' -_6BNtrc-a11';
        rules += ' vx11';
    } else {
        rules += ' -_6BNtrc-c11';
        rules += ' vx11';
    }
    rules += ' xd11';
    rules += ' _xa11';
    rules += ' xX0cczbc11';
    rules += ' _xX0cczba11';
    if (props.size === "XL") {
        rules += ' _Fd11';
        rules += ' _FnuYUweb11';
    } else if (props.size === "L") {
        rules += ' _Fd11';
        rules += ' _FnuYUweb11';
    } else if (props.size === "S") {
        rules += ' _Fd11';
        rules += ' _FnuYUweb11';
    } else if (props.size === "XS") {
        rules += ' _Fd11';
        rules += ' _FnuYUweb11';
    } else {
        rules += ' _Fd11';
        rules += ' _FnuYUweb11';
    }
    rules += ' pt11';
    rules += ' plb11';
    return rules;
};
// TODO: support user heading size customization, for now just set it to large
const $f329dd4f2aa58cd0$var$heading = " Jy11 Gy11 Iy11 Hy11 uk11 ucJ9TBTb11 ud3Euai11 uea11 ugb11 uhd11 uje11 u2NhKxcl11 uic11 -_6BNtrc-h11 vx11 xe11 _xa11 xX0cczbd11 _xX0cczba11 _Fd11 _FnuYUweb11 po11";
const $f329dd4f2aa58cd0$export$dabcc1ec9dd9d1cc = /*#__PURE__*/ (0, $a1dfd$forwardRef)(function Breadcrumb({ children: children, ...props }, ref) {
    let { href: href, target: target, rel: rel, download: download, ping: ping, referrerPolicy: referrerPolicy } = props;
    let { size: size = 'M' } = (0, $a1dfd$useContext)($f329dd4f2aa58cd0$var$InternalBreadcrumbsContext) ?? {};
    let domRef = (0, $a1dfd$useDOMRef)(ref);
    let { direction: direction } = (0, $a1dfd$useLocale)();
    return /*#__PURE__*/ (0, $a1dfd$jsx)((0, $a1dfd$Breadcrumb), {
        ...props,
        ref: domRef,
        // @ts-ignore
        originalProps: props,
        className: ({ isCurrent: isCurrent, isDisabled: isDisabled })=>$f329dd4f2aa58cd0$var$breadcrumbStyles({
                size: size,
                isCurrent: isCurrent,
                isDisabled: isDisabled
            }),
        children: ({ isCurrent: isCurrent, isDisabled: isDisabled, isMenu: // @ts-ignore
        isMenu })=>{
            if (isMenu) return children;
            return isCurrent ? /*#__PURE__*/ (0, $a1dfd$jsx)("div", {
                className: $f329dd4f2aa58cd0$var$currentStyles({
                    size: size
                }),
                children: /*#__PURE__*/ (0, $a1dfd$jsx)((0, $a1dfd$Provider), {
                    values: [
                        [
                            (0, $a1dfd$HeadingContext),
                            {
                                className: $f329dd4f2aa58cd0$var$heading
                            }
                        ]
                    ],
                    children: children
                })
            }) : /*#__PURE__*/ (0, $a1dfd$jsxs)((0, $a1dfd$Fragment), {
                children: [
                    /*#__PURE__*/ (0, $a1dfd$jsx)((0, $a1dfd$Link), {
                        style: ({ isFocusVisible: isFocusVisible })=>({
                                clipPath: isFocusVisible ? 'none' : 'margin-box'
                            }),
                        href: href,
                        target: target,
                        rel: rel,
                        download: download,
                        ping: ping,
                        referrerPolicy: referrerPolicy,
                        isDisabled: isDisabled || isCurrent,
                        className: ({ isFocused: isFocused, isFocusVisible: isFocusVisible, isHovered: isHovered, isDisabled: isDisabled, isPressed: isPressed })=>$f329dd4f2aa58cd0$var$linkStyles({
                                isFocused: isFocused,
                                isFocusVisible: isFocusVisible,
                                isHovered: isHovered,
                                isDisabled: isDisabled,
                                size: size,
                                isPressed: isPressed,
                                isCurrent: isCurrent
                            }),
                        children: children
                    }),
                    /*#__PURE__*/ (0, $a1dfd$jsx)((0, $4b69f02ec06b9226$export$2e2bcd8739ae039), {
                        size: "M",
                        className: $f329dd4f2aa58cd0$var$chevronStyles({
                            direction: direction
                        })
                    })
                ]
            });
        }
    });
});
// Context for passing the count for the custom renderer
let $f329dd4f2aa58cd0$var$CollapseContext = /*#__PURE__*/ (0, $a1dfd$createContext)(null);
function $f329dd4f2aa58cd0$var$CollapsingCollection({ children: children, containerRef: containerRef, onAction: onAction }) {
    return /*#__PURE__*/ (0, $a1dfd$jsx)($f329dd4f2aa58cd0$var$CollapseContext.Provider, {
        value: {
            containerRef: containerRef,
            onAction: onAction
        },
        children: /*#__PURE__*/ (0, $a1dfd$jsx)((0, $a1dfd$CollectionRendererContext).Provider, {
            value: $f329dd4f2aa58cd0$var$CollapsingCollectionRenderer,
            children: children
        })
    });
}
let $f329dd4f2aa58cd0$var$CollapsingCollectionRenderer = {
    CollectionRoot ({ collection: collection }) {
        return $f329dd4f2aa58cd0$var$useCollectionRender(collection);
    },
    CollectionBranch ({ collection: collection }) {
        return $f329dd4f2aa58cd0$var$useCollectionRender(collection);
    }
};
let $f329dd4f2aa58cd0$var$useCollectionRender = (collection)=>{
    let { containerRef: containerRef, onAction: onAction } = (0, $a1dfd$useContext)($f329dd4f2aa58cd0$var$CollapseContext) ?? {};
    let [visibleItems, setVisibleItems] = (0, $a1dfd$useState)(collection.size);
    let { size: size = 'M' } = (0, $a1dfd$useContext)($f329dd4f2aa58cd0$var$InternalBreadcrumbsContext);
    let children = (0, $a1dfd$useMemo)(()=>{
        let result = [];
        for (let key of collection.getKeys())result.push(collection.getItem(key));
        return result;
    }, [
        collection
    ]);
    let listRef = (0, $a1dfd$useRef)(null);
    let updateOverflow = (0, $a1dfd$useCallback)(()=>{
        let currListRef = listRef.current;
        if (!currListRef) {
            setVisibleItems(collection.size);
            return;
        }
        let container = currListRef.parentElement;
        if (!container) {
            setVisibleItems(collection.size);
            return;
        }
        let listItems = Array.from(currListRef.querySelectorAll('[data-hidden-breadcrumb]'));
        let folder = currListRef.querySelector('button');
        if (listItems.length <= 0) {
            setVisibleItems(collection.size);
            return;
        }
        let containerWidth = container.offsetWidth;
        let containerGap = parseInt(getComputedStyle(container).gap, 10);
        let folderGap = parseInt(getComputedStyle(folder).marginInlineStart, 10);
        let newVisibleItems = 0;
        let maxVisibleItems = $f329dd4f2aa58cd0$var$MAX_VISIBLE_ITEMS;
        let widths = [];
        let totalWidth = 0;
        for (let breadcrumb of listItems){
            let width = breadcrumb.offsetWidth + 1; // offsetWidth is rounded down
            widths.push(width);
            totalWidth += width;
        }
        // can we fit all the items without collapsing
        if (totalWidth <= containerWidth - collection.size * containerGap && collection.size <= $f329dd4f2aa58cd0$var$MAX_VISIBLE_ITEMS) {
            setVisibleItems(collection.size);
            return;
        }
        // we know there is always at least one item because of the listItems.length check up above
        let widthOfFirst = widths.shift();
        let availableWidth = containerWidth - widthOfFirst - folderGap - folder.offsetWidth - containerGap;
        maxVisibleItems -= 2; // account for the first item and folder
        for (let width of widths.reverse()){
            availableWidth -= width;
            if (availableWidth <= 0) break;
            availableWidth -= containerGap;
            newVisibleItems++;
        }
        setVisibleItems(Math.max($f329dd4f2aa58cd0$var$MIN_VISIBLE_ITEMS, Math.min(maxVisibleItems, newVisibleItems)));
    }, [
        collection.size,
        setVisibleItems
    ]);
    // making bad assumption that i can listen to containerRef when it's declared in the parent?
    (0, $a1dfd$useResizeObserver)({
        ref: containerRef,
        onResize: updateOverflow
    });
    (0, $a1dfd$useLayoutEffect)(()=>{
        if (collection.size > 0) queueMicrotask(updateOverflow);
    }, [
        collection.size,
        updateOverflow
    ]);
    (0, $a1dfd$useEffect)(()=>{
        // Recalculate visible tags when fonts are loaded.
        document.fonts?.ready.then(()=>updateOverflow());
    // eslint-disable-next-line react-hooks/exhaustive-deps
    }, []);
    let sliceIndex = collection.size - visibleItems;
    return /*#__PURE__*/ (0, $a1dfd$jsxs)((0, $a1dfd$Fragment), {
        children: [
            /*#__PURE__*/ (0, $a1dfd$jsx)($f329dd4f2aa58cd0$var$HiddenBreadcrumbs, {
                items: children,
                size: size,
                listRef: listRef
            }),
            visibleItems < collection.size && collection.size > 2 ? /*#__PURE__*/ (0, $a1dfd$jsxs)((0, $a1dfd$Fragment), {
                children: [
                    children[0].render?.(children[0]),
                    /*#__PURE__*/ (0, $a1dfd$jsx)($f329dd4f2aa58cd0$var$BreadcrumbMenu, {
                        items: children.slice(1, sliceIndex),
                        onAction: onAction
                    }),
                    children.slice(sliceIndex).map((node)=>/*#__PURE__*/ (0, $a1dfd$jsx)((0, $a1dfd$Fragment1), {
                            children: node.render?.(node)
                        }, node.key))
                ]
            }) : /*#__PURE__*/ (0, $a1dfd$jsx)((0, $a1dfd$Fragment), {
                children: children.map((node)=>/*#__PURE__*/ (0, $a1dfd$jsx)((0, $a1dfd$Fragment1), {
                        children: node.render?.(node)
                    }, node.key))
            })
        ]
    });
};


export {$f329dd4f2aa58cd0$export$65596d3621b0a4a0 as BreadcrumbsContext, $f329dd4f2aa58cd0$export$2dc68d50d56fbbd as Breadcrumbs, $f329dd4f2aa58cd0$export$dabcc1ec9dd9d1cc as Breadcrumb};
//# sourceMappingURL=Breadcrumbs.mjs.map
