import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { ADAPTER_STATUS, log } from "@web3auth/base";
import { useEffect } from "react";
import { MODAL_STATUS } from "../interfaces";
import Icon from "./Icon";
const closeIcon = _jsx(Icon, { iconName: "close" });
export default function Loader(props) {
    const { message, modalStatus, label, onClose, canEmit = true } = props;
    useEffect(() => {
        log.debug("loader re-rendering");
        if (modalStatus === MODAL_STATUS.CONNECTED && canEmit) {
            setTimeout(() => {
                onClose();
            }, 3000);
        }
    }, [canEmit, modalStatus, onClose]);
    return modalStatus !== MODAL_STATUS.INITIALIZED ? (_jsxs("div", Object.assign({ className: "w3ajs-modal-loader w3a-modal__loader" }, { children: [_jsx("div", Object.assign({ className: "w3a-modal__loader-content" }, { children: _jsxs("div", Object.assign({ className: "w3a-modal__loader-info" }, { children: [modalStatus === MODAL_STATUS.CONNECTING && (_jsxs("div", Object.assign({ className: "w3ajs-modal-loader__spinner w3a-spinner" }, { children: [_jsx("div", { className: "w3a-spinner__head" }), _jsx("div", { className: "w3a-spinner__mask" })] }))), _jsx("div", Object.assign({ className: "w3ajs-modal-loader__label w3a-spinner-label" }, { children: label })), modalStatus === ADAPTER_STATUS.CONNECTED && _jsx("div", Object.assign({ className: "w3ajs-modal-loader__message w3a-spinner-message" }, { children: message })), modalStatus === ADAPTER_STATUS.ERRORED && (_jsx("div", Object.assign({ className: "w3ajs-modal-loader__message w3a-spinner-message w3a-spinner-message--error" }, { children: message })))] })) })), (modalStatus === ADAPTER_STATUS.CONNECTED || modalStatus === ADAPTER_STATUS.ERRORED) && (_jsx("button", Object.assign({ type: "button", className: "w3a-header__button w3ajs-loader-close-btn", onClick: onClose }, { children: closeIcon })))] }))) : null;
}
//# sourceMappingURL=Loader.js.map