<template>
	<div class="page-container">
		<div style="height: 30px; width: 960px; display: flex; justify-content: flex-start">
			<el-breadcrumb :separator-icon="ArrowRight">
				<el-breadcrumb-item>国家科技安全</el-breadcrumb-item>
				<el-breadcrumb-item>中美博弈概览</el-breadcrumb-item>
				<el-breadcrumb-item :to="{ path: '/' }">科研资助体系</el-breadcrumb-item>
			</el-breadcrumb>
		</div>
		<el-input v-model="searchKey" style="max-width: 960px" placeholder="搜索政策关键词" class="input-with-select">
			<template #append>
				<el-button :icon="Search" size="large" type="primary">搜索</el-button>
			</template>
		</el-input>
		<div class="page-data">
			<div class="page-data-item" v-for="item in pageData" :key="item.desc">
				<div class="page-data-item-num">
					{{ item.num }}
				</div>
				<div class="page-data-item-desc">
					{{ item.desc }}
				</div>
			</div>
		</div>

		<div class="page-content">
			<el-row :gutter="20">
				<el-col :span="16">
					<custom-container title="美国对华规则限制动态" height="450px">
						<template #header-left>
							<div class="custom-container-header-left">
								<img class="custom-container-icon" src="@/assets/images/icon-law.png" alt="" />
								<span class="custom-container-title">美国联邦科研决策和资助体系</span>
							</div>
						</template>
						<!-- 顶部右侧自定义内容 -->
						<template #header-right>
							<div style="display: flex; gap: 12px">
								<el-button type="primary" link>查看详情 ></el-button>
							</div>
						</template>

						<!-- 中间内容自定义 -->
						<template #default>
							<div ref="treeRef" style="height: 340px; width: 100%"></div>
						</template>
					</custom-container>
				</el-col>
				<el-col :span="8">
					<custom-container title="风险信号" height="450px">
						<template #header-left>
							<div class="custom-container-header-left">
								<img class="custom-container-icon" src="@/assets/images/icon-warning.png" alt="" />
								<span class="custom-container-title">风险信号</span>
								<span class="custom-container-count">5</span>
							</div>
						</template>
						<!-- 顶部右侧自定义内容 -->
						<template #header-right>
							<div style="display: flex; gap: 12px">
								<el-button type="primary" link>更多 ></el-button>
							</div>
						</template>

						<!-- 中间内容自定义 -->
						<template #default>
							<div class="content-list-card" v-for="item in riskData" :key="item.title">
								<el-tag :type="item.danger" size="small">{{ item.importance }}</el-tag>
								<div class="content-list">
									<div class="content-list-title">{{ item.title }}</div>
									<div class="content-list-time">{{ item.date }}</div>
								</div>
							</div>
							<div class="content-list-footer">
								<el-button type="primary" size="default" style="width: 100%">
									<img class="icon-mark" src="@/assets/images/icon-mark.png" alt="" />
									风险处理
								</el-button>
							</div>
						</template>
					</custom-container>
				</el-col>
			</el-row>
			<el-row :gutter="20">
				<custom-container title="科技领域重点布局" height="520px">
					<!-- 顶部右侧自定义内容 -->
					<template #header-right>
						<div style="display: flex; gap: 12px">
							<el-button type="primary" link>查看详情 ></el-button>
						</div>
					</template>

					<!-- 中间内容自定义 -->
					<template #default>
						<div class="content-chart">
							<div class="content-chart-radio">
								<el-radio-group v-model="radio" size="small">
									<el-radio label="1">人工智能</el-radio>
									<el-radio label="2">量子技术</el-radio>
									<el-radio label="2">半导体</el-radio>
									<el-radio label="2">生物技术</el-radio>
									<el-radio label="2">能源技术</el-radio>
								</el-radio-group>
							</div>
							<div class="content-chart-wrapper">
								<el-row :gutter="20">
									<el-col :span="10">
										<div ref="pieRef" style="height: 400px; width: 100%"></div>
										<!-- <ECharts ref="pieRef" :option="pieOption" autoresize :style="{ height: '326px' }" /> -->
									</el-col>
									<el-col :span="14">
										<div class="content-list-item" v-for="item in policyBanData" :key="item.title">
											<div class="content-card-title-text-2">
												<!-- <el-tag :type="item.danger" size="small">{{ item.importance }}</el-tag> -->
												<div class="content-card-title-text">{{ item.title }}</div>
												<div class="content-card-desc">{{ item.desc }}</div>
												<div class="content-card-tag-box">
													<div class="content-card-tag-box-item">
														<el-tag :type="tagType[Math.floor(Math.random() * 5)]" v-for="tag in item.tag" :key="tag">{{
															tag
														}}</el-tag>
													</div>
													<!-- <el-button class="content-card-tag-btn" type="primary" link>查看全文 ></el-button> -->
												</div>
											</div>
											<div class="content-list-item-money">
												{{ item.money }}
											</div>
										</div>
									</el-col>
								</el-row>
							</div>
						</div>
					</template>
				</custom-container>
			</el-row>
			<el-row :gutter="20">
				<el-image :src="BGC" style="height: 429px; width: 100%"></el-image>
			</el-row>
		</div>
	</div>
</template>

<script setup>
import { onMounted, ref } from "vue";
import { Search } from "@element-plus/icons-vue";
import { ArrowRight } from "@element-plus/icons-vue";
import ECharts from "@/components/Chart/index.vue";
import CustomContainer from "@/components/Container/index.vue";
import { useEcharts } from "@/hooks/useEcharts";
import echarts from "@/plugins/echarts";
import { treeData } from "./mock";
import { TreeChart } from "echarts/charts"; // 树图组件
import BGC from "@/assets/images/bgc-mock.png";

// 导入必要的组件
import { TitleComponent, TooltipComponent, LegendComponent } from "echarts/components";

// 导入渲染器（Canvas或SVG）
import { CanvasRenderer } from "echarts/renderers";

// 2. 注册所有需要的组件
echarts.use([
	TreeChart, // 树图图表
	TitleComponent, // 标题组件
	TooltipComponent, // 提示框组件
	LegendComponent, // 图例组件
	CanvasRenderer // 渲染器:cite[7]
]);

const searchKey = ref("");
const pageData = ref([
	{
		num: 310,
		desc: "生效政策禁令"
	},
	{
		num: 14433,
		desc: "受限制实体"
	},
	{
		num: 126,
		desc: "受限制领域"
	},
	{
		num: 16,
		desc: "本月更新"
	}
]);

const riskData = ref([
	{
		date: "一天前",
		importance: "特别重大",
		danger: "danger",
		title: "美国大而美法案落地，总统签署通过"
	},
	{
		date: "两天前",
		importance: "重大风险",
		danger: "warning",
		title: "美大而美法案7月1日以51:50的票数通过..."
	},
	{
		date: "三天前",
		importance: "特别重大",
		danger: "danger",
		title: "首次提出“限制外国敏感实体获取补贴”"
	},
	{
		date: "四天前",
		importance: "一般风险",
		danger: "success",
		title: "将中国企业海外子公司、合资公司纳入受..."
	},
	{
		date: "五天前",
		importance: "一般风险",
		danger: "success",
		title: "H.R.8333《生物安全法案》将华大基因等..."
	}
]);
const treeRef = ref(null);
const pieRef = ref(null);
const treeOption = {
	tooltip: {
		trigger: "item",
		triggerOn: "mousemove"
	},
	series: [
		{
			type: "tree",
			data: [treeData],
			top: "1%",
			left: "7%",
			bottom: "1%",
			right: "20%",
			symbolSize: 7,
			label: {
				position: "left",
				verticalAlign: "middle",
				align: "right",
				fontSize: 9
			},
			leaves: {
				label: {
					position: "right",
					verticalAlign: "middle",
					align: "left"
				}
			},
			emphasis: {
				focus: "descendant"
			},
			expandAndCollapse: true,
			animationDuration: 550,
			animationDurationUpdate: 750
		}
	]
};
const pieOption = ref(null);
onMounted(() => {
	const treeChart = echarts.init(treeRef.value);
	const pieChart = echarts.init(pieRef.value);
	// tree.setOption(treeOption);
	pieOption.value = {
		title: {
			text: "",
			left: "center",
			textStyle: {
				color: "#999",
				fontWeight: "normal",
				fontSize: 14
			}
		},
		series: {
			type: "pie",
			radius: [70, 90],
			top: -10 + "%",
			//   height: '33.33%',
			left: "center",
			width: 500,
			itemStyle: {
				borderColor: "#fff",
				borderWidth: 1
			},
			label: {
				alignTo: "edge",
				// formatter: "{name|{b}}\n{time|{c} 小时}",
				formatter: "{name|{b}}\n",
				minMargin: 20,
				edgeDistance: 0,
				lineHeight: 15,
				rich: {
					time: {
						fontSize: 10,
						color: "#999"
					}
				}
			},
			labelLine: {
				length: 15,
				length2: 0,
				maxSurfaceAngle: 80
			},
			labelLayout: function (params) {
				const isLeft = params.labelRect.x < pieChart.getWidth() / 2;
				const points = params.labelLinePoints;
				// Update the end point.
				points[2][0] = isLeft ? params.labelRect.x : params.labelRect.x + params.labelRect.width;
				return {
					labelLinePoints: points
				};
			},
			data: [
				{ name: "专家系统", value: 5.6 },
				{ name: "机器人技术", value: 1 },
				{ name: "自动驾驶", value: 0.8 },
				{ name: "机器学习", value: 0.5 },
				{ name: "自然语言处理", value: 0.5 },
				{ name: "计算机视觉", value: 0.5 },
				{ name: "其它", value: 3.8 }
			]
		}
	};
	console.log("树形结构数据 =>", treeOption, treeRef.value);

	useEcharts(treeChart, treeOption);
	useEcharts(pieChart, pieOption.value);
});
// tag类型
const tagType = ["primary", "success", "info", "warning", "danger"];
const policyBanData = ref([
	{
		title: "《美国优先投资政策》总统备忘录",
		desc: `2025年2月签署，限制美国资本投资中国"军民融合"战略相关产业，并审查甚至阻止中国对美关键领域的投资。备忘录扩大CFIUS的审查范围，要求将限制领域扩展到"医疗、农业、能源、原材料等战略行业"。`,
		tag: ["投资审查", "国家暗安全"],
		money: "$125M"
	},
	{
		title: "《外国公司问责法》",
		desc: `2025年2月签署，限制美国资本投资中国"军民融合"战略相关产业，并审查甚至阻止中国对美关键领域的投资。备忘录扩大CFIUS的审查范围，要求将限制领域扩展到"医疗、农业、能源、原材料等战略行业"。`,
		tag: ["金融", "上市公司"],
		money: "$85M"
	},
	{
		title: "《外国公司问责法》",
		desc: `2025年2月签署，限制美国资本投资中国"军民融合"战略相关产业，并审查甚至阻止中国对美关键领域的投资。备忘录扩大CFIUS的审查范围，要求将限制领域扩展到"医疗、农业、能源、原材料等战略行业"。`,
		tag: ["金融", "上市公司"],
		money: "$69M"
	}
]);
</script>

<style scoped>
.page-container {
	display: flex;
	flex-direction: column;
	align-items: center;
	/* height: 100vh; */
	margin: 0px auto;
	padding: 0px 120px;
	padding-top: 40px;
	background-color: rgba(234, 236, 238, 1);
}
.page-data {
	display: flex;
	justify-content: center;
	align-items: center;
	margin-top: 20px;
	width: 960px;
	gap: 80px;
}
.page-data-item {
	display: flex;
	flex-direction: column;
	align-items: center;
}
.page-data-item-num {
	font-size: 24px;
	font-weight: 600;
	color: var(--base-color);
}
.page-data-item-desc {
	font-size: 12px;
	color: rgba(95, 101, 108, 1);
}
.page-content {
	margin-top: 20px;
	width: 100%;
	/* padding: 0px 20px; */
}
.content-chart-wrapper {
	height: 550px;
}

.custom-container-header-left {
	display: flex;
	align-items: center;
	gap: 8px;
	padding-left: 20px;
	padding-bottom: 5px;
	/* border-bottom: 1px solid rgba(234, 236, 238, 1); */
}
.custom-container-title {
	font-size: 16px;
	font-weight: 600;
	color: var(--base-color);
}
.custom-container-count {
	text-align: center;
	width: 24px;
	height: 16px;
	border-radius: 100px;
	font-size: 12px;
	background-color: rgba(255, 77, 79, 1);
	color: #fff;
}
.custom-container-icon {
	height: 18px;
	width: 18px;
}

.content-list-card {
	display: flex;
	justify-content: space-between;
	align-items: center;
	gap: 8px;
}
.content-list {
	height: 40px;
	width: 100%;
	display: flex;
	justify-content: space-between;
	align-items: center;
	gap: 8px;
	border-bottom: 1px solid rgba(234, 236, 238, 1);
}
.content-list-row {
	height: 60px;
	width: 100%;
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 8px;
	margin-bottom: 10px;
	padding-bottom: 10px;
	border-bottom: 1px solid rgba(234, 236, 238, 1);
}
.content-list-title {
	width: 80%;
	font-size: 16px;
	font-weight: 400;
	color: rgba(59, 65, 75, 1);
	overflow: hidden;
	white-space: nowrap;
	text-overflow: ellipsis;
}
.content-list-time {
	font-size: 14px;
	color: rgba(132, 136, 142, 1);
}
.content-list-footer {
	width: 100%;
	margin-top: 50px;
}

.icon-mark {
	height: 12px;
	width: 12px;
	margin-right: 5px;
	margin-left: 8px;
}
.content-list-item {
	display: flex;
	align-items: center;
	justify-content: space-between;
	margin-bottom: 20px;
	padding: 10px;
	margin-bottom: 10px;
	border-radius: 4px;
	/* box-shadow: 0 2px 8px rgba(60, 87, 126, 0.2); */
	box-shadow: 0 0 15px 0 rgba(60, 87, 126, 0.2);
}
.content-list-item-money {
	font-size: 20px;
	font-weight: 700;
	color: rgba(10, 87, 166, 1);
	margin-left: 50px;
}
.content-card-title-text {
	color: rgba(10, 87, 166, 1);
}
.content-card-desc {
	font-size: 14px;
	font-weight: 400;
	color: rgba(132, 136, 142, 1);
}
.content-card-title-text-2 {
	display: flex;
	flex-direction: column;
	gap: 11px;
}
.content-card-tag-box {
	display: flex;
	justify-content: space-between;
	align-items: center;
	gap: 8px;
}
.content-card-tag-box-item {
	display: flex;
	align-items: center;
	gap: 6px;
}
.content-card-tag-btn {
	margin-left: autp;
}
.content-card-title-tag {
	font-size: 12px;
	color: rgba(95, 101, 108, 1);
}
</style>
