import { nothing, TemplateResult } from 'lit';
import { ActivityState, IntentResult, type Intent } from './ActivityManager.js';
import { FragmentManager } from './FragmentManager.js';
import type { Fragment } from './Fragment.js';
import type { Application, UpdateRequest } from './Application.js';
import type { ActivityDetail, ActivityWithResultDetail } from '../events/IntentEvents.js';
/**
 * `Activity` is a crucial component of your app. An application sends an intent
 * to bring the activity. If it's found, the activity gets to the foreground and start its activity.
 *
 * **Lifecycle**
 *
 * - `onCreated()` - fires when the system first creates the activity.
 * - `onStart()` - the activity becomes visible to the user as the app prepares for
 *  the activity to enter the foreground and become interactive.
 * - `onResume()` - the state in which the app interacts with the user.
 * - `onPause()` - the first indication that the user is leaving your activity.
 * - `onStop()` - your activity is no longer visible to the user.
 * - `onDestroy()`- is called before the activity is destroyed
 */
export declare class Activity extends EventTarget {
    /**
     * To be set by an activity to replace the default render root.
     * This is particularly useful when the activity is a modal dialog
     * and the content should be rendered outside the application's render root.
     */
    renderRoot?: HTMLElement;
    /**
     * An activity can define its action name that does not change.
     * It then should be used as the activity registration key.
     * This way other activities/fragments can use it to call the activity.
     */
    static action?: string;
    state: ActivityState;
    protected parent: Application;
    /**
     * The fragment manager that manages fragments in this activity.
     */
    protected manager: FragmentManager;
    protected resultData?: unknown;
    protected exitCode: IntentResult;
    get resultCode(): IntentResult;
    /**
     * When starting an new activity for result, we add the request code here
     * so that the manager can track which activity originally called the
     * activity for result.
     */
    protected pendingRequestCodes: number[];
    constructor(parent: Application);
    /**
     * Called when the activity is starting. This is where most initialization should go.
     * You can call `finish()` from within this function, in which case `onDestroy()` will be
     * immediately called after `onCreate()` without any of the rest of the activity lifecycle
     * (`onStart()`, `onResume()`, `onPause()`, etc) executing.
     *
     * In the `onCreate()` method, perform basic activity startup logic that happens only once
     * for the entire life of the activity.
     * @param intent Optional intent data.
     */
    onCreate(intent?: Intent): void | Promise<void>;
    /**
     * Called when the activity becomes visible.
     * As `onCreate()` exits, the activity enters the `Started` state, and the activity becomes visible
     * to the user. This callback contains what amounts to the activity’s final preparations for coming
     * to the foreground and becoming interactive.
     *
     * Called after `onCreate()`.  It will usually be followed by onResume().
     * This is a good place to begin running animations, etc.
     * You can call `finish()` from within this function, in which case `onStop()` will be
     * immediately called after `onStart()` without the lifecycle transitions
     * in-between (`onResume()`, `onPause()`, etc) executing.
     */
    onStart(): void | Promise<void>;
    /**
     * Called when the activity gains focus.
     * Called after the `onPause()`. This is usually a hint for your activity to start interacting
     * with the user, which is a good indicator that the activity became active and ready to receive input.
     * This sometimes could also be a transit state toward another resting state.
     * For instance, an activity may be relaunched to `onPause()` due to configuration changes and
     * the activity was visible, but wasn't the top-most activity of an activity task.
     * The `render()` function is always called after this callback.
     */
    onResume(): void | Promise<void>;
    /**
     * Called when the activity loses focus.
     * Called as part of the activity lifecycle when the user no longer actively interacts with the activity,
     * but it is still visible on screen. The counterpart to `onResume()`.
     *
     * When activity B is launched in front of activity A, this callback will be invoked on A.
     * B will not be created until A's `onPause()` returns, so be sure to not do anything lengthy here.
     *
     * This callback is mostly used for saving any persistent state the activity is editing,
     * to present a "edit in place" model to the user and making sure nothing is lost if there are
     * not enough resources to start the new activity without first killing this one.
     * This is also a good place to stop things that consume a noticeable amount of CPU in order
     * to make the switch to the next activity as fast as possible.
     */
    onPause(): void | Promise<void>;
    /**
     * Called when you are no longer visible to the user.
     * You will next receive either onRestart(), onDestroy(), or nothing, depending on later user activity.
     * This is a good place to stop refreshing UI, running animations and other visual things.
     */
    onStop(): void | Promise<void>;
    onRestart(): void | Promise<void>;
    /**
     * Perform any final cleanup before an activity is destroyed.
     * This can happen because the activity is finishing (someone called finish() on it).
     */
    onDestroy(): void | Promise<void>;
    /**
     * Called when a new intent is delivered
     * @param intent New intent data.
     */
    onNewIntent(intent: Intent): void | Promise<void>;
    /**
     * Called by the renderer when the activity is rendered for the first time.
     */
    onFirstRender(): void;
    /**
     * A function called when it should render the view.
     */
    render(): TemplateResult | typeof nothing;
    /**
     * Finishes the activity.
     */
    finish(): Promise<void>;
    /**
     * When the activity changes its state it should call the
     * `requestUpdate()` method to inform the parent application to
     * perform the render operation.
     * The function dispatches the `activity:update` custom event
     * that is handled by the parent application.
     *
     * Note, the application may choose to not call the render procedure
     * (for example, when the activity is not visible). The rendering
     * function is asynchronous. The only way to know the activity is being rendered,
     * is when the `render()` method if called.
     */
    requestUpdate(opts?: UpdateRequest): void;
    /**
     * Registers a new fragment.
     * @param key The name of the fragment
     * @param fragment The fragment to register.
     */
    addFragment(key: string, fragment: Fragment, data?: unknown): Promise<void>;
    showFragment(key: string, root?: HTMLElement): Promise<void>;
    hideFragment(key: string): Promise<void>;
    /**
     * Unifies Fragment and Activity interfaces.
     * @returns `this`
     */
    getApplication(): Application;
    /**
     * A shortcut to the `manager` function.
     * @param intent The intent to start
     */
    startActivity(intent: Intent): Promise<void>;
    /**
     * Starts a new activity for a result.
     * @param intent The intent that created this activity.
     * @returns The request code created with this call.
     */
    startActivityForResult(intent: Intent): Promise<number>;
    /**
     * Call this method to return data to the activity that started this activity.
     * @param data The data to return.
     */
    setResult(resultCode: IntentResult, data?: unknown): void;
    /**
     * Called when an activity you launched exits, giving you the `requestCode` you started it with,
     * the `resultCode` it returned, and any additional data from it. The `resultCode` will be `RESULT_CANCELED`
     * if the activity explicitly returned that, didn't return any result, or crashed during its operation.
     *
     * An activity can never receive a result in the resumed state. You can count on `onResume()` being called
     * after this method, though not necessarily immediately after. If the activity was resumed,
     * it will be paused and the result will be delivered, followed by `onResume()`.
     *
     * @param requestCode The request code passed to startActivityForResult.
     * @param data The result from the activity.
     * @param intent The intent that was used to start the activity.
     */
    onActivityResult(requestCode: number, resultCode: IntentResult, intent: Intent): Promise<void>;
    getActivity(): Activity;
    /**
     * Checks whether this activity initiated the activity for result.
     * @param code The request code to look for.
     * @returns `true` if the activity has the request code.
     */
    hasRequestCode(code: number): boolean;
    getResult(): unknown | undefined;
    /**
     * A handler for the intent event dispatched by web components hosted by this activity.
     *
     * **Usage example:**
     *
     * ```ts
     * <custom-element @startactivity="${this.handleIntentEvent}"></custom-element>
     * <custom-element @startactivityforresult="${this.handleIntentEvent}"></custom-element>
     * ```
     *
     * @param event The event that was dispatched.
     * @returns A promise that resolves when the intent is handled.
     * @throws An error if the activity has no activity.
     * @throws An error if the event type is not recognized.
     */
    handleIntentEvent(event: CustomEvent<ActivityDetail | ActivityWithResultDetail>): Promise<void>;
}
//# sourceMappingURL=Activity.d.ts.map