code: def _write_collection(
      items: list[str], filename: PathLike | None, ext: str
  ) -> list[str]:
      if filename is None:
          filename = default_filename(ext)
      filename = os.fspath(filename)
  
      filenames: list[str] = []
  
      def _indexed(name: str, i: int) -> str:
          basename, ext = splitext(name)
          return f"{basename}_{i}{ext}"
  
      for i, item in enumerate(items):
          fname = filename if i == 0 else _indexed(filename, i)
  
          with open(fname, mode="w", encoding="utf-8") as f:
              f.write(item)
  
          filenames.append(fname)
  
      return filenames
  
imports: from __future__ import annotations
  import logging
  import io
  import os
  from contextlib import contextmanager
  from os.path import abspath, expanduser, splitext
  from tempfile import mkstemp
  from typing import TYPE_CHECKING, Any, Iterator, cast
  from ..core.types import PathLike
  from ..document import Document
  from ..embed import file_html
  from ..resources import INLINE, Resources
  from ..themes import Theme
  from ..util.warnings import warn
  from .state import State, curstate
  from .util import default_filename
label_desc: Use image node_id 10 for calling a global function with example usage: _write_collection(items, filename, ext) and returns: filenames, basename, str, i, ext