import "./TreeView.css";
import {ActionButtonGroupContext as $10401bdc118cbc90$export$33f5f2f2cb85d743} from "./ActionButtonGroup.mjs";
import {ActionMenuContext as $8bf3cd2442eb485e$export$7f4b66acaca28bd5} from "./ActionMenu.mjs";
import {centerBaseline as $1f4b04be3f24aae3$export$9d7e2342a7e53afa} from "./CenterBaseline.mjs";
import {Checkbox as $9b405e0f8095dce0$export$48513f6b9f8ce62d} from "./Checkbox.mjs";
import $4b69f02ec06b9226$export$2e2bcd8739ae039 from "./Chevron.mjs";
import {IconContext as $ac8c32e6775ddd1f$export$a49f528ae1a4d0ed} from "../icons/Icon.mjs";
import $iOVFT$intlStringsmjs from "./intlStrings.mjs";
import {ProgressCircle as $41ddd91dbbf0c389$export$c79b9d6b4cc92af7} from "./ProgressCircle.mjs";
import {Text as $8e847109a6ab556d$export$5f1af8db9871e1d6, TextContext as $8e847109a6ab556d$export$9afb8bc826b033ea} from "./Content.mjs";
import {useActionBarContainer as $f21f2186348fbc5b$export$13f32e21845e01d0} from "./ActionBar.mjs";
import {useScale as $859432f3b3573fcb$export$a8d2043b2d807f4d} from "./utils.mjs";
import {jsx as $iOVFT$jsx, jsxs as $iOVFT$jsxs} from "react/jsx-runtime";
import {Virtualizer as $iOVFT$Virtualizer, ListLayout as $iOVFT$ListLayout, Tree as $iOVFT$Tree, TreeItem as $iOVFT$TreeItem, TreeItemContent as $iOVFT$TreeItemContent, Provider as $iOVFT$Provider, TreeLoadMoreItem as $iOVFT$TreeLoadMoreItem, useContextProps as $iOVFT$useContextProps, ButtonContext as $iOVFT$ButtonContext, Button as $iOVFT$Button} from "react-aria-components";
import {createContext as $iOVFT$createContext, forwardRef as $iOVFT$forwardRef, useRef as $iOVFT$useRef} from "react";
import {useDOMRef as $iOVFT$useDOMRef} from "@react-spectrum/utils";
import {useLocalizedStringFormatter as $iOVFT$useLocalizedStringFormatter, useLocale as $iOVFT$useLocale} from "react-aria";


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 $03960a2740ca2b19$var$TreeRendererContext = /*#__PURE__*/ (0, $iOVFT$createContext)({});
const $03960a2740ca2b19$var$treeViewWrapper = function anonymous(props, overrides) {
    let rules = " ";
    let minHeight = false;
    let minWidth = false;
    let position = 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|F|M|K)[^\s]+/g);
    for (let p of matches){
        if (p[1] === "M") minHeight = true;
        if (p[1] === "N") minWidth = true;
        if (p[1] === "_P") position = true;
        rules += p[0];
    }
    if (!minHeight) rules += ' Ma11';
    if (!minWidth) rules += ' Na11';
    rules += ' sd11';
    rules += ' _Bb11';
    rules += ' __ca11';
    if (!position) rules += ' _Pc11';
    rules += ' _Nb11';
    rules += ' Pb11';
    return rules;
};
// TODO: the below is needed so the borders of the top and bottom row isn't cut off if the TreeView is wrapped within a container by always reserving the 2px needed for the
// keyboard focus ring. Perhaps find a different way of rendering the outlines since the top of the item doesn't
// scroll into view due to how the ring is offset. Alternatively, have the tree render the top/bottom outline like it does in Listview
const $03960a2740ca2b19$var$tree = function anonymous(props) {
    let rules = " ";
    if (props.isFocusVisible) rules += ' _Lf11';
    else rules += ' _Le11';
    rules += ' Oh11';
    rules += ' Olc11';
    rules += ' _Mc11';
    rules += ' _Kb11';
    rules += ' _4c11';
    rules += ' Ma11';
    rules += ' Na11';
    rules += ' Za11';
    rules += ' Fb11';
    rules += ' _Na11';
    rules += ' Pa11';
    rules += ' _oa11';
    if (props.isEmpty) rules += ' _Ca11';
    if (props.isEmpty) rules += ' eb11';
    rules += ' -lPUMEc-Zu11';
    return rules;
};
const $03960a2740ca2b19$export$6940b0d9c820eca7 = /*#__PURE__*/ (0, $iOVFT$forwardRef)(function TreeView(props, ref) {
    let { children: children, UNSAFE_className: UNSAFE_className, UNSAFE_style: UNSAFE_style } = props;
    let scale = (0, $859432f3b3573fcb$export$a8d2043b2d807f4d)();
    let renderer;
    if (typeof children === 'function') renderer = children;
    let domRef = (0, $iOVFT$useDOMRef)(ref);
    let scrollRef = (0, $iOVFT$useRef)(null);
    let { selectedKeys: selectedKeys, onSelectionChange: onSelectionChange, actionBar: actionBar, actionBarHeight: actionBarHeight } = (0, $f21f2186348fbc5b$export$13f32e21845e01d0)({
        ...props,
        scrollRef: scrollRef
    });
    let treeContent = /*#__PURE__*/ (0, $iOVFT$jsx)((0, $iOVFT$Virtualizer), {
        layout: (0, $iOVFT$ListLayout),
        layoutOptions: {
            rowHeight: scale === 'large' ? 50 : 40
        },
        children: /*#__PURE__*/ (0, $iOVFT$jsx)($03960a2740ca2b19$var$TreeRendererContext.Provider, {
            value: {
                renderer: renderer
            },
            children: /*#__PURE__*/ (0, $iOVFT$jsx)((0, $iOVFT$Tree), {
                ...props,
                style: {
                    ...!props.renderActionBar ? UNSAFE_style : {},
                    paddingBottom: actionBarHeight > 0 ? actionBarHeight + 8 : 0,
                    scrollPaddingBottom: actionBarHeight > 0 ? actionBarHeight + 8 : 0
                },
                className: (renderProps)=>(!props.renderActionBar ? UNSAFE_className ?? '' : '') + $03960a2740ca2b19$var$tree({
                        ...renderProps
                    }),
                selectionBehavior: "toggle",
                selectedKeys: selectedKeys,
                defaultSelectedKeys: undefined,
                onSelectionChange: onSelectionChange,
                ref: props.renderActionBar ? scrollRef : domRef,
                children: props.children
            })
        })
    });
    if (props.renderActionBar) return /*#__PURE__*/ (0, $iOVFT$jsxs)("div", {
        ref: domRef,
        className: (UNSAFE_className ?? '') + $03960a2740ca2b19$var$treeViewWrapper(null, props.styles),
        style: UNSAFE_style,
        children: [
            treeContent,
            actionBar
        ]
    });
    return treeContent;
});
const $03960a2740ca2b19$var$rowBackgroundColor = {
    default: '--s2-container-bg',
    isFocusVisibleWithin: "[color-mix(in srgb, light-dark(rgb(255, 255, 255), rgb(17, 17, 17)), light-dark(rgb(19, 19, 19), rgb(242, 242, 242)) 7%)]",
    isHovered: "[color-mix(in srgb, light-dark(rgb(255, 255, 255), rgb(17, 17, 17)), light-dark(rgb(19, 19, 19), rgb(242, 242, 242)) 7%)]",
    isPressed: "[color-mix(in srgb, light-dark(rgb(255, 255, 255), rgb(17, 17, 17)), light-dark(rgb(19, 19, 19), rgb(242, 242, 242)) 10%)]",
    isSelected: {
        default: "[color-mix(in srgb, light-dark(rgb(255, 255, 255), rgb(17, 17, 17)), light-dark(rgb(19, 19, 19), rgb(242, 242, 242)) 7%)]",
        isFocusVisibleWithin: "[color-mix(in srgb, light-dark(rgb(255, 255, 255), rgb(17, 17, 17)), light-dark(rgb(19, 19, 19), rgb(242, 242, 242)) 10%)]",
        isHovered: "[color-mix(in srgb, light-dark(rgb(255, 255, 255), rgb(17, 17, 17)), light-dark(rgb(19, 19, 19), rgb(242, 242, 242)) 10%)]",
        isPressed: "[color-mix(in srgb, light-dark(rgb(255, 255, 255), rgb(17, 17, 17)), light-dark(rgb(19, 19, 19), rgb(242, 242, 242)) 10%)]"
    },
    forcedColors: {
        default: 'Background'
    }
};
const $03960a2740ca2b19$var$treeRow = function anonymous(props) {
    let rules = " ";
    rules += ' _Pc11';
    rules += ' sd11';
    rules += ' Fv11';
    rules += ' Za11';
    rules += ' _oa11';
    rules += ' uk11';
    rules += ' ucJ9TBTb11';
    rules += ' ud3Euai11';
    rules += ' uea11';
    rules += ' ugb11';
    rules += ' uhd11';
    rules += ' uje11';
    rules += ' u2NhKxcl11';
    rules += ' uic11';
    rules += ' -_6BNtrc-c11';
    rules += ' vx11';
    rules += ' xb11';
    rules += ' _xa11';
    rules += ' _Fd11';
    rules += ' _FnuYUweb11';
    if (props.isSelected) {
        if (props.isPressed) rules += ' po11';
        else if (props.isFocusVisible) rules += ' po11';
        else if (props.isHovered) rules += ' po11';
        else rules += ' pt11';
    } else {
        if (props.isPressed) rules += ' pt11';
        else if (props.isFocusVisible) rules += ' pt11';
        else if (props.isHovered) rules += ' pt11';
        else rules += ' pv11';
    }
    rules += ' plb11';
    rules += ' _Le11';
    if (props.isLink) rules += ' ry11';
    else rules += ' ri11';
    if (props.isSelected) {
        if (props.isPressed) rules += ' -qH4xad-gRfT7e11';
        else if (props.isHovered) rules += ' -qH4xad-gRfT7e11';
        else if (props.isFocusVisibleWithin) rules += ' -qH4xad-gRfT7e11';
        else rules += ' -qH4xad-gj1B7i11';
    } else if (props.isPressed) rules += ' -qH4xad-gRfT7e11';
    else if (props.isHovered) rules += ' -qH4xad-gj1B7i11';
    else if (props.isFocusVisibleWithin) rules += ' -qH4xad-gj1B7i11';
    else rules += ' -qH4xad-gEzkoQe11';
    rules += ' -qH4xad-lga11';
    rules += ' -_34HbNb-Oh11';
    rules += ' -_34HbNb-lOc11';
    return rules;
};
const $03960a2740ca2b19$var$treeCellGrid = function anonymous(props) {
    let rules = " ";
    rules += ' se11';
    rules += ' Za11';
    rules += ' Fb11';
    rules += ' _oa11';
    rules += ' _cb11';
    rules += ' eb11';
    rules += ' Dw9uTxc11';
    rules += ' EM8Mfn11';
    rules += ' CgjMZ2c11';
    rules += ' gs9yXOb11';
    rules += ' Rp11';
    if (props.isDisabled) {
        rules += ' pp11';
        rules += ' plc11';
    }
    if (props.isFocusVisible) rules += ' -_7xg3bb-Oh11';
    else rules += ' -_7xg3bb-O8Izf8c11';
    rules += ' -_7xg3bb-lOc11';
    rules += ' -pKMv1c-Oh11';
    rules += ' -pKMv1c-lOc11';
    return rules;
};
const $03960a2740ca2b19$var$treeCheckbox = function anonymous(props) {
    let rules = " ";
    rules += ' zoRzcu11';
    rules += ' yoRzcu11';
    rules += ' BoRzcu11';
    rules += ' AoRzcu11';
    rules += ' Ix11';
    rules += ' Hy11';
    rules += ' Rd11';
    if (props.isDisabled) rules += ' _6b11';
    else rules += ' _6c11';
    return rules;
};
const $03960a2740ca2b19$var$treeIcon = " z2U5Crc11 y2U5Crc11 B2U5Crc11 A2U5Crc11 Ht11 Hsu11 -_8sjo0b-t5ZbAob11";
const $03960a2740ca2b19$var$treeContent = " zk52g2d11 yk52g2d11 Bk52g2d11 Ak52g2d11 _Yb11 _7c11 _Nc11 Pc11";
const $03960a2740ca2b19$var$treeActions = " zkG38H11 ykG38H11 BkG38H11 AkG38H11 Ir11 Hs11";
const $03960a2740ca2b19$var$treeActionMenu = " z6Nrfjc11 y6Nrfjc11 B6Nrfjc11 A6Nrfjc11";
const $03960a2740ca2b19$var$treeRowFocusIndicator = "tDhuzb";
const $03960a2740ca2b19$export$6e77ea6719814e9c = (props)=>{
    let { href: href } = props;
    return /*#__PURE__*/ (0, $iOVFT$jsx)((0, $iOVFT$TreeItem), {
        ...props,
        className: (renderProps)=>$03960a2740ca2b19$var$treeRow({
                ...renderProps,
                isLink: !!href
            }) + (renderProps.isFocusVisible ? ' ' + $03960a2740ca2b19$var$treeRowFocusIndicator : '')
    });
};
const $03960a2740ca2b19$export$9a5779ed3fade674 = (props)=>{
    let { children: children } = props;
    let scale = (0, $859432f3b3573fcb$export$a8d2043b2d807f4d)();
    return /*#__PURE__*/ (0, $iOVFT$jsx)((0, $iOVFT$TreeItemContent), {
        children: ({ isExpanded: isExpanded, hasChildItems: hasChildItems, selectionMode: selectionMode, selectionBehavior: selectionBehavior, isDisabled: isDisabled, isSelected: isSelected, id: id, state: state })=>{
            let isNextSelected = false;
            let isNextFocused = false;
            let keyAfter = state.collection.getKeyAfter(id);
            if (keyAfter != null) isNextSelected = state.selectionManager.isSelected(keyAfter);
            let isFirst = state.collection.getFirstKey() === id;
            return /*#__PURE__*/ (0, $iOVFT$jsxs)("div", {
                className: $03960a2740ca2b19$var$treeCellGrid({
                    isDisabled: isDisabled,
                    isNextSelected: isNextSelected,
                    isSelected: isSelected,
                    isFirst: isFirst,
                    isNextFocused: isNextFocused
                }),
                children: [
                    selectionMode !== 'none' && selectionBehavior === 'toggle' && // TODO: add transition?
                    /*#__PURE__*/ (0, $iOVFT$jsx)("div", {
                        className: $03960a2740ca2b19$var$treeCheckbox({
                            isDisabled: isDisabled || !state.selectionManager.canSelectItem(id) || state.disabledKeys.has(id)
                        }),
                        children: /*#__PURE__*/ (0, $iOVFT$jsx)((0, $9b405e0f8095dce0$export$48513f6b9f8ce62d), {
                            slot: "selection"
                        })
                    }),
                    /*#__PURE__*/ (0, $iOVFT$jsx)("div", {
                        className: " z7fSmKc11 y7fSmKc11 B7fSmKc11 A7fSmKc11 ZecPNad11"
                    }),
                    /*#__PURE__*/ (0, $iOVFT$jsx)($03960a2740ca2b19$var$ExpandableRowChevron, {
                        isDisabled: isDisabled,
                        isExpanded: isExpanded,
                        scale: scale,
                        isHidden: !hasChildItems
                    }),
                    /*#__PURE__*/ (0, $iOVFT$jsx)((0, $iOVFT$Provider), {
                        values: [
                            [
                                (0, $8e847109a6ab556d$export$9afb8bc826b033ea),
                                {
                                    styles: $03960a2740ca2b19$var$treeContent
                                }
                            ],
                            [
                                (0, $ac8c32e6775ddd1f$export$a49f528ae1a4d0ed),
                                {
                                    render: (0, $1f4b04be3f24aae3$export$9d7e2342a7e53afa)({
                                        slot: 'icon',
                                        styles: $03960a2740ca2b19$var$treeIcon
                                    }),
                                    styles: " ZuUmpre11 FuUmpre11 _va11"
                                }
                            ],
                            [
                                (0, $10401bdc118cbc90$export$33f5f2f2cb85d743),
                                {
                                    styles: $03960a2740ca2b19$var$treeActions,
                                    isDisabled: isDisabled
                                }
                            ],
                            [
                                (0, $8bf3cd2442eb485e$export$7f4b66acaca28bd5),
                                {
                                    styles: $03960a2740ca2b19$var$treeActionMenu,
                                    isQuiet: true,
                                    isDisabled: isDisabled
                                }
                            ]
                        ],
                        children: typeof children === 'string' ? /*#__PURE__*/ (0, $iOVFT$jsx)((0, $8e847109a6ab556d$export$5f1af8db9871e1d6), {
                            children: children
                        }) : children
                    })
                ]
            });
        }
    });
};
const $03960a2740ca2b19$var$centeredWrapper = " sd11 eb11 _Ca11 Za11 Fb11";
const $03960a2740ca2b19$export$6ceebe2a029205c = (props)=>{
    let { loadingState: loadingState, onLoadMore: onLoadMore } = props;
    let stringFormatter = (0, $iOVFT$useLocalizedStringFormatter)((0, ($parcel$interopDefault($iOVFT$intlStringsmjs))), '@react-spectrum/s2');
    let isLoading = loadingState === 'loading' || loadingState === 'loadingMore';
    return /*#__PURE__*/ (0, $iOVFT$jsx)((0, $iOVFT$TreeLoadMoreItem), {
        isLoading: isLoading,
        onLoadMore: onLoadMore,
        className: " Za11 Js11 Gs11",
        children: ()=>{
            return /*#__PURE__*/ (0, $iOVFT$jsx)("div", {
                className: $03960a2740ca2b19$var$centeredWrapper,
                children: /*#__PURE__*/ (0, $iOVFT$jsx)((0, $41ddd91dbbf0c389$export$c79b9d6b4cc92af7), {
                    isIndeterminate: true,
                    "aria-label": stringFormatter.format('table.loadingMore')
                })
            });
        }
    });
};
const $03960a2740ca2b19$var$expandButton = function anonymous(props) {
    let rules = " ";
    rules += ' z8dW5Qb11';
    rules += ' y8dW5Qb11';
    rules += ' B8dW5Qb11';
    rules += ' A8dW5Qb11';
    if (props.isDisabled) {
        rules += ' pp11';
        rules += ' plc11';
    } else rules += ' p40ub4c11';
    rules += ' Fv11';
    rules += ' Zw11';
    rules += ' sd11';
    rules += ' _wb11';
    rules += ' _cb11';
    rules += ' _Ca11';
    rules += ' _Le11';
    rules += ' ri11';
    if (props.isExpanded) {
        if (props.isRTL) rules += ' _Za11';
        else rules += ' _Zb11';
    }
    rules += ' Td11';
    rules += ' Qd11';
    rules += ' Sd11';
    rules += ' Rd11';
    rules += ' Yd11';
    rules += ' Xb11';
    rules += ' _2b11';
    rules += ' g911';
    rules += ' _je11';
    rules += ' __ca11';
    if (props.isHidden) rules += ' _6b11';
    return rules;
};
function $03960a2740ca2b19$var$ExpandableRowChevron(props1) {
    let expandButtonRef = (0, $iOVFT$useRef)(null);
    let [fullProps, ref] = (0, $iOVFT$useContextProps)({
        ...props1,
        slot: 'chevron'
    }, expandButtonRef, (0, $iOVFT$ButtonContext));
    let { isExpanded: isExpanded, scale: scale, isHidden: isHidden } = fullProps;
    let { direction: direction } = (0, $iOVFT$useLocale)();
    return /*#__PURE__*/ (0, $iOVFT$jsx)((0, $iOVFT$Button), {
        ...props1,
        ref: ref,
        slot: "chevron",
        className: (renderProps)=>$03960a2740ca2b19$var$expandButton({
                ...renderProps,
                isExpanded: isExpanded,
                isRTL: direction === 'rtl',
                scale: scale,
                isHidden: isHidden
            }),
        children: /*#__PURE__*/ (0, $iOVFT$jsx)((0, $4b69f02ec06b9226$export$2e2bcd8739ae039), {
            className: function anonymous(props) {
                let rules = " ";
                if (props.direction === "rtl") {
                    rules += ' -Z4Pn4c-a11';
                    rules += ' __Ha11';
                } else if (props.direction === "ltr") {
                    rules += ' -Z4Pn4c-b11';
                    rules += ' __Ha11';
                }
                if (props.direction === "rtl") {
                    rules += ' -_04Pn4c-a11';
                    rules += ' __Ha11';
                } else if (props.direction === "ltr") {
                    rules += ' -_04Pn4c-b11';
                    rules += ' __Ha11';
                }
                rules += ' -_8sjo0b-t5ZbAob11';
                return rules;
            }({
                direction: direction
            })
        })
    });
}


export {$03960a2740ca2b19$export$6940b0d9c820eca7 as TreeView, $03960a2740ca2b19$export$6e77ea6719814e9c as TreeViewItem, $03960a2740ca2b19$export$9a5779ed3fade674 as TreeViewItemContent, $03960a2740ca2b19$export$6ceebe2a029205c as TreeViewLoadMoreItem};
//# sourceMappingURL=TreeView.mjs.map
