<template>
  <TempImage :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 TempImage from "./temp-image.vue";
import { ImageData, 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: ImageData }>();
const emit = defineEmits<{
  (e: "updateShape", value: ImageData): void;
  (e: "addShape", value: ImageData): void;
  (e: "delShape"): void;
}>();

const { shape, tData, data, operateMenus, describes } = useComponentStatus({
  emit,
  props,
  getMouseStyle,
  transformType: "mat",
  defaultStyle,
  alignment(data, mat) {
    data.mat = mat.multiply(new Transform(props.data.mat)).m;
  },
  copyHandler(tf, data) {
    data.mat = tf.multiply(new Transform(data.mat)).m;
    return data;
  },
  propertys: [
    // "stroke", "strokeWidth",
    "opacity",
    //  "ref", "zIndex"
  ],
});
</script>
