<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 pentagon = new Konva.RegularPolygon({
		x: stage.width() / 2,
		y: stage.height() / 2,
		sides: 5,
		radius: 70,
		fill: 'red',
		stroke: 'black',
		strokeWidth: 4,
		opacity: 0.2,
	});

	pentagon.on('mouseover', function () {
		this.opacity(1);
	});
	pentagon.on('mouseout', function () {
		this.opacity(0.2);
	});

	layer.add(pentagon);
	stage.add(layer);
};

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