import { nothing, TemplateResult } from 'lit';
import { Activity } from './Activity.js';
import { FragmentState, type FragmentOptions, FragmentManager } from './FragmentManager.js';
import type { Application, UpdateRequest } from './Application.js';
import { FragmentRenderer } from './renderer/FragmentRenderer.js';
import { Intent, ResolvedIntent } from './ActivityManager.js';
import type { ActivityDetail, ActivityWithResultDetail } from '../events/IntentEvents.js';
import { type RefOrCallback } from 'lit/directives/ref.js';
/**
 * Similar to Activity, with lifecycle methods (onCreate, onAttach, onDetach, etc.).
 * The crucial difference is that a Fragment is always hosted by an `Activity` or
 * another `Fragment`.
 *
 * A `Fragment` represents a reusable portion of the app's UI.
 * A fragment defines and manages its own layout, has its own lifecycle,
 * and can handle its own input events.
 * Fragments can't live on their own. They must be hosted by an activity or another
 * fragment. The fragment’s view hierarchy becomes part of, or attaches to,
 * the host’s view hierarchy.
 */
export declare class Fragment extends EventTarget {
    #private;
    state: FragmentState;
    parent?: Activity | Fragment;
    protected children: Map<string, Fragment>;
    protected fragmentManager: FragmentManager;
    get renderer(): FragmentRenderer;
    /**
     * The host to be used by the FragmentRenderer to assign it to the Lit's render root.
     * Whatever is assigned to this property will be used as the root element.
     *
     * Fragments should use this property to manipulate the event's target.
     * If a fragment renders multiple children, but only one is visible,
     * it should assign the host value to the currently rendered child.
     */
    host: Fragment;
    constructor(options?: FragmentOptions);
    /**
     * When implemented, this method returns the class name to be used as a root class for the fragment.
     * This class name can be used to apply styles or identify the fragment in the DOM.
     * @returns The class name to be used as a root class for the fragment.
     */
    rootClass(): string | undefined;
    /**
     * @see {@link ./Renderer.js}
     */
    setRenderRoot(renderRoot: HTMLElement | string): void;
    onData(data: unknown): void | Promise<void>;
    /**
     * Called once when the fragment is created.
     *
     * In the `onCreate()` method, perform basic fragment startup logic that happens only once
     * for the entire life of the fragment.
     * @param data Optional init data.
     */
    onCreate(data?: unknown): void | Promise<void>;
    /**
     * Called when the fragment is attached to a parent
     */
    onAttach(data?: unknown): void | Promise<void>;
    /**
     * Called when the fragment becomes visible.
     */
    onStart(): void | Promise<void>;
    /**
     * Called when the fragment gains focus.
     */
    onResume(): void | Promise<void>;
    /**
     * Called when the fragment loses focus.
     */
    onPause(): void | Promise<void>;
    /**
     * Called when the fragment is no longer visible.
     */
    onStop(): void | Promise<void>;
    /**
     * Called when the fragment is detached from a parent
     */
    onDetach(): void | Promise<void>;
    /**
     * Called before the fragment is destroyed.
     */
    onDestroy(): void | Promise<void>;
    /**
     * Called by the renderer when the fragment is rendered for the first time.
     */
    onFirstRender(): void;
    /**
     * A function called when it should render the view.
     * By default it renders a fragment view if the fragment hosts other fragments and only one is visible.
     */
    render(): TemplateResult | typeof nothing;
    /**
     * Checks whether there's only one `Fragment` that is in the `Resumed` state
     * and returns it. It returns `null` if there is no `Fragment`s or more than a single
     * visible `Fragment`.
     * @returns A Fragment that is the only fragment that should be visible.
     */
    getSingleVisibleFragment(): Fragment | null;
    /**
     * Checks whether this fragment is a host for other fragments.
     * @returns `true` when this fragment hosts other fragments.
     */
    isRenderingFragments(): boolean;
    /**
     * @returns The list of all fragments that are in the Resumed state.
     */
    getVisibleFragments(): Fragment[];
    /**
     * Adds a child fragment to this fragment.
     * The FragmentManager will handle lifecycle.
     * @param key The name of the fragment.
     * @param fragment The fragment to add.
     */
    addChild(key: string, fragment: Fragment, data?: unknown): Promise<void>;
    /**
     * Removes a fragment from this fragment.
     * @param key The name of the fragment to remove.
     */
    removeChild(key: string): Promise<void>;
    /**
     * Creates a RefCallback that can be used with lit's `ref()` directive
     * to automatically show/hide a child fragment when its container element
     * is added or removed from the DOM.
     *
     * @param key The key of the child fragment to manage.
     * @returns A RefCallback to be used with the `ref()` directive.
     *
     * @example
     * // In your parent fragment's render method:
     * // html`<div ${ref(this.createFragmentRef('my-child-fragment'))}></div>`
     */
    createFragmentRef(key: string): RefOrCallback<Element>;
    /**
     * A helper to request an update.
     * Application or parent Fragment will handle rendering.
     */
    requestUpdate(opts?: UpdateRequest): void;
    getApplication(): Application | undefined;
    getActivity(): Activity | undefined;
    /**
     * Starts an activity for result.
     * @template T The type of the result data expected.
     * @param intent The intent to start.
     * @returns A promise that resolves when the started activity finishes, returning the result Intent with
     * data of type T.
     * @example
     * ```typescript
     * const resultIntent = await this.startActivityForResult<{ userId: string }>({ action: 'pickUser' });
     * if (resultIntent.resultCode === IntentResult.RESULT_OK) {
     *   console.log(resultIntent.data?.userId);
     * }
     * ```
     */
    startActivityForResult<T>(intent: Intent): Promise<ResolvedIntent<T | undefined>>;
    /**
     * Starts another activity.
     * @param intent The intent to start.
     */
    startActivity(intent: Intent): Promise<void>;
    /**
     * A handler for the intent event dispatched by web components hosted by this fragment.
     *
     * **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 fragment has no activity.
     * @throws An error if the event type is not recognized.
     */
    handleIntentEvent(event: CustomEvent<ActivityDetail | ActivityWithResultDetail>): Promise<void>;
    /**
     * Shows a registered fragment.
     * @param key The fragment's key.
     * @param options Fragment rendering options.
     */
    showFragment(key: string, options?: {
        renderTarget?: HTMLElement;
        isHost?: boolean;
    }): Promise<void>;
    /**
     * Hides a fragment by its key.
     * @param key The fragment's key.
     */
    hideFragment(fragment: Fragment | string): Promise<void>;
}
//# sourceMappingURL=Fragment.d.ts.map