<?php
namespace nur;

use nur\b\ui\IContent;
use nur\b\ui\IPrintable;

/**
 * Class co: affichage générique de données formatées avec {@link c}
 */
class co {
  /** afficher la chaine correspondant au tableau $vs applati */
  static final function _write(?iterable $vs): void {
    if ($vs === null) return;
    foreach (c::flatten($vs) as $v) {
      if ($v instanceof IPrintable) {
        $v->print();
      } elseif ($v instanceof IContent) {
        self::_write($v->getContent());
      } else {
        echo $v;
      }
    }
  }

  /** afficher $vs suivi d'un saut à la ligne */
  static final function _print(?iterable $vs): void {
    if ($vs === null) return;
    $print_nl = false;
    foreach (c::flatten($vs) as $v) {
      if ($v instanceof IPrintable) {
        $v->print();
      } elseif ($v instanceof IContent) {
        self::_write($v->getContent());
      } else {
        echo $v;
      }
      $print_nl = true;
    }
    if ($print_nl) echo "\n";
  }

  static final function write($vs): void { self::_write(c::nq($vs)); }
  static final function print($vs): void { self::_print(c::nq($vs)); }
}