module AdminHelper
  def format_bytes(bytes)
    return "—" if bytes.nil?

    units = %w[B KB MB GB TB]
    size = bytes.to_f
    unit = units.shift
    while size >= 1024 && units.any?
      size /= 1024
      unit = units.shift
    end
    "#{size.round(size >= 10 ? 0 : 1)} #{unit}"
  end

  def format_duration_minutes(minutes)
    return "0 min" if minutes.to_i <= 0

    hours = minutes / 60
    mins = minutes % 60
    hours.positive? ? "#{hours}h #{mins}m" : "#{mins} min"
  end
end
