# frozen_string_literal: true
module C
  module ApplicationHelper
    include FontAwesome::Rails::IconHelper
    ActionView::Base.default_form_builder = CFormBuilder

    def store_page_title(title)
      title ? "#{title} | #{C.store_name}" : C.store_name
    end

    def path_exists?(path)
      begin
        C::Engine.routes.recognize_path(path)
      rescue
        return false
      end
      true
    end

    def content_can_tag(tag, action, subject, content, opts={}, &block)
      return unless can? action, subject
      if block
        opts = content || {}
        content = capture(&block)
      end
      content_tag tag, content, opts
    end

    def index_table(collection, index_data, opts={})
      content_tag :div, class: 'data_table' do
        render 'index_table', collection: collection, index_data: index_data, sortable: opts[:sortable], bulk_actions: opts[:bulk_actions]
      end
    end

    def tinymce_standard
      tinymce(height: 200,
              menubar: false,
              plugins: ['autolink lists link image media charmap anchor',
                        'insertdatetime media table contextmenu paste code textcolor colorpicker'],
              toolbar: 'undo redo styleselect bold italic alignleft aligncenter alignright alignjustify bullist numlist link media uploadimage forecolor')
    end

    def tinymce_light
      tinymce(height: 200,
              menubar: false,
              plugins: ['lists'],
              toolbar: 'undo redo | bold italic | bullist')
    end

  end
end