import { getEditor, getRenderer } from '@operato/data-grist'

export function buildThemeValueRecordConfig() {
  return {
    editor: function (value, column, record, rowIndex, field) {
      return getEditor(record.type || 'text')(value, column, record, rowIndex, field)
    },
    renderer: function (value, column, record, rowIndex, field) {
      return getRenderer(record.type || 'text')(value, column, record, rowIndex, field)
    },
    editable: true
  }
}

function getEditorType(themeType: string): string {
  switch (themeType) {
    case 'legend':
    case 'color-map':
      return 'value-map'
    case 'color-ranges':
      return 'value-ranges'
    case 'color':
      return 'color'
    default:
      return 'text'
  }
}

function getRendererType(themeType: string): string {
  switch (themeType) {
    case 'legend':
    case 'color-map':
    case 'color-ranges':
      return 'json5'
    case 'color':
      return 'color'
    default:
      return 'text'
  }
}

function getOptions(themeType: string, name: string): any {
  switch (themeType) {
    case 'color-map':
    case 'color-ranges':
      return {
        name: `${themeType.toUpperCase()} : ${name}`,
        valuetype: 'color'
      }
    case 'color':
    default:
      return {
        name: `${themeType?.toUpperCase() || ''} : ${name}`
      }
  }
}
