<?php
/**
 * @copyright (c) Kufer Software GmbH, Oderstraße 7, D-84453 Mühldorf
 */

namespace Kufer\Admin\Classes\Settings\Helper\Tools;

final class LinkHelper
{
  private function __construct()
  {
  }

  public static function createLinkToTools(): string
  {
    return 'index.php?action=tools';
  }

  public static function createHardlinkToWssField(int $id): string
  {
    return static::createLinkToTools() . "&hardlink=wss$id";
  }

  public static function createHardlinkHtmlToWssField(int $id, string $text, bool $ajaxlink = false): string
  {
    $classes = array();
    if ($ajaxlink) {
      array_push($classes, 'ajaxlink', 'ajaxlink-boosted');
    }

    $classesstr = empty($classes) ? '' : 'class="' . implode(' ', $classes) . '" ';

    return '<a ' . $classesstr . 'href="' . \CleanOperations::cleanStringForHtml(static::createHardlinkToWssField($id)) . '">' . $text . '</a>';
  }

  public static function createHardlinkSettingItemToWssField(int $id, int $toolId): \Setting
  {
    $setting = new \Setting();
    $setting->description = static::createHardlinkHtmlToWssField($id, 'Zu den Feldereinstellungen', true);
    $setting->toolId = $toolId;
    $setting->hideSaveButton = true;
    $setting->config->loadConfiguration(SC_INFOTEXT);

    return $setting;
  }

  public static function createHardlinkToToolsSetting(string $settingsFile): string
  {
    return static::createLinkToTools() . "&hardlink=$settingsFile";
  }

  public static function createHardlinkHtmlToToolSetting(string $settingsFile, string $text): string
  {
    return '<a href="' . \CleanOperations::cleanStringForHtml(static::createHardlinkToToolsSetting($settingsFile)) . '">' . $text . '</a>';
  }

  public static function createHardlinkSettingItemToToolSetting(string $settingsFile, string $group, int $toolId, string $text): \Setting
  {
    $setting = new \Setting();
    $setting->description = static::createHardlinkHtmlToToolSetting($settingsFile, $text);
    $setting->toolId = $toolId;
    $setting->config->loadConfiguration(SC_INFOTEXT);
    $setting->subGroup = $group;

    return $setting;
  }

  public static function createHardlinkToListe(int $toolId, string $name): string
  {
    return static::createLinkToTools() . "&hardlink=$name$toolId";
  }

  public static function createHardlinkHtmlToListe(int $toolId, string $name, string $text): string
  {
    return '<a href="' . \CleanOperations::cleanStringForHtml(static::createHardlinkToListe($toolId, $name)) . '">' . $text . '</a>';
  }

  public static function createHardlinkSettingItemToListe(int $toolId, string $name, string $text): \Setting
  {
    $setting = new \Setting();
    $setting->description = static::createHardlinkHtmlToListe($toolId, $name, $text);
    $setting->toolId = $toolId;
    $setting->hideSaveButton = true;
    $setting->config->loadConfiguration(SC_INFOTEXT);

    return $setting;
  }
}