"use client";

import React from "react";
import { AutoRegisteringComponentRenderer } from "../../AutoRegisteringComponentRenderer";
import { V2ItemRoutingDefinition } from "./index";
import { ItemRoutingComponent } from "./ItemRoutingComponent";

export class ItemRoutingRenderer extends AutoRegisteringComponentRenderer {
  static componentDefinition = V2ItemRoutingDefinition;

  render(): React.ReactElement {
    const { formData, isPreview, config, tableName, screenId } = this.props as Record<
      string,
      unknown
    >;

    return (
      <ItemRoutingComponent
        config={(config as object) || {}}
        formData={formData as Record<string, unknown>}
        tableName={tableName as string}
        isPreview={isPreview as boolean}
        screenId={screenId as number | string}
      />
    );
  }
}

ItemRoutingRenderer.registerSelf();

if (process.env.NODE_ENV === "development") {
  ItemRoutingRenderer.enableHotReload();
}
