class CmAdmin::Models::Section

def alert_box(options = {})

def alert_box(options = {})
  @section_fields << CmAdmin::Models::Alert.new(options)
end

def field(field_name, options = {})

def field(field_name, options = {})
  if @current_nested_field
    @current_nested_field.fields << CmAdmin::Models::Field.new(field_name, options)
  else
    @section_fields << CmAdmin::Models::Field.new(field_name, options)
  end
end

def form_field(field_name, options = {}, arg = nil)

def form_field(field_name, options = {}, arg = nil)
  if @current_nested_field
    @current_nested_field.fields << CmAdmin::Models::FormField.new(field_name, options[:input_type], options)
  else
    @section_fields << CmAdmin::Models::FormField.new(field_name, options[:input_type], options)
  end
end

def initialize(section_name, current_action, cm_model, display_if, html_attrs, col_size, partial, &block)

def initialize(section_name, current_action, cm_model, display_if, html_attrs, col_size, partial, &block) 
  @section_fields = []
  @rows = []
  @nested_table_fields = []
  @col_size = col_size
  @section_name = section_name
  @current_action = current_action
  @cm_model = cm_model
  @html_attrs = html_attrs || {}
  @display_if = display_if || ->(arg) { true }
  @current_nested_field = nil
  @nested_sections = []
  @parent_section = nil
  @partial = partial || nil
  instance_eval(&block)
end

def nested_form_field(field_name, options = {}, &block)

def nested_form_field(field_name, options = {}, &block)
  # @current_action.is_nested_field = true
  # @current_action.nested_table_name = field_name
  nested_field = CmAdmin::Models::NestedField.new(field_name, options)
  if nested_field.parent_field
    @current_nested_field.associated_fields << nested_field
  else
    @nested_table_fields << nested_field
  end
  @current_nested_field = nested_field
  yield
end

def nested_form_section(section_name, display_if: nil, col_size: nil, html_attrs: nil, partial: nil, &block)

def nested_form_section(section_name, display_if: nil, col_size: nil, html_attrs: nil, partial: nil, &block)
  nested_section = CmAdmin::Models::Section.new(section_name, @current_action, @cm_model, display_if, html_attrs, col_size, partial, &block)
  nested_section.parent_section = self
  @nested_sections ||= []
  @nested_sections << nested_section
end

def row(display_if: nil, html_attrs: nil, &block)

def row(display_if: nil, html_attrs: nil, &block)
  @rows ||= []
  @rows << CmAdmin::Models::Row.new(@current_action, @model, display_if, html_attrs, &block)
end