import React__default, { useContext } from 'react';
import { B as Button } from './Button-es.js';
import 'classnames';
import { C as Chip } from './Chip-es.js';
import './tslib.es6-es.js';
import '@jobber/design';
import { a as ComboboxContext } from './ComboboxProvider-es.js';
import { C as COMBOBOX_MENU_ID } from './constants-es.js';

function useComboboxActivatorAccessibility() {
    const { label, open } = useContext(ComboboxContext);
    return {
        ariaLabel: label,
        ariaExpanded: open,
        ariaControls: COMBOBOX_MENU_ID,
        role: "combobox",
    };
}

function ComboboxActivator(props) {
    const { handleOpen } = React__default.useContext(ComboboxContext);
    const accessibilityAttributes = useComboboxActivatorAccessibility();
    if (React__default.isValidElement(props.children) &&
        (props.children.type === Button || props.children.type === Chip)) {
        return React__default.cloneElement(props.children, {
            role: accessibilityAttributes.role,
            onClick: handleOpen,
        });
    }
    else if (typeof props.children === "function") {
        return props.children(Object.assign(Object.assign({}, accessibilityAttributes), { open: handleOpen }));
    }
    return null;
}

export { ComboboxActivator as C };
