<template>
	<div class="header-main">
		<div class="layout-main-header">
			<div class="layout-main-header-left-box">
				<div class="left-box-top">
					<el-skeleton :loading="isLoading" animated>
						<template #template>
							<div class="icon">
								<el-skeleton-item class="skeleton-avatar" variant="image" />
							</div>
							<div class="info">
								<el-skeleton-item class="skeleton-title" variant="h1" />
								<el-skeleton-item class="skeleton-subtitle" variant="text" />
							</div>
						</template>

						<template #default>
							<div class="icon">
								<img :src="billInfo?.imageUrl || defaultLogo" alt="" />
							</div>
							<div class="info">
								<div class="info-box1">{{ billInfo?.billName }}</div>
								<div class="info-box2">{{ billInfo?.description }} {{ billInfo?.billNameEn }}</div>
							</div>
						</template>
					</el-skeleton>
				</div>

				<div class="left-box-bottom" v-if="showTabs">
					<template v-if="isLoading">
						<div class="left-box-bottom-item is-skeleton" v-for="n in 4" :key="n">
							<div class="icon">
								<el-skeleton-item class="skeleton-tab-icon" variant="text" />
							</div>
							<div class="name">
								<el-skeleton-item class="skeleton-tab-text" variant="text" />
							</div>
						</div>
					</template>
					<template v-else>
						<div class="left-box-bottom-item"
							:class="{ leftBoxBottomItemActive: activeTitle === item.name }" v-for="item in tabs"
							:key="item.path" @click="emit('tab-click', 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>
					</template>
				</div>
			</div>

			<div class="layout-main-header-right-box">
				<div class="right-box-top">
					<el-skeleton :loading="isLoading" animated>
						<template #template>
							<div class="time">
								<el-skeleton-item class="skeleton-right-line" variant="text" />
							</div>
							<div class="name">
								<el-skeleton-item class="skeleton-right-line" variant="text" />
							</div>
						</template>

						<template #default>
							<div class="time">{{ billInfo?.introductionDate }}</div>
							<div class="name">{{ billInfo?.tarName }}</div>
						</template>
					</el-skeleton>
				</div>

				<div class="right-box-bottom" v-if="showActions">
					<template v-if="isLoading">
						<div class="btn3 is-skeleton">
							<div class="icon">
								<el-skeleton-item class="skeleton-action-icon" variant="text" />
							</div>
							<div class="text">
								<el-skeleton-item class="skeleton-action-text" variant="text" />
							</div>
						</div>
					</template>
					<template v-else>
						<div class="btn2" @click="emit('open-analysis', 'forsee')">
							<div class="icon">
								<img :src="btnIconForsee" alt="" />
							</div>
							<div class="text">{{ "进展预测" }}</div>
						</div>
						<div class="btn3" @click="emit('open-analysis', 'analysis')">
							<div class="icon">
								<img :src="btnIconAnalysis" alt="" />
							</div>
							<div class="text">{{ "分析报告" }}</div>
						</div>
					</template>
				</div>
			</div>
		</div>
	</div>
</template>

<script setup>
import { computed } from "vue";
import btnIconAnalysis from "@/views/bill/billLayout/assets/icons/writting-icon.svg";
import btnIconForsee from "@/views/bill/billLayout/assets/icons/forsee-icon.svg";

const props = defineProps({
	billInfo: {
		type: Object,
		default: () => ({})
	},
	defaultLogo: {
		type: String,
		default: ""
	},
	tabs: {
		type: Array,
		default: () => []
	},
	activeTitle: {
		type: String,
		default: ""
	},
	showTabs: {
		type: Boolean,
		default: true
	},
	showActions: {
		type: Boolean,
		default: true
	}
});

const isLoading = computed(() => !props.billInfo || !props.billInfo.billName);

const emit = defineEmits(["tab-click", "open-analysis"]);
</script>

<style lang="scss" scoped>
.skeleton-avatar {
	width: 64px;
	height: 64px;
	border-radius: 50%;
}

.skeleton-title {
	width: 360px;
	height: 20px;
}

.skeleton-subtitle {
	width: 520px;
	height: 14px;
	margin-top: 8px;
}

.skeleton-right-line {
	width: 140px;
	height: 14px;
}

.skeleton-tab-icon,
.skeleton-action-icon {
	width: 16px;
	height: 16px;
	border-radius: 4px;
}

.skeleton-tab-text,
.skeleton-action-text {
	width: 80px;
	height: 14px;
	border-radius: 6px;
}

.header-main {
	position: sticky;
	top: 0;
	z-index: 1000;
	width: 100%;
	background-color: #fff;
	box-shadow: 0px 4px 10px 0px rgba(0, 0, 0, 0.05);
	overflow: hidden;
}

.layout-main-header {
	width: 1600px;
	background: #fff;
	display: flex;
	justify-content: space-between;
	margin: 0 auto;
	padding-top: 10px;

	.layout-main-header-left-box {
		width: 2600px;

		.left-box-top {
			height: 64px;
			display: flex;
			align-items: center;
			justify-content: left;
			margin-bottom: 21px;

			:deep(.el-skeleton) {
				width: 100%;
				display: flex;
				align-items: center;
			}

			.icon {
				width: 64px;
				height: 64px;
				flex: 0 0 64px;
				flex-shrink: 0;

				img {
					width: 100%;
					height: 100%;
					display: block;
					object-fit: contain;
				}
			}

			.info {
				margin-left: 8px;
				display: flex;
				align-items: left;
				flex-direction: column;

				.info-box1 {
					color: rgba(59, 65, 75, 1);
					font-family: "Microsoft YaHei";
					font-size: 20px;
					font-weight: 600;
					letter-spacing: 0px;
					text-align: left;
				}

				.info-box2 {
					margin-top: 4px;
					color: rgba(132, 136, 142, 1);
					font-family: "Microsoft YaHei";
					font-size: 14px;
					font-weight: 400;
					letter-spacing: 0px;
					text-align: left;
					display: -webkit-box;
					-webkit-box-orient: vertical;
					-webkit-line-clamp: 2;
					line-clamp: 2;
					overflow: hidden;
					text-overflow: ellipsis;
				}
			}
		}

		.left-box-bottom {
			display: flex;
			height: 40px;
			// margin-top: 21px;

			.left-box-bottom-item {
				display: flex;
				margin-right: 32px;
				margin-top: 3px;
				height: 36px;
				cursor: pointer;

				.icon {
					margin-top: 4px;
					width: 16px;
					height: 16px;

					img {
						width: 100%;
						height: 100%;
					}
				}

				.name {
					color: rgba(95, 101, 108, 1);
					font-family: Microsoft YaHei;
					font-size: 18px;
					font-weight: 400;
					line-height: 22px;
					letter-spacing: 0px;
					text-align: left;
					margin-left: 3px;
				}

				.nameActive {
					color: rgba(20, 89, 187, 1);
					font-weight: 700;
				}
			}

			.leftBoxBottomItemActive {
				border-bottom: 3px solid rgba(20, 89, 187, 1);
			}
		}
	}

	.layout-main-header-right-box {
		width: 600px;
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		align-items: right;

		.right-box-top {
			height: 64px;
			display: flex;
			align-items: right;
			flex-direction: column;
			justify-content: center;

			:deep(.el-skeleton) {
				width: 100%;
			}

			.time {
				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 {
				margin-top: 4px;
				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-bottom: 8px;
			display: flex;
			justify-content: flex-end;
			gap: 8px;

			.icon {
				width: 16px;
				height: 16px;

				img {
					width: 100%;
					height: 100%;
				}
			}

			.btn2 {
				cursor: pointer;
				width: 120px;
				height: 36px;
				border-radius: 6px;
				background: var(--bg-white-100);
				border: 1px solid var(--bg-black-10);
				display: flex;
				justify-content: center;
				align-items: center;
				gap: 8px;
			}

			.btn3 {
				cursor: pointer;
				width: 120px;
				height: 36px;
				border-radius: 6px;
				background: rgba(5, 95, 194, 1);
				display: flex;
				justify-content: center;
				align-items: center;
				gap: 8px;

				.text {
					height: 24px;
					color: rgba(255, 255, 255, 1);
					font-family: Microsoft YaHei;
					font-size: 16px;
					font-weight: 400;
					line-height: 24px;
					letter-spacing: 0px;
					text-align: left;
				}
			}

			.is-skeleton {
				pointer-events: none;
			}
		}
	}
}
</style>
