<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 { TriangleData, getMouseStyle, defaultStyle } from "./index.ts";
import { PropertyUpdate, Operate } from "../../propertys";
import TempLine from "./temp-triangle.vue";
import { useComponentStatus } from "@/core/hook/use-component.ts";
import { Transform } from "konva/lib/Util";

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

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