<?php
declare(strict_types=1);

namespace WP_AUX\Services\AuxFramework;

use WP_AUX\Entities\AuxFramework\ElementClassesEntity;

/**
 * Utilities for building and managing element class lists
 * @since 1.0.0
 */
class ElementClassesService
{
  /**
   * Build a classlist with a standard background from a base class and optional modifiers
   * @since 1.0.0
   */
  public static function buildClasses(
    string $baseClass,
    ?string $style = null,
    string|ElementClassesEntity|null $background = null,
    bool $dynamicBackground = false
  ): ElementClassesEntity
  {
    $classlist = new ElementClassesEntity($baseClass, $style);

    if ($background instanceof ElementClassesEntity) {
      if ($background->isDark()) {
        $classlist->addModifier('on-dark');
      }
    } else {
      $classlist->setBackground($background, $dynamicBackground);
    }

    return $classlist;
  }

  /**
   * Build a classlist with a dynamic background from a base class and optional modifiers
   * @since 1.0.0
   */
  public static function buildDynamicClasses(
    string $baseClass,
    ?string $style = null,
    string|ElementClassesEntity|null $background = null
  ): ElementClassesEntity
  {
    $classlist = self::buildClasses($baseClass, $style, $background, true);

    return $classlist;
  }
}
