<template>
	<div class="node-el" :class="{ center: posCenter, mask: mask }">
		<Handle
			v-for="handle in handles[type] || []"
			:key="handle.id"
			:type="handle.type"
			:id="handle.id"
			:position="handle.position"
			:connectable="false"
		/>
		<div class="item" @mousedown="(e) => stateManager.setActiveNodeID(node.id)">
			<slot></slot>
		</div>
		<div class="mask" v-show="mask"></div>
	</div>
</template>
<script lang="ts" setup>
	import { Handle, Position } from '@vue-flow/core'
	import { NODE_DATATYPE, NODE_TYPE } from '../tools/index.d'
	import { computed, ref, inject } from 'vue'
	const handles = ref({
		[NODE_TYPE.INPUT]: [{ id: 'Right', type: 'source', position: Position.Right }],
		[NODE_TYPE.SECONDARY]: [
			{ id: 'Left', type: 'target', position: Position.Left },
			{ id: 'Right', type: 'source', position: Position.Right }
		],
		[NODE_TYPE.OUTPUT]: [{ id: 'Left', type: 'target', position: Position.Left }],
		[NODE_TYPE.ALONE]: []
	})
	const props = defineProps({
		type: {
			type: String,
			default: 'InputNode'
		},
		node: {
			type: Object,
			required: true
		},
		stateManager: {
			type: Object,
			required: true
		},
		mask: {
			type: Boolean,
			default: false
		}
	})
	const posCenter = computed(() => {
		const arr = [NODE_DATATYPE.RESULT_IMAGE]
		return arr.includes(props.node?.data?.type)
	})
</script>

<style lang="less" scoped>
	.node-el {
		position: relative;
		--top: 50px;
		&.mask *,
		&.mask {
			pointer-events: none;
		}
		.vue-flow__handle {
			width: 12px;
			height: 12px;
			top: var(--top);
			z-index: 10;
			background: #b5b5b5;
			border: 1px solid #ffffff;
		}
		> .item {
			position: relative;
		}
		&.center {
			--top: 50%;
		}
		> .mask {
			position: absolute;
			top: 0;
			left: 0;
			width: 100%;
			height: 100%;
			z-index: 100;
		}
	}
</style>
