import textwrap


def _render_comma_list(prefix, items, suffix, indent, width):
  """Renders the given items as a list of strings bounded by the given width.

  The result has the same non-whitespace content as
    prefix + ', '.join(items) + suffix.

  However, every line begins with at least `indent` spaces, and line breaks are
  added to try to make no line exceed the given `width`.

  Rules:
  - The `prefix` is never broken across lines.
  - If a line break is necessary, one occurs immediately after the prefix,
    and the subsequent lines are indented two additional spaces.
  - Individual `items` (and the `suffix`) may be broken across lines.
  - Line breaks are only inserted instead of whitespace.

  Args:
    prefix: Python string.  The output begins with this.  Not subject to
      wrapping.
    items: Python list of strings.  The output will contain these, in order,
      separated by commas and whitespace.  If not everything fits in one line, a
      line break is inserted between the prefix and the first item, and
      subsequently on spaces within or between items as needed.
    suffix: Python string.  Appended to the `items` without a comma.  Lines
      may be broken at spaces inside `suffix` if needed.
    indent: Python int.  The whole returned paragraph is indented this many
      spaces.  Note that non-first lines are indented two additional spaces
      relative to the first.
    width: Python int.  The returned lines strive to be no longer than `width`,
      counting the indentation.

  Returns:
    lines: Python list of strings, wrapped and indented.
  """
  # Algorithm:
  # - If everything fits on one line, do that
  # - Else, break immediately after the prefix, add extra indent,
  #   and lay out as many items on each line as fit.
  with_commas = [str(item) + ', ' for item in items]
  if with_commas:
    # Last item, if it exists, should not be followed by a comma
    with_commas[-1] = items[-1]
  total_length = (len(prefix) + sum([len(item) for item in with_commas])
                  + len(suffix))
  if total_length <= width - indent:
    return [' ' * indent + prefix + ''.join(with_commas) + suffix]
  else:
    wrapped = textwrap.wrap(
        text=''.join(with_commas) + suffix,
        width=width,
        initial_indent=' ' * (indent + 2),
        subsequent_indent=' ' * (indent + 2),
        break_long_words=False,
        break_on_hyphens=False)
    return [' ' * indent + prefix] + wrapped