import { LabelPositionEnum } from '../../stores/useMapEditor';

export const getRGBANum = (color: string) => {
  if (!color) return [0, 0, 0, 0];
  const pattern = /\((\d+),\s*(\d+),\s*(\d+),\s*(\d+(\.\d+)?)\)$/;
  const array = color.match(pattern);
  return [
    Number(array![1]) || 0,
    Number(array![2]) || 0,
    Number(array![3]) || 0,
    Number(array![4]) || 0,
  ];
};

export const getPointCurvConfig = (posType: LabelPositionEnum, image: any) => {
  if (posType === LabelPositionEnum.LEFT) {
    return {
      x: 0,
      y: 0,
      width: 32,
      height: 39,
      image: image,
    };
  } else if (posType === LabelPositionEnum.RIGHT) {
    return {
      x: 183,
      y: 0,
      width: 32,
      height: 39,
      image: image,
    };
  } else {
    return {
      x: 65,
      y: 35,
      width: 32,
      height: 39,
      image: image,
    };
  }
};

export const getCirConfig = (posType: LabelPositionEnum, image: any) => {
  if (posType === LabelPositionEnum.LEFT) {
    return {
      x: 0,
      y: 0,
      width: 32,
      height: 32,
      image: image,
    };
  } else if (posType === LabelPositionEnum.RIGHT) {
    return {
      x: 183,
      y: 0,
      width: 32,
      height: 32,
      image: image,
    };
  } else {
    return {
      x: 65,
      y: 35,
      width: 32,
      height: 32,
      image: image,
    };
  }
};

export const getRectCurConfig = (posType: LabelPositionEnum, image: any) => {
  if (posType === LabelPositionEnum.LEFT) {
    return {
      x: 53,
      y: 0,
      width: 160,
      height: 38,
      image: image,
    };
  } else if (posType === LabelPositionEnum.RIGHT) {
    return {
      x: 0,
      y: 0,
      width: 160,
      height: 38,
      image: image,
    };
  } else {
    return {
      x: 0,
      y: 0,
      width: 160,
      height: 38,
      image: image,
    };
  }
};

export const getTextConfig = (shop: any) => {
  if (shop.posType === LabelPositionEnum.LEFT) {
    return {
      x: 53,
      y: 0,
      text: shop.name,
      fontSize: shop.fontSize,
      fontFamily: 'TRENDS',
      fill: shop.fontColor,
      width: 160,
      height: 32,
      align: 'center',
      verticalAlign: 'middle',
    };
  } else if (shop.posType === LabelPositionEnum.RIGHT) {
    return {
      x: 0,
      y: 0,
      text: shop.name,
      fontSize: shop.fontSize,
      fontFamily: 'TRENDS',
      fill: shop.fontColor,
      width: 160,
      height: 32,
      align: 'center',
      verticalAlign: 'middle',
    };
  } else {
    return {
      x: 0,
      y: 0,
      text: shop.name,
      fontSize: shop.fontSize,
      fontFamily: 'TRENDS',
      fill: shop.fontColor,
      width: 160,
      height: 32,
      align: 'center',
      verticalAlign: 'middle',
    };
  }
};

export const shineConfig = (posType: LabelPositionEnum, image: any) => {
  if (posType === LabelPositionEnum.LEFT) {
    return {
      x: 77,
      y: 0,
      width: 107,
      height: 38,
      image: image,
    };
  } else if (posType === LabelPositionEnum.RIGHT) {
    return {
      x: 25,
      y: 0,
      width: 107,
      height: 38,
      image: image,
    };
  } else {
    return {
      x: 25,
      y: 0,
      width: 107,
      height: 38,
      image: image,
    };
  }
};
