/* @oracle/oraclejet-preact: undefined */
import { jsx } from 'preact/jsx-runtime';
import { createContext, toChildArray } from 'preact';
import { useContext, useMemo } from 'preact/hooks';
import { forwardRef } from 'preact/compat';
import './FormContext-4d71f9c7.js';
import { u as useFormContext } from './useFormContext-875cacd7.js';
import { F as FormFieldContext } from './FormFieldContext-68eb5946.js';
import { u as useFormFieldContextProps } from './useFormFieldContextProps-d07cd618.js';
import './CheckboxSetStyles.styles.css';
import { u as useId } from './useId-03dbfdf0.js';
import { C as CheckboxRadioField } from './CheckboxRadioField-294463ba.js';

const CheckboxSetContext = createContext({});
const useCheckboxSetContext = () => useContext(CheckboxSetContext);

var styles = {ul:'CheckboxSetStyles_styles_ul__68p6630'};

/**
 * A CheckboxSet allows the user to select one or more options from a set.
 */
const CheckboxSet = forwardRef(({ 'aria-describedby': ariaDescribedBy, assistiveText, columnSpan, direction = 'column', helpSourceLink, helpSourceText, isDisabled: propIsDisabled, isReadonly: propIsReadonly, isRequired = false, label, labelEdge: propLabelEdge, labelStartWidth: propLabelStartWidth, messages, onCommit, userAssistanceDensity: propUserAssistanceDensity, value, children, testId }, ref) => {
    const hasValue = value !== undefined ? value.size > 0 : false;
    const baseId = useId();
    const { isDisabled: isFormDisabled, isReadonly: isFormReadonly, labelEdge: formLabelEdge, labelStartWidth: formLabelStartWidth, userAssistanceDensity: formUserAssistanceDensity } = useFormContext();
    // default to FormContext values if component properties are not specified
    const isDisabled = propIsDisabled ?? isFormDisabled;
    const isReadonly = propIsReadonly ?? isFormReadonly;
    const labelEdge = propLabelEdge ?? formLabelEdge;
    const labelStartWidth = propLabelStartWidth ?? formLabelStartWidth;
    const userAssistanceDensity = propUserAssistanceDensity ?? formUserAssistanceDensity;
    const formFieldContext = useFormFieldContextProps({
        hasValue,
        isDisabled,
        isReadonly
    });
    const checkboxSetContext = useMemo(() => ({
        name: baseId,
        value,
        onCommit
    }), [baseId, onCommit, value]);
    // wrap each CheckboxItem in an <li> tag and the entire set with <ul>
    const childrenArray = toChildArray(children).filter(Boolean);
    const wrappedChildren = childrenArray.map((item) => jsx("li", { children: item }));
    return (jsx(FormFieldContext.Provider, { value: formFieldContext, children: jsx(CheckboxRadioField, { "aria-describedby": ariaDescribedBy, assistiveText: assistiveText, baseId: baseId, columnSpan: columnSpan, direction: direction, helpSourceLink: helpSourceLink, helpSourceText: helpSourceText, isDisabled: isDisabled, isReadonly: isReadonly, isRequired: isRequired, label: label, labelEdge: labelEdge, labelStartWidth: labelStartWidth, parentComponentVariant: "checkboxSet", messages: messages, userAssistanceDensity: userAssistanceDensity, hasValue: hasValue, role: "group", testId: testId, ref: ref, children: jsx(CheckboxSetContext.Provider, { value: checkboxSetContext, children: jsx("ul", { className: styles.ul, children: wrappedChildren }) }) }) }));
});

export { CheckboxSet as C, CheckboxSetContext as a, useCheckboxSetContext as u };
//# sourceMappingURL=CheckboxSet-140804f2.js.map
