module ApplicationHelper
  include Pagy::Frontend

  def locale_switcher
    locale = cookies[:user_locale] || I18n.default_locale
    svg = <<SVG
    <svg xmlns="http://www.w3.org/2000/svg" class="ml-1 h-6 w-6 text-gray3" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
        <path stroke-linecap="round" stroke-linejoin="round" d="M21 12a9 9 0 01-9 9m9-9a9 9 0 00-9-9m9 9H3m9 9a9 9 0 01-9-9m9 9c1.657 0 3-4.03 3-9s-1.343-9-3-9m0 18c-1.657 0-3-4.03-3-9s1.343-9 3-9m-9 9a9 9 0 019-9"></path>
      </svg>
SVG
    
    if locale.to_sym == :en
      %(<a class="text-lg inline-flex items-center font-bold" title="set language to Chinese" href="#{main_app.locale_path(lang: "zh-CN")}">CH #{svg}</a>).html_safe
    else
      %(<a class="text-lg inline-flex items-center font-bold" title="set language to English" href="#{main_app.locale_path(lang: "en")}">EN #{svg}</a>).html_safe
    end
  end

  def encode64(raw_text)
    return "" if raw_text.blank?

    Base64.encode64(raw_text)
  end

end
