<?php
/**
 * @package DJ-Catalog2-Yootheme
 * @copyright Copyright (C) DJ-Extensions.com, All rights reserved.
 * @license http://www.gnu.org/licenses GNU/GPL
 * @author url: http://dj-extensions.com
 * @author email contact@dj-extensions.com
 */

namespace DJExtensions\DJCatalog2\YOOtheme\Builder\Source\Type\Item;
defined('_JEXEC') or die;
use function YOOtheme\app;
use Joomla\CMS\Factory;
use YOOtheme\Builder\Source;
use YOOtheme\Path;
use YOOtheme\View;

class ItemFilesType
{
	/**
	 * @return array
	 */
	public static function config()
	{
		return [

			'fields' => [

				'group_label' => [
					'type' => 'String',
					'metadata' => [
						'label' => 'Label',
					],
					'extensions' => [
						'call' => __CLASS__ . '::label',
					],
				],

				'caption' => [
					'type' => 'String',
					'metadata' => [
						'label' => 'Caption',
					],
					'extensions' => [
						'call' => __CLASS__ . '::caption',
					],
				],

				'ext' => [
					'type' => 'String',
					'metadata' => [
						'label' => 'Extension',
					],
					'extensions' => [
						'call' => __CLASS__ . '::ext',
					],
				],
				'size' => [
					'type' => 'String',
					'metadata' => [
						'label' => 'Size',
					],
					'extensions' => [
						'call' => __CLASS__ . '::size',
					],
				],

				'hits' => [
					'type' => 'String',
					'metadata' => [
						'label' => 'Hits',
					],
					'extensions' => [
						'call' => __CLASS__ . '::hits',
					],

				],
				'link' => [
					'type' => 'String',
					'metadata' => [
						'label' => 'Download Link',
					],
					'extensions' => [
						'call' => __CLASS__ . '::downloadLink',
					],
				],

			],
			'metadata' => [
				'type' => true,
				'label' => "Product's Files",
			],

		];
	}
	public static function downloadLink($file){
		return $file->source === 'remote' ? $file->fullpath : \JRoute::_('index.php?option=com_djcatalog2&format=raw&task=download&fid='.$file->id.'#.'.$file->ext);
	}

	public static function label($file){
		return $file->fullname ?? '';
	}

	public static function hits($file){
		return $file->hits ?? '';
	}

	public static function size($file){
		return $file->size ?? '';
	}

	public static function ext($file){
		return $file->ext ?? '';
	}

	public static function caption($file){
		return $file->caption ?? '';
	}

}
