class Admin::ClientsController < Admin::DashboardController
	
	before_action :set_client, only: [:edit, :update, :destroy]	

	def index
		@clients = Client.paginate(:page => params[:page], :per_page => 200).order(:updated_at => "DESC")
	end

	def new
		@client = Client.new
	end

	def create
		@client = Client.new(client_params)
		respond_to do |format|
			if @client.save
				format.html{ redirect_to admin_clients_path, :notice => "New Client has been created" }
			else
				format.html{ render :new }
			end
		end
	end

	def show
		
	end

	def edit
		
	end

	def update
		respond_to do |format|
			if @client.update(client_params)
				format.html{ redirect_to admin_clients_path, :notice => "Client has been updated" }
			else
				format.html{ render :new }
			end
		end
	end

	def destroy
		if @client.destroy
			flash[:notice] = "Client has been deleted successfully"
		else
			flash[:notice] = "There was an error in deleting client. Please try again"
		end
		redirect_to admin_clients_path
	end

	private

		def set_client
			@client = Client.find(params[:id]) if params[:id]
		end

		def client_params
			params.require(:client).permit(:clients_category_id, :title, :alt_text, :logo)
		end
	
end