function _array_like_to_array(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 _array_with_holes(arr) {
    if (Array.isArray(arr)) return arr;
}
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 _iterable_to_array_limit(arr, i) {
    var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
    if (_i == null) return;
    var _arr = [];
    var _n = true;
    var _d = false;
    var _s, _e;
    try {
        for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
            _arr.push(_s.value);
            if (i && _arr.length === i) break;
        }
    } catch (err) {
        _d = true;
        _e = err;
    } finally{
        try {
            if (!_n && _i["return"] != null) _i["return"]();
        } finally{
            if (_d) throw _e;
        }
    }
    return _arr;
}
function _non_iterable_rest() {
    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 _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 _sliced_to_array(arr, i) {
    return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
}
function _type_of(obj) {
    "@swc/helpers - typeof";
    return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
}
function _unsupported_iterable_to_array(o, minLen) {
    if (!o) return;
    if (typeof o === "string") return _array_like_to_array(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(n);
    if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
}
import React, { useState, useCallback } from 'react';
import { ToastController } from './ToastController';
import { ToastContext } from './ToastContext';
var DEFAULT_POSITION = 'bottom';
var DEFAULT_TIMEOUT = 3000;
var DEFAULT_FADE = true;
var getShowToastCallSignature = function getShowToastCallSignature(args) {
    if (_type_of(args[0]) === 'object' && 'text' in args[0]) {
        return args[0];
    }
    // TODO: issue https://github.com/salute-developers/plasma/issues/333
    var _args = _sliced_to_array(args, 6), text = _args[0], position = _args[1], timeout = _args[2], fade = _args[3], contentLeft = _args[4], role = _args[5];
    return {
        text: text,
        position: position,
        timeout: timeout,
        fade: fade,
        contentLeft: contentLeft,
        role: role
    };
};
export var ToastProvider = function ToastProvider(param) {
    var children = param.children;
    var _useState = _sliced_to_array(useState({
        text: null,
        position: null,
        timeout: null
    }), 2), value = _useState[0], setValue = _useState[1];
    var showToastCallback = function showToastCallback() {
        for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
            args[_key] = arguments[_key];
        }
        var _getShowToastCallSignature = getShowToastCallSignature(args), text = _getShowToastCallSignature.text, _getShowToastCallSignature_position = _getShowToastCallSignature.position, position = _getShowToastCallSignature_position === void 0 ? DEFAULT_POSITION : _getShowToastCallSignature_position, _getShowToastCallSignature_timeout = _getShowToastCallSignature.timeout, timeout = _getShowToastCallSignature_timeout === void 0 ? DEFAULT_TIMEOUT : _getShowToastCallSignature_timeout, _getShowToastCallSignature_fade = _getShowToastCallSignature.fade, fade = _getShowToastCallSignature_fade === void 0 ? DEFAULT_FADE : _getShowToastCallSignature_fade, contentLeft = _getShowToastCallSignature.contentLeft, role = _getShowToastCallSignature.role, onHide = _getShowToastCallSignature.onHide, onShow = _getShowToastCallSignature.onShow, offset = _getShowToastCallSignature.offset;
        setValue({
            text: text,
            position: position,
            timeout: timeout,
            fade: fade,
            contentLeft: contentLeft,
            role: role,
            onHide: onHide,
            onShow: onShow,
            offset: offset
        });
        if (onShow) {
            onShow();
        }
    };
    var showToast = useCallback(showToastCallback, []);
    var onHide = value.onHide;
    var hideToast = useCallback(function() {
        setValue({
            text: null,
            position: null,
            timeout: null
        });
        if (onHide) {
            onHide();
        }
    }, [
        onHide
    ]);
    return /*#__PURE__*/ React.createElement(ToastContext.Provider, {
        value: _object_spread_props(_object_spread({}, value), {
            showToast: showToast,
            hideToast: hideToast
        })
    }, children, /*#__PURE__*/ React.createElement(ToastController, value));
};
