<template>
	<div class="knowledge-management-page">
		<div class="header">
			<div class="flex items-center justify-between">
				<h1>知识库</h1>
			</div>
			<p class="subtitle">统一管理知识库，并在库内处理知识内容和问答条目。</p>
		</div>
		<div class="main-container">
			<KnowledgeBaseSidebar :current-base-id="currentBase?.id!" @select-base="handleSelectBase" />
			<div v-if="currentBase" class="content-container">
				<el-tabs v-model="currentModule" type="border-card">
					<el-tab-pane label="知识" name="document" v-if="currentBase.type === 'document'">
						<DocumentManage v-if="currentModule === 'document'" :current-base="currentBase" />
					</el-tab-pane>
					<el-tab-pane label="Wiki" name="wiki" v-if="currentBase.type === 'document'">
						<WikiManage v-if="currentModule === 'wiki'" :current-base="currentBase" mode="wiki" />
					</el-tab-pane>
					<el-tab-pane label="知识图谱" name="graph" v-if="currentBase.type === 'document'">
						<WikiManage v-if="currentModule === 'graph'" :current-base="currentBase" mode="graph" />
					</el-tab-pane>
					<el-tab-pane label="问答" name="qa" v-if="currentBase.type === 'faq'">
						<QaManage v-if="currentModule === 'qa'" :current-base-id="currentBase?.id!" />
					</el-tab-pane>
				</el-tabs>
			</div>
			<el-empty v-else description="请先在左侧选择一个知识库" class="empty-container" />
		</div>
	</div>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import DocumentManage from './DocumentManage.vue'
import KnowledgeBaseSidebar from './KnowledgeBaseSidebar.vue'
import QaManage from './QaManage.vue'
import type { KnowledgeBaseItem } from './types'
import WikiManage from './WikiManage.vue'

const currentBase = ref<KnowledgeBaseItem>()
const currentModule = ref<'document' | 'qa' | 'wiki' | 'graph'>('document')

function handleSelectBase(base?: KnowledgeBaseItem) {
	currentBase.value = base
	currentModule.value = base?.type === 'document' ? 'document' : 'qa'
}
</script>

<style scoped lang="less">
.knowledge-management-page {
	min-height: 100%;
	padding: 24px;
	background: #f5f7fa;
	box-sizing: border-box;
}

.header {
	margin-bottom: 16px;

	h1 {
		margin: 0;
		font-size: 28px;
		color: var(--text-primary);
	}
}

.subtitle {
	margin: 6px 0 0;
	font-size: 14px;
	color: var(--text-secondary);
}

.main-container {
	display: flex;
	gap: 16px;
	align-items: stretch;
	min-height: calc(100vh - 108px);
}

.content-container {
	flex: 1;
	min-width: 0;

	:deep(.el-tabs) {
		height: 100%;
		border-radius: 12px;
		overflow: hidden;
	}

	:deep(.el-tabs__content) {
		min-height: calc(100vh - 250px);
		padding-top: 16px;
		background: #fff;
	}
}

.empty-container {
	flex: 1;
	display: flex;
	align-items: center;
	justify-content: center;
	min-height: calc(100vh - 108px);
	border-radius: 12px;
	background: #fff;
}

@media (max-width: 960px) {
	.main-container {
		flex-direction: column;
	}
}
</style>
