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

<script lang="ts" setup>
import { RectangleData, getMouseStyle, defaultStyle } from "./index.ts";
import { PropertyUpdate, Operate } from "../../propertys";
import TempLine from "./temp-rectangle.vue";
import { useComponentStatus } from "@/core/hook/use-component.ts";

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

const { shape, tData, data, operateMenus, describes } = useComponentStatus({
  emit,
  props,
  getMouseStyle,
  defaultStyle,
  copyHandler(tf, data) {
    data.points = data.points.map((v) => tf.point(v));
    return data;
  },
});
</script>
