import ViewUI from 'view-ui-plus';
import iviewCoustom from './static/iview/coustom';
import pkg from '../package.json';
// import 'view-ui-plus/dist/styles/viewuiplus.css'
/** 自定义封装 */
// import './styles/components/iconfont/index.js';
import Method from './method/index';
import store from './store/index';
import 'viewerjs/dist/viewer.css';
import '@vueup/vue-quill/dist/vue-quill.snow.css';
import { Ebutton, Toolbar } from './components/toolbar';
import ComboBox from './components/combobox';
import {
    ExpandRow,
    EditGrid,
    ViewGrid,
    ViewGridBase,
    EditGridCard,
} from './components/grid';
import TextBox from './components/textbox';
import RichTextBox from './components/richtextbox';
import { NumberBox, NumberRangeBox,NumberBoxV1 } from './components/numberbox';
import { DateBox, DateRangeBox,DateBoxV1 } from './components/datebox';
import TimePicBox from './components/timebox';
import PopTextBox from './components/poptextbox';
import { ControlBox, ControlBase} from './components/base';
import {
    ConditionBox,
    QueryConditionBoxBase,
    ConditionSelectorBox,
    ConditionFilterBox,
} from './components/conditionbox';
import {PictureBox,FileBox} from './components/picturebox';
import VideoBox from './components/videobox';
import { CheckBox, CheckGroupBox } from './components/checkbox';
import {
    FormBox,
    FormDetail,
    WorkForm,
    BaseForm,
    FormCardBox,
    FormCardGroupBox,
    DetailsBox,
} from './components/form';
import ShowText from './components/label';
import BillImport  from './components/upload';
import { TreeBox, TreeBoxBase } from './components/tree';
import CommonIcon  from './components/icon';
import BillBox from './components/billbox';
import RadioGroupBox  from './components/radiobox';
import ColorBox from './components/colorbox';
import {
    MyBar,
    MyPie,
    MyBarLine,
    MyLine,
    MyScatter,
    MyGauge,
    MyRadar,
    MyLiquidFill
} from './components/mychart';
import PopTagBox from './components/poptagbox';
import CascaderBox from './components/cascaderbox';

import {
    RowBtnToolbar,
    PageCustom,
    SimpleViewGrid,
    DetailBtnToolbar,
    BillTemplate,
    SimpleTree,
    mListDetails,
    mLeftListRightDetails,
    mLeftTreeRightDetails,
    mLeftListRightList,
    mBillSingleGrid,
    mReportBill,
    mLevelReport,
    mBirtReport,
    ListBtnToolbar,
    mAppendixBoxs,
    PromptMessages,
    BillOperLog,
    mFormCardBox,
    mEditGridCard,
    mBillAsyncImport,
    mBillImport,
    mBillListDetails,
    mListDetailsV2,
    mListDetailsV3
} from './components/masterplate';

import MapBox from './components/map';
import wRichTextBox from './components/wrichtextbox';

import VXETable from "./plugins/vxeTable";
import XEUtils from "xe-utils";

const components = {
    /*自定义组件*/
   Ebutton,
   Toolbar,
   ComboBox,
   ExpandRow,
   EditGrid,
   ViewGridBase,
   ViewGrid,
   EditGridCard,
   TextBox,
   RichTextBox,
   NumberBox,
   NumberRangeBox,
   DateBox,
   DateRangeBox,
   TimePicBox,
   PopTextBox,
   ControlBox,
   ControlBase,
   ConditionBox,
   QueryConditionBoxBase,
   ConditionSelectorBox,
   ConditionFilterBox,
   FormBox,
   FormDetail,
   WorkForm,
   FormCardBox,
   FormCardGroupBox,
   DetailsBox,
   PictureBox,
   FileBox,
   VideoBox,
   CheckBox,
   CheckGroupBox,
   BillBox,
   ShowText,
   BillImport,
   TreeBoxBase,
   TreeBox,
   CommonIcon,
   RadioGroupBox,
   BaseForm,
   MyBar,
   MyBarLine,
   MyPie,
   MyLine,
   MyScatter,
   MyGauge,
   MyRadar,
   MyLiquidFill,
   PopTagBox,
   CascaderBox,
   ColorBox,
   RowBtnToolbar,
   PageCustom,
   DetailBtnToolbar,
   BillTemplate,
   SimpleViewGrid,
   SimpleTree,
   mListDetails,
   mLeftListRightDetails,
   mLeftTreeRightDetails,
   mLeftListRightList,
   mBillSingleGrid,
   mReportBill,
   mLevelReport,
   mBirtReport,
   ListBtnToolbar,
   mAppendixBoxs,
   MapBox,
   PromptMessages,
   BillOperLog,
   mFormCardBox,
   mEditGridCard,
   mBillAsyncImport,
   mBillImport,
   wRichTextBox,
   mBillListDetails,
   NumberBoxV1,
   mListDetailsV2,
   DateBoxV1,
   mListDetailsV3
};

import { setupCopyFormatRestore } from './plugins/copyFormatRestore'

const iview = {
    ...components
};



const install = function(app, opts = {}) {
    if (install.installed) return;

    setupCopyFormatRestore()

    VXETable.install(app)
    app.config.globalProperties.$utils = XEUtils;

    iviewCoustom.initEview(ViewUI);
    app.use(ViewUI);
    Object.keys(iview).forEach(key => {
        app.component(key, iview[key]);
    });


    /**自定义方法**/
    app.config.globalProperties.$Method = Method.commonMethod;
    app.config.globalProperties.$Store = store;
    app.config.globalProperties.query = Method.query;
    app.config.globalProperties.BillTemplate = components.BillTemplate;
    for (let v in Method.caseMethod) {
        app.config.globalProperties[v] = Method.caseMethod[v];
    }
};

// auto install
if (typeof window !== 'undefined' && window.Vue) {
    install(window.Vue);
}

const API = {
    version: pkg.version, // eslint-disable-line no-undef
    install,
    //...ViewUI,
    ...components
};

/*API.lang = (code) => {
    const langObject = window['iview/locale'].default;
    if (code === langObject.i.locale) locale.use(langObject);
    else console.log(`The ${code} language pack is not loaded.`); // eslint-disable-line no-console
};*/

export default API;   // eslint-disable-line no-undef
