import { OpenFin } from '@openfin/core';

/**
 * @internal
 * @interface
 */
type BaseContent = {
    title?: string;
    iconUrl?: string;
};
/**
 * SuperTabs are complex top level tabs in HERE-ZERO which can contain a layout of different
 * apps.
 *
 * @interface
 * @category Content
 */
type SupertabContent = BaseContent & {
    type: 'supertab';
    layout: OpenFin.LayoutOptions;
};
/**
 * An App can be launched in a SuperTab, or as a stand alone SuperTab of its own and always has a single URL.
 * @category Content
 *
 * @interface
 */
type AppContent = BaseContent & {
    type: 'app';
    url: string;
};
/**
 * External Apps are allow URLS which cannot be opened in HERE-ZERO due to CORS or frame-ancestors restrictions
 * to be launched in a separate browser window.
 *
 * @interface
 * @category Content
 */
type ExternalAppContent = BaseContent & {
    type: 'externalApp';
    /**
     * The URL of the External App.
     */
    url: string;
    /**
     * Controls the features of the window, see https://developer.mozilla.org/en-US/docs/Web/API/Window/open#windowfeatures
     */
    windowFeatures?: string;
    /**
     * Determines the name of the window. In modern browsers, names are unique, and relaunching a window with the same name
     * causes it to be brought to front again. This can be handy in HERE-ZERO to ensure only one instance of an external-app
     * exists per HERE-ZERO Instance. Please note, this will only be unique within each browser tab, which means multiple HERE-ZERO instances
     * in multiple Browser Tabs will each be able to launch one instance of a window with the same name.
     *
     * See https://developer.mozilla.org/en-US/docs/Web/API/Window/open#target
     */
    windowName?: string;
};
/**
 * Represents the types of Content that can be launched in HERE-ZERO
 * @category Content
 */
type Content = SupertabContent | AppContent | ExternalAppContent;
/**
 * @category Configuration
 */
type ContextGroupStrategy = 'window' | 'supertab' | 'global';
interface Icon {
    src: string;
    sizes: string;
    type?: string;
    purpose?: 'any' | 'maskable' | 'monochrome' | string;
}
/**
 * Configuration options for customizing logos and icons within the HERE-ZERO UI.
 *
 * @interface
 * @category Configuration
 */
type LogoConfig = {
    /**
     * URL or path to the icon displayed in the search command bar.
     * This icon appears in the search interface to help users identify the search functionality.
     */
    searchCommandBar?: string;
    /**
     * URL or path to the icon displayed on new tab buttons.
     * This icon appears on buttons that create new tabs in HERE-ZERO.
     */
    newTab?: string;
};
/**
 * Configuration options for controlling how content within HERE-ZERO interacts
 * through the FDC3 and fin.interop APIs.
 *
 * @interface
 * @category Configuration
 */
type InteropConfig = {
    /**
     * Controls the default grouping strategy for content within HERE-ZERO.
     *
     * This setting determines how views share context groups for interop communication:
     *
     * - `'supertab'` - Each view in a HERE-ZERO SuperTab will share a context group only with other views in the same SuperTab.
     * - `'window'` - Each view in a HERE-ZERO Browser Tab will share a context group with all other views in the same Browser Tab.
     * - `'global'` - Each view in a HERE-ZERO Browser Tab will be able to share with all other views, even across Browser Tabs.
     *
     * @see [FDC3:Interop](https://fdc3.finos.org/docs/1.2/interop)
     * @see [fin.interop](https://developers.openfin.co/docs/interop)
     */
    contextGroupStrategy: ContextGroupStrategy;
};
/**
 * Configuration options for Progressive Web App (PWA) features in HERE-ZERO.
 *
 * @interface
 * @category Configuration
 */
type PWAConfig = {
    /**
     * Specifies the icons that should be used for this HERE-ZERO Progressive Web Application
     * when users decide to install it on their devices.
     *
     * These icons follow the standard PWA icon format and will be used for:
     * - App installation prompts
     * - Home screen icons
     * - Splash screens
     * - App switcher interfaces
     *
     * @see [MDN: Progressive Web Apps - Icons](https://developer.mozilla.org/en-US/docs/Web/Progressive_web_apps/How_to/Define_app_icons)
     */
    icons?: Icon[];
};
/**
 * The HereConfig is where all required configuration options are specified for a HERE-ZERO
 * application.
 *
 * @category Configuration
 * @interface
 * @hidden
 */
type HereConfig = {
    /**
     * @inheritDoc LogoConfig
     */
    logo?: LogoConfig;
    /**
     * The title controls the HTML Title tag of the HERE-Zero application.
     *
     * @see [MDN: Title Element](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/title)
     */
    title?: string;
    /**
     * Specifies url of the favicon.ico of the HERE-ZERO application.
     */
    favicon?: string;
    /**
     * @inheritDoc InteropConfig
     */
    interop?: InteropConfig;
    /**
     * Specifies the Base path of HERE-ZERO. This must match the base path of your Server in order for HERE-ZERO to properly load.
     *
     * E.g. If you are hosting the output of this build on https://www.my-company.com/apps/zero, the value of base should be `'apps/zero/'`.
     *
     * @example ```
     * {
     *  ...
     *  base: 'app/zero'
     * }
     * ```
     * Optional, if not specified, defaults to `'/'`
     *
     */
    base?: string;
    /**
     * @inheritDoc PWAConfig
     *
     * If not specified, or false, PWA Install features will be disabled.
     * @see [MDN: Progressive Web Apps](https://developer.mozilla.org/en-US/docs/Web/Progressive_web_apps)
     */
    pwa?: PWAConfig | false;
};
/**
 * Initial content seen in HERE-ZERO
 * @interface
 * @category Configuration
 */
type InitialContent = {
    /**
     * The initial content to show in a HERE-ZERO application.
     */
    content: Content[];
};

/**
 * Parameters passed to the user-provided search function.
 */

/**
 * Search Params passed by HERE-ZERO to a Search Handling override.
 * @category Search
 */
interface SearchParams {
    /**
     * The current user search query string.
     */
    query: string;
    /**
     * Represents the users current pagination state
     */
    pagination: {
        /**
         * Represents the expected number of search results each page should contain.
         */
        offset: number;
        /**
         * The page number (e.g., starting from 1 or 0).
         */
        limit: number;
    };
    /**
     * Signal to abort the request if it's superseded by a new one.
     *
     * HERE-ZERO will automatically abort a pending search request if the user updates the
     * query or dismisses the search UI entirely.
     *
     * This allows the implemented to also tear down the request gracefully.
     */
    signal: AbortSignal;
}
/**
 * The expected structure of the resolved value from the search function.
 * @category Search
 */
interface SearchResult<TResult> {
    /** The array of result items for the current query/page. */
    items: TResult[];
    /** The total number of items available for the query (for pagination controls). */
    totalCount: number;
}
/**
 * Type definition for the user-provided search function.
 * It takes SearchParams and returns a Promise resolving with SearchResult.
 * TResult defines the type of individual items in the results array.
 * @function
 * @category Search
 */
type SearchHandler<TResult> = (params: SearchParams) => Promise<SearchResult<TResult>>;
/**
 * Type definition for a search result in HERE-ZERO.
 * @interface
 * @category Search
 */
type SearchResultValue = Content | SearchContextResult;
/**
 * An action that can be triggered by a user on a search result returned by a Search Agent.
 *
 * Actions are displayed as buttons alongside search results in Here™'s search UI. That is, except for the first action, which is hidden as it is triggered automatically when the user selects the search result.
 *
 * @interface
 */
type BaseSearchAction = {
    /**
     * A fuller description of the action that will be displayed in Here™’s search UI when the user hovers over the action button.
     */
    description?: string;
    /**
     * An icon that will be displayed within the action button.
     */
    icon?: string;
    /**
     * Compact title of the action displayed within the action button.
     */
    title: string;
};
/**
 * @interface
 * @category Search
 */
type SearchOpenAction = {
    type: 'open';
    content: Content;
};
/**
 * @interface
 * @category Search
 */
type SearchAction = BaseSearchAction & SearchOpenAction;
/**
 * @interface
 * @category Search
 */
type SearchContextResult<ContextType extends {
    type: string;
} = {
    type: string;
} & Record<string, unknown>> = {
    type: 'context';
    context: ContextType;
    /**
     * An array of actions that can be triggered by a user on a search result returned by a Search Agent.
     * The first action in the array is the default action that will be triggered automatically when the user selects the search result.
     * Up to three more actions can be provided, which will be displayed as buttons alongside the search result in Here™’s search UI.
     */
    actions: SearchAction[];
    /**
     * URL or data URI of an icon that will be displayed with the search result in Here™’s search UI.
     */
    icon?: string;
    /**
     * Secondary text that will be displayed with the search result in Here™’s search UI.
     */
    label?: string;
    /**
     * Primary text that will be displayed with the search result in Here™’s search UI.
     */
    title: string;
};

/**
 * Override function that retrieves the Featured Content displayed in the New View UI.
 *
 * Will be called every time the user opens a New HERE-ZERO View Tab.
 *
 * @returns A Promise resolving with an array of Content. The featured content will be shown in the same order as the array.
 * @category Configuration
 * @experimental
 */
type FetchFeaturedContentOverride = () => Promise<Content[]>;
/**
 * Override function that retrieves the Featured Content displayed in launcher sidebar.
 *
 * Will be called once, every time HERE-ZERO Loads.
 *
 * @returns A Promise resolving with an array of Content. The featured content will be shown in the same order as the array.
 * @category Configuration
 * @experimental
 */
type FetchLauncherContentOverride = () => Promise<Content[]>;
/**
 * Override function that determines the initial collection seen by the user whenever they launch a fresh instance of HERE-ZERO.
 *
 * A Collection represents all Supertabs shown in a HERE-ZERO Browser Instance, as well as the content to be displayed in those supertabs.
 *
 * A fresh HERE-ZERO instance is only created when a Browser Tab navigates to HERE-ZERO for the first time.
 *
 * In the following scenarios, the previous state of the HERE-ZERO Browser Tab Session will be restored:
 * - When navigating back or forward to HERE-ZERO from a different website using the Browser's back or forward buttons.
 * - When loading HERE-ZERO again in a Browser Tab Session without using the back or forward buttons (e.g. Redirect).
 * - When reloading a HERE-ZERO instance.
 * - When duplicating a HERE-ZERO Browser Tab Session using the Browser's 'Duplicate Tab' feature.
 * - When restoring a HERE-ZERO Browser Tab from a Browser's 'Recently Closed' section.
 *
 * Please note, the ability for HERE-ZERO to restore and duplicate Browser Tabs will depend on how the Browser handles session storage in these scenarios.
 *
 * @returns The initial Collection to show to the user, or a promise resolving with it.
 * @category Configuration
 * @experimental
 */
type GetInitialContentOverride = () => InitialContent | Promise<InitialContent>;
/**
 * Override function that enables resolution of user search input in the HERE-ZERO search bar.
 *
 * @category Configuration
 * @experimental
 */
type HandleSearchQueryOverride = SearchHandler<SearchResultValue>;
/**
 * Override function invoked whenever the user clicks the 'logout' button in the HERE-ZERO menu.
 *
 * If no authentication overrides are specified, this logout button will be hidden.
 *
 * This override can be used to action the logout, for example by redirecting to a logout page or
 * fetching an API endpoint that will invalidate the current cookies.
 *
 * @returns A Promise resolving once the logout action is completed.
 * @category Configuration
 * @experimental
 */
type OnLogoutOverride = () => Promise<void>;
/**
 * Override function called periodically by HERE-ZERO to validate the health of a session.
 *
 * When false is returned, HERE-ZERO will display a warning to the user that their session has been ended,
 * and prompts them to reload.
 *
 * It is up to the implementer of this override to decide what an invalid session is and when it occurs.
 *
 * @returns True if the session is still active, or false otherwise.
 * @category Configuration
 * @experimental
 */
type ValidateSessionOverride = () => Promise<boolean>;
/**
 * The Overrides type allows customisation of certain bespoke behaviors in HERE-ZERO.
 *
 * Some are mandatory for HERE-ZERO to successfully build, while others are optional features.
 *
 * See {@link `defineOverrides`} for info on how to declare overrides.
 *
 * @interface
 * @category Configuration
 * @experimental
 */
type Overrides = {
    /**
     * Content overrides are used to control the Content shown to the user in various parts of the HERE-ZERO
     * user interface.
     */
    content: {
        /**
         * @inheritDoc FetchFeaturedContentOverride
         */
        fetchFeaturedContent: FetchFeaturedContentOverride;
        /**
         * @inheritDoc FetchLauncherContentOverride
         */
        fetchLauncherContent: FetchLauncherContentOverride;
        /**
         * @inheritDoc GetInitialContentOverride
         */
        getInitialContent: GetInitialContentOverride;
    };
    /**
     * Search overrides allow customisation of the search results a user sees in HERE-ZERO.
     */
    search: {
        /**
         * @inheritDoc HandleSearchQueryOverride
         */
        handleSearchQuery: HandleSearchQueryOverride;
    };
    /**
     * Optional overrides that allow basic authentication flows to be implemented.
     */
    authentication?: {
        /**
         * @inheritDoc OnLogoutOverride
         */
        onLogout: OnLogoutOverride;
        /**
         * @inheritDoc ValidateSessionOverride
         */
        validateSession: ValidateSessionOverride;
    };
};

type OverridesConfig = {
    file: string;
};
type Config = HereConfig & {
    overrides: OverridesConfig;
    outputDir: string;
};
declare function defineConfig(config: Config): Config;

declare function defineOverrides(overrides: Overrides): void;

export { type AppContent, type Config, type Content, type ContextGroupStrategy, type ExternalAppContent, type FetchFeaturedContentOverride, type FetchLauncherContentOverride, type GetInitialContentOverride, type HandleSearchQueryOverride, type HereConfig, type InitialContent, type InteropConfig, type LogoConfig, type OnLogoutOverride, type Overrides, type OverridesConfig, type PWAConfig, type SearchAction, type SearchContextResult, type SearchHandler, type SearchParams, type SearchResult, type SearchResultValue, type SupertabContent, type ValidateSessionOverride, defineConfig, defineOverrides };
