<commit_before>module Cms
  module Helpers
    module AnotherFormsHelper
      def self.included(base)
        methods = [:input]
        if base.respond_to?(:helper_method)
          base.helper_method methods
        end
      end

      def input(resource_name, input_name, options = {})
        resource = nil
        if !resource_name.is_a?(String) && !resource_name.is_a?(Symbol)
          resource = resource_name
          resource_name = resource_name.class.name.underscore
        end
        input_name = input_name.to_s
        defaults = {
            type: :string,
            required: false
        }
        options = defaults.merge(options)
        options[:input_html] ||= {}

        options[:type] = :email if input_name == "email"
        options[:type] = :tel if input_name == "phone"

        html_name = options[:name] != false ? "#{resource_name}[#{input_name}]" : nil
        html_input_id = "#{resource_name}__#{input_name}"
        input_type = options[:type]
        input_type = :text if options[:type] == :string

        wrap_html = {
            class: "input-field"
        }

        (options[:wrap_html] || {}).map{|k, v|
          default_value = wrap_html[k.to_sym];

          if k.to_sym == :class
            wrap_html[k.to_sym] += " #{v}"
          else
            wrap_html[k.to_sym] = v
          end
        }

        if options[:input_template].present?
          wrap_html[:class] += " #{options[:input_template]}-input-field"
        end

        wrap_html[:class] += " input-#{options[:type]}"

        attr_value = options[:value] || resource.try(input_name)
        attr_value = "" if options[:reset]
        input_content = ""


        i18n_resource_scope = options[:i18n_resource_scope] || resource_name

        label_html_attributes = { for: html_input_id, class: "placeholder sub_title" }.merge(options[:reset_label_html] || {})
        label_text = (I18n.t("forms.labels.common.#{input_name}", raise: true) rescue nil) || (I18n.t("forms.labels.#{i18n_resource_scope}.#{input_name}", raise: true) rescue nil) || I18n.t("forms.#{i18n_resource_scope}.#{input_name}", raise: true) rescue I18n.t("forms.#{input_name}", raise: true) rescue input_name.humanize
        label_text = input_name.humanize if label_text.blank?
        input_placeholder_text = (I18n.t("forms.placeholders.common.#{input_name}", raise: true) rescue nil) || I18n.t("forms.placeholders.#{i18n_resource_scope}.#{input_name}", raise: true) rescue label_text
        input_html_attributes = {name: html_name, id: html_input_id, type: input_type, placeholder: input_placeholder_text }.merge(options[:input_html])
        if options[:required]
          wrap_html[:class] += " required"
          input_html_attributes[:required] = "required"
          #label_text = label_text + "<span>&nbsp;*</span>"
        end


        if attr_value.present?
          input_html_attributes[:class] = (c = input_html_attributes[:class]).present? ? c + " used" : "used"
        end

        if options[:type] == :text
          input_html_attributes.delete(:type)
          input_content = attr_value
        elsif options[:type] == :checkbox
          checkbox_value = options[:checkbox_value]
          input_html_attributes[:value] = checkbox_value
          if options[:checked]
            input_html_attributes[:checked] = "checked"
          else
            input_html_attributes[:checked] = attr_value.present?
          end
        else
          input_html_attributes[:value] = attr_value
        end


        input_tip_title = I18n.t("forms.tooltips.#{i18n_resource_scope}.#{input_name}.title", raise: true) rescue nil
        input_tip_description = I18n.t("forms.tooltips.#{i18n_resource_scope}.#{input_name}.description", raise: true) rescue nil
        input_tip_description = input_tip_description.present? ? input_tip_description.html_safe : nil
        show_input_tip = input_tip_title.present? || input_tip_description.present?

        input_html_attributes_str = input_html_attributes.map{|k, v| "#{k}='#{v}'" }.join(' ')

        if options[:type] == :text
          input_tag_str = "<textarea #{input_html_attributes_str}>#{input_content}</textarea>"
        elsif options[:type] == :checkbox
          checkbox_label_text = options[:checkbox_label_text]
          input_tag_str = "<input #{input_html_attributes_str}/>"
          if checkbox_label_text.present?<commit_msg>add tabindex to input_html_attributes<commit_after>module Cms
  module Helpers
    module AnotherFormsHelper
      def self.included(base)
        methods = [:input]
        if base.respond_to?(:helper_method)
          base.helper_method methods
        end
      end

      def input(resource_name, input_name, options = {})
        resource = nil
        if !resource_name.is_a?(String) && !resource_name.is_a?(Symbol)
          resource = resource_name
          resource_name = resource_name.class.name.underscore
        end
        input_name = input_name.to_s
        defaults = {
            type: :string,
            required: false,
            tabindex: nil
        }
        options = defaults.merge(options)
        options[:input_html] ||= {}

        options[:type] = :email if input_name == "email"
        options[:type] = :tel if input_name == "phone"

        html_name = options[:name] != false ? "#{resource_name}[#{input_name}]" : nil
        html_input_id = "#{resource_name}__#{input_name}"
        input_type = options[:type]
        input_type = :text if options[:type] == :string

        wrap_html = {
            class: "input-field"
        }

        (options[:wrap_html] || {}).map{|k, v|
          default_value = wrap_html[k.to_sym];

          if k.to_sym == :class
            wrap_html[k.to_sym] += " #{v}"
          else
            wrap_html[k.to_sym] = v
          end
        }

        if options[:input_template].present?
          wrap_html[:class] += " #{options[:input_template]}-input-field"
        end

        wrap_html[:class] += " input-#{options[:type]}"

        attr_value = options[:value] || resource.try(input_name)
        attr_value = "" if options[:reset]
        input_content = ""


        i18n_resource_scope = options[:i18n_resource_scope] || resource_name

        label_html_attributes = { for: html_input_id, class: "placeholder sub_title" }.merge(options[:reset_label_html] || {})
        label_text = (I18n.t("forms.labels.common.#{input_name}", raise: true) rescue nil) || (I18n.t("forms.labels.#{i18n_resource_scope}.#{input_name}", raise: true) rescue nil) || I18n.t("forms.#{i18n_resource_scope}.#{input_name}", raise: true) rescue I18n.t("forms.#{input_name}", raise: true) rescue input_name.humanize
        label_text = input_name.humanize if label_text.blank?
        input_placeholder_text = (I18n.t("forms.placeholders.common.#{input_name}", raise: true) rescue nil) || I18n.t("forms.placeholders.#{i18n_resource_scope}.#{input_name}", raise: true) rescue label_text
        input_html_attributes = {name: html_name, id: html_input_id, type: input_type, placeholder: input_placeholder_text }.merge(options[:input_html])
        if options[:required]
          wrap_html[:class] += " required"
          input_html_attributes[:required] = "required"
          #label_text = label_text + "<span>&nbsp;*</span>"
        end


        if attr_value.present?
          input_html_attributes[:class] = (c = input_html_attributes[:class]).present? ? c + " used" : "used"
        end

        if options[:type] == :text
          input_html_attributes.delete(:type)
          input_content = attr_value
        elsif options[:type] == :checkbox
          checkbox_value = options[:checkbox_value]
          input_html_attributes[:value] = checkbox_value
          if options[:checked]
            input_html_attributes[:checked] = "checked"
          else
            input_html_attributes[:checked] = attr_value.present?
          end
        else
          input_html_attributes[:value] = attr_value
        end

        if options[:tabindex].present?
          input_html_attributes[:tabindex] = options[:tabindex]
        end


        input_tip_title = I18n.t("forms.tooltips.#{i18n_resource_scope}.#{input_name}.title", raise: true) rescue nil
        input_tip_description = I18n.t("forms.tooltips.#{i18n_resource_scope}.#{input_name}.description", raise: true) rescue nil
        input_tip_description = input_tip_description.present? ? input_tip_description.html_safe : nil
        show_input_tip = input_tip_title.present? || input_tip_description.present?

        input_html_attributes_str = input_html_attributes.map{|k, v| "#{k}='#{v}'" }.join(' ')

        if options[:type] == :text
          input_tag_str = "<textarea #{input_html_attributes_str}>#{input_content}</textarea>"
        elsif options[:type] == :checkbox
          checkbox_label_text = options[:checkbox_label_text]
          input_tag_str = "<input #{input_html_attributes_str}/>"
          if checkbox_label_text.present?
{'fraction_non_alphanumeric': 0.12743244745913487, 'fraction_numerical': 0.006671855887912821, 'mean_word_length': 2.833759590792839, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2751372', 'n_tokens_mistral': 2759, 'n_tokens_neox': 2707, 'n_words': 477}