import { App } from "vue";
import PageHeader from "./components/page-header/PageHeader.vue";
import LeftMenu from "./components/left-menu/LeftMenu.vue";
import BreadcrumbNav from "./components/breadcrumb-nav/BreadcrumbNav.vue";
import Login from "./components/auth/Login.vue";
import { routeTopologyService } from "./services/route-topology.service";
import { breadcrumbNavService } from "./services/breadcrumb-nav.service";
import { OauthConfig } from "./model/domain/OauthConfig";
import { CoreConfig } from "./model/domain/CoreConfig";
import { oauthService } from "./services/oauth.service";
import { coreEventService } from "./services/core-event.service";
import { userStore } from "./stores/user.store";
import antdVueService from "./services/antd-vue.service";
import { AuthType } from "./constants/enum/auth-type.enum";
import { SCOPE, STATE } from "./constants/config/oauth.config";
import "./styles/index.scss";
export * from "./components/index";
export * from "./constants/index";
export * from "./model/index";
export * from "./services/index";
export * from "./stores/index";
export * from "./types/dc";

const components: any = {
  PageHeader: PageHeader,
  LeftMenu: LeftMenu,
  BreadcrumbNav: BreadcrumbNav,
  Login: Login,
};
const install: any = (app: App, option: CoreConfig) => {
  if (install.installed) {
    return;
  }
  install.installed = true;
  Object.keys(components).forEach((key) => {
    app.component(key, components[key]);
  });

  // 初始化授权类型
  option.authPreferTo = option.authPreferTo ? option.authPreferTo : AuthType.OAUTH.code;

  // 初始化oauth的基本数据
  const oauthConfig: OauthConfig = new OauthConfig(option.oauth);
  oauthConfig.scope = oauthConfig.scope ? oauthConfig.scope : SCOPE;
  oauthConfig.state = oauthConfig.state ? oauthConfig.state : STATE;

  // app.use(Contextmenu as any);
  app.config.globalProperties.$dc = {
    sysId: option.sysId || "",
    baseApi: option.baseApi || "",
    authPreferTo: option.authPreferTo,
    oauth: oauthConfig,
    cas: option.cas,
    wxQyOauth: option.wxQyOauth,
  };
  app.config.globalProperties.$breadcrumbNavService = breadcrumbNavService;
  app.config.globalProperties.$routeTopologyService = routeTopologyService;
  app.config.globalProperties.$oauthService = oauthService;
  app.config.globalProperties.$userStore = userStore;
  app.config.globalProperties.$coreEventService = coreEventService;

  app.use(antdVueService);
};

const VueDc = {
  install,
};
export default VueDc;
