import { type Filter } from '@sisense/sdk-data';
import { WidgetProps } from '../../../../domains/widgets/components/widget/types';
import { DataPoint, ScatterDataPoint } from '../../../../types';
import { JtdConfig } from './jtd-types.js';
/**
 * Jump To Dashboard (JTD) Filter Merging Logic:
 *
 * When a user clicks on a datapoint to open a JTD modal, multiple types of filters are merged:
 *
 * 1. **Generated Filters**: Created from the clicked datapoint's category and breakBy entries
 * 2. **Dashboard Filters**: Current dashboard filters (filtered by includeDashFilterDims)
 * 3. **Widget Filters**: Original widget-specific filters (filtered by includeWidgetFilterDims)
 * 4. **Formula Context Filters**: Embedded filters from the clicked widget's datapoint calculations
 *
 * ## Formula Context Filters (New Feature)
 *
 * Formula context filters are embedded within datapoint calculations and represent intrinsic
 * filters that are part of the measure/column computation itself. They are extracted only from
 * the specific widget that was clicked, not from all widgets. For example:
 *
 * ```
 * clickedWidget.dataOptions.value[0].column.context = {
 *   "13FC1-655": {
 *     "type": "filter",
 *     "filterType": "numeric",
 *     "attribute": { ... },
 *     "valueA": 10,
 *     "valueB": 27249.89453125
 *   }
 * }
 * ```
 *
 * These filters:
 * - Represent calculation constraints that are intrinsic to the clicked widget's datapoint
 * - Are extracted from all dataOption fields of the clicked widget (value, category, breakBy, x, y, etc.)
 * - Support both object format and string reference format
 *
 * ## Duplicate Filter Handling
 *
 * Complex formulas like `AVG(cost) - AVG(PREVMONTH(cost))` can contain multiple filters on the same dimension.
 * The `sendFormulaFiltersDuplicate` parameter controls how duplicates are handled:
 *
 * - **"none"**: Exclude all duplicate filters (only include filters that appear once)
 * - **Number (1+)**: Include only the filter at that position (1-indexed). Invalid numbers treated as "none"
 * - **Other values**: Include only the first duplicate filter
 *
 * Examples:
 * - Formula has 2 filters on Commerce.Cost dimension
 * - `sendFormulaFiltersDuplicate = "none"` → No Cost filters included
 * - `sendFormulaFiltersDuplicate = 1` → Include first Cost filter
 * - `sendFormulaFiltersDuplicate = 2` → Include second Cost filter
 * - `sendFormulaFiltersDuplicate = 3` → Invalid (out of range), treat as "none"
 */
/**
 * Extract formula context filters from data point
 *
 * @param clickedWidget - The clicked widget
 * @param jtdConfig - The JTD configuration
 * @returns Array of formula context filters
 * @internal
 */
export declare const getFormulaContextFilters: (clickedWidget: WidgetProps, jtdConfig: JtdConfig) => Filter[];
/**
 * Handle duplicate formula filters based on sendFormulaFiltersDuplicate parameter
 *
 * @param filters - The filters to handle
 * @param sendFormulaFiltersDuplicate - The send formula filters duplicate parameter
 * @returns The filtered filters
 * @internal
 */
export declare const handleFormulaDuplicateFilters: (filters: Filter[], sendFormulaFiltersDuplicate?: number | 'none') => Filter[];
/**
 * Normalizes a date value to the start of the period for the given granularity
 * This ensures the filter member value matches what the backend query returns
 * Uses existing date utilities instead of manual parsing to reduce business logic
 *
 * @param value - The raw date value (e.g., "2009-11-15T12:30:00.000")
 * @param granularity - The date granularity (e.g., "Months")
 * @returns Normalized date string that matches backend member query format
 * @internal
 */
export declare const normalizeDateForGranularity: (value: string, granularity: string) => string;
/**
 * Type guard to check if a data point is a ScatterDataPoint.
 * Checks for actual scatter chart structure (x/y coordinates) and scatter-only properties.
 *
 * @param point - The data point to check
 * @returns True if the point is a ScatterDataPoint, false otherwise
 * @internal
 */
export declare const isScatterDataPoint: (point: DataPoint | ScatterDataPoint) => point is ScatterDataPoint;
/**
 * Extracts filters from scatter chart data point (breakByColor and breakByPoint).
 *
 * @param point - The scatter data point
 * @returns Array of filters generated from scatter chart breakBy properties
 * @internal
 */
export declare const getFiltersFromScatterDataPoint: (point: ScatterDataPoint) => Filter[];
/**
 * Extracts filters from regular chart data point (category and breakBy array).
 * Also processes any scatter properties (breakByColor/breakByPoint) if present.
 *
 * @param point - The regular data point (may have mixed properties)
 * @returns Array of filters generated from all available entries
 * @internal
 */
export declare const getFiltersFromRegularDataPoint: (point: DataPoint) => Filter[];
/**
 * Extracts filters from a data point for Jump To Dashboard functionality.
 *
 * This function handles both regular DataPoint and ScatterDataPoint types:
 * - If data point has scatter properties (breakByColor/breakByPoint), process as scatter chart
 * - Otherwise, process as regular chart (category/breakBy entries)
 * - Scatter properties take priority over regular properties when both exist
 *
 * @param point - The data point from chart interaction
 * @returns Array of filters generated from the data point
 * @internal
 */
export declare const getFiltersFromDataPoint: (point: DataPoint | ScatterDataPoint) => Filter[];
/**
 * Filter filters based on allowed dimension names, supporting cascading filters
 *
 * @param filters - The filters to filter
 * @param allowedDims - The allowed dimensions
 * @returns The filtered filters
 * @internal
 */
export declare const filterByAllowedDimensions: (filters: Filter[], allowedDims?: string[]) => Filter[];
/**
 * Merge all types of filters for JTD functionality
 *
 * @param generatedFilters - Filters generated from data point
 * @param dashboardFilters - Current dashboard filters
 * @param widgetFilters - Widget-specific filters
 * @param formulaContextFilters - Formula context filters
 * @returns Merged filters array
 * @internal
 */
export declare const mergeJtdFilters: (generatedFilters: Filter[], dashboardFilters: Filter[], widgetFilters: Filter[], formulaContextFilters: Filter[]) => Filter[];
