<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" lang="en">
	<head th:replace="layout.html :: head(title='Cache')">
		<title>Cache - OpenRS2 Archive</title>
		<link rel="stylesheet" href="/webjars/bootstrap/css/bootstrap.min.css" />
		<link rel="stylesheet" href="/static/css/openrs2.css" />
		<script src="/webjars/jquery/jquery.min.js" defer></script>
		<script src="/webjars/bootstrap/js/bootstrap.bundle.min.js" defer></script>
	</head>
	<body>
		<nav th:replace="layout.html :: nav"></nav>
		<main class="container">
			<h1>Cache</h1>

			<!--/*@thymesVar id="cache" type="org.openrs2.archive.cache.CacheExporter.Cache"*/-->
			<table class="table table-striped table-bordered table-hover">
				<tr>
					<th class="table-dark">Format</th>
					<td th:text="${cache.masterIndex.format}">VERSIONED</td>
				</tr>
				<tr>
					<th class="table-dark">Indexes</th>
					<td th:class="${cache.stats}? (${cache.stats.allIndexesValid}? 'table-success' : 'table-danger')"
					    th:text="${cache.stats}? ${cache.stats.validIndexes} + ' / ' + ${cache.stats.indexes} + ' (' + ${#numbers.formatPercent(cache.stats.validIndexesFraction, 1, 2)} + ')' : 'Calculating...'">
						Calculating...
					</td>
				</tr>
				<tr>
					<th class="table-dark">Groups</th>
					<td th:class="${cache.stats}? (${cache.stats.allGroupsValid}? 'table-success' : 'table-warning')"
					    th:text="${cache.stats}? ${#numbers.formatInteger(cache.stats.validGroups, 1, 'COMMA')} + ' / ' + ${#numbers.formatInteger(cache.stats.groups, 1, 'COMMA')} + ' (' + ${#numbers.formatPercent(cache.stats.validGroupsFraction, 1, 2)} + ')' : 'Calculating...'">
						Calculating...
					</td>
				</tr>
				<tr>
					<th class="table-dark">Keys<sup><a href="/caches#empty-locs">1</a></sup></th>
					<td th:class="${cache.stats}? (${cache.stats.allKeysValid}? 'table-success' : 'table-warning')"
					    th:text="${cache.stats}? ${#numbers.formatInteger(cache.stats.validKeys, 1, 'COMMA')} + ' / ' + ${#numbers.formatInteger(cache.stats.keys, 1, 'COMMA')} + ' (' + ${#numbers.formatPercent(cache.stats.validKeysFraction, 1, 2)} + ')' : 'Calculating...'">
						Calculating...
					</td>
				</tr>
				<tr>
					<th class="table-dark">Size<sup><a href="/caches#size">2</a></sup></th>
					<!--/*@thymesVar id="#byteunits" type="org.openrs2.archive.web.ByteUnits"*/-->
					<td th:text="${cache.stats}? ${#byteunits.format(cache.stats.size)} : 'Calculating...'">
						Calculating...
					</td>
				</tr>
				<tr>
					<th class="table-dark">Download</th>
					<td>
						<div class="btn-toolbar">
							<div class="btn-group me-2">
								<a th:href="${'/caches/' + cache.id + '/disk.zip'}"
								   class="btn btn-primary btn-sm">Cache (.dat2/.idx)</a>
								<a th:href="${'/caches/' + cache.id + '/flat-file.zip'}"
								   class="btn btn-primary btn-sm">Cache (Flat file)</a>
							</div>
							<div class="btn-group me-2">
								<a th:href="${'/caches/' + cache.id + '/keys.json'}"
								   class="btn btn-primary btn-sm">Keys (JSON)</a>
								<a th:href="${'/caches/' + cache.id + '/keys.zip'}"
								   class="btn btn-primary btn-sm">Keys (Text)</a>
							</div>
							<div class="btn-group">
								<a th:href="${'/caches/' + cache.id + '/map.png'}"
								   class="btn btn-primary btn-sm">Map</a>
							</div>
						</div>
					</td>
				</tr>
			</table>

			<h2>Sources</h2>

			<div class="table-responsive">
				<table class="table table-striped table-bordered table-hover">
					<thead class="table-dark">
						<tr>
							<th>Game</th>
							<th>Build</th>
							<th>Timestamp</th>
							<th>Name</th>
							<th>Description</th>
							<th>URL</th>
						</tr>
					</thead>
					<tbody>
						<tr th:each="source : ${cache.sources}">
							<td th:text="${source.game}">runescape</td>
							<td th:text="${source.build}" class="text-right">550</td>
							<td th:text="${#temporals.format(source.timestamp, 'yyyy-MM-dd HH:mm:ss')}"></td>
							<td th:text="${source.name}"></td>
							<td th:text="${source.description}"></td>
							<td>
								<a th:href="${source.url}" th:text="${source.url}" th:if="${source.url}">https://www.example.com/</a>
							</td>
						</tr>
					</tbody>
				</table>
			</div>

			<h2>Master index</h2>

			<div class="table-responsive">
				<table class="table table-striped table-bordered table-hover">
					<thead class="table-dark">
						<tr>
							<th>Archive</th>
							<th>Version</th>
							<th>Checksum</th>
							<th>Digest</th>
							<th>Groups</th>
							<th>Total uncompressed length</th>
						</tr>
					</thead>
					<tbody>
						<tr th:each="entry, it : ${cache.masterIndex.entries}">
							<td th:text="${it.index}" class="text-right">0</td>
							<td th:text="${#numbers.formatInteger(entry.version, 1, 'COMMA')}" class="text-right">0</td>
							<td class="text-right">
								<code th:text="${entry.checksum}">0</code>
							</td>
							<td>
								<code
									th:if="${cache.masterIndex.format >= @org.openrs2.cache.MasterIndexFormat@DIGESTS}"><span
									th:remove="tag"
									th:text="${@io.netty.buffer.ByteBufUtil@hexDump(entry.digest).substring(0, 64)}"></span>&ZeroWidthSpace;<span
									th:remove="tag"
									th:text="${@io.netty.buffer.ByteBufUtil@hexDump(entry.digest).substring(64)}"></span></code>
							</td>
							<td class="text-right">
								<span
									th:if="${cache.masterIndex.format >= @org.openrs2.cache.MasterIndexFormat@LENGTHS}"
									th:text="${#numbers.formatInteger(entry.groups, 1, 'COMMA')}"></span>
							</td>
							<td class="text-right">
								<!--/*@thymesVar id="#byteunits" type="org.openrs2.archive.web.ByteUnits"*/-->
								<span
									th:if="${cache.masterIndex.format >= @org.openrs2.cache.MasterIndexFormat@LENGTHS}"
									th:text="${#byteunits.format(@java.lang.Integer@toUnsignedLong(entry.totalUncompressedLength))}"></span>
							</td>
						</tr>
					</tbody>
				</table>
			</div>
		</main>
	</body>
</html>
