# User profiles and screenshot upload management
class MyController < ApplicationController
  before_action :authenticate_user!

  # Show audit logs
  def logs
    @logs = Log.paginate(page: params[:page], per_page: 20)
  end

  # Show the user's own uploaded screenshots
  def screenshots
    @screenshots = current_user.screenshots.paginate(page: params[:page], per_page: 10)
  end
  

  # def profile
  # end

  # def uploads
  #   # @current_users_screenshots gets filled in ApplicationController
  #   #
  #   # Get packages that the uploaded screenshots belong to.
  #   @packages = Package.joins(:screenshots).where(
  #     'screenshots.id' => @current_users_screenshots)
  # end

  def moderate_list
    # First package with pending screenshots
    # @packages = Package.joins(:screenshots).where('screenshots.approved=false or screenshots.markedfordelete=true').distinct(:name)
    @packages = Package.need_moderation

    # # # List of screenshots that were reported (to be removed)
    # # @reported_screenshots = Screenshot.where(markedfordelete: true)
    # # # First package with reported screenshots
    # # @reported_package = Package.joins(:screenshots).where('screenshots.markedfordelete=true').distinct(:name).first

    # if @package
    #   # List of screenshots to be moderated
    #   @pending_screenshots = @package.screenshots_pending
    #   # Number of screenshots that were already moderated (during this session)
    #   session[:already_moderated] ||= 0
    #   @moderated_screenshots = session[:already_moderated]

    #   # BUG: calculation is wrong when pending and reported screenshots are in the queue
    #   # Percentage of already moderated screenshots
    #   @percent_moderated = 100 * (@moderated_screenshots+1) / (@moderated_screenshots + @pending_screenshots.count)
    #   # @percent_moderated = 100 * (@moderated_screenshots+1) / (@moderated_screenshots + @pending_screenshots.count + @reported_screenshots.count)
    # end
  end

  # def welcome
  # end

end
