"use strict";
var __webpack_require__ = {};
(()=>{
    __webpack_require__.n = (module)=>{
        var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
        __webpack_require__.d(getter, {
            a: getter
        });
        return getter;
    };
})();
(()=>{
    __webpack_require__.d = (exports1, definition)=>{
        for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
            enumerable: true,
            get: definition[key]
        });
    };
})();
(()=>{
    __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
})();
(()=>{
    __webpack_require__.r = (exports1)=>{
        if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
            value: 'Module'
        });
        Object.defineProperty(exports1, '__esModule', {
            value: true
        });
    };
})();
var __webpack_exports__ = {};
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
    ApButton: ()=>ApButton
});
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
const material_namespaceObject = require("@mui/material");
const Button_namespaceObject = require("@mui/material/Button");
var Button_default = /*#__PURE__*/ __webpack_require__.n(Button_namespaceObject);
const styles_namespaceObject = require("@mui/material/styles");
const external_react_namespaceObject = require("react");
var external_react_default = /*#__PURE__*/ __webpack_require__.n(external_react_namespaceObject);
const apollo_core_namespaceObject = require("@uipath/apollo-core");
var apollo_core_default = /*#__PURE__*/ __webpack_require__.n(apollo_core_namespaceObject);
const variantToProps = {
    primary: {
        variant: 'contained'
    },
    secondary: {
        variant: 'outlined',
        sx: {
            background: 'transparent'
        }
    },
    destructive: {
        className: 'warning'
    },
    tertiary: {},
    text: {
        variant: 'text',
        sx: {
            background: 'transparent'
        }
    },
    'text-foreground': {
        variant: 'text',
        sx: {
            color: 'var(--color-foreground)',
            '&&:hover': {
                backgroundColor: 'var(--color-background-hover)'
            },
            '&&:focus': {
                backgroundColor: 'var(--color-background-hover)'
            },
            '&&:focus-visible': {
                backgroundColor: 'var(--color-background-hover)'
            },
            '&&:active': {
                backgroundColor: 'var(--color-background-pressed)'
            }
        }
    }
};
function joinClasses(...classes) {
    return classes.filter(Boolean).join(' ');
}
const LoadingMouseInteractionBlocker = (0, styles_namespaceObject.styled)('div')({
    position: 'absolute',
    inset: 0,
    cursor: 'not-allowed'
});
const LabelLoadingIndicatorContainer = (0, styles_namespaceObject.styled)('div')({
    position: 'absolute',
    top: 0,
    left: 0,
    right: 0,
    bottom: 0,
    display: 'flex',
    alignItems: 'center',
    justifyContent: 'center'
});
const ApButton = /*#__PURE__*/ external_react_default().forwardRef((props, ref)=>{
    const { startIcon, endIcon, id, variant = 'primary', size = 'tall', widthMode = 'default', label, customContent, type = 'button', disabled = false, loading = false, onClick, href, tabIndex, expanded, title, onMouseEnter, onMouseLeave, onMouseDown, onMouseUp, onFocus, onBlur, onKeyDown, ...rest } = props;
    const hasStartIcon = !!startIcon;
    const hasEndIcon = !!endIcon;
    const shouldShowLoadingAsStartIcon = loading && hasStartIcon;
    const shouldShowLoadingAsEndIcon = loading && !hasStartIcon && hasEndIcon;
    const shouldShowLoadingAsLabel = loading && !hasStartIcon && !hasEndIcon;
    const { sx: variantSx, ...restVariantProps } = variantToProps[variant];
    const { sx: userSx, ...restProps } = rest;
    const loadingIndicator = loading ? /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(ButtonLoadingIndicator, {
        "aria-label": label
    }) : null;
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)("div", {
        style: {
            position: 'relative'
        },
        children: [
            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(StyledButton, {
                ref: ref,
                type: type,
                id: id,
                color: "secondary",
                ...disabled ? {
                    disabled: true
                } : {},
                disableElevation: true,
                onClick: loading ? void 0 : onClick,
                onKeyDown: onKeyDown,
                onMouseEnter: onMouseEnter,
                onMouseLeave: onMouseLeave,
                onMouseDown: onMouseDown,
                onMouseUp: onMouseUp,
                onFocus: onFocus,
                onBlur: onBlur,
                startIcon: loading && shouldShowLoadingAsStartIcon ? loadingIndicator : startIcon,
                endIcon: loading && shouldShowLoadingAsEndIcon ? loadingIndicator : endIcon,
                ...restVariantProps,
                sx: [
                    variantSx ?? {},
                    userSx ?? {}
                ],
                tabIndex: tabIndex ?? (loading ? -1 : void 0),
                "aria-disabled": disabled || loading ? 'true' : void 0,
                "aria-expanded": expanded,
                title: title,
                className: joinClasses(restVariantProps?.className, loading && 'loading'),
                href: href,
                customSize: size,
                customWidth: widthMode,
                ...restProps,
                children: [
                    /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("span", {
                        style: {
                            opacity: shouldShowLoadingAsLabel ? 0 : 1
                        },
                        children: customContent ?? label
                    }),
                    shouldShowLoadingAsLabel && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(LabelLoadingIndicatorContainer, {
                        children: loadingIndicator
                    })
                ]
            }),
            loading && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(LoadingMouseInteractionBlocker, {})
        ]
    });
});
const StyledButton = (0, styles_namespaceObject.styled)(Button_default(), {
    shouldForwardProp: (prop)=>'customSize' !== prop && 'customWidth' !== prop
})(({ customSize, customWidth })=>({
        '--border-radius': apollo_core_default().Border.BorderRadiusM,
        '--focus-border-offset': "1px",
        '--focus-border-width': apollo_core_default().Border.BorderThickM,
        '--focus-border-radius': "calc( var(--border-radius) + var(--focus-border-offset) + var(--focus-border-width) )",
        '--focus-border-inset': "calc( -1 * (var(--focus-border-offset) + var(--focus-border-width) + 1px))",
        position: 'relative',
        borderRadius: 'var(--border-radius)',
        minWidth: 'fit-content' === customWidth ? void 0 : '120px',
        height: 'tall' === customSize ? apollo_core_default().Spacing.SpacingXxl : apollo_core_default().Spacing.SpacingXl,
        '&.loading': {
            pointerEvents: 'none'
        },
        ':before': {
            content: "''",
            boxSizing: 'border-box',
            position: 'absolute',
            inset: "var(--focus-border-inset)",
            border: "var(--focus-border-width) solid var(--color-focus-indicator)",
            borderRadius: 'var(--focus-border-radius)',
            pointerEvents: 'none',
            display: 'none'
        },
        ':focus-visible': {
            outline: 'none',
            ':before': {
                display: 'block'
            }
        }
    }));
const StyledCircularProgress = (0, styles_namespaceObject.styled)(material_namespaceObject.CircularProgress)({
    color: 'inherit !important',
    stroke: 'currentColor !important'
});
function ButtonLoadingIndicator(props) {
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(StyledCircularProgress, {
        size: 16,
        ...props,
        className: props.className
    });
}
ApButton.displayName = 'ApButton';
exports.ApButton = __webpack_exports__.ApButton;
for(var __rspack_i in __webpack_exports__)if (-1 === [
    "ApButton"
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
Object.defineProperty(exports, '__esModule', {
    value: true
});
