import { Pos } from "@/utils/math.ts";
import { themeMouseColors } from "@/constant/help-style.ts";
import { BaseItem, generateSnapInfos, getBaseItem } from "../util.ts";
import { getMouseColors } from "@/utils/colors.ts";
import { AddMessage } from "@/core/hook/use-draw.ts";

export { default as Component } from "./line.vue";
export { default as TempComponent } from "./temp-line.vue";

export const shapeName = "线段";
export const defaultStyle = {
  stroke: themeMouseColors.theme,
  strokeWidth: 5,
};

export const addMode = "dots";

export const getMouseStyle = (data: LineData) => {
  const strokeStatus = getMouseColors(data.stroke || defaultStyle.stroke);
  const strokeWidth = data.strokeWidth || defaultStyle.strokeWidth;

  return {
    default: { stroke: strokeStatus.pub, strokeWidth },
    hover: { stroke: strokeStatus.hover },
    press: { stroke: strokeStatus.press },
  };
};

export const getSnapInfos = (data: LineData) => generateSnapInfos(getSnapPoints(data), true, true, true)


export const getSnapPoints = (data: LineData) => {
  return data.points
}


export type LineData = Partial<typeof defaultStyle> & BaseItem & {
  points: Pos[];
  attitude: number[];
};

export const interactiveToData = (
  info: AddMessage<'line'>,
  preset: Partial<LineData> = {}
): LineData | undefined => {
  if (info.cur) {
    return interactiveFixData(
      { ...getBaseItem(), ...preset, points: [], attitude: [1, 0, 0, 1, 0, 0] },
      info
    );
  }
};

export const interactiveFixData = (
  data: LineData,
  info: AddMessage<'line'>
) => {
  data.points = [...info.consumed, info.cur!]
  return data;
};
