"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isDropdownEmpty = isDropdownEmpty;
exports.getCalloutCollisionTransformationProps = getCalloutCollisionTransformationProps;
exports.getCalloutCollisionTransformationPropsForDropdown = getCalloutCollisionTransformationPropsForDropdown;
/**
 * Method checks if drodpown or combobox is empty or any value is selected.
 *
 * @param {Partial<IDropdownProps | IComboBoxProps>} props Dropdown or combobox props.
 * @returns {boolean} Is dropdown or combobox empty.
 */
function isDropdownEmpty(props) {
    const { selectedKey } = props;
    if (Array.isArray(selectedKey)) {
        return selectedKey.length === 0;
    }
    if (('text' in props && props.text) || ('selectedKeys' in props && props.selectedKeys?.length)) {
        return false;
    }
    return !selectedKey;
}
/**
 * Method returns additional callout props for callout collision transformation if feature is enabled.
 * Callout collision transformation checks if dropdown menu overlaps with dialog action/submit buttons
 *  and if overlap happens, then additional offset is applied to make action buttons visible.
 *
 * @param calloutCollisionTransform Instance of callout collision transformation.
 * @param multiSelect Is multi select enabled.
 * @param enabled Is transformation enabled.
 * @returns Callout props to enable callout collision transformation.
 */
function getCalloutCollisionTransformationProps(calloutCollisionTransform, multiSelect, enabled) {
    if (multiSelect && enabled) {
        return {
            preventDismissOnEvent: calloutCollisionTransform.preventDismissOnEvent,
            layerProps: {
                onLayerDidMount: calloutCollisionTransform.applyTransformation,
                onLayerWillUnmount: calloutCollisionTransform.resetTransformation
            }
        };
    }
    return undefined;
}
/**
 * Method returns callback function to 'onLayerDidMount' property of dropdown 'callout'.
 *
 * @param dropdown Instance of dropdown.
 * @param calloutCollisionTransform of callout collision transformation.
 * @returns Returns callback function to 'onLayerDidMount' property of dropdown 'callout'.
 */
function getOnLayerDidMount(dropdown, calloutCollisionTransform) {
    return () => {
        const { layerProps } = getCalloutCollisionTransformationProps(calloutCollisionTransform, dropdown.props.multiSelect, dropdown.props.calloutCollisionTransformation) ?? {};
        if (dropdown.props.calloutProps?.layerProps?.onLayerDidMount) {
            dropdown.props.calloutProps?.layerProps?.onLayerDidMount();
        }
        if (layerProps?.onLayerDidMount) {
            layerProps.onLayerDidMount();
        }
    };
}
/**
 * Method returns callback function to 'onLayerWillUnmount' property of dropdown 'callout'.
 *
 * @param dropdown Instance of dropdown.
 * @param calloutCollisionTransform of callout collision transformation.
 * @returns Returns callback function to 'onLayerWillUnmount' property of dropdown 'callout'.
 */
function getOnLayerWillUnmount(dropdown, calloutCollisionTransform) {
    return () => {
        const { layerProps } = getCalloutCollisionTransformationProps(calloutCollisionTransform, dropdown.props.multiSelect, dropdown.props.calloutCollisionTransformation) ?? {};
        if (dropdown.props.calloutProps?.layerProps?.onLayerWillUnmount) {
            dropdown.props.calloutProps?.layerProps?.onLayerWillUnmount();
        }
        if (layerProps?.onLayerWillUnmount) {
            layerProps.onLayerWillUnmount();
        }
    };
}
/**
 * Method returns callback function to 'preventDismissOnEvent' property of dropdown 'callout', which prevents callout dismiss/close if focus/click on target elements.
 *
 * @param dropdown Instance of dropdown.
 * @param calloutCollisionTransform of callout collision transformation.
 * @returns Returns callback function to 'preventDismissOnEvent' property of dropdown 'callout'.
 */
function getPreventDismissOnEvent(dropdown, calloutCollisionTransform) {
    return (event) => {
        let preventDismiss = false;
        if (dropdown.props.calloutProps?.preventDismissOnEvent) {
            preventDismiss = dropdown.props.calloutProps.preventDismissOnEvent(event);
        }
        if (!preventDismiss) {
            const { preventDismissOnEvent } = getCalloutCollisionTransformationProps(calloutCollisionTransform, dropdown.props.multiSelect, dropdown.props.calloutCollisionTransformation) ?? {};
            if (preventDismissOnEvent) {
                return preventDismissOnEvent(event);
            }
        }
        return preventDismiss;
    };
}
/**
 * Method returns additional callout props for callout collision transformation if feature is enabled.
 * Callout collision transformation checks if dropdown menu overlaps with dialog action/submit buttons
 *  and if overlap happens, then additional offset is applied to make action buttons visible.
 *
 * @param dropdown Instance of dropdown.
 * @param calloutCollisionTransform of callout collision transformation.
 * @returns Callout props to enable callout collision transformation.
 */
function getCalloutCollisionTransformationPropsForDropdown(dropdown, calloutCollisionTransform) {
    if (dropdown.props.multiSelect && dropdown.props.calloutCollisionTransformation) {
        return {
            preventDismissOnEvent: getPreventDismissOnEvent(dropdown, calloutCollisionTransform),
            layerProps: {
                onLayerDidMount: getOnLayerDidMount(dropdown, calloutCollisionTransform),
                onLayerWillUnmount: getOnLayerWillUnmount(dropdown, calloutCollisionTransform)
            }
        };
    }
    return undefined;
}
//# sourceMappingURL=utils.js.map