export type BadgeVariant =
    'neutral' | 'success' | 'warning' | 'danger' | 'info';

export type ColumnType =
    'text' | 'number' | 'money' | 'date' | 'datetime' | 'badge' | 'boolean';

export type ColumnDef = {
    key: string;
    label: string;
    type: ColumnType;
    sortable: boolean;
    toggleable: boolean;
    visible: boolean;
    align: 'left' | 'right' | 'center';
    badges: Record<string, { label: string; variant: BadgeVariant }> | null;
    currencyKey: string | null;
};

export type FilterType = 'text' | 'number' | 'date' | 'select' | 'boolean';

export type FilterOption = { value: string; label: string };

export type FilterDef = {
    key: string;
    label: string;
    type: FilterType;
    operators: string[];
    options: FilterOption[] | null;
};

export type FilterCondition = {
    id: string;
    type: 'condition';
    field: string;
    operator: string;
    value: unknown;
};

export type FilterGroup = {
    id: string;
    type: 'group';
    match: 'and' | 'or';
    conditions: Array<FilterCondition | FilterGroup>;
};

export type TableRow = Record<string, unknown> & { id: number | string };

export type TableMeta = {
    current_page: number;
    last_page: number;
    per_page: number;
    total: number;
    from: number | null;
    to: number | null;
};

export type TableState = {
    q: string;
    sort: string;
    filters: FilterGroup | null;
    per_page: number;
    cols: string[] | null;
};

export type TablePayload = {
    key: string;
    columns: ColumnDef[];
    filters: FilterDef[];
    rows: TableRow[];
    meta: TableMeta;
    state: TableState;
    perPageOptions: number[];
};

export type SavedView = {
    name: string;
    state: {
        q: string;
        sort: string;
        filters: FilterGroup | null;
        per_page: number;
        cols: string[] | null;
    };
};
