function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
import React, { useEffect, useImperativeHandle, useState, forwardRef } from 'react';
import { AnimatePresence, motion } from 'framer-motion';
import { Flexbox } from '../..';
import { BoxContainer, StyledTypography } from './ToastMessage.styled';
var ToastMessages = forwardRef(function (_ref, ref) {
  var label = _ref.label,
    icon = _ref.icon,
    linkButton = _ref.linkButton,
    _ref$isVisible = _ref.isVisible,
    isVisible = _ref$isVisible === void 0 ? false : _ref$isVisible,
    _ref$key = _ref.key,
    key = _ref$key === void 0 ? 'toast' : _ref$key,
    _ref$timeout = _ref.timeout,
    timeout = _ref$timeout === void 0 ? 6000 : _ref$timeout;
  var _useState = useState(isVisible),
    _useState2 = _slicedToArray(_useState, 2),
    visible = _useState2[0],
    setVisibility = _useState2[1];
  var _useState3 = useState(false),
    _useState4 = _slicedToArray(_useState3, 2),
    mouseEnter = _useState4[0],
    setMouseEnter = _useState4[1];
  useImperativeHandle(ref, function () {
    return {
      setVisible: function setVisible() {
        setVisibility(true);
      }
    };
  });
  useEffect(function () {
    if (mouseEnter) {
      setVisibility(true);
    }
  }, [mouseEnter]);
  useEffect(function () {
    if (typeof ref === 'undefined' || ref === null) {
      setVisibility(function (prevValue) {
        return prevValue || isVisible;
      });
    }
  }, [isVisible, ref]);
  useEffect(function () {
    var timer = setTimeout(function () {
      if (visible && !mouseEnter) {
        setVisibility(false);
      }
    }, timeout);
    return function () {
      return clearTimeout(timer);
    };
  }, [timeout, visible, mouseEnter]);
  return React.createElement(AnimatePresence, {
    mode: "wait"
  }, visible && React.createElement(motion.div, {
    key: key,
    initial: {
      opacity: 0
    },
    animate: {
      opacity: 1
    },
    exit: {
      opacity: 0
    },
    transition: {
      duration: 0.35,
      ease: 'easeInOut'
    }
  }, React.createElement(BoxContainer, {
    onMouseEnter: function onMouseEnter() {
      return setMouseEnter(true);
    },
    onMouseLeave: function onMouseLeave() {
      return setMouseEnter(false);
    }
  }, React.createElement(Flexbox, {
    container: true,
    alignItems: "center",
    gap: 6,
    align: "center"
  }, React.createElement(Flexbox, {
    item: true,
    container: true,
    gap: 3
  }, icon && React.createElement(Flexbox, {
    item: true
  }, icon), React.createElement(Flexbox, {
    item: true
  }, React.createElement(StyledTypography, {
    type: "primary",
    weight: "bold"
  }, label))), linkButton && React.createElement(Flexbox, {
    item: true
  }, linkButton)))));
});
export default ToastMessages;