module ChecklistHelper
  def format_criteria_list(criteria)
    criteria.map { |criterion| { readable_text: criterion.text } }
  end

  def format_action_audiences(actions)
    action_groups = actions.group_by(&:audience)

    action_groups.map do |key, action_group|
      {
        heading: I18n.t("checklists_results.audiences.#{key}.heading"),
        actions: action_group.sort_by.with_index do |action, index|
          [-action.priority, index]
        end
      }
    end
  end

  def filter_actions(actions, criteria_keys)
    actions.select do |action|
      action.applies_to?(criteria_keys)
    end
  end

  def persistent_criteria_keys(question_criteria_keys)
    criteria_keys - question_criteria_keys
  end

  def format_question_options(options, criteria_keys)
    options.map { |o| format_question_option(o, criteria_keys) }
  end

  def format_question_option(option, criteria_keys)
    checked = criteria_keys.include?(option["value"])
    { label: option["label"], text: option["label"], value: option["value"], checked: checked }
  end
end

module ChecklistHelper
  def format_criteria_list(criteria)
    criteria.map { |criterion| { readable_text: criterion.text } }
  end

  def format_action_audiences(actions)
    action_groups = actions.group_by(&:audience)

    action_groups.map do |key, action_group|
      {
        heading: I18n.t("checklists_results.audiences.#{key}.heading"),
        actions: action_group.sort_by.with_index do |action, index|
          [-action.priority, index]
        end
      }
    end
  end

  def filter_actions(actions, criteria_keys)
    actions.select do |action|
      action.applies_to?(criteria_keys)
    end
  end

  def persistent_criteria_keys(question_criteria_keys)
    criteria_keys - question_criteria_keys
  end

  def format_question_options(options, criteria_keys)
    options.map { |o| format_question_option(o, criteria_keys) }
  end

  def format_question_option(option, criteria_keys)
    checked = criteria_keys.include?(option["value"])
    { label: option["label"], text: option["label"], value: option["value"], checked: checked, hint_text: option["hint_text"] }
  end
end

Allow radio buttons to display hint text
Allow radio buttons to display hint text
