<template>
	<div class="layout-container">
		<!-- 导航菜单 -->
		<div class="layout-main">
			<div class="layout-main-header">
				<div class="layout-main-header-left-box">
					<div class="left-box-top">
						<div class="icon">
							<img :src="summaryInfo.imageUrl" alt="" />
						</div>
						<div class="info">
							<div class="info-box1">{{ summaryInfo.name }}</div>
							<div class="info-box2">
								<div class="info-box2-item item1">{{ summaryInfo.order }}</div>
								|
								<div class="info-box2-item item2">{{ summaryInfo.type }}</div>
								|
								<div class="info-box2-item item3">{{ summaryInfo.ename }}</div>
							</div>
						</div>
					</div>
					<div class="left-box-bottom">
						<div
							class="left-box-bottom-item"
							:class="{ leftBoxBottomItemActive: activeTitle === item.name }"
							v-for="(item, index) in mainHeaderBtnList"
							:key="index"
							@click="handleClickMainHeaderBtn(item)"
						>
							<div class="icon">
								<img v-if="activeTitle === item.name" :src="item.activeIcon" alt="" />
								<img v-else :src="item.icon" alt="" />
							</div>
							<div class="name" :class="{ nameActive: activeTitle === item.name }">
								{{ item.name }}
							</div>
						</div>
					</div>
				</div>
				<div class="layout-main-header-right-box">
					<div class="right-box-top">
						<div class="time">{{ summaryInfo.postDate }}</div>
						<div class="name">{{ summaryInfo.orgName }}</div>
					</div>
					<div class="right-box-bottom">
						<div class="btn" @click="handleShowReport">
							<div class="icon">
								<img src="./assets/icons/report-icon.png" alt="" />
							</div>
							<div class="text">{{ "政令原文" }}</div>
						</div>
						<div class="btn-active">
							<div class="icon-active">
								<img src="./assets/icons/edit-icon.png" alt="" />
							</div>
							<div class="text-active">{{ "分析报告" }}</div>
						</div>
						<!-- <el-button type="plain" size="large" icon="Search" @click="handleShowReport">政令原文</el-button>
						<el-button type="primary" size="large" icon="EditPen">分析报告</el-button> -->
					</div>
				</div>
			</div>
			<div class="layout-main-center">
				<router-view />
			</div>
		</div>
		<div class="layout-report-box" v-if="activeName === '法案原文'">
			<div class="report-close" @click="handleSwitchActiveName('分析报告')">
				<img src="./assets/images/report-close-icon.png" alt="" />
			</div>
			<div class="report-main">
				<div class="report-header">
					<div class="report-header-left">
						<div class="text">法案版本：</div>
						<div class="select-box">
							<el-select v-model="curBill" placeholder="选择法案" style="width: 240px">
								<el-option v-for="item in billList" :key="item.value" :label="item.label" :value="item.value" />
							</el-select>
						</div>
					</div>
					<div class="report-header-right">
						<div class="btn">
							<div class="icon">
								<img src="./assets/images/report-header-icon1.png" alt="" />
							</div>
							<div class="text">翻译</div>
						</div>
						<div class="btn">
							<div class="icon">
								<img src="./assets/images/report-header-icon2.png" alt="" />
							</div>
							<div class="text">下载</div>
						</div>
						<div class="btn">
							<div class="icon">
								<img src="./assets/images/report-header-icon3.png" alt="" />
							</div>
							<div class="text">对比</div>
						</div>
						<div class="btn">
							<div class="icon">
								<img src="./assets/images/report-header-icon4.png" alt="" />
							</div>
							<div class="text">查找</div>
						</div>
					</div>
				</div>
				<div class="report-content">
					<div class="content-left">
						<img src="./assets/images/report1.png" alt="" />
					</div>
					<div class="content-right">
						<img src="./assets/images/report2.png" alt="" />
					</div>
				</div>
			</div>
		</div>
		<div class="report" v-if="isShowReport">
			<div class="report-close" @click="handleCloseReport">
				<img src="@/assets/icons/close.png" alt="" />
			</div>
			<div class="report-header">
				{{ "政令原文" }}
			</div>
			<div class="report-main">
				<div class="left">
					<div v-if="!reportUrl" class="noContent">{{ "中文原文暂无数据" }}</div>
					<iframe v-else :src="reportUrl" style="border: none" width="100%" height="100%"> </iframe>
				</div>
				<div class="right">
					<div v-if="!reportUrlEn" class="noContent">{{ "英文原文暂无数据" }}</div>
					<iframe v-else :src="reportUrlEn" style="border: none" width="100%" height="100%"> </iframe>
				</div>
			</div>
		</div>
	</div>
</template>

<script setup>
import { ref, onMounted, onUnmounted } from "vue";
import router from "@/router";
import { useRoute } from "vue-router";
import { getDecreeSummary } from "@/api/decree/introduction";
import { getDecreeReport } from "@/api/decree/introduction";
import search from "./assets/images/search.png";

import icon1 from "./assets/icons/icon1.png";
import icon1Active from "./assets/icons/icon1_active.png";
import icon2 from "./assets/icons/icon2.png";
import icon2Active from "./assets/icons/icon2_active.png";
import icon3 from "./assets/icons/icon3.png";
import icon3Active from "./assets/icons/icon3_active.png";

import DefaultIcon2 from "@/assets/icons/default-icon2.png";

const route = useRoute();

const decreeId = ref(route.query.id);

const isShowReport = ref(false);
const reportUrl = ref("");
const reportUrlEn = ref("");

const activeName = ref("分析报告");

const summaryInfo = ref({});

const handleSwitchActiveName = name => {
	activeName.value = name;
};

const curBill = ref("公法（2025年7月4日）");

const billList = ref([
	{
		label: "公法（2025年7月4日）",
		value: "公法（2025年7月4日）"
	},
	{
		label: "公法（2025年7月2日）",
		value: "公法（2025年7月2日）"
	}
]);

const mainHeaderBtnList = ref([
	{
		icon: icon1,
		activeIcon: icon1Active,
		name: "政令概况",
		path: "/decreeLayout/overview"
	},
	{
		icon: icon2,
		activeIcon: icon2Active,
		name: "深度挖掘",
		path: "/decreeLayout/deepDig"
	}
	// {
	// 	icon: icon3,
	// 	activeIcon: icon3Active,
	// 	name: "影响分析",
	// 	path: "/decreeLayout/influence"
	// }
]);

const activeTitle = ref("政令概况");

const handleClickMainHeaderBtn = item => {
	activeTitle.value = item.name;
	router.push({
		path: item.path,
		query: {
			id: decreeId.value
		}
	});
};

// 获取全局信息
const handleGetSummary = async () => {
	const params = {
		id: route.query.id
	};
	try {
		const res = await getDecreeSummary(params);
		console.log("全局信息", res);
		if (res.code === 200 && res.data) {
			summaryInfo.value = res.data;
		}
	} catch (error) {}
};

// 获取报告原文
const handleGetReport = async () => {
	const params = {
		id: route.query.id
	};

	try {
		const res = await getDecreeReport(params);
		console.log("报告原文", res);
		if (res.code === 200 && res.data) {
			reportUrl.value = res.data.content;
			reportUrlEn.value = res.data.contentEn;
		}
	} catch (error) {}
};

const handleCloseReport = () => {
	isShowReport.value = false;
};
const handleShowReport = () => {
	isShowReport.value = true;
};

onMounted(() => {
	handleGetSummary();
	console.log(route.path);
	if (route.path === "/decreeLayout/overview/introduction" || route.path === "/decreeLayout/overview/background") {
		activeTitle.value = "政令概况";
	} else if (route.path === "/decreeLayout/deepDig") {
		activeTitle.value = "深度挖掘";
	} else {
		activeTitle.value = "影响分析";
	}
	handleGetReport();
});
</script>

<style lang="scss" scoped>
.layout-container {
	width: 100%;
	height: 100%;
	overflow: hidden;
	overflow-y: auto;
	.report {
		padding: 10px 150px;
		position: absolute;
		left: 0;
		top: 0;
		z-index: 999999;
		width: 100%;
		height: 100%;
		background: #f7f8f9;
		.report-close {
			position: absolute;
			top: 20px;
			right: 230px;
			width: 20px;
			height: 20px;
			cursor: pointer;
			img {
				width: 100%;
				height: 100%;
			}
		}
		.report-header {
			width: 100%;
			height: 50px;
			color: rgba(59, 65, 75, 1);
			font-family: Microsoft YaHei;
			font-style: Bold;
			font-size: 20px;
			font-weight: 700;
			line-height: 50px;
			letter-spacing: 0px;
			text-align: left;
			padding-left: 30px;
			border-bottom: 1px solid rgba(234, 236, 238, 1);
		}
		.report-main {
			display: flex;
			height: calc(100% - 100px);
			justify-content: space-between;
			.left {
				width: 800px;
				.noContent {
					height: 100px;
					line-height: 100px;
					text-align: center;
					color: rgba(59, 65, 75, 1);
					font-family: Microsoft YaHei;
					font-style: Regular;
					font-size: 20px;
					font-weight: 400;
				}
			}
			.right {
				width: 800px;
				.noContent {
					height: 100px;
					line-height: 100px;
					text-align: center;
					color: rgba(59, 65, 75, 1);
					font-family: Microsoft YaHei;
					font-style: Regular;
					font-size: 20px;
					font-weight: 400;
				}
			}
		}
	}
	.layout-main {
		width: 100%;
		.layout-main-header {
			height: 137px;
			background: rgba(255, 255, 255, 1);
			display: flex;
			justify-content: space-between;
			position: sticky;
			top: 0;
			z-index: 99999999;
			.layout-main-header-left-box {
				width: 1100px;
				margin-left: 160px;
				margin-top: 13px;
				.left-box-top {
					height: 64px;
					display: flex;
					.icon {
						width: 122px;
						height: 64px;
						border-radius: 4px;
						overflow: hidden;
						img {
							width: 100%;
							height: 100%;
						}
					}
					.info {
						width: 700px;
						margin-left: 9px;
						.info-box1 {
							width: 700px;
							color: rgba(59, 65, 75, 1);
							font-family: Microsoft YaHei;
							font-size: 20px;
							font-weight: 600;
							line-height: 22px;
							letter-spacing: 0px;
							text-align: left;
							margin-top: 5px;
							overflow: hidden;
							text-overflow: ellipsis;
							white-space: nowrap;
						}
						.info-box2 {
							margin-top: 5px;
							height: 22px;
							line-height: 22px;
							color: rgba(132, 136, 142, 1);
							font-family: Microsoft YaHei;
							font-size: 14px;
							font-weight: 400;
							line-height: 22px;
							letter-spacing: 0px;
							text-align: left;
							display: flex;
							margin-left: -10px;
							.info-box2-item {
								padding: 0 10px;
							}
							.item1 {
								width: 100px;
								overflow: hidden;
								text-overflow: ellipsis;
								white-space: nowrap;
							}
							.item2 {
								width: 180px;
								overflow: hidden;
								text-overflow: ellipsis;
								white-space: nowrap;
							}
							.item3 {
								width: 420px;
								overflow: hidden;
								text-overflow: ellipsis;
								white-space: nowrap;
							}
						}
					}
				}
				.left-box-bottom {
					display: flex;
					height: 40px;
					margin-top: 21px;
					.left-box-bottom-item {
						display: flex;
						margin-right: 32px;
						margin-top: 3px;
						height: 35px;
						cursor: pointer;
						.icon {
							margin-top: 4px;
							width: 16px;
							height: 16px;
							img {
								width: 100%;
								height: 100%;
							}
						}
						.name {
							height: 24px;
							color: rgba(59, 65, 75, 1);
							font-family: Microsoft YaHei;
							font-size: 18px;
							font-weight: 400;
							line-height: 24px;
							letter-spacing: 0px;
							text-align: left;
							margin-left: 3px;
						}
						.nameActive {
							color: var(--color-main-active);
							font-weight: 700;
						}
					}
					.leftBoxBottomItemActive {
						border-bottom: 3px solid var(--color-main-active);
					}
				}
			}
			.layout-main-header-right-box {
				width: 300px;
				margin-right: 150px;
				margin-top: 19px;
				.right-box-top {
					.time {
						height: 24px;
						line-height: 24px;
						color: rgba(95, 101, 108, 1);
						font-family: Microsoft YaHei;
						font-size: 16px;
						font-weight: 400;
						line-height: 22px;
						letter-spacing: 0px;
						text-align: right;
					}
					.name {
						height: 24px;
						line-height: 24px;
						color: rgba(95, 101, 108, 1);
						font-family: Microsoft YaHei;
						font-size: 16px;
						font-weight: 400;
						line-height: 22px;
						letter-spacing: 0px;
						text-align: right;
					}
				}
				.right-box-bottom {
					margin-top: 24px;
					text-align: right;
					display: flex;
					justify-content: flex-end;
					gap: 8px;
					.btn {
						width: 120px;
						height: 36px;
						box-sizing: border-box;
						border: 1px solid rgba(230, 231, 232, 1);
						border-radius: 6px;
						background: rgba(255, 255, 255, 1);
						display: flex;
						justify-content: center;
						gap: 8px;
						align-items: center;
						cursor: pointer;
						.icon {
							width: 16px;
							height: 16px;
							img {
								width: 100%;
								height: 100%;
							}
						}
						.text {
							width: 64px;
							height: 24px;
							color: rgba(95, 101, 108, 1);
							font-family: Microsoft YaHei;
							font-style: Regular;
							font-size: 16px;
							font-weight: 400;
							line-height: 24px;
							letter-spacing: 0px;
							text-align: left;
						}
					}
					.btn-active {
						width: 120px;
						height: 36px;
						border-radius: 6px;
						background: var(--color-main-active);
						display: flex;
						justify-content: center;
						align-items: center;
						gap: 8px;
						cursor: pointer;
						.icon-active {
							width: 16px;
							height: 16px;
							img {
								width: 100%;
								height: 100%;
							}
						}
						.text-active {
							width: 64px;
							height: 24px;
							color: rgba(255, 255, 255, 1);
							font-family: Microsoft YaHei;
							font-style: Regular;
							font-size: 16px;
							font-weight: 400;
							line-height: 24px;
							letter-spacing: 0px;
							text-align: center;
						}
					}
				}
			}
		}
		.layout-main-center {

		}
	}
	.layout-report-box {
		position: absolute;
		z-index: 9999;
		top: 154px;
		left: 0;
		width: 100%;
		height: 926px;
		background: rgba(248, 249, 250, 1);
		.report-close {
			position: absolute;
			top: 24px;
			right: 178px;
			width: 32px;
			height: 32px;
			cursor: pointer;
			img {
				width: 100%;
				height: 100%;
			}
		}
		.report-main {
			width: 1600px;
			height: 926px;
			margin: 0 auto;
			background: #fff;
			box-sizing: border-box;
			padding: 0 69px;
			.report-header {
				height: 77px;
				border-bottom: 1px solid rgba(240, 242, 244, 1);
				display: flex;
				justify-content: space-between;
				.report-header-left {
					display: flex;
					.text {
						margin-top: 32px;
						width: 70px;
						height: 14px;
						color: rgba(95, 101, 108, 1);
						font-family: Microsoft YaHei;
						font-size: 14px;
						font-weight: 400;
						line-height: 14px;
					}
					.select-box {
						margin-left: 8px;
						margin-top: 23px;
					}
				}
				.report-header-right {
					display: flex;
					margin-top: 24px;
					.btn {
						display: flex;
						width: 88px;
						height: 32px;
						margin-left: 8px;
						box-sizing: border-box;
						border: 1px solid rgba(230, 231, 232, 1);
						border-radius: 4px;
						background: rgba(255, 255, 255, 1);
						display: flex;
						justify-content: center;
						align-items: center;
						.icon {
							width: 16px;
							height: 16px;
							img {
								width: 100%;
								height: 100%;
							}
						}
						.text {
							margin-left: 8px;
							height: 32px;
							color: rgba(95, 101, 108, 1);
							font-family: Microsoft YaHei;
							font-size: 16px;
							font-weight: 400;
							line-height: 32px;
						}
					}
				}
			}
			.report-content {
				display: flex;
				margin-top: 35px;
				.content-left {
					width: 680px;
					height: 786px;
					img {
						width: 100%;
						height: 100%;
					}
				}
				.content-right {
					margin-left: 89px;
					width: 680px;
					height: 786px;
					img {
						width: 100%;
						height: 100%;
					}
				}
			}
		}
	}
	// .tool-box {
	//   position: fixed;
	//   z-index: 10000;
	//   bottom: 80px;
	//   left: 0;
	//   width: 48px;
	//   height: 144px;
	//   border-radius: 0px 10px 10px 0px;
	//   box-shadow: 0px 0px 15px 0px rgba(22, 119, 255, 0.1);
	//   background: rgba(255, 255, 255, 1);
	//   .tool1 {
	//     width: 17px;
	//     height: 18px;
	//     margin-top: 17px;
	//     margin-left: 16px;
	//     cursor: pointer;
	//     img {
	//       width: 100%;
	//       height: 100%;
	//     }
	//   }
	//   .tool2 {
	//     width: 22px;
	//     height: 20px;
	//     margin-top: 26px;
	//     margin-left: 14px;
	//     cursor: pointer;
	//     img {
	//       width: 100%;
	//       height: 100%;
	//     }
	//   }
	//   .tool3 {
	//     width: 20px;
	//     height: 20px;
	//     margin-top: 25px;
	//     margin-left: 15px;
	//     cursor: pointer;
	//     img {
	//       width: 100%;
	//       height: 100%;
	//     }
	//   }
	// }
}
</style>