import type { ModelTypes, ModelTypeToSeriesType } from "../../model/interfaces/common.js";
import type { WebBoxPlot, WebChart, WebChartBarChartSeries, WebChartBoxPlotSeries, WebChartGaugeSeries, WebChartHistogramSeries, WebChartLegend, WebChartLineChartSeries, WebChartPieChartLegend, WebChartPieChartSeries, WebChartRadarChartSeries, WebChartScatterplotSeries, WebGaugeChart, WebHeatChart } from "../../spec/web-chart.js";

/** Interface to hold the action bar properties. */
export interface ActionBarHideActionsProps {
  /** Determines whether to hide clear selection action or not. */
  hideClearSelection?: boolean;
  /** Determines whether to hide filter by extent action or not. */
  hideFilterByExtent?: boolean;
  /** Determines whether to hide filter by selection action or not. */
  hideFilterBySelection?: boolean;
  /** Determines whether to hide full extent action or not. */
  hideFullExtent?: boolean;
  /** Determines whether to hide legend action or not. */
  hideLegend?: boolean;
  /** Determines whether to hide rotate action or not. */
  hideRotateChart?: boolean;
  /** Determines whether to hide selection action or not. */
  hideSelection?: boolean;
  /** Determines whether to hide switch selection action or not. */
  hideSwitchSelection?: boolean;
  /** Determines whether to hide zoom action or not. */
  hideZoom?: boolean;
  /** Determines whether to hide expand action or not. */
  hideExpandAction?: boolean;
}

export const ChartComponentEvents: {
    readonly DataProcessComplete: "arcgisDataProcessComplete";
    readonly DataFetchComplete: "arcgisDataFetchComplete";
    readonly DataProcessError: "arcgisDataProcessError";
    readonly LegendItemVisibilityChange: "arcgisLegendItemVisibilityChange";
    readonly UpdateComplete: "arcgisUpdateComplete";
    readonly SeriesColorChange: "arcgisSeriesColorChange";
    readonly AxesMinMaxChange: "arcgisAxesMinMaxChange";
    readonly DefaultActionSelect: "arcgisDefaultActionSelect";
    readonly SelectionComplete: "arcgisSelectionComplete";
    readonly ActionBarToggle: "arcgisActionBarToggle";
    readonly NoRenderPropChange: "arcgisNoRenderPropChange";
    readonly BadDataWarningRaise: "arcgisBadDataWarningRaise";
    readonly InvalidConfigRaise: "arcgisInvalidConfigWarningRaise";
    readonly SeriesOrder: "arcgisSeriesOrder";
    readonly RuntimeError: "arcgisRuntimeError";
    readonly ConfigChange: "arcgisConfigChange";
    readonly RenderingComplete: "arcgisRenderingComplete";
};

/** @internal */
export const DefaultChartActions: {
    readonly FilterBySelection: "filterBySelection";
    readonly FilterByExtent: "filterByExtent";
    readonly Legend: "legend";
    readonly RotateChart: "rotateChart";
    readonly Selection: "selection";
    readonly ClearSelection: "clearSelection";
    readonly SwitchSelection: "switchSelection";
    readonly Zoom: "zoom";
    readonly FullExtent: "fullExtent";
    readonly EditChart: "editChart";
    readonly ExportAsImage: "exportAsImage";
    readonly ExportAsCSV: "exportAsCSV";
};

export type DefaultChartActions = (typeof DefaultChartActions)[keyof typeof DefaultChartActions];

/**
 * Type alias for a histogram config.
 *
 * @internal
 */
export type HistogramConfig = Omit<WebChart, "series">
  & {
  series: WebChartHistogramSeries[];
};

/**
 * Type alias for a scatterplot config.
 *
 * @internal
 */
export type ScatterplotConfig = Omit<WebChart, "series">
  & {
  series: WebChartScatterplotSeries[];
};

/**
 * Type alias for a gauge  config.
 *
 * @internal
 */
export type GaugeChartConfig = WebGaugeChart;

/**
 * Type alias for a box plot config.
 *
 * @internal
 */
export type BoxPlotConfig = WebBoxPlot;

/**
 * Type alias for a heat chart config.
 *
 * @internal
 */
export type HeatChartConfig = WebHeatChart;

/**
 * Type alias for the supported chart series types.
 *
 * @internal
 */
export type SupportedChartSeries = WebChartBarChartSeries | WebChartBoxPlotSeries | WebChartGaugeSeries | WebChartHistogramSeries | WebChartLineChartSeries | WebChartPieChartSeries | WebChartRadarChartSeries | WebChartScatterplotSeries;

/**
 * Type alias for a chart configuration.
 *
 * This type is generic and supports configuration for different chart types, data source types, and data source requirement policies.
 *
 * It extends and modifies the base `WebChart` while replacing the generic `series` with the specific series type.
 *
 * @template T - The series type. It can be any of the supported chart series types.
 * @template V - The chart type. This acts as the base type for the configuration. Default type is derived from the series type.
 */
export type ChartConfig<T extends ModelTypes = ModelTypes, V extends WebChart = T extends typeof ModelTypes.BoxPlot ? WebBoxPlot : T extends typeof ModelTypes.Gauge ? WebGaugeChart : T extends typeof ModelTypes.HeatChart ? WebHeatChart : WebChart> = Omit<V, "legend" | "series">
  & {
  series: ModelTypeToSeriesType<T>[];
  legend?: T extends typeof ModelTypes.PieChart ? WebChartPieChartLegend : WebChartLegend;
};

export const ActionToggle: {
    readonly Active: "active";
    readonly Inactive: "inactive";
};

export type ActionToggle = (typeof ActionToggle)[keyof typeof ActionToggle];

export const ActionState: {
    readonly Enabled: "enabled";
    readonly Disabled: "disabled";
};

export type ActionState = (typeof ActionState)[keyof typeof ActionState];

export const ErrorPolicy: {
    readonly Ignore: "ignore";
    readonly Throw: "throw";
};

export type ErrorPolicy = (typeof ErrorPolicy)[keyof typeof ErrorPolicy];

export const ChangePolicy: {
    readonly Ignore: "ignore";
    readonly Refresh: "refresh";
};

export type ChangePolicy = (typeof ChangePolicy)[keyof typeof ChangePolicy];

export const LayerFilterChangePolicy: {
    readonly Ignore: "ignore";
    readonly Refresh: "refresh";
};

export type LayerFilterChangePolicy = ChangePolicy;

export const LayerRendererChangePolicy: {
    readonly Ignore: "ignore";
    readonly Refresh: "refresh";
};

export type LayerRendererChangePolicy = ChangePolicy;

export const LayerFieldsChangePolicy: {
    readonly Ignore: "ignore";
    readonly Refresh: "refresh";
};

export type LayerFieldsChangePolicy = ChangePolicy;

export const ViewTimeExtentChangePolicy: {
    readonly Ignore: "ignore";
    readonly Refresh: "refresh";
};

export type ViewTimeExtentChangePolicy = ChangePolicy;

export const SyncSelectionsBetweenChartAndLayerViewPolicy: {
    readonly Enabled: "enabled";
    readonly Disabled: "disabled";
};

export type SyncSelectionsBetweenChartAndLayerViewPolicy = (typeof SyncSelectionsBetweenChartAndLayerViewPolicy)[keyof typeof SyncSelectionsBetweenChartAndLayerViewPolicy];