import { isDef } from '@/utils/common/tools';
import { parse } from '@/utils/frontend/dom';
import { GridSettings } from '@sc/handsontable';
import { GljTypeShortName, GljTypeFullName, IBaseGlj } from '@sc/types';

// 工料机类型至显示文字转换
export default function (
  instance: Handsontable,
  row: number,
  col: number,
  prop: string | number,
  value: any,
  cellProperties: GridSettings
): HTMLElement {
  // 当前行的源数据
  const glj = instance.getSourceDataAtRow(row) as IBaseGlj;
  let text = '';
  if (isDef(glj.type)) {
    text = prop === 'fullTypeName' ? GljTypeFullName[glj.type] : GljTypeShortName[glj.type];
  }
  const container = parse(`<div>${text}</div>`) as HTMLElement;
  cellProperties.readOnly = true;
  return container;
}
