class Admin::JobsController < ApplicationController
  include Pagy::Backend

  before_action :authorize!
  def index
    @q = Job.ransack(params[:q])
    @q.sorts = "id desc" if @q.sorts.empty?
    # @pagy, @records = pagy(@q.result(distinct: true), limit: 20)
    @calendar, @pagy, @records = pagy_calendar(@q.result, year:  {}, month: {}, pagy:  {}, active: params[:calendar])
  end

  def pagy_calendar_period(collection)
    [ collection.minimum(:created_at).in_time_zone, collection.maximum(:created_at).in_time_zone ] if collection
  end

  def pagy_calendar_filter(collection, from, to)
    collection.where(created_at: from...to)
  end
end
