import { ReactNode } from 'react';
import { BooleanFormatterOptions, CurrencyFormatterOptions, DateFormatterOptions, DateTimeFormatterOptions, NumberFormatterOptions, PercentFormatterOptions, TimeFormatterOptions } from './formatters';
/**
 * Column type literals for display configuration.
 * Each type maps to a default formatter and alignment.
 */
export type ColumnType = "text" | "number" | "currency" | "percent" | "date" | "dateTime" | "time" | "boolean";
/**
 * Maps column types to their formatter options.
 * Used for type-safe formatter configuration.
 */
export type ColumnTypeOptionsMap = {
    text: undefined;
    number: NumberFormatterOptions;
    currency: CurrencyFormatterOptions;
    percent: PercentFormatterOptions;
    date: DateFormatterOptions;
    dateTime: DateTimeFormatterOptions;
    time: TimeFormatterOptions;
    boolean: BooleanFormatterOptions;
};
/**
 * Column type configuration.
 * Can be a simple type string (uses defaults) or an object with custom options.
 *
 * @example
 * ```ts
 * // Simple - uses default formatter options
 * type: "currency"
 *
 * // With options - customizes formatter behavior
 * type: { type: "currency", options: { currency: "EUR", locale: "de-DE" } }
 * ```
 */
export type ColumnTypeConfig<T extends ColumnType = ColumnType> = T | {
    type: T;
    options: ColumnTypeOptionsMap[T];
};
/**
 * Utility type that extracts the element type from an array type.
 * Used for multiselect options type inference.
 */
type ArrayElement<T> = T extends (infer U)[] ? U : never;
/**
 * Edit mode literals for editable cells.
 */
export type EditMode = "text" | "number" | "select" | "multiselect" | "boolean";
/**
 * Base edit configuration shared by all edit modes.
 * @template T - The row data type
 * @template K - The column key
 */
type BaseEditConfig<T, K extends keyof T> = {
    /**
     * Callback fired when the cell value is saved.
     * @param value - The new value
     * @param rowId - The id of the row being edited
     */
    onChange: (value: T[K], rowId: string) => void;
};
/**
 * Edit configuration for text mode cells.
 * @template T - The row data type
 * @template K - The column key
 */
export type TextEditConfig<T, K extends keyof T> = BaseEditConfig<T, K> & {
    /**
     * Text edit mode - renders an inline text input.
     */
    mode: "text";
};
/**
 * Edit configuration for number mode cells.
 * Renders an inline number input with increment/decrement support.
 *
 * @template T - The row data type
 * @template K - The column key
 */
export type NumberEditConfig<T, K extends keyof T> = BaseEditConfig<T, K> & {
    /**
     * Number edit mode - renders an inline number input with formatting and validation.
     */
    mode: "number";
    /**
     * The minimum value for the number field.
     * @default 0
     */
    minValue?: number;
    /**
     * The maximum value for the number field.
     * @default 100000000000000
     */
    maxValue?: number;
    /**
     * The step value for the number field.
     * @default 1
     */
    step?: number;
    /**
     * The maximum number of decimal places for the number field.
     * @default 0
     */
    maximumFractionDigits?: number;
    /**
     * The minimum number of decimal places for the number field.
     * @default 0
     */
    minimumFractionDigits?: number;
};
/**
 * Edit configuration for select mode cells.
 * @template T - The row data type
 * @template K - The column key
 */
export type SelectEditConfig<T, K extends keyof T> = BaseEditConfig<T, K> & {
    /**
     * Select edit mode - renders a dropdown menu.
     */
    mode: "select";
    /**
     * The options available for selection.
     */
    options: {
        value: T[K];
        label: string;
    }[];
};
/**
 * Edit configuration for multiselect mode cells.
 * @template T - The row data type
 * @template K - The column key
 */
export type MultiselectEditConfig<T, K extends keyof T> = BaseEditConfig<T, K> & {
    /**
     * Multiselect edit mode - renders a searchable multi-select popover.
     */
    mode: "multiselect";
    /**
     * The options available for selection.
     */
    options: {
        value: ArrayElement<T[K]>;
        label: string;
    }[];
};
/**
 * Edit configuration for boolean mode cells.
 * Renders a dropdown menu with predefined true/false options and an optional null option.
 *
 * @template T - The row data type
 * @template K - The column key
 */
export type BooleanEditConfig<T, K extends keyof T> = BaseEditConfig<T, K> & {
    /**
     * Boolean edit mode - renders a dropdown with true/false/null options.
     */
    mode: "boolean";
    /**
     * The label displayed for the `true` option.
     * @default "True"
     */
    trueLabel?: string;
    /**
     * The label displayed for the `false` option.
     * @default "False"
     */
    falseLabel?: string;
    /**
     * Whether to include a null option in the dropdown.
     * @default false
     */
    allowNull?: boolean;
    /**
     * The label displayed for the `null` option. Only used when `allowNull` is true.
     * @default "Unset"
     */
    nullLabel?: string;
};
/**
 * Union of all edit configurations.
 * Use with `editConfig` property on column definitions.
 *
 * @template T - The row data type
 * @template K - The column key
 *
 * @example
 * ```ts
 * // Text editing
 * editConfig: { mode: "text", onChange: (value, rowId) => save(value, rowId) }
 *
 * // Number editing
 * editConfig: {
 *   mode: "number",
 *   minValue: 0,
 *   maxValue: 1000,
 *   step: 1,
 *   onChange: (value, rowId) => save(value, rowId)
 * }
 *
 * // Select editing
 * editConfig: {
 *   mode: "select",
 *   options: [{ value: "active", label: "Active" }],
 *   onChange: (value, rowId) => save(value, rowId)
 * }
 *
 * // Boolean editing
 * editConfig: {
 *   mode: "boolean",
 *   trueLabel: "Yes",
 *   falseLabel: "No",
 *   onChange: (value, rowId) => save(value, rowId)
 * }
 * ```
 */
export type EditConfig<T, K extends keyof T> = TextEditConfig<T, K> | NumberEditConfig<T, K> | SelectEditConfig<T, K> | MultiselectEditConfig<T, K> | BooleanEditConfig<T, K>;
/**
 * The type for a table row
 * @extends T
 */
export type TableRow<T> = T & {
    /**
     * The id of the row
     */
    id: string | number;
    /**
     * Row metadata including errors
     */
    meta?: {
        /**
         * Cell-level errors keyed by column id.
         * - `true` marks the cell as having an error
         * - A string marks the cell as having an error with an accessible error message
         */
        errors?: Partial<Record<keyof T, boolean | string>>;
        /**
         * Row-level error displayed in the first column.
         * - `true` marks the row as having an error
         * - A string marks the row as having an error with an accessible error message
         */
        rowError?: boolean | string;
    };
    /**
     * The sub component displayed when the row is expanded
     */
    subComponent?: ReactNode;
    /**
     * The sub rows of the row when the row is expanded
     */
    subRows?: TableRow<T>[];
};
/**
 * Column definition type for DataTable columns.
 *
 * Use `createColumnHelper<T>()` to create type-safe column definitions with
 * proper type inference for `type`, `editConfig`, and value types.
 *
 * @example
 * ```ts
 * type Data = { name: string; amount: number; tags: string[] };
 * const createColumn = createColumnHelper<Data>();
 *
 * const columns = [
 *   // Display-only column with type defaults
 *   createColumn("amount", { headerLabel: "Amount", type: "currency" }),
 *
 *   // Editable column with editConfig
 *   createColumn("name", {
 *     headerLabel: "Name",
 *     type: "text",
 *     editConfig: { mode: "text", onChange: (value, rowId) => save(value, rowId) }
 *   }),
 *
 *   // Multiselect editing
 *   createColumn("tags", {
 *     headerLabel: "Tags",
 *     editConfig: {
 *       mode: "multiselect",
 *       options: [{ value: "urgent", label: "Urgent" }],
 *       onChange: (value, rowId) => save(value, rowId)
 *     }
 *   }),
 * ];
 * ```
 */
export type ColumnDef<T> = {
    /**
     * The id of the column - must be a key of T
     */
    id: keyof T;
    /**
     * The label of the header
     */
    headerLabel: string;
    /**
     * The alignment of the header and cell content.
     * When using `type`, this is set automatically but can be overridden.
     */
    align?: "start" | "center" | "end";
    /**
     * Columns of a group column
     */
    columns?: ColumnDef<T>[];
    /**
     * Configuration for cell editing. Presence enables editing for the column.
     * Consolidates edit mode, options, and onChange into a single object.
     *
     * @example
     * ```ts
     * // Text editing
     * editConfig: { mode: "text", onChange: (value, rowId) => save(value, rowId) }
     *
     * // Select editing
     * editConfig: {
     *   mode: "select",
     *   options: [{ value: "active", label: "Active" }],
     *   onChange: (value, rowId) => save(value, rowId)
     * }
     * ```
     */
    editConfig?: EditConfig<T, keyof T>;
    /**
     * The edit mode of the cells in the column.
     * @deprecated Use `editConfig` instead. Example: `editConfig: { mode: "text", onChange: ... }`
     */
    editMode?: "text" | "number" | "select" | "multiselect" | "boolean";
    /**
     * The content of the footer cell. An array will display multiple footer rows
     */
    footerContent?: ReactNode | ReactNode[];
    /**
     * The maximum width of the column, in pixels
     */
    maxWidth?: number;
    /**
     * The minimum width of the column, in pixels
     */
    minWidth?: number;
    /**
     * The function to call when the value of an editable cell is saved.
     * @deprecated Move inside `editConfig`. Example: `editConfig: { mode: "text", onChange: ... }`
     */
    onChange?: (value: T[keyof T], rowId: string) => void;
    /**
     * The options for the select or multiselect cells.
     * @deprecated Move inside `editConfig`. Example: `editConfig: { mode: "select", options: [...], onChange: ... }`
     */
    options?: {
        value: T[keyof T];
        label: string;
    }[];
    /**
     * The pinning location of the column
     */
    pinned?: "left" | "right";
    /**
     * The function to customize how the cell content is rendered.
     * When using `type`, a default renderer is provided but can be overridden.
     */
    renderCell?: (value: T[keyof T], { row, depth }: {
        row?: T;
        depth?: number;
    }) => ReactNode;
    /**
     * Whether the column is resizable
     */
    resizable?: boolean;
    /**
     * Whether the column is sortable, or a function to customize the sorting logic.
     * When a function, receives values of the column's value type.
     */
    sortable?: boolean | ((valueA: T[keyof T], valueB: T[keyof T]) => number);
    /**
     * The column type for automatic display configuration.
     * Sets default `renderCell` (formatter) and `align` based on the data type.
     *
     * @example
     * ```ts
     * // Simple - uses default formatter options
     * type: "currency"
     *
     * // With options - customizes formatter behavior
     * type: { type: "currency", options: { currency: "EUR", locale: "de-DE" } }
     * ```
     */
    type?: ColumnTypeConfig;
};
/**
 * The type for a custom table footer cell props
 */
export type CustomTableFooterCellProps = {
    /**
     * The content of the footer cell
     */
    content: ReactNode;
    /**
     * The number of columns the footer cell should span
     */
    colSpan: number;
};
export {};
