var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
    if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
        if (ar || !(i in from)) {
            if (!ar) ar = Array.prototype.slice.call(from, 0, i);
            ar[i] = from[i];
        }
    }
    return to.concat(ar || Array.prototype.slice.call(from));
};
import createCache from '@emotion/cache';
export var createShadowElement = function (_a) {
    var container = _a.container, className = _a.className;
    var shadowRoot = container.attachShadow({ mode: 'open' });
    var emotionRoot = document.createElement('style');
    var fontLink = document.createElement('link');
    fontLink.href = 'https://fonts.googleapis.com/css?family=Josefin+Sans';
    fontLink.rel = 'stylesheet';
    fontLink.type = 'text/css';
    var mountPoint = document.createElement('div');
    mountPoint.classList.add(className);
    var root = shadowRoot.appendChild(mountPoint);
    shadowRoot.insertBefore(fontLink, mountPoint);
    shadowRoot.insertBefore(emotionRoot, mountPoint);
    var cache = createCache({
        key: 'css',
        prepend: true,
        container: emotionRoot,
    });
    return {
        cache: cache,
        root: root,
        shadowRoot: shadowRoot,
        mountPoint: mountPoint,
    };
};
export var extractAttributes = function (nodeMap) {
    if (!nodeMap.attributes) {
        return {};
    }
    var obj = {};
    var attribute;
    var attributesAsNodeMap = __spreadArray([], nodeMap.attributes, true);
    console.log(attributesAsNodeMap);
    var attributes = attributesAsNodeMap.map(function (attr) {
        var _a;
        return _a = {}, _a[attr.name] = attr.value, _a;
    });
    for (var _i = 0, attributes_1 = attributes; _i < attributes_1.length; _i++) {
        attribute = attributes_1[_i];
        var key = Object.keys(attribute)[0];
        var camelCasedKey = key.replace(/-([a-z])/g, function (g) { return g[1].toUpperCase(); });
        obj[camelCasedKey] = attribute[key];
    }
    return obj;
};
export var isElement = function (obj) {
    try {
        return obj instanceof HTMLElement;
    }
    catch (e) {
        return typeof obj === 'object' && obj.nodeType === 1 && typeof obj.style === 'object' && typeof obj.ownerDocument === 'object';
    }
};
