import { Icon } from 'view-design';
class Config {
	constructor(column) {
		this.title = column.headerName;
		this.children = column.children ? column.children.map(child => new Config(child)) : null;
		this.column = column;
		this.expand = true;
		this.disabled = false;
		this.hide = column.hide;
		this.sort = column.sort ? column.sort : false;
		this.filter = column.filter;
		this.render = (h, { root, node, data }) => {
			return h(
				'span',
				{
					style: {
						display: 'inline-block',
						width: '100%'
					}
				},
				[
					h(
						'span',
						{
							attrs: {
								class: 'config-title'
							}
						},
						data.title
					),
					h(Icon, {
						props: {
							type: this.hide ? 'md-eye-off' : 'md-eye'
						},
						on: {
							click: () => {
								this.hide = !this.hide;
								if (this.children && this.children.length > 0) {
									for (let child of this.children) {
										child.hide = this.hide;
									}
								}
							}
						}
					}),
					// h(Icon, {
					// 	props: {
					// 		type: column.sort?'ios-funnel':'ios-funnel-outline'
					// 	},
					// 	on: {
					// 		click: () => {
					//             column.sort = !column.sort;
					// 		}
					// 	}
					// })
				]
			);
		};
		return this;
	}
}
export default columns => columns.filter(column => !['_selection', '_rowIndex'].includes(column.field)).map(column => new Config(column));
