/* @oracle/oraclejet-preact: undefined */
'use strict';

var useMessageSeverity = require('./useMessageSeverity-cfc4ae9d.js');
var stringUtils = require('./stringUtils-4e4a6b2b.js');


/**
 * @license
 * Copyright (c) %FIRST_YEAR% %CURRENT_YEAR%, Oracle and/or its affiliates.
 * The Universal Permissive License (UPL), Version 1.0
 * as shown at https://oss.oracle.com/licenses/upl/
 * @ignore
 */
function useCheckboxRadioField({ ariaDescribedBy, baseId, hasValue, hasTopUserAssistance, hasBottomUserAssistance, isReadonly, isRequired = false, isDisabled, label, labelEdge, messages, parentComponentVariant }) {
    const optionsGroupId = `${baseId}-group`;
    const labelId = `${baseId}-label`;
    const topUaId = hasTopUserAssistance ? `${baseId}-top-ua` : undefined;
    const bottomUaId = hasBottomUserAssistance ? `${baseId}-bottom-ua` : undefined;
    const readonlyId = isReadonly ? `${baseId}-readonly` : undefined;
    const ariaLabel = label && label.length > 0 && labelEdge === 'none' ? label : undefined;
    const ariaLabelledBy = ariaLabel ? undefined : labelId;
    const isRadioSet = parentComponentVariant === 'radioSet';
    const highestMessageSeverity = useMessageSeverity.useMessageSeverity(messages);
    const hasErrorMessage = highestMessageSeverity === 'error';
    return {
        groupProps: {
            'aria-describedby': stringUtils.merge([topUaId, bottomUaId, readonlyId, ariaDescribedBy]),
            ...(isRadioSet && { 'aria-required': isRequired }),
            ...(ariaLabelledBy && { 'aria-labelledby': ariaLabelledBy }),
            ...(ariaLabel && { 'aria-label': ariaLabel }),
            ...(isReadonly && isRadioSet && { 'aria-readonly': true }),
            ...(hasErrorMessage && { 'aria-invalid': true }),
            ...(isDisabled && { 'aria-disabled': true }),
            id: optionsGroupId
        },
        labelProps: {
            forId: optionsGroupId,
            id: labelId
        },
        // TOP UA is assistive text and help link/text
        ...(hasTopUserAssistance && {
            topUserAssistanceProps: {
                id: topUaId,
                // Use reflow variant so that top UA doesn't have min height
                variant: 'reflow'
            }
        }),
        // Bottom UA is required indicator or messages
        ...(hasBottomUserAssistance && {
            bottomUserAssistanceProps: {
                id: bottomUaId,
                isRequiredShown: !!isRequired && !hasValue
            }
        }),
        ...(isReadonly && {
            readonlyId
        })
    };
}

var topUAContainerStyles = {top:'CheckboxRadioFieldStyles_topUAContainerStyles_top__j1xru60',start:'CheckboxRadioFieldStyles_topUAContainerStyles_start__j1xru61'};

exports.topUAContainerStyles = topUAContainerStyles;
exports.useCheckboxRadioField = useCheckboxRadioField;
//# sourceMappingURL=CheckboxRadioFieldStyles.css-7d820452.js.map
