import {ButtonContext as $fc203795b9b363cd$export$24d547caef80ccd1} from "./Button.js";
import {dom as $b7b7a92703138c9b$export$df3a06d6289f983e, Provider as $b7b7a92703138c9b$export$2881499e37b75b9a, useContextProps as $b7b7a92703138c9b$export$29f1550f4b0d4415, useRenderProps as $b7b7a92703138c9b$export$4d86445c2cf5e3, useSlot as $b7b7a92703138c9b$export$9d4c57ee4c6ffdd8} from "./utils.js";
import {CollectionRendererContext as $a53f0f6636929daa$export$4feb769f8ddf26c5, DefaultCollectionRenderer as $a53f0f6636929daa$export$a164736487e3f0ae, usePersistedKeys as $a53f0f6636929daa$export$90e00781bc59d8f9} from "./Collection.js";
import {LabelContext as $3e4839e5b30e7b17$export$75b6ee27786ba447} from "./Label.js";
import {ListStateContext as $ba3142315b3e1149$export$7c5906fe4f1f2af2} from "./ListBox.js";
import {SelectableCollectionContext as $8f09b710ef85b337$export$b0d3ecf7112093a7} from "./Autocomplete.js";
import {SelectionIndicatorContext as $0d6f83ad40839938$export$c9549807523555e0} from "./SelectionIndicator.js";
import {SharedElementTransition as $347bc273c4058e94$export$758399f318e6385a} from "./SharedElementTransition.js";
import {TextContext as $20d769b1e2b13352$export$9afb8bc826b033ea} from "./Text.js";
import {useTagGroup as $7VBu2$useTagGroup, useTag as $7VBu2$useTag} from "react-aria/useTagGroup";
import {CollectionBuilder as $7VBu2$CollectionBuilder, Collection as $7VBu2$Collection, createLeafComponent as $7VBu2$createLeafComponent} from "react-aria/private/collections/CollectionBuilder";
import {filterDOMProps as $7VBu2$filterDOMProps} from "react-aria/private/utils/filterDOMProps";
import {ItemNode as $7VBu2$ItemNode} from "react-aria/private/collections/BaseCollection";
import {useListState as $7VBu2$useListState, UNSTABLE_useFilteredListState as $7VBu2$UNSTABLE_useFilteredListState} from "react-stately/useListState";
import {mergeProps as $7VBu2$mergeProps} from "react-aria/mergeProps";
import $7VBu2$react, {createContext as $7VBu2$createContext, forwardRef as $7VBu2$forwardRef, useRef as $7VBu2$useRef, useContext as $7VBu2$useContext, useEffect as $7VBu2$useEffect} from "react";
import {useFocusRing as $7VBu2$useFocusRing} from "react-aria/useFocusRing";
import {useHover as $7VBu2$useHover} from "react-aria/useHover";
import {useObjectRef as $7VBu2$useObjectRef} from "react-aria/useObjectRef";

/*
 * Copyright 2022 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 $ada7ba7890ac1d93$export$5b07b5dd2cbd96e3 = /*#__PURE__*/ (0, $7VBu2$createContext)(null);
const $ada7ba7890ac1d93$export$e755ce3685dd0ca9 = /*#__PURE__*/ (0, $7VBu2$createContext)(null);
const $ada7ba7890ac1d93$export$67ea30858aaf75e3 = /*#__PURE__*/ (0, $7VBu2$forwardRef)(function TagGroup(props, ref) {
    [props, ref] = (0, $b7b7a92703138c9b$export$29f1550f4b0d4415)(props, ref, $ada7ba7890ac1d93$export$5b07b5dd2cbd96e3);
    return /*#__PURE__*/ (0, $7VBu2$react).createElement((0, $ba3142315b3e1149$export$7c5906fe4f1f2af2).Provider, {
        value: null
    }, /*#__PURE__*/ (0, $7VBu2$react).createElement((0, $7VBu2$CollectionBuilder), {
        content: props.children
    }, (collection)=>/*#__PURE__*/ (0, $7VBu2$react).createElement($ada7ba7890ac1d93$var$TagGroupInner, {
            props: props,
            forwardedRef: ref,
            collection: collection
        })));
});
function $ada7ba7890ac1d93$var$TagGroupInner({ props: props, forwardedRef: ref, collection: collection }) {
    let tagListRef = (0, $7VBu2$useRef)(null);
    // Extract the user provided id so it doesn't clash with the collection id provided by Autocomplete
    let { id: id, ...otherProps } = props;
    [otherProps, tagListRef] = (0, $b7b7a92703138c9b$export$29f1550f4b0d4415)(otherProps, tagListRef, (0, $8f09b710ef85b337$export$b0d3ecf7112093a7));
    // eslint-disable-next-line @typescript-eslint/no-unused-vars
    let { filter: filter, shouldUseVirtualFocus: shouldUseVirtualFocus, ...DOMCollectionProps } = otherProps;
    let [labelRef, label] = (0, $b7b7a92703138c9b$export$9d4c57ee4c6ffdd8)(!props['aria-label'] && !props['aria-labelledby']);
    let tagGroupState = (0, $7VBu2$useListState)({
        ...DOMCollectionProps,
        children: undefined,
        collection: collection
    });
    let filteredState = (0, $7VBu2$UNSTABLE_useFilteredListState)(tagGroupState, filter);
    // Prevent DOM props from going to two places.
    let domProps = (0, $7VBu2$filterDOMProps)(otherProps, {
        global: true
    });
    let domPropOverrides = Object.fromEntries(Object.entries(domProps).map(([k, val])=>[
            k,
            k === 'id' ? val : undefined
        ]));
    let { gridProps: gridProps, labelProps: labelProps, descriptionProps: descriptionProps, errorMessageProps: errorMessageProps } = (0, $7VBu2$useTagGroup)({
        ...DOMCollectionProps,
        ...domPropOverrides,
        label: label
    }, filteredState, tagListRef);
    var _props_className;
    return /*#__PURE__*/ (0, $7VBu2$react).createElement((0, $b7b7a92703138c9b$export$df3a06d6289f983e).div, {
        render: props.render,
        ...domProps,
        id: id,
        ref: ref,
        slot: props.slot || undefined,
        className: (_props_className = props.className) !== null && _props_className !== void 0 ? _props_className : 'react-aria-TagGroup',
        style: props.style
    }, /*#__PURE__*/ (0, $7VBu2$react).createElement((0, $b7b7a92703138c9b$export$2881499e37b75b9a), {
        values: [
            [
                (0, $3e4839e5b30e7b17$export$75b6ee27786ba447),
                {
                    ...labelProps,
                    elementType: 'span',
                    ref: labelRef
                }
            ],
            [
                $ada7ba7890ac1d93$export$e755ce3685dd0ca9,
                {
                    ...gridProps,
                    ref: tagListRef
                }
            ],
            [
                (0, $ba3142315b3e1149$export$7c5906fe4f1f2af2),
                filteredState
            ],
            [
                (0, $20d769b1e2b13352$export$9afb8bc826b033ea),
                {
                    slots: {
                        description: descriptionProps,
                        errorMessage: errorMessageProps
                    }
                }
            ]
        ]
    }, props.children));
}
const $ada7ba7890ac1d93$export$f9fef0f55402315b = /*#__PURE__*/ (0, $7VBu2$forwardRef)(function TagList(props, ref) {
    let state = (0, $7VBu2$useContext)((0, $ba3142315b3e1149$export$7c5906fe4f1f2af2));
    return state ? /*#__PURE__*/ (0, $7VBu2$react).createElement($ada7ba7890ac1d93$var$TagListInner, {
        props: props,
        forwardedRef: ref
    }) : /*#__PURE__*/ (0, $7VBu2$react).createElement((0, $7VBu2$Collection), props);
});
function $ada7ba7890ac1d93$var$TagListInner({ props: props, forwardedRef: forwardedRef }) {
    let state = (0, $7VBu2$useContext)((0, $ba3142315b3e1149$export$7c5906fe4f1f2af2));
    let { CollectionRoot: CollectionRoot } = (0, $7VBu2$useContext)((0, $a53f0f6636929daa$export$4feb769f8ddf26c5));
    let [gridProps, ref] = (0, $b7b7a92703138c9b$export$29f1550f4b0d4415)({}, forwardedRef, $ada7ba7890ac1d93$export$e755ce3685dd0ca9);
    let { focusProps: focusProps, isFocused: isFocused, isFocusVisible: isFocusVisible } = (0, $7VBu2$useFocusRing)();
    let renderValues = {
        isEmpty: state.collection.size === 0,
        isFocused: isFocused,
        isFocusVisible: isFocusVisible,
        state: state
    };
    let renderProps = (0, $b7b7a92703138c9b$export$4d86445c2cf5e3)({
        ...props,
        children: undefined,
        defaultClassName: 'react-aria-TagList',
        values: renderValues
    });
    let persistedKeys = (0, $a53f0f6636929daa$export$90e00781bc59d8f9)(state.selectionManager.focusedKey);
    let DOMProps = (0, $7VBu2$filterDOMProps)(props, {
        global: true
    });
    return /*#__PURE__*/ (0, $7VBu2$react).createElement((0, $b7b7a92703138c9b$export$df3a06d6289f983e).div, {
        ...(0, $7VBu2$mergeProps)(DOMProps, renderProps, gridProps, focusProps),
        ref: ref,
        "data-empty": state.collection.size === 0 || undefined,
        "data-focused": isFocused || undefined,
        "data-focus-visible": isFocusVisible || undefined
    }, /*#__PURE__*/ (0, $7VBu2$react).createElement((0, $347bc273c4058e94$export$758399f318e6385a), null, state.collection.size === 0 && props.renderEmptyState ? props.renderEmptyState(renderValues) : /*#__PURE__*/ (0, $7VBu2$react).createElement(CollectionRoot, {
        collection: state.collection,
        persistedKeys: persistedKeys
    })));
}
const $ada7ba7890ac1d93$export$3288d34c523a1192 = /*#__PURE__*/ (0, $7VBu2$createLeafComponent)((0, $7VBu2$ItemNode), (props, forwardedRef, item)=>{
    let state = (0, $7VBu2$useContext)((0, $ba3142315b3e1149$export$7c5906fe4f1f2af2));
    let ref = (0, $7VBu2$useObjectRef)(forwardedRef);
    let { focusProps: focusProps, isFocusVisible: isFocusVisible } = (0, $7VBu2$useFocusRing)({
        within: false
    });
    let { rowProps: rowProps, gridCellProps: gridCellProps, removeButtonProps: removeButtonProps, ...states } = (0, $7VBu2$useTag)({
        item: item
    }, state, ref);
    let { hoverProps: hoverProps, isHovered: isHovered } = (0, $7VBu2$useHover)({
        isDisabled: !states.allowsSelection && !states.hasAction,
        onHoverStart: item.props.onHoverStart,
        onHoverChange: item.props.onHoverChange,
        onHoverEnd: item.props.onHoverEnd
    });
    let renderProps = (0, $b7b7a92703138c9b$export$4d86445c2cf5e3)({
        ...props,
        id: undefined,
        children: item.rendered,
        defaultClassName: 'react-aria-Tag',
        values: {
            ...states,
            isFocusVisible: isFocusVisible,
            isHovered: isHovered,
            selectionMode: state.selectionManager.selectionMode,
            selectionBehavior: state.selectionManager.selectionBehavior
        }
    });
    (0, $7VBu2$useEffect)(()=>{
        if (!item.textValue && process.env.NODE_ENV !== 'production') console.warn('A `textValue` prop is required for <Tag> elements with non-plain text children for accessibility.');
    }, [
        item.textValue
    ]);
    let DOMProps = (0, $7VBu2$filterDOMProps)(props, {
        global: true
    });
    delete DOMProps.id;
    delete DOMProps.onClick;
    return /*#__PURE__*/ (0, $7VBu2$react).createElement((0, $b7b7a92703138c9b$export$df3a06d6289f983e).div, {
        ref: ref,
        ...(0, $7VBu2$mergeProps)(DOMProps, renderProps, rowProps, focusProps, hoverProps),
        "data-selected": states.isSelected || undefined,
        "data-disabled": states.isDisabled || undefined,
        "data-hovered": isHovered || undefined,
        "data-focused": states.isFocused || undefined,
        "data-focus-visible": isFocusVisible || undefined,
        "data-pressed": states.isPressed || undefined,
        "data-allows-removing": states.allowsRemoving || undefined,
        "data-selection-mode": state.selectionManager.selectionMode === 'none' ? undefined : state.selectionManager.selectionMode
    }, /*#__PURE__*/ (0, $7VBu2$react).createElement("div", {
        ...gridCellProps,
        style: {
            display: 'contents'
        }
    }, /*#__PURE__*/ (0, $7VBu2$react).createElement((0, $b7b7a92703138c9b$export$2881499e37b75b9a), {
        values: [
            [
                (0, $fc203795b9b363cd$export$24d547caef80ccd1),
                {
                    slots: {
                        remove: removeButtonProps
                    }
                }
            ],
            [
                (0, $a53f0f6636929daa$export$4feb769f8ddf26c5),
                (0, $a53f0f6636929daa$export$a164736487e3f0ae)
            ],
            [
                (0, $0d6f83ad40839938$export$c9549807523555e0),
                {
                    isSelected: states.isSelected
                }
            ]
        ]
    }, renderProps.children)));
});


export {$ada7ba7890ac1d93$export$5b07b5dd2cbd96e3 as TagGroupContext, $ada7ba7890ac1d93$export$e755ce3685dd0ca9 as TagListContext, $ada7ba7890ac1d93$export$67ea30858aaf75e3 as TagGroup, $ada7ba7890ac1d93$export$f9fef0f55402315b as TagList, $ada7ba7890ac1d93$export$3288d34c523a1192 as Tag};
//# sourceMappingURL=TagGroup.js.map
