import { parse } from '@/utils/frontend/dom';
import { GridSettings } from '@sc/handsontable';
import { BRType, GljTypeShortName, IBill } from '@sc/types';

const TextMap: any = {
  1: '大项',
  2: '分部',
  3: '分项',
  4: '清单',
  5: '补项',
  6: '分类',
  7: '费用',
  20: '定',
  21: '安',
  22: '量',
  24: '超',
  25: '子目',
  50: '主',
  51: '设',
};

export default function (
  instance: Handsontable,
  row: number,
  col: number,
  prop: string | number,
  value: any,
  cellProperties: GridSettings
): HTMLElement {
  // 当前行的源数据
  const bill = instance.getSourceDataAtRow(row) as IBill;
  let text = '';
  if (bill.kind === BRType.GLJ) {
    text = GljTypeShortName[bill.type];
  } else if (bill.kind === BRType.VP) {
    text = TextMap[bill.kind] + GljTypeShortName[bill.type];
  } else {
    text = TextMap[bill.kind];
  }
  const container = parse(`<div>${text}</div>`) as HTMLElement;
  cellProperties.readOnly = true;
  return container;
}
