"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
var __rest = (this && this.__rest) || function (s, e) {
    var t = {};
    for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
        t[p] = s[p];
    if (s != null && typeof Object.getOwnPropertySymbols === "function")
        for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
            if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
                t[p[i]] = s[p[i]];
        }
    return t;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.SnackBar = void 0;
const react_1 = __importStar(require("react"));
const styled_components_1 = __importDefault(require("styled-components"));
const Grid_1 = require("../Grid");
const Box_1 = require("../Box");
const Icon_1 = require("../Icon");
const LinkButton_1 = require("../LinkButton");
const Text_1 = require("../Text");
const icons_1 = require("../../assets/images/icons");
const iconMap = {
    alert: icons_1.SvgCloseCircle,
    success: icons_1.SvgCheckboxMarkedCircle,
    warning: icons_1.SvgWarning,
    info: icons_1.SvgInfo,
};
const BarWrapper = styled_components_1.default(Grid_1.Grid) `
  position: fixed;
  top: 15px;
  left: 50%;
  transform: translateX(-50%) translateY(-150%);
  z-index: 9999;
  color: ${({ theme }) => theme.colors.white};
  transition: transform 0.3s;

  &.show {
    transform: translateX(-50%);
  }
`;
exports.SnackBar = (_a) => {
    var { variant = 'info', details, onDismiss } = _a, boxProps = __rest(_a, ["variant", "details", "onDismiss"]);
    const [show, setShow] = react_1.useState(false);
    const defaultBoxProps = {
        bg: variant,
        borderRadius: '3',
        boxShadow: '5',
        p: '4',
        width: '100%',
        maxWidth: 504,
    };
    const dismiss = () => {
        setShow(false);
        if (onDismiss)
            onDismiss();
    };
    react_1.useEffect(() => {
        setShow(!!details);
    }, [details]);
    react_1.useEffect(() => {
        let dismissTimout;
        if (details) {
            dismissTimout = setTimeout(() => {
                dismiss();
            }, 10000);
        }
        return () => {
            if (dismissTimout)
                clearTimeout(dismissTimout);
        };
    }, [details, dismiss]);
    return (react_1.default.createElement(BarWrapper, Object.assign({ className: show ? 'show' : null, gridTemplateColumns: "20px 1fr auto" }, Object.assign(Object.assign({}, defaultBoxProps), boxProps)),
        react_1.default.createElement(Icon_1.Icon, { Asset: iconMap[variant], width: 20, height: 20, color: "white" }),
        react_1.default.createElement(Box_1.Box, null, details),
        react_1.default.createElement(LinkButton_1.LinkButton, { onClick: dismiss },
            react_1.default.createElement(Text_1.Text, { color: "white", fontSize: "0" }, "DISMISS"))));
};
//# sourceMappingURL=SnackBar.js.map