<!-- 
    filename: CustomBomList.vue
    author: liubin
    date: 2023-11-17 14:06:04
    description: 
-->

<template>
	<div class="custom-bom-list—wrapper">
		<div
			class="ct__equipment-name"
			@click.prevent="
				() => {
					$emit('open', equipment.id);
				}
			">
			{{ equipment.name }}
		</div>
		<div
			class="ct__bom-list"
			:class="{
				hidden: active && bomListLength > 0 ? false : true,
			}">
			<ul class="param-bom">
				<li v-for="bom in equipment.paramBomList" :key="bom.name">
					{{ bom.name }}
				</li>
			</ul>
			<ul class="material-bom">
				<li v-for="bom in equipment.materialBomList" :key="bom.name">
					{{ bom.name }}
				</li>
			</ul>
		</div>
	</div>
</template>

<script>
export default {
	name: 'CustomBomList',
	components: {},
	props: {
		equipment: {
			type: Object,
			default: () => ({}),
		},
		active: {
			type: Boolean,
			default: false,
		},
	},
	computed: {
		bomListLength() {
			return (
				(this.equipment.paramBomList?.length || 0) +
				(this.equipment.materialBomList?.length || 0)
			);
		},
	},
	data() {
		return {
			showList: false,
		};
	},
	methods: {},
};
</script>

<style scoped lang="scss">
// .custom-bom-list—wrapper {
//     height: auto;
//     transition: height .2s ease-in-out;
// }

.ct__equipment-name {
	background: #0001;
	padding: 8px;
	border-radius: 4px;
	cursor: pointer;
	transition: all 0.3s;

	&:hover {
		background: #0002;
	}
}

.hidden {
	display: none;
}

ul,
li {
	margin: 0;
	padding: 0;
	list-style: none;
}

ul {
	display: flex;
	flex-direction: column;
	gap: 4px;
	margin-top: 4px;
}

.material-bom > li,
.param-bom > li {
	padding: 4px 24px;
	background: #0001;
	border-radius: 4px;
}
</style>
