export const updatePen = (pen: any, prop: string, render = true) => {
    const v: any = { id: pen.id };
  v[prop] = pen[prop];
  if (prop === 'width' && pen.ratio) {
    const rect = meta2d.findOne(pen.id);
    v.height = (pen.width / rect.width) * rect.height;
    pen.height = v.height;
  } else if (prop === 'height' && pen.ratio) {
    const rect = meta2d.findOne(pen.id);
    v.width = (pen.height / rect.height) * rect.width;
    pen.width = v.width;
  } else if (prop === 'shadow') {
    if (v[prop]) {
      !v.shadowOffsetX && (v.shadowOffsetX = 0);
      !v.shadowOffsetY && (v.shadowOffsetY = 0);
      !v.shadowBlur && (v.shadowBlur = 0);
    } else {
      v.shadowColor = '';
    }
  } else if (prop === 'lineGradientColors') {
    //@ts-ignore
    if (meta2d.store.active[0].name === 'line') {
      //@ts-ignore
      meta2d.store.active[0].calculative.gradientColorStop = null;
    } else {
      //@ts-ignore
      meta2d.store.active[0].calculative.lineGradient = null;
    }
    //不同模式切换不同的系统配色
  } else if (prop === 'titleFnJs') {
    v.titleFn = null;
  } else if (prop === 'dash') {
    if(v[prop] === -1) {
      v.lineDash = undefined;
      v.lineWidth = 0;
    }else{
      v.lineWidth = pen.lineWidth || 1;
      v.lineDash = lineDashObj[v[prop]];
    }
  } else if (prop === 'whiteSpace') {
    if(!pen.whiteSpace || pen.whiteSpace !== 'break-all') {
      pen.whiteSpace = 'break-all';
      v.whiteSpace = 'break-all';
    } else {
      v.whiteSpace = 'nowrap';
      pen.whiteSpace = 'nowrap';
    }
  } else if(pen.name === 'tab' && ['direction','btnWidth','btnHeight','gap'].includes(prop)){
    let {btnHeight, btnWidth, gap, direction, data} = pen;
    const len = data.length;
    btnHeight= v.btnHeight = btnHeight || 32;
    btnWidth = v.btnWidth = btnWidth || 100;
    gap = v.gap = gap || 8;
    if (direction == 'vertical') {
      v.height = btnHeight * len + gap * (len + 1);
      v.width = btnWidth + gap * 2;
    } else {
      v.height = btnHeight + gap * 2; 
      v.width = btnWidth  * len + gap * (len + 1);
    }
  } else if(prop === 'lineWidth') {
    if(v[prop] === undefined){
      v[prop] = 1;
    }
  }
    meta2d.setValue(v, { render });
};

export const lineDashObj = [
  undefined,
  [5, 5],
  [10, 10],
  [10, 10, 2, 10],
  [1, 16],
];
