<?php
namespace Inoby;

use WPBS_Base_Object;

abstract class WPBS_Outputter {
  abstract public function table_body(): void;

  protected function format_date(string $date, string $from_format = "") {
    $format = get_option("date_format");
    if (!empty($from_format)) {
      $datetime = \DateTime::createFromFormat($from_format, $date);
    } else {
      $datetime = new \DateTime($date);
    }

    return wp_date($format, $datetime->getTimestamp());
  }

  protected function print_row(...$cells): void {
    echo "<tr>";
    $this->print_cells(...$cells);
    echo "</tr>";
  }

  protected function print_cells(...$cells): void {
    foreach ($cells as $cell) {
      echo "<td>$cell</td>";
    }
  }

  protected function format_price(string $price): string {
    return wc_price($price);
  }

  protected function get_translated_label(array $field): string {
    $language = wpbs_get_locale();
    if (isset($field["values"][$language]["label"]) && !empty($field["values"][$language]["label"])) {
      return $field["values"][$language]["label"];
    }

    return $field["values"]["default"]["label"];
  }
}
