import { renderEditInputCell } from "@mui/x-data-grid"
import { CellRender } from "../types"

function convertValueToString(value: unknown) {
  if (value === undefined) {
    return ""
  }
  if (typeof value === "string") {
    return value
  }
  if (typeof value === "number") {
    if (isNaN(value)) {
      return ""
    }
  }
  if (typeof value === "object") {
    return value as React.ReactNode
  }
  return "" + value
}

const renderStringCell: CellRender = params => {
  if (params.value === "1080") {
    console.log("1080")
  }
  return <div className="defualt-string-cell">{convertValueToString(params.value as unknown)}</div>
}

export function defaultCellBuilder() {
  return {
    editorCellRender: renderEditInputCell,
    cellRender: renderStringCell,
  }
}
