"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.getAsyncComponent = getAsyncComponent;
exports.getElementAttributes = getElementAttributes;
exports.getElementTag = getElementTag;
var _parse = require("./parse");
/* -----------------------------------
 *
 * Async
 *
 * -------------------------------- */

function getAsyncComponent(component, tagName) {
  return component.then(response => getComponentResult(response, tagName));
}

/* -----------------------------------
 *
 * Result
 *
 * -------------------------------- */

function getComponentResult(response, tagName) {
  let result = void 0;
  if (typeof response === 'function') {
    return response;
  }
  if (typeof response === 'object') {
    result = response[getNameFromTag(tagName)] || void 0;
  }
  return result;
}

/* -----------------------------------
 *
 * Element
 *
 * -------------------------------- */

function getElementTag(tagName) {
  let result = tagName.toLowerCase();
  if (result.indexOf('-') < 0) {
    result = 'component-' + result;
  }
  return result;
}

/* -----------------------------------
 *
 * Tag
 *
 * -------------------------------- */

function getNameFromTag(value) {
  value = value.toLowerCase();
  return value.replace(/(^\w|-\w)/g, item => item.replace(/-/, '').toUpperCase());
}

/* -----------------------------------
 *
 * Attributes
 *
 * -------------------------------- */

function getElementAttributes() {
  const {
    attributes = []
  } = this.__options;
  const result = {};
  if (!this.hasAttributes()) {
    return result;
  }
  return (0, _parse.getAttributeProps)(this.attributes, attributes);
}

/* -----------------------------------
 *
 * Export
 *
 * -------------------------------- */