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 ownKeys(object, enumerableOnly) {
    var keys = Object.keys(object);
    if (Object.getOwnPropertySymbols) {
        var symbols = Object.getOwnPropertySymbols(object);
        if (enumerableOnly) {
            symbols = symbols.filter(function(sym) {
                return Object.getOwnPropertyDescriptor(object, sym).enumerable;
            });
        }
        keys.push.apply(keys, symbols);
    }
    return keys;
}
function _object_spread_props(target, source) {
    source = source != null ? source : {};
    if (Object.getOwnPropertyDescriptors) {
        Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
    } else {
        ownKeys(Object(source)).forEach(function(key) {
            Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(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, { forwardRef } from "react";
import toast, { Toaster, resolveValue } from "react-hot-toast";
import { tokens } from "../Toast.tokens";
import { IconCrossThin } from "../../_Icon/Icons/IconCrossThin";
import { base, Toast, CloseIconWrapper, StyledContentLeft } from "./ToastNew.styles";
export var toastContainerRoot = function toastContainerRoot(Root) {
    return /*#__PURE__*/ forwardRef(function(props, ref) {
        var _props_hasClose = props.hasClose, hasClose = _props_hasClose === void 0 ? true : _props_hasClose, view = props.view, size = props.size, pilled = props.pilled, contentLeft = props.contentLeft, width = props.width, textColor = props.textColor, _props_position = props.position, position = _props_position === void 0 ? 'bottom-center' : _props_position, _props_duration = props.duration, duration = _props_duration === void 0 ? Infinity : _props_duration, onCloseButtonClick = props.onCloseButtonClick, rest = _object_without_properties(props, [
            "hasClose",
            "view",
            "size",
            "pilled",
            "contentLeft",
            "width",
            "textColor",
            "position",
            "duration",
            "onCloseButtonClick"
        ]);
        return /*#__PURE__*/ React.createElement(Root, _object_spread({
            ref: ref,
            view: view,
            size: size,
            pilled: pilled
        }, rest), /*#__PURE__*/ React.createElement(Toaster, {
            toastOptions: {
                duration: duration,
                position: position
            }
        }, function(options) {
            var _ref;
            var _options_plasmaOptions, _options_plasmaOptions1, _options_plasmaOptions2, _options_plasmaOptions3, _options_plasmaOptions4, _options_plasmaOptions5, _options_plasmaOptions6, _options_plasmaOptions7, _options_plasmaOptions8;
            return /*#__PURE__*/ React.createElement(Root, {
                view: (_options_plasmaOptions = options.plasmaOptions) === null || _options_plasmaOptions === void 0 ? void 0 : _options_plasmaOptions.view,
                size: (_options_plasmaOptions1 = options.plasmaOptions) === null || _options_plasmaOptions1 === void 0 ? void 0 : _options_plasmaOptions1.size,
                pilled: (_options_plasmaOptions2 = options.plasmaOptions) === null || _options_plasmaOptions2 === void 0 ? void 0 : _options_plasmaOptions2.pilled
            }, /*#__PURE__*/ React.createElement(Toast, {
                style: {
                    opacity: options.visible ? 1 : 0
                },
                width: ((_options_plasmaOptions3 = options.plasmaOptions) === null || _options_plasmaOptions3 === void 0 ? void 0 : _options_plasmaOptions3.width) || width,
                textColor: ((_options_plasmaOptions4 = options.plasmaOptions) === null || _options_plasmaOptions4 === void 0 ? void 0 : _options_plasmaOptions4.textColor) || textColor
            }, (((_options_plasmaOptions5 = options.plasmaOptions) === null || _options_plasmaOptions5 === void 0 ? void 0 : _options_plasmaOptions5.contentLeft) || contentLeft) && /*#__PURE__*/ React.createElement(StyledContentLeft, null, ((_options_plasmaOptions6 = options.plasmaOptions) === null || _options_plasmaOptions6 === void 0 ? void 0 : _options_plasmaOptions6.contentLeft) || contentLeft), resolveValue(options.message, options), (((_options_plasmaOptions7 = options.plasmaOptions) === null || _options_plasmaOptions7 === void 0 ? void 0 : _options_plasmaOptions7.hasClose) || ((_ref = (_options_plasmaOptions8 = options.plasmaOptions) === null || _options_plasmaOptions8 === void 0 ? void 0 : _options_plasmaOptions8.hasClose) !== null && _ref !== void 0 ? _ref : hasClose)) && /*#__PURE__*/ React.createElement(CloseIconWrapper, {
                view: "clear",
                size: "s",
                stretching: "fixed",
                onClick: function onClick() {
                    if (onCloseButtonClick) {
                        onCloseButtonClick();
                    }
                    toast.dismiss(options.id);
                }
            }, /*#__PURE__*/ React.createElement(IconCrossThin, {
                size: "s",
                color: "inherit",
                sizeCustomProperty: tokens.closeIconSize
            }))));
        }));
    });
};
export var showToast = function showToast(text, options) {
    toast(text, _object_spread_props(_object_spread({
        // INFO: id всегда одинаковый для отключения стекирования
        id: 'toast'
    }, (options === null || options === void 0 ? void 0 : options.position) ? {
        position: options === null || options === void 0 ? void 0 : options.position
    } : undefined, (options === null || options === void 0 ? void 0 : options.duration) ? {
        duration: options === null || options === void 0 ? void 0 : options.duration
    } : undefined), {
        // @ts-ignore
        plasmaOptions: {
            view: options === null || options === void 0 ? void 0 : options.view,
            size: options === null || options === void 0 ? void 0 : options.size,
            pilled: options === null || options === void 0 ? void 0 : options.pilled,
            contentLeft: options === null || options === void 0 ? void 0 : options.contentLeft,
            hasClose: options === null || options === void 0 ? void 0 : options.hasClose,
            width: options === null || options === void 0 ? void 0 : options.width,
            textColor: options === null || options === void 0 ? void 0 : options.textColor
        }
    }));
};
export var toastContainerConfig = {
    name: 'ToastContainer',
    tag: 'div',
    layout: toastContainerRoot,
    base: base,
    variations: {
        view: {
            css: ''
        },
        size: {
            css: ''
        },
        pilled: {
            css: '',
            attrs: true
        }
    },
    defaults: {
        view: 'default',
        size: 'm'
    }
};
