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 += ' Ma12';
    if (!minWidth) rules += ' Na12';
    rules += ' sd12';
    rules += ' _Bb12';
    rules += ' __ca12';
    if (!position) rules += ' _Pc12';
    rules += ' _Nb12';
    rules += ' Pb12';
    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 += ' _Lf12';
    else rules += ' _Le12';
    rules += ' Oh12';
    rules += ' Olc12';
    rules += ' _Mc12';
    rules += ' _Kb12';
    rules += ' _4c12';
    rules += ' Ma12';
    rules += ' Na12';
    rules += ' Za12';
    rules += ' Fb12';
    rules += ' _Na12';
    rules += ' Pa12';
    rules += ' _oa12';
    if (props.isEmpty) rules += ' _Ca12';
    if (props.isEmpty) rules += ' eb12';
    rules += ' -lPUMEc-Zu12';
    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 += ' _Pc12';
    rules += ' sd12';
    rules += ' Fv12';
    rules += ' Za12';
    rules += ' _oa12';
    rules += ' uk12';
    rules += ' ucJ9TBTb12';
    rules += ' ud3Euai12';
    rules += ' uea12';
    rules += ' ugb12';
    rules += ' uhd12';
    rules += ' uje12';
    rules += ' u2NhKxcl12';
    rules += ' uic12';
    rules += ' -_6BNtrc-c12';
    rules += ' vx12';
    rules += ' xb12';
    rules += ' _xa12';
    rules += ' _Fd12';
    rules += ' _FnuYUweb12';
    if (props.isSelected) {
        if (props.isPressed) rules += ' po12';
        else if (props.isFocusVisible) rules += ' po12';
        else if (props.isHovered) rules += ' po12';
        else rules += ' pt12';
    } else {
        if (props.isPressed) rules += ' pt12';
        else if (props.isFocusVisible) rules += ' pt12';
        else if (props.isHovered) rules += ' pt12';
        else rules += ' pv12';
    }
    rules += ' plb12';
    rules += ' _Le12';
    if (props.isLink) rules += ' ry12';
    else rules += ' ri12';
    if (props.isSelected) {
        if (props.isPressed) rules += ' -qH4xad-gRfT7e12';
        else if (props.isHovered) rules += ' -qH4xad-gRfT7e12';
        else if (props.isFocusVisibleWithin) rules += ' -qH4xad-gRfT7e12';
        else rules += ' -qH4xad-gj1B7i12';
    } else if (props.isPressed) rules += ' -qH4xad-gRfT7e12';
    else if (props.isHovered) rules += ' -qH4xad-gj1B7i12';
    else if (props.isFocusVisibleWithin) rules += ' -qH4xad-gj1B7i12';
    else rules += ' -qH4xad-gEzkoQe12';
    rules += ' -qH4xad-lga12';
    rules += ' -_34HbNb-Oh12';
    rules += ' -_34HbNb-lOc12';
    return rules;
};
const $03960a2740ca2b19$var$treeCellGrid = function anonymous(props) {
    let rules = " ";
    rules += ' se12';
    rules += ' Za12';
    rules += ' Fb12';
    rules += ' _oa12';
    rules += ' _cb12';
    rules += ' eb12';
    rules += ' Dw9uTxc12';
    rules += ' EM8Mfn12';
    rules += ' CgjMZ2c12';
    rules += ' gs9yXOb12';
    rules += ' Rp12';
    if (props.isDisabled) {
        rules += ' pp12';
        rules += ' plc12';
    }
    if (props.isFocusVisible) rules += ' -_7xg3bb-Oh12';
    else rules += ' -_7xg3bb-O8Izf8c12';
    rules += ' -_7xg3bb-lOc12';
    rules += ' -pKMv1c-Oh12';
    rules += ' -pKMv1c-lOc12';
    return rules;
};
const $03960a2740ca2b19$var$treeCheckbox = function anonymous(props) {
    let rules = " ";
    rules += ' zoRzcu12';
    rules += ' yoRzcu12';
    rules += ' BoRzcu12';
    rules += ' AoRzcu12';
    rules += ' Ix12';
    rules += ' Hy12';
    rules += ' Rd12';
    if (props.isDisabled) rules += ' _6b12';
    else rules += ' _6c12';
    return rules;
};
const $03960a2740ca2b19$var$treeIcon = " z2U5Crc12 y2U5Crc12 B2U5Crc12 A2U5Crc12 Ht12 Hsu12 -_8sjo0b-t5ZbAob12";
const $03960a2740ca2b19$var$treeContent = " zk52g2d12 yk52g2d12 Bk52g2d12 Ak52g2d12 _Yb12 _7c12 _Nc12 Pc12";
const $03960a2740ca2b19$var$treeActions = " zkG38H12 ykG38H12 BkG38H12 AkG38H12 Ir12 Hs12";
const $03960a2740ca2b19$var$treeActionMenu = " z6Nrfjc12 y6Nrfjc12 B6Nrfjc12 A6Nrfjc12";
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: " z7fSmKc12 y7fSmKc12 B7fSmKc12 A7fSmKc12 ZecPNad12"
                    }),
                    /*#__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: " ZuUmpre12 FuUmpre12 _va12"
                                }
                            ],
                            [
                                (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 = " sd12 eb12 _Ca12 Za12 Fb12";
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: " Za12 Js12 Gs12",
        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 += ' z8dW5Qb12';
    rules += ' y8dW5Qb12';
    rules += ' B8dW5Qb12';
    rules += ' A8dW5Qb12';
    if (props.isDisabled) {
        rules += ' pp12';
        rules += ' plc12';
    } else rules += ' p40ub4c12';
    rules += ' Fv12';
    rules += ' Zw12';
    rules += ' sd12';
    rules += ' _wb12';
    rules += ' _cb12';
    rules += ' _Ca12';
    rules += ' _Le12';
    rules += ' ri12';
    if (props.isExpanded) {
        if (props.isRTL) rules += ' _Za12';
        else rules += ' _Zb12';
    }
    rules += ' Td12';
    rules += ' Qd12';
    rules += ' Sd12';
    rules += ' Rd12';
    rules += ' Yd12';
    rules += ' Xb12';
    rules += ' _2b12';
    rules += ' g912';
    rules += ' _je12';
    rules += ' __ca12';
    if (props.isHidden) rules += ' _6b12';
    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-a12';
                    rules += ' __Ha12';
                } else if (props.direction === "ltr") {
                    rules += ' -Z4Pn4c-b12';
                    rules += ' __Ha12';
                }
                if (props.direction === "rtl") {
                    rules += ' -_04Pn4c-a12';
                    rules += ' __Ha12';
                } else if (props.direction === "ltr") {
                    rules += ' -_04Pn4c-b12';
                    rules += ' __Ha12';
                }
                rules += ' -_8sjo0b-t5ZbAob12';
                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
