<?php
/*
 * Software Name: Eorisis Pixels
 * Software URI: https://eorisis.com/shop/software/joomla/pixels
 * Author: Eorisis
 * Author URI: https://eorisis.com
 * Copyright: Copyright (C) 2011-2025 EORISIS. All Rights Reserved.
 * License: GNU General Public License version 2; See https://eorisis.com/gpl
 * Terms of Service: https://eorisis.com/tos
 */
namespace com_eorisis_pixels\framework\lib\core\view;
\defined('_JEXEC') or die;

use array_replace, array_filter, implode;
use com_eorisis_pixels\framework\lib\core\cms\document as cms_document;

class link
{
	public function __construct() {}

	// --------------------------------------------------

	public static function a(string $uri, array $args = []) : string
	{
		$args = array_replace([
			'title' => '',
			'content' => '',
			'target' => '',
			'class' => ''
		], $args);

		$txt = $args['content'] ? $args['content'] : $uri;
		$arr = array_filter([
			$args['title'] ? 'title="'.$args['title'].'"' : '',
			$args['target'] ? 'target="'.$args['target'].'"' : '',
			$args['class'] ? 'class="'.$args['class'].'"' : ''
		]);
		return '<a href="'.$uri.'" '.implode(' ', $arr).'>'.$txt.'</a>';
	}

	// --------------------------------------------------

	public static function img(string $uri, array $args = []) : string
	{
		$args = array_replace([
			'alt' => 'image',
			'width' => '',
			'height' => '',
			'title' => '',
			'class' => '',
			'style' => '',
			'loading' => '',
			'version' => false
		], $args);

		if ($args['version'])
		{
			$uri .= '?'.cms_document::media_version();
		}

		$arr = array_filter([
			$args['width'] ? 'width="'.$args['width'].'"' : '',
			$args['height'] ? 'height="'.$args['height'].'"' : '',
			$args['title'] ? 'title="'.$args['title'].'"' : '',
			$args['class'] ? 'class="'.$args['class'].'"' : '',
			$args['style'] ? 'style="'.$args['style'].'"' : '',
			$args['loading'] ? 'loading="'.$args['loading'].'"' : ''
		]);
		return '<img src="'.$uri.'" alt="'.$args['alt'].'" '.implode(' ', $arr).'>';
	}
}
