<commit_before># frozen_string_literal: true

module GobiertoPeople
  module DatesRangeHelper
    extend ActiveSupport::Concern

    RANGE_PARAM_NAMES = %w(start_date end_date).freeze

    included do
      helper_method :site_configuration_dates_range?, :filter_start_date, :filter_end_date, :date_range_params, :all_start_date, :all_end_date
    end

    def date_range_params
      params.slice(:start_date, :end_date).permit(:start_date, :end_date)
    end

    def all_start_date
      current_site.events.published.order(starts_at: :asc).first.starts_at if site_configuration_date_range[:start_date].present?
    end

    def all_end_date
      current_site.events.published.order(ends_at: :desc).first.ends_at if site_configuration_date_range[:end_date].present?
    end

    def filter_start_date
      date_from_param(:start_date) if site_configuration_dates_range?
    end

    def filter_end_date
      date_from_param(:end_date) if site_configuration_dates_range?
    end

    def site_configuration_dates_range?
      site_configuration_date_range.values.compact.present?
    end

    def empty_date_range_param?
      (params.keys & RANGE_PARAM_NAMES).empty?
    end

    private<commit_msg>Fix date params when there are no events<commit_after># frozen_string_literal: true

module GobiertoPeople
  module DatesRangeHelper
    extend ActiveSupport::Concern

    RANGE_PARAM_NAMES = %w(start_date end_date).freeze

    included do
      helper_method :site_configuration_dates_range?, :filter_start_date, :filter_end_date, :date_range_params, :all_start_date, :all_end_date
    end

    def date_range_params
      params.slice(:start_date, :end_date).permit(:start_date, :end_date)
    end

    def all_start_date
      if site_configuration_date_range[:start_date].present? && current_site.events.any?
        current_site.events.published.order(starts_at: :asc).first.starts_at
      end
    end

    def all_end_date
      if site_configuration_date_range[:end_date].present? && current_site.events.any?
        current_site.events.published.order(ends_at: :desc).first.ends_at
      end
    end

    def filter_start_date
      date_from_param(:start_date) if site_configuration_dates_range?
    end

    def filter_end_date
      date_from_param(:end_date) if site_configuration_dates_range?
    end

    def site_configuration_dates_range?
      site_configuration_date_range.values.compact.present?
    end

    def empty_date_range_param?
      (params.keys & RANGE_PARAM_NAMES).empty?
    end

    private
{'fraction_non_alphanumeric': 0.07038355081059708, 'fraction_numerical': 0.0, 'mean_word_length': 4.163265306122449, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '827226', 'n_tokens_mistral': 830, 'n_tokens_neox': 801, 'n_words': 138}