# frozen_string_literal: true
class MarkdownTextareaCell < FormCellBase
  attribute :name, mandatory: true, description: "The textarea's name attribute."
  attribute :form, mandatory: true, description: 'A Rails form object.'
  attribute :value, description: "The textarea's content."
  attribute :rows, description: 'Number of rows.'
  attribute :label, description: 'A label for the form input.'

  private

  def textarea
    form.text_area options[:name], textarea_opts
  end

  def textarea_opts
    opts = {
      skip_label: true,
      rows: options[:rows] || 10,
      control_col: 'col-sm-12',
      label_col: '',
      data: { toggle: 'markdown', target: "##{preview_id}" }
    }

    opts[:value] = options[:value] if options[:value]

    opts
  end

  def form_group
    form.__send__(:form_group_builder, name, label: label) do
      yield.html_safe
    end
  end

  def preview_id
    "markdown_textarea_preview_#{name_param}"
  end

  def edit_id
    "markdown_textarea_edit_#{name_param}"
  end
end

# frozen_string_literal: true
class MarkdownTextareaCell < FormCellBase
  attribute :name, mandatory: true, description: "The textarea's name attribute."
  attribute :form, mandatory: true, description: 'A Rails form object.'
  attribute :value, description: "The textarea's content."
  attribute :rows, description: 'Number of rows.'
  attribute :label, description: 'A label for the form input.'

  private

  def textarea
    form.text_area options[:name], textarea_opts
  end

  def textarea_opts
    opts = {
      skip_label: true,
      rows: options[:rows] || 10,
      control_col: 'col-sm-12'.dup,
      label_col: '',
      data: { toggle: 'markdown', target: "##{preview_id}" }
    }

    opts[:value] = options[:value] if options[:value]

    opts
  end

  def form_group
    form.__send__(:form_group_builder, name, label: label) do
      yield.html_safe
    end
  end

  def preview_id
    "markdown_textarea_preview_#{name_param}"
  end

  def edit_id
    "markdown_textarea_edit_#{name_param}"
  end
end

Allow for modification of passed control_col option
Allow for modification of passed control_col option

In the markdown_textarea cell, when we attempt to build the form group
using the provided rails-bootstrap-forms form object, that gem then
tries to call `#concat` on our passed in `control_col` option:

https://github.com/bootstrap-ruby/rails-bootstrap-forms/blob/v2.3.0/lib/bootstrap_form/form_builder.rb#L190

Unfortunately this now fails with the recently added frozen string
pragma. To prevent the error, we can supply a non-frozen string instead.
Hopefully we can get rid of the mutation upstream in the forms gem and
this just becomes a temporary solution.
