<!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}? ${cache.masterIndex.format} : 'LEGACY'">VERSIONED</td>
				</tr>
				<tr>
					<th class="table-dark">Archives</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:if="${cache.stats != null and cache.stats.diskStoreValid}"
								   th:href="${'/caches/' + scope + '/' + cache.id + '/disk.zip'}"
								   class="btn btn-primary btn-sm">Cache (.dat2/.idx)</a>
								<a th:href="${'/caches/' + scope + '/' + cache.id + '/flat-file.tar.gz'}"
								   class="btn btn-primary btn-sm">Cache (Flat file)</a>
							</div>
							<div class="btn-group me-2">
								<a th:href="${'/caches/' + scope + '/' + cache.id + '/keys.json'}"
								   class="btn btn-primary btn-sm">Keys (JSON)</a>
								<a th:href="${'/caches/' + scope + '/' + cache.id + '/keys.zip'}"
								   class="btn btn-primary btn-sm">Keys (Text)</a>
							</div>
							<div class="btn-group">
								<a th:href="${'/caches/' + scope + '/' + cache.id + '/map.png'}"
								   class="btn btn-primary btn-sm">Map</a>
							</div>
						</div>
					</td>
				</tr>
				<tr>
					<th class="table-dark">Update(s)</th>
					<td>
						<span th:each="update, it : ${cache.updates}" th:remove="tag">
							<a th:href="${update}" th:text="${update}">https://www.example.com/</a>
							<br th:remove="${it.last}? 'all' : 'none'" />
						</span>
					</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>Environment</th>
							<th>Language</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.environment}">live</td>
							<td th:text="${source.language}">en</td>
							<td th:text="${source.build}" class="text-end">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>

			<div th:if="${cache.masterIndex}" th:remove="tag">
				<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>Groups</th>
								<th>Keys<sup><a href="/caches#empty-locs">1</a></sup></th>
								<th>Size<sup><a href="/caches#size">2</a></sup></th>
							</tr>
						</thead>
						<tbody>
							<tr th:each="entry, it : ${cache.masterIndex.entries}" th:with="archive=${cache.archives[it.index]}">
								<td th:text="${it.index}" class="text-end">0</td>
								<td th:text="${#numbers.formatInteger(entry.version, 1, 'COMMA')}" class="text-end">0</td>
								<td class="text-end">
									<code th:text="${entry.checksum}">0</code>
								</td>
								<div th:switch="true" th:remove="tag">
									<div th:case="${archive.stats != null}" th:remove="tag">
										<td th:classappend="${archive.stats.allGroupsValid}? 'table-success' : 'table-warning'" class="text-end">
											<span th:text="${#numbers.formatInteger(archive.stats.validGroups, 1, 'COMMA')} + '&nbsp;/&nbsp;' + ${#numbers.formatInteger(archive.stats.groups, 1, 'COMMA')}"></span>
											<br />
											<span th:text="'(' + ${#numbers.formatPercent(archive.stats.validGroupsFraction, 1, 2)} + ')'"></span>
										</td>
										<td th:classappend="${archive.stats.allKeysValid}? 'table-success' : 'table-warning'" class="text-end">
											<span th:text="${#numbers.formatInteger(archive.stats.validKeys, 1, 'COMMA')} + '&nbsp;/&nbsp;' + ${#numbers.formatInteger(archive.stats.keys, 1, 'COMMA')}"></span>
											<br />
											<span th:text="'(' + ${#numbers.formatPercent(archive.stats.validKeysFraction, 1, 2)} + ')'"></span>
										</td>
										<!--/*@thymesVar id="#byteunits" type="org.openrs2.archive.web.ByteUnits"*/-->
										<td th:text="${#byteunits.format(archive.stats.size)}" class="text-end">0 B</td>
									</div>
									<div th:case="${archive.resolved}" th:remove="tag">
										<td class="text-center" colspan="3">Calculating...</td>
									</div>
									<div th:case="${entry.checksum != 0 || entry.version != 0}" th:remove="tag">
										<td class="text-center table-danger" colspan="3">Index missing</td>
									</div>
									<div th:case="true" th:remove="tag">
										<td class="text-center text-muted" colspan="3">N/A</td>
									</div>
								</div>
							</tr>
						</tbody>
					</table>
				</div>
			</div>

			<div th:if="${cache.checksumTable}" th:remove="tag">
				<h2>Checksum table</h2>

				<div class="table-responsive">
					<table class="table table-striped table-bordered table-hover">
						<thead class="table-dark">
							<tr>
								<th>Archive</th>
								<th>Checksum</th>
								<th>Size<sup><a href="/caches#size">2</a></sup></th>
							</tr>
						</thead>
						<tbody>
							<tr th:each="entry, it : ${cache.checksumTable.entries}" th:with="archive=${cache.archives[it.index]}">
								<td th:text="${it.index}" class="text-end">0</td>
								<td class="text-end">
									<code th:text="${entry}">0</code>
								</td>
								<div th:switch="true" th:remove="tag">
									<!--/*@thymesVar id="#byteunits" type="org.openrs2.archive.web.ByteUnits"*/-->
									<td th:case="${archive.stats != null}" th:text="${#byteunits.format(archive.stats.size)}" class="text-end">0 B</td>
									<td th:case="${archive.resolved}" class="text-center">Calculating...</td>
									<td th:case="${entry != 0}" class="text-center table-danger">Missing</td>
									<td th:case="true" class="text-center text-muted">N/A</td>
								</div>
							</tr>
						</tbody>
					</table>
				</div>

				<div th:if="${cache.indexes}" th:remove="tag">
					<h2>Version list</h2>

					<div class="table-responsive">
						<table class="table table-striped table-bordered table-hover">
							<thead class="table-dark">
								<tr>
									<th>Index</th>
									<th>Files</th>
									<th>Size<sup><a href="/caches#size">2</a></sup></th>
								</tr>
							</thead>
							<tbody>
								<tr th:each="index, it : ${cache.indexes}">
									<td th:text="${it.index + 1}" class="text-end">0</td>
									<td th:classappend="${index.allFilesValid}? 'table-success' : 'table-warning'" class="text-end">
										<span th:text="${#numbers.formatInteger(index.validFiles, 1, 'COMMA')} + '&nbsp;/&nbsp;' + ${#numbers.formatInteger(index.files, 1, 'COMMA')}"></span>
										<br />
										<span th:text="'(' + ${#numbers.formatPercent(index.validFilesFraction, 1, 2)} + ')'"></span>
									</td>
									<!--/*@thymesVar id="#byteunits" type="org.openrs2.archive.web.ByteUnits"*/-->
									<td th:text="${#byteunits.format(index.size)}" class="text-end">0 B</td>
								</tr>
							</tbody>
						</table>
					</div>
				</div>
			</div>
		</main>
	</body>
</html>
