<template>
	<div id="container"></div>
</template>

<script setup lang="ts">
import { useWindowSize } from '@vueuse/core';
import Konva from 'konva/lib';
import { onMounted } from 'vue';

const { width, height } = useWindowSize();

const initial = () => {
	const stage = new Konva.Stage({
		container: 'container',
		width: width.value,
		height: height.value,
	});

	const layer = new Konva.Layer({ draggable: true });

	const shape1 = new Konva.RegularPolygon({
		x: 80,
		y: stage.height() / 2,
		sides: 5,
		radius: 70,
		fill: 'red',
		stroke: 'black',
		strokeWidth: 4,
		draggable: true,
	});

	const shape2 = new Konva.RegularPolygon({
		x: 220,
		y: stage.height() / 2,
		sides: 5,
		radius: 70,
		fill: 'green',
		stroke: 'black',
		strokeWidth: 4,
		draggable: true,
	});

	const shape3 = new Konva.RegularPolygon({
		x: 360,
		y: stage.height() / 2,
		sides: 5,
		radius: 70,
		fill: 'green',
		stroke: 'black',
		strokeWidth: 4,
		draggable: true,
	});

	shape1.on('mouseenter', function () {
		stage.container().style.cursor = 'pointer';
	});

	shape1.on('mouseleave', function () {
		stage.container().style.cursor = 'default';
	});

	shape2.on('mouseenter', function () {
		stage.container().style.cursor = 'move';
	});
	shape2.on('mouseleave', function () {
		stage.container().style.cursor = 'default';
	});

	shape3.on('mouseenter', function () {
		stage.container().style.cursor = 'crosshair';
	});
	shape3.on('mouseleave', function () {
		stage.container().style.cursor = 'default';
	});

	layer.add(shape3);
	layer.add(shape2);
	layer.add(shape1);
	stage.add(layer);
};

onMounted(() => {
	initial();
});
</script>
