/*!
 * Copyright 2019-2020 VMware, Inc.
 * SPDX-License-Identifier: BSD-2-Clause
 */
import { AfterViewInit, ChangeDetectorRef, ElementRef, EventEmitter, OnDestroy, OnInit, QueryList, TrackByFunction } from '@angular/core';
import { ClrDatagrid, ClrDatagridPagination, ClrDatagridStateInterface } from '@clr/angular';
import { LazyString, TranslationService } from '@vcd/i18n';
import { Observable } from 'rxjs';
import { ActionMenuComponent } from '../action-menu/action-menu.component';
import { ActivityReporter } from '../common/activity-reporter';
import { ActionDisplayConfig, ActionItem } from '../common/interfaces/action-item.interface';
import { TooltipSize } from '../lib/directives/show-clipped-text.directive';
import { ComponentRendererConstructor, ComponentRendererSpec } from './interfaces/component-renderer.interface';
import { ColumnRendererSpec, FunctionRenderer, GridColumn, GridColumnHideable } from './interfaces/datagrid-column.interface';
/**
 * An enum that describes where the contextual buttons should display.
 */
export declare enum ContextualActionPosition {
    TOP = "TOP",
    ROW = "ROW"
}
/**
 * Key used for translation of pagination when a translation key is not given as input from the caller
 */
export declare const DEFAULT_PAGINATION_TRANSLATION_KEY = "vcd.cc.grid.default.pagination";
/**
 * Different types of row selection on the grid
 */
export declare enum GridSelectionType {
    /**
     * For selecting multiple rows
     */
    Multi = "MULTI",
    /**
     * For selecting only one row at a time
     */
    Single = "SINGLE",
    /**
     * Disables the selection
     */
    None = "NONE"
}
/**
 * Representation of data required for rendering contents of cells and pagination information
 */
export interface GridDataFetchResult<R> {
    /**
     * Items to be listed in the grid
     */
    items: R[];
    /**
     * Total number of items
     */
    totalItems?: number;
}
/**
 * The information about the currently sorted column.
 */
export interface SortedColumn {
    /**
     * Whether the column is sorted normally or reversed.
     */
    reverse: boolean;
    /**
     * The name of the column that is sorted.
     */
    name: string;
}
/**
 * The types of activity indicators that can be displayed on top of the grid.
 */
export declare enum ActivityIndicatorType {
    /**
     * Display a {@link SpinnerActivityReporterComponent} indicator
     */
    SPINNER = 0,
    /**
     * Display a {@link BannerActivityReporterComponent} indicator
     */
    BANNER = 1
}
/**
 * The information about pagionation that will be exposed.
 */
export interface PagionationInformation {
    /**
     * What page is currently selected.
     */
    pageNumber: number;
    /**
     * How many items belong on a page.
     */
    itemsPerPage: number;
}
/**
 * The information the user gives to show page size and page size options in the pagination footer.
 */
export interface PaginationConfiguration {
    /**
     * Available page size options in the dropdown
     */
    pageSizeOptions?: number[];
    /**
     * Number of items to be displayed on one page. As a result, the server will return a set of pages with the defined
     * number of items per page(They can be smaller than the number here in case of last page, filtering etc.,)
     *
     * Magic: Auto calculates the size based on available height of the container
     */
    pageSize: number | 'Magic';
    /**
     * The height of a row in the datagrid. If not set, will use the default of {@link ROW_HEIGHT}.
     */
    rowHeight?: number;
    /**
     * If the page size option dropdown should be shown.
     * Defaults to false.
     */
    shouldShowPageSizeSelector?: boolean;
    /**
     * If the page number input should be shown.
     * Defaults to false.
     */
    shouldShowPageNumberInput?: boolean;
}
/**
 * The configuration object that is passed to the detail row component.
 */
export interface DetailRowConfig<R> {
    /**
     * The record that this detail row should render.
     */
    record: R;
    /**
     * The index this detail row is in the datagrid.
     */
    index: number;
    /**
     * The total number of rows in the datagrid.
     */
    count: number;
}
/**
 * The configuration object that is passed to the detail pane component.
 */
export interface DetailPaneConfig<R> {
    /**
     * The record that this detail pane should render.
     */
    record: R;
}
/**
 * The configuration objet used to create the detail pane on the datagrid.
 */
export interface DetailPane<R> {
    /**
     * The header that goes on top of this detail pane.
     */
    header: (record: R) => string;
    /**
     * The contents that go within this detail pane.
     */
    component: ComponentRendererConstructor<DetailPaneConfig<R>>;
}
/**
 * The current state of various features of the grid like filtering, sorting, pagination. This object is emitted as
 * part of the event {@link DatagridComponent.gridRefresh}. The handler then used this object to construct a query.
 */
export interface GridState<R> {
    /**
     * FIQL formatted list of active filters
     */
    filters?: string[];
    /**
     * The currently sorted column in the datagrid.
     */
    sortColumn?: SortedColumn;
    /**
     * The pagination information that the datagrid should show.
     */
    pagination?: PagionationInformation;
}
/**
 * A function that can be used to render the pagination data in the grid.
 */
export interface PaginationCallback {
    (firstItem: number, lastItem: number, totalItems: number): string | Observable<string>;
}
/**
 * For simplifying logic inside the HTML template to differentiate between different {@link GridColumn.renderer}
 * types.
 */
interface ColumnConfigInternal<R, T> extends GridColumn<R> {
    fieldName?: string;
    fieldRenderer?: FunctionRenderer<R>;
    fieldColumnRendererSpec?: ColumnRendererSpec<R, T>;
}
/**
 * Component used for saving the time required for developing a data grid. It takes different properties required for
 * rendering as Inputs and Outputs.
 *
 * Example usage in a component:
 * In the component view, different properties required for the grid are wired as Inputs and Outputs.
 *
 * @example
 * <vcd-datagrid
 *    (onGridRefresh)="fetchData()"
 *    [columns]="columns"
 *    [gridData]="gridData">
 *  </vcd-datagrid>
 *
 */
export declare class DatagridComponent<R extends B, B = any> implements OnInit, AfterViewInit, OnDestroy {
    private node;
    private translationService;
    private changeDetectorRef;
    /**
     * Sets the configuration of columns on the grid and updates the {@link columnsConfig} array. Also pushes
     * notifications for listeners to make changes to the _columns array
     */
    set columns(cols: GridColumn<R>[]);
    get columns(): GridColumn<R>[];
    /**
     * Set from the caller component using this grid. The input is set upon fetching data by the caller
     */
    set gridData(result: GridDataFetchResult<R>);
    /**
     * Type of row selection on the grid
     */
    set selectionType(selectionType: GridSelectionType);
    /**
     * List of actions given by the caller
     */
    set actions(actions: ActionItem<R, unknown>[]);
    get actions(): ActionItem<R, unknown>[];
    /**
     * To display static and contextual actions in a action bar on top of a grid
     */
    get shouldShowActionBarOnTop(): boolean;
    private get hasStaticActions();
    private get hasContextualActions();
    /**
     * Filters contextual actions from the list of actions to be displayed in a grid row
     */
    get contextualActions(): ActionItem<R, unknown>[];
    constructor(node: ElementRef, translationService: TranslationService, changeDetectorRef: ChangeDetectorRef);
    /**
     * The pagination information that the user should supply.
     */
    set pagination(pagination: PaginationConfiguration);
    get pagination(): PaginationConfiguration;
    /**
     * Desired height of the grid in pixels. If unspecificed, the grid fills the parent container.
     */
    set height(height: number);
    get height(): number;
    get shouldFillParent(): boolean;
    /**
     * Returns the items selected in the VCD datagrid.
     */
    get datagridSelection(): B[];
    /**
     * Sets the items selected in the VCD datagrid.
     */
    set datagridSelection(selection: B[]);
    /**
     * If the contextual buttons should display on the top of a grid.
     */
    get shouldDisplayContextualActionsOnTop(): boolean;
    /**
     * If the contextual buttons should display in a row.
     */
    get shouldDisplayContextualActionsInRow(): boolean;
    /**
     * The {@link #maxFeaturedActionsOnRow} value depends in the contextual featured actions config which belongs to the
     * {@link ActionMenuComponent} being used in the rows. So, we wait for action menus in rows to be initialized and then calculate
     * the value
     */
    set actionMenusInRow(actionMenus: QueryList<ActionMenuComponent<R, unknown>>);
    /**
     * Actions to be displayed on a grid or in a row
     */
    private _actions;
    private initialSelection;
    /**
     * An output that emits when the selection changes on the grid.
     */
    datagridSelectionChange: EventEmitter<(R | B)[]>;
    /**
     * An output that emits when the selection changes on the grid.
     *
     * @deprecated
     */
    selectionChanged: EventEmitter<(R | B)[]>;
    /**
     * How to display the static and contextual actions.
     */
    actionDisplayConfig: ActionDisplayConfig;
    /**
     * Whether to display contextual actions inside the row or on top of the grid
     */
    contextualActionPosition: ContextualActionPosition;
    /**
     * Emitted whenever {@link #columns} input is updated
     */
    columnsUpdated: EventEmitter<void>;
    /**
     * Columns are updated using set columns, addColumn and removeColumn methods. This cache helps in preserving changes
     * made by each of the methods to columns array and helps in not overwriting the changes made by one of the methods
     * with changes made by another method
     */
    private _columns;
    /**
     * A optional string to be displayed above the grid.
     */
    header?: string;
    /**
     * The type of activity indicator that should sit ontop of the grid.
     */
    indicatorType: ActivityIndicatorType;
    GridColumnHideable: typeof GridColumnHideable;
    TooltipSize: typeof TooltipSize;
    ActivityIndicatorType: typeof ActivityIndicatorType;
    /**
     * The component that sound be rendered for this detail row.
     *
     * @param R The type of record that this detail component will display.
     */
    detailComponent: ComponentRendererConstructor<DetailRowConfig<R>>;
    /**
     * Specifies if the row is expanded. The default is false.
     */
    isRowExpanded: boolean;
    /**
     * A detail pane that will be displayed when a user selects to expand a row.
     *
     * @param R The type of record that this detail pane will display.
     */
    detailPane: DetailPane<R>;
    private _selectionType;
    /**
     * The CSS class to use for the Clarity datagrid.
     */
    clrDatagridCssClass: string;
    /**
     * The text placed next to the pagination number dropdown.
     */
    paginationDropdownText: string;
    /**
     * When there is no data, show this message.
     */
    emptyGridPlaceholder: string;
    private _pagination;
    /**
     * The page size to display.
     */
    pageSize: number;
    /**
     * The complete set of options to show the user.
     */
    pageSizeOptions: number[];
    private _height;
    /**
     * Loading indicator on the grid
     */
    isLoading: boolean;
    /**
     * Used for simplifying logic inside the HTML template to differentiate between different
     * {@link GridColumn.renderer} types.
     */
    columnsConfig: ColumnConfigInternal<R, unknown>[];
    /**
     * List of items used for displaying rows on the grid
     */
    items: R[];
    /**
     * The total number of items that could be displayed in the grid.
     */
    totalItems?: number;
    /**
     * Emitted during the initial rendering, and is emitted whenever filtering/sorting/paging params change
     * {@link #GridState} is the type of value emitted
     */
    gridRefresh: EventEmitter<GridState<R>>;
    datagrid: ClrDatagrid;
    /**
     * The pagination display within the datagrid.
     */
    paginationComponent: ClrDatagridPagination;
    /**
     * The activity reporter that all activites are displayed on
     */
    actionReporter: ActivityReporter;
    private viewInitted;
    /**
     * Used for translating pagination information displayed in the grid
     */
    paginationTranslationKey: string;
    private subTracker;
    /**
     * Used for calculating the width of actions column
     */
    maxFeaturedActionsOnRow: number;
    /**
     * If selection should be preserved when the item is not loaded to the grid.
     *
     * Defaults to false;
     */
    preserveSelection: boolean;
    /**
     * To add or replace a column of this datagrid columns. Exposed for columns modifiers(eg: directives) that listen to
     * {@link columnsUpdated} event and want to modify the columns set by components using this datagrid.
     */
    addColumn(col: GridColumn<R>): void;
    /**
     * To remove a column from this datagrid columns. Exposed for columns modifiers(eg: directives) that listen to
     * {@link columnsUpdated} event and want to modify the columns set by components using this datagrid.
     */
    removeColumn(col: GridColumn<R>): void;
    private findColumnIndex;
    private updateColumnsConfig;
    /**
     * Returns an identifier for the given record at the given index.
     *
     * If the record has a href, defaults to that. Else, defaults to index.
     */
    trackBy: TrackByFunction<B>;
    /**
     * Gives the render spec to create the detail row for the row with the given record, at the given index, and
     * in a datagrid with the given count of total items.
     */
    getDetailRowRenderSpec(record: R, index: number, count: number): ComponentRendererSpec<DetailRowConfig<R>>;
    getDetailPaneRenderSpec(record: R): ComponentRendererSpec<DetailPaneConfig<R>>;
    /**
     * Gives the CSS class to use for a given datarow based on its relative index and entity definition.
     */
    clrDatarowCssClassGetter(row: R, index: number): string;
    private updateSelectedItems;
    /**
     * Given an existing selection that is made up of records that are about to become stale,
     * and new records to be loaded into the grid, returns the selection mapped to records
     * from the newly added records, excluding any records that may not be present in the
     * new selection because they are not present in the new data.
     */
    private mapSelectedRecords;
    private clearSelectionInformation;
    /**
     * Called when the {@param state} of the Clarity datagrid changes.
     */
    gridStateChanged(state: ClrDatagridStateInterface): void;
    /**
     * Is the given column able to be hidden by the user through the show/hide menu.
     */
    isColumnHideable(column: GridColumn<R>): boolean;
    /**
     * Resets the pagination to page 1.
     */
    resetToPageOne(): void;
    /**
     * Gives the correct string to display for the pagination.
     */
    getPaginationTranslation(paginationData: ClrDatagridPagination): LazyString;
    /**
     * The number of rows in a single page.
     */
    private getPageSize;
    /**
     * Available page size options in the dropdown
     */
    private getPageSizeOptions;
    /**
     *  Calculates the pageSize from the available space in the datagrid body
     */
    private calculatePageSize;
    /**
     * Updates the pagination information by recalculating pageSize if needed.
     */
    private updatePagination;
    /**
     * Defines the {@property columnsConfig} by adding extra property required for differentiating different kinds
     * of renderers which is required in the HTML template.
     */
    getColumnsConfig(columns: any): ColumnConfigInternal<R, unknown>[];
    ngOnInit(): void;
    ngAfterViewInit(): void;
    ngOnDestroy(): void;
}
export {};
