import { empty } from '@/utils/frontend/dom';
import { cellTypes, GridSettings } from '@sc/handsontable';

// 普通的不支持key Value 的下拉框render
export default function simpleSelectRender(
  instance: Handsontable,
  TD: HTMLElement,
  row: number,
  col: number,
  prop: string | number,
  value: any,
  cellProperties: GridSettings
) {
  // 调用dropdown绑定相关事件
  cellTypes.dropdown.renderer(instance, TD, row, col, prop, '', cellProperties);
  const container = document.createElement('div');
  container.className = 'wcDropdown';
  const textDiv = document.createElement('div');
  textDiv.className = 'wcDropdownText';
  textDiv.appendChild(document.createTextNode(value || ''));
  const ARROW = TD.firstChild;
  if (cellProperties.readOnly !== true) container.appendChild(ARROW as HTMLElement);

  container.appendChild(textDiv);
  empty(TD);
  TD.appendChild(container);

  return container;
}
