/* @oracle/oraclejet-preact: undefined */
import { jsx, jsxs } from 'preact/jsx-runtime';
import { u as useProgressButtonLabelLayoutTheme } from './useProgressButtonLabelLayoutTheme-7ce1cf07.js';
import { c as classNames } from './classNames-4e12b00d.js';
import { P as ProgressCircle } from './ProgressCircle-faf79b79.js';
import { w as withThemeProps } from './withThemeProps-1621f692.js';
import { V as View } from './View-afe98b65.js';
import { u as useColorScheme } from './useColorScheme-c4e237ad.js';
import { useState } from 'preact/hooks';
import { H as HiddenAccessible } from './HiddenAccessible-61197e7c.js';

/**
 * AdjustedProgressCircle provides a Progress Circle that can be rendered on a dark background as needed.
 * @param param0
 * @returns
 */
function AdjustedProgressCircle({ isLoadingContrast = false }) {
    const ViewWithThemeProps = withThemeProps(View);
    const currentColorScheme = useColorScheme();
    const newColorScheme = !currentColorScheme || currentColorScheme === 'light' ? 'dark' : 'light';
    return isLoadingContrast ? (jsx(ViewWithThemeProps, { colorScheme: newColorScheme, children: jsx(ProgressCircle, { size: "sm", value: "indeterminate" }) })) : (jsx(ProgressCircle, { size: "sm", value: "indeterminate" }));
}
AdjustedProgressCircle.displayName = 'AdjustedProgressCircle';

/**
 * ProgressButtonLabelLayout provides the layout for progress button labels.
 * @param param0
 * @returns
 */
function ProgressButtonLabelLayout({ size = 'md', display = 'all', styling = 'default', isLoadingContrast = false, isLoading = false, children, startIcon, accessibleLoadedLabel, accessibleLoadingLabel }) {
    const { startIconClasses, labelClasses, labelStyles, progressIconClasses, containerClasses, isShowIcons, isShowText, hasTextStartIcon } = useProgressButtonLabelLayoutTheme({
        display,
        size,
        styling,
        isLoading,
        startIcon,
        children
    });
    const isLabelOnly = display === 'label' || !startIcon;
    const mergedContainerClasses = classNames([
        containerClasses,
        isLoading ? progressIconClasses : undefined
    ]);
    const [loaded, setLoaded] = useState(false);
    const [loading, setLoading] = useState(false);
    if (isLoading && !loaded) {
        setLoading(true);
    }
    if (!isLoading && loading) {
        setLoaded(true);
        setLoading(false);
        setTimeout(() => {
            setLoaded(false);
        }, 500);
    }
    return (jsxs("span", { class: mergedContainerClasses, children: [isShowIcons && startIcon && (jsx("span", { class: startIconClasses, "aria-hidden": true, children: isLoading ? jsx(AdjustedProgressCircle, { isLoadingContrast: isLoadingContrast }) : startIcon })), isShowText && children && (jsxs("span", { "aria-hidden": true, class: isLabelOnly ? undefined : labelClasses, children: [' ', children, ' '] })), isShowText && children && isLoading && !hasTextStartIcon && (jsx("span", { class: labelStyles['floatingIcon'], "aria-hidden": true, children: jsx(AdjustedProgressCircle, { isLoadingContrast: isLoadingContrast }) })), accessibleLoadedLabel ? (jsx("span", { "aria-live": "assertive", children: jsx(HiddenAccessible, { children: loaded ? accessibleLoadedLabel : isLoading ? accessibleLoadingLabel : undefined }) })) : undefined] }));
}
ProgressButtonLabelLayout.displayName = 'ProgressButtonLabelLayout';

export { ProgressButtonLabelLayout as P };
//# sourceMappingURL=ProgressButtonLabelLayout-f1d097d6.js.map
