import Component from './component-class';
import parseComponent from './parse-component';
import customComponents from './custom-components';
import componentMixins from './component-mixins';

function registerComponentMixin(name, mixin) {
  componentMixins[name] = mixin;
}

function registerComponent(tagName, component) {
  customComponents[tagName] = component;
}

export { Component };
export default {
  name: 'component',
  static: {
    Component: Component,
    registerComponentMixin: registerComponentMixin,
    registerComponent: registerComponent
  },
  create: function create() {
    var app = this;
    app.component = {
      registerComponentMixin: registerComponentMixin,
      registerComponent: registerComponent,
      parse: function parse(componentString) {
        return parseComponent(componentString);
      },
      create: function create(options, context, children) {
        if (typeof options === 'function') {
          var root = options.root,
              el = options.el; // eslint-disable-next-line

          return new options(app, {
            isClassComponent: true,
            root: root,
            el: el
          }, context, children);
        }

        return new Component(app, options, context, children);
      }
    };
  }
};