import { PolylineEdge, PolylineEdgeModel } from "@logicflow/core";

class FlowLinkModel extends PolylineEdgeModel {
  initEdgeData(data) {    
    super.initEdgeData(data);    
  }
  getEdgeStyle() {
    const style = super.getEdgeStyle();
    style.strokeWidth = 1;
    style.stroke = this.isSelected ? "#ff7f0e" : "#999";
    return style;
  }
  setAttributes() {
    this.isAnimation = true;
  }
  
  getEdgeAnimationStyle() {
    let tmps=this.graphModel.edges.filter(d=>d.targetNodeId==this.sourceNodeId||d.sourceNodeId==this.sourceNodeId);
    const colors=["#EF5350","#B71C1C","#F06292","#C2185B","#AB47BC","#4A148C","#311B92","#304FFE","#2196F3","#0D47A1","#00BCD4","#006064","#004D40","#1DE9B6","#00C853",
      "#33691E","#FDD835","#FF6F00","#3E2723","#212121"] ;
    
    const style = super.getEdgeAnimationStyle();
    style.strokeDasharray = "5 5";
    style.stroke=colors[tmps.indexOf(this)%colors.length];
    style.animationDuration = "60s";
    return style;
  }
}
class FlowLink extends PolylineEdge {

}

export default {
  type: "ai-link",
  view: FlowLink,
  model: FlowLinkModel,
};
