import { coord, util } from '../common';
const defaultFactory = (req) => null;
export class FactoryManager {
    constructor(args) {
        this.grid = args.grid;
        this.factory = args.factory || defaultFactory;
    }
    editor(args) {
        return this.render(Object.assign(Object.assign({}, args), { type: 'EDITOR' }));
    }
    cell(args) {
        return this.render(Object.assign(Object.assign({}, args), { type: 'CELL' }));
    }
    render(args) {
        const { type, row, column } = args;
        const key = coord.cell.toKey(column, row);
        const grid = this.grid;
        const props = util.toGridCellProps(args.cell ? args.cell.props : {});
        const data = Object.assign(Object.assign({}, args.cell), { props });
        const cell = { key, props, data };
        const view = props.view;
        const req = { type, grid, cell, view };
        return this.factory(req);
    }
}
