import XEUtils from 'xe-utils';
import GlobalConfig from '../../v-x-e-table/src/conf';
import { formats } from '../../v-x-e-table/src/formats';
import { toFilters } from './util';
import { getFuncText } from '../../tools/utils';
import { warnLog, errLog } from '../../tools/log';
var ColumnInfo = /** @class */ (function () {
    /* eslint-disable @typescript-eslint/no-use-before-define */
    function ColumnInfo($xetable, _vm, _a) {
        var _b = _a === void 0 ? {} : _a, renderHeader = _b.renderHeader, renderCell = _b.renderCell, renderFooter = _b.renderFooter, renderData = _b.renderData;
        var $xegrid = $xetable.xegrid;
        var formatter = _vm.formatter;
        var visible = XEUtils.isBoolean(_vm.visible) ? _vm.visible : true;
        if (process.env.NODE_ENV === 'development') {
            var types = ['seq', 'checkbox', 'radio', 'expand', 'html'];
            if (_vm.type && types.indexOf(_vm.type) === -1) {
                warnLog('vxe.error.errProp', ["type=".concat(_vm.type), types.join(', ')]);
            }
            if (XEUtils.isBoolean(_vm.cellRender) || (_vm.cellRender && !XEUtils.isObject(_vm.cellRender))) {
                warnLog('vxe.error.errProp', ["column.cell-render=".concat(_vm.cellRender), 'column.cell-render={}']);
            }
            if (XEUtils.isBoolean(_vm.editRender) || (_vm.editRender && !XEUtils.isObject(_vm.editRender))) {
                warnLog('vxe.error.errProp', ["column.edit-render=".concat(_vm.editRender), 'column.edit-render={}']);
            }
            if (_vm.cellRender && _vm.editRender) {
                warnLog('vxe.error.errConflicts', ['column.cell-render', 'column.edit-render']);
            }
            if (_vm.type === 'expand') {
                var tableProps = $xetable.props;
                var treeConfig = tableProps.treeConfig;
                var computeTreeOpts = $xetable.getComputeMaps().computeTreeOpts;
                var treeOpts = computeTreeOpts.value;
                if (treeConfig && (treeOpts.showLine || treeOpts.line)) {
                    errLog('vxe.error.errConflicts', ['tree-config.showLine', 'column.type=expand']);
                }
            }
            if (formatter) {
                if (XEUtils.isString(formatter)) {
                    var gFormatOpts = formats.get(formatter) || XEUtils[formatter];
                    if (!gFormatOpts || !XEUtils.isFunction(gFormatOpts.cellFormatMethod)) {
                        errLog('vxe.error.notFormats', [formatter]);
                    }
                }
                else if (XEUtils.isArray(formatter)) {
                    var gFormatOpts = formats.get(formatter[0]) || XEUtils[formatter[0]];
                    if (!gFormatOpts || !XEUtils.isFunction(gFormatOpts.cellFormatMethod)) {
                        errLog('vxe.error.notFormats', [formatter[0]]);
                    }
                }
            }
        }
        Object.assign(this, {
            // 基本属性
            type: _vm.type,
            property: _vm.field,
            field: _vm.field,
            title: _vm.title,
            width: _vm.width,
            minWidth: _vm.minWidth,
            maxWidth: _vm.maxWidth,
            resizable: _vm.resizable,
            fixed: _vm.fixed,
            align: _vm.align,
            headerAlign: _vm.headerAlign,
            footerAlign: _vm.footerAlign,
            showOverflow: _vm.showOverflow,
            showHeaderOverflow: _vm.showHeaderOverflow,
            showFooterOverflow: _vm.showFooterOverflow,
            className: _vm.className,
            headerClassName: _vm.headerClassName,
            footerClassName: _vm.footerClassName,
            formatter: formatter,
            sortable: _vm.sortable,
            sortBy: _vm.sortBy,
            sortType: _vm.sortType,
            filters: toFilters(_vm.filters),
            filterMultiple: XEUtils.isBoolean(_vm.filterMultiple) ? _vm.filterMultiple : true,
            filterMethod: _vm.filterMethod,
            filterResetMethod: _vm.filterResetMethod,
            filterRecoverMethod: _vm.filterRecoverMethod,
            filterRender: _vm.filterRender,
            treeNode: _vm.treeNode,
            cellType: _vm.cellType,
            cellRender: _vm.cellRender,
            editRender: _vm.editRender,
            contentRender: _vm.contentRender,
            headerExportMethod: _vm.headerExportMethod,
            exportMethod: _vm.exportMethod,
            footerExportMethod: _vm.footerExportMethod,
            titleHelp: _vm.titleHelp,
            titlePrefix: _vm.titlePrefix,
            titleSuffix: _vm.titleSuffix,
            // 自定义参数
            params: _vm.params,
            // 渲染属性
            id: _vm.colId || XEUtils.uniqueId('col_'),
            parentId: null,
            visible: visible,
            // 内部属性（一旦被使用，将导致不可升级版本）
            halfVisible: false,
            defaultVisible: visible,
            defaultFixed: _vm.fixed,
            checked: false,
            halfChecked: false,
            disabled: false,
            // 分组层级
            level: 1,
            // 跨行
            rowSpan: 1,
            // 跨列
            colSpan: 1,
            // 数据排序-自定义排序
            order: null,
            // 数据排序-用于多列的先后顺序
            sortTime: 0,
            // 列排序
            customOrder: 0,
            renderWidth: 0,
            renderHeight: 0,
            resizeWidth: 0,
            renderLeft: 0,
            renderArgs: [],
            model: {},
            renderHeader: renderHeader || _vm.renderHeader,
            renderCell: renderCell || _vm.renderCell,
            renderFooter: renderFooter || _vm.renderFooter,
            renderData: renderData,
            // 单元格插槽，只对 grid 有效
            slots: _vm.slots
        });
        if ($xegrid) {
            var computeProxyOpts = $xegrid.getComputeMaps().computeProxyOpts;
            var proxyOpts = computeProxyOpts.value;
            if (proxyOpts.beforeColumn) {
                proxyOpts.beforeColumn({ $grid: $xegrid, column: this });
            }
        }
    }
    ColumnInfo.prototype.getTitle = function () {
        return getFuncText(this.title || (this.type === 'seq' ? GlobalConfig.i18n('vxe.table.seqTitle') : ''));
    };
    ColumnInfo.prototype.getKey = function () {
        return this.field || (this.type ? "type=".concat(this.type) : null);
    };
    ColumnInfo.prototype.update = function (name, value) {
        // 不支持直接修改的属性
        if (name !== 'filters') {
            if (name === 'field') {
                // 兼容旧属性
                this.property = value;
            }
            this[name] = value;
        }
    };
    return ColumnInfo;
}());
export { ColumnInfo };
