import { tools } from 'hq-tools';
//标准列
export class Column {
	constructor({
		//base
		key,
		title,

		//Style:{position,class,style}
		fixed,

		width,
		minWidth,
		maxWidth,

		filter,
		//sort
		//behiv

		//extra
		template,
		dict, //dictName or dictObj
		asyncTranslate,
		asyncTranslateByPager,
		format, //date or number format
		fastqueryType,
		exportExcel = true,
		btnOptions = [],

		//不在ag-grid里使用的项，只在入参声明，不处理
		//进阶，ag-grid的属性,如果和上方的属性有冲突，覆盖上方；
		colId,
		hide = false,
		lockPosition = false,
		lockVisible = false,
		lockPinned = false,
		sortable = true,
		unSortIcon = true,
		resizable = true,
		rowDrag = false,
		editable = false,
		columnGroupShow = false,
		autoHeight = false,
		cellRendererParams,
		subTotal = false,

		headerComponent,
		headerComponentFramework,
		headerComponentParams,
		headerClass,
		toolPanelClass,
		suppressColumnsToolPanel,
		suppressFiltersToolPanel,
		flex = true,
		filterFramework,
		filterParams,
		floatingFilterComponentFramework,
		floatingFilterComponentParams,
		sort,
		sortedAt,
		sortingOrder,

		headerTooltip,
		tooltipField,
		tooltip,
		checkboxSelection,

		dndSource,
		dndSourceOnRowDrag,
		cellStyle,
		cellClass,
		cellClassRules,
		onCellValueChanged,
		cellRenderer,
		cellRendererFramework,
		pinnedRowCellRendererFramework,
		pinnedRowCellRendererParams,
		cellRendererSelector,
		cellEditorSelector,
		cellEditorFramework,
		cellEditorParams,
		valueGetter,
		headerValueGetter,
		filterValueGetter,
		valueFormatter,
		valueSetter,
		valueParser,
		keyCreator,
		getQuickFilterText,
		aggFunc,
		allowedAggFuncs,
		rowGroupIndex,
		comparator,

		enableCellChangeFlash,
		menuTabs,
		suppressMenu,
		suppressSizeToFit,
		suppressMovable,
		suppressNavigable,
		suppressCellFlash,
		suppressKeyboardEvent,
		onCellClicked,
		onCellDoubleClicked,
		onCellContextMenu,
		singleClickEdit,
		chartDataType,
		fastquery = true
		// ...otherConfig
	}) {
		//域，键,属性名
		this.field = key;
		this.tooltipField = key;
		//本列id
		this.colId = colId ? colId : `row_${tools.createUUID()}`;
		// 类型 ， 用来做模式化的配置
		this.type = asyncTranslate || asyncTranslateByPager ? 'asyncTrans' : template;

		//列的表头名。如果没有设置，域的名将会作为表头名
		this.headerName = title;
		//表头组件
		this.headerComponent = headerComponent;
		this.headerComponentFramework = headerComponentFramework;
		//表头组件参数
		this.headerComponentParams = headerComponentParams;

		//在所属组展示或者隐藏时是否展示列
		this.columnGroupShow = columnGroupShow;
		//表头类
		this.headerClass = headerClass;
		//工具栏的类
		this.toolPanelClass = toolPanelClass;
		//在列工具栏中不显示
		this.suppressColumnsToolPanel = suppressColumnsToolPanel;
		//在过滤工具栏中不显示
		this.suppressFiltersToolPanel = suppressFiltersToolPanel;

		//宽度
		this.minWidth = minWidth ? minWidth : this.headerName.length * 18 + 60;
		this.width = width;
		this.maxWidth = maxWidth;

		//自动宽度调节
		//this.flex = flex;

		//过滤器 设置为true 使用默认过滤器
		// this.filter = filter
		//过滤器对应组件
		//this.filterFramework = filterFramework;
		//过滤参数
		//this.filterParams = filterParams;
		//浮动过滤
		// this.floatingFilterComponent = floatingFilterComponent;
		//this.floatingFilterComponentFramework = floatingFilterComponentFramework;
		//浮动过滤器参数
		//this.floatingFilterComponentParams = floatingFilterComponentParams;

		//隐藏列
		this.hide = hide;

		//左右固定 'left' | 'right'
		this.pinned = fixed;
		//锁定位置， 设置为true 则本列永远显示在最前
		this.lockPosition = lockPosition;
		//锁定显示状态,api扔能起作用
		this.lockVisible = lockVisible;
		//锁定固定位置,api扔能起作用
		this.lockPinned = lockPinned;

		//可否排序
		this.sortable = sortable;
		//排序模式 asc | desc
		//this.sort = sort;
		//如果默认情况下执行多重排序，则此列应说明每列的排序时间（以毫秒为单位），因此网格知道执行排序的顺序
		//this.sortedAt = sortedAt;
		//如果启用了排序,定义排序发生顺序的数组。值可以是 asc|desc|null。
		//this.sortingOrder = sortingOrder;

		//是否可以改变尺寸
		this.resizable = resizable;

		//表头提示
		// this.headerTooltip = headerTooltip;
		//提示的域
		//this.tooltipField = tooltipField;
		//提示回调 ： (value, valueFormatted, data, node , colDef, rowIndex and api) => String
		//this.tooltip = tooltip

		//复选框 Boolean | ()=>Boolean
		//this.checkboxSelection = checkboxSelection;

		//行是否可拖动  Boolean | ()=>Boolean
		this.rowDrag = rowDrag;
		//是否开启原生的拖放 Boolean | ()=>Boolean
		//this.dndSource = dndSource;
		//是否以拖放的形式使用原生拖放
		//this.dndSourceOnRowDrag = dndSourceOnRowDrag;

		//单元格样式/类/css类规则
		//this.cellStyle = cellStyle;
		//this.cellClass = [`text-${align}`].concat( cellClass );
		//this.cellClassRules = cellClassRules;

		//是否可以编辑Boolean | ()=>Boolean
		this.editable = editable;
		//单元格数据变化回调 (params)=>{}
		//this.onCellValueChanged = onCellValueChanged;
		//单元格渲染器
		if (cellRenderer) {
			this.cellRenderer = cellRenderer;
		}
		if (cellRendererFramework) {
			this.cellRendererFramework = cellRendererFramework;
		}
		//this.cellRendererFramework = cellRendererFramework;
		//单元格渲染参数

		this.cellRendererParams = Object.assign({ dict, asyncTranslate, asyncTranslateByPager, format, fastqueryType, fastquery, exportExcel, subTotal, btnOptions, print: this.type !== 'button' }, cellRendererParams);

		//固定列的渲染器
		//this.pinnedRowCellRenderer = pinnedRowCellRenderer;
		//this.pinnedRowCellRendererFramework = pinnedRowCellRendererFramework;
		//固定列渲染器的参数
		//this.pinnedRowCellRendererParams = pinnedRowCellRendererParams;

		//渲染器选择 ()=>{}
		//this.cellRendererSelector = cellRendererSelector;
		//编辑器选择 ()=>{}
		//this.cellEditorSelector = cellEditorSelector;
		//单元格编辑器
		//this.cellEditor = cellEditor;
		//this.cellEditorFramework = cellEditorFramework;
		//单元格编辑器参数
		//this.cellEditorParams = cellEditorParams;

		//获取展示数据 expression | (params)=>{}
		//this.valueGetter = valueGetter;
		//获取展示表头数据 expression | (params)=>{}
		//this.headerValueGetter = headerValueGetter;
		//获取展示过滤目标数据 expression | (params)=>{}
		//this.filterValueGetter = filterValueGetter;

		//格式化 expression | (params)=>{}
		//固定列格式化，如果不存在则使用一般的格式化 expression | (params)=>{}
		//this.valueFormatter = valueFormatter;

		//相数据赋值，如果值改变返回true expression | (params)=>{}
		//this.valueSetter = valueSetter;
		//数据序列化，如果值改变返回true expression | (params)=>{}
		//this.valueParser = valueParser;

		//key生成器 (params)=>String
		//this.keyCreator = keyCreator;

		//function。取代默认的快速过滤文字
		// this.getQuickFilterText = getQuickFilterText;

		//用于聚合的函数名，sum|min|max|first|last|自定义聚合函数
		//this.aggFunc = aggFunc;
		//允许使用聚合函数
		//this.allowedAggFuncs = allowedAggFuncs;

		//分组显示序号
		//this.rowGroupIndex =rowGroupIndex;

		//pivotIndex???
		//pivotComparator ???
		//排序用比较器 (valueA, valueB, nodeA, nodeB, isInverted)=>{}
		//this.comparator = comparator;

		// 显示未排序图标
		this.unSortIcon = unSortIcon;

		//enableCellChangeFlash
		//this.enableCellChangeFlash = enableCellChangeFlash;
		//menuTabs [filterMenuTab,generalMenuTab,columnsMenuTab]
		//this.menuTabs = menuTabs;
		// 不显示菜单
		// this.suppressMenu = suppressMenu;
		// // 不自适应尺寸
		// this.suppressSizeToFit = suppressSizeToFit;
		// // 无法移动
		// this.suppressMovable = suppressMovable;
		// // 无法导航
		// this.suppressNavigable = suppressNavigable;
		// // 无法闪变
		// this.suppressCellFlash = suppressCellFlash;
		// 不响应键盘事件
		// this.suppressKeyboardEvent = suppressKeyboardEvent;

		//事件 (params)=>{}
		// this.onCellClicked = onCellClicked;
		// this.onCellDoubleClicked = onCellDoubleClicked;
		// this.onCellContextMenu = onCellContextMenu;

		//自动高度
		this.autoHeight = autoHeight;
		//单击编辑
		// this.singleClickEdit = singleClickEdit;
		// 图标数据类型
		// this.chartDataType = chartDataType;
		let otherConfig = {
			flex,
			filter,
			filterFramework,
			filterParams,
			floatingFilterComponentFramework,
			floatingFilterComponentParams,
			sort,
			sortedAt,
			sortingOrder,

			headerTooltip,
			tooltipField,
			tooltip,
			checkboxSelection,

			dndSource,
			dndSourceOnRowDrag,
			cellStyle,
			cellClass,
			cellClassRules,
			onCellValueChanged,
			cellRenderer,
			cellRendererFramework,
			pinnedRowCellRendererFramework,
			pinnedRowCellRendererParams,
			cellRendererSelector,
			cellEditorSelector,
			cellEditorFramework,
			cellEditorParams,
			valueGetter,
			headerValueGetter,
			filterValueGetter,
			valueFormatter,
			valueSetter,
			valueParser,
			keyCreator,
			getQuickFilterText,
			aggFunc,
			allowedAggFuncs,
			rowGroupIndex,
			comparator,

			enableCellChangeFlash,
			menuTabs,
			suppressMenu,
			suppressSizeToFit,
			suppressMovable,
			suppressNavigable,
			suppressCellFlash,
			suppressKeyboardEvent,
			onCellClicked,
			onCellDoubleClicked,
			onCellContextMenu,
			singleClickEdit,
			chartDataType
		};
		const KEYS = Object.keys(otherConfig);
		for (let key of KEYS) {
			let config = otherConfig[key];
			if (config) {
				this[key] = config;
			}
		}
	}
}

export class ColumnGroup {
	constructor({ headerName, columnGroupShow, toolPanelClass, suppressColumnsToolPanel, suppressFiltersToolPanel, groupId, children, marryChildren, headerGroupComponentFramework, headerGroupComponentParams }) {
		this.headerName = headerName;
		//在所属组展示或者隐藏时是否展示列
		this.columnGroupShow = columnGroupShow;
		//表头类
		this.headerClass = headerClass;
		//工具栏的类
		this.toolPanelClass = toolPanelClass;
		//在列工具栏中不显示
		this.suppressColumnsToolPanel = suppressColumnsToolPanel;
		//在过滤工具栏中不显示
		this.suppressFiltersToolPanel = suppressFiltersToolPanel;

		this.groupId = groupId;
		this.children = children;
		this.marryChildren = marryChildren;
		this.openByDefault = openByDefault;
		//this.headerGroupComponent = headerGroupComponent;
		this.headerGroupComponentFramework = headerGroupComponentFramework;
		this.headerGroupComponentParams = headerGroupComponentParams;
	}
}
export default Column;
