import * as React from 'react';
import { IEditor, RendererProps } from './index.data';

import BaseInputEditor from './base/BaseInputEditor';
export { BaseInputEditor };

import BasePickableRenderer from './base/BasePickableRenderer';
export { BasePickableRenderer };

import NumericRenderer from './numeric//NumericRenderer';
import NumericEditor from './numeric/NumericEditor';
export { NumericRenderer, NumericEditor };

import TextRenderer from './text/TextRenderer';
import TextEditor from './text/TextEditor';
export { TextRenderer, TextEditor };

import RichTextRenderer from './richtext/RichTextRenderer';
import RichTextEditor from './richtext/RichTextEditor';
export { RichTextRenderer, RichTextEditor };

import RowNoRenderer from './rowno/RowNoRenderer';
export { RowNoRenderer };

import ListEditor from './list/ListEditor';
import ListRenderer from './list/ListRenderer';
export { ListRenderer, ListEditor };

import FormulaEditor from './formula/FormulaEditor';
import { ICellType } from '../index.data';
import FakeEditor from './base/FakeEditor';
export { FormulaEditor };

export const cellTypes: Record<
  string,
  {
    renderer: React.FC<RendererProps<any>> | React.ComponentClass<any>;
    editor: IEditor<any> | null;
  }
> = {
  numeric: { renderer: NumericRenderer, editor: NumericEditor },
  text: { renderer: TextRenderer, editor: TextEditor },
  richtext: { renderer: RichTextRenderer, editor: RichTextEditor },
  // row-no 虽然分配了fakeEditor, 但在DataSheet的处理中, 一旦双击, 就进行展开动作, 根本没进入Active模式
  // 也就是: fakeEditor 与 rownoRenderer 会同时存在, 但不会active
  'row-no': { renderer: RowNoRenderer, editor: FakeEditor },
  // formula不用注册
};

export function getEditor(type: ICellType): IEditor<any> | null {
  return cellTypes[type].editor;
}

export function getRenderer(type: ICellType) {
  return cellTypes[type].renderer;
}

export function registerCellType(
  cellType: string,
  renderer: React.FC<RendererProps<any>> | React.ComponentClass<any>,
  editor: IEditor<any> | null,
) {
  cellTypes[cellType] = {
    renderer,
    editor,
  };
}

export function removeCellType(cellType: string) {
  delete cellTypes[cellType];
}
