function _define_property(obj, key, value) {
    if (key in obj) {
        Object.defineProperty(obj, key, {
            value: value,
            enumerable: true,
            configurable: true,
            writable: true
        });
    } else {
        obj[key] = value;
    }
    return obj;
}
function _object_spread(target) {
    for(var i = 1; i < arguments.length; i++){
        var source = arguments[i] != null ? arguments[i] : {};
        var ownKeys = Object.keys(source);
        if (typeof Object.getOwnPropertySymbols === "function") {
            ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
                return Object.getOwnPropertyDescriptor(source, sym).enumerable;
            }));
        }
        ownKeys.forEach(function(key) {
            _define_property(target, key, source[key]);
        });
    }
    return target;
}
function _object_without_properties(source, excluded) {
    if (source == null) return {};
    var target = {}, sourceKeys, key, i;
    if (typeof Reflect !== "undefined" && Reflect.ownKeys) {
        sourceKeys = Reflect.ownKeys(source);
        for(i = 0; i < sourceKeys.length; i++){
            key = sourceKeys[i];
            if (excluded.indexOf(key) >= 0) continue;
            if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
            target[key] = source[key];
        }
        return target;
    }
    target = _object_without_properties_loose(source, excluded);
    if (Object.getOwnPropertySymbols) {
        sourceKeys = Object.getOwnPropertySymbols(source);
        for(i = 0; i < sourceKeys.length; i++){
            key = sourceKeys[i];
            if (excluded.indexOf(key) >= 0) continue;
            if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
            target[key] = source[key];
        }
    }
    return target;
}
function _object_without_properties_loose(source, excluded) {
    if (source == null) return {};
    var target = {}, sourceKeys = Object.getOwnPropertyNames(source), key, i;
    for(i = 0; i < sourceKeys.length; i++){
        key = sourceKeys[i];
        if (excluded.indexOf(key) >= 0) continue;
        if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
        target[key] = source[key];
    }
    return target;
}
import React from "react";
import { classes } from "./Toast.tokens";
import { StyledOverlay, StyledRoot } from "./Toast.styles";
import { useToastInner } from "./ToastProvider";
import { FADE_Z_INDEX, gradients } from "./utils";
export var ToastControllerHoc = function ToastControllerHoc(ToastComponent) {
    return function ToastController(props) {
        var _props_position = props.position, position = _props_position === void 0 ? 'bottom' : _props_position, offset = props.offset, fade = props.fade, text = props.text, rest = _object_without_properties(props, [
            "position",
            "offset",
            "fade",
            "text"
        ]);
        var _useToastInner = useToastInner(), hideToast = _useToastInner.hideToast, isVisible = _useToastInner.isVisible;
        var toastKey = "".concat(text).concat(position);
        var showedClass = isVisible ? classes.toastShowed : classes.toastHidden;
        var showedFadeClass = isVisible ? classes.toastFadeShowed : classes.toastFadeHidden;
        var toastProps = _object_spread({
            text: text,
            onCloseButtonClick: hideToast
        }, rest);
        if (!text) {
            return null;
        }
        return /*#__PURE__*/ React.createElement(React.Fragment, null, fade && /*#__PURE__*/ React.createElement(StyledOverlay, {
            className: showedFadeClass,
            zIndex: FADE_Z_INDEX,
            backgroundColorProperty: gradients[position],
            isClickable: false
        }), /*#__PURE__*/ React.createElement(StyledRoot, {
            key: toastKey,
            position: position,
            offset: offset,
            isVisible: isVisible,
            className: showedClass
        }, /*#__PURE__*/ React.createElement(ToastComponent, toastProps)));
    };
};
