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 FilterPickerContext } from './FilterPickerProvider-es.js';
import { F as FILTER_PICKER_MENU_ID } from './constants-es.js';

function useFilterPickerActivatorAccessibility() {
    const { label, open } = useContext(FilterPickerContext);
    return {
        ariaLabel: label,
        ariaExpanded: open,
        ariaControls: FILTER_PICKER_MENU_ID,
        role: "combobox",
    };
}

function FilterPickerActivator(props) {
    const { handleOpen } = React__default.useContext(FilterPickerContext);
    const accessibilityAttributes = useFilterPickerActivatorAccessibility();
    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 { FilterPickerActivator as F };
