# frozen_string_literal: true

# Getting Newsletter emails
class NewsletterController < ApplicationController

  def index; end

  def new
    @pages = PublishedPage.where('type_of != 3').order('priority ASC')
    @ss = ScSetting.first
    @new_email = NewEmail.new

  end

  def create
    if params[:new_email][:email].blank?
      @new_email = NewEmail.new
      @ready_to_download = false
    else
      @new_email = NewEmail.where(email: params[:new_email][:email]).first
      @new_email ||= NewEmail.new(new_email_params)
      @new_email.active = true
      @new_email.accepted = Time.now
      @new_email.save
      @ready_to_download = true
    end
  end

  def get_file
    send_file("#{Rails.root}/storage/CFRP1.pdf")
  end

  def destroy; end

  private

  def new_email_params
    params.require(:new_email).permit(:email)
  end
end
