"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.AutoSaveIndicator = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const CrossOutlineMd_1 = require("../../icons/CrossOutlineMd");
const Popover_1 = require("../Popover");
const DefaultState_1 = require("./DefaultState");
const ErrorState_1 = require("./ErrorState");
const LoadingState_1 = require("./LoadingState");
const SuccessState_1 = require("./SuccessState");
const styles_1 = require("./styles");
const useLogic_1 = require("./useLogic");
const AutoSaveIndicator = (props) => {
    const { isSuccess, isError, isLoading, errorMsg, onRetry } = props;
    const { popoverProps, handleClose, ref } = (0, useLogic_1.useLogic)();
    const renderContent = () => {
        if (isLoading) {
            return (0, jsx_runtime_1.jsx)(LoadingState_1.LoadingState, {});
        }
        if (isError) {
            return (0, jsx_runtime_1.jsx)(ErrorState_1.ErrorState, { onRetry: onRetry, errorMsg: errorMsg });
        }
        if (isSuccess) {
            return (0, jsx_runtime_1.jsx)(SuccessState_1.SuccessState, {});
        }
        return (0, jsx_runtime_1.jsx)(DefaultState_1.DefaultState, {});
    };
    return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(styles_1.Wrapper, { ref: ref, children: renderContent() }), (0, jsx_runtime_1.jsx)(Popover_1.Popover, { ...popoverProps, anchorOrigin: {
                    vertical: 'bottom',
                    horizontal: 'center',
                }, transformOrigin: {
                    horizontal: 'center',
                    vertical: 'top',
                }, children: (0, jsx_runtime_1.jsxs)(styles_1.PopoverContent, { children: [(0, jsx_runtime_1.jsx)(styles_1.StyledTypography, { children: "\u0418\u0437\u043C\u0435\u043D\u0435\u043D\u0438\u044F \u043D\u0430 \u044D\u0442\u043E\u0439 \u0441\u0442\u0440\u0430\u043D\u0438\u0446\u0435 \u0441\u043E\u0445\u0440\u0430\u043D\u044F\u044E\u0442\u0441\u044F \u0430\u0432\u0442\u043E\u043C\u0430\u0442\u0438\u0447\u0435\u0441\u043A\u0438" }), (0, jsx_runtime_1.jsx)(styles_1.StyledIconButton, { variant: "text", onClick: handleClose, children: (0, jsx_runtime_1.jsx)(CrossOutlineMd_1.CrossOutlineMd, {}) })] }) })] }));
};
exports.AutoSaveIndicator = AutoSaveIndicator;
