/** The PieChartRadiusInputProcessor class calculates the radius, inner radius, and center of a pie chart based on input options and previous layout results. */
export class PieChartRadiusInputProcessor {
  /**
   * This function calculates the radius and center position of a pie chart based on input options and previous layout results.
   *
   * @param {ChartOptions<PieChartSourceType>} input - An object of type ChartOptions that contains options for the pie chart, including
   * the type of chart (either "Pie" or "Donut") and the donut radius (a number between 0 and 1 that
   * determines the size of the hole in the center of a donut chart).
   * @param {LayoutProcessResultType} previousOutput - The `previousOutput` parameter is of type
   * `LayoutProcessResultType` and represents the output of the previous layout process. It contains
   * information about the inner width and height of the chart area, which is used to calculate the
   * radius and center of the pie chart.
   * @returns {PieChartRadiusProcessResultType} an object of type `PieChartRadiusProcessResultType` which contains the `radius`,
   * `innerRadius`, and `center` properties.
   */
  process(input, previousOutput) {
    const { type, donutRadius } = input;
    const { innerWidth, innerHeight } = previousOutput;
    const radius = Math.min(innerWidth, innerHeight) / 2;
    const innerRadius = type === 'Donut' ? (!donutRadius || donutRadius <= 0 ? 0.6 : Math.min(donutRadius, 0.9)) : 0;
    // left pie chart, right legend center should be x: innerWidth/4, the top legend, bottom chart center should be x: innerWidth/2
    const center = {
      x: innerWidth / 2,
      y: innerHeight / 2,
    };
    return { radius, innerRadius: innerRadius * radius, center };
  }
}
