{extends file=$smarty.const.SMARTY_LAYOUT_CONTENT_LIST_TABLE_CURRENT_DATA}

{block name="listing-td-content-datetime"}
	<div>
		{$rowFields['datetime']|dateTimeFormat:'dateWithHMS'}
	</div>
{/block}

{block name="listing-td-content-tags"}
	<div style="color: #444;">
		{$sep=""}
		{foreach $rowFields['tags'] as $tag}{$sep}{$absLang['index']['reportTags']['tags'][$tag]|default:$tag}{$sep=", "}{/foreach}
	</div>
{/block}

{block name="listing-td-content-files"}
	{foreach $rowFields['files'] as $file}
		{$file->getFilename()} ({$file->getSize()|formatFilesize})
	{/foreach}
{/block}

{block name="listing-td-content-filters"}
	{if $rowFields['filters']}
		<ul class="filters">
			{foreach $rowFields['filters']->getFilters() as $filterId=>$filter}
				{$class=$filter|get_class}
				{$element=$filterContainer->findElementByName($filterId)}
				{if !$element && $class=="ModulesAbstract\PluginReports\Report\Model\Filters\CorporatesAndSegments"}
					{$fid="$filterId[type]"}
					{$element=$filterContainer->findElementByName($fid)}
				{/if}

				{if !$element && $class=="ModulesAbstract\PluginReports\Report\Model\Filters\CorporatesAndSegmentsAndGroups"}
					{$fid="$filterId[type]"}
					{$element=$filterContainer->findElementByName($fid)}
				{/if}

				{* This code is duplicated because some reports use corporate(s) and segment(s), but gatherers must use filter CorporatesAndSegmentsAndGroups. *}
				{* TODO: remove this after 2022-01-01, if CorporatesAndSegments is no longer used *}
				{if !$element && $class=="ModulesAbstract\PluginReports\Report\Model\Filters\CorporatesAndSegmentsAndGroups"}
					{$fid="corporatesAndSegments[type]"}
					{$element=$filterContainer->findElementByName($fid)}
				{/if}
				{if !$element && $class=="ModulesAbstract\PluginReports\Report\Model\Filters\CorporatesAndSegmentsAndGroups"}
					{$fid="corporateFilter[type]"}
					{$element=$filterContainer->findElementByName($fid)}
				{/if}

				{$filters_undefined_filter_content=''}
				{if !$element}
					{capture assign=filters_undefined_filter_content}{block name=filters_undefined_filter}{/block}{/capture}
					{$filters_undefined_filter_content={$filters_undefined_filter_content|trim}}
					{if $filters_undefined_filter_content}
						{$filters_undefined_filter_content}
					{/if}
				{/if}

				{if !$filters_undefined_filter_content}
					<li class="{if !$element}undefined{/if}">
						{if $element}
							<div class="label">{$element->getLabel()}:</div>
						{else}
							<div class="label">{$filterId}:</div>
						{/if}

						{if $filter|get_class=="ModulesAbstract\PluginReports\Report\Model\Filters\DateInterval"}
							{$value=$filter->getValue()}
							<div class="value DateInterval">{$value['start']|dateTimeFormat} - {$value['end']|dateTimeFormat}</div>
						{elseif $filter|get_class=="ModulesAbstract\PluginReports\Report\Model\Filters\Boolean"}
							<div class="value Boolean">
								{$value=$filter->getValue()}
								{if $value}{$_LANG['yes']}{else}{$_LANG['no']}{/if}
							</div>
						{elseif $filter|get_class=="ModulesAbstract\PluginReports\Report\Model\Filters\CorporatesAndSegments"}
							{$value=$filter->getValue()}
							{$possibleValues=['all' => 'all', 'segment' => 'segment', 'corporate' => 'corporate']}

							{if $element}
								{$possibleValues=$element->getPossibleValues()}
							{/if}
							{if $value['type']=='all'}
								<div class="value">{$possibleValues['all']}</div>
							{elseif $value['type']=='segment'}
								<div class="value">{$possibleValues['segment']} {foreach $value['entityIds'] as $id} {corporateSegmentLabel ref=$id} {/foreach}</div>
							{elseif $value['type']=='corporate'}
								<div class="value">{$possibleValues['corporate']} {foreach $value['entityIds'] as $id} {corporateLabel ref=$id} , {/foreach}</div>
							{/if}
						{elseif $filter|get_class=="ModulesAbstract\PluginReports\Report\Model\Filters\CorporatesAndSegmentsAndGroups"}
							{$value=$filter->getValue()}
							{$possibleValues=['all' => 'all', 'segment' => 'segment', 'corporate' => 'corporate', 'groups' => 'groups']}

							{if $element}
								{$possibleValues=$element->getPossibleValues()}
							{/if}
							{if $value['type']=='all'}
								<div class="value">{$possibleValues['all']}</div>
							{elseif $value['type']=='segment'}
								<div class="value">
									{$possibleValues['segment']}
									{foreach $value['entityIds'] as $index => $id}
										{corporateSegmentLabel ref=$id}{if $index < count($value['entityIds'])}, {/if}
									{/foreach}
								</div>
							{elseif $value['type']=='corporate'}
								<div class="value">
									{$possibleValues['corporate']}
									{foreach $value['corporateIds'] as $index => $id}
										{corporateLabel ref=$id}{if $index < count($value['corporateIds'])-1}, {/if}
									{/foreach}
								</div>
							{elseif $value['type']=='groups'}
								<div class="value">{$possibleValues['groups']}
									{$groupsList=[]}
									{foreach $value['entityIds'] as $id}
										{$groups=$id|split:'_'}
										{$groupsList[$groups[0]][] = $groups[1]}
									{/foreach}
									{foreach $groupsList as $groupName => $groupElements}
										{$groupId = \App\Config\CorporateGroups::getInstance()->getGroupIdByName($groupName)}
										{if $groupId}
											{$groupElementsList = \App\Config\CorporateGroups::getInstance()->getGroupById($groupId)}
											<span><b>{$groupName}:</b></span>
											{foreach $groupElements as $index => $idElement}
												{$groupElementsList['groupElements'][$idElement]}{if $index < count($groupElements)-1}, {/if}
											{/foreach}
										{else}
											<div style="color:#f00;">{$groupName} has no id!</div>
										{/if}
									{/foreach}
								</div>
							{/if}
						{elseif $filter|get_class=="ModulesAbstract\PluginReports\Report\Model\Filters\ListRaw"}
							{$value=$filter->getValue()}
							{$value|join:", "}
						{else}
							<div class="value">{$filter->getValue()|default:"-"}</div>
						{/if}
					</li>
				{/if}
			{/foreach}
		</ul>
	{else}
		-
	{/if}
{/block}

