/*
 * @Author: zhangzc
 * @Email: zhangzc2@guahao.com
 * @Date: 2019-04-25 14:39:21
 * @Last Modified by: mikey.zhaopeng
 * @Last Modified time: 2022-05-09 17:13:01
 * @Description: 组件集成挂载输出
 */
// 页面组件
import BkList from 'pc/bk-list';
import BkForm from 'pc/bk-form';
import BkFormMaterial from 'pc/bk-form-material';
import BkContrast from 'pc/bk-contrast';

// 元组件/物料组件
import BkImageViewer from 'mc/image-viewer';
import BkUpload from 'mc/upload/index';
import BkUploadBlock from 'mc/upload_block/index';
import BkDialog from 'mc/dialog';
import BkTitle from 'mc/title';
// import BkDialogList from 'mc/dialog-list';
import BkAreaSelect from 'mc/area-select';
// import BkListSelect from 'mc/list-select';
import BkSelectContent from 'mc/select-content';
// import BkDialogListSelect from 'mc/dialog-list-select';
import BkImageCode from 'mc/image-code';
import BkPhoneCode from 'mc/phone-code';
import BkContrastMaterial from 'mc/contrast-material';
// import BkFormCopy from 'mc/form-copy';
import BkButton from 'mc/button';
import BkAnchorLocationTag from 'mc/bk-anchor-location-tag';
import BkSlot from 'mc/slot';
import BkPdfViewer from 'mc/pdf-viewer';
import BkPdfReader from 'mc/pdf-reader';
import BkEditor from 'mc/editor';
import BKTableFooter from 'mc/table-footer/el-table-footer';
import BkAddressSelect from 'mc/bk-address-select';
import BKListAlert from 'mc/list-alert';
import BkTableHeaderIcons from 'mc/table-header-icons';

import localForage from 'localforage';
import { isIE } from './utils/util';

const pkg = require('../package.json');

const components = [
    BkList,
    BkForm,
    BkContrast,
    BkImageViewer,
    BkUpload,
    BkUploadBlock,
    BkDialog,
    BkTitle,
    BkFormMaterial,
    // BkDialogList,
    BkEditor,
    BkAreaSelect,
    // BkListSelect,
    BkSelectContent,
    // BkDialogListSelect,
    BkImageCode,
    BkPhoneCode,
    BkContrastMaterial,
    // BkFormCopy,
    BkButton,
    BkAnchorLocationTag,
    BkSlot,
    BkPdfViewer,
    BkPdfReader,
    BKTableFooter,
    BkAddressSelect,
    BKListAlert,
    BkTableHeaderIcons
];

const install = Vue => {
    if (isIE()) {
        localForage.setDriver(localForage.LOCALSTORAGE);
    }
    window.localForage = localForage;
    components.forEach(component => (
        Vue.component(component.name, component)
    ));
    // 浏览器兼容
    /* eslint consistent-return: 'off' */
    /* eslint func-names: 'off' */
    const getExplorer = (function () {
        const explorer = window.navigator.userAgent;
        const compare = function (s) { return (explorer.indexOf(s) >= 0); };
        const ie11 = (function () { return ('ActiveXObject' in window); }());
        if (compare('MSIE') || ie11) { return 'ie'; }
        if (compare('Firefox') && !ie11) { return 'Firefox'; }
        if (compare('Chrome') && !ie11) { return 'Chrome'; }
        if (compare('Opera') && !ie11) { return 'Opera'; }
        if (compare('Safari') && !ie11) { return 'Safari'; }
    }());
    if (getExplorer === 'ie') {
        document.documentElement.className += 'ie';
    }
    // 处理singleSPA AMD引入导致XLSX异常的问题
    try {
        // eslint-disable-next-line
        const { make_xlsx_lib, XLSX } = window;
        window.addEventListener('single-spa:before-routing-event', () => {
            // eslint-disable-next-line
            if (make_xlsx_lib && XLSX && Object.getOwnPropertyNames(XLSX).length === 0) {
                make_xlsx_lib(XLSX);
            }
        });
    } catch (e) {
        console.error(e, '处理singleSPA AMD引入导致XLSX异常的问题');
    }
};

export default {
    version: pkg.version,
    install
};
