import { CellRender, CellRenderBuilder2 } from "../types"
import { KeyValueItem, renderEnumSelectCell } from "./enum-render"
import { EditorProperty } from "@iplusplus/y-model"

const items: KeyValueItem[] = [
  ["0", "禁用"],
  ["1", "启用"],
]

function renderEnumCell(items: KeyValueItem[]) {
  const xx: CellRender = params => {
    //    console.log(params.value)
    const r = items.find(item => item[0] == "" + params.value)
    return <div> {r ? r[1] : params.value}</div>
  }
  return xx
}

export const enableRenderBuilder: CellRenderBuilder2 = (property: EditorProperty) => {
  if (property.editorType === "enable") {
    //    console.log(property.editorType);

    return {
      editorCellRender: renderEnumSelectCell(items),
      cellRender: renderEnumCell(items),
    }
  }

  return undefined
}
