import { BaseChart } from './base-chart';
import { XAxisDrawer } from './drawers/x-axis-drawer';
import { YAxisDrawer } from './drawers/y-axis-drawer';
import { RectDrawer } from './drawers/rect-drawer';
import { LegendDrawer } from './drawers/legend-drawer';
import { LayoutInputProcessor } from './input-processors/layout-input-processor';
import { ProcessorChain } from './input-processors/processor-chain';
import { XAxisInputProcessor } from './input-processors/x-axis-input-processor';
import { YAxisInputProcessor } from './input-processors/y-axis-input-processor';
import { LegendInputProcessor } from './input-processors/legend-input-processor';
import { HorizontalXAxisInputProcessor } from './input-processors/horizontal-x-axis-input-processor';
import { HorizontalYAxisInputProcessor } from './input-processors/horizontal-y-axis-input-processor';
/**
 * The BarChart class is a TypeScript implementation of a bar chart that extends the BaseChart class
 * and includes methods for creating a drawer chain
 */
export class BarChart extends BaseChart {
  constructor() {
    super(...arguments);
    this.layoutInputProcessor = new LayoutInputProcessor();
    this.xAxisInputProcessorChain = new ProcessorChain([this.layoutInputProcessor, new XAxisInputProcessor()]);
    this.horizontalXAxisInputProcessorChain = new ProcessorChain([this.layoutInputProcessor, new HorizontalXAxisInputProcessor()]);
    this.yAxisInputProcessorChain = new ProcessorChain([this.layoutInputProcessor, new YAxisInputProcessor()]);
    this.horizontalYAxisInputProcessorChain = new ProcessorChain([this.layoutInputProcessor, new HorizontalYAxisInputProcessor()]);
    this.legendInputProcessorChain = new ProcessorChain([
      this.layoutInputProcessor,
      new LegendInputProcessor(),
    ]);
  }
  /**
   * This function creates an array of BaseDrawer objects for rendering a chart with axes, legends, and paths.
   *
   * @param {BaseRenderer<SVGElement | HTMLCanvasElement>} renderer - an instance of a BaseRenderer class that can render SVG or Canvas elements.
   * @param {BaseInteractor<SVGElement | HTMLCanvasElement>} interactor - an instance of a BaseInteractor class
   * @returns {BaseDrawer<unknown>[]} An array of BaseDrawer array.
   */
  createDrawerChain(renderer, interactor) {
    const { colors, xAxis, dataSource, direction } = this.options;
    const renderOptions = Object.assign(Object.assign({}, this.options), { xAxis: Object.assign(Object.assign({}, xAxis), { type: 'category' }) });
    const xAxisOutput = direction === 'horizontal'
      ? this.horizontalXAxisInputProcessorChain.process(renderOptions)
      : this.xAxisInputProcessorChain.process(renderOptions);
    const yAxisOutput = direction === 'horizontal'
      ? this.horizontalYAxisInputProcessorChain.process(renderOptions)
      : this.yAxisInputProcessorChain.process(renderOptions);
    return [
      new XAxisDrawer(renderer, interactor, {
        renderOptions: xAxisOutput,
      }),
      new YAxisDrawer(renderer, interactor, {
        renderOptions: yAxisOutput,
      }),
      new LegendDrawer(renderer, interactor, {
        renderOptions: this.legendInputProcessorChain.process(renderOptions),
      }),
      new RectDrawer(renderer, interactor, {
        renderOptions: {
          dataSource,
          xScale: xAxisOutput.scale,
          yScale: yAxisOutput.scale,
          colors,
          direction,
        },
      }),
    ];
  }
}
