import { InjectionToken } from "@angular/core";
import { ToolBarItem } from "../toolbar-items";
import { DataItem } from "../metadata/data-item";
import { Observable } from "rxjs";

export declare const ITEM_HOOKS_PROVIDER_TOKEN: InjectionToken<string>;

/**
 * Provides item lifecycle hooks
 */
export interface ItemHooksProvider {
    /**
     * Fires when the item is loaded in the edit screen.
     * @param item The item that is loaded.
     */
    onItemLoaded?(item: DataItem): void;

    /**
     *  Fires when the create/edit form is being initializing.
     *
     * @param {EditLifecycleHookParam} data The item that was edited or 'null' if the item was in create.
     * @returns {Observable<void>} Observable result that marks when the hook is completed.
     * @memberof ItemHooksProvider
     */
    onEditItemInitializing?(data: EditLifecycleHookParam): Observable<void>;

    /**
     * Fires when the create/edit form is being unloading/destroying.
     *
     * @param {EditLifecycleHookParam} data The item that is being edited or 'null' if the item is in create.
     * @returns {Observable<void>} Observable result that marks when the hook is completed.
     * @memberof ItemHooksProvider
     */
    onEditItemUnloading?(data: EditLifecycleHookParam): Observable<void>;

    /**
     * Fires when the create/edit form is being changed.
     * Most commonly fired when some operation is executed such as Publish, Save as Draft etc.
     * @param {EditLifecycleHookParam} data The item that is being edited or 'null' if the item is in create.
     * @returns {Observable<void>} Observable result that marks when the hook is completed.
     * @memberof ItemHooksProvider
     */
    onEditItemChanged?(data: EditLifecycleHookParam): Observable<void>;

    /**
     * Fires when the list/thumbs/timeline view is being initializing.
     *
     * @param {ListLifecycleHookParam} data The items that will be rendered in the view.
     * @returns {Observable<void>} Observable result that marks when the hook is completed.
     * @memberof ItemHooksProvider
     */
    onGridItemsInitializing?(data: ListLifecycleHookParam): Observable<void>;

    /**
     * Fires when the list/thumbs/timeline view is being unloading/destroying.
     *
     * @param {ListLifecycleHookParam} data The items that were rendered in the view.
     * @returns {Observable<void>} Observable result that marks when the hook is completed.
     * @memberof ItemHooksProvider
     */
    onGridItemsUnloading?(data: ListLifecycleHookParam): Observable<void>;

    /**
     * Fires when the list/thumbs/timeline view items are being changed.
     *
     * @param {ListLifecycleHookParam} data The new items that will be rendered in the view.
     * @returns {Observable<void>} Observable result that marks when the hook is completed.
     * @memberof ItemHooksProvider
     */
    onGridItemsChanged?(data: ListLifecycleHookParam): Observable<void>;
}

export interface EditLifecycleHookParam {
    item: DataItem;
}

export interface ListLifecycleHookParam {
    items: DataItem[];
}
