<template>
  <TempIcon :data="tData" :ref="(e: any) => shape = e.shape" />
  <PropertyUpdate
    :describes="describes"
    :data="data"
    :target="shape"
    @change="emit('updateShape', { ...data })"
  />
  <Operate :target="shape" :menus="operateMenus" />
</template>

<script lang="ts" setup>
import TempIcon from "./temp-icon.vue";
import { IconData, getMouseStyle, defaultStyle } from "./index.ts";
import { useComponentStatus } from "@/core/hook/use-component.ts";
import { PropertyUpdate, Operate } from "../../propertys";
import { Transform } from "konva/lib/Util";

const props = defineProps<{ data: IconData }>();
const emit = defineEmits<{
  (e: "updateShape", value: IconData): void;
  (e: "addShape", value: IconData): void;
  (e: "delShape"): void;
}>();

const { shape, tData, data, operateMenus, describes } = useComponentStatus({
  emit,
  props,
  getMouseStyle,
  line: false,
  defaultStyle,
  copyHandler(tf, data) {
    data.mat = tf.multiply(new Transform(data.mat)).m;
    return data;
  },
});
</script>
