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

var jsxRuntime = require('preact/jsx-runtime');
var useProgressButtonLabelLayoutTheme = require('./useProgressButtonLabelLayoutTheme-9c9f986f.js');
var classNames = require('./classNames-c14c6ef3.js');
var ProgressCircle = require('./ProgressCircle-b3e0fbca.js');
var withThemeProps = require('./withThemeProps-c4127d27.js');
var View = require('./View-216e5184.js');
var useColorScheme = require('./useColorScheme-b4de9e67.js');
var hooks = require('preact/hooks');
var HiddenAccessible = require('./HiddenAccessible-087eb49a.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.withThemeProps(View.View);
    const currentColorScheme = useColorScheme.useColorScheme();
    const newColorScheme = !currentColorScheme || currentColorScheme === 'light' ? 'dark' : 'light';
    return isLoadingContrast ? (jsxRuntime.jsx(ViewWithThemeProps, { colorScheme: newColorScheme, children: jsxRuntime.jsx(ProgressCircle.ProgressCircle, { size: "sm", value: "indeterminate" }) })) : (jsxRuntime.jsx(ProgressCircle.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.useProgressButtonLabelLayoutTheme({
        display,
        size,
        styling,
        isLoading,
        startIcon,
        children
    });
    const isLabelOnly = display === 'label' || !startIcon;
    const mergedContainerClasses = classNames.classNames([
        containerClasses,
        isLoading ? progressIconClasses : undefined
    ]);
    const [loaded, setLoaded] = hooks.useState(false);
    const [loading, setLoading] = hooks.useState(false);
    if (isLoading && !loaded) {
        setLoading(true);
    }
    if (!isLoading && loading) {
        setLoaded(true);
        setLoading(false);
        setTimeout(() => {
            setLoaded(false);
        }, 500);
    }
    return (jsxRuntime.jsxs("span", { class: mergedContainerClasses, children: [isShowIcons && startIcon && (jsxRuntime.jsx("span", { class: startIconClasses, "aria-hidden": true, children: isLoading ? jsxRuntime.jsx(AdjustedProgressCircle, { isLoadingContrast: isLoadingContrast }) : startIcon })), isShowText && children && (jsxRuntime.jsxs("span", { "aria-hidden": true, class: isLabelOnly ? undefined : labelClasses, children: [' ', children, ' '] })), isShowText && children && isLoading && !hasTextStartIcon && (jsxRuntime.jsx("span", { class: labelStyles['floatingIcon'], "aria-hidden": true, children: jsxRuntime.jsx(AdjustedProgressCircle, { isLoadingContrast: isLoadingContrast }) })), accessibleLoadedLabel ? (jsxRuntime.jsx("span", { "aria-live": "assertive", children: jsxRuntime.jsx(HiddenAccessible.HiddenAccessible, { children: loaded ? accessibleLoadedLabel : isLoading ? accessibleLoadingLabel : undefined }) })) : undefined] }));
}
ProgressButtonLabelLayout.displayName = 'ProgressButtonLabelLayout';

exports.ProgressButtonLabelLayout = ProgressButtonLabelLayout;
//# sourceMappingURL=ProgressButtonLabelLayout-b47ca0c8.js.map
