/** 经纬度点（GCJ-02），与微信 map 组件一致 */
export interface MapLocationPoint {
  latitude: number;
  longitude: number;
}

/** marker 上气泡 callout */
export interface MapMarkerCallout {
  content?: string;
  color?: string;
  fontSize?: number;
  borderRadius?: number;
  borderWidth?: number;
  borderColor?: string;
  bgColor?: string;
  padding?: number;
  /** BYCLICK: 点击显示；ALWAYS: 常显 */
  display?: 'BYCLICK' | 'ALWAYS';
  textAlign?: 'left' | 'right' | 'center';
  anchorX?: number;
  anchorY?: number;
  collision?: string;
}

/** marker 自定义气泡 customCallout（存在时忽略 callout 与 title） */
export interface MapMarkerCustomCallout {
  display?: 'BYCLICK' | 'ALWAYS';
  anchorX?: number;
  anchorY?: number;
}

/** marker 旁 label */
export interface MapMarkerLabel {
  content?: string;
  color?: string;
  fontSize?: number;
  /** @deprecated 文档标记废弃，优先使用 anchorX / anchorY */
  x?: number;
  /** @deprecated 文档标记废弃，优先使用 anchorX / anchorY */
  y?: number;
  anchorX?: number;
  anchorY?: number;
  borderWidth?: number;
  borderColor?: string;
  borderRadius?: number;
  bgColor?: string;
  padding?: number;
  textAlign?: 'left' | 'right' | 'center';
  collision?: string;
}

/** 经纬度在标注图标的锚点，默认底边中点 */
export interface MapMarkerAnchor {
  /** 横向 0~1 */
  x: number;
  /** 竖向 0~1 */
  y: number;
}

/**
 * 地图标记点 marker
 * @see https://developers.weixin.qq.com/miniprogram/dev/component/map.html
 */
export interface MapMarker {
  /** 标记点 id，点击事件回调会返回此 id */
  id: number;
  clusterId?: number;
  joinCluster?: boolean;
  latitude: number;
  longitude: number;
  title?: string;
  zIndex?: number;
  iconPath: string;
  rotate?: number;
  /** 透明度 0~1，默认 1 */
  alpha?: number;
  width?: number | string;
  height?: number | string;
  callout?: MapMarkerCallout;
  customCallout?: MapMarkerCustomCallout;
  label?: MapMarkerLabel;
  anchor?: MapMarkerAnchor;
  /** 无障碍访问描述 */
  'aria-label'?: string;
  /** alone | together */
  collisionRelation?: string;
  /** 如 poi、marker，多类型逗号分隔，如 "poi,marker" */
  collision?: string;
}

/** polyline 折线上文字样式 */
export interface MapPolylineTextStyle {
  textColor?: string;
  strokeColor?: string;
  fontSize?: number;
}

/** polyline 分段文本 */
export interface MapPolylineSegmentText {
  name?: string;
  startIndex?: number;
  endIndex?: number;
}

/**
 * 路线 polyline
 * 彩虹线：points 含 n 个点时 colorList 宜为 n-1 段颜色；不足时余段与最后一色相同
 * @see https://developers.weixin.qq.com/miniprogram/dev/component/map.html#polyline
 */
export interface MapPolyline {
  points: MapLocationPoint[];
  /** 十六进制颜色；存在 colorList 时被忽略 */
  color?: string;
  colorList?: string[];
  width?: number;
  dottedLine?: boolean;
  arrowLine?: boolean;
  arrowIconPath?: string;
  borderColor?: string;
  borderWidth?: number;
  /** 压盖关系，默认 abovelabels */
  level?: 'abovelabels' | 'abovebuildings' | 'aboveroads';
  textStyle?: MapPolylineTextStyle;
  segmentTexts?: MapPolylineSegmentText[];
}

/**
 * 多边形 polygon（闭合区域）
 * @see https://developers.weixin.qq.com/miniprogram/dev/component/map.html#polygon
 */
export interface MapPolygon {
  /** [0,0] 为实线；如 [10,10] 表示 10px 实线 + 10px 空白循环 */
  dashArray?: number[];
  points: MapLocationPoint[];
  strokeWidth?: number;
  strokeColor?: string;
  fillColor?: string;
  zIndex?: number;
  level?: 'abovelabels' | 'abovebuildings' | 'aboveroads';
}

/**
 * 圆形 circle
 * @see https://developers.weixin.qq.com/miniprogram/dev/component/map.html#circle
 */
export interface MapCircle {
  latitude: number;
  longitude: number;
  /** 描边颜色 */
  color?: string;
  fillColor?: string;
  radius: number;
  strokeWidth?: number;
  level?: 'abovelabels' | 'abovebuildings' | 'aboveroads';
}
