import EzCellRender from "../editor/EzCellRender";
import { HTMLBuilder } from "@sankhyalabs/core";
import { CustomRenderSource } from "../../../../../utils/customRender/interfaces/ICustomRender";
export default class EzGridCustomCellRender extends EzCellRender {
  init(params) {
    var _a, _b;
    this._fieldName = params.column.getColId();
    this._customRenderInstance = params.customRendersInfo.customRender;
    super.init(params);
    const fieldMetadata = super.getFieldMetadata();
    this._params = {
      value: params.value,
      charPress: '',
      currentRender: super.getGui(),
      name: this._fieldName,
      source: CustomRenderSource.GRID,
      getValue: () => params.getValue(),
      detailContext: params.customRendersInfo.detailContext,
      renderMetadata: {
        hidden: ((_a = fieldMetadata.props) === null || _a === void 0 ? void 0 : _a.visible) === false,
        label: fieldMetadata.label,
        userInterface: fieldMetadata.userInterface,
        props: fieldMetadata.props,
        optionLoader: fieldMetadata.optionLoader,
        options: ((_b = fieldMetadata.props) === null || _b === void 0 ? void 0 : _b.options) || {},
      }
    };
  }
  getGui() {
    const editorElement = this._customRenderInstance.getRenderElement(this._params);
    if (!editorElement) {
      return super.getGui();
    }
    if (typeof editorElement === 'string') {
      const element = HTMLBuilder.parseElement(editorElement);
      return element;
    }
    return editorElement;
  }
}
