"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
function _export(target, all) {
    for(var name in all)Object.defineProperty(target, name, {
        enumerable: true,
        get: Object.getOwnPropertyDescriptor(all, name).get
    });
}
_export(exports, {
    get toastConfig () {
        return toastConfig;
    },
    get toastRoot () {
        return toastRoot;
    }
});
var _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
var _utils = require("../../utils");
var _IconCross = require("../_Icon/Icons/IconCross");
var _IconCrossThin = require("../_Icon/Icons/IconCrossThin");
var _Toasttokens = require("./Toast.tokens");
var _base = require("./variations/_view/base");
var _base1 = require("./variations/_size/base");
var _base2 = require("./variations/_pilled/base");
var _base3 = require("./variations/_closeIconType/base");
var _Toaststyles = require("./Toast.styles");
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 _getRequireWildcardCache(nodeInterop) {
    if (typeof WeakMap !== "function") return null;
    var cacheBabelInterop = new WeakMap();
    var cacheNodeInterop = new WeakMap();
    return (_getRequireWildcardCache = function(nodeInterop) {
        return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
    })(nodeInterop);
}
function _interop_require_wildcard(obj, nodeInterop) {
    if (!nodeInterop && obj && obj.__esModule) {
        return obj;
    }
    if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
        return {
            default: obj
        };
    }
    var cache = _getRequireWildcardCache(nodeInterop);
    if (cache && cache.has(obj)) {
        return cache.get(obj);
    }
    var newObj = {
        __proto__: null
    };
    var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
    for(var key in obj){
        if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
            var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
            if (desc && (desc.get || desc.set)) {
                Object.defineProperty(newObj, key, desc);
            } else {
                newObj[key] = obj[key];
            }
        }
    }
    newObj.default = obj;
    if (cache) {
        cache.set(obj, newObj);
    }
    return newObj;
}
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;
}
var toastRoot = function toastRoot(Root) {
    return /*#__PURE__*/ (0, _react.forwardRef)(function(props, ref) {
        var _props_role = props.role, role = _props_role === void 0 ? 'status' : _props_role, width = props.width, text = props.text, hasClose = props.hasClose, contentLeft = props.contentLeft, view = props.view, size = props.size, pilled = props.pilled, className = props.className, style = props.style, closeIconType = props.closeIconType, onCloseButtonClick = props.onCloseButtonClick, textColor = props.textColor, rest = _object_without_properties(props, [
            "role",
            "width",
            "text",
            "hasClose",
            "contentLeft",
            "view",
            "size",
            "pilled",
            "className",
            "style",
            "closeIconType",
            "onCloseButtonClick",
            "textColor"
        ]);
        var pilledClass = pilled ? _Toasttokens.classes.toastPilled : undefined;
        var fixedWidth = !Number.isNaN(Number(width)) ? "".concat(width, "%") : width;
        var ariaLive = 'polite';
        var ariaAtomic = false;
        if (role === 'alert') {
            ariaLive = 'assertive';
        } else if (role === 'status') {
            ariaAtomic = true;
        }
        return /*#__PURE__*/ _react.default.createElement(Root, _object_spread({
            view: view,
            size: size,
            pilled: pilled,
            closeIconType: closeIconType,
            className: (0, _utils.cx)(pilledClass, className),
            style: _object_spread({
                width: width ? fixedWidth : 'unset'
            }, style),
            ref: ref,
            role: role,
            "aria-live": ariaLive,
            "aria-atomic": ariaAtomic
        }, rest), contentLeft && /*#__PURE__*/ _react.default.createElement(_Toaststyles.StyledContentLeft, null, contentLeft), /*#__PURE__*/ _react.default.createElement(_Toaststyles.StyledContent, {
            textColor: textColor
        }, text), hasClose && /*#__PURE__*/ _react.default.createElement(_Toaststyles.CloseIconWrapper, {
            view: "clear",
            size: "s",
            onClick: onCloseButtonClick,
            className: (0, _utils.cx)(_Toasttokens.classes.closeIcon),
            stretching: "fixed"
        }, closeIconType === 'default' ? /*#__PURE__*/ _react.default.createElement(_IconCross.IconCross, {
            size: "s",
            sizeCustomProperty: _Toasttokens.tokens.closeIconSize,
            color: "inherit"
        }) : /*#__PURE__*/ _react.default.createElement(_IconCrossThin.IconCrossThin, {
            size: "s",
            sizeCustomProperty: _Toasttokens.tokens.closeIconSize,
            color: "inherit"
        })));
    });
};
var toastConfig = {
    name: 'Toast',
    tag: 'div',
    layout: toastRoot,
    base: _Toaststyles.base,
    variations: {
        view: {
            css: _base.base
        },
        size: {
            css: _base1.base
        },
        pilled: {
            css: _base2.base,
            attrs: true
        },
        closeIconType: {
            css: _base3.base
        }
    },
    defaults: {
        view: 'primary',
        size: 'm',
        closeIconType: 'default'
    }
};
