{namespace belog=TYPO3\CMS\Belog\ViewHelpers}

<f:if condition="{constraint.groupByPage}">
	<div class="divider">
		<h3>
			<f:translate key="overview" />
		</h3>
		<f:translate
			key="timeInfo"
			arguments="{
				0: '{f:format.date(format:\'{settings.dateFormat} H:i\', date:\'@{constraint.startTimestamp}\')}',
				1: '{f:format.date(format:\'{settings.dateFormat} H:i\', date:\'@{constraint.endTimestamp}\')}'
			}"
		/>
		<br />
		<f:for each="{groupedLogEntries}" as="pidEntry" key="pid">
			<f:if condition="{pid} > 0">
				<br />
				<f:translate
					key="pagenameWithUID"
					arguments="{
						0: '{belog:be.pagePath(pid:\'{pid}\')}',
						1: '{pid}'
					}"
				/>
			</f:if>
		</f:for>
	</div>
</f:if>

<f:for each="{groupedLogEntries}" as="pidEntry" key="pid">
	<div>
		<div style="padding-top: 10px;"></div>
		<h3>
			<f:if condition="{constraint.groupByPage}">
				<f:then>
					<f:if condition="{pid} < 1">
						<f:then>
							<f:if condition="{pid} == -1">
								<f:translate
									key="logForNonPageRelatedActionsOrRootLevelOrPage"
									arguments="{
										0: '{f:translate(key:\'forNonPageRelatedActions\')}',
										1: '{f:format.date(format:\'{settings.dateFormat} H:i\', date:\'@{constraint.startTimestamp}\')}',
										2: '{f:format.date(format:\'{settings.dateFormat} H:i\', date:\'@{constraint.endTimestamp}\')}'
									}"
								/>
							</f:if>
							<f:if condition="{pid} == 0">
								<f:translate
									key="logForNonPageRelatedActionsOrRootLevelOrPage"
									arguments="{
										0: '{f:translate(key:\'forRootLevel\')}',
										1: '{f:format.date(format:\'{settings.dateFormat} H:i\', date:\'@{constraint.startTimestamp}\')}',
										2: '{f:format.date(format:\'{settings.dateFormat} H:i\', date:\'@{constraint.endTimestamp}\')}'
									}"
								/>
							</f:if>
						</f:then>
						<f:else>
							<f:comment>
								Nest view helpers three times:
								1. Feed pid as argument to be.pagePath
								2. Use this as argument for 'forPage' translate
								3. Use this as argument for 'logForNonPageRelatedActionsOrRootLevelOrPage' translate
							</f:comment>
							<f:translate
								key="logForNonPageRelatedActionsOrRootLevelOrPage"
								arguments="{
									0: '{f:translate(
										key:\'forPage\',
										htmlEscape:\'0\',
										arguments:\'{
											0:\\\'{belog:be.pagePath(pid:\\\\\\\'{pid}\\\\\\\')}\\\',
											1:\\\'{pid}\\\'
										}\'
									)}',
									1: '{f:format.date(format:\'{settings.dateFormat} H:i\', date:\'@{constraint.startTimestamp}\')}',
									2: '{f:format.date(format:\'{settings.dateFormat} H:i\', date:\'@{constraint.endTimestamp}\')}'
								}"
							/>
						</f:else>
					</f:if>
				</f:then>
				<f:else>
					<f:translate
						key="logForNonPageRelatedActionsOrRootLevelOrPage"
						arguments="{
							0: '',
							1: '{f:format.date(format:\'{settings.dateFormat} H:i\', date:\'@{constraint.startTimestamp}\')}',
							2: '{f:format.date(format:\'{settings.dateFormat} H:i\', date:\'@{constraint.endTimestamp}\')}'
						}"
					/>
				</f:else>
			</f:if>
		</h3>
		<f:for each="{pidEntry}" as="day" key="dayTimestamp">
			<h4 class="uppercase">
				<f:format.date format="{settings.dateFormat}">@{dayTimestamp}</f:format.date>
			</h4>
			<table border="0" cellspacing="0" cellpadding="0" class="typo3-dblist">
				<thead>
					<tr>
						<th valign="top" class="t3-row-header">
							<strong>
								<f:translate key="chLog_l_error" />
							</strong>
						</th>
						<th class="t3-row-header"><img src="clear.gif" width="10" height="1" alt="" /></th>
						<th valign="top" class="t3-row-header">
							<strong>
								<f:translate key="chLog_l_time" />
							</strong>
						</th>
						<th class="t3-row-header"><img src="clear.gif" width="10" height="1" alt="" /></th>
						<th valign="top" class="t3-row-header">
							<strong>
								<f:translate key="chLog_l_user" />
							</strong>
						</th>
						<th class="t3-row-header"><img src="clear.gif" width="10" height="1" alt="" /></th>
						<th valign="top" class="t3-row-header">
							<strong>
								<f:if condition="{constraint.isInPageContext}">
									<f:then>
										<f:translate key="chLog_l_table" />
									</f:then>
									<f:else>
										<f:translate key="chLog_l_types" />
									</f:else>
								</f:if>
							</strong>
						</th>
						<th class="t3-row-header"><img src="clear.gif" width="10" height="1" alt="" /></th>
						<th valign="top" class="t3-row-header">
							<strong>
								<f:translate key="chLog_l_action" />
							</strong>
						</th>
						<th class="t3-row-header"><img src="clear.gif" width="10" height="1" alt="" /></th>
						<th valign="top" class="t3-row-header">
							<strong>
								<f:translate key="chLog_l_details" />
							</strong>
						</th>
						<th class="t3-row-header"><img src="clear.gif" width="10" height="1" alt="" /></th>
					</tr>
				</thead>
				<tbody>
					<f:for each="{day}" as="logItem">
						<tr>
							<td valign="top">
								<belog:ErrorIcon errorNumber="{logItem.error}" />
							</td>
							<td><img src="clear.gif" width="10" height="1" alt="" /></td>

							<td valign="top">
								<f:format.date format="H:i:s">@{logItem.tstamp}</f:format.date>
							</td>
							<td><img src="clear.gif" width="10" height="1" alt="" /></td>

							<td valign="top">
								<f:if condition="{belog:username(uid:logItem.backendUserUid)}">
									<f:then><belog:username uid="{logItem.backendUserUid}" /></f:then>
									<f:else>[{logItem.backendUserUid}]</f:else>
								</f:if>@<f:if condition="{belog:workspaceTitle(uid:logItem.workspaceUid)}">
									<f:then><belog:workspaceTitle uid="{logItem.workspaceUid}" /></f:then>
									<f:else>[{logItem.workspaceUid}]</f:else>
								</f:if>
							</td>
							<td><img src="clear.gif" width="10" height="1" alt="" /></td>

							<td valign="top">
								<f:if condition="{constraint.isInPageContext}">
									<f:then>
										{logItem.tableName}
									</f:then>
									<f:else>
										<f:if condition="{f:translate(key:'type_{logItem.type}')}">
											<f:then>
												<f:translate key="type_{logItem.type}" />
											</f:then>
											<f:else>
												[{logItem.type}]
											</f:else>
										</f:if>
									</f:else>
								</f:if>
							</td>
							<td><img src="clear.gif" width="10" height="1" alt="" /></td>

							<td valign="top">
								<f:if condition="{f:translate(key:'action_{logItem.type}_{logItem.action}')}">
									<f:then>
										<f:translate
											key="action_{logItem.type}_{logItem.action}"
											htmlEscape="0"
										/>
									</f:then>
									<f:else>
										[{logItem.action}]
									</f:else>
								</f:if>
							</td>
							<td><img src="clear.gif" width="10" height="1" alt="" /></td>

							<td valign="top">
								<belog:formatDetails logEntry="{logItem}" />
								<belog:historyEntry uid="{logItem.uid}" />
								<f:if condition="{logItem.detailsNumber} > 0">
									(msg#{logItem.type}.{logItem.action}.{logItem.detailsNumber})
								</f:if>
							</td>
							<td><img src="clear.gif" width="10" height="1" alt="" /></td>
						</tr>
					</f:for>
				</tbody>
			</table>
		</f:for>
	</div>
</f:for>