# frozen_string_literal: true

# helper for home
module HomeHelper
  def change_ammount(ammount)
    return '' if ammount.blank?

    ret = if ammount >= 1_000_000
            "#{ammount / 1_000_000} mln"
          else
            "#{ammount / 1_000} tys."
          end
    ret
  end

  def self.change_ammount(ammount)
    return '' if ammount.blank?

    ret = if ammount >= 1_000_000
            "#{ammount / 1_000_000} mln"
          else
            "#{ammount / 1_000} tys."
          end
    ret
  end

  def render_to_stringi(data, comp_sizes)
    action_view = ActionView::Base.new
    action_view.view_paths = ActionController::Base.view_paths
    action_view.class_eval do
      include ApplicationHelper
    end
    action_view.render template: 'home/show.pdf',
                       layout: 'layouts/pdf.html',
                       locals: { dotation: data, company_sizes: comp_sizes }
  end

  def render_to_pdf_all(data, comp_sizes)
    action_view = ActionView::Base.new
    action_view.view_paths = ActionController::Base.view_paths
    action_view.class_eval do
      include ApplicationHelper
    end
    action_view.render template: 'home/prepare_pdf.pdf',
                       layout: 'layouts/pdf.html',
                       locals: { dotations: data, company_sizes: comp_sizes }
  end

  def render_cover_header(data, comp_sizes)
    action_view = ActionView::Base.new
    action_view.view_paths = ActionController::Base.view_paths
    action_view.class_eval do
      include ApplicationHelper
    end
    action_view.render template: 'home/show.pdf',
                       layout: 'layouts/pdf_header.html',
                       locals: { dotation: data, company_sizes: comp_sizes }
  end

  def render_cover_footer(data, comp_sizes)
    action_view = ActionView::Base.new
    action_view.view_paths = ActionController::Base.view_paths
    action_view.class_eval do
      include ApplicationHelper
    end
    action_view.render template: 'home/show.pdf',
                       layout: 'layouts/pdf_footer.html',
                       locals: { dotation: data, company_sizes: comp_sizes }
  end
end
