<?php
declare(strict_types=1);

namespace WP_AUX\Services\AuxFramework;

use WP_AUX\Entities\AuxFramework\Partials\TagCollectionEntity;

class PageComponentsService
{
  public static function getCategoriesTagsCollection(int|\WP_Post|null $post = null): string|TagCollectionEntity
  {
    $categories = get_the_category($post);

    if (!$categories) {
      return '';
    }

    $collection = TagCollectionEntity::create()
      ->setTagType('category');

    foreach ($categories as $category) {
      $collection->addItem($category->cat_name, get_term_link($category));
    }

    return $collection;
  }

  public static function getTagsCollection(int|\WP_Post|null $post = null): string|TagCollectionEntity
  {
    $tags = get_the_tags($post);

    if (empty($tags)) {
      return '';
    }

    $collection = TagCollectionEntity::createContainer('Tags');

    foreach ($tags as $tag) {
      $collection->addItem($tag->name, get_term_link($tag));
    }

    return $collection;
  }
}
