import { BaseChart } from './base-chart';
import { XAxisDrawer } from './drawers/x-axis-drawer';
import { YAxisDrawer } from './drawers/y-axis-drawer';
import { PathDrawer } from './drawers/path-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 { LinePathInputProcessor } from './input-processors/line-path-input-processor';
import { FormatTimePositionsInputProcessor } from './input-processors/format-time-positions-input-processor';
import { SortPositionsInputProcessor } from './input-processors/sort-positions-input-processor';
import { XAxisLabelFormatterInputProcessor } from './input-processors/x-axis-label-formatter-input-processor';
/**
 * The LineChart class is a TypeScript implementation of a line chart that extends the BaseChart class
 * and includes methods for creating a drawer chain
 */
export class LineChart extends BaseChart {
  constructor() {
    super(...arguments);
    this.layoutInputProcessor = new LayoutInputProcessor();
    this.lineDataSourceInputProcessorChain = new ProcessorChain([new FormatTimePositionsInputProcessor(), new SortPositionsInputProcessor()]);
    this.xAxisInputProcessorChain = new ProcessorChain([
      this.layoutInputProcessor,
      new XAxisInputProcessor(),
      new XAxisLabelFormatterInputProcessor(),
    ]);
    this.yAxisInputProcessorChain = new ProcessorChain([this.layoutInputProcessor, new YAxisInputProcessor()]);
    this.legendInputProcessorChain = new ProcessorChain([
      this.layoutInputProcessor,
      new LegendInputProcessor(),
    ]);
    this.linePathInputProcessor = new LinePathInputProcessor();
  }
  /**
   * 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 lineRenderOptionsOutput = this.lineDataSourceInputProcessorChain.process(this.options);
    const xAxisOutput = this.xAxisInputProcessorChain.process(lineRenderOptionsOutput);
    const yAxisOutput = this.yAxisInputProcessorChain.process(lineRenderOptionsOutput);
    return [
      new XAxisDrawer(renderer, interactor, {
        renderOptions: xAxisOutput,
      }),
      new YAxisDrawer(renderer, interactor, {
        renderOptions: yAxisOutput,
      }),
      new LegendDrawer(renderer, interactor, {
        renderOptions: this.legendInputProcessorChain.process(this.options),
      }),
      new PathDrawer(renderer, interactor, {
        renderOptions: this.linePathInputProcessor.process(lineRenderOptionsOutput, {
          xScale: xAxisOutput.scale,
          yScale: yAxisOutput.scale,
        }),
      }),
    ];
  }
}
