module LightBoxesHelper

=begin
    def select_user_light_boxes(id_element)
        select("light_box", "id", current_user.light_boxes.collect {|lb| [ "#{lb.name} (#{lb.images.where(content_error: 0).count})", lb.id ] }, {}, { id: "#{id_element}", class: 'input-xs form-control-fixed-width'} )
    end

    def select_for_current_user_light_boxes(id_element)
        select("light_box", "id", current_user.light_boxes.collect {|lb| [ "#{lb.name} (#{lb.images.where(content_error: 0).count})", lb.id ] }, {}, { id: "#{id_element}", class: 'input-xs form-control-fixed-width'} )
    end
=end

    def select_for_current_user_light_boxes
        select("light_box", "id",
               #current_user.light_boxes.collect {|lb| [ "#{lb.name} (#{lb.images.where(content_error: 0, provider_id: session[:provs]).count})", lb.id ] }) #ToDo : To optimise, light_box loading time is longer with this providers control
               current_user.light_boxes.collect {|lb| [ "#{lb.name} (#{lb.images.where(content_error: 0).count})", lb.id ] })
    end

    def fit_square(ratio,side)
      ratio>1 ? "#{side}x#{(side/ratio).round}" : "#{(ratio*side).round}x#{side}"
    end

    def lb_nb_img(light_box, nb)
        if Server.itself?(PTREF_SERVER_NAME)
            light_box.images.where.not(action_IR_web: 21).count > nb
        else
            light_box.images.where(content_error: 0).count > nb
        end
    end

  def weight_format(lb_weight)
    if lb_weight < 1000
      return "#{lb_weight} #{t :byte}"
    elsif lb_weight >= 1000 && lb_weight < 1000000
      return "#{(lb_weight/1000.to_f).round(2)} #{t :kb}"
    elsif lb_weight >= 1000000 && lb_weight < 1000000000
      return "#{(lb_weight/1000000.to_f).round(2)} #{t :mb}"
    elsif lb_weight >= 1000000000
      return "#{(lb_weight/1000000000.to_f).round(2)} #{t :gb}"
    end
  end

end