import React from 'react';

import {RendererProps, Renderer} from '../../factory';
import {SchemaCollection} from '../../Schema';
import {autobind} from '../../utils/helper';
import {FormBaseControl, FormItemWrap} from './Item';

/**
 * Group 表单集合渲染器，能让多个表单在一行显示
 */
export interface FormControlSchema extends FormBaseControl {
  type: 'control';

  /**
   * FormItem 内容
   */
  body: SchemaCollection;
}

@Renderer({
  type: 'control'
})
export class ControlRenderer extends React.Component<RendererProps> {
  @autobind
  renderInput() {
    const {render, body} = this.props;
    return render('inner', body);
  }

  render() {
    const {render, label, control, ...rest} = this.props;
    return (
      <FormItemWrap
        {...(rest as any)}
        formMode={rest.mode ?? rest.formMode}
        render={render}
        sizeMutable={false}
        label={label}
        renderControl={this.renderInput}
      />
    );
  }
}
