<!-- Copyright (C) Microsoft Corporation. All rights reserved. -->
<!DOCTYPE html>
<html>
	<head>
		<script>
			performance.mark('code/didStartRenderer');
		</script>
		<meta charset="utf-8" />

		<!-- Mobile tweaks -->
		<meta name="mobile-web-app-capable" content="yes" />
		<meta name="apple-mobile-web-app-capable" content="yes" />
		<meta name="apple-mobile-web-app-title" content="Code">
		<link rel="apple-touch-icon" href="{{WORKBENCH_WEB_BASE_URL}}/resources/server/code-192.png" />

		<!-- Disable pinch zooming -->
		<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no">

		<!-- Workbench Configuration -->
		<meta id="vscode-workbench-web-configuration" data-settings="{{WORKBENCH_WEB_CONFIGURATION}}">

		<!-- Workbench Auth Session -->
		<meta id="vscode-workbench-auth-session" data-settings="{{WORKBENCH_AUTH_SESSION}}">

		<!-- NLS Configuration -->
		<meta id="vscode-remote-nls-configuration" data-settings="{{NLS_CONFIGURATION}}">

		<!-- Workbench Icon/Manifest/CSS -->
		<link rel="icon" href="{{WORKBENCH_WEB_BASE_URL}}/resources/server/favicon.ico" type="image/x-icon" />
		<link rel="manifest" href=".{{STATIC_ROUTE}}/resources/server/manifest.json" crossorigin="use-credentials" />
		<link data-name="vs/workbench/workbench.web.main" rel="stylesheet" href="{{WORKBENCH_WEB_BASE_URL}}/out/vs/workbench/workbench.web.main.css">
		<script src="https://cdn-go.cn/aegis/aegis-sdk/latest/aegis.min.js"></script>
		<script>
			const getId = () => {
					const hostname = window.location.hostname;
					switch (true) {
						case hostname.includes("cloudstudio"):
							return 'okyPOubvJnKY2KEQ9m';
						case hostname.includes('tencent'):
							return '3o0lYfLoO0JL9rmbgO';
					}
					return '2epG3TKoKzZY1eg7zE';
				};
				const aegis = new Aegis({
					id: getId(), // 上报 id
					reportApiSpeed: true, // 接口测速
					reportAssetSpeed: true, // 静态资源测速
					spa: true, // spa 应用页面跳转的时候开启 pv 计算
				});
		</script>
		<style>
			.loading-iframe {
				position: absolute;
				top: 0;
				left: 0;
				right: 0;
				bottom: 0;
				width: 100%;
				height: 100%;
				border: none;
			}
			.workspace-loader {
				visibility: hidden;
				position: absolute;
			}
		</style>
	</head>

	<body aria-label="">
		<iframe class="loading-iframe" src="{{WORKBENCH_WEB_BASE_URL}}/out/vs/code/browser/workbench/loading.html"></iframe>
		<iframe class="workspace-loader" src="{{HIDDEN_IFRAME_URL}}"></iframe>
	</body>

	<!-- Startup (do not modify order of script tags!) -->
	<script src="{{WORKBENCH_WEB_BASE_URL}}/out/vs/loader.js"></script>
	<script src="{{WORKBENCH_WEB_BASE_URL}}/out/vs/webPackagePaths.js"></script>
	<script>
		let pathname = window.location.pathname;
		pathname = pathname.endsWith('/') ? pathname.substring(0, pathname.length - 1) : pathname;
		const baseUrl = new URL('{{WORKBENCH_WEB_BASE_URL}}', window.location.origin + pathname + '/').toString();
		try {
			const colorInfo = JSON.parse(localStorage.getItem("monaco-parts-splash")).colorInfo;
			const { background, foreground } = colorInfo;
			document.body.style.background = background;
			window.frames[0].postMessage({ background, foreground }, '*')
		} catch (error) {
			document.body.style.background =  '#1e1e1e';
		}

		if (typeof navigator !== 'undefined' && 'serviceWorker' in navigator) {
			navigator.serviceWorker.register('./_static/out/browser/serviceWorker.js', {
				scope: '/',
			}).then(function() {
				console.info('[Service Worker] registered');
			})
			.catch(function(error) {
				console.error('[Service Worker] registration', error);
			});
		}

		/**
		 * Updated to use relative path.
		 * Use relative paths and NLS configuration (based on
		 * ../../../../bootstrap.js).
		 * @author cs
		 */
		let nlsConfig;
		try {
			nlsConfig = JSON.parse(document.getElementById("vscode-remote-nls-configuration").getAttribute("data-settings"));
			if (nlsConfig._resolvedLanguagePackCoreLocation) {
				const bundles = Object.create(null)
				nlsConfig.loadBundle = (bundle, _language, cb) => {
					const result = bundles[bundle]
					if (result) {
						return cb(undefined, result)
					}

					const href = window.location.href;
					const token = new URL(href).searchParams.get('token') || '';
					const path = nlsConfig._resolvedLanguagePackCoreLocation + "/" + bundle.replace(/\//g, "!") + ".nls.json"
					query = `?path=${encodeURIComponent(path)}`
					if (token) {
						query += `&token=${encodeURIComponent(token)}`;
					}
					fetch(`${window.location.origin}${pathname}/vscode-remote-resource${query}`)
						.then((response) => response.json())
						.then((json) => {
							bundles[bundle] = json
							cb(undefined, json)
						})
						.catch(cb)
				}
			}
		} catch (error) { /* Probably fine. */ }
		Object.keys(self.webPackagePaths).map(function (key, index) {
			self.webPackagePaths[key] = `${baseUrl}/node_modules/${key}/${self.webPackagePaths[key]}`;
		});

		// Set up nls if the user is not using the default language (English)
		// const nlsConfig = {};
		// const locale = window.localStorage.getItem('vscode.nls.locale') || navigator.language;
		// if (!locale.startsWith('en')) {
		// 	nlsConfig['vs/nls'] = {
		// 		availableLanguages: {
		// 			'*': locale
		// 		},
		// 		translationServiceUrl: '{{WORKBENCH_NLS_BASE_URL}}'
		// 	};
		// }

		require.config({
			baseUrl: `${baseUrl}/out`,
			recordStats: true,
			trustedTypesPolicy: window.trustedTypes?.createPolicy('amdLoader', {
				createScriptURL(value) {
					return value;
				}
			}),
			paths: self.webPackagePaths,
			'vs/nls': nlsConfig
		});
	</script>
	<script>
		performance.mark('code/willLoadWorkbenchMain');
	</script>
	<script src="{{WORKBENCH_WEB_BASE_URL}}/out/vs/workbench/workbench.web.main.nls.js"></script>
	<script src="{{WORKBENCH_WEB_BASE_URL}}/out/vs/workbench/workbench.web.main.js"></script>
	<script src="{{WORKBENCH_WEB_BASE_URL}}/out/vs/code/browser/workbench/workbench.js"></script>
</html>
