<script lang="ts">
	import { getVersionUpdates } from '$lib/apis';
	import { getOllamaVersion } from '$lib/apis/ollama';
	import { WEBUI_BUILD_HASH, WEBUI_VERSION } from '$lib/constants';
	import { compareVersion } from '$lib/utils';
	import { onMount, getContext } from 'svelte';

	const i18n = getContext('i18n');

	let ollamaVersion = '';

	let updateAvailable = null;
	let version = {
		current: '',
		latest: ''
	};

	const checkForVersionUpdates = async () => {
		updateAvailable = null;
		version = await getVersionUpdates(localStorage.token).catch((error) => {
			return {
				current: WEBUI_VERSION,
				latest: WEBUI_VERSION
			};
		});

		console.log(version);

		updateAvailable = compareVersion(version.latest, version.current);
		console.log(updateAvailable);
	};

	onMount(async () => {
		ollamaVersion = await getOllamaVersion(localStorage.token).catch((error) => {
			return '';
		});

		checkForVersionUpdates();
	});
</script>

<div class="flex flex-col h-full justify-between space-y-3 text-sm mb-6">
	<div class=" space-y-3 overflow-y-scroll max-h-[28rem] lg:max-h-full">
		<div>
			<div class="mb-2.5 text-sm font-medium">关于宇光同行AI</div>
			<div class="flex w-full">
				<div class="flex-1 text-xs text-gray-700 dark:text-gray-200">
					宇光同行AI chat平台是一个先进的人工智能对话系统，致力于为用户提供智能、专业的对话服务。
					我们整合了多种大语言模型，支持中英文等多语言交互，可应用于教育、商业、技术支持等多个领域。
					
					<div class="mt-4">
						<div class="font-medium mb-2">平台特点：</div>
						<ul class="list-disc pl-5 space-y-1">
							<li>支持多种AI模型接入</li>
							<li>安全可靠的对话环境</li>
							<li>简洁直观的用户界面</li>
							<li>持续更新优化的服务</li>
						</ul>
					</div>
				</div>
			</div>
		</div>

		<hr class="border-gray-100 dark:border-gray-850" />

		{#if ollamaVersion}
			<div>
				<div class=" mb-2.5 text-sm font-medium">{$i18n.t('Ollama Version')}</div>
				<div class="flex w-full">
					<div class="flex-1 text-xs text-gray-700 dark:text-gray-200">
						{ollamaVersion ?? 'N/A'}
					</div>
				</div>
			</div>
		{/if}

	</div>
</div>
