"use client";

import React from "react";
import { AutoRegisteringComponentRenderer } from "../../AutoRegisteringComponentRenderer";
import { V2LocationSwapSelectorDefinition } from "./index";
import { LocationSwapSelectorComponent } from "./LocationSwapSelectorComponent";

/**
 * LocationSwapSelector 렌더러
 */
export class LocationSwapSelectorRenderer extends AutoRegisteringComponentRenderer {
  static componentDefinition = V2LocationSwapSelectorDefinition;

  render(): React.ReactElement {
    const { component, formData, onFormDataChange, isDesignMode, style, ...restProps } = this.props;

    // component.componentConfig에서 설정 가져오기
    const componentConfig = component?.componentConfig || {};

    console.log("[LocationSwapSelectorRenderer] render:", {
      componentConfig,
      formData,
      isDesignMode,
    });

    return (
      <LocationSwapSelectorComponent
        id={component?.id}
        style={style}
        isDesignMode={isDesignMode}
        formData={formData}
        onFormDataChange={onFormDataChange}
        componentConfig={componentConfig}
        {...restProps}
      />
    );
  }
}

// 자동 등록 실행
LocationSwapSelectorRenderer.registerSelf();

// Hot Reload 지원 (개발 모드)
if (process.env.NODE_ENV === "development") {
  LocationSwapSelectorRenderer.enableHotReload();
}
