export * from "./components";
import * as components from "./components";
import config from './constants/config'
import * as directives from './directives'

import pkg from "../package.json";
import ViewUI from "view-ui-plus";

export const install = function (app, opts = {}) {
  if (install.installed) return;
  Object.keys(directives).forEach(key => {
    app.directive(key, directives[key]);
  });
  app.use(ViewUI);
  Object.keys(components).forEach((key) => {
    app.component(key, components[key]);
  });
  setConfig(opts)
};

export const setConfig = opts => {
  let {BASE_URL, PUBLIC_USER, USER} = opts
  BASE_URL && (config.BASE_URL = BASE_URL)
  PUBLIC_USER && (config.PUBLIC_USER = PUBLIC_USER)
  USER && (config.USER = USER)
}

export const version = pkg.version;

const API = {
  version,
  install,
  ...components,
  setConfig
};

export default API;
