/**
 * 基础字段策略基类
 * 提供通用的只读和禁用处理逻辑
 */

import React from 'react';
import type { IFieldRenderStrategy, FieldRenderContext } from '../IFieldRenderStrategy';

export abstract class BaseFieldStrategy implements IFieldRenderStrategy {
  supportsReadonly = false;

  /**
   * 获取组件的禁用/只读状态
   */
  protected getDisabledProps(context: FieldRenderContext): { disabled?: boolean; readOnly?: boolean } {
    const { isDisabled, isReadonly } = context;
    const supportsReadonly = this.supportsReadonly ?? false;
    
    if (supportsReadonly && isReadonly) {
      return { readOnly: true, disabled: false };
    }
    
    return { disabled: isDisabled || isReadonly };
  }

  /**
   * 抽象方法：子类实现具体的渲染逻辑
   */
  abstract render(context: FieldRenderContext): React.ReactNode;
}

