class Public::MyAccountController < ApplicationController

  layout "public"

  before_filter :auth_customer

  def index

    @accepted_offers = current_customer.accepted_offers.order(created_at: :desc).page(params[:page_offers]).per(5)

    @wishes = current_customer.wishes.includes(:need).page(params[:page_wishes]).per(5)

    @needs = Kaminari.paginate_array(current_customer.owned_needs.order(created_at: :desc))
      .page(params[:page_needs])
      .per(5)

  end

  def edit_infos
    @no_search = true
  end

  def my_annonces
    @no_search = true
  end

  def binary
    @no_search = true
    if params[:parrain_id] and current_customer.binary_child_ids.include?(params[:parrain_id].to_i)
      @parrain = Customer.find(params[:parrain_id])

    else
      @parrain = current_customer
    end
  end

  def filleuls
    @no_search = true
    @filleuls = current_customer.children

    session[:mail_prev] = public_filleuls_path

  end

  def reconfirm
    @no_search = true
    CustomerMailer.confirm(current_customer).deliver

    redirect_to public_my_account_path, :notice => "Le mail vous a été renvoyé"
  end


  def favoris

    per_page = (params[:per_page] and params[:per_page] != "") ? params[:per_page] : 10

    page = (params[:page] and params[:page] != "") ? params[:page] : 1

    @annonces = current_customer.annonce_favs.valid_to_show
    @annonces = @annonces.page(page).per(per_page).all
  end


end
