import { extends as _extends } from '../../../_virtual/_rollupPluginBabelHelpers.js';
import { jsx } from '@emotion/core';
import { useMemo } from 'react';
import _pt from 'prop-types';
import { Toast } from './Toast.esm.js';
import { ToastContext } from './ToastContext.esm.js';
import { useToastActions } from './hooks.esm.js';

var ToastConsumer = ToastContext.Consumer;

var containerCss = function containerCss(theme) {
  return {
    alignItems: "center",
    bottom: 0,
    display: "flex",
    flexDirection: "column-reverse",
    left: "50%",
    position: "fixed",
    transform: "translate(-50%, 0)",
    width: "100%",
    zIndex: theme.zIndices.base
  };
};

var ToastProvider = function ToastProvider(_ref) {
  var children = _ref.children,
      _ref$closeButtonLabel = _ref.closeButtonLabel,
      closeButtonLabel = _ref$closeButtonLabel === void 0 ? "Close" : _ref$closeButtonLabel;

  var _useToastActions = useToastActions(),
      toasts = _useToastActions.toasts,
      showToast = _useToastActions.showToast,
      removeToast = _useToastActions.removeToast;

  var contextValue = useMemo(function () {
    return {
      showToast: showToast
    };
  }, [showToast]);
  return jsx(ToastContext.Provider, {
    value: contextValue
  }, children, jsx("div", {
    css: containerCss
  }, toasts.map(function (toast, index) {
    return jsx(Toast, _extends({
      key: "toast-".concat(index) // this is probably not the best, but we can't use symbol as key :(

    }, toast, {
      onClose: function onClose() {
        return removeToast(toast.id);
      },
      closeButtonLabel: closeButtonLabel || "close"
    }));
  })));
};
ToastProvider.propTypes = {
  closeButtonLabel: _pt.string
};
ToastProvider.__docgenInfo = {
  "description": "",
  "methods": [],
  "displayName": "ToastProvider",
  "props": {
    "closeButtonLabel": {
      "defaultValue": {
        "value": "`Close`",
        "computed": false
      },
      "required": false
    }
  }
};

if (typeof STORYBOOK_REACT_CLASSES !== "undefined") {
  STORYBOOK_REACT_CLASSES["src/components/Toast/ToastProvider.tsx"] = {
    name: "ToastProvider",
    docgenInfo: ToastProvider.__docgenInfo,
    path: "src/components/Toast/ToastProvider.tsx"
  };
}

export { ToastConsumer, ToastProvider };
//# sourceMappingURL=ToastProvider.esm.js.map
