import { BaseDrawer } from './base-drawer';
/** The RectDrawer class draws a rectangle on a chart using the provided options. */
export class RectDrawer extends BaseDrawer {
  /** This function adds interaction support */
  // eslint-disable-next-line @typescript-eslint/no-empty-function
  addInteractionSupport() { }
  /**
   * This function draws a rectangle on a chart using the provided options.
   */
  draw() {
    const { dataSource = [], xScale, yScale, colors, direction, } = this.options.renderOptions;
    const xData = dataSource.map((item) => item.x);
    const yData = dataSource.map((item) => item.y);
    xData.forEach((item, i) => {
      var _a, _b;
      const yValue = yData[i] || 0;
      let width = 0, height = 0, position = { x: 0, y: 0 };
      if (direction !== 'horizontal') {
        width = ((_a = xScale.bandwidth) === null || _a === void 0 ? void 0 : _a.call(xScale)) || 5;
        height = Math.abs(yScale(0) - yScale(yValue));
        position = { x: xScale(item), y: yScale(Math.max(0, yValue)) };
      }
      else {
        height = ((_b = yScale.bandwidth) === null || _b === void 0 ? void 0 : _b.call(yScale)) || 5;
        width = Math.abs(xScale(yValue) - xScale(0));
        position = { x: xScale(Math.min(yValue, 0)), y: yScale(item) };
      }
      this.renderer.drawRect(position, width, height, this.getColorFromToken(this.getColorByIndex(0, colors)));
    });
  }
}
