<template>
	<!-- 高级工具选择 -->
	<div class="cards-select">
		<div 
			v-for="v in (node.data?.secondaryMenu?.selectList || list)" 
			:key="v.type" 
			@click="onClickItem(v)" 
			v-show="
				(v.tier === tier) &&
				((v.type == NODE_DATATYPE.TO_REAL_VARIANTS && (superiorNode?.data?.superiorNodeType == NODE_DATATYPE.TO_3D_MODEL && props.tier == NODE_DATATIER.TO_REAL_VARIANTS))||
				(v.type != NODE_DATATYPE.TO_REAL_VARIANTS && (superiorNode?.data?.superiorNodeType != NODE_DATATYPE.TO_3D_MODEL || props.tier != NODE_DATATIER.TO_REAL_VARIANTS)))
			"
		>
			<span class="icon">
				<svg-icon :name="v.type.split('_')[0] + '-2'" size="15" size-unit="px" />
			</span>
			<span class="title">{{ v.title }}</span>
		</div>
	</div>
</template>

<script setup lang="ts">
	import { ref, inject, computed } from 'vue'
	import { NODE_DATATYPE, NODE_DATATIER } from '../../../tools/index.d'
	import { useI18n } from 'vue-i18n'
	const { t } = useI18n()
	const nodeManager = inject('nodeManager') as any
	const stateManager = inject('stateManager') as any
	const props = defineProps({
		node: { required: true, type: Object },
		tier: { default: 1, type: Number }
	})
	const superiorNode = computed(() => {
		return stateManager.getNodeById(props.node.data.superiorID)
	})
	const list = ref([
		{
			tier: NODE_DATATIER.TO_REAL_STYLE,
			type: NODE_DATATYPE.TO_REAL_STYLE,
			title: t('FlowCanvas.toRealStyleTitle')
		},
		{
			tier: NODE_DATATIER.TO_REAL_VARIANTS,
			type: NODE_DATATYPE.TO_REAL_VARIANTS,
			title: t('FlowCanvas.toRealVariantsTitle')
		},
		{
			tier: NODE_DATATIER.SURFACE_EDIT,
			type: NODE_DATATYPE.SURFACE_EDIT,
			title: t('FlowCanvas.surfaceEditTitle'),
			secondaryMenu: {
				title: t('FlowCanvas.surfaceEditTitle'),
				icon: NODE_DATATYPE.SURFACE_EDIT,
				selectList: [
					{
						tier: NODE_DATATIER.CANVAS_MODE,
						type: NODE_DATATYPE.CANVAS_MODE,
						title: t('FlowCanvas.surfaceEditCanvasTitle'),
					},{
						tier: NODE_DATATIER.Fast_MODE,
						type: NODE_DATATYPE.Fast_MODE,
						title: t('FlowCanvas.surfaceEditTitle'),
					},
				]
			}
		},{
			tier: NODE_DATATIER.SURFACE_EDIT_,
			type: NODE_DATATYPE.SURFACE_EDIT_,
			title: t('FlowCanvas.surfaceEditTitle'),
			secondaryMenu: {
				title: t('FlowCanvas.surfaceEditTitle'),
				icon: NODE_DATATYPE.SURFACE_EDIT_,
				selectList: [
					{
						tier: NODE_DATATIER.CANVAS_MODE_,
						type: NODE_DATATYPE.CANVAS_MODE_,
						title: t('FlowCanvas.surfaceEditCanvasTitle'),
					},{
						tier: NODE_DATATIER.Fast_MODE_,
						type: NODE_DATATYPE.Fast_MODE_,
						title: t('FlowCanvas.surfaceEditTitle'),
					},
				]
			}
		},
		{
			tier: NODE_DATATIER.SCENE_COMPOSITION,
			type: NODE_DATATYPE.SCENE_COMPOSITION,
			title: t('FlowCanvas.sceneCompositionTitle')
		},
		{
			tier: NODE_DATATIER.COLOR_PALETTE,
			type: NODE_DATATYPE.COLOR_PALETTE,
			title: t('FlowCanvas.colorPaletteTitle')
		},
		{
			tier: NODE_DATATIER.TO_3D_MODEL,
			type: NODE_DATATYPE.TO_3D_MODEL,
			title: t('FlowCanvas.to3DModelTitle')
		},
		{
			tier: NODE_DATATIER.TO_3VIEW,
			type: NODE_DATATYPE.TO_3VIEW,
			title: t('FlowCanvas.to3ViewTitle')
		}
	])
	const onClickItem = (v) => {
		const id = props.node.id
		if (!id) return
		const superiorID = props.node.data.superiorID
		if(v.secondaryMenu){
			nodeManager.createCardsSelect({
				data: { 
					tier: props.node.data?.tier, 
					superiorID, 
					isActive: props.node.data?.isActive,
					secondaryMenu: v.secondaryMenu,
					createIndexPosition: props.node.data.createIndexPosition,
				}
			})
		}else{
			nodeManager.createCardNode({
				data: {
					tier: v.tier,
					type: v.type,
					superiorID,
					isActive: props.node.data?.isActive,
					createIndexPosition: props.node.data.createIndexPosition,
				}
			})
		}
		// stateManager.deleteNode(id)
	}

	defineExpose({})
</script>

<style lang="less" scoped>
	.cards-select {
		--cards-item-margin-bottom: 8px;
		user-select: none;
		> div {
			display: flex;
			align-items: center;
			padding: 0 5px;
			height: 30px;
			border-radius: 5px;
			cursor: pointer;
			&:hover {
				background-color: rgb(225, 225, 225);
			}
			> .icon {
				margin-right: 10px;
			}
			> .title {
				font-size: 14px;
				color: #000;
			}
		}
	}
</style>
