module Avo::ResourcesHelper

def field_wrapper(**args, &block)

def field_wrapper(**args, &block)
  render Avo::FieldWrapperComponent.new(**args) do
    capture(&block)
  end
end

def filter_wrapper(name: nil, index: nil, **args, &block)

def filter_wrapper(name: nil, index: nil, **args, &block)
  render layout: "layouts/avo/filter_wrapper", locals: {
    name: name,
    index: index
  } do
    capture(&block)
  end
end

def index_field_wrapper(**args, &block)

def index_field_wrapper(**args, &block)
  render Index::FieldWrapperComponent.new(**args) do
    capture(&block)
  end
end

def item_selector_data_attributes(resource, controller: "")

def item_selector_data_attributes(resource, controller: "")
  {
    resource_name: resource.model_key,
    resource_id: resource.record.to_param,
    controller: "item-selector #{controller}"
  }
end

def record_path(record)

def record_path(record)
  resource_for_record(record).record_path
end

def record_title(record)

def record_title(record)
  resource_for_record(record).record_title
end

def resource_for_record(record)

def resource_for_record(record)
  klass = Avo.resource_manager.get_resource_by_model_class(record.class)
  klass.new(record: record)
end

def resource_grid(resources, resource)

def resource_grid(resources, resource)
  render partial: "avo/partials/resource_grid", locals: {
    resources: resources,
    resource: resource
  }
end

def resource_show_path(resource:, parent_resource: nil, parent_record: nil, parent_or_child_resource: nil)

def resource_show_path(resource:, parent_resource: nil, parent_record: nil, parent_or_child_resource: nil)
  args = {}
  if parent_record.present?
    args = {
      via_resource_class: parent_resource.class.to_s,
      via_record_id: parent_record.to_param
    }
  end
  resource_path(record: resource.record, resource: parent_or_child_resource, **args)
end

def resource_table(resources, resource)

def resource_table(resources, resource)
  render partial: "avo/partials/resource_table", locals: {
    resources: resources,
    resource: resource
  }
end