
import { Observable } from 'rxjs';
import { ContextMenuItem } from '../right-click-menu/context-menu-item.model';
import { FancyColumn, FancyGroup, FtTrigger } from './fancy-row-column.model';
import { FancyEditorInstance } from './fancy-selection.model';

export class FancySettings<T = any> {
    /**
     * Displaying titles of each column, default as `true`
     */
    public showHeader?: boolean = true;
    /**
     * Displaying footer, default as `false`
     */
    public showFooter?: boolean = false;
    /**
     * Displaying filter of each column, default as `true`
     */
    public showFilters?: boolean = true;
    /**
     * Allow user selecting row and hight light it, default as `true`
     */
    public allowSelection?: boolean = true;
    /**
     * Allow user drag and drop row, default as `false`
     */
    public allowDragAndDrop?: boolean = false;
    /**
     * Allow user selecting multi rows, default as `false`
     */
    public multiselect?: boolean = false;
    /**
     * Allow user resizing columns, default as `true`
     */
    public resizingColumn?: boolean = true;

    private _columns?: FancyColumn<T>[];
    public get columns(): FancyColumn<T>[] {
        return this._columns;
    }
    public set columns(v: FancyColumn<T>[]) {
        if (v) {
            for (let i = 0; i < v.length; i++) {
                v[i] = new FancyColumn<T>({ ...v[i] });
            }
        }
        this._columns = v;
    }

    // public groups: FancyGroup[];
    public contextMenuItems?: ContextMenuItem<T>[];
    public onContextMenuOpening?: (datum: T, rightClickMenuItems: ContextMenuItem<T>[], event: MouseEvent) => void;
    public editorTrigger?: FtTrigger = FtTrigger.NOOP;
    public groupSortFunction?: (a: FancyGroup<T>, b: FancyGroup<T>) => number;

    /**
     * initial rows count for infinite scrolling, default as 50
     */
    public initialRows?: number = 200;//50;
    /**
     * append rows count for infinite scrolling, default as 10
     */
    public appendRowsOnScroll?: number = 10;

    /**
     * adding validation for build-in editor, return `Observable<string>` error message, if valid return `null`
     */
    public addingValidation?: (obj: FancyEditorInstance<T>) => Observable<string> | string;
    /**
     * editing validation for build-in editor, return `Observable<string>` error message, if valid return `null`
     */
    public editingValidation?: (obj: FancyEditorInstance<T>) => Observable<string> | string;
    /**
     * deleting validation for build-in editor, return `Observable<string>` error message, if valid return `null`
     */
    public deletingValidation?: (obj: FancyEditorInstance<T>) => Observable<string> | string;

    constructor(config: Partial<FancySettings<T>>) {
        Object.assign(this, config);
    }
}
