import {ButtonContext as $7705c033048f6da7$export$24d547caef80ccd1} from "./Button.mjs";
import {dom as $7230ffa83bc0c2cf$export$df3a06d6289f983e, Provider as $7230ffa83bc0c2cf$export$2881499e37b75b9a, useContextProps as $7230ffa83bc0c2cf$export$29f1550f4b0d4415, useRenderProps as $7230ffa83bc0c2cf$export$4d86445c2cf5e3, useSlot as $7230ffa83bc0c2cf$export$9d4c57ee4c6ffdd8} from "./utils.mjs";
import {CollectionRendererContext as $263ab7fc0f95ccdb$export$4feb769f8ddf26c5, DefaultCollectionRenderer as $263ab7fc0f95ccdb$export$a164736487e3f0ae, usePersistedKeys as $263ab7fc0f95ccdb$export$90e00781bc59d8f9} from "./Collection.mjs";
import {LabelContext as $43a3b93638fe5db9$export$75b6ee27786ba447} from "./Label.mjs";
import {ListStateContext as $928221da08ecbc62$export$7c5906fe4f1f2af2} from "./ListBox.mjs";
import {SelectableCollectionContext as $4b38b5b75ecc6208$export$b0d3ecf7112093a7} from "./Autocomplete.mjs";
import {SelectionIndicatorContext as $91fe5e721c7f36c1$export$c9549807523555e0} from "./SelectionIndicator.mjs";
import {SharedElementTransition as $792f28e438b9ad5f$export$758399f318e6385a} from "./SharedElementTransition.mjs";
import {TextContext as $efe09c6d1c304b50$export$9afb8bc826b033ea} from "./Text.mjs";
import {useTagGroup as $ck0pj$useTagGroup, useTag as $ck0pj$useTag} from "react-aria/useTagGroup";
import {CollectionBuilder as $ck0pj$CollectionBuilder, Collection as $ck0pj$Collection, createLeafComponent as $ck0pj$createLeafComponent} from "react-aria/private/collections/CollectionBuilder";
import {filterDOMProps as $ck0pj$filterDOMProps} from "react-aria/private/utils/filterDOMProps";
import {ItemNode as $ck0pj$ItemNode} from "react-aria/private/collections/BaseCollection";
import {useListState as $ck0pj$useListState, UNSTABLE_useFilteredListState as $ck0pj$UNSTABLE_useFilteredListState} from "react-stately/useListState";
import {mergeProps as $ck0pj$mergeProps} from "react-aria/mergeProps";
import $ck0pj$react, {createContext as $ck0pj$createContext, forwardRef as $ck0pj$forwardRef, useRef as $ck0pj$useRef, useContext as $ck0pj$useContext, useEffect as $ck0pj$useEffect} from "react";
import {useFocusRing as $ck0pj$useFocusRing} from "react-aria/useFocusRing";
import {useHover as $ck0pj$useHover} from "react-aria/useHover";
import {useObjectRef as $ck0pj$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 $3df3ddf5bafbc7b1$export$5b07b5dd2cbd96e3 = /*#__PURE__*/ (0, $ck0pj$createContext)(null);
const $3df3ddf5bafbc7b1$export$e755ce3685dd0ca9 = /*#__PURE__*/ (0, $ck0pj$createContext)(null);
const $3df3ddf5bafbc7b1$export$67ea30858aaf75e3 = /*#__PURE__*/ (0, $ck0pj$forwardRef)(function TagGroup(props, ref) {
    [props, ref] = (0, $7230ffa83bc0c2cf$export$29f1550f4b0d4415)(props, ref, $3df3ddf5bafbc7b1$export$5b07b5dd2cbd96e3);
    return /*#__PURE__*/ (0, $ck0pj$react).createElement((0, $928221da08ecbc62$export$7c5906fe4f1f2af2).Provider, {
        value: null
    }, /*#__PURE__*/ (0, $ck0pj$react).createElement((0, $ck0pj$CollectionBuilder), {
        content: props.children
    }, (collection)=>/*#__PURE__*/ (0, $ck0pj$react).createElement($3df3ddf5bafbc7b1$var$TagGroupInner, {
            props: props,
            forwardedRef: ref,
            collection: collection
        })));
});
function $3df3ddf5bafbc7b1$var$TagGroupInner({ props: props, forwardedRef: ref, collection: collection }) {
    let tagListRef = (0, $ck0pj$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, $7230ffa83bc0c2cf$export$29f1550f4b0d4415)(otherProps, tagListRef, (0, $4b38b5b75ecc6208$export$b0d3ecf7112093a7));
    // eslint-disable-next-line @typescript-eslint/no-unused-vars
    let { filter: filter, shouldUseVirtualFocus: shouldUseVirtualFocus, ...DOMCollectionProps } = otherProps;
    let [labelRef, label] = (0, $7230ffa83bc0c2cf$export$9d4c57ee4c6ffdd8)(!props['aria-label'] && !props['aria-labelledby']);
    let tagGroupState = (0, $ck0pj$useListState)({
        ...DOMCollectionProps,
        children: undefined,
        collection: collection
    });
    let filteredState = (0, $ck0pj$UNSTABLE_useFilteredListState)(tagGroupState, filter);
    // Prevent DOM props from going to two places.
    let domProps = (0, $ck0pj$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, $ck0pj$useTagGroup)({
        ...DOMCollectionProps,
        ...domPropOverrides,
        label: label
    }, filteredState, tagListRef);
    return /*#__PURE__*/ (0, $ck0pj$react).createElement((0, $7230ffa83bc0c2cf$export$df3a06d6289f983e).div, {
        render: props.render,
        ...domProps,
        id: id,
        ref: ref,
        slot: props.slot || undefined,
        className: props.className ?? 'react-aria-TagGroup',
        style: props.style
    }, /*#__PURE__*/ (0, $ck0pj$react).createElement((0, $7230ffa83bc0c2cf$export$2881499e37b75b9a), {
        values: [
            [
                (0, $43a3b93638fe5db9$export$75b6ee27786ba447),
                {
                    ...labelProps,
                    elementType: 'span',
                    ref: labelRef
                }
            ],
            [
                $3df3ddf5bafbc7b1$export$e755ce3685dd0ca9,
                {
                    ...gridProps,
                    ref: tagListRef
                }
            ],
            [
                (0, $928221da08ecbc62$export$7c5906fe4f1f2af2),
                filteredState
            ],
            [
                (0, $efe09c6d1c304b50$export$9afb8bc826b033ea),
                {
                    slots: {
                        description: descriptionProps,
                        errorMessage: errorMessageProps
                    }
                }
            ]
        ]
    }, props.children));
}
const $3df3ddf5bafbc7b1$export$f9fef0f55402315b = /*#__PURE__*/ (0, $ck0pj$forwardRef)(function TagList(props, ref) {
    let state = (0, $ck0pj$useContext)((0, $928221da08ecbc62$export$7c5906fe4f1f2af2));
    return state ? /*#__PURE__*/ (0, $ck0pj$react).createElement($3df3ddf5bafbc7b1$var$TagListInner, {
        props: props,
        forwardedRef: ref
    }) : /*#__PURE__*/ (0, $ck0pj$react).createElement((0, $ck0pj$Collection), props);
});
function $3df3ddf5bafbc7b1$var$TagListInner({ props: props, forwardedRef: forwardedRef }) {
    let state = (0, $ck0pj$useContext)((0, $928221da08ecbc62$export$7c5906fe4f1f2af2));
    let { CollectionRoot: CollectionRoot } = (0, $ck0pj$useContext)((0, $263ab7fc0f95ccdb$export$4feb769f8ddf26c5));
    let [gridProps, ref] = (0, $7230ffa83bc0c2cf$export$29f1550f4b0d4415)({}, forwardedRef, $3df3ddf5bafbc7b1$export$e755ce3685dd0ca9);
    let { focusProps: focusProps, isFocused: isFocused, isFocusVisible: isFocusVisible } = (0, $ck0pj$useFocusRing)();
    let renderValues = {
        isEmpty: state.collection.size === 0,
        isFocused: isFocused,
        isFocusVisible: isFocusVisible,
        state: state
    };
    let renderProps = (0, $7230ffa83bc0c2cf$export$4d86445c2cf5e3)({
        ...props,
        children: undefined,
        defaultClassName: 'react-aria-TagList',
        values: renderValues
    });
    let persistedKeys = (0, $263ab7fc0f95ccdb$export$90e00781bc59d8f9)(state.selectionManager.focusedKey);
    let DOMProps = (0, $ck0pj$filterDOMProps)(props, {
        global: true
    });
    return /*#__PURE__*/ (0, $ck0pj$react).createElement((0, $7230ffa83bc0c2cf$export$df3a06d6289f983e).div, {
        ...(0, $ck0pj$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, $ck0pj$react).createElement((0, $792f28e438b9ad5f$export$758399f318e6385a), null, state.collection.size === 0 && props.renderEmptyState ? props.renderEmptyState(renderValues) : /*#__PURE__*/ (0, $ck0pj$react).createElement(CollectionRoot, {
        collection: state.collection,
        persistedKeys: persistedKeys
    })));
}
const $3df3ddf5bafbc7b1$export$3288d34c523a1192 = /*#__PURE__*/ (0, $ck0pj$createLeafComponent)((0, $ck0pj$ItemNode), (props, forwardedRef, item)=>{
    let state = (0, $ck0pj$useContext)((0, $928221da08ecbc62$export$7c5906fe4f1f2af2));
    let ref = (0, $ck0pj$useObjectRef)(forwardedRef);
    let { focusProps: focusProps, isFocusVisible: isFocusVisible } = (0, $ck0pj$useFocusRing)({
        within: false
    });
    let { rowProps: rowProps, gridCellProps: gridCellProps, removeButtonProps: removeButtonProps, ...states } = (0, $ck0pj$useTag)({
        item: item
    }, state, ref);
    let { hoverProps: hoverProps, isHovered: isHovered } = (0, $ck0pj$useHover)({
        isDisabled: !states.allowsSelection && !states.hasAction,
        onHoverStart: item.props.onHoverStart,
        onHoverChange: item.props.onHoverChange,
        onHoverEnd: item.props.onHoverEnd
    });
    let renderProps = (0, $7230ffa83bc0c2cf$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, $ck0pj$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, $ck0pj$filterDOMProps)(props, {
        global: true
    });
    delete DOMProps.id;
    delete DOMProps.onClick;
    return /*#__PURE__*/ (0, $ck0pj$react).createElement((0, $7230ffa83bc0c2cf$export$df3a06d6289f983e).div, {
        ref: ref,
        ...(0, $ck0pj$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, $ck0pj$react).createElement("div", {
        ...gridCellProps,
        style: {
            display: 'contents'
        }
    }, /*#__PURE__*/ (0, $ck0pj$react).createElement((0, $7230ffa83bc0c2cf$export$2881499e37b75b9a), {
        values: [
            [
                (0, $7705c033048f6da7$export$24d547caef80ccd1),
                {
                    slots: {
                        remove: removeButtonProps
                    }
                }
            ],
            [
                (0, $263ab7fc0f95ccdb$export$4feb769f8ddf26c5),
                (0, $263ab7fc0f95ccdb$export$a164736487e3f0ae)
            ],
            [
                (0, $91fe5e721c7f36c1$export$c9549807523555e0),
                {
                    isSelected: states.isSelected
                }
            ]
        ]
    }, renderProps.children)));
});


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